From 569525f03e17ba32204733108a950a5170662299 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 May 2021 14:51:11 +0200 Subject: [PATCH 1/5] stage1: support inline keyword on function decls This is an alternative to callconv(.Inline). Using an inline keyword as well as an explicit callconv() is a compile error. --- src/stage1/all_types.hpp | 12 +++++++++++- src/stage1/analyze.cpp | 8 +++++++- src/stage1/ast_render.cpp | 11 ++++++++--- src/stage1/parser.cpp | 17 ++++++++++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 9eed42f4cd..88d10e9e6a 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -714,6 +714,12 @@ enum NodeType { NodeTypeAnyTypeField, }; +enum FnInline { + FnInlineAuto, + FnInlineAlways, + FnInlineNever, +}; + struct AstNodeFnProto { Buf *name; ZigList params; @@ -729,12 +735,16 @@ struct AstNodeFnProto { AstNode *callconv_expr; Buf doc_comments; + // This is set based only on the existence of a noinline or inline keyword. + // This is then resolved to an is_noinline bool and (potentially .Inline) + // calling convention in resolve_decl_fn() in analyze.cpp. + FnInline fn_inline; + VisibMod visib_mod; bool auto_err_set; bool is_var_args; bool is_extern; bool is_export; - bool is_noinline; }; struct AstNodeFnDef { diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index a87fd80613..581e34acfc 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -1638,6 +1638,9 @@ CallingConvention cc_from_fn_proto(AstNodeFnProto *fn_proto) { if (fn_proto->is_extern || fn_proto->is_export) return CallingConventionC; + if (fn_proto->fn_inline == FnInlineAlways) + return CallingConventionInline; + return CallingConventionUnspecified; } @@ -3649,7 +3652,7 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node) { assert(proto_node->type == NodeTypeFnProto); AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; - ZigFn *fn_entry = create_fn_raw(g, fn_proto->is_noinline); + ZigFn *fn_entry = create_fn_raw(g, fn_proto->fn_inline == FnInlineNever); fn_entry->proto_node = proto_node; fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr : @@ -3742,6 +3745,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { CallingConvention cc; if (fn_proto->callconv_expr != nullptr) { + if (fn_proto->fn_inline == FnInlineAlways) { + add_node_error(g, fn_proto->callconv_expr, buf_sprintf("explicit callconv incompatible with inline keyword")); + } ZigType *cc_enum_value = get_builtin_type(g, "CallingConvention"); ZigValue *result_val = analyze_const_value(g, child_scope, fn_proto->callconv_expr, diff --git a/src/stage1/ast_render.cpp b/src/stage1/ast_render.cpp index ed53cf7ccb..75ad7267ab 100644 --- a/src/stage1/ast_render.cpp +++ b/src/stage1/ast_render.cpp @@ -123,8 +123,13 @@ static const char *export_string(bool is_export) { // zig_unreachable(); //} -static const char *inline_string(bool is_inline) { - return is_inline ? "inline" : ""; +static const char *inline_string(FnInline fn_inline) { + switch (fn_inline) { + case FnInlineAlways: return "inline "; + case FnInlineNever: return "noinline "; + case FnInlineAuto: return ""; + } + zig_unreachable(); } static const char *const_or_var_string(bool is_const) { @@ -441,7 +446,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod); const char *extern_str = extern_string(node->data.fn_proto.is_extern); const char *export_str = export_string(node->data.fn_proto.is_export); - const char *inline_str = inline_string(node->data.fn_proto.is_noinline); + const char *inline_str = inline_string(node->data.fn_proto.fn_inline); fprintf(ar->f, "%s%s%s%sfn ", pub_str, inline_str, export_str, extern_str); if (node->data.fn_proto.name != nullptr) { print_symbol(ar, node->data.fn_proto.name); diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 08323d3086..19cd977c71 100644 --- a/src/stage1/parser.cpp +++ b/src/stage1/parser.cpp @@ -693,6 +693,8 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B Token *first = eat_token_if(pc, TokenIdKeywordExport); if (first == nullptr) first = eat_token_if(pc, TokenIdKeywordExtern); + if (first == nullptr) + first = eat_token_if(pc, TokenIdKeywordInline); if (first == nullptr) first = eat_token_if(pc, TokenIdKeywordNoInline); if (first != nullptr) { @@ -700,7 +702,7 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B if (first->id == TokenIdKeywordExtern) lib_name = eat_token_if(pc, TokenIdStringLiteral); - if (first->id != TokenIdKeywordNoInline) { + if (first->id != TokenIdKeywordNoInline && first->id != TokenIdKeywordInline) { Token *thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal); AstNode *var_decl = ast_parse_var_decl(pc); if (var_decl != nullptr) { @@ -737,8 +739,17 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B if (!fn_proto->data.fn_proto.is_extern) fn_proto->data.fn_proto.is_extern = first->id == TokenIdKeywordExtern; fn_proto->data.fn_proto.is_export = first->id == TokenIdKeywordExport; - if (first->id == TokenIdKeywordNoInline) - fn_proto->data.fn_proto.is_noinline = true; + switch (first->id) { + case TokenIdKeywordInline: + fn_proto->data.fn_proto.fn_inline = FnInlineAlways; + break; + case TokenIdKeywordNoInline: + fn_proto->data.fn_proto.fn_inline = FnInlineNever; + break; + default: + fn_proto->data.fn_proto.fn_inline = FnInlineAuto; + break; + } fn_proto->data.fn_proto.lib_name = token_buf(lib_name); AstNode *res = fn_proto; From 3fd8ac092e88ac4bc604afcdd3fcb33249dba967 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 May 2021 14:08:57 +0200 Subject: [PATCH 2/5] stage2: support inline keyword on function decls This is an alternative to callconv(.Inline). Using an inline keyword as well as an explicit callconv() is a compile error. --- lib/std/zig/ast.zig | 10 +++++++--- src/AstGen.zig | 46 +++++++++++++++++++++++++++++++-------------- src/Zir.zig | 13 +++++++++++++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index f55defce81..523f171f44 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -1833,7 +1833,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 +1842,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 +2127,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/src/AstGen.zig b/src/AstGen.zig index 8798c98021..547d608625 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -995,7 +995,7 @@ fn fnProtoExpr( const token_tags = tree.tokens.items(.tag); const is_extern = blk: { - const maybe_extern_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_extern_token] == .keyword_extern; }; assert(!is_extern); @@ -2735,15 +2735,20 @@ fn fnDecl( }; defer decl_gz.instructions.deinit(gpa); + // TODO: support noinline const is_pub = fn_proto.visib_token != null; const is_export = blk: { - const maybe_export_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_export_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_export_token] == .keyword_export; }; const is_extern = blk: { - const maybe_extern_token = fn_proto.extern_export_token orelse break :blk false; + const maybe_extern_token = fn_proto.extern_export_inline_token orelse break :blk false; break :blk token_tags[maybe_extern_token] == .keyword_extern; }; + const has_inline_keyword = blk: { + const maybe_inline_token = fn_proto.extern_export_inline_token orelse break :blk false; + break :blk token_tags[maybe_inline_token] == .keyword_inline; + }; const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: { break :inst try expr(&decl_gz, &decl_gz.base, align_rl, fn_proto.ast.align_expr); }; @@ -2812,17 +2817,30 @@ fn fnDecl( fn_proto.ast.return_type, ); - const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0) - try AstGen.expr( - &decl_gz, - &decl_gz.base, - .{ .ty = .calling_convention_type }, - fn_proto.ast.callconv_expr, - ) - else if (is_extern) // note: https://github.com/ziglang/zig/issues/5269 - Zir.Inst.Ref.calling_convention_c - else - Zir.Inst.Ref.none; + const cc: Zir.Inst.Ref = blk: { + if (fn_proto.ast.callconv_expr != 0) { + if (has_inline_keyword) { + return astgen.failNode( + fn_proto.ast.callconv_expr, + "explicit callconv incompatible with inline keyword", + .{}, + ); + } + break :blk try AstGen.expr( + &decl_gz, + &decl_gz.base, + .{ .ty = .calling_convention_type }, + fn_proto.ast.callconv_expr, + ); + } else if (is_extern) { + // note: https://github.com/ziglang/zig/issues/5269 + break :blk .calling_convention_c; + } else if (has_inline_keyword) { + break :blk .calling_convention_inline; + } else { + break :blk .none; + } + }; const func_inst: Zir.Inst.Ref = if (body_node == 0) func: { if (!is_extern) { diff --git a/src/Zir.zig b/src/Zir.zig index 73f8e3e43b..9270325de8 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -1687,6 +1687,8 @@ pub const Inst = struct { one_usize, /// `std.builtin.CallingConvention.C` calling_convention_c, + /// `std.builtin.CallingConvention.Inline` + calling_convention_inline, _, @@ -1954,6 +1956,10 @@ pub const Inst = struct { .ty = Type.initTag(.calling_convention), .val = .{ .ptr_otherwise = &calling_convention_c_payload.base }, }, + .calling_convention_inline = .{ + .ty = Type.initTag(.calling_convention), + .val = .{ .ptr_otherwise = &calling_convention_inline_payload.base }, + }, }); }; @@ -1964,6 +1970,13 @@ pub const Inst = struct { .data = @enumToInt(std.builtin.CallingConvention.C), }; + /// We would like this to be const but `Value` wants a mutable pointer for + /// its payload field. Nothing should mutate this though. + var calling_convention_inline_payload: Value.Payload.U32 = .{ + .base = .{ .tag = .enum_field_index }, + .data = @enumToInt(std.builtin.CallingConvention.Inline), + }; + /// All instructions have an 8-byte payload, which is contained within /// this union. `Tag` determines which union field is active, as well as /// how to interpret the data within. From 4a582734fd84f2096ca9bb559387ddd04c70ed57 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 May 2021 01:31:37 +0200 Subject: [PATCH 3/5] zig fmt: replace callconv(.Inline) with the inline keyword --- lib/std/zig/ast.zig | 3 ++- lib/std/zig/parser_test.zig | 34 +++++++++++++++++++++++++++------- lib/std/zig/render.zig | 29 ++++++++++++++++++----------- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 523f171f44..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, 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) { From 5b850d5c9251900962e52154eb0fb9c2a344476d Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 May 2021 17:07:06 +0200 Subject: [PATCH 4/5] Run `zig fmt` on src/ and lib/std/ This replaces callconv(.Inline) with the more idiomatic inline keyword. --- lib/std/Thread.zig | 2 +- lib/std/bit_set.zig | 10 +- lib/std/c/builtins.zig | 92 +++++----- lib/std/compress/deflate.zig | 2 +- lib/std/crypto/25519/curve25519.zig | 4 +- lib/std/crypto/25519/edwards25519.zig | 6 +- lib/std/crypto/25519/field.zig | 28 +-- lib/std/crypto/25519/ristretto255.zig | 8 +- lib/std/crypto/25519/scalar.zig | 2 +- lib/std/crypto/aegis.zig | 4 +- lib/std/crypto/aes/aesni.zig | 32 ++-- lib/std/crypto/aes/armcrypto.zig | 32 ++-- lib/std/crypto/aes/soft.zig | 20 +-- lib/std/crypto/aes_ocb.zig | 6 +- lib/std/crypto/blake3.zig | 6 +- lib/std/crypto/chacha20.zig | 12 +- lib/std/crypto/ghash.zig | 4 +- lib/std/crypto/gimli.zig | 4 +- lib/std/crypto/pcurves/p256/p256_64.zig | 8 +- .../crypto/pcurves/p256/p256_scalar_64.zig | 8 +- lib/std/crypto/salsa20.zig | 6 +- lib/std/elf.zig | 16 +- lib/std/fmt/parse_float.zig | 8 +- lib/std/hash/cityhash.zig | 2 +- lib/std/json.zig | 7 +- lib/std/math.zig | 2 +- lib/std/math/complex.zig | 2 +- lib/std/os/bits/freebsd.zig | 8 +- lib/std/os/bits/haiku.zig | 8 +- lib/std/os/bits/netbsd.zig | 8 +- lib/std/os/linux.zig | 2 +- lib/std/os/linux/tls.zig | 2 +- lib/std/os/windows.zig | 2 +- lib/std/start.zig | 4 +- lib/std/target/spirv.zig | 165 ++++++------------ lib/std/zig/system/x86.zig | 4 +- src/DepTokenizer.zig | 5 +- src/libc_installation.zig | 3 +- src/link/MachO.zig | 2 +- src/link/MachO/reloc/aarch64.zig | 2 +- src/tracy.zig | 2 +- 41 files changed, 244 insertions(+), 306 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 db261c0ecc..c12b767d56 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1745,7 +1745,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/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; } diff --git a/src/DepTokenizer.zig b/src/DepTokenizer.zig index c8417f2df1..fb28b8e583 100644 --- a/src/DepTokenizer.zig +++ b/src/DepTokenizer.zig @@ -275,10 +275,7 @@ fn errorIllegalChar(comptime id: std.meta.Tag(Token), index: usize, char: u8) To } fn finishTarget(must_resolve: bool, bytes: []const u8) Token { - return if (must_resolve) - .{ .target_must_resolve = bytes } - else - .{ .target = bytes }; + return if (must_resolve) .{ .target_must_resolve = bytes } else .{ .target = bytes }; } const State = enum { diff --git a/src/libc_installation.zig b/src/libc_installation.zig index c681884054..a6826108d4 100644 --- a/src/libc_installation.zig +++ b/src/libc_installation.zig @@ -286,8 +286,7 @@ pub const LibCInstallation = struct { else if (is_haiku) "posix/errno.h" else - "sys/errno.h" - ; + "sys/errno.h"; var path_i: usize = 0; while (path_i < search_paths.items.len) : (path_i += 1) { diff --git a/src/link/MachO.zig b/src/link/MachO.zig index f0f25bea66..5e6d052896 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -2514,7 +2514,7 @@ fn allocatedSizeLinkedit(self: *MachO, start: u64) u64 { return min_pos - start; } -fn checkForCollision(start: u64, end: u64, off: u64, size: u64) callconv(.Inline) ?u64 { +inline fn checkForCollision(start: u64, end: u64, off: u64, size: u64) ?u64 { const increased_size = padToIdeal(size); const test_end = off + increased_size; if (end > off and start < test_end) { diff --git a/src/link/MachO/reloc/aarch64.zig b/src/link/MachO/reloc/aarch64.zig index c08934d84b..c4b3104879 100644 --- a/src/link/MachO/reloc/aarch64.zig +++ b/src/link/MachO/reloc/aarch64.zig @@ -585,7 +585,7 @@ pub const Parser = struct { } }; -fn isArithmeticOp(inst: *const [4]u8) callconv(.Inline) bool { +inline fn isArithmeticOp(inst: *const [4]u8) bool { const group_decode = @truncate(u5, inst[3]); return ((group_decode >> 2) == 4); } diff --git a/src/tracy.zig b/src/tracy.zig index 3f6cf56588..6f56a87ce6 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -31,7 +31,7 @@ pub const Ctx = if (enable) ___tracy_c_zone_context else struct { pub fn end(self: Ctx) void {} }; -pub fn trace(comptime src: std.builtin.SourceLocation) callconv(.Inline) Ctx { +pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx { if (!enable) return .{}; const loc: ___tracy_source_location_data = .{ From 563ea60a86a733f53f2394a11cb9ec4e56063fa3 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 20 May 2021 21:58:39 +0200 Subject: [PATCH 5/5] translate-c: use inline keyword instead of callconv(.Inline) --- src/translate_c/ast.zig | 46 +++++++++++---------------------- test/translate_c.zig | 56 ++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/translate_c/ast.zig b/src/translate_c/ast.zig index 60b1b6f93d..0ea997e177 100644 --- a/src/translate_c/ast.zig +++ b/src/translate_c/ast.zig @@ -2689,6 +2689,7 @@ fn renderFunc(c: *Context, node: Node) !NodeIndex { fn renderMacroFunc(c: *Context, node: Node) !NodeIndex { const payload = node.castTag(.pub_inline_fn).?.data; _ = try c.addToken(.keyword_pub, "pub"); + _ = try c.addToken(.keyword_inline, "inline"); const fn_token = try c.addToken(.keyword_fn, "fn"); _ = try c.addIdentifier(payload.name); @@ -2697,50 +2698,31 @@ fn renderMacroFunc(c: *Context, node: Node) !NodeIndex { var span: NodeSubRange = undefined; if (params.items.len > 1) span = try c.listToSpan(params.items); - const callconv_expr = blk: { - _ = try c.addToken(.keyword_callconv, "callconv"); - _ = try c.addToken(.l_paren, "("); - _ = try c.addToken(.period, "."); - const res = try c.addNode(.{ - .tag = .enum_literal, - .main_token = try c.addToken(.identifier, "Inline"), - .data = undefined, - }); - _ = try c.addToken(.r_paren, ")"); - break :blk res; - }; const return_type_expr = try renderNodeGrouped(c, payload.return_type); - const fn_proto = try blk: { - if (params.items.len < 2) - break :blk c.addNode(.{ - .tag = .fn_proto_one, + const fn_proto = blk: { + if (params.items.len < 2) { + break :blk try c.addNode(.{ + .tag = .fn_proto_simple, .main_token = fn_token, .data = .{ - .lhs = try c.addExtra(std.zig.ast.Node.FnProtoOne{ - .param = params.items[0], - .align_expr = 0, - .section_expr = 0, - .callconv_expr = callconv_expr, - }), + .lhs = params.items[0], .rhs = return_type_expr, }, - }) - else - break :blk c.addNode(.{ - .tag = .fn_proto, + }); + } else { + break :blk try c.addNode(.{ + .tag = .fn_proto_multi, .main_token = fn_token, .data = .{ - .lhs = try c.addExtra(std.zig.ast.Node.FnProto{ - .params_start = span.start, - .params_end = span.end, - .align_expr = 0, - .section_expr = 0, - .callconv_expr = callconv_expr, + .lhs = try c.addExtra(std.zig.ast.Node.SubRange{ + .start = span.start, + .end = span.end, }), .rhs = return_type_expr, }, }); + } }; return c.addNode(.{ .tag = .fn_decl, diff --git a/test/translate_c.zig b/test/translate_c.zig index 2647c712b9..798dab075b 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -232,7 +232,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("use cast param as macro fn return type", \\#define MEM_PHYSICAL_TO_K0(x) (void*)((u32)(x) + SYS_BASE_CACHED) , &[_][]const u8{ - \\pub fn MEM_PHYSICAL_TO_K0(x: anytype) callconv(.Inline) ?*c_void { + \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void { \\ return @import("std").meta.cast(?*c_void, @import("std").meta.cast(u32, x) + SYS_BASE_CACHED); \\} }); @@ -273,7 +273,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub const VALUE = ((((@as(c_int, 1) + (@as(c_int, 2) * @as(c_int, 3))) + (@as(c_int, 4) * @as(c_int, 5))) + @as(c_int, 6)) << @as(c_int, 7)) | @boolToInt(@as(c_int, 8) == @as(c_int, 9)); , - \\pub fn _AL_READ3BYTES(p: anytype) callconv(.Inline) @TypeOf((@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) { + \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) { \\ return (@import("std").meta.cast([*c]u8, p).* | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").meta.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16)); \\} }); @@ -345,7 +345,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\}; \\pub const Color = struct_Color; , - \\pub fn CLITERAL(type_1: anytype) callconv(.Inline) @TypeOf(type_1) { + \\pub inline fn CLITERAL(type_1: anytype) @TypeOf(type_1) { \\ return type_1; \\} , @@ -380,7 +380,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("correct semicolon after infixop", \\#define __ferror_unlocked_body(_fp) (((_fp)->_flags & _IO_ERR_SEEN) != 0) , &[_][]const u8{ - \\pub fn __ferror_unlocked_body(_fp: anytype) callconv(.Inline) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { + \\pub inline fn __ferror_unlocked_body(_fp: anytype) @TypeOf((_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0)) { \\ return (_fp.*._flags & _IO_ERR_SEEN) != @as(c_int, 0); \\} }); @@ -389,7 +389,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define FOO(x) ((x >= 0) + (x >= 0)) \\#define BAR 1 && 2 > 4 , &[_][]const u8{ - \\pub fn FOO(x: anytype) callconv(.Inline) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) { + \\pub inline fn FOO(x: anytype) @TypeOf(@boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0))) { \\ return @boolToInt(x >= @as(c_int, 0)) + @boolToInt(x >= @as(c_int, 0)); \\} , @@ -438,7 +438,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :blk bar; \\}; , - \\pub fn bar(x: anytype) callconv(.Inline) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { + \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { \\ return blk: { \\ _ = &x; \\ _ = @as(c_int, 3); @@ -1782,13 +1782,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub extern var fn_ptr: ?fn () callconv(.C) void; , - \\pub fn foo() callconv(.Inline) void { + \\pub inline fn foo() void { \\ return fn_ptr.?(); \\} , \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8; , - \\pub fn bar(arg_1: c_int, arg_2: f32) callconv(.Inline) u8 { + \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 { \\ return fn_ptr2.?(arg_1, arg_2); \\} }); @@ -1821,7 +1821,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub const glClearPFN = PFNGLCLEARPROC; , - \\pub fn glClearUnion(arg_2: GLbitfield) callconv(.Inline) void { + \\pub inline fn glClearUnion(arg_2: GLbitfield) void { \\ return glProcs.gl.Clear.?(arg_2); \\} , @@ -1842,15 +1842,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub extern var c: c_int; , - \\pub fn BASIC(c_1: anytype) callconv(.Inline) @TypeOf(c_1 * @as(c_int, 2)) { + \\pub inline fn BASIC(c_1: anytype) @TypeOf(c_1 * @as(c_int, 2)) { \\ return c_1 * @as(c_int, 2); \\} , - \\pub fn FOO(L: anytype, b: anytype) callconv(.Inline) @TypeOf(L + b) { + \\pub inline fn FOO(L: anytype, b: anytype) @TypeOf(L + b) { \\ return L + b; \\} , - \\pub fn BAR() callconv(.Inline) @TypeOf(c * c) { + \\pub inline fn BAR() @TypeOf(c * c) { \\ return c * c; \\} }); @@ -2549,7 +2549,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("macro call", \\#define CALL(arg) bar(arg) , &[_][]const u8{ - \\pub fn CALL(arg: anytype) callconv(.Inline) @TypeOf(bar(arg)) { + \\pub inline fn CALL(arg: anytype) @TypeOf(bar(arg)) { \\ return bar(arg); \\} }); @@ -2557,7 +2557,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("macro call with no args", \\#define CALL(arg) bar() , &[_][]const u8{ - \\pub fn CALL(arg: anytype) callconv(.Inline) @TypeOf(bar()) { + \\pub inline fn CALL(arg: anytype) @TypeOf(bar()) { \\ return bar(); \\} }); @@ -3120,7 +3120,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define BAR (void*) a \\#define BAZ (uint32_t)(2) , &[_][]const u8{ - \\pub fn FOO(bar: anytype) callconv(.Inline) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) { + \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) { \\ return baz(@import("std").meta.cast(?*c_void, baz)); \\} , @@ -3160,11 +3160,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define MIN(a, b) ((b) < (a) ? (b) : (a)) \\#define MAX(a, b) ((b) > (a) ? (b) : (a)) , &[_][]const u8{ - \\pub fn MIN(a: anytype, b: anytype) callconv(.Inline) @TypeOf(if (b < a) b else a) { + \\pub inline fn MIN(a: anytype, b: anytype) @TypeOf(if (b < a) b else a) { \\ return if (b < a) b else a; \\} , - \\pub fn MAX(a: anytype, b: anytype) callconv(.Inline) @TypeOf(if (b > a) b else a) { + \\pub inline fn MAX(a: anytype, b: anytype) @TypeOf(if (b > a) b else a) { \\ return if (b > a) b else a; \\} }); @@ -3351,7 +3351,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) \\ , &[_][]const u8{ - \\pub fn DefaultScreen(dpy: anytype) callconv(.Inline) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) { + \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) { \\ return @import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen; \\} }); @@ -3501,17 +3501,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { }); cases.add("global assembly", - \\__asm__(".globl func\n\t" - \\ ".type func, @function\n\t" - \\ "func:\n\t" - \\ ".cfi_startproc\n\t" - \\ "movl $42, %eax\n\t" - \\ "ret\n\t" - \\ ".cfi_endproc"); + \\__asm__(".globl func\n\t" + \\ ".type func, @function\n\t" + \\ "func:\n\t" + \\ ".cfi_startproc\n\t" + \\ "movl $42, %eax\n\t" + \\ "ret\n\t" + \\ ".cfi_endproc"); , &[_][]const u8{ - \\comptime { - \\ asm (".globl func\n\t.type func, @function\n\tfunc:\n\t.cfi_startproc\n\tmovl $42, %eax\n\tret\n\t.cfi_endproc"); - \\} + \\comptime { + \\ asm (".globl func\n\t.type func, @function\n\tfunc:\n\t.cfi_startproc\n\tmovl $42, %eax\n\tret\n\t.cfi_endproc"); + \\} }); cases.add("Demote function that initializes opaque struct",