diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-22 20:56:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-22 20:56:30 -0400 |
| commit | 1c636e2564e2fc2e8e4b6b1edbc782592ee3d2d7 (patch) | |
| tree | 5311dc81615ff9efa2b4840070371f54182f8bee /lib/std | |
| parent | 9baf8917725ede02d9fc1aeebe253842174ee57b (diff) | |
| parent | 563ea60a86a733f53f2394a11cb9ec4e56063fa3 (diff) | |
| download | zig-1c636e2564e2fc2e8e4b6b1edbc782592ee3d2d7.tar.gz zig-1c636e2564e2fc2e8e4b6b1edbc782592ee3d2d7.zip | |
Merge pull request #8844 from ifreund/inline
Support inline keyword as well as callconv(.Inline)
Diffstat (limited to 'lib/std')
39 files changed, 293 insertions, 319 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index a85219a458..ad82e4beef 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -68,7 +68,7 @@ else switch (std.Target.current.os.tag) { }; /// Signals the processor that it is inside a busy-wait spin-loop ("spin lock"). -pub fn spinLoopHint() callconv(.Inline) void { +pub inline fn spinLoopHint() void { switch (std.Target.current.cpu.arch) { .i386, .x86_64 => { asm volatile ("pause" ::: "memory"); diff --git a/lib/std/bit_set.zig b/lib/std/bit_set.zig index e6a99ce250..7187b564d2 100644 --- a/lib/std/bit_set.zig +++ b/lib/std/bit_set.zig @@ -83,7 +83,7 @@ pub fn IntegerBitSet(comptime size: u16) type { } /// Returns the number of bits in this bit set - pub fn capacity(self: Self) callconv(.Inline) usize { + pub inline fn capacity(self: Self) usize { return bit_length; } @@ -310,7 +310,7 @@ pub fn ArrayBitSet(comptime MaskIntType: type, comptime size: usize) type { } /// Returns the number of bits in this bit set - pub fn capacity(self: Self) callconv(.Inline) usize { + pub inline fn capacity(self: Self) usize { return bit_length; } @@ -574,7 +574,7 @@ pub const DynamicBitSetUnmanaged = struct { } /// Returns the number of bits in this bit set - pub fn capacity(self: Self) callconv(.Inline) usize { + pub inline fn capacity(self: Self) usize { return self.bit_length; } @@ -789,7 +789,7 @@ pub const DynamicBitSet = struct { } /// Returns the number of bits in this bit set - pub fn capacity(self: Self) callconv(.Inline) usize { + pub inline fn capacity(self: Self) usize { return self.unmanaged.capacity(); } @@ -969,7 +969,7 @@ fn BitSetIterator(comptime MaskInt: type, comptime options: IteratorOptions) typ // isn't a next word. If the next word is the // last word, mask off the padding bits so we // don't visit them. - fn nextWord(self: *Self, comptime is_first_word: bool) callconv(.Inline) void { + inline fn nextWord(self: *Self, comptime is_first_word: bool) void { var word = switch (direction) { .forward => self.words_remain[0], .reverse => self.words_remain[self.words_remain.len - 1], diff --git a/lib/std/c/builtins.zig b/lib/std/c/builtins.zig index 99721a150c..d8a23ec8f1 100644 --- a/lib/std/c/builtins.zig +++ b/lib/std/c/builtins.zig @@ -6,136 +6,136 @@ const std = @import("std"); -pub fn __builtin_bswap16(val: u16) callconv(.Inline) u16 { +pub inline fn __builtin_bswap16(val: u16) u16 { return @byteSwap(u16, val); } -pub fn __builtin_bswap32(val: u32) callconv(.Inline) u32 { +pub inline fn __builtin_bswap32(val: u32) u32 { return @byteSwap(u32, val); } -pub fn __builtin_bswap64(val: u64) callconv(.Inline) u64 { +pub inline fn __builtin_bswap64(val: u64) u64 { return @byteSwap(u64, val); } -pub fn __builtin_signbit(val: f64) callconv(.Inline) c_int { +pub inline fn __builtin_signbit(val: f64) c_int { return @boolToInt(std.math.signbit(val)); } -pub fn __builtin_signbitf(val: f32) callconv(.Inline) c_int { +pub inline fn __builtin_signbitf(val: f32) c_int { return @boolToInt(std.math.signbit(val)); } -pub fn __builtin_popcount(val: c_uint) callconv(.Inline) c_int { +pub inline fn __builtin_popcount(val: c_uint) c_int { // popcount of a c_uint will never exceed the capacity of a c_int @setRuntimeSafety(false); return @bitCast(c_int, @as(c_uint, @popCount(c_uint, val))); } -pub fn __builtin_ctz(val: c_uint) callconv(.Inline) c_int { +pub inline fn __builtin_ctz(val: c_uint) c_int { // Returns the number of trailing 0-bits in val, starting at the least significant bit position. // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint @setRuntimeSafety(false); return @bitCast(c_int, @as(c_uint, @ctz(c_uint, val))); } -pub fn __builtin_clz(val: c_uint) callconv(.Inline) c_int { +pub inline fn __builtin_clz(val: c_uint) c_int { // Returns the number of leading 0-bits in x, starting at the most significant bit position. // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint @setRuntimeSafety(false); return @bitCast(c_int, @as(c_uint, @clz(c_uint, val))); } -pub fn __builtin_sqrt(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_sqrt(val: f64) f64 { return @sqrt(val); } -pub fn __builtin_sqrtf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_sqrtf(val: f32) f32 { return @sqrt(val); } -pub fn __builtin_sin(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_sin(val: f64) f64 { return @sin(val); } -pub fn __builtin_sinf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_sinf(val: f32) f32 { return @sin(val); } -pub fn __builtin_cos(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_cos(val: f64) f64 { return @cos(val); } -pub fn __builtin_cosf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_cosf(val: f32) f32 { return @cos(val); } -pub fn __builtin_exp(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_exp(val: f64) f64 { return @exp(val); } -pub fn __builtin_expf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_expf(val: f32) f32 { return @exp(val); } -pub fn __builtin_exp2(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_exp2(val: f64) f64 { return @exp2(val); } -pub fn __builtin_exp2f(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_exp2f(val: f32) f32 { return @exp2(val); } -pub fn __builtin_log(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_log(val: f64) f64 { return @log(val); } -pub fn __builtin_logf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_logf(val: f32) f32 { return @log(val); } -pub fn __builtin_log2(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_log2(val: f64) f64 { return @log2(val); } -pub fn __builtin_log2f(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_log2f(val: f32) f32 { return @log2(val); } -pub fn __builtin_log10(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_log10(val: f64) f64 { return @log10(val); } -pub fn __builtin_log10f(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_log10f(val: f32) f32 { return @log10(val); } // Standard C Library bug: The absolute value of the most negative integer remains negative. -pub fn __builtin_abs(val: c_int) callconv(.Inline) c_int { +pub inline fn __builtin_abs(val: c_int) c_int { return std.math.absInt(val) catch std.math.minInt(c_int); } -pub fn __builtin_fabs(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_fabs(val: f64) f64 { return @fabs(val); } -pub fn __builtin_fabsf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_fabsf(val: f32) f32 { return @fabs(val); } -pub fn __builtin_floor(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_floor(val: f64) f64 { return @floor(val); } -pub fn __builtin_floorf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_floorf(val: f32) f32 { return @floor(val); } -pub fn __builtin_ceil(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_ceil(val: f64) f64 { return @ceil(val); } -pub fn __builtin_ceilf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_ceilf(val: f32) f32 { return @ceil(val); } -pub fn __builtin_trunc(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_trunc(val: f64) f64 { return @trunc(val); } -pub fn __builtin_truncf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_truncf(val: f32) f32 { return @trunc(val); } -pub fn __builtin_round(val: f64) callconv(.Inline) f64 { +pub inline fn __builtin_round(val: f64) f64 { return @round(val); } -pub fn __builtin_roundf(val: f32) callconv(.Inline) f32 { +pub inline fn __builtin_roundf(val: f32) f32 { return @round(val); } -pub fn __builtin_strlen(s: [*c]const u8) callconv(.Inline) usize { +pub inline fn __builtin_strlen(s: [*c]const u8) usize { return std.mem.lenZ(s); } -pub fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) callconv(.Inline) c_int { +pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int { return @as(c_int, std.cstr.cmp(s1, s2)); } -pub fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) callconv(.Inline) usize { +pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize { // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html // If it is not possible to determine which objects ptr points to at compile time, // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0 @@ -145,37 +145,37 @@ pub fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) callconv(.Inline) u unreachable; } -pub fn __builtin___memset_chk( +pub inline fn __builtin___memset_chk( dst: ?*c_void, val: c_int, len: usize, remaining: usize, -) callconv(.Inline) ?*c_void { +) ?*c_void { if (len > remaining) @panic("std.c.builtins.memset_chk called with len > remaining"); return __builtin_memset(dst, val, len); } -pub fn __builtin_memset(dst: ?*c_void, val: c_int, len: usize) callconv(.Inline) ?*c_void { +pub inline fn __builtin_memset(dst: ?*c_void, val: c_int, len: usize) ?*c_void { const dst_cast = @ptrCast([*c]u8, dst); @memset(dst_cast, @bitCast(u8, @truncate(i8, val)), len); return dst; } -pub fn __builtin___memcpy_chk( +pub inline fn __builtin___memcpy_chk( noalias dst: ?*c_void, noalias src: ?*const c_void, len: usize, remaining: usize, -) callconv(.Inline) ?*c_void { +) ?*c_void { if (len > remaining) @panic("std.c.builtins.memcpy_chk called with len > remaining"); return __builtin_memcpy(dst, src, len); } -pub fn __builtin_memcpy( +pub inline fn __builtin_memcpy( noalias dst: ?*c_void, noalias src: ?*const c_void, len: usize, -) callconv(.Inline) ?*c_void { +) ?*c_void { const dst_cast = @ptrCast([*c]u8, dst); const src_cast = @ptrCast([*c]const u8, src); @@ -185,7 +185,7 @@ pub fn __builtin_memcpy( /// The return value of __builtin_expect is `expr`. `c` is the expected value /// of `expr` and is used as a hint to the compiler in C. Here it is unused. -pub fn __builtin_expect(expr: c_long, c: c_long) callconv(.Inline) c_long { +pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long { return expr; } diff --git a/lib/std/compress/deflate.zig b/lib/std/compress/deflate.zig index 45ffb64b4f..d7209981ce 100644 --- a/lib/std/compress/deflate.zig +++ b/lib/std/compress/deflate.zig @@ -209,7 +209,7 @@ pub fn InflateStream(comptime ReaderType: type) type { // Insert a single byte into the window. // Assumes there's enough space. - fn appendUnsafe(self: *WSelf, value: u8) callconv(.Inline) void { + inline fn appendUnsafe(self: *WSelf, value: u8) void { self.buf[self.wi] = value; self.wi = (self.wi + 1) & (self.buf.len - 1); self.el += 1; diff --git a/lib/std/crypto/25519/curve25519.zig b/lib/std/crypto/25519/curve25519.zig index 7edebf4445..9b8cecb917 100644 --- a/lib/std/crypto/25519/curve25519.zig +++ b/lib/std/crypto/25519/curve25519.zig @@ -20,12 +20,12 @@ pub const Curve25519 = struct { x: Fe, /// Decode a Curve25519 point from its compressed (X) coordinates. - pub fn fromBytes(s: [32]u8) callconv(.Inline) Curve25519 { + pub inline fn fromBytes(s: [32]u8) Curve25519 { return .{ .x = Fe.fromBytes(s) }; } /// Encode a Curve25519 point. - pub fn toBytes(p: Curve25519) callconv(.Inline) [32]u8 { + pub inline fn toBytes(p: Curve25519) [32]u8 { return p.x.toBytes(); } diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig index 95e71fd6ad..fd0c2e1ab8 100644 --- a/lib/std/crypto/25519/edwards25519.zig +++ b/lib/std/crypto/25519/edwards25519.zig @@ -91,7 +91,7 @@ pub const Edwards25519 = struct { } /// Flip the sign of the X coordinate. - pub fn neg(p: Edwards25519) callconv(.Inline) Edwards25519 { + pub inline fn neg(p: Edwards25519) Edwards25519 { return .{ .x = p.x.neg(), .y = p.y, .z = p.z, .t = p.t.neg() }; } @@ -136,14 +136,14 @@ pub const Edwards25519 = struct { return p.add(q.neg()); } - fn cMov(p: *Edwards25519, a: Edwards25519, c: u64) callconv(.Inline) void { + inline fn cMov(p: *Edwards25519, a: Edwards25519, c: u64) void { p.x.cMov(a.x, c); p.y.cMov(a.y, c); p.z.cMov(a.z, c); p.t.cMov(a.t, c); } - fn pcSelect(comptime n: usize, pc: [n]Edwards25519, b: u8) callconv(.Inline) Edwards25519 { + inline fn pcSelect(comptime n: usize, pc: [n]Edwards25519, b: u8) Edwards25519 { var t = Edwards25519.identityElement; comptime var i: u8 = 1; inline while (i < pc.len) : (i += 1) { diff --git a/lib/std/crypto/25519/field.zig b/lib/std/crypto/25519/field.zig index 3378191451..33ee36b816 100644 --- a/lib/std/crypto/25519/field.zig +++ b/lib/std/crypto/25519/field.zig @@ -56,7 +56,7 @@ pub const Fe = struct { pub const edwards25519sqrtam2 = Fe{ .limbs = .{ 1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600 } }; /// Return true if the field element is zero - pub fn isZero(fe: Fe) callconv(.Inline) bool { + pub inline fn isZero(fe: Fe) bool { var reduced = fe; reduced.reduce(); const limbs = reduced.limbs; @@ -64,7 +64,7 @@ pub const Fe = struct { } /// Return true if both field elements are equivalent - pub fn equivalent(a: Fe, b: Fe) callconv(.Inline) bool { + pub inline fn equivalent(a: Fe, b: Fe) bool { return a.sub(b).isZero(); } @@ -168,7 +168,7 @@ pub const Fe = struct { } /// Add a field element - pub fn add(a: Fe, b: Fe) callconv(.Inline) Fe { + pub inline fn add(a: Fe, b: Fe) Fe { var fe: Fe = undefined; comptime var i = 0; inline while (i < 5) : (i += 1) { @@ -178,7 +178,7 @@ pub const Fe = struct { } /// Substract a field elememnt - pub fn sub(a: Fe, b: Fe) callconv(.Inline) Fe { + pub inline fn sub(a: Fe, b: Fe) Fe { var fe = b; comptime var i = 0; inline while (i < 4) : (i += 1) { @@ -197,17 +197,17 @@ pub const Fe = struct { } /// Negate a field element - pub fn neg(a: Fe) callconv(.Inline) Fe { + pub inline fn neg(a: Fe) Fe { return zero.sub(a); } /// Return true if a field element is negative - pub fn isNegative(a: Fe) callconv(.Inline) bool { + pub inline fn isNegative(a: Fe) bool { return (a.toBytes()[0] & 1) != 0; } /// Conditonally replace a field element with `a` if `c` is positive - pub fn cMov(fe: *Fe, a: Fe, c: u64) callconv(.Inline) void { + pub inline fn cMov(fe: *Fe, a: Fe, c: u64) void { const mask: u64 = 0 -% c; var x = fe.*; comptime var i = 0; @@ -248,7 +248,7 @@ pub const Fe = struct { } } - fn _carry128(r: *[5]u128) callconv(.Inline) Fe { + inline fn _carry128(r: *[5]u128) Fe { var rs: [5]u64 = undefined; comptime var i = 0; inline while (i < 4) : (i += 1) { @@ -269,7 +269,7 @@ pub const Fe = struct { } /// Multiply two field elements - pub fn mul(a: Fe, b: Fe) callconv(.Inline) Fe { + pub inline fn mul(a: Fe, b: Fe) Fe { var ax: [5]u128 = undefined; var bx: [5]u128 = undefined; var a19: [5]u128 = undefined; @@ -292,7 +292,7 @@ pub const Fe = struct { return _carry128(&r); } - fn _sq(a: Fe, comptime double: bool) callconv(.Inline) Fe { + inline fn _sq(a: Fe, comptime double: bool) Fe { var ax: [5]u128 = undefined; var r: [5]u128 = undefined; comptime var i = 0; @@ -321,17 +321,17 @@ pub const Fe = struct { } /// Square a field element - pub fn sq(a: Fe) callconv(.Inline) Fe { + pub inline fn sq(a: Fe) Fe { return _sq(a, false); } /// Square and double a field element - pub fn sq2(a: Fe) callconv(.Inline) Fe { + pub inline fn sq2(a: Fe) Fe { return _sq(a, true); } /// Multiply a field element with a small (32-bit) integer - pub fn mul32(a: Fe, comptime n: u32) callconv(.Inline) Fe { + pub inline fn mul32(a: Fe, comptime n: u32) Fe { const sn = @intCast(u128, n); var fe: Fe = undefined; var x: u128 = 0; @@ -346,7 +346,7 @@ pub const Fe = struct { } /// Square a field element `n` times - fn sqn(a: Fe, comptime n: comptime_int) callconv(.Inline) Fe { + inline fn sqn(a: Fe, comptime n: comptime_int) Fe { var i: usize = 0; var fe = a; while (i < n) : (i += 1) { diff --git a/lib/std/crypto/25519/ristretto255.zig b/lib/std/crypto/25519/ristretto255.zig index c17461e40a..dea6193fca 100644 --- a/lib/std/crypto/25519/ristretto255.zig +++ b/lib/std/crypto/25519/ristretto255.zig @@ -47,7 +47,7 @@ pub const Ristretto255 = struct { } /// Reject the neutral element. - pub fn rejectIdentity(p: Ristretto255) callconv(.Inline) IdentityElementError!void { + pub inline fn rejectIdentity(p: Ristretto255) IdentityElementError!void { return p.p.rejectIdentity(); } @@ -146,19 +146,19 @@ pub const Ristretto255 = struct { } /// Double a Ristretto255 element. - pub fn dbl(p: Ristretto255) callconv(.Inline) Ristretto255 { + pub inline fn dbl(p: Ristretto255) Ristretto255 { return .{ .p = p.p.dbl() }; } /// Add two Ristretto255 elements. - pub fn add(p: Ristretto255, q: Ristretto255) callconv(.Inline) Ristretto255 { + pub inline fn add(p: Ristretto255, q: Ristretto255) Ristretto255 { return .{ .p = p.p.add(q.p) }; } /// Multiply a Ristretto255 element with a scalar. /// Return error.WeakPublicKey if the resulting element is /// the identity element. - pub fn mul(p: Ristretto255, s: [encoded_length]u8) callconv(.Inline) (IdentityElementError || WeakPublicKeyError)!Ristretto255 { + pub inline fn mul(p: Ristretto255, s: [encoded_length]u8) (IdentityElementError || WeakPublicKeyError)!Ristretto255 { return Ristretto255{ .p = try p.p.mul(s) }; } diff --git a/lib/std/crypto/25519/scalar.zig b/lib/std/crypto/25519/scalar.zig index e89c6d6f2a..46ab2017ca 100644 --- a/lib/std/crypto/25519/scalar.zig +++ b/lib/std/crypto/25519/scalar.zig @@ -48,7 +48,7 @@ pub fn reduce64(s: [64]u8) [32]u8 { /// Perform the X25519 "clamping" operation. /// The scalar is then guaranteed to be a multiple of the cofactor. -pub fn clamp(s: *[32]u8) callconv(.Inline) void { +pub inline fn clamp(s: *[32]u8) void { s[0] &= 248; s[31] = (s[31] & 127) | 64; } diff --git a/lib/std/crypto/aegis.zig b/lib/std/crypto/aegis.zig index a9418c6ca6..194b6de8f5 100644 --- a/lib/std/crypto/aegis.zig +++ b/lib/std/crypto/aegis.zig @@ -36,7 +36,7 @@ const State128L = struct { return state; } - fn update(state: *State128L, d1: AesBlock, d2: AesBlock) callconv(.Inline) void { + inline fn update(state: *State128L, d1: AesBlock, d2: AesBlock) void { const blocks = &state.blocks; const tmp = blocks[7]; comptime var i: usize = 7; @@ -208,7 +208,7 @@ const State256 = struct { return state; } - fn update(state: *State256, d: AesBlock) callconv(.Inline) void { + inline fn update(state: *State256, d: AesBlock) void { const blocks = &state.blocks; const tmp = blocks[5].encrypt(blocks[0]); comptime var i: usize = 5; diff --git a/lib/std/crypto/aes/aesni.zig b/lib/std/crypto/aes/aesni.zig index 1d719af9c7..7fbbaac7e8 100644 --- a/lib/std/crypto/aes/aesni.zig +++ b/lib/std/crypto/aes/aesni.zig @@ -19,24 +19,24 @@ pub const Block = struct { repr: BlockVec, /// Convert a byte sequence into an internal representation. - pub fn fromBytes(bytes: *const [16]u8) callconv(.Inline) Block { + pub inline fn fromBytes(bytes: *const [16]u8) Block { const repr = mem.bytesToValue(BlockVec, bytes); return Block{ .repr = repr }; } /// Convert the internal representation of a block into a byte sequence. - pub fn toBytes(block: Block) callconv(.Inline) [16]u8 { + pub inline fn toBytes(block: Block) [16]u8 { return mem.toBytes(block.repr); } /// XOR the block with a byte sequence. - pub fn xorBytes(block: Block, bytes: *const [16]u8) callconv(.Inline) [16]u8 { + pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 { const x = block.repr ^ fromBytes(bytes).repr; return mem.toBytes(x); } /// Encrypt a block with a round key. - pub fn encrypt(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encrypt(block: Block, round_key: Block) Block { return Block{ .repr = asm ( \\ vaesenc %[rk], %[in], %[out] @@ -48,7 +48,7 @@ pub const Block = struct { } /// Encrypt a block with the last round key. - pub fn encryptLast(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encryptLast(block: Block, round_key: Block) Block { return Block{ .repr = asm ( \\ vaesenclast %[rk], %[in], %[out] @@ -60,7 +60,7 @@ pub const Block = struct { } /// Decrypt a block with a round key. - pub fn decrypt(block: Block, inv_round_key: Block) callconv(.Inline) Block { + pub inline fn decrypt(block: Block, inv_round_key: Block) Block { return Block{ .repr = asm ( \\ vaesdec %[rk], %[in], %[out] @@ -72,7 +72,7 @@ pub const Block = struct { } /// Decrypt a block with the last round key. - pub fn decryptLast(block: Block, inv_round_key: Block) callconv(.Inline) Block { + pub inline fn decryptLast(block: Block, inv_round_key: Block) Block { return Block{ .repr = asm ( \\ vaesdeclast %[rk], %[in], %[out] @@ -84,17 +84,17 @@ pub const Block = struct { } /// Apply the bitwise XOR operation to the content of two blocks. - pub fn xorBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn xorBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr ^ block2.repr }; } /// Apply the bitwise AND operation to the content of two blocks. - pub fn andBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn andBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr & block2.repr }; } /// Apply the bitwise OR operation to the content of two blocks. - pub fn orBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn orBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr | block2.repr }; } @@ -114,7 +114,7 @@ pub const Block = struct { }; /// Encrypt multiple blocks in parallel, each their own round key. - pub fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) callconv(.Inline) [count]Block { + pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -124,7 +124,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel, each their own round key. - pub fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) callconv(.Inline) [count]Block { + pub inline fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -134,7 +134,7 @@ pub const Block = struct { } /// Encrypt multiple blocks in parallel with the same round key. - pub fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -144,7 +144,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel with the same round key. - pub fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -154,7 +154,7 @@ pub const Block = struct { } /// Encrypt multiple blocks in parallel with the same last round key. - pub fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -164,7 +164,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel with the same last round key. - pub fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { diff --git a/lib/std/crypto/aes/armcrypto.zig b/lib/std/crypto/aes/armcrypto.zig index 85578fcad9..4d16b2f680 100644 --- a/lib/std/crypto/aes/armcrypto.zig +++ b/lib/std/crypto/aes/armcrypto.zig @@ -19,18 +19,18 @@ pub const Block = struct { repr: BlockVec, /// Convert a byte sequence into an internal representation. - pub fn fromBytes(bytes: *const [16]u8) callconv(.Inline) Block { + pub inline fn fromBytes(bytes: *const [16]u8) Block { const repr = mem.bytesToValue(BlockVec, bytes); return Block{ .repr = repr }; } /// Convert the internal representation of a block into a byte sequence. - pub fn toBytes(block: Block) callconv(.Inline) [16]u8 { + pub inline fn toBytes(block: Block) [16]u8 { return mem.toBytes(block.repr); } /// XOR the block with a byte sequence. - pub fn xorBytes(block: Block, bytes: *const [16]u8) callconv(.Inline) [16]u8 { + pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 { const x = block.repr ^ fromBytes(bytes).repr; return mem.toBytes(x); } @@ -38,7 +38,7 @@ pub const Block = struct { const zero = Vector(2, u64){ 0, 0 }; /// Encrypt a block with a round key. - pub fn encrypt(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encrypt(block: Block, round_key: Block) Block { return Block{ .repr = asm ( \\ mov %[out].16b, %[in].16b @@ -54,7 +54,7 @@ pub const Block = struct { } /// Encrypt a block with the last round key. - pub fn encryptLast(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encryptLast(block: Block, round_key: Block) Block { return Block{ .repr = asm ( \\ mov %[out].16b, %[in].16b @@ -69,7 +69,7 @@ pub const Block = struct { } /// Decrypt a block with a round key. - pub fn decrypt(block: Block, inv_round_key: Block) callconv(.Inline) Block { + pub inline fn decrypt(block: Block, inv_round_key: Block) Block { return Block{ .repr = asm ( \\ mov %[out].16b, %[in].16b @@ -85,7 +85,7 @@ pub const Block = struct { } /// Decrypt a block with the last round key. - pub fn decryptLast(block: Block, inv_round_key: Block) callconv(.Inline) Block { + pub inline fn decryptLast(block: Block, inv_round_key: Block) Block { return Block{ .repr = asm ( \\ mov %[out].16b, %[in].16b @@ -100,17 +100,17 @@ pub const Block = struct { } /// Apply the bitwise XOR operation to the content of two blocks. - pub fn xorBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn xorBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr ^ block2.repr }; } /// Apply the bitwise AND operation to the content of two blocks. - pub fn andBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn andBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr & block2.repr }; } /// Apply the bitwise OR operation to the content of two blocks. - pub fn orBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn orBlocks(block1: Block, block2: Block) Block { return Block{ .repr = block1.repr | block2.repr }; } @@ -120,7 +120,7 @@ pub const Block = struct { pub const optimal_parallel_blocks = 8; /// Encrypt multiple blocks in parallel, each their own round key. - pub fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) callconv(.Inline) [count]Block { + pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -130,7 +130,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel, each their own round key. - pub fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) callconv(.Inline) [count]Block { + pub inline fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -140,7 +140,7 @@ pub const Block = struct { } /// Encrypt multiple blocks in parallel with the same round key. - pub fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -150,7 +150,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel with the same round key. - pub fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -160,7 +160,7 @@ pub const Block = struct { } /// Encrypt multiple blocks in parallel with the same last round key. - pub fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { @@ -170,7 +170,7 @@ pub const Block = struct { } /// Decrypt multiple blocks in parallel with the same last round key. - pub fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) callconv(.Inline) [count]Block { + pub inline fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block { comptime var i = 0; var out: [count]Block = undefined; inline while (i < count) : (i += 1) { diff --git a/lib/std/crypto/aes/soft.zig b/lib/std/crypto/aes/soft.zig index 6f305b4050..5eda9557ee 100644 --- a/lib/std/crypto/aes/soft.zig +++ b/lib/std/crypto/aes/soft.zig @@ -18,7 +18,7 @@ pub const Block = struct { repr: BlockVec align(16), /// Convert a byte sequence into an internal representation. - pub fn fromBytes(bytes: *const [16]u8) callconv(.Inline) Block { + pub inline fn fromBytes(bytes: *const [16]u8) Block { const s0 = mem.readIntBig(u32, bytes[0..4]); const s1 = mem.readIntBig(u32, bytes[4..8]); const s2 = mem.readIntBig(u32, bytes[8..12]); @@ -27,7 +27,7 @@ pub const Block = struct { } /// Convert the internal representation of a block into a byte sequence. - pub fn toBytes(block: Block) callconv(.Inline) [16]u8 { + pub inline fn toBytes(block: Block) [16]u8 { var bytes: [16]u8 = undefined; mem.writeIntBig(u32, bytes[0..4], block.repr[0]); mem.writeIntBig(u32, bytes[4..8], block.repr[1]); @@ -37,7 +37,7 @@ pub const Block = struct { } /// XOR the block with a byte sequence. - pub fn xorBytes(block: Block, bytes: *const [16]u8) callconv(.Inline) [16]u8 { + pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 { const block_bytes = block.toBytes(); var x: [16]u8 = undefined; comptime var i: usize = 0; @@ -48,7 +48,7 @@ pub const Block = struct { } /// Encrypt a block with a round key. - pub fn encrypt(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encrypt(block: Block, round_key: Block) Block { const src = &block.repr; const s0 = block.repr[0]; @@ -65,7 +65,7 @@ pub const Block = struct { } /// Encrypt a block with the last round key. - pub fn encryptLast(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn encryptLast(block: Block, round_key: Block) Block { const src = &block.repr; const t0 = block.repr[0]; @@ -87,7 +87,7 @@ pub const Block = struct { } /// Decrypt a block with a round key. - pub fn decrypt(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn decrypt(block: Block, round_key: Block) Block { const src = &block.repr; const s0 = block.repr[0]; @@ -104,7 +104,7 @@ pub const Block = struct { } /// Decrypt a block with the last round key. - pub fn decryptLast(block: Block, round_key: Block) callconv(.Inline) Block { + pub inline fn decryptLast(block: Block, round_key: Block) Block { const src = &block.repr; const t0 = block.repr[0]; @@ -126,7 +126,7 @@ pub const Block = struct { } /// Apply the bitwise XOR operation to the content of two blocks. - pub fn xorBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn xorBlocks(block1: Block, block2: Block) Block { var x: BlockVec = undefined; comptime var i = 0; inline while (i < 4) : (i += 1) { @@ -136,7 +136,7 @@ pub const Block = struct { } /// Apply the bitwise AND operation to the content of two blocks. - pub fn andBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn andBlocks(block1: Block, block2: Block) Block { var x: BlockVec = undefined; comptime var i = 0; inline while (i < 4) : (i += 1) { @@ -146,7 +146,7 @@ pub const Block = struct { } /// Apply the bitwise OR operation to the content of two blocks. - pub fn orBlocks(block1: Block, block2: Block) callconv(.Inline) Block { + pub inline fn orBlocks(block1: Block, block2: Block) Block { var x: BlockVec = undefined; comptime var i = 0; inline while (i < 4) : (i += 1) { diff --git a/lib/std/crypto/aes_ocb.zig b/lib/std/crypto/aes_ocb.zig index 6c5ea84ace..48548f942f 100644 --- a/lib/std/crypto/aes_ocb.zig +++ b/lib/std/crypto/aes_ocb.zig @@ -33,7 +33,7 @@ fn AesOcb(comptime Aes: anytype) type { table: [56]Block align(16) = undefined, upto: usize, - fn double(l: Block) callconv(.Inline) Block { + inline fn double(l: Block) Block { const l_ = mem.readIntBig(u128, &l); const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127)); var l2: Block = undefined; @@ -245,7 +245,7 @@ fn AesOcb(comptime Aes: anytype) type { }; } -fn xorBlocks(x: Block, y: Block) callconv(.Inline) Block { +inline fn xorBlocks(x: Block, y: Block) Block { var z: Block = x; for (z) |*v, i| { v.* = x[i] ^ y[i]; @@ -253,7 +253,7 @@ fn xorBlocks(x: Block, y: Block) callconv(.Inline) Block { return z; } -fn xorWith(x: *Block, y: Block) callconv(.Inline) void { +inline fn xorWith(x: *Block, y: Block) void { for (x) |*v, i| { v.* ^= y[i]; } diff --git a/lib/std/crypto/blake3.zig b/lib/std/crypto/blake3.zig index e6b5e42f47..c4ef40de3d 100644 --- a/lib/std/crypto/blake3.zig +++ b/lib/std/crypto/blake3.zig @@ -66,7 +66,7 @@ const CompressVectorized = struct { const Lane = Vector(4, u32); const Rows = [4]Lane; - fn g(comptime even: bool, rows: *Rows, m: Lane) callconv(.Inline) void { + inline fn g(comptime even: bool, rows: *Rows, m: Lane) void { rows[0] +%= rows[1] +% m; rows[3] ^= rows[0]; rows[3] = math.rotr(Lane, rows[3], if (even) 8 else 16); @@ -75,13 +75,13 @@ const CompressVectorized = struct { rows[1] = math.rotr(Lane, rows[1], if (even) 7 else 12); } - fn diagonalize(rows: *Rows) callconv(.Inline) void { + inline fn diagonalize(rows: *Rows) void { rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 3, 0, 1, 2 }); rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 }); rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 1, 2, 3, 0 }); } - fn undiagonalize(rows: *Rows) callconv(.Inline) void { + inline fn undiagonalize(rows: *Rows) void { rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 1, 2, 3, 0 }); rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 }); rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 3, 0, 1, 2 }); diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig index b007d52353..b89a35cbd4 100644 --- a/lib/std/crypto/chacha20.zig +++ b/lib/std/crypto/chacha20.zig @@ -102,7 +102,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type { }; } - fn chacha20Core(x: *BlockVec, input: BlockVec) callconv(.Inline) void { + inline fn chacha20Core(x: *BlockVec, input: BlockVec) void { x.* = input; var r: usize = 0; @@ -147,7 +147,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type { } } - fn hashToBytes(out: *[64]u8, x: BlockVec) callconv(.Inline) void { + inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { var i: usize = 0; while (i < 4) : (i += 1) { mem.writeIntLittle(u32, out[16 * i + 0 ..][0..4], x[i][0]); @@ -157,7 +157,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize) type { } } - fn contextFeedback(x: *BlockVec, ctx: BlockVec) callconv(.Inline) void { + inline fn contextFeedback(x: *BlockVec, ctx: BlockVec) void { x[0] +%= ctx[0]; x[1] +%= ctx[1]; x[2] +%= ctx[2]; @@ -259,7 +259,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { }; } - fn chacha20Core(x: *BlockVec, input: BlockVec) callconv(.Inline) void { + inline fn chacha20Core(x: *BlockVec, input: BlockVec) void { x.* = input; const rounds = comptime [_]QuarterRound{ @@ -288,7 +288,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { } } - fn hashToBytes(out: *[64]u8, x: BlockVec) callconv(.Inline) void { + inline fn hashToBytes(out: *[64]u8, x: BlockVec) void { var i: usize = 0; while (i < 4) : (i += 1) { mem.writeIntLittle(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0]); @@ -298,7 +298,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type { } } - fn contextFeedback(x: *BlockVec, ctx: BlockVec) callconv(.Inline) void { + inline fn contextFeedback(x: *BlockVec, ctx: BlockVec) void { var i: usize = 0; while (i < 16) : (i += 1) { x[i] +%= ctx[i]; diff --git a/lib/std/crypto/ghash.zig b/lib/std/crypto/ghash.zig index 054e9edd94..b9a7e48adc 100644 --- a/lib/std/crypto/ghash.zig +++ b/lib/std/crypto/ghash.zig @@ -95,7 +95,7 @@ pub const Ghash = struct { } } - fn clmul_pclmul(x: u64, y: u64) callconv(.Inline) u64 { + inline fn clmul_pclmul(x: u64, y: u64) u64 { const Vector = std.meta.Vector; const product = asm ( \\ vpclmulqdq $0x00, %[x], %[y], %[out] @@ -106,7 +106,7 @@ pub const Ghash = struct { return product[0]; } - fn clmul_pmull(x: u64, y: u64) callconv(.Inline) u64 { + inline fn clmul_pmull(x: u64, y: u64) u64 { const Vector = std.meta.Vector; const product = asm ( \\ pmull %[out].1q, %[x].1d, %[y].1d diff --git a/lib/std/crypto/gimli.zig b/lib/std/crypto/gimli.zig index 0485769193..b55466e639 100644 --- a/lib/std/crypto/gimli.zig +++ b/lib/std/crypto/gimli.zig @@ -49,7 +49,7 @@ pub const State = struct { return mem.asBytes(&self.data); } - fn endianSwap(self: *Self) callconv(.Inline) void { + inline fn endianSwap(self: *Self) void { for (self.data) |*w| { w.* = mem.littleToNative(u32, w.*); } @@ -117,7 +117,7 @@ pub const State = struct { const Lane = Vector(4, u32); - fn shift(x: Lane, comptime n: comptime_int) callconv(.Inline) Lane { + inline fn shift(x: Lane, comptime n: comptime_int) Lane { return x << @splat(4, @as(u5, n)); } diff --git a/lib/std/crypto/pcurves/p256/p256_64.zig b/lib/std/crypto/pcurves/p256/p256_64.zig index ca04ee961d..e1b1e4aba5 100644 --- a/lib/std/crypto/pcurves/p256/p256_64.zig +++ b/lib/std/crypto/pcurves/p256/p256_64.zig @@ -35,7 +35,7 @@ pub const Limbs = [4]u64; /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0x1] -fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); var t: u64 = undefined; @@ -56,7 +56,7 @@ fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv( /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0x1] -fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); var t: u64 = undefined; @@ -76,7 +76,7 @@ fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0xffffffffffffffff] -fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) callconv(.Inline) void { +inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void { @setRuntimeSafety(mode == .Debug); const x = @as(u128, arg1) * @as(u128, arg2); @@ -94,7 +94,7 @@ fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) callconv(.Inline) void /// arg3: [0x0 ~> 0xffffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] -fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const mask = 0 -% @as(u64, arg1); diff --git a/lib/std/crypto/pcurves/p256/p256_scalar_64.zig b/lib/std/crypto/pcurves/p256/p256_scalar_64.zig index 7e3cc211f5..4b763f8030 100644 --- a/lib/std/crypto/pcurves/p256/p256_scalar_64.zig +++ b/lib/std/crypto/pcurves/p256/p256_scalar_64.zig @@ -35,7 +35,7 @@ pub const Limbs = [4]u64; /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0x1] -fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); var t: u64 = undefined; @@ -56,7 +56,7 @@ fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv( /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0x1] -fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); var t: u64 = undefined; @@ -76,7 +76,7 @@ fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) callconv /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] /// out2: [0x0 ~> 0xffffffffffffffff] -fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) callconv(.Inline) void { +inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void { @setRuntimeSafety(mode == .Debug); const x = @as(u128, arg1) * @as(u128, arg2); @@ -94,7 +94,7 @@ fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) callconv(.Inline) void /// arg3: [0x0 ~> 0xffffffffffffffff] /// Output Bounds: /// out1: [0x0 ~> 0xffffffffffffffff] -fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) callconv(.Inline) void { +inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void { @setRuntimeSafety(mode == .Debug); const mask = 0 -% @as(u64, arg1); diff --git a/lib/std/crypto/salsa20.zig b/lib/std/crypto/salsa20.zig index 8a800c8a40..55e4db13f0 100644 --- a/lib/std/crypto/salsa20.zig +++ b/lib/std/crypto/salsa20.zig @@ -41,7 +41,7 @@ const Salsa20VecImpl = struct { }; } - fn salsa20Core(x: *BlockVec, input: BlockVec, comptime feedback: bool) callconv(.Inline) void { + inline fn salsa20Core(x: *BlockVec, input: BlockVec, comptime feedback: bool) void { const n1n2n3n0 = Lane{ input[3][1], input[3][2], input[3][3], input[3][0] }; const n1n2 = Half{ n1n2n3n0[0], n1n2n3n0[1] }; const n3n0 = Half{ n1n2n3n0[2], n1n2n3n0[3] }; @@ -215,7 +215,7 @@ const Salsa20NonVecImpl = struct { d: u6, }; - fn Rp(a: usize, b: usize, c: usize, d: u6) callconv(.Inline) QuarterRound { + inline fn Rp(a: usize, b: usize, c: usize, d: u6) QuarterRound { return QuarterRound{ .a = a, .b = b, @@ -224,7 +224,7 @@ const Salsa20NonVecImpl = struct { }; } - fn salsa20Core(x: *BlockVec, input: BlockVec, comptime feedback: bool) callconv(.Inline) void { + inline fn salsa20Core(x: *BlockVec, input: BlockVec, comptime feedback: bool) void { const arx_steps = comptime [_]QuarterRound{ Rp(4, 0, 12, 7), Rp(8, 4, 0, 9), Rp(12, 8, 4, 13), Rp(0, 12, 8, 18), Rp(9, 5, 1, 7), Rp(13, 9, 5, 9), Rp(1, 13, 9, 13), Rp(5, 1, 13, 18), diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 97ca6d6369..390a163014 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -721,10 +721,10 @@ pub const Elf32_Rel = extern struct { r_offset: Elf32_Addr, r_info: Elf32_Word, - pub fn r_sym(self: @This()) callconv(.Inline) u24 { + pub inline fn r_sym(self: @This()) u24 { return @truncate(u24, self.r_info >> 8); } - pub fn r_type(self: @This()) callconv(.Inline) u8 { + pub inline fn r_type(self: @This()) u8 { return @truncate(u8, self.r_info & 0xff); } }; @@ -732,10 +732,10 @@ pub const Elf64_Rel = extern struct { r_offset: Elf64_Addr, r_info: Elf64_Xword, - pub fn r_sym(self: @This()) callconv(.Inline) u32 { + pub inline fn r_sym(self: @This()) u32 { return @truncate(u32, self.r_info >> 32); } - pub fn r_type(self: @This()) callconv(.Inline) u32 { + pub inline fn r_type(self: @This()) u32 { return @truncate(u32, self.r_info & 0xffffffff); } }; @@ -744,10 +744,10 @@ pub const Elf32_Rela = extern struct { r_info: Elf32_Word, r_addend: Elf32_Sword, - pub fn r_sym(self: @This()) callconv(.Inline) u24 { + pub inline fn r_sym(self: @This()) u24 { return @truncate(u24, self.r_info >> 8); } - pub fn r_type(self: @This()) callconv(.Inline) u8 { + pub inline fn r_type(self: @This()) u8 { return @truncate(u8, self.r_info & 0xff); } }; @@ -756,10 +756,10 @@ pub const Elf64_Rela = extern struct { r_info: Elf64_Xword, r_addend: Elf64_Sxword, - pub fn r_sym(self: @This()) callconv(.Inline) u32 { + pub inline fn r_sym(self: @This()) u32 { return @truncate(u32, self.r_info >> 32); } - pub fn r_type(self: @This()) callconv(.Inline) u32 { + pub inline fn r_type(self: @This()) u32 { return @truncate(u32, self.r_info & 0xffffffff); } }; diff --git a/lib/std/fmt/parse_float.zig b/lib/std/fmt/parse_float.zig index b4a925f1a4..3173d749b4 100644 --- a/lib/std/fmt/parse_float.zig +++ b/lib/std/fmt/parse_float.zig @@ -52,21 +52,21 @@ const Z96 = struct { d2: u32, // d = s >> 1 - fn shiftRight1(d: *Z96, s: Z96) callconv(.Inline) void { + inline fn shiftRight1(d: *Z96, s: Z96) void { d.d0 = (s.d0 >> 1) | ((s.d1 & 1) << 31); d.d1 = (s.d1 >> 1) | ((s.d2 & 1) << 31); d.d2 = s.d2 >> 1; } // d = s << 1 - fn shiftLeft1(d: *Z96, s: Z96) callconv(.Inline) void { + inline fn shiftLeft1(d: *Z96, s: Z96) void { d.d2 = (s.d2 << 1) | ((s.d1 & (1 << 31)) >> 31); d.d1 = (s.d1 << 1) | ((s.d0 & (1 << 31)) >> 31); d.d0 = s.d0 << 1; } // d += s - fn add(d: *Z96, s: Z96) callconv(.Inline) void { + inline fn add(d: *Z96, s: Z96) void { var w = @as(u64, d.d0) + @as(u64, s.d0); d.d0 = @truncate(u32, w); @@ -80,7 +80,7 @@ const Z96 = struct { } // d -= s - fn sub(d: *Z96, s: Z96) callconv(.Inline) void { + inline fn sub(d: *Z96, s: Z96) void { var w = @as(u64, d.d0) -% @as(u64, s.d0); d.d0 = @truncate(u32, w); diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 7094c09cfd..920a006b8f 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -6,7 +6,7 @@ const std = @import("std"); const builtin = std.builtin; -fn offsetPtr(ptr: [*]const u8, offset: usize) callconv(.Inline) [*]const u8 { +inline fn offsetPtr(ptr: [*]const u8, offset: usize) [*]const u8 { // ptr + offset doesn't work at comptime so we need this instead. return @ptrCast([*]const u8, &ptr[offset]); } diff --git a/lib/std/json.zig b/lib/std/json.zig index 56d379f9f8..811db020ca 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -2014,12 +2014,9 @@ test "parse into struct with duplicate field" { const ballast = try testing.allocator.alloc(u64, 1); defer testing.allocator.free(ballast); - const options_first = ParseOptions{ - .allocator = testing.allocator, - .duplicate_field_behavior = .UseFirst - }; + const options_first = ParseOptions{ .allocator = testing.allocator, .duplicate_field_behavior = .UseFirst }; - const options_last = ParseOptions{ + const options_last = ParseOptions{ .allocator = testing.allocator, .duplicate_field_behavior = .UseLast, }; diff --git a/lib/std/math.zig b/lib/std/math.zig index 6606a55034..4605c46970 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -1334,7 +1334,7 @@ test "math.comptime" { /// Returns a mask of all ones if value is true, /// and a mask of all zeroes if value is false. /// Compiles to one instruction for register sized integers. -pub fn boolMask(comptime MaskInt: type, value: bool) callconv(.Inline) MaskInt { +pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { if (@typeInfo(MaskInt) != .Int) @compileError("boolMask requires an integer mask type."); diff --git a/lib/std/math/complex.zig b/lib/std/math/complex.zig index 614d9d0ae1..7d37fcca5b 100644 --- a/lib/std/math/complex.zig +++ b/lib/std/math/complex.zig @@ -38,7 +38,7 @@ pub fn Complex(comptime T: type) type { /// Imaginary part. im: T, - + /// Deprecated, use init() pub const new = init; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index 98e2898ab0..34ea0256e1 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -823,16 +823,16 @@ pub const sigval = extern union { pub const _SIG_WORDS = 4; pub const _SIG_MAXSIG = 128; -pub fn _SIG_IDX(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_IDX(sig: usize) usize { return sig - 1; } -pub fn _SIG_WORD(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_WORD(sig: usize) usize { return_SIG_IDX(sig) >> 5; } -pub fn _SIG_BIT(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_BIT(sig: usize) usize { return 1 << (_SIG_IDX(sig) & 31); } -pub fn _SIG_VALID(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_VALID(sig: usize) usize { return sig <= _SIG_MAXSIG and sig > 0; } diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index 287a62ebb7..42718d302b 100644 --- a/lib/std/os/bits/haiku.zig +++ b/lib/std/os/bits/haiku.zig @@ -721,16 +721,16 @@ pub const Sigaction = extern struct { pub const _SIG_WORDS = 4; pub const _SIG_MAXSIG = 128; -pub fn _SIG_IDX(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_IDX(sig: usize) usize { return sig - 1; } -pub fn _SIG_WORD(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_WORD(sig: usize) usize { return_SIG_IDX(sig) >> 5; } -pub fn _SIG_BIT(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_BIT(sig: usize) usize { return 1 << (_SIG_IDX(sig) & 31); } -pub fn _SIG_VALID(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_VALID(sig: usize) usize { return sig <= _SIG_MAXSIG and sig > 0; } diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index 06fd3e6ba2..3a3ece3b07 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -804,16 +804,16 @@ pub const _ksiginfo = extern struct { pub const _SIG_WORDS = 4; pub const _SIG_MAXSIG = 128; -pub fn _SIG_IDX(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_IDX(sig: usize) usize { return sig - 1; } -pub fn _SIG_WORD(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_WORD(sig: usize) usize { return_SIG_IDX(sig) >> 5; } -pub fn _SIG_BIT(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_BIT(sig: usize) usize { return 1 << (_SIG_IDX(sig) & 31); } -pub fn _SIG_VALID(sig: usize) callconv(.Inline) usize { +pub inline fn _SIG_VALID(sig: usize) usize { return sig <= _SIG_MAXSIG and sig > 0; } diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index d057b2f7b3..0d6b87c15f 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -145,7 +145,7 @@ pub fn fork() usize { /// It is advised to avoid this function and use clone instead, because /// the compiler is not aware of how vfork affects control flow and you may /// see different results in optimized builds. -pub fn vfork() callconv(.Inline) usize { +pub inline fn vfork() usize { return @call(.{ .modifier = .always_inline }, syscall0, .{.vfork}); } diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 4d5dba3112..502868f9d4 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -307,7 +307,7 @@ fn initTLS() void { }; } -fn alignPtrCast(comptime T: type, ptr: [*]u8) callconv(.Inline) *T { +inline fn alignPtrCast(comptime T: type, ptr: [*]u8) *T { return @ptrCast(*T, @alignCast(@alignOf(T), ptr)); } diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index e02cf4e280..a01d35f210 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1881,7 +1881,7 @@ pub fn wToPrefixedFileW(s: []const u16) !PathSpace { return path_space; } -fn MAKELANGID(p: c_ushort, s: c_ushort) callconv(.Inline) LANGID { +inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID { return (s << 10) | p; } diff --git a/lib/std/start.zig b/lib/std/start.zig index d3bf121c1b..250dea6a7b 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -375,7 +375,7 @@ const bad_main_ret = "expected return type of main to be 'void', '!void', 'noret // This is marked inline because for some reason LLVM in release mode fails to inline it, // and we want fewer call frames in stack traces. -fn initEventLoopAndCallMain() callconv(.Inline) u8 { +inline fn initEventLoopAndCallMain() u8 { if (std.event.Loop.instance) |loop| { if (!@hasDecl(root, "event_loop")) { loop.init() catch |err| { @@ -404,7 +404,7 @@ fn initEventLoopAndCallMain() callconv(.Inline) u8 { // and we want fewer call frames in stack traces. // TODO This function is duplicated from initEventLoopAndCallMain instead of using generics // because it is working around stage1 compiler bugs. -fn initEventLoopAndCallWinMain() callconv(.Inline) std.os.windows.INT { +inline fn initEventLoopAndCallWinMain() std.os.windows.INT { if (std.event.Loop.instance) |loop| { if (!@hasDecl(root, "event_loop")) { loop.init() catch |err| { diff --git a/lib/std/target/spirv.zig b/lib/std/target/spirv.zig index 690501f731..7d2dc7fd6d 100644 --- a/lib/std/target/spirv.zig +++ b/lib/std/target/spirv.zig @@ -732,8 +732,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.Matrix)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Matrix", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Shader)] = .{ .llvm_name = null, @@ -759,20 +758,17 @@ pub const all_features = blk: { result[@enumToInt(Feature.Addresses)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Addresses", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Linkage)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Linkage", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Kernel)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Kernel", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Vector16)] = .{ .llvm_name = null, @@ -791,20 +787,17 @@ pub const all_features = blk: { result[@enumToInt(Feature.Float16)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Float16", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Float64)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Float64", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Int64)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Int64", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Int64Atomics)] = .{ .llvm_name = null, @@ -844,8 +837,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.Groups)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Groups", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.DeviceEnqueue)] = .{ .llvm_name = null, @@ -871,8 +863,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.Int16)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Int16", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.TessellationPointSize)] = .{ .llvm_name = null, @@ -982,8 +973,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.Int8)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Int8", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.InputAttachment)] = .{ .llvm_name = null, @@ -1009,8 +999,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.Sampled1D)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability Sampled1D", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.Image1D)] = .{ .llvm_name = null, @@ -1029,8 +1018,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.SampledBuffer)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SampledBuffer", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.ImageBuffer)] = .{ .llvm_name = null, @@ -1220,8 +1208,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.SubgroupBallotKHR)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupBallotKHR", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.DrawParameters)] = .{ .llvm_name = null, @@ -1255,8 +1242,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.SubgroupVoteKHR)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupVoteKHR", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.StorageBuffer16BitAccess)] = .{ .llvm_name = null, @@ -1338,14 +1324,12 @@ pub const all_features = blk: { result[@enumToInt(Feature.AtomicStorageOps)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability AtomicStorageOps", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SampleMaskPostDepthCoverage)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SampleMaskPostDepthCoverage", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.StorageBuffer8BitAccess)] = .{ .llvm_name = null, @@ -1548,20 +1532,17 @@ pub const all_features = blk: { result[@enumToInt(Feature.ImageFootprintNV)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability ImageFootprintNV", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FragmentBarycentricNV)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FragmentBarycentricNV", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.ComputeDerivativeGroupQuadsNV)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability ComputeDerivativeGroupQuadsNV", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FragmentDensityEXT)] = .{ .llvm_name = null, @@ -1580,8 +1561,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.GroupNonUniformPartitionedNV)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability GroupNonUniformPartitionedNV", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.ShaderNonUniform)] = .{ .llvm_name = null, @@ -1835,8 +1815,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.ComputeDerivativeGroupLinearNV)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability ComputeDerivativeGroupLinearNV", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.RayTracingProvisionalKHR)] = .{ .llvm_name = null, @@ -1890,38 +1869,32 @@ pub const all_features = blk: { result[@enumToInt(Feature.SubgroupShuffleINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupShuffleINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupBufferBlockIOINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupBufferBlockIOINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupImageBlockIOINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupImageBlockIOINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupImageMediaBlockIOINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupImageMediaBlockIOINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.RoundToInfinityINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability RoundToInfinityINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FloatingPointModeINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FloatingPointModeINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.IntegerFunctions2INTEL)] = .{ .llvm_name = null, @@ -1933,38 +1906,32 @@ pub const all_features = blk: { result[@enumToInt(Feature.FunctionPointersINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FunctionPointersINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.IndirectReferencesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability IndirectReferencesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.AsmINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability AsmINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.AtomicFloat32MinMaxEXT)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability AtomicFloat32MinMaxEXT", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.AtomicFloat64MinMaxEXT)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability AtomicFloat64MinMaxEXT", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.AtomicFloat16MinMaxEXT)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability AtomicFloat16MinMaxEXT", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.VectorComputeINTEL)] = .{ .llvm_name = null, @@ -1976,50 +1943,42 @@ pub const all_features = blk: { result[@enumToInt(Feature.VectorAnyINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability VectorAnyINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.ExpectAssumeKHR)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability ExpectAssumeKHR", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupAvcMotionEstimationINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupAvcMotionEstimationINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupAvcMotionEstimationIntraINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupAvcMotionEstimationIntraINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.SubgroupAvcMotionEstimationChromaINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability SubgroupAvcMotionEstimationChromaINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.VariableLengthArrayINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability VariableLengthArrayINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FunctionFloatControlINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FunctionFloatControlINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGAMemoryAttributesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGAMemoryAttributesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPFastMathModeINTEL)] = .{ .llvm_name = null, @@ -2031,80 +1990,67 @@ pub const all_features = blk: { result[@enumToInt(Feature.ArbitraryPrecisionIntegersINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability ArbitraryPrecisionIntegersINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.UnstructuredLoopControlsINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability UnstructuredLoopControlsINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGALoopControlsINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGALoopControlsINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.KernelAttributesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability KernelAttributesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGAKernelAttributesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGAKernelAttributesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGAMemoryAccessesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGAMemoryAccessesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGAClusterAttributesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGAClusterAttributesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.LoopFuseINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability LoopFuseINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGABufferLocationINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGABufferLocationINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.USMStorageClassesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability USMStorageClassesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.IOPipesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability IOPipesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.BlockingPipesINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability BlockingPipesINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.FPGARegINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability FPGARegINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; result[@enumToInt(Feature.AtomicFloat32AddEXT)] = .{ .llvm_name = null, @@ -2123,8 +2069,7 @@ pub const all_features = blk: { result[@enumToInt(Feature.LongConstantCompositeINTEL)] = .{ .llvm_name = null, .description = "Enable SPIR-V capability LongConstantCompositeINTEL", - .dependencies = featureSet(&[_]Feature{ - }), + .dependencies = featureSet(&[_]Feature{}), }; const ti = @typeInfo(Feature); for (result) |*elem, i| { diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index f55defce81..6ed8987e54 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -459,7 +459,8 @@ pub const Tree = struct { .keyword_extern, .keyword_export, .keyword_pub, - .keyword_threadlocal, + .keyword_inline, + .keyword_noinline, .string_literal, => continue, @@ -1833,7 +1834,7 @@ pub const Tree = struct { var result: full.FnProto = .{ .ast = info, .visib_token = null, - .extern_export_token = null, + .extern_export_inline_token = null, .lib_name = null, .name_token = null, .lparen = undefined, @@ -1842,7 +1843,11 @@ pub const Tree = struct { while (i > 0) { i -= 1; switch (token_tags[i]) { - .keyword_extern, .keyword_export => result.extern_export_token = i, + .keyword_extern, + .keyword_export, + .keyword_inline, + .keyword_noinline, + => result.extern_export_inline_token = i, .keyword_pub => result.visib_token = i, .string_literal => result.lib_name = i, else => break, @@ -2123,7 +2128,7 @@ pub const full = struct { pub const FnProto = struct { visib_token: ?TokenIndex, - extern_export_token: ?TokenIndex, + extern_export_inline_token: ?TokenIndex, lib_name: ?TokenIndex, name_token: ?TokenIndex, lparen: TokenIndex, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index b2ce8df73f..63138ba8ab 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -61,13 +61,33 @@ test "zig fmt: respect line breaks in struct field value declaration" { ); } -// TODO Remove this after zig 0.9.0 is released. -test "zig fmt: rewrite inline functions as callconv(.Inline)" { - try testTransform( +test "zig fmt: respect line breaks before functions" { + try testCanonical( + \\const std = @import("std"); + \\ \\inline fn foo() void {} \\ - , + \\noinline fn foo() void {} + \\ + \\export fn foo() void {} + \\ + \\extern fn foo() void; + \\ + \\extern "foo" fn foo() void; + \\ + ); +} + +test "zig fmt: rewrite callconv(.Inline) to the inline keyword" { + try testTransform( \\fn foo() callconv(.Inline) void {} + \\const bar = .Inline; + \\fn foo() callconv(bar) void {} + \\ + , + \\inline fn foo() void {} + \\const bar = .Inline; + \\fn foo() callconv(bar) void {} \\ ); } @@ -2867,17 +2887,17 @@ test "zig fmt: functions" { \\extern fn puts(s: *const u8) c_int; \\extern "c" fn puts(s: *const u8) c_int; \\export fn puts(s: *const u8) c_int; - \\fn puts(s: *const u8) callconv(.Inline) c_int; + \\inline fn puts(s: *const u8) c_int; \\noinline fn puts(s: *const u8) c_int; \\pub extern fn puts(s: *const u8) c_int; \\pub extern "c" fn puts(s: *const u8) c_int; \\pub export fn puts(s: *const u8) c_int; - \\pub fn puts(s: *const u8) callconv(.Inline) c_int; + \\pub inline fn puts(s: *const u8) c_int; \\pub noinline fn puts(s: *const u8) c_int; \\pub extern fn puts(s: *const u8) align(2 + 2) c_int; \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int; \\pub export fn puts(s: *const u8) align(2 + 2) c_int; - \\pub fn puts(s: *const u8) align(2 + 2) callconv(.Inline) c_int; + \\pub inline fn puts(s: *const u8) align(2 + 2) c_int; \\pub noinline fn puts(s: *const u8) align(2 + 2) c_int; \\ ); diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 237ecf777d..10abbdace9 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -83,13 +83,23 @@ fn renderMember(gpa: *Allocator, ais: *Ais, tree: ast.Tree, decl: ast.Node.Index } } while (i < fn_token) : (i += 1) { - if (token_tags[i] == .keyword_inline) { - // TODO remove this special case when 0.9.0 is released. - // See the commit that introduced this comment for more details. - continue; - } try renderToken(ais, tree, i, .space); } + switch (tree.nodes.items(.tag)[fn_proto]) { + .fn_proto_one, .fn_proto => { + const callconv_expr = if (tree.nodes.items(.tag)[fn_proto] == .fn_proto_one) + tree.extraData(datas[fn_proto].lhs, ast.Node.FnProtoOne).callconv_expr + else + tree.extraData(datas[fn_proto].lhs, ast.Node.FnProto).callconv_expr; + if (callconv_expr != 0 and tree.nodes.items(.tag)[callconv_expr] == .enum_literal) { + if (mem.eql(u8, "Inline", tree.tokenSlice(main_tokens[callconv_expr]))) { + try ais.writer().writeAll("inline "); + } + } + }, + .fn_proto_simple, .fn_proto_multi => {}, + else => unreachable, + } assert(datas[decl].rhs != 0); try renderExpression(gpa, ais, tree, fn_proto, .space); return renderExpression(gpa, ais, tree, datas[decl].rhs, space); @@ -1246,9 +1256,6 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. const token_tags = tree.tokens.items(.tag); const token_starts = tree.tokens.items(.start); - const is_inline = fn_proto.ast.fn_token > 0 and - token_tags[fn_proto.ast.fn_token - 1] == .keyword_inline; - const after_fn_token = fn_proto.ast.fn_token + 1; const lparen = if (token_tags[after_fn_token] == .identifier) blk: { try renderToken(ais, tree, fn_proto.ast.fn_token, .space); // fn @@ -1424,7 +1431,9 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. try renderToken(ais, tree, section_rparen, .space); // ) } - if (fn_proto.ast.callconv_expr != 0) { + if (fn_proto.ast.callconv_expr != 0 and + !mem.eql(u8, "Inline", tree.tokenSlice(tree.nodes.items(.main_token)[fn_proto.ast.callconv_expr]))) + { const callconv_lparen = tree.firstToken(fn_proto.ast.callconv_expr) - 1; const callconv_rparen = tree.lastToken(fn_proto.ast.callconv_expr) + 1; @@ -1432,8 +1441,6 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. try renderToken(ais, tree, callconv_lparen, .none); // ( try renderExpression(gpa, ais, tree, fn_proto.ast.callconv_expr, .none); try renderToken(ais, tree, callconv_rparen, .space); // ) - } else if (is_inline) { - try ais.writer().writeAll("callconv(.Inline) "); } if (token_tags[maybe_bang] == .bang) { diff --git a/lib/std/zig/system/x86.zig b/lib/std/zig/system/x86.zig index 0b645ae8e3..9a33a1daaf 100644 --- a/lib/std/zig/system/x86.zig +++ b/lib/std/zig/system/x86.zig @@ -19,11 +19,11 @@ fn setFeature(cpu: *Target.Cpu, feature: Target.x86.Feature, enabled: bool) void if (enabled) cpu.features.addFeature(idx) else cpu.features.removeFeature(idx); } -fn bit(input: u32, offset: u5) callconv(.Inline) bool { +inline fn bit(input: u32, offset: u5) bool { return (input >> offset) & 1 != 0; } -fn hasMask(input: u32, mask: u32) callconv(.Inline) bool { +inline fn hasMask(input: u32, mask: u32) bool { return (input & mask) == mask; } |
