authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-15 07:59:46+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-15 07:59:46+03:00
log97946e2a41a6a44ed376b57b32a19ce9d85f0bc2
tree5c7de4068bbb50e11ebe414bfc61540bc85b79ce
parentac42503266f27af2a4528af3ff0f1ef2cfbfe766
parent6dbdac4b605fb56b4180b6c66154275c22954a8d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9091 from Vexu/translate-c

Translate-c: move utility functions to a separate namespace

11 files changed, 999 insertions(+), 976 deletions(-)

lib/std/c.zig-1
...@@ -10,7 +10,6 @@ const page_size = std.mem.page_size;...@@ -10,7 +10,6 @@ const page_size = std.mem.page_size;
10pub const tokenizer = @import("c/tokenizer.zig");10pub const tokenizer = @import("c/tokenizer.zig");
11pub const Token = tokenizer.Token;11pub const Token = tokenizer.Token;
12pub const Tokenizer = tokenizer.Tokenizer;12pub const Tokenizer = tokenizer.Tokenizer;
13pub const builtins = @import("c/builtins.zig");
1413
15test {14test {
16 _ = tokenizer;15 _ = tokenizer;
lib/std/c/builtins.zig deleted-196
...@@ -1,196 +0,0 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("std");
8
9pub inline fn __builtin_bswap16(val: u16) u16 {
10 return @byteSwap(u16, val);
11}
12pub inline fn __builtin_bswap32(val: u32) u32 {
13 return @byteSwap(u32, val);
14}
15pub inline fn __builtin_bswap64(val: u64) u64 {
16 return @byteSwap(u64, val);
17}
18
19pub inline fn __builtin_signbit(val: f64) c_int {
20 return @boolToInt(std.math.signbit(val));
21}
22pub inline fn __builtin_signbitf(val: f32) c_int {
23 return @boolToInt(std.math.signbit(val));
24}
25
26pub inline fn __builtin_popcount(val: c_uint) c_int {
27 // popcount of a c_uint will never exceed the capacity of a c_int
28 @setRuntimeSafety(false);
29 return @bitCast(c_int, @as(c_uint, @popCount(c_uint, val)));
30}
31pub inline fn __builtin_ctz(val: c_uint) c_int {
32 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.
33 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
34 @setRuntimeSafety(false);
35 return @bitCast(c_int, @as(c_uint, @ctz(c_uint, val)));
36}
37pub inline fn __builtin_clz(val: c_uint) c_int {
38 // Returns the number of leading 0-bits in x, starting at the most significant bit position.
39 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
40 @setRuntimeSafety(false);
41 return @bitCast(c_int, @as(c_uint, @clz(c_uint, val)));
42}
43
44pub inline fn __builtin_sqrt(val: f64) f64 {
45 return @sqrt(val);
46}
47pub inline fn __builtin_sqrtf(val: f32) f32 {
48 return @sqrt(val);
49}
50
51pub inline fn __builtin_sin(val: f64) f64 {
52 return @sin(val);
53}
54pub inline fn __builtin_sinf(val: f32) f32 {
55 return @sin(val);
56}
57pub inline fn __builtin_cos(val: f64) f64 {
58 return @cos(val);
59}
60pub inline fn __builtin_cosf(val: f32) f32 {
61 return @cos(val);
62}
63
64pub inline fn __builtin_exp(val: f64) f64 {
65 return @exp(val);
66}
67pub inline fn __builtin_expf(val: f32) f32 {
68 return @exp(val);
69}
70pub inline fn __builtin_exp2(val: f64) f64 {
71 return @exp2(val);
72}
73pub inline fn __builtin_exp2f(val: f32) f32 {
74 return @exp2(val);
75}
76pub inline fn __builtin_log(val: f64) f64 {
77 return @log(val);
78}
79pub inline fn __builtin_logf(val: f32) f32 {
80 return @log(val);
81}
82pub inline fn __builtin_log2(val: f64) f64 {
83 return @log2(val);
84}
85pub inline fn __builtin_log2f(val: f32) f32 {
86 return @log2(val);
87}
88pub inline fn __builtin_log10(val: f64) f64 {
89 return @log10(val);
90}
91pub inline fn __builtin_log10f(val: f32) f32 {
92 return @log10(val);
93}
94
95// Standard C Library bug: The absolute value of the most negative integer remains negative.
96pub inline fn __builtin_abs(val: c_int) c_int {
97 return std.math.absInt(val) catch std.math.minInt(c_int);
98}
99pub inline fn __builtin_fabs(val: f64) f64 {
100 return @fabs(val);
101}
102pub inline fn __builtin_fabsf(val: f32) f32 {
103 return @fabs(val);
104}
105
106pub inline fn __builtin_floor(val: f64) f64 {
107 return @floor(val);
108}
109pub inline fn __builtin_floorf(val: f32) f32 {
110 return @floor(val);
111}
112pub inline fn __builtin_ceil(val: f64) f64 {
113 return @ceil(val);
114}
115pub inline fn __builtin_ceilf(val: f32) f32 {
116 return @ceil(val);
117}
118pub inline fn __builtin_trunc(val: f64) f64 {
119 return @trunc(val);
120}
121pub inline fn __builtin_truncf(val: f32) f32 {
122 return @trunc(val);
123}
124pub inline fn __builtin_round(val: f64) f64 {
125 return @round(val);
126}
127pub inline fn __builtin_roundf(val: f32) f32 {
128 return @round(val);
129}
130
131pub inline fn __builtin_strlen(s: [*c]const u8) usize {
132 return std.mem.lenZ(s);
133}
134pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
135 return @as(c_int, std.cstr.cmp(s1, s2));
136}
137
138pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize {
139 // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
140 // If it is not possible to determine which objects ptr points to at compile time,
141 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0
142 // for type 2 or 3.
143 if (ty == 0 or ty == 1) return @bitCast(usize, -@as(isize, 1));
144 if (ty == 2 or ty == 3) return 0;
145 unreachable;
146}
147
148pub inline fn __builtin___memset_chk(
149 dst: ?*c_void,
150 val: c_int,
151 len: usize,
152 remaining: usize,
153) ?*c_void {
154 if (len > remaining) @panic("std.c.builtins.memset_chk called with len > remaining");
155 return __builtin_memset(dst, val, len);
156}
157
158pub inline fn __builtin_memset(dst: ?*c_void, val: c_int, len: usize) ?*c_void {
159 const dst_cast = @ptrCast([*c]u8, dst);
160 @memset(dst_cast, @bitCast(u8, @truncate(i8, val)), len);
161 return dst;
162}
163
164pub inline fn __builtin___memcpy_chk(
165 noalias dst: ?*c_void,
166 noalias src: ?*const c_void,
167 len: usize,
168 remaining: usize,
169) ?*c_void {
170 if (len > remaining) @panic("std.c.builtins.memcpy_chk called with len > remaining");
171 return __builtin_memcpy(dst, src, len);
172}
173
174pub inline fn __builtin_memcpy(
175 noalias dst: ?*c_void,
176 noalias src: ?*const c_void,
177 len: usize,
178) ?*c_void {
179 const dst_cast = @ptrCast([*c]u8, dst);
180 const src_cast = @ptrCast([*c]const u8, src);
181
182 @memcpy(dst_cast, src_cast, len);
183 return dst;
184}
185
186/// The return value of __builtin_expect is `expr`. `c` is the expected value
187/// of `expr` and is used as a hint to the compiler in C. Here it is unused.
188pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
189 return expr;
190}
191
192// __builtin_alloca_with_align is not currently implemented.
193// It is used in a run-translated-c test and a test-translate-c test to ensure that non-implemented
194// builtins are correctly demoted. If you implement __builtin_alloca_with_align, please update the
195// run-translated-c test and the test-translate-c test to use a different non-implemented builtin.
196// pub fn __builtin_alloca_with_align(size: usize, alignment: usize) callconv(.Inline) *c_void {}
lib/std/crypto/pcurves/p256/p256_64.zig+158-159
...@@ -18,7 +18,6 @@...@@ -18,7 +18,6 @@
18// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^25618// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256
1919
20const std = @import("std");20const std = @import("std");
21const cast = std.meta.cast;
22const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels21const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels
2322
24// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.
...@@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
148 var x17: u64 = undefined;147 var x17: u64 = undefined;
149 var x18: u1 = undefined;148 var x18: u1 = undefined;
150 addcarryxU64(&x17, &x18, x16, x8, x5);149 addcarryxU64(&x17, &x18, x16, x8, x5);
151 const x19 = (cast(u64, x18) + x6);150 const x19 = (@as(u64, x18) + x6);
152 var x20: u64 = undefined;151 var x20: u64 = undefined;
153 var x21: u64 = undefined;152 var x21: u64 = undefined;
154 mulxU64(&x20, &x21, x11, 0xffffffff00000001);153 mulxU64(&x20, &x21, x11, 0xffffffff00000001);
...@@ -161,7 +160,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -161,7 +160,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
161 var x26: u64 = undefined;160 var x26: u64 = undefined;
162 var x27: u1 = undefined;161 var x27: u1 = undefined;
163 addcarryxU64(&x26, &x27, 0x0, x25, x22);162 addcarryxU64(&x26, &x27, 0x0, x25, x22);
164 const x28 = (cast(u64, x27) + x23);163 const x28 = (@as(u64, x27) + x23);
165 var x29: u64 = undefined;164 var x29: u64 = undefined;
166 var x30: u1 = undefined;165 var x30: u1 = undefined;
167 addcarryxU64(&x29, &x30, 0x0, x11, x24);166 addcarryxU64(&x29, &x30, 0x0, x11, x24);
...@@ -198,7 +197,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -198,7 +197,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
198 var x51: u64 = undefined;197 var x51: u64 = undefined;
199 var x52: u1 = undefined;198 var x52: u1 = undefined;
200 addcarryxU64(&x51, &x52, x50, x42, x39);199 addcarryxU64(&x51, &x52, x50, x42, x39);
201 const x53 = (cast(u64, x52) + x40);200 const x53 = (@as(u64, x52) + x40);
202 var x54: u64 = undefined;201 var x54: u64 = undefined;
203 var x55: u1 = undefined;202 var x55: u1 = undefined;
204 addcarryxU64(&x54, &x55, 0x0, x31, x45);203 addcarryxU64(&x54, &x55, 0x0, x31, x45);
...@@ -213,7 +212,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -213,7 +212,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
213 addcarryxU64(&x60, &x61, x59, x37, x51);212 addcarryxU64(&x60, &x61, x59, x37, x51);
214 var x62: u64 = undefined;213 var x62: u64 = undefined;
215 var x63: u1 = undefined;214 var x63: u1 = undefined;
216 addcarryxU64(&x62, &x63, x61, cast(u64, x38), x53);215 addcarryxU64(&x62, &x63, x61, @as(u64, x38), x53);
217 var x64: u64 = undefined;216 var x64: u64 = undefined;
218 var x65: u64 = undefined;217 var x65: u64 = undefined;
219 mulxU64(&x64, &x65, x54, 0xffffffff00000001);218 mulxU64(&x64, &x65, x54, 0xffffffff00000001);
...@@ -226,7 +225,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -226,7 +225,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
226 var x70: u64 = undefined;225 var x70: u64 = undefined;
227 var x71: u1 = undefined;226 var x71: u1 = undefined;
228 addcarryxU64(&x70, &x71, 0x0, x69, x66);227 addcarryxU64(&x70, &x71, 0x0, x69, x66);
229 const x72 = (cast(u64, x71) + x67);228 const x72 = (@as(u64, x71) + x67);
230 var x73: u64 = undefined;229 var x73: u64 = undefined;
231 var x74: u1 = undefined;230 var x74: u1 = undefined;
232 addcarryxU64(&x73, &x74, 0x0, x54, x68);231 addcarryxU64(&x73, &x74, 0x0, x54, x68);
...@@ -242,7 +241,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -242,7 +241,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
242 var x81: u64 = undefined;241 var x81: u64 = undefined;
243 var x82: u1 = undefined;242 var x82: u1 = undefined;
244 addcarryxU64(&x81, &x82, x80, x62, x65);243 addcarryxU64(&x81, &x82, x80, x62, x65);
245 const x83 = (cast(u64, x82) + cast(u64, x63));244 const x83 = (@as(u64, x82) + @as(u64, x63));
246 var x84: u64 = undefined;245 var x84: u64 = undefined;
247 var x85: u64 = undefined;246 var x85: u64 = undefined;
248 mulxU64(&x84, &x85, x2, (arg2[3]));247 mulxU64(&x84, &x85, x2, (arg2[3]));
...@@ -264,7 +263,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -264,7 +263,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
264 var x96: u64 = undefined;263 var x96: u64 = undefined;
265 var x97: u1 = undefined;264 var x97: u1 = undefined;
266 addcarryxU64(&x96, &x97, x95, x87, x84);265 addcarryxU64(&x96, &x97, x95, x87, x84);
267 const x98 = (cast(u64, x97) + x85);266 const x98 = (@as(u64, x97) + x85);
268 var x99: u64 = undefined;267 var x99: u64 = undefined;
269 var x100: u1 = undefined;268 var x100: u1 = undefined;
270 addcarryxU64(&x99, &x100, 0x0, x75, x90);269 addcarryxU64(&x99, &x100, 0x0, x75, x90);
...@@ -292,7 +291,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -292,7 +291,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
292 var x115: u64 = undefined;291 var x115: u64 = undefined;
293 var x116: u1 = undefined;292 var x116: u1 = undefined;
294 addcarryxU64(&x115, &x116, 0x0, x114, x111);293 addcarryxU64(&x115, &x116, 0x0, x114, x111);
295 const x117 = (cast(u64, x116) + x112);294 const x117 = (@as(u64, x116) + x112);
296 var x118: u64 = undefined;295 var x118: u64 = undefined;
297 var x119: u1 = undefined;296 var x119: u1 = undefined;
298 addcarryxU64(&x118, &x119, 0x0, x99, x113);297 addcarryxU64(&x118, &x119, 0x0, x99, x113);
...@@ -308,7 +307,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -308,7 +307,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
308 var x126: u64 = undefined;307 var x126: u64 = undefined;
309 var x127: u1 = undefined;308 var x127: u1 = undefined;
310 addcarryxU64(&x126, &x127, x125, x107, x110);309 addcarryxU64(&x126, &x127, x125, x107, x110);
311 const x128 = (cast(u64, x127) + cast(u64, x108));310 const x128 = (@as(u64, x127) + @as(u64, x108));
312 var x129: u64 = undefined;311 var x129: u64 = undefined;
313 var x130: u64 = undefined;312 var x130: u64 = undefined;
314 mulxU64(&x129, &x130, x3, (arg2[3]));313 mulxU64(&x129, &x130, x3, (arg2[3]));
...@@ -330,7 +329,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -330,7 +329,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
330 var x141: u64 = undefined;329 var x141: u64 = undefined;
331 var x142: u1 = undefined;330 var x142: u1 = undefined;
332 addcarryxU64(&x141, &x142, x140, x132, x129);331 addcarryxU64(&x141, &x142, x140, x132, x129);
333 const x143 = (cast(u64, x142) + x130);332 const x143 = (@as(u64, x142) + x130);
334 var x144: u64 = undefined;333 var x144: u64 = undefined;
335 var x145: u1 = undefined;334 var x145: u1 = undefined;
336 addcarryxU64(&x144, &x145, 0x0, x120, x135);335 addcarryxU64(&x144, &x145, 0x0, x120, x135);
...@@ -358,7 +357,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -358,7 +357,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
358 var x160: u64 = undefined;357 var x160: u64 = undefined;
359 var x161: u1 = undefined;358 var x161: u1 = undefined;
360 addcarryxU64(&x160, &x161, 0x0, x159, x156);359 addcarryxU64(&x160, &x161, 0x0, x159, x156);
361 const x162 = (cast(u64, x161) + x157);360 const x162 = (@as(u64, x161) + x157);
362 var x163: u64 = undefined;361 var x163: u64 = undefined;
363 var x164: u1 = undefined;362 var x164: u1 = undefined;
364 addcarryxU64(&x163, &x164, 0x0, x144, x158);363 addcarryxU64(&x163, &x164, 0x0, x144, x158);
...@@ -374,7 +373,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -374,7 +373,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
374 var x171: u64 = undefined;373 var x171: u64 = undefined;
375 var x172: u1 = undefined;374 var x172: u1 = undefined;
376 addcarryxU64(&x171, &x172, x170, x152, x155);375 addcarryxU64(&x171, &x172, x170, x152, x155);
377 const x173 = (cast(u64, x172) + cast(u64, x153));376 const x173 = (@as(u64, x172) + @as(u64, x153));
378 var x174: u64 = undefined;377 var x174: u64 = undefined;
379 var x175: u1 = undefined;378 var x175: u1 = undefined;
380 subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff);379 subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff);
...@@ -383,13 +382,13 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -383,13 +382,13 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
383 subborrowxU64(&x176, &x177, x175, x167, 0xffffffff);382 subborrowxU64(&x176, &x177, x175, x167, 0xffffffff);
384 var x178: u64 = undefined;383 var x178: u64 = undefined;
385 var x179: u1 = undefined;384 var x179: u1 = undefined;
386 subborrowxU64(&x178, &x179, x177, x169, cast(u64, 0x0));385 subborrowxU64(&x178, &x179, x177, x169, @as(u64, 0x0));
387 var x180: u64 = undefined;386 var x180: u64 = undefined;
388 var x181: u1 = undefined;387 var x181: u1 = undefined;
389 subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001);388 subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001);
390 var x182: u64 = undefined;389 var x182: u64 = undefined;
391 var x183: u1 = undefined;390 var x183: u1 = undefined;
392 subborrowxU64(&x182, &x183, x181, x173, cast(u64, 0x0));391 subborrowxU64(&x182, &x183, x181, x173, @as(u64, 0x0));
393 var x184: u64 = undefined;392 var x184: u64 = undefined;
394 cmovznzU64(&x184, x183, x174, x165);393 cmovznzU64(&x184, x183, x174, x165);
395 var x185: u64 = undefined;394 var x185: u64 = undefined;
...@@ -440,7 +439,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -440,7 +439,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
440 var x17: u64 = undefined;439 var x17: u64 = undefined;
441 var x18: u1 = undefined;440 var x18: u1 = undefined;
442 addcarryxU64(&x17, &x18, x16, x8, x5);441 addcarryxU64(&x17, &x18, x16, x8, x5);
443 const x19 = (cast(u64, x18) + x6);442 const x19 = (@as(u64, x18) + x6);
444 var x20: u64 = undefined;443 var x20: u64 = undefined;
445 var x21: u64 = undefined;444 var x21: u64 = undefined;
446 mulxU64(&x20, &x21, x11, 0xffffffff00000001);445 mulxU64(&x20, &x21, x11, 0xffffffff00000001);
...@@ -453,7 +452,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -453,7 +452,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
453 var x26: u64 = undefined;452 var x26: u64 = undefined;
454 var x27: u1 = undefined;453 var x27: u1 = undefined;
455 addcarryxU64(&x26, &x27, 0x0, x25, x22);454 addcarryxU64(&x26, &x27, 0x0, x25, x22);
456 const x28 = (cast(u64, x27) + x23);455 const x28 = (@as(u64, x27) + x23);
457 var x29: u64 = undefined;456 var x29: u64 = undefined;
458 var x30: u1 = undefined;457 var x30: u1 = undefined;
459 addcarryxU64(&x29, &x30, 0x0, x11, x24);458 addcarryxU64(&x29, &x30, 0x0, x11, x24);
...@@ -490,7 +489,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -490,7 +489,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
490 var x51: u64 = undefined;489 var x51: u64 = undefined;
491 var x52: u1 = undefined;490 var x52: u1 = undefined;
492 addcarryxU64(&x51, &x52, x50, x42, x39);491 addcarryxU64(&x51, &x52, x50, x42, x39);
493 const x53 = (cast(u64, x52) + x40);492 const x53 = (@as(u64, x52) + x40);
494 var x54: u64 = undefined;493 var x54: u64 = undefined;
495 var x55: u1 = undefined;494 var x55: u1 = undefined;
496 addcarryxU64(&x54, &x55, 0x0, x31, x45);495 addcarryxU64(&x54, &x55, 0x0, x31, x45);
...@@ -505,7 +504,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -505,7 +504,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
505 addcarryxU64(&x60, &x61, x59, x37, x51);504 addcarryxU64(&x60, &x61, x59, x37, x51);
506 var x62: u64 = undefined;505 var x62: u64 = undefined;
507 var x63: u1 = undefined;506 var x63: u1 = undefined;
508 addcarryxU64(&x62, &x63, x61, cast(u64, x38), x53);507 addcarryxU64(&x62, &x63, x61, @as(u64, x38), x53);
509 var x64: u64 = undefined;508 var x64: u64 = undefined;
510 var x65: u64 = undefined;509 var x65: u64 = undefined;
511 mulxU64(&x64, &x65, x54, 0xffffffff00000001);510 mulxU64(&x64, &x65, x54, 0xffffffff00000001);
...@@ -518,7 +517,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -518,7 +517,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
518 var x70: u64 = undefined;517 var x70: u64 = undefined;
519 var x71: u1 = undefined;518 var x71: u1 = undefined;
520 addcarryxU64(&x70, &x71, 0x0, x69, x66);519 addcarryxU64(&x70, &x71, 0x0, x69, x66);
521 const x72 = (cast(u64, x71) + x67);520 const x72 = (@as(u64, x71) + x67);
522 var x73: u64 = undefined;521 var x73: u64 = undefined;
523 var x74: u1 = undefined;522 var x74: u1 = undefined;
524 addcarryxU64(&x73, &x74, 0x0, x54, x68);523 addcarryxU64(&x73, &x74, 0x0, x54, x68);
...@@ -534,7 +533,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -534,7 +533,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
534 var x81: u64 = undefined;533 var x81: u64 = undefined;
535 var x82: u1 = undefined;534 var x82: u1 = undefined;
536 addcarryxU64(&x81, &x82, x80, x62, x65);535 addcarryxU64(&x81, &x82, x80, x62, x65);
537 const x83 = (cast(u64, x82) + cast(u64, x63));536 const x83 = (@as(u64, x82) + @as(u64, x63));
538 var x84: u64 = undefined;537 var x84: u64 = undefined;
539 var x85: u64 = undefined;538 var x85: u64 = undefined;
540 mulxU64(&x84, &x85, x2, (arg1[3]));539 mulxU64(&x84, &x85, x2, (arg1[3]));
...@@ -556,7 +555,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -556,7 +555,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
556 var x96: u64 = undefined;555 var x96: u64 = undefined;
557 var x97: u1 = undefined;556 var x97: u1 = undefined;
558 addcarryxU64(&x96, &x97, x95, x87, x84);557 addcarryxU64(&x96, &x97, x95, x87, x84);
559 const x98 = (cast(u64, x97) + x85);558 const x98 = (@as(u64, x97) + x85);
560 var x99: u64 = undefined;559 var x99: u64 = undefined;
561 var x100: u1 = undefined;560 var x100: u1 = undefined;
562 addcarryxU64(&x99, &x100, 0x0, x75, x90);561 addcarryxU64(&x99, &x100, 0x0, x75, x90);
...@@ -584,7 +583,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -584,7 +583,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
584 var x115: u64 = undefined;583 var x115: u64 = undefined;
585 var x116: u1 = undefined;584 var x116: u1 = undefined;
586 addcarryxU64(&x115, &x116, 0x0, x114, x111);585 addcarryxU64(&x115, &x116, 0x0, x114, x111);
587 const x117 = (cast(u64, x116) + x112);586 const x117 = (@as(u64, x116) + x112);
588 var x118: u64 = undefined;587 var x118: u64 = undefined;
589 var x119: u1 = undefined;588 var x119: u1 = undefined;
590 addcarryxU64(&x118, &x119, 0x0, x99, x113);589 addcarryxU64(&x118, &x119, 0x0, x99, x113);
...@@ -600,7 +599,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -600,7 +599,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
600 var x126: u64 = undefined;599 var x126: u64 = undefined;
601 var x127: u1 = undefined;600 var x127: u1 = undefined;
602 addcarryxU64(&x126, &x127, x125, x107, x110);601 addcarryxU64(&x126, &x127, x125, x107, x110);
603 const x128 = (cast(u64, x127) + cast(u64, x108));602 const x128 = (@as(u64, x127) + @as(u64, x108));
604 var x129: u64 = undefined;603 var x129: u64 = undefined;
605 var x130: u64 = undefined;604 var x130: u64 = undefined;
606 mulxU64(&x129, &x130, x3, (arg1[3]));605 mulxU64(&x129, &x130, x3, (arg1[3]));
...@@ -622,7 +621,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -622,7 +621,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
622 var x141: u64 = undefined;621 var x141: u64 = undefined;
623 var x142: u1 = undefined;622 var x142: u1 = undefined;
624 addcarryxU64(&x141, &x142, x140, x132, x129);623 addcarryxU64(&x141, &x142, x140, x132, x129);
625 const x143 = (cast(u64, x142) + x130);624 const x143 = (@as(u64, x142) + x130);
626 var x144: u64 = undefined;625 var x144: u64 = undefined;
627 var x145: u1 = undefined;626 var x145: u1 = undefined;
628 addcarryxU64(&x144, &x145, 0x0, x120, x135);627 addcarryxU64(&x144, &x145, 0x0, x120, x135);
...@@ -650,7 +649,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -650,7 +649,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
650 var x160: u64 = undefined;649 var x160: u64 = undefined;
651 var x161: u1 = undefined;650 var x161: u1 = undefined;
652 addcarryxU64(&x160, &x161, 0x0, x159, x156);651 addcarryxU64(&x160, &x161, 0x0, x159, x156);
653 const x162 = (cast(u64, x161) + x157);652 const x162 = (@as(u64, x161) + x157);
654 var x163: u64 = undefined;653 var x163: u64 = undefined;
655 var x164: u1 = undefined;654 var x164: u1 = undefined;
656 addcarryxU64(&x163, &x164, 0x0, x144, x158);655 addcarryxU64(&x163, &x164, 0x0, x144, x158);
...@@ -666,7 +665,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -666,7 +665,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
666 var x171: u64 = undefined;665 var x171: u64 = undefined;
667 var x172: u1 = undefined;666 var x172: u1 = undefined;
668 addcarryxU64(&x171, &x172, x170, x152, x155);667 addcarryxU64(&x171, &x172, x170, x152, x155);
669 const x173 = (cast(u64, x172) + cast(u64, x153));668 const x173 = (@as(u64, x172) + @as(u64, x153));
670 var x174: u64 = undefined;669 var x174: u64 = undefined;
671 var x175: u1 = undefined;670 var x175: u1 = undefined;
672 subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff);671 subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff);
...@@ -675,13 +674,13 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -675,13 +674,13 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
675 subborrowxU64(&x176, &x177, x175, x167, 0xffffffff);674 subborrowxU64(&x176, &x177, x175, x167, 0xffffffff);
676 var x178: u64 = undefined;675 var x178: u64 = undefined;
677 var x179: u1 = undefined;676 var x179: u1 = undefined;
678 subborrowxU64(&x178, &x179, x177, x169, cast(u64, 0x0));677 subborrowxU64(&x178, &x179, x177, x169, @as(u64, 0x0));
679 var x180: u64 = undefined;678 var x180: u64 = undefined;
680 var x181: u1 = undefined;679 var x181: u1 = undefined;
681 subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001);680 subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001);
682 var x182: u64 = undefined;681 var x182: u64 = undefined;
683 var x183: u1 = undefined;682 var x183: u1 = undefined;
684 subborrowxU64(&x182, &x183, x181, x173, cast(u64, 0x0));683 subborrowxU64(&x182, &x183, x181, x173, @as(u64, 0x0));
685 var x184: u64 = undefined;684 var x184: u64 = undefined;
686 cmovznzU64(&x184, x183, x174, x165);685 cmovznzU64(&x184, x183, x174, x165);
687 var x185: u64 = undefined;686 var x185: u64 = undefined;
...@@ -728,13 +727,13 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -728,13 +727,13 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
728 subborrowxU64(&x11, &x12, x10, x3, 0xffffffff);727 subborrowxU64(&x11, &x12, x10, x3, 0xffffffff);
729 var x13: u64 = undefined;728 var x13: u64 = undefined;
730 var x14: u1 = undefined;729 var x14: u1 = undefined;
731 subborrowxU64(&x13, &x14, x12, x5, cast(u64, 0x0));730 subborrowxU64(&x13, &x14, x12, x5, @as(u64, 0x0));
732 var x15: u64 = undefined;731 var x15: u64 = undefined;
733 var x16: u1 = undefined;732 var x16: u1 = undefined;
734 subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000001);733 subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000001);
735 var x17: u64 = undefined;734 var x17: u64 = undefined;
736 var x18: u1 = undefined;735 var x18: u1 = undefined;
737 subborrowxU64(&x17, &x18, x16, cast(u64, x8), cast(u64, 0x0));736 subborrowxU64(&x17, &x18, x16, @as(u64, x8), @as(u64, 0x0));
738 var x19: u64 = undefined;737 var x19: u64 = undefined;
739 cmovznzU64(&x19, x18, x9, x1);738 cmovznzU64(&x19, x18, x9, x1);
740 var x20: u64 = undefined;739 var x20: u64 = undefined;
...@@ -774,7 +773,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -774,7 +773,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
774 var x8: u1 = undefined;773 var x8: u1 = undefined;
775 subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3]));774 subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3]));
776 var x9: u64 = undefined;775 var x9: u64 = undefined;
777 cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff);776 cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff);
778 var x10: u64 = undefined;777 var x10: u64 = undefined;
779 var x11: u1 = undefined;778 var x11: u1 = undefined;
780 addcarryxU64(&x10, &x11, 0x0, x1, x9);779 addcarryxU64(&x10, &x11, 0x0, x1, x9);
...@@ -783,7 +782,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -783,7 +782,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
783 addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff));782 addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff));
784 var x14: u64 = undefined;783 var x14: u64 = undefined;
785 var x15: u1 = undefined;784 var x15: u1 = undefined;
786 addcarryxU64(&x14, &x15, x13, x5, cast(u64, 0x0));785 addcarryxU64(&x14, &x15, x13, x5, @as(u64, 0x0));
787 var x16: u64 = undefined;786 var x16: u64 = undefined;
788 var x17: u1 = undefined;787 var x17: u1 = undefined;
789 addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001));788 addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001));
...@@ -806,18 +805,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -806,18 +805,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
806805
807 var x1: u64 = undefined;806 var x1: u64 = undefined;
808 var x2: u1 = undefined;807 var x2: u1 = undefined;
809 subborrowxU64(&x1, &x2, 0x0, cast(u64, 0x0), (arg1[0]));808 subborrowxU64(&x1, &x2, 0x0, @as(u64, 0x0), (arg1[0]));
810 var x3: u64 = undefined;809 var x3: u64 = undefined;
811 var x4: u1 = undefined;810 var x4: u1 = undefined;
812 subborrowxU64(&x3, &x4, x2, cast(u64, 0x0), (arg1[1]));811 subborrowxU64(&x3, &x4, x2, @as(u64, 0x0), (arg1[1]));
813 var x5: u64 = undefined;812 var x5: u64 = undefined;
814 var x6: u1 = undefined;813 var x6: u1 = undefined;
815 subborrowxU64(&x5, &x6, x4, cast(u64, 0x0), (arg1[2]));814 subborrowxU64(&x5, &x6, x4, @as(u64, 0x0), (arg1[2]));
816 var x7: u64 = undefined;815 var x7: u64 = undefined;
817 var x8: u1 = undefined;816 var x8: u1 = undefined;
818 subborrowxU64(&x7, &x8, x6, cast(u64, 0x0), (arg1[3]));817 subborrowxU64(&x7, &x8, x6, @as(u64, 0x0), (arg1[3]));
819 var x9: u64 = undefined;818 var x9: u64 = undefined;
820 cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff);819 cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff);
821 var x10: u64 = undefined;820 var x10: u64 = undefined;
822 var x11: u1 = undefined;821 var x11: u1 = undefined;
823 addcarryxU64(&x10, &x11, 0x0, x1, x9);822 addcarryxU64(&x10, &x11, 0x0, x1, x9);
...@@ -826,7 +825,7 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -826,7 +825,7 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
826 addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff));825 addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff));
827 var x14: u64 = undefined;826 var x14: u64 = undefined;
828 var x15: u1 = undefined;827 var x15: u1 = undefined;
829 addcarryxU64(&x14, &x15, x13, x5, cast(u64, 0x0));828 addcarryxU64(&x14, &x15, x13, x5, @as(u64, 0x0));
830 var x16: u64 = undefined;829 var x16: u64 = undefined;
831 var x17: u1 = undefined;830 var x17: u1 = undefined;
832 addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001));831 addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001));
...@@ -865,7 +864,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -865,7 +864,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
865 addcarryxU64(&x10, &x11, 0x0, x1, x6);864 addcarryxU64(&x10, &x11, 0x0, x1, x6);
866 var x12: u64 = undefined;865 var x12: u64 = undefined;
867 var x13: u1 = undefined;866 var x13: u1 = undefined;
868 addcarryxU64(&x12, &x13, x11, cast(u64, 0x0), x8);867 addcarryxU64(&x12, &x13, x11, @as(u64, 0x0), x8);
869 var x14: u64 = undefined;868 var x14: u64 = undefined;
870 var x15: u1 = undefined;869 var x15: u1 = undefined;
871 addcarryxU64(&x14, &x15, 0x0, x12, (arg1[1]));870 addcarryxU64(&x14, &x15, 0x0, x12, (arg1[1]));
...@@ -886,10 +885,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -886,10 +885,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
886 addcarryxU64(&x24, &x25, 0x0, x14, x20);885 addcarryxU64(&x24, &x25, 0x0, x14, x20);
887 var x26: u64 = undefined;886 var x26: u64 = undefined;
888 var x27: u1 = undefined;887 var x27: u1 = undefined;
889 addcarryxU64(&x26, &x27, x25, (cast(u64, x15) + (cast(u64, x13) + (cast(u64, x9) + x5))), x22);888 addcarryxU64(&x26, &x27, x25, (@as(u64, x15) + (@as(u64, x13) + (@as(u64, x9) + x5))), x22);
890 var x28: u64 = undefined;889 var x28: u64 = undefined;
891 var x29: u1 = undefined;890 var x29: u1 = undefined;
892 addcarryxU64(&x28, &x29, x27, x2, (cast(u64, x23) + x19));891 addcarryxU64(&x28, &x29, x27, x2, (@as(u64, x23) + x19));
893 var x30: u64 = undefined;892 var x30: u64 = undefined;
894 var x31: u1 = undefined;893 var x31: u1 = undefined;
895 addcarryxU64(&x30, &x31, x29, x3, x16);894 addcarryxU64(&x30, &x31, x29, x3, x16);
...@@ -898,10 +897,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -898,10 +897,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
898 addcarryxU64(&x32, &x33, 0x0, x26, (arg1[2]));897 addcarryxU64(&x32, &x33, 0x0, x26, (arg1[2]));
899 var x34: u64 = undefined;898 var x34: u64 = undefined;
900 var x35: u1 = undefined;899 var x35: u1 = undefined;
901 addcarryxU64(&x34, &x35, x33, x28, cast(u64, 0x0));900 addcarryxU64(&x34, &x35, x33, x28, @as(u64, 0x0));
902 var x36: u64 = undefined;901 var x36: u64 = undefined;
903 var x37: u1 = undefined;902 var x37: u1 = undefined;
904 addcarryxU64(&x36, &x37, x35, x30, cast(u64, 0x0));903 addcarryxU64(&x36, &x37, x35, x30, @as(u64, 0x0));
905 var x38: u64 = undefined;904 var x38: u64 = undefined;
906 var x39: u64 = undefined;905 var x39: u64 = undefined;
907 mulxU64(&x38, &x39, x32, 0xffffffff00000001);906 mulxU64(&x38, &x39, x32, 0xffffffff00000001);
...@@ -922,19 +921,19 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -922,19 +921,19 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
922 addcarryxU64(&x48, &x49, x47, x34, x44);921 addcarryxU64(&x48, &x49, x47, x34, x44);
923 var x50: u64 = undefined;922 var x50: u64 = undefined;
924 var x51: u1 = undefined;923 var x51: u1 = undefined;
925 addcarryxU64(&x50, &x51, x49, x36, (cast(u64, x45) + x41));924 addcarryxU64(&x50, &x51, x49, x36, (@as(u64, x45) + x41));
926 var x52: u64 = undefined;925 var x52: u64 = undefined;
927 var x53: u1 = undefined;926 var x53: u1 = undefined;
928 addcarryxU64(&x52, &x53, x51, (cast(u64, x37) + (cast(u64, x31) + x17)), x38);927 addcarryxU64(&x52, &x53, x51, (@as(u64, x37) + (@as(u64, x31) + x17)), x38);
929 var x54: u64 = undefined;928 var x54: u64 = undefined;
930 var x55: u1 = undefined;929 var x55: u1 = undefined;
931 addcarryxU64(&x54, &x55, 0x0, x48, (arg1[3]));930 addcarryxU64(&x54, &x55, 0x0, x48, (arg1[3]));
932 var x56: u64 = undefined;931 var x56: u64 = undefined;
933 var x57: u1 = undefined;932 var x57: u1 = undefined;
934 addcarryxU64(&x56, &x57, x55, x50, cast(u64, 0x0));933 addcarryxU64(&x56, &x57, x55, x50, @as(u64, 0x0));
935 var x58: u64 = undefined;934 var x58: u64 = undefined;
936 var x59: u1 = undefined;935 var x59: u1 = undefined;
937 addcarryxU64(&x58, &x59, x57, x52, cast(u64, 0x0));936 addcarryxU64(&x58, &x59, x57, x52, @as(u64, 0x0));
938 var x60: u64 = undefined;937 var x60: u64 = undefined;
939 var x61: u64 = undefined;938 var x61: u64 = undefined;
940 mulxU64(&x60, &x61, x54, 0xffffffff00000001);939 mulxU64(&x60, &x61, x54, 0xffffffff00000001);
...@@ -955,11 +954,11 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -955,11 +954,11 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
955 addcarryxU64(&x70, &x71, x69, x56, x66);954 addcarryxU64(&x70, &x71, x69, x56, x66);
956 var x72: u64 = undefined;955 var x72: u64 = undefined;
957 var x73: u1 = undefined;956 var x73: u1 = undefined;
958 addcarryxU64(&x72, &x73, x71, x58, (cast(u64, x67) + x63));957 addcarryxU64(&x72, &x73, x71, x58, (@as(u64, x67) + x63));
959 var x74: u64 = undefined;958 var x74: u64 = undefined;
960 var x75: u1 = undefined;959 var x75: u1 = undefined;
961 addcarryxU64(&x74, &x75, x73, (cast(u64, x59) + (cast(u64, x53) + x39)), x60);960 addcarryxU64(&x74, &x75, x73, (@as(u64, x59) + (@as(u64, x53) + x39)), x60);
962 const x76 = (cast(u64, x75) + x61);961 const x76 = (@as(u64, x75) + x61);
963 var x77: u64 = undefined;962 var x77: u64 = undefined;
964 var x78: u1 = undefined;963 var x78: u1 = undefined;
965 subborrowxU64(&x77, &x78, 0x0, x70, 0xffffffffffffffff);964 subborrowxU64(&x77, &x78, 0x0, x70, 0xffffffffffffffff);
...@@ -968,13 +967,13 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -968,13 +967,13 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
968 subborrowxU64(&x79, &x80, x78, x72, 0xffffffff);967 subborrowxU64(&x79, &x80, x78, x72, 0xffffffff);
969 var x81: u64 = undefined;968 var x81: u64 = undefined;
970 var x82: u1 = undefined;969 var x82: u1 = undefined;
971 subborrowxU64(&x81, &x82, x80, x74, cast(u64, 0x0));970 subborrowxU64(&x81, &x82, x80, x74, @as(u64, 0x0));
972 var x83: u64 = undefined;971 var x83: u64 = undefined;
973 var x84: u1 = undefined;972 var x84: u1 = undefined;
974 subborrowxU64(&x83, &x84, x82, x76, 0xffffffff00000001);973 subborrowxU64(&x83, &x84, x82, x76, 0xffffffff00000001);
975 var x85: u64 = undefined;974 var x85: u64 = undefined;
976 var x86: u1 = undefined;975 var x86: u1 = undefined;
977 subborrowxU64(&x85, &x86, x84, cast(u64, 0x0), cast(u64, 0x0));976 subborrowxU64(&x85, &x86, x84, @as(u64, 0x0), @as(u64, 0x0));
978 var x87: u64 = undefined;977 var x87: u64 = undefined;
979 cmovznzU64(&x87, x86, x77, x70);978 cmovznzU64(&x87, x86, x77, x70);
980 var x88: u64 = undefined;979 var x88: u64 = undefined;
...@@ -1045,13 +1044,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1045,13 +1044,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1045 addcarryxU64(&x29, &x30, x28, x13, x25);1044 addcarryxU64(&x29, &x30, x28, x13, x25);
1046 var x31: u64 = undefined;1045 var x31: u64 = undefined;
1047 var x32: u1 = undefined;1046 var x32: u1 = undefined;
1048 addcarryxU64(&x31, &x32, x30, x15, (cast(u64, x26) + x22));1047 addcarryxU64(&x31, &x32, x30, x15, (@as(u64, x26) + x22));
1049 var x33: u64 = undefined;1048 var x33: u64 = undefined;
1050 var x34: u1 = undefined;1049 var x34: u1 = undefined;
1051 addcarryxU64(&x33, &x34, x32, x17, x19);1050 addcarryxU64(&x33, &x34, x32, x17, x19);
1052 var x35: u64 = undefined;1051 var x35: u64 = undefined;
1053 var x36: u1 = undefined;1052 var x36: u1 = undefined;
1054 addcarryxU64(&x35, &x36, x34, (cast(u64, x18) + x6), x20);1053 addcarryxU64(&x35, &x36, x34, (@as(u64, x18) + x6), x20);
1055 var x37: u64 = undefined;1054 var x37: u64 = undefined;
1056 var x38: u64 = undefined;1055 var x38: u64 = undefined;
1057 mulxU64(&x37, &x38, x1, 0x4fffffffd);1056 mulxU64(&x37, &x38, x1, 0x4fffffffd);
...@@ -1105,13 +1104,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1105,13 +1104,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1105 addcarryxU64(&x69, &x70, x68, x53, x65);1104 addcarryxU64(&x69, &x70, x68, x53, x65);
1106 var x71: u64 = undefined;1105 var x71: u64 = undefined;
1107 var x72: u1 = undefined;1106 var x72: u1 = undefined;
1108 addcarryxU64(&x71, &x72, x70, x55, (cast(u64, x66) + x62));1107 addcarryxU64(&x71, &x72, x70, x55, (@as(u64, x66) + x62));
1109 var x73: u64 = undefined;1108 var x73: u64 = undefined;
1110 var x74: u1 = undefined;1109 var x74: u1 = undefined;
1111 addcarryxU64(&x73, &x74, x72, x57, x59);1110 addcarryxU64(&x73, &x74, x72, x57, x59);
1112 var x75: u64 = undefined;1111 var x75: u64 = undefined;
1113 var x76: u1 = undefined;1112 var x76: u1 = undefined;
1114 addcarryxU64(&x75, &x76, x74, ((cast(u64, x58) + cast(u64, x36)) + (cast(u64, x50) + x38)), x60);1113 addcarryxU64(&x75, &x76, x74, ((@as(u64, x58) + @as(u64, x36)) + (@as(u64, x50) + x38)), x60);
1115 var x77: u64 = undefined;1114 var x77: u64 = undefined;
1116 var x78: u64 = undefined;1115 var x78: u64 = undefined;
1117 mulxU64(&x77, &x78, x2, 0x4fffffffd);1116 mulxU64(&x77, &x78, x2, 0x4fffffffd);
...@@ -1165,13 +1164,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1165,13 +1164,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1165 addcarryxU64(&x109, &x110, x108, x93, x105);1164 addcarryxU64(&x109, &x110, x108, x93, x105);
1166 var x111: u64 = undefined;1165 var x111: u64 = undefined;
1167 var x112: u1 = undefined;1166 var x112: u1 = undefined;
1168 addcarryxU64(&x111, &x112, x110, x95, (cast(u64, x106) + x102));1167 addcarryxU64(&x111, &x112, x110, x95, (@as(u64, x106) + x102));
1169 var x113: u64 = undefined;1168 var x113: u64 = undefined;
1170 var x114: u1 = undefined;1169 var x114: u1 = undefined;
1171 addcarryxU64(&x113, &x114, x112, x97, x99);1170 addcarryxU64(&x113, &x114, x112, x97, x99);
1172 var x115: u64 = undefined;1171 var x115: u64 = undefined;
1173 var x116: u1 = undefined;1172 var x116: u1 = undefined;
1174 addcarryxU64(&x115, &x116, x114, ((cast(u64, x98) + cast(u64, x76)) + (cast(u64, x90) + x78)), x100);1173 addcarryxU64(&x115, &x116, x114, ((@as(u64, x98) + @as(u64, x76)) + (@as(u64, x90) + x78)), x100);
1175 var x117: u64 = undefined;1174 var x117: u64 = undefined;
1176 var x118: u64 = undefined;1175 var x118: u64 = undefined;
1177 mulxU64(&x117, &x118, x3, 0x4fffffffd);1176 mulxU64(&x117, &x118, x3, 0x4fffffffd);
...@@ -1225,13 +1224,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1225,13 +1224,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1225 addcarryxU64(&x149, &x150, x148, x133, x145);1224 addcarryxU64(&x149, &x150, x148, x133, x145);
1226 var x151: u64 = undefined;1225 var x151: u64 = undefined;
1227 var x152: u1 = undefined;1226 var x152: u1 = undefined;
1228 addcarryxU64(&x151, &x152, x150, x135, (cast(u64, x146) + x142));1227 addcarryxU64(&x151, &x152, x150, x135, (@as(u64, x146) + x142));
1229 var x153: u64 = undefined;1228 var x153: u64 = undefined;
1230 var x154: u1 = undefined;1229 var x154: u1 = undefined;
1231 addcarryxU64(&x153, &x154, x152, x137, x139);1230 addcarryxU64(&x153, &x154, x152, x137, x139);
1232 var x155: u64 = undefined;1231 var x155: u64 = undefined;
1233 var x156: u1 = undefined;1232 var x156: u1 = undefined;
1234 addcarryxU64(&x155, &x156, x154, ((cast(u64, x138) + cast(u64, x116)) + (cast(u64, x130) + x118)), x140);1233 addcarryxU64(&x155, &x156, x154, ((@as(u64, x138) + @as(u64, x116)) + (@as(u64, x130) + x118)), x140);
1235 var x157: u64 = undefined;1234 var x157: u64 = undefined;
1236 var x158: u1 = undefined;1235 var x158: u1 = undefined;
1237 subborrowxU64(&x157, &x158, 0x0, x149, 0xffffffffffffffff);1236 subborrowxU64(&x157, &x158, 0x0, x149, 0xffffffffffffffff);
...@@ -1240,13 +1239,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1240,13 +1239,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1240 subborrowxU64(&x159, &x160, x158, x151, 0xffffffff);1239 subborrowxU64(&x159, &x160, x158, x151, 0xffffffff);
1241 var x161: u64 = undefined;1240 var x161: u64 = undefined;
1242 var x162: u1 = undefined;1241 var x162: u1 = undefined;
1243 subborrowxU64(&x161, &x162, x160, x153, cast(u64, 0x0));1242 subborrowxU64(&x161, &x162, x160, x153, @as(u64, 0x0));
1244 var x163: u64 = undefined;1243 var x163: u64 = undefined;
1245 var x164: u1 = undefined;1244 var x164: u1 = undefined;
1246 subborrowxU64(&x163, &x164, x162, x155, 0xffffffff00000001);1245 subborrowxU64(&x163, &x164, x162, x155, 0xffffffff00000001);
1247 var x165: u64 = undefined;1246 var x165: u64 = undefined;
1248 var x166: u1 = undefined;1247 var x166: u1 = undefined;
1249 subborrowxU64(&x165, &x166, x164, cast(u64, x156), cast(u64, 0x0));1248 subborrowxU64(&x165, &x166, x164, @as(u64, x156), @as(u64, 0x0));
1250 var x167: u64 = undefined;1249 var x167: u64 = undefined;
1251 cmovznzU64(&x167, x166, x157, x149);1250 cmovznzU64(&x167, x166, x157, x149);
1252 var x168: u64 = undefined;1251 var x168: u64 = undefined;
...@@ -1325,62 +1324,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1325,62 +1324,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1325 const x2 = (arg1[2]);1324 const x2 = (arg1[2]);
1326 const x3 = (arg1[1]);1325 const x3 = (arg1[1]);
1327 const x4 = (arg1[0]);1326 const x4 = (arg1[0]);
1328 const x5 = cast(u8, (x4 & cast(u64, 0xff)));1327 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));
1329 const x6 = (x4 >> 8);1328 const x6 = (x4 >> 8);
1330 const x7 = cast(u8, (x6 & cast(u64, 0xff)));1329 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));
1331 const x8 = (x6 >> 8);1330 const x8 = (x6 >> 8);
1332 const x9 = cast(u8, (x8 & cast(u64, 0xff)));1331 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));
1333 const x10 = (x8 >> 8);1332 const x10 = (x8 >> 8);
1334 const x11 = cast(u8, (x10 & cast(u64, 0xff)));1333 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));
1335 const x12 = (x10 >> 8);1334 const x12 = (x10 >> 8);
1336 const x13 = cast(u8, (x12 & cast(u64, 0xff)));1335 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));
1337 const x14 = (x12 >> 8);1336 const x14 = (x12 >> 8);
1338 const x15 = cast(u8, (x14 & cast(u64, 0xff)));1337 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));
1339 const x16 = (x14 >> 8);1338 const x16 = (x14 >> 8);
1340 const x17 = cast(u8, (x16 & cast(u64, 0xff)));1339 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));
1341 const x18 = cast(u8, (x16 >> 8));1340 const x18 = @truncate(u8, (x16 >> 8));
1342 const x19 = cast(u8, (x3 & cast(u64, 0xff)));1341 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));
1343 const x20 = (x3 >> 8);1342 const x20 = (x3 >> 8);
1344 const x21 = cast(u8, (x20 & cast(u64, 0xff)));1343 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));
1345 const x22 = (x20 >> 8);1344 const x22 = (x20 >> 8);
1346 const x23 = cast(u8, (x22 & cast(u64, 0xff)));1345 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));
1347 const x24 = (x22 >> 8);1346 const x24 = (x22 >> 8);
1348 const x25 = cast(u8, (x24 & cast(u64, 0xff)));1347 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));
1349 const x26 = (x24 >> 8);1348 const x26 = (x24 >> 8);
1350 const x27 = cast(u8, (x26 & cast(u64, 0xff)));1349 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));
1351 const x28 = (x26 >> 8);1350 const x28 = (x26 >> 8);
1352 const x29 = cast(u8, (x28 & cast(u64, 0xff)));1351 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));
1353 const x30 = (x28 >> 8);1352 const x30 = (x28 >> 8);
1354 const x31 = cast(u8, (x30 & cast(u64, 0xff)));1353 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));
1355 const x32 = cast(u8, (x30 >> 8));1354 const x32 = @truncate(u8, (x30 >> 8));
1356 const x33 = cast(u8, (x2 & cast(u64, 0xff)));1355 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));
1357 const x34 = (x2 >> 8);1356 const x34 = (x2 >> 8);
1358 const x35 = cast(u8, (x34 & cast(u64, 0xff)));1357 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));
1359 const x36 = (x34 >> 8);1358 const x36 = (x34 >> 8);
1360 const x37 = cast(u8, (x36 & cast(u64, 0xff)));1359 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));
1361 const x38 = (x36 >> 8);1360 const x38 = (x36 >> 8);
1362 const x39 = cast(u8, (x38 & cast(u64, 0xff)));1361 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));
1363 const x40 = (x38 >> 8);1362 const x40 = (x38 >> 8);
1364 const x41 = cast(u8, (x40 & cast(u64, 0xff)));1363 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));
1365 const x42 = (x40 >> 8);1364 const x42 = (x40 >> 8);
1366 const x43 = cast(u8, (x42 & cast(u64, 0xff)));1365 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));
1367 const x44 = (x42 >> 8);1366 const x44 = (x42 >> 8);
1368 const x45 = cast(u8, (x44 & cast(u64, 0xff)));1367 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));
1369 const x46 = cast(u8, (x44 >> 8));1368 const x46 = @truncate(u8, (x44 >> 8));
1370 const x47 = cast(u8, (x1 & cast(u64, 0xff)));1369 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));
1371 const x48 = (x1 >> 8);1370 const x48 = (x1 >> 8);
1372 const x49 = cast(u8, (x48 & cast(u64, 0xff)));1371 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));
1373 const x50 = (x48 >> 8);1372 const x50 = (x48 >> 8);
1374 const x51 = cast(u8, (x50 & cast(u64, 0xff)));1373 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));
1375 const x52 = (x50 >> 8);1374 const x52 = (x50 >> 8);
1376 const x53 = cast(u8, (x52 & cast(u64, 0xff)));1375 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));
1377 const x54 = (x52 >> 8);1376 const x54 = (x52 >> 8);
1378 const x55 = cast(u8, (x54 & cast(u64, 0xff)));1377 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));
1379 const x56 = (x54 >> 8);1378 const x56 = (x54 >> 8);
1380 const x57 = cast(u8, (x56 & cast(u64, 0xff)));1379 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));
1381 const x58 = (x56 >> 8);1380 const x58 = (x56 >> 8);
1382 const x59 = cast(u8, (x58 & cast(u64, 0xff)));1381 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));
1383 const x60 = cast(u8, (x58 >> 8));1382 const x60 = @truncate(u8, (x58 >> 8));
1384 out1[0] = x5;1383 out1[0] = x5;
1385 out1[1] = x7;1384 out1[1] = x7;
1386 out1[2] = x9;1385 out1[2] = x9;
...@@ -1430,60 +1429,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1430,60 +1429,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1430pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {1429pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {
1431 @setRuntimeSafety(mode == .Debug);1430 @setRuntimeSafety(mode == .Debug);
14321431
1433 const x1 = (cast(u64, (arg1[31])) << 56);1432 const x1 = (@as(u64, (arg1[31])) << 56);
1434 const x2 = (cast(u64, (arg1[30])) << 48);1433 const x2 = (@as(u64, (arg1[30])) << 48);
1435 const x3 = (cast(u64, (arg1[29])) << 40);1434 const x3 = (@as(u64, (arg1[29])) << 40);
1436 const x4 = (cast(u64, (arg1[28])) << 32);1435 const x4 = (@as(u64, (arg1[28])) << 32);
1437 const x5 = (cast(u64, (arg1[27])) << 24);1436 const x5 = (@as(u64, (arg1[27])) << 24);
1438 const x6 = (cast(u64, (arg1[26])) << 16);1437 const x6 = (@as(u64, (arg1[26])) << 16);
1439 const x7 = (cast(u64, (arg1[25])) << 8);1438 const x7 = (@as(u64, (arg1[25])) << 8);
1440 const x8 = (arg1[24]);1439 const x8 = (arg1[24]);
1441 const x9 = (cast(u64, (arg1[23])) << 56);1440 const x9 = (@as(u64, (arg1[23])) << 56);
1442 const x10 = (cast(u64, (arg1[22])) << 48);1441 const x10 = (@as(u64, (arg1[22])) << 48);
1443 const x11 = (cast(u64, (arg1[21])) << 40);1442 const x11 = (@as(u64, (arg1[21])) << 40);
1444 const x12 = (cast(u64, (arg1[20])) << 32);1443 const x12 = (@as(u64, (arg1[20])) << 32);
1445 const x13 = (cast(u64, (arg1[19])) << 24);1444 const x13 = (@as(u64, (arg1[19])) << 24);
1446 const x14 = (cast(u64, (arg1[18])) << 16);1445 const x14 = (@as(u64, (arg1[18])) << 16);
1447 const x15 = (cast(u64, (arg1[17])) << 8);1446 const x15 = (@as(u64, (arg1[17])) << 8);
1448 const x16 = (arg1[16]);1447 const x16 = (arg1[16]);
1449 const x17 = (cast(u64, (arg1[15])) << 56);1448 const x17 = (@as(u64, (arg1[15])) << 56);
1450 const x18 = (cast(u64, (arg1[14])) << 48);1449 const x18 = (@as(u64, (arg1[14])) << 48);
1451 const x19 = (cast(u64, (arg1[13])) << 40);1450 const x19 = (@as(u64, (arg1[13])) << 40);
1452 const x20 = (cast(u64, (arg1[12])) << 32);1451 const x20 = (@as(u64, (arg1[12])) << 32);
1453 const x21 = (cast(u64, (arg1[11])) << 24);1452 const x21 = (@as(u64, (arg1[11])) << 24);
1454 const x22 = (cast(u64, (arg1[10])) << 16);1453 const x22 = (@as(u64, (arg1[10])) << 16);
1455 const x23 = (cast(u64, (arg1[9])) << 8);1454 const x23 = (@as(u64, (arg1[9])) << 8);
1456 const x24 = (arg1[8]);1455 const x24 = (arg1[8]);
1457 const x25 = (cast(u64, (arg1[7])) << 56);1456 const x25 = (@as(u64, (arg1[7])) << 56);
1458 const x26 = (cast(u64, (arg1[6])) << 48);1457 const x26 = (@as(u64, (arg1[6])) << 48);
1459 const x27 = (cast(u64, (arg1[5])) << 40);1458 const x27 = (@as(u64, (arg1[5])) << 40);
1460 const x28 = (cast(u64, (arg1[4])) << 32);1459 const x28 = (@as(u64, (arg1[4])) << 32);
1461 const x29 = (cast(u64, (arg1[3])) << 24);1460 const x29 = (@as(u64, (arg1[3])) << 24);
1462 const x30 = (cast(u64, (arg1[2])) << 16);1461 const x30 = (@as(u64, (arg1[2])) << 16);
1463 const x31 = (cast(u64, (arg1[1])) << 8);1462 const x31 = (@as(u64, (arg1[1])) << 8);
1464 const x32 = (arg1[0]);1463 const x32 = (arg1[0]);
1465 const x33 = (x31 + cast(u64, x32));1464 const x33 = (x31 + @as(u64, x32));
1466 const x34 = (x30 + x33);1465 const x34 = (x30 + x33);
1467 const x35 = (x29 + x34);1466 const x35 = (x29 + x34);
1468 const x36 = (x28 + x35);1467 const x36 = (x28 + x35);
1469 const x37 = (x27 + x36);1468 const x37 = (x27 + x36);
1470 const x38 = (x26 + x37);1469 const x38 = (x26 + x37);
1471 const x39 = (x25 + x38);1470 const x39 = (x25 + x38);
1472 const x40 = (x23 + cast(u64, x24));1471 const x40 = (x23 + @as(u64, x24));
1473 const x41 = (x22 + x40);1472 const x41 = (x22 + x40);
1474 const x42 = (x21 + x41);1473 const x42 = (x21 + x41);
1475 const x43 = (x20 + x42);1474 const x43 = (x20 + x42);
1476 const x44 = (x19 + x43);1475 const x44 = (x19 + x43);
1477 const x45 = (x18 + x44);1476 const x45 = (x18 + x44);
1478 const x46 = (x17 + x45);1477 const x46 = (x17 + x45);
1479 const x47 = (x15 + cast(u64, x16));1478 const x47 = (x15 + @as(u64, x16));
1480 const x48 = (x14 + x47);1479 const x48 = (x14 + x47);
1481 const x49 = (x13 + x48);1480 const x49 = (x13 + x48);
1482 const x50 = (x12 + x49);1481 const x50 = (x12 + x49);
1483 const x51 = (x11 + x50);1482 const x51 = (x11 + x50);
1484 const x52 = (x10 + x51);1483 const x52 = (x10 + x51);
1485 const x53 = (x9 + x52);1484 const x53 = (x9 + x52);
1486 const x54 = (x7 + cast(u64, x8));1485 const x54 = (x7 + @as(u64, x8));
1487 const x55 = (x6 + x54);1486 const x55 = (x6 + x54);
1488 const x56 = (x5 + x55);1487 const x56 = (x5 + x55);
1489 const x57 = (x4 + x56);1488 const x57 = (x4 + x56);
...@@ -1505,7 +1504,7 @@ pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {...@@ -1505,7 +1504,7 @@ pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {
1505pub fn setOne(out1: *MontgomeryDomainFieldElement) void {1504pub fn setOne(out1: *MontgomeryDomainFieldElement) void {
1506 @setRuntimeSafety(mode == .Debug);1505 @setRuntimeSafety(mode == .Debug);
15071506
1508 out1[0] = cast(u64, 0x1);1507 out1[0] = @as(u64, 0x1);
1509 out1[1] = 0xffffffff00000000;1508 out1[1] = 0xffffffff00000000;
1510 out1[2] = 0xffffffffffffffff;1509 out1[2] = 0xffffffffffffffff;
1511 out1[3] = 0xfffffffe;1510 out1[3] = 0xfffffffe;
...@@ -1524,9 +1523,9 @@ pub fn msat(out1: *[5]u64) void {...@@ -1524,9 +1523,9 @@ pub fn msat(out1: *[5]u64) void {
15241523
1525 out1[0] = 0xffffffffffffffff;1524 out1[0] = 0xffffffffffffffff;
1526 out1[1] = 0xffffffff;1525 out1[1] = 0xffffffff;
1527 out1[2] = cast(u64, 0x0);1526 out1[2] = @as(u64, 0x0);
1528 out1[3] = 0xffffffff00000001;1527 out1[3] = 0xffffffff00000001;
1529 out1[4] = cast(u64, 0x0);1528 out1[4] = @as(u64, 0x0);
1530}1529}
15311530
1532/// The function divstep computes a divstep.1531/// The function divstep computes a divstep.
...@@ -1562,11 +1561,11 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1562,11 +1561,11 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
15621561
1563 var x1: u64 = undefined;1562 var x1: u64 = undefined;
1564 var x2: u1 = undefined;1563 var x2: u1 = undefined;
1565 addcarryxU64(&x1, &x2, 0x0, (~arg1), cast(u64, 0x1));1564 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));
1566 const x3 = (cast(u1, (x1 >> 63)) & cast(u1, ((arg3[0]) & cast(u64, 0x1))));1565 const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & @as(u64, 0x1))));
1567 var x4: u64 = undefined;1566 var x4: u64 = undefined;
1568 var x5: u1 = undefined;1567 var x5: u1 = undefined;
1569 addcarryxU64(&x4, &x5, 0x0, (~arg1), cast(u64, 0x1));1568 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));
1570 var x6: u64 = undefined;1569 var x6: u64 = undefined;
1571 cmovznzU64(&x6, x3, arg1, x4);1570 cmovznzU64(&x6, x3, arg1, x4);
1572 var x7: u64 = undefined;1571 var x7: u64 = undefined;
...@@ -1581,19 +1580,19 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1581,19 +1580,19 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1581 cmovznzU64(&x11, x3, (arg2[4]), (arg3[4]));1580 cmovznzU64(&x11, x3, (arg2[4]), (arg3[4]));
1582 var x12: u64 = undefined;1581 var x12: u64 = undefined;
1583 var x13: u1 = undefined;1582 var x13: u1 = undefined;
1584 addcarryxU64(&x12, &x13, 0x0, cast(u64, 0x1), (~(arg2[0])));1583 addcarryxU64(&x12, &x13, 0x0, @as(u64, 0x1), (~(arg2[0])));
1585 var x14: u64 = undefined;1584 var x14: u64 = undefined;
1586 var x15: u1 = undefined;1585 var x15: u1 = undefined;
1587 addcarryxU64(&x14, &x15, x13, cast(u64, 0x0), (~(arg2[1])));1586 addcarryxU64(&x14, &x15, x13, @as(u64, 0x0), (~(arg2[1])));
1588 var x16: u64 = undefined;1587 var x16: u64 = undefined;
1589 var x17: u1 = undefined;1588 var x17: u1 = undefined;
1590 addcarryxU64(&x16, &x17, x15, cast(u64, 0x0), (~(arg2[2])));1589 addcarryxU64(&x16, &x17, x15, @as(u64, 0x0), (~(arg2[2])));
1591 var x18: u64 = undefined;1590 var x18: u64 = undefined;
1592 var x19: u1 = undefined;1591 var x19: u1 = undefined;
1593 addcarryxU64(&x18, &x19, x17, cast(u64, 0x0), (~(arg2[3])));1592 addcarryxU64(&x18, &x19, x17, @as(u64, 0x0), (~(arg2[3])));
1594 var x20: u64 = undefined;1593 var x20: u64 = undefined;
1595 var x21: u1 = undefined;1594 var x21: u1 = undefined;
1596 addcarryxU64(&x20, &x21, x19, cast(u64, 0x0), (~(arg2[4])));1595 addcarryxU64(&x20, &x21, x19, @as(u64, 0x0), (~(arg2[4])));
1597 var x22: u64 = undefined;1596 var x22: u64 = undefined;
1598 cmovznzU64(&x22, x3, (arg3[0]), x12);1597 cmovznzU64(&x22, x3, (arg3[0]), x12);
1599 var x23: u64 = undefined;1598 var x23: u64 = undefined;
...@@ -1632,31 +1631,31 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1632,31 +1631,31 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1632 subborrowxU64(&x41, &x42, x40, x33, 0xffffffff);1631 subborrowxU64(&x41, &x42, x40, x33, 0xffffffff);
1633 var x43: u64 = undefined;1632 var x43: u64 = undefined;
1634 var x44: u1 = undefined;1633 var x44: u1 = undefined;
1635 subborrowxU64(&x43, &x44, x42, x35, cast(u64, 0x0));1634 subborrowxU64(&x43, &x44, x42, x35, @as(u64, 0x0));
1636 var x45: u64 = undefined;1635 var x45: u64 = undefined;
1637 var x46: u1 = undefined;1636 var x46: u1 = undefined;
1638 subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000001);1637 subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000001);
1639 var x47: u64 = undefined;1638 var x47: u64 = undefined;
1640 var x48: u1 = undefined;1639 var x48: u1 = undefined;
1641 subborrowxU64(&x47, &x48, x46, cast(u64, x38), cast(u64, 0x0));1640 subborrowxU64(&x47, &x48, x46, @as(u64, x38), @as(u64, 0x0));
1642 const x49 = (arg4[3]);1641 const x49 = (arg4[3]);
1643 const x50 = (arg4[2]);1642 const x50 = (arg4[2]);
1644 const x51 = (arg4[1]);1643 const x51 = (arg4[1]);
1645 const x52 = (arg4[0]);1644 const x52 = (arg4[0]);
1646 var x53: u64 = undefined;1645 var x53: u64 = undefined;
1647 var x54: u1 = undefined;1646 var x54: u1 = undefined;
1648 subborrowxU64(&x53, &x54, 0x0, cast(u64, 0x0), x52);1647 subborrowxU64(&x53, &x54, 0x0, @as(u64, 0x0), x52);
1649 var x55: u64 = undefined;1648 var x55: u64 = undefined;
1650 var x56: u1 = undefined;1649 var x56: u1 = undefined;
1651 subborrowxU64(&x55, &x56, x54, cast(u64, 0x0), x51);1650 subborrowxU64(&x55, &x56, x54, @as(u64, 0x0), x51);
1652 var x57: u64 = undefined;1651 var x57: u64 = undefined;
1653 var x58: u1 = undefined;1652 var x58: u1 = undefined;
1654 subborrowxU64(&x57, &x58, x56, cast(u64, 0x0), x50);1653 subborrowxU64(&x57, &x58, x56, @as(u64, 0x0), x50);
1655 var x59: u64 = undefined;1654 var x59: u64 = undefined;
1656 var x60: u1 = undefined;1655 var x60: u1 = undefined;
1657 subborrowxU64(&x59, &x60, x58, cast(u64, 0x0), x49);1656 subborrowxU64(&x59, &x60, x58, @as(u64, 0x0), x49);
1658 var x61: u64 = undefined;1657 var x61: u64 = undefined;
1659 cmovznzU64(&x61, x60, cast(u64, 0x0), 0xffffffffffffffff);1658 cmovznzU64(&x61, x60, @as(u64, 0x0), 0xffffffffffffffff);
1660 var x62: u64 = undefined;1659 var x62: u64 = undefined;
1661 var x63: u1 = undefined;1660 var x63: u1 = undefined;
1662 addcarryxU64(&x62, &x63, 0x0, x53, x61);1661 addcarryxU64(&x62, &x63, 0x0, x53, x61);
...@@ -1665,7 +1664,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1665,7 +1664,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1665 addcarryxU64(&x64, &x65, x63, x55, (x61 & 0xffffffff));1664 addcarryxU64(&x64, &x65, x63, x55, (x61 & 0xffffffff));
1666 var x66: u64 = undefined;1665 var x66: u64 = undefined;
1667 var x67: u1 = undefined;1666 var x67: u1 = undefined;
1668 addcarryxU64(&x66, &x67, x65, x57, cast(u64, 0x0));1667 addcarryxU64(&x66, &x67, x65, x57, @as(u64, 0x0));
1669 var x68: u64 = undefined;1668 var x68: u64 = undefined;
1670 var x69: u1 = undefined;1669 var x69: u1 = undefined;
1671 addcarryxU64(&x68, &x69, x67, x59, (x61 & 0xffffffff00000001));1670 addcarryxU64(&x68, &x69, x67, x59, (x61 & 0xffffffff00000001));
...@@ -1677,17 +1676,17 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1677,17 +1676,17 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1677 cmovznzU64(&x72, x3, (arg5[2]), x66);1676 cmovznzU64(&x72, x3, (arg5[2]), x66);
1678 var x73: u64 = undefined;1677 var x73: u64 = undefined;
1679 cmovznzU64(&x73, x3, (arg5[3]), x68);1678 cmovznzU64(&x73, x3, (arg5[3]), x68);
1680 const x74 = cast(u1, (x22 & cast(u64, 0x1)));1679 const x74 = @truncate(u1, (x22 & @as(u64, 0x1)));
1681 var x75: u64 = undefined;1680 var x75: u64 = undefined;
1682 cmovznzU64(&x75, x74, cast(u64, 0x0), x7);1681 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
1683 var x76: u64 = undefined;1682 var x76: u64 = undefined;
1684 cmovznzU64(&x76, x74, cast(u64, 0x0), x8);1683 cmovznzU64(&x76, x74, @as(u64, 0x0), x8);
1685 var x77: u64 = undefined;1684 var x77: u64 = undefined;
1686 cmovznzU64(&x77, x74, cast(u64, 0x0), x9);1685 cmovznzU64(&x77, x74, @as(u64, 0x0), x9);
1687 var x78: u64 = undefined;1686 var x78: u64 = undefined;
1688 cmovznzU64(&x78, x74, cast(u64, 0x0), x10);1687 cmovznzU64(&x78, x74, @as(u64, 0x0), x10);
1689 var x79: u64 = undefined;1688 var x79: u64 = undefined;
1690 cmovznzU64(&x79, x74, cast(u64, 0x0), x11);1689 cmovznzU64(&x79, x74, @as(u64, 0x0), x11);
1691 var x80: u64 = undefined;1690 var x80: u64 = undefined;
1692 var x81: u1 = undefined;1691 var x81: u1 = undefined;
1693 addcarryxU64(&x80, &x81, 0x0, x22, x75);1692 addcarryxU64(&x80, &x81, 0x0, x22, x75);
...@@ -1704,13 +1703,13 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1704,13 +1703,13 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1704 var x89: u1 = undefined;1703 var x89: u1 = undefined;
1705 addcarryxU64(&x88, &x89, x87, x26, x79);1704 addcarryxU64(&x88, &x89, x87, x26, x79);
1706 var x90: u64 = undefined;1705 var x90: u64 = undefined;
1707 cmovznzU64(&x90, x74, cast(u64, 0x0), x27);1706 cmovznzU64(&x90, x74, @as(u64, 0x0), x27);
1708 var x91: u64 = undefined;1707 var x91: u64 = undefined;
1709 cmovznzU64(&x91, x74, cast(u64, 0x0), x28);1708 cmovznzU64(&x91, x74, @as(u64, 0x0), x28);
1710 var x92: u64 = undefined;1709 var x92: u64 = undefined;
1711 cmovznzU64(&x92, x74, cast(u64, 0x0), x29);1710 cmovznzU64(&x92, x74, @as(u64, 0x0), x29);
1712 var x93: u64 = undefined;1711 var x93: u64 = undefined;
1713 cmovznzU64(&x93, x74, cast(u64, 0x0), x30);1712 cmovznzU64(&x93, x74, @as(u64, 0x0), x30);
1714 var x94: u64 = undefined;1713 var x94: u64 = undefined;
1715 var x95: u1 = undefined;1714 var x95: u1 = undefined;
1716 addcarryxU64(&x94, &x95, 0x0, x70, x90);1715 addcarryxU64(&x94, &x95, 0x0, x70, x90);
...@@ -1731,16 +1730,16 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1731,16 +1730,16 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1731 subborrowxU64(&x104, &x105, x103, x96, 0xffffffff);1730 subborrowxU64(&x104, &x105, x103, x96, 0xffffffff);
1732 var x106: u64 = undefined;1731 var x106: u64 = undefined;
1733 var x107: u1 = undefined;1732 var x107: u1 = undefined;
1734 subborrowxU64(&x106, &x107, x105, x98, cast(u64, 0x0));1733 subborrowxU64(&x106, &x107, x105, x98, @as(u64, 0x0));
1735 var x108: u64 = undefined;1734 var x108: u64 = undefined;
1736 var x109: u1 = undefined;1735 var x109: u1 = undefined;
1737 subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000001);1736 subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000001);
1738 var x110: u64 = undefined;1737 var x110: u64 = undefined;
1739 var x111: u1 = undefined;1738 var x111: u1 = undefined;
1740 subborrowxU64(&x110, &x111, x109, cast(u64, x101), cast(u64, 0x0));1739 subborrowxU64(&x110, &x111, x109, @as(u64, x101), @as(u64, 0x0));
1741 var x112: u64 = undefined;1740 var x112: u64 = undefined;
1742 var x113: u1 = undefined;1741 var x113: u1 = undefined;
1743 addcarryxU64(&x112, &x113, 0x0, x6, cast(u64, 0x1));1742 addcarryxU64(&x112, &x113, 0x0, x6, @as(u64, 0x1));
1744 const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff));1743 const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff));
1745 const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff));1744 const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff));
1746 const x116 = ((x84 >> 1) | ((x86 << 63) & 0xffffffffffffffff));1745 const x116 = ((x84 >> 1) | ((x86 << 63) & 0xffffffffffffffff));
lib/std/crypto/pcurves/p256/p256_scalar_64.zig+144-145
...@@ -18,7 +18,6 @@...@@ -18,7 +18,6 @@
18// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^25618// if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256
1919
20const std = @import("std");20const std = @import("std");
21const cast = std.meta.cast;
22const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels21const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels
2322
24// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.23// The type MontgomeryDomainFieldElement is a field element in the Montgomery domain.
...@@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
148 var x17: u64 = undefined;147 var x17: u64 = undefined;
149 var x18: u1 = undefined;148 var x18: u1 = undefined;
150 addcarryxU64(&x17, &x18, x16, x8, x5);149 addcarryxU64(&x17, &x18, x16, x8, x5);
151 const x19 = (cast(u64, x18) + x6);150 const x19 = (@as(u64, x18) + x6);
152 var x20: u64 = undefined;151 var x20: u64 = undefined;
153 var x21: u64 = undefined;152 var x21: u64 = undefined;
154 mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f);153 mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f);
...@@ -173,7 +172,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -173,7 +172,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
173 var x34: u64 = undefined;172 var x34: u64 = undefined;
174 var x35: u1 = undefined;173 var x35: u1 = undefined;
175 addcarryxU64(&x34, &x35, x33, x25, x22);174 addcarryxU64(&x34, &x35, x33, x25, x22);
176 const x36 = (cast(u64, x35) + x23);175 const x36 = (@as(u64, x35) + x23);
177 var x37: u64 = undefined;176 var x37: u64 = undefined;
178 var x38: u1 = undefined;177 var x38: u1 = undefined;
179 addcarryxU64(&x37, &x38, 0x0, x11, x28);178 addcarryxU64(&x37, &x38, 0x0, x11, x28);
...@@ -210,7 +209,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -210,7 +209,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
210 var x59: u64 = undefined;209 var x59: u64 = undefined;
211 var x60: u1 = undefined;210 var x60: u1 = undefined;
212 addcarryxU64(&x59, &x60, x58, x50, x47);211 addcarryxU64(&x59, &x60, x58, x50, x47);
213 const x61 = (cast(u64, x60) + x48);212 const x61 = (@as(u64, x60) + x48);
214 var x62: u64 = undefined;213 var x62: u64 = undefined;
215 var x63: u1 = undefined;214 var x63: u1 = undefined;
216 addcarryxU64(&x62, &x63, 0x0, x39, x53);215 addcarryxU64(&x62, &x63, 0x0, x39, x53);
...@@ -225,7 +224,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -225,7 +224,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
225 addcarryxU64(&x68, &x69, x67, x45, x59);224 addcarryxU64(&x68, &x69, x67, x45, x59);
226 var x70: u64 = undefined;225 var x70: u64 = undefined;
227 var x71: u1 = undefined;226 var x71: u1 = undefined;
228 addcarryxU64(&x70, &x71, x69, cast(u64, x46), x61);227 addcarryxU64(&x70, &x71, x69, @as(u64, x46), x61);
229 var x72: u64 = undefined;228 var x72: u64 = undefined;
230 var x73: u64 = undefined;229 var x73: u64 = undefined;
231 mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f);230 mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f);
...@@ -250,7 +249,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -250,7 +249,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
250 var x86: u64 = undefined;249 var x86: u64 = undefined;
251 var x87: u1 = undefined;250 var x87: u1 = undefined;
252 addcarryxU64(&x86, &x87, x85, x77, x74);251 addcarryxU64(&x86, &x87, x85, x77, x74);
253 const x88 = (cast(u64, x87) + x75);252 const x88 = (@as(u64, x87) + x75);
254 var x89: u64 = undefined;253 var x89: u64 = undefined;
255 var x90: u1 = undefined;254 var x90: u1 = undefined;
256 addcarryxU64(&x89, &x90, 0x0, x62, x80);255 addcarryxU64(&x89, &x90, 0x0, x62, x80);
...@@ -266,7 +265,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -266,7 +265,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
266 var x97: u64 = undefined;265 var x97: u64 = undefined;
267 var x98: u1 = undefined;266 var x98: u1 = undefined;
268 addcarryxU64(&x97, &x98, x96, x70, x88);267 addcarryxU64(&x97, &x98, x96, x70, x88);
269 const x99 = (cast(u64, x98) + cast(u64, x71));268 const x99 = (@as(u64, x98) + @as(u64, x71));
270 var x100: u64 = undefined;269 var x100: u64 = undefined;
271 var x101: u64 = undefined;270 var x101: u64 = undefined;
272 mulxU64(&x100, &x101, x2, (arg2[3]));271 mulxU64(&x100, &x101, x2, (arg2[3]));
...@@ -288,7 +287,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -288,7 +287,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
288 var x112: u64 = undefined;287 var x112: u64 = undefined;
289 var x113: u1 = undefined;288 var x113: u1 = undefined;
290 addcarryxU64(&x112, &x113, x111, x103, x100);289 addcarryxU64(&x112, &x113, x111, x103, x100);
291 const x114 = (cast(u64, x113) + x101);290 const x114 = (@as(u64, x113) + x101);
292 var x115: u64 = undefined;291 var x115: u64 = undefined;
293 var x116: u1 = undefined;292 var x116: u1 = undefined;
294 addcarryxU64(&x115, &x116, 0x0, x91, x106);293 addcarryxU64(&x115, &x116, 0x0, x91, x106);
...@@ -328,7 +327,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -328,7 +327,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
328 var x139: u64 = undefined;327 var x139: u64 = undefined;
329 var x140: u1 = undefined;328 var x140: u1 = undefined;
330 addcarryxU64(&x139, &x140, x138, x130, x127);329 addcarryxU64(&x139, &x140, x138, x130, x127);
331 const x141 = (cast(u64, x140) + x128);330 const x141 = (@as(u64, x140) + x128);
332 var x142: u64 = undefined;331 var x142: u64 = undefined;
333 var x143: u1 = undefined;332 var x143: u1 = undefined;
334 addcarryxU64(&x142, &x143, 0x0, x115, x133);333 addcarryxU64(&x142, &x143, 0x0, x115, x133);
...@@ -344,7 +343,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -344,7 +343,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
344 var x150: u64 = undefined;343 var x150: u64 = undefined;
345 var x151: u1 = undefined;344 var x151: u1 = undefined;
346 addcarryxU64(&x150, &x151, x149, x123, x141);345 addcarryxU64(&x150, &x151, x149, x123, x141);
347 const x152 = (cast(u64, x151) + cast(u64, x124));346 const x152 = (@as(u64, x151) + @as(u64, x124));
348 var x153: u64 = undefined;347 var x153: u64 = undefined;
349 var x154: u64 = undefined;348 var x154: u64 = undefined;
350 mulxU64(&x153, &x154, x3, (arg2[3]));349 mulxU64(&x153, &x154, x3, (arg2[3]));
...@@ -366,7 +365,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -366,7 +365,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
366 var x165: u64 = undefined;365 var x165: u64 = undefined;
367 var x166: u1 = undefined;366 var x166: u1 = undefined;
368 addcarryxU64(&x165, &x166, x164, x156, x153);367 addcarryxU64(&x165, &x166, x164, x156, x153);
369 const x167 = (cast(u64, x166) + x154);368 const x167 = (@as(u64, x166) + x154);
370 var x168: u64 = undefined;369 var x168: u64 = undefined;
371 var x169: u1 = undefined;370 var x169: u1 = undefined;
372 addcarryxU64(&x168, &x169, 0x0, x144, x159);371 addcarryxU64(&x168, &x169, 0x0, x144, x159);
...@@ -406,7 +405,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -406,7 +405,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
406 var x192: u64 = undefined;405 var x192: u64 = undefined;
407 var x193: u1 = undefined;406 var x193: u1 = undefined;
408 addcarryxU64(&x192, &x193, x191, x183, x180);407 addcarryxU64(&x192, &x193, x191, x183, x180);
409 const x194 = (cast(u64, x193) + x181);408 const x194 = (@as(u64, x193) + x181);
410 var x195: u64 = undefined;409 var x195: u64 = undefined;
411 var x196: u1 = undefined;410 var x196: u1 = undefined;
412 addcarryxU64(&x195, &x196, 0x0, x168, x186);411 addcarryxU64(&x195, &x196, 0x0, x168, x186);
...@@ -422,7 +421,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -422,7 +421,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
422 var x203: u64 = undefined;421 var x203: u64 = undefined;
423 var x204: u1 = undefined;422 var x204: u1 = undefined;
424 addcarryxU64(&x203, &x204, x202, x176, x194);423 addcarryxU64(&x203, &x204, x202, x176, x194);
425 const x205 = (cast(u64, x204) + cast(u64, x177));424 const x205 = (@as(u64, x204) + @as(u64, x177));
426 var x206: u64 = undefined;425 var x206: u64 = undefined;
427 var x207: u1 = undefined;426 var x207: u1 = undefined;
428 subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551);427 subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551);
...@@ -437,7 +436,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -437,7 +436,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
437 subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000);436 subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000);
438 var x214: u64 = undefined;437 var x214: u64 = undefined;
439 var x215: u1 = undefined;438 var x215: u1 = undefined;
440 subborrowxU64(&x214, &x215, x213, x205, cast(u64, 0x0));439 subborrowxU64(&x214, &x215, x213, x205, @as(u64, 0x0));
441 var x216: u64 = undefined;440 var x216: u64 = undefined;
442 cmovznzU64(&x216, x215, x206, x197);441 cmovznzU64(&x216, x215, x206, x197);
443 var x217: u64 = undefined;442 var x217: u64 = undefined;
...@@ -488,7 +487,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -488,7 +487,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
488 var x17: u64 = undefined;487 var x17: u64 = undefined;
489 var x18: u1 = undefined;488 var x18: u1 = undefined;
490 addcarryxU64(&x17, &x18, x16, x8, x5);489 addcarryxU64(&x17, &x18, x16, x8, x5);
491 const x19 = (cast(u64, x18) + x6);490 const x19 = (@as(u64, x18) + x6);
492 var x20: u64 = undefined;491 var x20: u64 = undefined;
493 var x21: u64 = undefined;492 var x21: u64 = undefined;
494 mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f);493 mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f);
...@@ -513,7 +512,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -513,7 +512,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
513 var x34: u64 = undefined;512 var x34: u64 = undefined;
514 var x35: u1 = undefined;513 var x35: u1 = undefined;
515 addcarryxU64(&x34, &x35, x33, x25, x22);514 addcarryxU64(&x34, &x35, x33, x25, x22);
516 const x36 = (cast(u64, x35) + x23);515 const x36 = (@as(u64, x35) + x23);
517 var x37: u64 = undefined;516 var x37: u64 = undefined;
518 var x38: u1 = undefined;517 var x38: u1 = undefined;
519 addcarryxU64(&x37, &x38, 0x0, x11, x28);518 addcarryxU64(&x37, &x38, 0x0, x11, x28);
...@@ -550,7 +549,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -550,7 +549,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
550 var x59: u64 = undefined;549 var x59: u64 = undefined;
551 var x60: u1 = undefined;550 var x60: u1 = undefined;
552 addcarryxU64(&x59, &x60, x58, x50, x47);551 addcarryxU64(&x59, &x60, x58, x50, x47);
553 const x61 = (cast(u64, x60) + x48);552 const x61 = (@as(u64, x60) + x48);
554 var x62: u64 = undefined;553 var x62: u64 = undefined;
555 var x63: u1 = undefined;554 var x63: u1 = undefined;
556 addcarryxU64(&x62, &x63, 0x0, x39, x53);555 addcarryxU64(&x62, &x63, 0x0, x39, x53);
...@@ -565,7 +564,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -565,7 +564,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
565 addcarryxU64(&x68, &x69, x67, x45, x59);564 addcarryxU64(&x68, &x69, x67, x45, x59);
566 var x70: u64 = undefined;565 var x70: u64 = undefined;
567 var x71: u1 = undefined;566 var x71: u1 = undefined;
568 addcarryxU64(&x70, &x71, x69, cast(u64, x46), x61);567 addcarryxU64(&x70, &x71, x69, @as(u64, x46), x61);
569 var x72: u64 = undefined;568 var x72: u64 = undefined;
570 var x73: u64 = undefined;569 var x73: u64 = undefined;
571 mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f);570 mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f);
...@@ -590,7 +589,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -590,7 +589,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
590 var x86: u64 = undefined;589 var x86: u64 = undefined;
591 var x87: u1 = undefined;590 var x87: u1 = undefined;
592 addcarryxU64(&x86, &x87, x85, x77, x74);591 addcarryxU64(&x86, &x87, x85, x77, x74);
593 const x88 = (cast(u64, x87) + x75);592 const x88 = (@as(u64, x87) + x75);
594 var x89: u64 = undefined;593 var x89: u64 = undefined;
595 var x90: u1 = undefined;594 var x90: u1 = undefined;
596 addcarryxU64(&x89, &x90, 0x0, x62, x80);595 addcarryxU64(&x89, &x90, 0x0, x62, x80);
...@@ -606,7 +605,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -606,7 +605,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
606 var x97: u64 = undefined;605 var x97: u64 = undefined;
607 var x98: u1 = undefined;606 var x98: u1 = undefined;
608 addcarryxU64(&x97, &x98, x96, x70, x88);607 addcarryxU64(&x97, &x98, x96, x70, x88);
609 const x99 = (cast(u64, x98) + cast(u64, x71));608 const x99 = (@as(u64, x98) + @as(u64, x71));
610 var x100: u64 = undefined;609 var x100: u64 = undefined;
611 var x101: u64 = undefined;610 var x101: u64 = undefined;
612 mulxU64(&x100, &x101, x2, (arg1[3]));611 mulxU64(&x100, &x101, x2, (arg1[3]));
...@@ -628,7 +627,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -628,7 +627,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
628 var x112: u64 = undefined;627 var x112: u64 = undefined;
629 var x113: u1 = undefined;628 var x113: u1 = undefined;
630 addcarryxU64(&x112, &x113, x111, x103, x100);629 addcarryxU64(&x112, &x113, x111, x103, x100);
631 const x114 = (cast(u64, x113) + x101);630 const x114 = (@as(u64, x113) + x101);
632 var x115: u64 = undefined;631 var x115: u64 = undefined;
633 var x116: u1 = undefined;632 var x116: u1 = undefined;
634 addcarryxU64(&x115, &x116, 0x0, x91, x106);633 addcarryxU64(&x115, &x116, 0x0, x91, x106);
...@@ -668,7 +667,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -668,7 +667,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
668 var x139: u64 = undefined;667 var x139: u64 = undefined;
669 var x140: u1 = undefined;668 var x140: u1 = undefined;
670 addcarryxU64(&x139, &x140, x138, x130, x127);669 addcarryxU64(&x139, &x140, x138, x130, x127);
671 const x141 = (cast(u64, x140) + x128);670 const x141 = (@as(u64, x140) + x128);
672 var x142: u64 = undefined;671 var x142: u64 = undefined;
673 var x143: u1 = undefined;672 var x143: u1 = undefined;
674 addcarryxU64(&x142, &x143, 0x0, x115, x133);673 addcarryxU64(&x142, &x143, 0x0, x115, x133);
...@@ -684,7 +683,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -684,7 +683,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
684 var x150: u64 = undefined;683 var x150: u64 = undefined;
685 var x151: u1 = undefined;684 var x151: u1 = undefined;
686 addcarryxU64(&x150, &x151, x149, x123, x141);685 addcarryxU64(&x150, &x151, x149, x123, x141);
687 const x152 = (cast(u64, x151) + cast(u64, x124));686 const x152 = (@as(u64, x151) + @as(u64, x124));
688 var x153: u64 = undefined;687 var x153: u64 = undefined;
689 var x154: u64 = undefined;688 var x154: u64 = undefined;
690 mulxU64(&x153, &x154, x3, (arg1[3]));689 mulxU64(&x153, &x154, x3, (arg1[3]));
...@@ -706,7 +705,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -706,7 +705,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
706 var x165: u64 = undefined;705 var x165: u64 = undefined;
707 var x166: u1 = undefined;706 var x166: u1 = undefined;
708 addcarryxU64(&x165, &x166, x164, x156, x153);707 addcarryxU64(&x165, &x166, x164, x156, x153);
709 const x167 = (cast(u64, x166) + x154);708 const x167 = (@as(u64, x166) + x154);
710 var x168: u64 = undefined;709 var x168: u64 = undefined;
711 var x169: u1 = undefined;710 var x169: u1 = undefined;
712 addcarryxU64(&x168, &x169, 0x0, x144, x159);711 addcarryxU64(&x168, &x169, 0x0, x144, x159);
...@@ -746,7 +745,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -746,7 +745,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
746 var x192: u64 = undefined;745 var x192: u64 = undefined;
747 var x193: u1 = undefined;746 var x193: u1 = undefined;
748 addcarryxU64(&x192, &x193, x191, x183, x180);747 addcarryxU64(&x192, &x193, x191, x183, x180);
749 const x194 = (cast(u64, x193) + x181);748 const x194 = (@as(u64, x193) + x181);
750 var x195: u64 = undefined;749 var x195: u64 = undefined;
751 var x196: u1 = undefined;750 var x196: u1 = undefined;
752 addcarryxU64(&x195, &x196, 0x0, x168, x186);751 addcarryxU64(&x195, &x196, 0x0, x168, x186);
...@@ -762,7 +761,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -762,7 +761,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
762 var x203: u64 = undefined;761 var x203: u64 = undefined;
763 var x204: u1 = undefined;762 var x204: u1 = undefined;
764 addcarryxU64(&x203, &x204, x202, x176, x194);763 addcarryxU64(&x203, &x204, x202, x176, x194);
765 const x205 = (cast(u64, x204) + cast(u64, x177));764 const x205 = (@as(u64, x204) + @as(u64, x177));
766 var x206: u64 = undefined;765 var x206: u64 = undefined;
767 var x207: u1 = undefined;766 var x207: u1 = undefined;
768 subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551);767 subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551);
...@@ -777,7 +776,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl...@@ -777,7 +776,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl
777 subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000);776 subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000);
778 var x214: u64 = undefined;777 var x214: u64 = undefined;
779 var x215: u1 = undefined;778 var x215: u1 = undefined;
780 subborrowxU64(&x214, &x215, x213, x205, cast(u64, 0x0));779 subborrowxU64(&x214, &x215, x213, x205, @as(u64, 0x0));
781 var x216: u64 = undefined;780 var x216: u64 = undefined;
782 cmovznzU64(&x216, x215, x206, x197);781 cmovznzU64(&x216, x215, x206, x197);
783 var x217: u64 = undefined;782 var x217: u64 = undefined;
...@@ -830,7 +829,7 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -830,7 +829,7 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
830 subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000000);829 subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000000);
831 var x17: u64 = undefined;830 var x17: u64 = undefined;
832 var x18: u1 = undefined;831 var x18: u1 = undefined;
833 subborrowxU64(&x17, &x18, x16, cast(u64, x8), cast(u64, 0x0));832 subborrowxU64(&x17, &x18, x16, @as(u64, x8), @as(u64, 0x0));
834 var x19: u64 = undefined;833 var x19: u64 = undefined;
835 cmovznzU64(&x19, x18, x9, x1);834 cmovznzU64(&x19, x18, x9, x1);
836 var x20: u64 = undefined;835 var x20: u64 = undefined;
...@@ -870,7 +869,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -870,7 +869,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
870 var x8: u1 = undefined;869 var x8: u1 = undefined;
871 subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3]));870 subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3]));
872 var x9: u64 = undefined;871 var x9: u64 = undefined;
873 cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff);872 cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff);
874 var x10: u64 = undefined;873 var x10: u64 = undefined;
875 var x11: u1 = undefined;874 var x11: u1 = undefined;
876 addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551));875 addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551));
...@@ -902,18 +901,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme...@@ -902,18 +901,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme
902901
903 var x1: u64 = undefined;902 var x1: u64 = undefined;
904 var x2: u1 = undefined;903 var x2: u1 = undefined;
905 subborrowxU64(&x1, &x2, 0x0, cast(u64, 0x0), (arg1[0]));904 subborrowxU64(&x1, &x2, 0x0, @as(u64, 0x0), (arg1[0]));
906 var x3: u64 = undefined;905 var x3: u64 = undefined;
907 var x4: u1 = undefined;906 var x4: u1 = undefined;
908 subborrowxU64(&x3, &x4, x2, cast(u64, 0x0), (arg1[1]));907 subborrowxU64(&x3, &x4, x2, @as(u64, 0x0), (arg1[1]));
909 var x5: u64 = undefined;908 var x5: u64 = undefined;
910 var x6: u1 = undefined;909 var x6: u1 = undefined;
911 subborrowxU64(&x5, &x6, x4, cast(u64, 0x0), (arg1[2]));910 subborrowxU64(&x5, &x6, x4, @as(u64, 0x0), (arg1[2]));
912 var x7: u64 = undefined;911 var x7: u64 = undefined;
913 var x8: u1 = undefined;912 var x8: u1 = undefined;
914 subborrowxU64(&x7, &x8, x6, cast(u64, 0x0), (arg1[3]));913 subborrowxU64(&x7, &x8, x6, @as(u64, 0x0), (arg1[3]));
915 var x9: u64 = undefined;914 var x9: u64 = undefined;
916 cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff);915 cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff);
917 var x10: u64 = undefined;916 var x10: u64 = undefined;
918 var x11: u1 = undefined;917 var x11: u1 = undefined;
919 addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551));918 addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551));
...@@ -973,22 +972,22 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -973,22 +972,22 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
973 addcarryxU64(&x18, &x19, 0x0, x1, x10);972 addcarryxU64(&x18, &x19, 0x0, x1, x10);
974 var x20: u64 = undefined;973 var x20: u64 = undefined;
975 var x21: u1 = undefined;974 var x21: u1 = undefined;
976 addcarryxU64(&x20, &x21, x19, cast(u64, 0x0), x12);975 addcarryxU64(&x20, &x21, x19, @as(u64, 0x0), x12);
977 var x22: u64 = undefined;976 var x22: u64 = undefined;
978 var x23: u1 = undefined;977 var x23: u1 = undefined;
979 addcarryxU64(&x22, &x23, x21, cast(u64, 0x0), x14);978 addcarryxU64(&x22, &x23, x21, @as(u64, 0x0), x14);
980 var x24: u64 = undefined;979 var x24: u64 = undefined;
981 var x25: u1 = undefined;980 var x25: u1 = undefined;
982 addcarryxU64(&x24, &x25, x23, cast(u64, 0x0), x16);981 addcarryxU64(&x24, &x25, x23, @as(u64, 0x0), x16);
983 var x26: u64 = undefined;982 var x26: u64 = undefined;
984 var x27: u1 = undefined;983 var x27: u1 = undefined;
985 addcarryxU64(&x26, &x27, 0x0, x20, (arg1[1]));984 addcarryxU64(&x26, &x27, 0x0, x20, (arg1[1]));
986 var x28: u64 = undefined;985 var x28: u64 = undefined;
987 var x29: u1 = undefined;986 var x29: u1 = undefined;
988 addcarryxU64(&x28, &x29, x27, x22, cast(u64, 0x0));987 addcarryxU64(&x28, &x29, x27, x22, @as(u64, 0x0));
989 var x30: u64 = undefined;988 var x30: u64 = undefined;
990 var x31: u1 = undefined;989 var x31: u1 = undefined;
991 addcarryxU64(&x30, &x31, x29, x24, cast(u64, 0x0));990 addcarryxU64(&x30, &x31, x29, x24, @as(u64, 0x0));
992 var x32: u64 = undefined;991 var x32: u64 = undefined;
993 var x33: u64 = undefined;992 var x33: u64 = undefined;
994 mulxU64(&x32, &x33, x26, 0xccd1c8aaee00bc4f);993 mulxU64(&x32, &x33, x26, 0xccd1c8aaee00bc4f);
...@@ -1024,16 +1023,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -1024,16 +1023,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
1024 addcarryxU64(&x52, &x53, x51, x30, x44);1023 addcarryxU64(&x52, &x53, x51, x30, x44);
1025 var x54: u64 = undefined;1024 var x54: u64 = undefined;
1026 var x55: u1 = undefined;1025 var x55: u1 = undefined;
1027 addcarryxU64(&x54, &x55, x53, (cast(u64, x31) + (cast(u64, x25) + (cast(u64, x17) + x5))), x46);1026 addcarryxU64(&x54, &x55, x53, (@as(u64, x31) + (@as(u64, x25) + (@as(u64, x17) + x5))), x46);
1028 var x56: u64 = undefined;1027 var x56: u64 = undefined;
1029 var x57: u1 = undefined;1028 var x57: u1 = undefined;
1030 addcarryxU64(&x56, &x57, 0x0, x50, (arg1[2]));1029 addcarryxU64(&x56, &x57, 0x0, x50, (arg1[2]));
1031 var x58: u64 = undefined;1030 var x58: u64 = undefined;
1032 var x59: u1 = undefined;1031 var x59: u1 = undefined;
1033 addcarryxU64(&x58, &x59, x57, x52, cast(u64, 0x0));1032 addcarryxU64(&x58, &x59, x57, x52, @as(u64, 0x0));
1034 var x60: u64 = undefined;1033 var x60: u64 = undefined;
1035 var x61: u1 = undefined;1034 var x61: u1 = undefined;
1036 addcarryxU64(&x60, &x61, x59, x54, cast(u64, 0x0));1035 addcarryxU64(&x60, &x61, x59, x54, @as(u64, 0x0));
1037 var x62: u64 = undefined;1036 var x62: u64 = undefined;
1038 var x63: u64 = undefined;1037 var x63: u64 = undefined;
1039 mulxU64(&x62, &x63, x56, 0xccd1c8aaee00bc4f);1038 mulxU64(&x62, &x63, x56, 0xccd1c8aaee00bc4f);
...@@ -1069,16 +1068,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -1069,16 +1068,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
1069 addcarryxU64(&x82, &x83, x81, x60, x74);1068 addcarryxU64(&x82, &x83, x81, x60, x74);
1070 var x84: u64 = undefined;1069 var x84: u64 = undefined;
1071 var x85: u1 = undefined;1070 var x85: u1 = undefined;
1072 addcarryxU64(&x84, &x85, x83, (cast(u64, x61) + (cast(u64, x55) + (cast(u64, x47) + x35))), x76);1071 addcarryxU64(&x84, &x85, x83, (@as(u64, x61) + (@as(u64, x55) + (@as(u64, x47) + x35))), x76);
1073 var x86: u64 = undefined;1072 var x86: u64 = undefined;
1074 var x87: u1 = undefined;1073 var x87: u1 = undefined;
1075 addcarryxU64(&x86, &x87, 0x0, x80, (arg1[3]));1074 addcarryxU64(&x86, &x87, 0x0, x80, (arg1[3]));
1076 var x88: u64 = undefined;1075 var x88: u64 = undefined;
1077 var x89: u1 = undefined;1076 var x89: u1 = undefined;
1078 addcarryxU64(&x88, &x89, x87, x82, cast(u64, 0x0));1077 addcarryxU64(&x88, &x89, x87, x82, @as(u64, 0x0));
1079 var x90: u64 = undefined;1078 var x90: u64 = undefined;
1080 var x91: u1 = undefined;1079 var x91: u1 = undefined;
1081 addcarryxU64(&x90, &x91, x89, x84, cast(u64, 0x0));1080 addcarryxU64(&x90, &x91, x89, x84, @as(u64, 0x0));
1082 var x92: u64 = undefined;1081 var x92: u64 = undefined;
1083 var x93: u64 = undefined;1082 var x93: u64 = undefined;
1084 mulxU64(&x92, &x93, x86, 0xccd1c8aaee00bc4f);1083 mulxU64(&x92, &x93, x86, 0xccd1c8aaee00bc4f);
...@@ -1114,8 +1113,8 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -1114,8 +1113,8 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
1114 addcarryxU64(&x112, &x113, x111, x90, x104);1113 addcarryxU64(&x112, &x113, x111, x90, x104);
1115 var x114: u64 = undefined;1114 var x114: u64 = undefined;
1116 var x115: u1 = undefined;1115 var x115: u1 = undefined;
1117 addcarryxU64(&x114, &x115, x113, (cast(u64, x91) + (cast(u64, x85) + (cast(u64, x77) + x65))), x106);1116 addcarryxU64(&x114, &x115, x113, (@as(u64, x91) + (@as(u64, x85) + (@as(u64, x77) + x65))), x106);
1118 const x116 = (cast(u64, x115) + (cast(u64, x107) + x95));1117 const x116 = (@as(u64, x115) + (@as(u64, x107) + x95));
1119 var x117: u64 = undefined;1118 var x117: u64 = undefined;
1120 var x118: u1 = undefined;1119 var x118: u1 = undefined;
1121 subborrowxU64(&x117, &x118, 0x0, x110, 0xf3b9cac2fc632551);1120 subborrowxU64(&x117, &x118, 0x0, x110, 0xf3b9cac2fc632551);
...@@ -1130,7 +1129,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo...@@ -1130,7 +1129,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo
1130 subborrowxU64(&x123, &x124, x122, x116, 0xffffffff00000000);1129 subborrowxU64(&x123, &x124, x122, x116, 0xffffffff00000000);
1131 var x125: u64 = undefined;1130 var x125: u64 = undefined;
1132 var x126: u1 = undefined;1131 var x126: u1 = undefined;
1133 subborrowxU64(&x125, &x126, x124, cast(u64, 0x0), cast(u64, 0x0));1132 subborrowxU64(&x125, &x126, x124, @as(u64, 0x0), @as(u64, 0x0));
1134 var x127: u64 = undefined;1133 var x127: u64 = undefined;
1135 cmovznzU64(&x127, x126, x117, x110);1134 cmovznzU64(&x127, x126, x117, x110);
1136 var x128: u64 = undefined;1135 var x128: u64 = undefined;
...@@ -1219,7 +1218,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1219,7 +1218,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1219 addcarryxU64(&x41, &x42, x40, x17, x33);1218 addcarryxU64(&x41, &x42, x40, x17, x33);
1220 var x43: u64 = undefined;1219 var x43: u64 = undefined;
1221 var x44: u1 = undefined;1220 var x44: u1 = undefined;
1222 addcarryxU64(&x43, &x44, x42, (cast(u64, x18) + x6), (cast(u64, x34) + x22));1221 addcarryxU64(&x43, &x44, x42, (@as(u64, x18) + x6), (@as(u64, x34) + x22));
1223 var x45: u64 = undefined;1222 var x45: u64 = undefined;
1224 var x46: u64 = undefined;1223 var x46: u64 = undefined;
1225 mulxU64(&x45, &x46, x1, 0x66e12d94f3d95620);1224 mulxU64(&x45, &x46, x1, 0x66e12d94f3d95620);
...@@ -1291,7 +1290,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1291,7 +1290,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1291 addcarryxU64(&x89, &x90, x88, x65, x81);1290 addcarryxU64(&x89, &x90, x88, x65, x81);
1292 var x91: u64 = undefined;1291 var x91: u64 = undefined;
1293 var x92: u1 = undefined;1292 var x92: u1 = undefined;
1294 addcarryxU64(&x91, &x92, x90, ((cast(u64, x66) + cast(u64, x44)) + (cast(u64, x58) + x46)), (cast(u64, x82) + x70));1293 addcarryxU64(&x91, &x92, x90, ((@as(u64, x66) + @as(u64, x44)) + (@as(u64, x58) + x46)), (@as(u64, x82) + x70));
1295 var x93: u64 = undefined;1294 var x93: u64 = undefined;
1296 var x94: u64 = undefined;1295 var x94: u64 = undefined;
1297 mulxU64(&x93, &x94, x2, 0x66e12d94f3d95620);1296 mulxU64(&x93, &x94, x2, 0x66e12d94f3d95620);
...@@ -1363,7 +1362,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1363,7 +1362,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1363 addcarryxU64(&x137, &x138, x136, x113, x129);1362 addcarryxU64(&x137, &x138, x136, x113, x129);
1364 var x139: u64 = undefined;1363 var x139: u64 = undefined;
1365 var x140: u1 = undefined;1364 var x140: u1 = undefined;
1366 addcarryxU64(&x139, &x140, x138, ((cast(u64, x114) + cast(u64, x92)) + (cast(u64, x106) + x94)), (cast(u64, x130) + x118));1365 addcarryxU64(&x139, &x140, x138, ((@as(u64, x114) + @as(u64, x92)) + (@as(u64, x106) + x94)), (@as(u64, x130) + x118));
1367 var x141: u64 = undefined;1366 var x141: u64 = undefined;
1368 var x142: u64 = undefined;1367 var x142: u64 = undefined;
1369 mulxU64(&x141, &x142, x3, 0x66e12d94f3d95620);1368 mulxU64(&x141, &x142, x3, 0x66e12d94f3d95620);
...@@ -1435,7 +1434,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1435,7 +1434,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1435 addcarryxU64(&x185, &x186, x184, x161, x177);1434 addcarryxU64(&x185, &x186, x184, x161, x177);
1436 var x187: u64 = undefined;1435 var x187: u64 = undefined;
1437 var x188: u1 = undefined;1436 var x188: u1 = undefined;
1438 addcarryxU64(&x187, &x188, x186, ((cast(u64, x162) + cast(u64, x140)) + (cast(u64, x154) + x142)), (cast(u64, x178) + x166));1437 addcarryxU64(&x187, &x188, x186, ((@as(u64, x162) + @as(u64, x140)) + (@as(u64, x154) + x142)), (@as(u64, x178) + x166));
1439 var x189: u64 = undefined;1438 var x189: u64 = undefined;
1440 var x190: u1 = undefined;1439 var x190: u1 = undefined;
1441 subborrowxU64(&x189, &x190, 0x0, x181, 0xf3b9cac2fc632551);1440 subborrowxU64(&x189, &x190, 0x0, x181, 0xf3b9cac2fc632551);
...@@ -1450,7 +1449,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma...@@ -1450,7 +1449,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma
1450 subborrowxU64(&x195, &x196, x194, x187, 0xffffffff00000000);1449 subborrowxU64(&x195, &x196, x194, x187, 0xffffffff00000000);
1451 var x197: u64 = undefined;1450 var x197: u64 = undefined;
1452 var x198: u1 = undefined;1451 var x198: u1 = undefined;
1453 subborrowxU64(&x197, &x198, x196, cast(u64, x188), cast(u64, 0x0));1452 subborrowxU64(&x197, &x198, x196, @as(u64, x188), @as(u64, 0x0));
1454 var x199: u64 = undefined;1453 var x199: u64 = undefined;
1455 cmovznzU64(&x199, x198, x189, x181);1454 cmovznzU64(&x199, x198, x189, x181);
1456 var x200: u64 = undefined;1455 var x200: u64 = undefined;
...@@ -1529,62 +1528,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1529,62 +1528,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1529 const x2 = (arg1[2]);1528 const x2 = (arg1[2]);
1530 const x3 = (arg1[1]);1529 const x3 = (arg1[1]);
1531 const x4 = (arg1[0]);1530 const x4 = (arg1[0]);
1532 const x5 = cast(u8, (x4 & cast(u64, 0xff)));1531 const x5 = @truncate(u8, (x4 & @as(u64, 0xff)));
1533 const x6 = (x4 >> 8);1532 const x6 = (x4 >> 8);
1534 const x7 = cast(u8, (x6 & cast(u64, 0xff)));1533 const x7 = @truncate(u8, (x6 & @as(u64, 0xff)));
1535 const x8 = (x6 >> 8);1534 const x8 = (x6 >> 8);
1536 const x9 = cast(u8, (x8 & cast(u64, 0xff)));1535 const x9 = @truncate(u8, (x8 & @as(u64, 0xff)));
1537 const x10 = (x8 >> 8);1536 const x10 = (x8 >> 8);
1538 const x11 = cast(u8, (x10 & cast(u64, 0xff)));1537 const x11 = @truncate(u8, (x10 & @as(u64, 0xff)));
1539 const x12 = (x10 >> 8);1538 const x12 = (x10 >> 8);
1540 const x13 = cast(u8, (x12 & cast(u64, 0xff)));1539 const x13 = @truncate(u8, (x12 & @as(u64, 0xff)));
1541 const x14 = (x12 >> 8);1540 const x14 = (x12 >> 8);
1542 const x15 = cast(u8, (x14 & cast(u64, 0xff)));1541 const x15 = @truncate(u8, (x14 & @as(u64, 0xff)));
1543 const x16 = (x14 >> 8);1542 const x16 = (x14 >> 8);
1544 const x17 = cast(u8, (x16 & cast(u64, 0xff)));1543 const x17 = @truncate(u8, (x16 & @as(u64, 0xff)));
1545 const x18 = cast(u8, (x16 >> 8));1544 const x18 = @truncate(u8, (x16 >> 8));
1546 const x19 = cast(u8, (x3 & cast(u64, 0xff)));1545 const x19 = @truncate(u8, (x3 & @as(u64, 0xff)));
1547 const x20 = (x3 >> 8);1546 const x20 = (x3 >> 8);
1548 const x21 = cast(u8, (x20 & cast(u64, 0xff)));1547 const x21 = @truncate(u8, (x20 & @as(u64, 0xff)));
1549 const x22 = (x20 >> 8);1548 const x22 = (x20 >> 8);
1550 const x23 = cast(u8, (x22 & cast(u64, 0xff)));1549 const x23 = @truncate(u8, (x22 & @as(u64, 0xff)));
1551 const x24 = (x22 >> 8);1550 const x24 = (x22 >> 8);
1552 const x25 = cast(u8, (x24 & cast(u64, 0xff)));1551 const x25 = @truncate(u8, (x24 & @as(u64, 0xff)));
1553 const x26 = (x24 >> 8);1552 const x26 = (x24 >> 8);
1554 const x27 = cast(u8, (x26 & cast(u64, 0xff)));1553 const x27 = @truncate(u8, (x26 & @as(u64, 0xff)));
1555 const x28 = (x26 >> 8);1554 const x28 = (x26 >> 8);
1556 const x29 = cast(u8, (x28 & cast(u64, 0xff)));1555 const x29 = @truncate(u8, (x28 & @as(u64, 0xff)));
1557 const x30 = (x28 >> 8);1556 const x30 = (x28 >> 8);
1558 const x31 = cast(u8, (x30 & cast(u64, 0xff)));1557 const x31 = @truncate(u8, (x30 & @as(u64, 0xff)));
1559 const x32 = cast(u8, (x30 >> 8));1558 const x32 = @truncate(u8, (x30 >> 8));
1560 const x33 = cast(u8, (x2 & cast(u64, 0xff)));1559 const x33 = @truncate(u8, (x2 & @as(u64, 0xff)));
1561 const x34 = (x2 >> 8);1560 const x34 = (x2 >> 8);
1562 const x35 = cast(u8, (x34 & cast(u64, 0xff)));1561 const x35 = @truncate(u8, (x34 & @as(u64, 0xff)));
1563 const x36 = (x34 >> 8);1562 const x36 = (x34 >> 8);
1564 const x37 = cast(u8, (x36 & cast(u64, 0xff)));1563 const x37 = @truncate(u8, (x36 & @as(u64, 0xff)));
1565 const x38 = (x36 >> 8);1564 const x38 = (x36 >> 8);
1566 const x39 = cast(u8, (x38 & cast(u64, 0xff)));1565 const x39 = @truncate(u8, (x38 & @as(u64, 0xff)));
1567 const x40 = (x38 >> 8);1566 const x40 = (x38 >> 8);
1568 const x41 = cast(u8, (x40 & cast(u64, 0xff)));1567 const x41 = @truncate(u8, (x40 & @as(u64, 0xff)));
1569 const x42 = (x40 >> 8);1568 const x42 = (x40 >> 8);
1570 const x43 = cast(u8, (x42 & cast(u64, 0xff)));1569 const x43 = @truncate(u8, (x42 & @as(u64, 0xff)));
1571 const x44 = (x42 >> 8);1570 const x44 = (x42 >> 8);
1572 const x45 = cast(u8, (x44 & cast(u64, 0xff)));1571 const x45 = @truncate(u8, (x44 & @as(u64, 0xff)));
1573 const x46 = cast(u8, (x44 >> 8));1572 const x46 = @truncate(u8, (x44 >> 8));
1574 const x47 = cast(u8, (x1 & cast(u64, 0xff)));1573 const x47 = @truncate(u8, (x1 & @as(u64, 0xff)));
1575 const x48 = (x1 >> 8);1574 const x48 = (x1 >> 8);
1576 const x49 = cast(u8, (x48 & cast(u64, 0xff)));1575 const x49 = @truncate(u8, (x48 & @as(u64, 0xff)));
1577 const x50 = (x48 >> 8);1576 const x50 = (x48 >> 8);
1578 const x51 = cast(u8, (x50 & cast(u64, 0xff)));1577 const x51 = @truncate(u8, (x50 & @as(u64, 0xff)));
1579 const x52 = (x50 >> 8);1578 const x52 = (x50 >> 8);
1580 const x53 = cast(u8, (x52 & cast(u64, 0xff)));1579 const x53 = @truncate(u8, (x52 & @as(u64, 0xff)));
1581 const x54 = (x52 >> 8);1580 const x54 = (x52 >> 8);
1582 const x55 = cast(u8, (x54 & cast(u64, 0xff)));1581 const x55 = @truncate(u8, (x54 & @as(u64, 0xff)));
1583 const x56 = (x54 >> 8);1582 const x56 = (x54 >> 8);
1584 const x57 = cast(u8, (x56 & cast(u64, 0xff)));1583 const x57 = @truncate(u8, (x56 & @as(u64, 0xff)));
1585 const x58 = (x56 >> 8);1584 const x58 = (x56 >> 8);
1586 const x59 = cast(u8, (x58 & cast(u64, 0xff)));1585 const x59 = @truncate(u8, (x58 & @as(u64, 0xff)));
1587 const x60 = cast(u8, (x58 >> 8));1586 const x60 = @truncate(u8, (x58 >> 8));
1588 out1[0] = x5;1587 out1[0] = x5;
1589 out1[1] = x7;1588 out1[1] = x7;
1590 out1[2] = x9;1589 out1[2] = x9;
...@@ -1634,60 +1633,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {...@@ -1634,60 +1633,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void {
1634pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {1633pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void {
1635 @setRuntimeSafety(mode == .Debug);1634 @setRuntimeSafety(mode == .Debug);
16361635
1637 const x1 = (cast(u64, (arg1[31])) << 56);1636 const x1 = (@as(u64, (arg1[31])) << 56);
1638 const x2 = (cast(u64, (arg1[30])) << 48);1637 const x2 = (@as(u64, (arg1[30])) << 48);
1639 const x3 = (cast(u64, (arg1[29])) << 40);1638 const x3 = (@as(u64, (arg1[29])) << 40);
1640 const x4 = (cast(u64, (arg1[28])) << 32);1639 const x4 = (@as(u64, (arg1[28])) << 32);
1641 const x5 = (cast(u64, (arg1[27])) << 24);1640 const x5 = (@as(u64, (arg1[27])) << 24);
1642 const x6 = (cast(u64, (arg1[26])) << 16);1641 const x6 = (@as(u64, (arg1[26])) << 16);
1643 const x7 = (cast(u64, (arg1[25])) << 8);1642 const x7 = (@as(u64, (arg1[25])) << 8);
1644 const x8 = (arg1[24]);1643 const x8 = (arg1[24]);
1645 const x9 = (cast(u64, (arg1[23])) << 56);1644 const x9 = (@as(u64, (arg1[23])) << 56);
1646 const x10 = (cast(u64, (arg1[22])) << 48);1645 const x10 = (@as(u64, (arg1[22])) << 48);
1647 const x11 = (cast(u64, (arg1[21])) << 40);1646 const x11 = (@as(u64, (arg1[21])) << 40);
1648 const x12 = (cast(u64, (arg1[20])) << 32);1647 const x12 = (@as(u64, (arg1[20])) << 32);
1649 const x13 = (cast(u64, (arg1[19])) << 24);1648 const x13 = (@as(u64, (arg1[19])) << 24);
1650 const x14 = (cast(u64, (arg1[18])) << 16);1649 const x14 = (@as(u64, (arg1[18])) << 16);
1651 const x15 = (cast(u64, (arg1[17])) << 8);1650 const x15 = (@as(u64, (arg1[17])) << 8);
1652 const x16 = (arg1[16]);1651 const x16 = (arg1[16]);
1653 const x17 = (cast(u64, (arg1[15])) << 56);1652 const x17 = (@as(u64, (arg1[15])) << 56);
1654 const x18 = (cast(u64, (arg1[14])) << 48);1653 const x18 = (@as(u64, (arg1[14])) << 48);
1655 const x19 = (cast(u64, (arg1[13])) << 40);1654 const x19 = (@as(u64, (arg1[13])) << 40);
1656 const x20 = (cast(u64, (arg1[12])) << 32);1655 const x20 = (@as(u64, (arg1[12])) << 32);
1657 const x21 = (cast(u64, (arg1[11])) << 24);1656 const x21 = (@as(u64, (arg1[11])) << 24);
1658 const x22 = (cast(u64, (arg1[10])) << 16);1657 const x22 = (@as(u64, (arg1[10])) << 16);
1659 const x23 = (cast(u64, (arg1[9])) << 8);1658 const x23 = (@as(u64, (arg1[9])) << 8);
1660 const x24 = (arg1[8]);1659 const x24 = (arg1[8]);
1661 const x25 = (cast(u64, (arg1[7])) << 56);1660 const x25 = (@as(u64, (arg1[7])) << 56);
1662 const x26 = (cast(u64, (arg1[6])) << 48);1661 const x26 = (@as(u64, (arg1[6])) << 48);
1663 const x27 = (cast(u64, (arg1[5])) << 40);1662 const x27 = (@as(u64, (arg1[5])) << 40);
1664 const x28 = (cast(u64, (arg1[4])) << 32);1663 const x28 = (@as(u64, (arg1[4])) << 32);
1665 const x29 = (cast(u64, (arg1[3])) << 24);1664 const x29 = (@as(u64, (arg1[3])) << 24);
1666 const x30 = (cast(u64, (arg1[2])) << 16);1665 const x30 = (@as(u64, (arg1[2])) << 16);
1667 const x31 = (cast(u64, (arg1[1])) << 8);1666 const x31 = (@as(u64, (arg1[1])) << 8);
1668 const x32 = (arg1[0]);1667 const x32 = (arg1[0]);
1669 const x33 = (x31 + cast(u64, x32));1668 const x33 = (x31 + @as(u64, x32));
1670 const x34 = (x30 + x33);1669 const x34 = (x30 + x33);
1671 const x35 = (x29 + x34);1670 const x35 = (x29 + x34);
1672 const x36 = (x28 + x35);1671 const x36 = (x28 + x35);
1673 const x37 = (x27 + x36);1672 const x37 = (x27 + x36);
1674 const x38 = (x26 + x37);1673 const x38 = (x26 + x37);
1675 const x39 = (x25 + x38);1674 const x39 = (x25 + x38);
1676 const x40 = (x23 + cast(u64, x24));1675 const x40 = (x23 + @as(u64, x24));
1677 const x41 = (x22 + x40);1676 const x41 = (x22 + x40);
1678 const x42 = (x21 + x41);1677 const x42 = (x21 + x41);
1679 const x43 = (x20 + x42);1678 const x43 = (x20 + x42);
1680 const x44 = (x19 + x43);1679 const x44 = (x19 + x43);
1681 const x45 = (x18 + x44);1680 const x45 = (x18 + x44);
1682 const x46 = (x17 + x45);1681 const x46 = (x17 + x45);
1683 const x47 = (x15 + cast(u64, x16));1682 const x47 = (x15 + @as(u64, x16));
1684 const x48 = (x14 + x47);1683 const x48 = (x14 + x47);
1685 const x49 = (x13 + x48);1684 const x49 = (x13 + x48);
1686 const x50 = (x12 + x49);1685 const x50 = (x12 + x49);
1687 const x51 = (x11 + x50);1686 const x51 = (x11 + x50);
1688 const x52 = (x10 + x51);1687 const x52 = (x10 + x51);
1689 const x53 = (x9 + x52);1688 const x53 = (x9 + x52);
1690 const x54 = (x7 + cast(u64, x8));1689 const x54 = (x7 + @as(u64, x8));
1691 const x55 = (x6 + x54);1690 const x55 = (x6 + x54);
1692 const x56 = (x5 + x55);1691 const x56 = (x5 + x55);
1693 const x57 = (x4 + x56);1692 const x57 = (x4 + x56);
...@@ -1711,7 +1710,7 @@ pub fn setOne(out1: *MontgomeryDomainFieldElement) void {...@@ -1711,7 +1710,7 @@ pub fn setOne(out1: *MontgomeryDomainFieldElement) void {
17111710
1712 out1[0] = 0xc46353d039cdaaf;1711 out1[0] = 0xc46353d039cdaaf;
1713 out1[1] = 0x4319055258e8617b;1712 out1[1] = 0x4319055258e8617b;
1714 out1[2] = cast(u64, 0x0);1713 out1[2] = @as(u64, 0x0);
1715 out1[3] = 0xffffffff;1714 out1[3] = 0xffffffff;
1716}1715}
17171716
...@@ -1730,7 +1729,7 @@ pub fn msat(out1: *[5]u64) void {...@@ -1730,7 +1729,7 @@ pub fn msat(out1: *[5]u64) void {
1730 out1[1] = 0xbce6faada7179e84;1729 out1[1] = 0xbce6faada7179e84;
1731 out1[2] = 0xffffffffffffffff;1730 out1[2] = 0xffffffffffffffff;
1732 out1[3] = 0xffffffff00000000;1731 out1[3] = 0xffffffff00000000;
1733 out1[4] = cast(u64, 0x0);1732 out1[4] = @as(u64, 0x0);
1734}1733}
17351734
1736/// The function divstep computes a divstep.1735/// The function divstep computes a divstep.
...@@ -1766,11 +1765,11 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1766,11 +1765,11 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
17661765
1767 var x1: u64 = undefined;1766 var x1: u64 = undefined;
1768 var x2: u1 = undefined;1767 var x2: u1 = undefined;
1769 addcarryxU64(&x1, &x2, 0x0, (~arg1), cast(u64, 0x1));1768 addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));
1770 const x3 = (cast(u1, (x1 >> 63)) & cast(u1, ((arg3[0]) & cast(u64, 0x1))));1769 const x3 = (@as(u1, (x1 >> 63)) & @as(u1, ((arg3[0]) & @as(u64, 0x1))));
1771 var x4: u64 = undefined;1770 var x4: u64 = undefined;
1772 var x5: u1 = undefined;1771 var x5: u1 = undefined;
1773 addcarryxU64(&x4, &x5, 0x0, (~arg1), cast(u64, 0x1));1772 addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));
1774 var x6: u64 = undefined;1773 var x6: u64 = undefined;
1775 cmovznzU64(&x6, x3, arg1, x4);1774 cmovznzU64(&x6, x3, arg1, x4);
1776 var x7: u64 = undefined;1775 var x7: u64 = undefined;
...@@ -1785,19 +1784,19 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1785,19 +1784,19 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1785 cmovznzU64(&x11, x3, (arg2[4]), (arg3[4]));1784 cmovznzU64(&x11, x3, (arg2[4]), (arg3[4]));
1786 var x12: u64 = undefined;1785 var x12: u64 = undefined;
1787 var x13: u1 = undefined;1786 var x13: u1 = undefined;
1788 addcarryxU64(&x12, &x13, 0x0, cast(u64, 0x1), (~(arg2[0])));1787 addcarryxU64(&x12, &x13, 0x0, @as(u64, 0x1), (~(arg2[0])));
1789 var x14: u64 = undefined;1788 var x14: u64 = undefined;
1790 var x15: u1 = undefined;1789 var x15: u1 = undefined;
1791 addcarryxU64(&x14, &x15, x13, cast(u64, 0x0), (~(arg2[1])));1790 addcarryxU64(&x14, &x15, x13, @as(u64, 0x0), (~(arg2[1])));
1792 var x16: u64 = undefined;1791 var x16: u64 = undefined;
1793 var x17: u1 = undefined;1792 var x17: u1 = undefined;
1794 addcarryxU64(&x16, &x17, x15, cast(u64, 0x0), (~(arg2[2])));1793 addcarryxU64(&x16, &x17, x15, @as(u64, 0x0), (~(arg2[2])));
1795 var x18: u64 = undefined;1794 var x18: u64 = undefined;
1796 var x19: u1 = undefined;1795 var x19: u1 = undefined;
1797 addcarryxU64(&x18, &x19, x17, cast(u64, 0x0), (~(arg2[3])));1796 addcarryxU64(&x18, &x19, x17, @as(u64, 0x0), (~(arg2[3])));
1798 var x20: u64 = undefined;1797 var x20: u64 = undefined;
1799 var x21: u1 = undefined;1798 var x21: u1 = undefined;
1800 addcarryxU64(&x20, &x21, x19, cast(u64, 0x0), (~(arg2[4])));1799 addcarryxU64(&x20, &x21, x19, @as(u64, 0x0), (~(arg2[4])));
1801 var x22: u64 = undefined;1800 var x22: u64 = undefined;
1802 cmovznzU64(&x22, x3, (arg3[0]), x12);1801 cmovznzU64(&x22, x3, (arg3[0]), x12);
1803 var x23: u64 = undefined;1802 var x23: u64 = undefined;
...@@ -1842,25 +1841,25 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1842,25 +1841,25 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1842 subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000000);1841 subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000000);
1843 var x47: u64 = undefined;1842 var x47: u64 = undefined;
1844 var x48: u1 = undefined;1843 var x48: u1 = undefined;
1845 subborrowxU64(&x47, &x48, x46, cast(u64, x38), cast(u64, 0x0));1844 subborrowxU64(&x47, &x48, x46, @as(u64, x38), @as(u64, 0x0));
1846 const x49 = (arg4[3]);1845 const x49 = (arg4[3]);
1847 const x50 = (arg4[2]);1846 const x50 = (arg4[2]);
1848 const x51 = (arg4[1]);1847 const x51 = (arg4[1]);
1849 const x52 = (arg4[0]);1848 const x52 = (arg4[0]);
1850 var x53: u64 = undefined;1849 var x53: u64 = undefined;
1851 var x54: u1 = undefined;1850 var x54: u1 = undefined;
1852 subborrowxU64(&x53, &x54, 0x0, cast(u64, 0x0), x52);1851 subborrowxU64(&x53, &x54, 0x0, @as(u64, 0x0), x52);
1853 var x55: u64 = undefined;1852 var x55: u64 = undefined;
1854 var x56: u1 = undefined;1853 var x56: u1 = undefined;
1855 subborrowxU64(&x55, &x56, x54, cast(u64, 0x0), x51);1854 subborrowxU64(&x55, &x56, x54, @as(u64, 0x0), x51);
1856 var x57: u64 = undefined;1855 var x57: u64 = undefined;
1857 var x58: u1 = undefined;1856 var x58: u1 = undefined;
1858 subborrowxU64(&x57, &x58, x56, cast(u64, 0x0), x50);1857 subborrowxU64(&x57, &x58, x56, @as(u64, 0x0), x50);
1859 var x59: u64 = undefined;1858 var x59: u64 = undefined;
1860 var x60: u1 = undefined;1859 var x60: u1 = undefined;
1861 subborrowxU64(&x59, &x60, x58, cast(u64, 0x0), x49);1860 subborrowxU64(&x59, &x60, x58, @as(u64, 0x0), x49);
1862 var x61: u64 = undefined;1861 var x61: u64 = undefined;
1863 cmovznzU64(&x61, x60, cast(u64, 0x0), 0xffffffffffffffff);1862 cmovznzU64(&x61, x60, @as(u64, 0x0), 0xffffffffffffffff);
1864 var x62: u64 = undefined;1863 var x62: u64 = undefined;
1865 var x63: u1 = undefined;1864 var x63: u1 = undefined;
1866 addcarryxU64(&x62, &x63, 0x0, x53, (x61 & 0xf3b9cac2fc632551));1865 addcarryxU64(&x62, &x63, 0x0, x53, (x61 & 0xf3b9cac2fc632551));
...@@ -1881,17 +1880,17 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1881,17 +1880,17 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1881 cmovznzU64(&x72, x3, (arg5[2]), x66);1880 cmovznzU64(&x72, x3, (arg5[2]), x66);
1882 var x73: u64 = undefined;1881 var x73: u64 = undefined;
1883 cmovznzU64(&x73, x3, (arg5[3]), x68);1882 cmovznzU64(&x73, x3, (arg5[3]), x68);
1884 const x74 = cast(u1, (x22 & cast(u64, 0x1)));1883 const x74 = @as(u1, (x22 & @as(u64, 0x1)));
1885 var x75: u64 = undefined;1884 var x75: u64 = undefined;
1886 cmovznzU64(&x75, x74, cast(u64, 0x0), x7);1885 cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
1887 var x76: u64 = undefined;1886 var x76: u64 = undefined;
1888 cmovznzU64(&x76, x74, cast(u64, 0x0), x8);1887 cmovznzU64(&x76, x74, @as(u64, 0x0), x8);
1889 var x77: u64 = undefined;1888 var x77: u64 = undefined;
1890 cmovznzU64(&x77, x74, cast(u64, 0x0), x9);1889 cmovznzU64(&x77, x74, @as(u64, 0x0), x9);
1891 var x78: u64 = undefined;1890 var x78: u64 = undefined;
1892 cmovznzU64(&x78, x74, cast(u64, 0x0), x10);1891 cmovznzU64(&x78, x74, @as(u64, 0x0), x10);
1893 var x79: u64 = undefined;1892 var x79: u64 = undefined;
1894 cmovznzU64(&x79, x74, cast(u64, 0x0), x11);1893 cmovznzU64(&x79, x74, @as(u64, 0x0), x11);
1895 var x80: u64 = undefined;1894 var x80: u64 = undefined;
1896 var x81: u1 = undefined;1895 var x81: u1 = undefined;
1897 addcarryxU64(&x80, &x81, 0x0, x22, x75);1896 addcarryxU64(&x80, &x81, 0x0, x22, x75);
...@@ -1908,13 +1907,13 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1908,13 +1907,13 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1908 var x89: u1 = undefined;1907 var x89: u1 = undefined;
1909 addcarryxU64(&x88, &x89, x87, x26, x79);1908 addcarryxU64(&x88, &x89, x87, x26, x79);
1910 var x90: u64 = undefined;1909 var x90: u64 = undefined;
1911 cmovznzU64(&x90, x74, cast(u64, 0x0), x27);1910 cmovznzU64(&x90, x74, @as(u64, 0x0), x27);
1912 var x91: u64 = undefined;1911 var x91: u64 = undefined;
1913 cmovznzU64(&x91, x74, cast(u64, 0x0), x28);1912 cmovznzU64(&x91, x74, @as(u64, 0x0), x28);
1914 var x92: u64 = undefined;1913 var x92: u64 = undefined;
1915 cmovznzU64(&x92, x74, cast(u64, 0x0), x29);1914 cmovznzU64(&x92, x74, @as(u64, 0x0), x29);
1916 var x93: u64 = undefined;1915 var x93: u64 = undefined;
1917 cmovznzU64(&x93, x74, cast(u64, 0x0), x30);1916 cmovznzU64(&x93, x74, @as(u64, 0x0), x30);
1918 var x94: u64 = undefined;1917 var x94: u64 = undefined;
1919 var x95: u1 = undefined;1918 var x95: u1 = undefined;
1920 addcarryxU64(&x94, &x95, 0x0, x70, x90);1919 addcarryxU64(&x94, &x95, 0x0, x70, x90);
...@@ -1941,10 +1940,10 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[...@@ -1941,10 +1940,10 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
1941 subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000000);1940 subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000000);
1942 var x110: u64 = undefined;1941 var x110: u64 = undefined;
1943 var x111: u1 = undefined;1942 var x111: u1 = undefined;
1944 subborrowxU64(&x110, &x111, x109, cast(u64, x101), cast(u64, 0x0));1943 subborrowxU64(&x110, &x111, x109, @as(u64, x101), @as(u64, 0x0));
1945 var x112: u64 = undefined;1944 var x112: u64 = undefined;
1946 var x113: u1 = undefined;1945 var x113: u1 = undefined;
1947 addcarryxU64(&x112, &x113, 0x0, x6, cast(u64, 0x1));1946 addcarryxU64(&x112, &x113, 0x0, x6, @as(u64, 0x1));
1948 const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff));1947 const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff));
1949 const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff));1948 const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff));
1950 const x116 = ((x84 >> 1) | ((x86 << 63) & 0xffffffffffffffff));1949 const x116 = ((x84 >> 1) | ((x86 << 63) & 0xffffffffffffffff));
lib/std/meta.zig-376
...@@ -884,319 +884,6 @@ pub fn Vector(comptime len: u32, comptime child: type) type {...@@ -884,319 +884,6 @@ pub fn Vector(comptime len: u32, comptime child: type) type {
884 });884 });
885}885}
886886
887/// Given a type and value, cast the value to the type as c would.
888/// This is for translate-c and is not intended for general use.
889pub fn cast(comptime DestType: type, target: anytype) DestType {
890 // this function should behave like transCCast in translate-c, except it's for macros and enums
891 const SourceType = @TypeOf(target);
892 switch (@typeInfo(DestType)) {
893 .Pointer => return castToPtr(DestType, SourceType, target),
894 .Optional => |dest_opt| {
895 if (@typeInfo(dest_opt.child) == .Pointer) {
896 return castToPtr(DestType, SourceType, target);
897 }
898 },
899 .Enum => |enum_type| {
900 if (@typeInfo(SourceType) == .Int or @typeInfo(SourceType) == .ComptimeInt) {
901 const intermediate = cast(enum_type.tag_type, target);
902 return @intToEnum(DestType, intermediate);
903 }
904 },
905 .Int => {
906 switch (@typeInfo(SourceType)) {
907 .Pointer => {
908 return castInt(DestType, @ptrToInt(target));
909 },
910 .Optional => |opt| {
911 if (@typeInfo(opt.child) == .Pointer) {
912 return castInt(DestType, @ptrToInt(target));
913 }
914 },
915 .Enum => {
916 return castInt(DestType, @enumToInt(target));
917 },
918 .Int => {
919 return castInt(DestType, target);
920 },
921 else => {},
922 }
923 },
924 else => {},
925 }
926 return @as(DestType, target);
927}
928
929fn castInt(comptime DestType: type, target: anytype) DestType {
930 const dest = @typeInfo(DestType).Int;
931 const source = @typeInfo(@TypeOf(target)).Int;
932
933 if (dest.bits < source.bits)
934 return @bitCast(DestType, @truncate(Int(source.signedness, dest.bits), target))
935 else
936 return @bitCast(DestType, @as(Int(source.signedness, dest.bits), target));
937}
938
939fn castPtr(comptime DestType: type, target: anytype) DestType {
940 const dest = ptrInfo(DestType);
941 const source = ptrInfo(@TypeOf(target));
942
943 if (source.is_const and !dest.is_const or source.is_volatile and !dest.is_volatile)
944 return @intToPtr(DestType, @ptrToInt(target))
945 else if (@typeInfo(dest.child) == .Opaque)
946 // dest.alignment would error out
947 return @ptrCast(DestType, target)
948 else
949 return @ptrCast(DestType, @alignCast(dest.alignment, target));
950}
951
952fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {
953 switch (@typeInfo(SourceType)) {
954 .Int => {
955 return @intToPtr(DestType, castInt(usize, target));
956 },
957 .ComptimeInt => {
958 if (target < 0)
959 return @intToPtr(DestType, @bitCast(usize, @intCast(isize, target)))
960 else
961 return @intToPtr(DestType, @intCast(usize, target));
962 },
963 .Pointer => {
964 return castPtr(DestType, target);
965 },
966 .Optional => |target_opt| {
967 if (@typeInfo(target_opt.child) == .Pointer) {
968 return castPtr(DestType, target);
969 }
970 },
971 else => {},
972 }
973 return @as(DestType, target);
974}
975
976fn ptrInfo(comptime PtrType: type) TypeInfo.Pointer {
977 return switch (@typeInfo(PtrType)) {
978 .Optional => |opt_info| @typeInfo(opt_info.child).Pointer,
979 .Pointer => |ptr_info| ptr_info,
980 else => unreachable,
981 };
982}
983
984test "std.meta.cast" {
985 const E = enum(u2) {
986 Zero,
987 One,
988 Two,
989 };
990
991 var i = @as(i64, 10);
992
993 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
994 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
995 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
996
997 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
998 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
999 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
1000
1001 try testing.expect(cast(E, 1) == .One);
1002
1003 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
1004 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
1005 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
1006 try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
1007
1008 try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
1009
1010 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
1011 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
1012
1013 try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
1014
1015 const C_ENUM = enum(c_int) {
1016 A = 0,
1017 B,
1018 C,
1019 _,
1020 };
1021 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
1022 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
1023 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
1024 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
1025
1026 var foo: c_int = -1;
1027 try testing.expect(cast(*c_void, -1) == @intToPtr(*c_void, @bitCast(usize, @as(isize, -1))));
1028 try testing.expect(cast(*c_void, foo) == @intToPtr(*c_void, @bitCast(usize, @as(isize, -1))));
1029 try testing.expect(cast(?*c_void, -1) == @intToPtr(?*c_void, @bitCast(usize, @as(isize, -1))));
1030 try testing.expect(cast(?*c_void, foo) == @intToPtr(?*c_void, @bitCast(usize, @as(isize, -1))));
1031}
1032
1033/// Given a value returns its size as C's sizeof operator would.
1034/// This is for translate-c and is not intended for general use.
1035pub fn sizeof(target: anytype) usize {
1036 const T: type = if (@TypeOf(target) == type) target else @TypeOf(target);
1037 switch (@typeInfo(T)) {
1038 .Float, .Int, .Struct, .Union, .Enum, .Array, .Bool, .Vector => return @sizeOf(T),
1039 .Fn => {
1040 // sizeof(main) returns 1, sizeof(&main) returns pointer size.
1041 // We cannot distinguish those types in Zig, so use pointer size.
1042 return @sizeOf(T);
1043 },
1044 .Null => return @sizeOf(*c_void),
1045 .Void => {
1046 // Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
1047 return 1;
1048 },
1049 .Opaque => {
1050 if (T == c_void) {
1051 // Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
1052 return 1;
1053 } else {
1054 @compileError("Cannot use C sizeof on opaque type " ++ @typeName(T));
1055 }
1056 },
1057 .Optional => |opt| {
1058 if (@typeInfo(opt.child) == .Pointer) {
1059 return sizeof(opt.child);
1060 } else {
1061 @compileError("Cannot use C sizeof on non-pointer optional " ++ @typeName(T));
1062 }
1063 },
1064 .Pointer => |ptr| {
1065 if (ptr.size == .Slice) {
1066 @compileError("Cannot use C sizeof on slice type " ++ @typeName(T));
1067 }
1068 // for strings, sizeof("a") returns 2.
1069 // normal pointer decay scenarios from C are handled
1070 // in the .Array case above, but strings remain literals
1071 // and are therefore always pointers, so they need to be
1072 // specially handled here.
1073 if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .Array) {
1074 const array_info = @typeInfo(ptr.child).Array;
1075 if ((array_info.child == u8 or array_info.child == u16) and
1076 array_info.sentinel != null and
1077 array_info.sentinel.? == 0)
1078 {
1079 // length of the string plus one for the null terminator.
1080 return (array_info.len + 1) * @sizeOf(array_info.child);
1081 }
1082 }
1083 // When zero sized pointers are removed, this case will no
1084 // longer be reachable and can be deleted.
1085 if (@sizeOf(T) == 0) {
1086 return @sizeOf(*c_void);
1087 }
1088 return @sizeOf(T);
1089 },
1090 .ComptimeFloat => return @sizeOf(f64), // TODO c_double #3999
1091 .ComptimeInt => {
1092 // TODO to get the correct result we have to translate
1093 // `1073741824 * 4` as `int(1073741824) *% int(4)` since
1094 // sizeof(1073741824 * 4) != sizeof(4294967296).
1095
1096 // TODO test if target fits in int, long or long long
1097 return @sizeOf(c_int);
1098 },
1099 else => @compileError("std.meta.sizeof does not support type " ++ @typeName(T)),
1100 }
1101}
1102
1103test "sizeof" {
1104 const E = enum(c_int) { One, _ };
1105 const S = extern struct { a: u32 };
1106
1107 const ptr_size = @sizeOf(*c_void);
1108
1109 try testing.expect(sizeof(u32) == 4);
1110 try testing.expect(sizeof(@as(u32, 2)) == 4);
1111 try testing.expect(sizeof(2) == @sizeOf(c_int));
1112
1113 try testing.expect(sizeof(2.0) == @sizeOf(f64));
1114
1115 try testing.expect(sizeof(E) == @sizeOf(c_int));
1116 try testing.expect(sizeof(E.One) == @sizeOf(c_int));
1117
1118 try testing.expect(sizeof(S) == 4);
1119
1120 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
1121 try testing.expect(sizeof([3]u32) == 12);
1122 try testing.expect(sizeof([3:0]u32) == 16);
1123 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
1124
1125 try testing.expect(sizeof(*u32) == ptr_size);
1126 try testing.expect(sizeof([*]u32) == ptr_size);
1127 try testing.expect(sizeof([*c]u32) == ptr_size);
1128 try testing.expect(sizeof(?*u32) == ptr_size);
1129 try testing.expect(sizeof(?[*]u32) == ptr_size);
1130 try testing.expect(sizeof(*c_void) == ptr_size);
1131 try testing.expect(sizeof(*void) == ptr_size);
1132 try testing.expect(sizeof(null) == ptr_size);
1133
1134 try testing.expect(sizeof("foobar") == 7);
1135 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
1136 try testing.expect(sizeof(*const [4:0]u8) == 5);
1137 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
1138 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
1139 try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
1140 try testing.expect(sizeof(*const [4]u8) == ptr_size);
1141
1142 try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
1143
1144 try testing.expect(sizeof(void) == 1);
1145 try testing.expect(sizeof(c_void) == 1);
1146}
1147
1148pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
1149
1150fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
1151 const signed_decimal = [_]type{ c_int, c_long, c_longlong };
1152 const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
1153 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
1154
1155 const list: []const type = if (@typeInfo(SuffixType).Int.signedness == .unsigned)
1156 &unsigned
1157 else if (radix == .decimal)
1158 &signed_decimal
1159 else
1160 &signed_oct_hex;
1161
1162 var pos = mem.indexOfScalar(type, list, SuffixType).?;
1163
1164 while (pos < list.len) : (pos += 1) {
1165 if (number >= math.minInt(list[pos]) and number <= math.maxInt(list[pos])) {
1166 return list[pos];
1167 }
1168 }
1169 @compileError("Integer literal is too large");
1170}
1171
1172/// Promote the type of an integer literal until it fits as C would.
1173/// This is for translate-c and is not intended for general use.
1174pub fn promoteIntLiteral(
1175 comptime SuffixType: type,
1176 comptime number: comptime_int,
1177 comptime radix: CIntLiteralRadix,
1178) PromoteIntLiteralReturnType(SuffixType, number, radix) {
1179 return number;
1180}
1181
1182test "promoteIntLiteral" {
1183 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
1184 try testing.expectEqual(c_uint, @TypeOf(signed_hex));
1185
1186 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
1187
1188 const signed_decimal = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .decimal);
1189 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
1190
1191 if (math.maxInt(c_long) > math.maxInt(c_int)) {
1192 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
1193 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
1194 } else {
1195 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
1196 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
1197 }
1198}
1199
1200/// For a given function type, returns a tuple type which fields will887/// For a given function type, returns a tuple type which fields will
1201/// correspond to the argument types.888/// correspond to the argument types.
1202///889///
...@@ -1316,38 +1003,6 @@ pub fn globalOption(comptime name: []const u8, comptime T: type) ?T {...@@ -1316,38 +1003,6 @@ pub fn globalOption(comptime name: []const u8, comptime T: type) ?T {
1316 return @as(T, @field(root, name));1003 return @as(T, @field(root, name));
1317}1004}
13181005
1319/// This function is for translate-c and is not intended for general use.
1320/// Convert from clang __builtin_shufflevector index to Zig @shuffle index
1321/// clang requires __builtin_shufflevector index arguments to be integer constants.
1322/// negative values for `this_index` indicate "don't care" so we arbitrarily choose 0
1323/// clang enforces that `this_index` is less than the total number of vector elements
1324/// See https://ziglang.org/documentation/master/#shuffle
1325/// See https://clang.llvm.org/docs/LanguageExtensions.html#langext-builtin-shufflevector
1326pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 {
1327 if (this_index <= 0) return 0;
1328
1329 const positive_index = @intCast(usize, this_index);
1330 if (positive_index < source_vector_len) return @intCast(i32, this_index);
1331 const b_index = positive_index - source_vector_len;
1332 return ~@intCast(i32, b_index);
1333}
1334
1335test "shuffleVectorIndex" {
1336 const vector_len: usize = 4;
1337
1338 try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
1339
1340 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
1341 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
1342 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
1343 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
1344
1345 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
1346 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
1347 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
1348 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
1349}
1350
1351/// Returns whether `error_union` contains an error.1006/// Returns whether `error_union` contains an error.
1352pub fn isError(error_union: anytype) bool {1007pub fn isError(error_union: anytype) bool {
1353 return if (error_union) |_| false else |_| true;1008 return if (error_union) |_| false else |_| true;
...@@ -1357,34 +1012,3 @@ test "isError" {...@@ -1357,34 +1012,3 @@ test "isError" {
1357 try std.testing.expect(isError(math.absInt(@as(i8, -128))));1012 try std.testing.expect(isError(math.absInt(@as(i8, -128))));
1358 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));1013 try std.testing.expect(!isError(math.absInt(@as(i8, -127))));
1359}1014}
1360
1361/// This function is for translate-c and is not intended for general use.
1362/// Constructs a [*c] pointer with the const and volatile annotations
1363/// from SelfType for pointing to a C flexible array of ElementType.
1364pub fn FlexibleArrayType(comptime SelfType: type, ElementType: type) type {
1365 switch (@typeInfo(SelfType)) {
1366 .Pointer => |ptr| {
1367 return @Type(TypeInfo{ .Pointer = .{
1368 .size = .C,
1369 .is_const = ptr.is_const,
1370 .is_volatile = ptr.is_volatile,
1371 .alignment = @alignOf(ElementType),
1372 .child = ElementType,
1373 .is_allowzero = true,
1374 .sentinel = null,
1375 } });
1376 },
1377 else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)),
1378 }
1379}
1380
1381test "Flexible Array Type" {
1382 const Container = extern struct {
1383 size: usize,
1384 };
1385
1386 try testing.expectEqual(FlexibleArrayType(*Container, c_int), [*c]c_int);
1387 try testing.expectEqual(FlexibleArrayType(*const Container, c_int), [*c]const c_int);
1388 try testing.expectEqual(FlexibleArrayType(*volatile Container, c_int), [*c]volatile c_int);
1389 try testing.expectEqual(FlexibleArrayType(*const volatile Container, c_int), [*c]const volatile c_int);
1390}
lib/std/zig.zig+4
...@@ -16,6 +16,10 @@ pub const ast = @import("zig/ast.zig");...@@ -16,6 +16,10 @@ pub const ast = @import("zig/ast.zig");
16pub const system = @import("zig/system.zig");16pub const system = @import("zig/system.zig");
17pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget;17pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget;
1818
19// Files needed by translate-c.
20pub const c_builtins = @import("zig/c_builtins.zig");
21pub const c_translation = @import("zig/c_translation.zig");
22
19pub const SrcHash = [16]u8;23pub const SrcHash = [16]u8;
2024
21pub fn hashSrc(src: []const u8) SrcHash {25pub fn hashSrc(src: []const u8) SrcHash {
lib/std/zig/c_builtins.zig created+196
...@@ -0,0 +1,196 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("std");
8
9pub inline fn __builtin_bswap16(val: u16) u16 {
10 return @byteSwap(u16, val);
11}
12pub inline fn __builtin_bswap32(val: u32) u32 {
13 return @byteSwap(u32, val);
14}
15pub inline fn __builtin_bswap64(val: u64) u64 {
16 return @byteSwap(u64, val);
17}
18
19pub inline fn __builtin_signbit(val: f64) c_int {
20 return @boolToInt(std.math.signbit(val));
21}
22pub inline fn __builtin_signbitf(val: f32) c_int {
23 return @boolToInt(std.math.signbit(val));
24}
25
26pub inline fn __builtin_popcount(val: c_uint) c_int {
27 // popcount of a c_uint will never exceed the capacity of a c_int
28 @setRuntimeSafety(false);
29 return @bitCast(c_int, @as(c_uint, @popCount(c_uint, val)));
30}
31pub inline fn __builtin_ctz(val: c_uint) c_int {
32 // Returns the number of trailing 0-bits in val, starting at the least significant bit position.
33 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
34 @setRuntimeSafety(false);
35 return @bitCast(c_int, @as(c_uint, @ctz(c_uint, val)));
36}
37pub inline fn __builtin_clz(val: c_uint) c_int {
38 // Returns the number of leading 0-bits in x, starting at the most significant bit position.
39 // In C if `val` is 0, the result is undefined; in zig it's the number of bits in a c_uint
40 @setRuntimeSafety(false);
41 return @bitCast(c_int, @as(c_uint, @clz(c_uint, val)));
42}
43
44pub inline fn __builtin_sqrt(val: f64) f64 {
45 return @sqrt(val);
46}
47pub inline fn __builtin_sqrtf(val: f32) f32 {
48 return @sqrt(val);
49}
50
51pub inline fn __builtin_sin(val: f64) f64 {
52 return @sin(val);
53}
54pub inline fn __builtin_sinf(val: f32) f32 {
55 return @sin(val);
56}
57pub inline fn __builtin_cos(val: f64) f64 {
58 return @cos(val);
59}
60pub inline fn __builtin_cosf(val: f32) f32 {
61 return @cos(val);
62}
63
64pub inline fn __builtin_exp(val: f64) f64 {
65 return @exp(val);
66}
67pub inline fn __builtin_expf(val: f32) f32 {
68 return @exp(val);
69}
70pub inline fn __builtin_exp2(val: f64) f64 {
71 return @exp2(val);
72}
73pub inline fn __builtin_exp2f(val: f32) f32 {
74 return @exp2(val);
75}
76pub inline fn __builtin_log(val: f64) f64 {
77 return @log(val);
78}
79pub inline fn __builtin_logf(val: f32) f32 {
80 return @log(val);
81}
82pub inline fn __builtin_log2(val: f64) f64 {
83 return @log2(val);
84}
85pub inline fn __builtin_log2f(val: f32) f32 {
86 return @log2(val);
87}
88pub inline fn __builtin_log10(val: f64) f64 {
89 return @log10(val);
90}
91pub inline fn __builtin_log10f(val: f32) f32 {
92 return @log10(val);
93}
94
95// Standard C Library bug: The absolute value of the most negative integer remains negative.
96pub inline fn __builtin_abs(val: c_int) c_int {
97 return std.math.absInt(val) catch std.math.minInt(c_int);
98}
99pub inline fn __builtin_fabs(val: f64) f64 {
100 return @fabs(val);
101}
102pub inline fn __builtin_fabsf(val: f32) f32 {
103 return @fabs(val);
104}
105
106pub inline fn __builtin_floor(val: f64) f64 {
107 return @floor(val);
108}
109pub inline fn __builtin_floorf(val: f32) f32 {
110 return @floor(val);
111}
112pub inline fn __builtin_ceil(val: f64) f64 {
113 return @ceil(val);
114}
115pub inline fn __builtin_ceilf(val: f32) f32 {
116 return @ceil(val);
117}
118pub inline fn __builtin_trunc(val: f64) f64 {
119 return @trunc(val);
120}
121pub inline fn __builtin_truncf(val: f32) f32 {
122 return @trunc(val);
123}
124pub inline fn __builtin_round(val: f64) f64 {
125 return @round(val);
126}
127pub inline fn __builtin_roundf(val: f32) f32 {
128 return @round(val);
129}
130
131pub inline fn __builtin_strlen(s: [*c]const u8) usize {
132 return std.mem.lenZ(s);
133}
134pub inline fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) c_int {
135 return @as(c_int, std.cstr.cmp(s1, s2));
136}
137
138pub inline fn __builtin_object_size(ptr: ?*const c_void, ty: c_int) usize {
139 // clang semantics match gcc's: https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
140 // If it is not possible to determine which objects ptr points to at compile time,
141 // __builtin_object_size should return (size_t) -1 for type 0 or 1 and (size_t) 0
142 // for type 2 or 3.
143 if (ty == 0 or ty == 1) return @bitCast(usize, -@as(isize, 1));
144 if (ty == 2 or ty == 3) return 0;
145 unreachable;
146}
147
148pub inline fn __builtin___memset_chk(
149 dst: ?*c_void,
150 val: c_int,
151 len: usize,
152 remaining: usize,
153) ?*c_void {
154 if (len > remaining) @panic("std.c.builtins.memset_chk called with len > remaining");
155 return __builtin_memset(dst, val, len);
156}
157
158pub inline fn __builtin_memset(dst: ?*c_void, val: c_int, len: usize) ?*c_void {
159 const dst_cast = @ptrCast([*c]u8, dst);
160 @memset(dst_cast, @bitCast(u8, @truncate(i8, val)), len);
161 return dst;
162}
163
164pub inline fn __builtin___memcpy_chk(
165 noalias dst: ?*c_void,
166 noalias src: ?*const c_void,
167 len: usize,
168 remaining: usize,
169) ?*c_void {
170 if (len > remaining) @panic("std.c.builtins.memcpy_chk called with len > remaining");
171 return __builtin_memcpy(dst, src, len);
172}
173
174pub inline fn __builtin_memcpy(
175 noalias dst: ?*c_void,
176 noalias src: ?*const c_void,
177 len: usize,
178) ?*c_void {
179 const dst_cast = @ptrCast([*c]u8, dst);
180 const src_cast = @ptrCast([*c]const u8, src);
181
182 @memcpy(dst_cast, src_cast, len);
183 return dst;
184}
185
186/// The return value of __builtin_expect is `expr`. `c` is the expected value
187/// of `expr` and is used as a hint to the compiler in C. Here it is unused.
188pub inline fn __builtin_expect(expr: c_long, c: c_long) c_long {
189 return expr;
190}
191
192// __builtin_alloca_with_align is not currently implemented.
193// It is used in a run-translated-c test and a test-translate-c test to ensure that non-implemented
194// builtins are correctly demoted. If you implement __builtin_alloca_with_align, please update the
195// run-translated-c test and the test-translate-c test to use a different non-implemented builtin.
196// pub fn __builtin_alloca_with_align(size: usize, alignment: usize) callconv(.Inline) *c_void {}
lib/std/zig/c_translation.zig created+385
...@@ -0,0 +1,385 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2021 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6
7const std = @import("std");
8const testing = std.testing;
9const math = std.math;
10const mem = std.mem;
11
12/// Given a type and value, cast the value to the type as c would.
13pub fn cast(comptime DestType: type, target: anytype) DestType {
14 // this function should behave like transCCast in translate-c, except it's for macros and enums
15 const SourceType = @TypeOf(target);
16 switch (@typeInfo(DestType)) {
17 .Fn, .Pointer => return castToPtr(DestType, SourceType, target),
18 .Optional => |dest_opt| {
19 if (@typeInfo(dest_opt.child) == .Pointer or @typeInfo(dest_opt.child) == .Fn) {
20 return castToPtr(DestType, SourceType, target);
21 }
22 },
23 .Enum => |enum_type| {
24 if (@typeInfo(SourceType) == .Int or @typeInfo(SourceType) == .ComptimeInt) {
25 const intermediate = cast(enum_type.tag_type, target);
26 return @intToEnum(DestType, intermediate);
27 }
28 },
29 .Int => {
30 switch (@typeInfo(SourceType)) {
31 .Pointer => {
32 return castInt(DestType, @ptrToInt(target));
33 },
34 .Optional => |opt| {
35 if (@typeInfo(opt.child) == .Pointer) {
36 return castInt(DestType, @ptrToInt(target));
37 }
38 },
39 .Enum => {
40 return castInt(DestType, @enumToInt(target));
41 },
42 .Int => {
43 return castInt(DestType, target);
44 },
45 else => {},
46 }
47 },
48 else => {},
49 }
50 return @as(DestType, target);
51}
52
53fn castInt(comptime DestType: type, target: anytype) DestType {
54 const dest = @typeInfo(DestType).Int;
55 const source = @typeInfo(@TypeOf(target)).Int;
56
57 if (dest.bits < source.bits)
58 return @bitCast(DestType, @truncate(std.meta.Int(source.signedness, dest.bits), target))
59 else
60 return @bitCast(DestType, @as(std.meta.Int(source.signedness, dest.bits), target));
61}
62
63fn castPtr(comptime DestType: type, target: anytype) DestType {
64 const dest = ptrInfo(DestType);
65 const source = ptrInfo(@TypeOf(target));
66
67 if (source.is_const and !dest.is_const or source.is_volatile and !dest.is_volatile)
68 return @intToPtr(DestType, @ptrToInt(target))
69 else if (@typeInfo(dest.child) == .Opaque)
70 // dest.alignment would error out
71 return @ptrCast(DestType, target)
72 else
73 return @ptrCast(DestType, @alignCast(dest.alignment, target));
74}
75
76fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {
77 switch (@typeInfo(SourceType)) {
78 .Int => {
79 return @intToPtr(DestType, castInt(usize, target));
80 },
81 .ComptimeInt => {
82 if (target < 0)
83 return @intToPtr(DestType, @bitCast(usize, @intCast(isize, target)))
84 else
85 return @intToPtr(DestType, @intCast(usize, target));
86 },
87 .Pointer => {
88 return castPtr(DestType, target);
89 },
90 .Optional => |target_opt| {
91 if (@typeInfo(target_opt.child) == .Pointer) {
92 return castPtr(DestType, target);
93 }
94 },
95 else => {},
96 }
97 return @as(DestType, target);
98}
99
100fn ptrInfo(comptime PtrType: type) std.builtin.TypeInfo.Pointer {
101 return switch (@typeInfo(PtrType)) {
102 .Optional => |opt_info| @typeInfo(opt_info.child).Pointer,
103 .Pointer => |ptr_info| ptr_info,
104 else => unreachable,
105 };
106}
107
108test "cast" {
109 const E = enum(u2) {
110 Zero,
111 One,
112 Two,
113 };
114
115 var i = @as(i64, 10);
116
117 try testing.expect(cast(*u8, 16) == @intToPtr(*u8, 16));
118 try testing.expect(cast(*u64, &i).* == @as(u64, 10));
119 try testing.expect(cast(*i64, @as(?*align(1) i64, &i)) == &i);
120
121 try testing.expect(cast(?*u8, 2) == @intToPtr(*u8, 2));
122 try testing.expect(cast(?*i64, @as(*align(1) i64, &i)) == &i);
123 try testing.expect(cast(?*i64, @as(?*align(1) i64, &i)) == &i);
124
125 try testing.expect(cast(E, 1) == .One);
126
127 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(*u32, 4)));
128 try testing.expectEqual(@as(u32, 4), cast(u32, @intToPtr(?*u32, 4)));
129 try testing.expectEqual(@as(u32, 10), cast(u32, @as(u64, 10)));
130 try testing.expectEqual(@as(u8, 2), cast(u8, E.Two));
131
132 try testing.expectEqual(@bitCast(i32, @as(u32, 0x8000_0000)), cast(i32, @as(u32, 0x8000_0000)));
133
134 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*const u8, 2)));
135 try testing.expectEqual(@intToPtr(*u8, 2), cast(*u8, @intToPtr(*volatile u8, 2)));
136
137 try testing.expectEqual(@intToPtr(?*c_void, 2), cast(?*c_void, @intToPtr(*u8, 2)));
138
139 const C_ENUM = enum(c_int) {
140 A = 0,
141 B,
142 C,
143 _,
144 };
145 try testing.expectEqual(cast(C_ENUM, @as(i64, -1)), @intToEnum(C_ENUM, -1));
146 try testing.expectEqual(cast(C_ENUM, @as(i8, 1)), .B);
147 try testing.expectEqual(cast(C_ENUM, @as(u64, 1)), .B);
148 try testing.expectEqual(cast(C_ENUM, @as(u64, 42)), @intToEnum(C_ENUM, 42));
149
150 var foo: c_int = -1;
151 try testing.expect(cast(*c_void, -1) == @intToPtr(*c_void, @bitCast(usize, @as(isize, -1))));
152 try testing.expect(cast(*c_void, foo) == @intToPtr(*c_void, @bitCast(usize, @as(isize, -1))));
153 try testing.expect(cast(?*c_void, -1) == @intToPtr(?*c_void, @bitCast(usize, @as(isize, -1))));
154 try testing.expect(cast(?*c_void, foo) == @intToPtr(?*c_void, @bitCast(usize, @as(isize, -1))));
155
156 const FnPtr = ?fn (*c_void) void;
157 try testing.expect(cast(FnPtr, 0) == @intToPtr(FnPtr, @as(usize, 0)));
158 try testing.expect(cast(FnPtr, foo) == @intToPtr(FnPtr, @bitCast(usize, @as(isize, -1))));
159}
160
161/// Given a value returns its size as C's sizeof operator would.
162pub fn sizeof(target: anytype) usize {
163 const T: type = if (@TypeOf(target) == type) target else @TypeOf(target);
164 switch (@typeInfo(T)) {
165 .Float, .Int, .Struct, .Union, .Enum, .Array, .Bool, .Vector => return @sizeOf(T),
166 .Fn => {
167 // sizeof(main) returns 1, sizeof(&main) returns pointer size.
168 // We cannot distinguish those types in Zig, so use pointer size.
169 return @sizeOf(T);
170 },
171 .Null => return @sizeOf(*c_void),
172 .Void => {
173 // Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
174 return 1;
175 },
176 .Opaque => {
177 if (T == c_void) {
178 // Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
179 return 1;
180 } else {
181 @compileError("Cannot use C sizeof on opaque type " ++ @typeName(T));
182 }
183 },
184 .Optional => |opt| {
185 if (@typeInfo(opt.child) == .Pointer) {
186 return sizeof(opt.child);
187 } else {
188 @compileError("Cannot use C sizeof on non-pointer optional " ++ @typeName(T));
189 }
190 },
191 .Pointer => |ptr| {
192 if (ptr.size == .Slice) {
193 @compileError("Cannot use C sizeof on slice type " ++ @typeName(T));
194 }
195 // for strings, sizeof("a") returns 2.
196 // normal pointer decay scenarios from C are handled
197 // in the .Array case above, but strings remain literals
198 // and are therefore always pointers, so they need to be
199 // specially handled here.
200 if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .Array) {
201 const array_info = @typeInfo(ptr.child).Array;
202 if ((array_info.child == u8 or array_info.child == u16) and
203 array_info.sentinel != null and
204 array_info.sentinel.? == 0)
205 {
206 // length of the string plus one for the null terminator.
207 return (array_info.len + 1) * @sizeOf(array_info.child);
208 }
209 }
210 // When zero sized pointers are removed, this case will no
211 // longer be reachable and can be deleted.
212 if (@sizeOf(T) == 0) {
213 return @sizeOf(*c_void);
214 }
215 return @sizeOf(T);
216 },
217 .ComptimeFloat => return @sizeOf(f64), // TODO c_double #3999
218 .ComptimeInt => {
219 // TODO to get the correct result we have to translate
220 // `1073741824 * 4` as `int(1073741824) *% int(4)` since
221 // sizeof(1073741824 * 4) != sizeof(4294967296).
222
223 // TODO test if target fits in int, long or long long
224 return @sizeOf(c_int);
225 },
226 else => @compileError("std.meta.sizeof does not support type " ++ @typeName(T)),
227 }
228}
229
230test "sizeof" {
231 const E = enum(c_int) { One, _ };
232 const S = extern struct { a: u32 };
233
234 const ptr_size = @sizeOf(*c_void);
235
236 try testing.expect(sizeof(u32) == 4);
237 try testing.expect(sizeof(@as(u32, 2)) == 4);
238 try testing.expect(sizeof(2) == @sizeOf(c_int));
239
240 try testing.expect(sizeof(2.0) == @sizeOf(f64));
241
242 try testing.expect(sizeof(E) == @sizeOf(c_int));
243 try testing.expect(sizeof(E.One) == @sizeOf(c_int));
244
245 try testing.expect(sizeof(S) == 4);
246
247 try testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
248 try testing.expect(sizeof([3]u32) == 12);
249 try testing.expect(sizeof([3:0]u32) == 16);
250 try testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
251
252 try testing.expect(sizeof(*u32) == ptr_size);
253 try testing.expect(sizeof([*]u32) == ptr_size);
254 try testing.expect(sizeof([*c]u32) == ptr_size);
255 try testing.expect(sizeof(?*u32) == ptr_size);
256 try testing.expect(sizeof(?[*]u32) == ptr_size);
257 try testing.expect(sizeof(*c_void) == ptr_size);
258 try testing.expect(sizeof(*void) == ptr_size);
259 try testing.expect(sizeof(null) == ptr_size);
260
261 try testing.expect(sizeof("foobar") == 7);
262 try testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
263 try testing.expect(sizeof(*const [4:0]u8) == 5);
264 try testing.expect(sizeof(*[4:0]u8) == ptr_size);
265 try testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
266 try testing.expect(sizeof(*const *const [4:0]u8) == ptr_size);
267 try testing.expect(sizeof(*const [4]u8) == ptr_size);
268
269 try testing.expect(sizeof(sizeof) == @sizeOf(@TypeOf(sizeof)));
270
271 try testing.expect(sizeof(void) == 1);
272 try testing.expect(sizeof(c_void) == 1);
273}
274
275pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
276
277fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
278 const signed_decimal = [_]type{ c_int, c_long, c_longlong };
279 const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
280 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
281
282 const list: []const type = if (@typeInfo(SuffixType).Int.signedness == .unsigned)
283 &unsigned
284 else if (radix == .decimal)
285 &signed_decimal
286 else
287 &signed_oct_hex;
288
289 var pos = mem.indexOfScalar(type, list, SuffixType).?;
290
291 while (pos < list.len) : (pos += 1) {
292 if (number >= math.minInt(list[pos]) and number <= math.maxInt(list[pos])) {
293 return list[pos];
294 }
295 }
296 @compileError("Integer literal is too large");
297}
298
299/// Promote the type of an integer literal until it fits as C would.
300pub fn promoteIntLiteral(
301 comptime SuffixType: type,
302 comptime number: comptime_int,
303 comptime radix: CIntLiteralRadix,
304) PromoteIntLiteralReturnType(SuffixType, number, radix) {
305 return number;
306}
307
308test "promoteIntLiteral" {
309 const signed_hex = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .hexadecimal);
310 try testing.expectEqual(c_uint, @TypeOf(signed_hex));
311
312 if (math.maxInt(c_longlong) == math.maxInt(c_int)) return;
313
314 const signed_decimal = promoteIntLiteral(c_int, math.maxInt(c_int) + 1, .decimal);
315 const unsigned = promoteIntLiteral(c_uint, math.maxInt(c_uint) + 1, .hexadecimal);
316
317 if (math.maxInt(c_long) > math.maxInt(c_int)) {
318 try testing.expectEqual(c_long, @TypeOf(signed_decimal));
319 try testing.expectEqual(c_ulong, @TypeOf(unsigned));
320 } else {
321 try testing.expectEqual(c_longlong, @TypeOf(signed_decimal));
322 try testing.expectEqual(c_ulonglong, @TypeOf(unsigned));
323 }
324}
325
326/// Convert from clang __builtin_shufflevector index to Zig @shuffle index
327/// clang requires __builtin_shufflevector index arguments to be integer constants.
328/// negative values for `this_index` indicate "don't care" so we arbitrarily choose 0
329/// clang enforces that `this_index` is less than the total number of vector elements
330/// See https://ziglang.org/documentation/master/#shuffle
331/// See https://clang.llvm.org/docs/LanguageExtensions.html#langext-builtin-shufflevector
332pub fn shuffleVectorIndex(comptime this_index: c_int, comptime source_vector_len: usize) i32 {
333 if (this_index <= 0) return 0;
334
335 const positive_index = @intCast(usize, this_index);
336 if (positive_index < source_vector_len) return @intCast(i32, this_index);
337 const b_index = positive_index - source_vector_len;
338 return ~@intCast(i32, b_index);
339}
340
341test "shuffleVectorIndex" {
342 const vector_len: usize = 4;
343
344 try testing.expect(shuffleVectorIndex(-1, vector_len) == 0);
345
346 try testing.expect(shuffleVectorIndex(0, vector_len) == 0);
347 try testing.expect(shuffleVectorIndex(1, vector_len) == 1);
348 try testing.expect(shuffleVectorIndex(2, vector_len) == 2);
349 try testing.expect(shuffleVectorIndex(3, vector_len) == 3);
350
351 try testing.expect(shuffleVectorIndex(4, vector_len) == -1);
352 try testing.expect(shuffleVectorIndex(5, vector_len) == -2);
353 try testing.expect(shuffleVectorIndex(6, vector_len) == -3);
354 try testing.expect(shuffleVectorIndex(7, vector_len) == -4);
355}
356
357/// Constructs a [*c] pointer with the const and volatile annotations
358/// from SelfType for pointing to a C flexible array of ElementType.
359pub fn FlexibleArrayType(comptime SelfType: type, ElementType: type) type {
360 switch (@typeInfo(SelfType)) {
361 .Pointer => |ptr| {
362 return @Type(.{ .Pointer = .{
363 .size = .C,
364 .is_const = ptr.is_const,
365 .is_volatile = ptr.is_volatile,
366 .alignment = @alignOf(ElementType),
367 .child = ElementType,
368 .is_allowzero = true,
369 .sentinel = null,
370 } });
371 },
372 else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)),
373 }
374}
375
376test "Flexible Array Type" {
377 const Container = extern struct {
378 size: usize,
379 };
380
381 try testing.expectEqual(FlexibleArrayType(*Container, c_int), [*c]c_int);
382 try testing.expectEqual(FlexibleArrayType(*const Container, c_int), [*c]const c_int);
383 try testing.expectEqual(FlexibleArrayType(*volatile Container, c_int), [*c]volatile c_int);
384 try testing.expectEqual(FlexibleArrayType(*const volatile Container, c_int), [*c]const volatile c_int);
385}
src/translate_c.zig+35-23
...@@ -12,7 +12,6 @@ const meta = std.meta;...@@ -12,7 +12,6 @@ const meta = std.meta;
12const ast = @import("translate_c/ast.zig");12const ast = @import("translate_c/ast.zig");
13const Node = ast.Node;13const Node = ast.Node;
14const Tag = Node.Tag;14const Tag = Node.Tag;
15const c_builtins = std.c.builtins;
1615
17const CallingConvention = std.builtin.CallingConvention;16const CallingConvention = std.builtin.CallingConvention;
1817
...@@ -863,7 +862,7 @@ fn buildFlexibleArrayFn(...@@ -863,7 +862,7 @@ fn buildFlexibleArrayFn(
863 defer block_scope.deinit();862 defer block_scope.deinit();
864863
865 const intermediate_type_name = try block_scope.makeMangledName(c, "Intermediate");864 const intermediate_type_name = try block_scope.makeMangledName(c, "Intermediate");
866 const intermediate_type = try Tag.std_meta_flexible_array_type.create(c.arena, .{ .lhs = self_type, .rhs = u8_type });865 const intermediate_type = try Tag.helpers_flexible_array_type.create(c.arena, .{ .lhs = self_type, .rhs = u8_type });
867 const intermediate_type_decl = try Tag.var_simple.create(c.arena, .{866 const intermediate_type_decl = try Tag.var_simple.create(c.arena, .{
868 .name = intermediate_type_name,867 .name = intermediate_type_name,
869 .init = intermediate_type,868 .init = intermediate_type,
...@@ -872,7 +871,7 @@ fn buildFlexibleArrayFn(...@@ -872,7 +871,7 @@ fn buildFlexibleArrayFn(
872 const intermediate_type_ident = try Tag.identifier.create(c.arena, intermediate_type_name);871 const intermediate_type_ident = try Tag.identifier.create(c.arena, intermediate_type_name);
873872
874 const return_type_name = try block_scope.makeMangledName(c, "ReturnType");873 const return_type_name = try block_scope.makeMangledName(c, "ReturnType");
875 const return_type = try Tag.std_meta_flexible_array_type.create(c.arena, .{ .lhs = self_type, .rhs = element_type });874 const return_type = try Tag.helpers_flexible_array_type.create(c.arena, .{ .lhs = self_type, .rhs = element_type });
876 const return_type_decl = try Tag.var_simple.create(c.arena, .{875 const return_type_decl = try Tag.var_simple.create(c.arena, .{
877 .name = return_type_name,876 .name = return_type_name,
878 .init = return_type,877 .init = return_type,
...@@ -1290,9 +1289,19 @@ fn transStmt(...@@ -1290,9 +1289,19 @@ fn transStmt(
1290 return maybeSuppressResult(c, scope, result_used, shuffle_vec_node);1289 return maybeSuppressResult(c, scope, result_used, shuffle_vec_node);
1291 },1290 },
1292 // When adding new cases here, see comment for maybeBlockify()1291 // When adding new cases here, see comment for maybeBlockify()
1293 else => {1292 .GCCAsmStmtClass,
1294 return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO implement translation of stmt class {s}", .{@tagName(sc)});1293 .GotoStmtClass,
1295 },1294 .IndirectGotoStmtClass,
1295 .AttributedStmtClass,
1296 .AddrLabelExprClass,
1297 .AtomicExprClass,
1298 .BlockExprClass,
1299 .UserDefinedLiteralClass,
1300 .BuiltinBitCastExprClass,
1301 .DesignatedInitExprClass,
1302 .LabelStmtClass,
1303 => return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO implement translation of stmt class {s}", .{@tagName(sc)}),
1304 else => return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "unsupported stmt class {s}", .{@tagName(sc)}),
1296 }1305 }
1297}1306}
12981307
...@@ -1374,7 +1383,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE...@@ -1374,7 +1383,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE
13741383
1375 for (init_list) |*init, i| {1384 for (init_list) |*init, i| {
1376 const index_expr = try transExprCoercing(c, scope, expr.getExpr(@intCast(c_uint, i + 2)), .used);1385 const index_expr = try transExprCoercing(c, scope, expr.getExpr(@intCast(c_uint, i + 2)), .used);
1377 const converted_index = try Tag.std_meta_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len });1386 const converted_index = try Tag.helpers_shuffle_vector_index.create(c.arena, .{ .lhs = index_expr, .rhs = vector_len });
1378 init.* = converted_index;1387 init.* = converted_index;
1379 }1388 }
13801389
...@@ -1820,13 +1829,10 @@ fn transDeclStmtOne(...@@ -1820,13 +1829,10 @@ fn transDeclStmtOne(
1820 .Function => {1829 .Function => {
1821 try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));1830 try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));
1822 },1831 },
1823 else => |kind| return fail(1832 else => {
1824 c,1833 const decl_name = try c.str(decl.getDeclKindName());
1825 error.UnsupportedTranslation,1834 try warn(c, &c.global_scope.base, decl.getLocation(), "ignoring {s} declaration", .{decl_name});
1826 decl.getLocation(),1835 },
1827 "TODO implement translation of DeclStmt kind {s}",
1828 .{@tagName(kind)},
1829 ),
1830 }1836 }
1831}1837}
18321838
...@@ -1902,7 +1908,7 @@ fn transImplicitCastExpr(...@@ -1902,7 +1908,7 @@ fn transImplicitCastExpr(
1902 const ne = try Tag.not_equal.create(c.arena, .{ .lhs = ptr_to_int, .rhs = Tag.zero_literal.init() });1908 const ne = try Tag.not_equal.create(c.arena, .{ .lhs = ptr_to_int, .rhs = Tag.zero_literal.init() });
1903 return maybeSuppressResult(c, scope, result_used, ne);1909 return maybeSuppressResult(c, scope, result_used, ne);
1904 },1910 },
1905 .IntegralToBoolean => {1911 .IntegralToBoolean, .FloatingToBoolean => {
1906 const sub_expr_node = try transExpr(c, scope, sub_expr, .used);1912 const sub_expr_node = try transExpr(c, scope, sub_expr, .used);
19071913
1908 // The expression is already a boolean one, return it as-is1914 // The expression is already a boolean one, return it as-is
...@@ -1924,14 +1930,14 @@ fn transImplicitCastExpr(...@@ -1924,14 +1930,14 @@ fn transImplicitCastExpr(
1924 c,1930 c,
1925 error.UnsupportedTranslation,1931 error.UnsupportedTranslation,
1926 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),1932 @ptrCast(*const clang.Stmt, expr).getBeginLoc(),
1927 "TODO implement translation of CastKind {s}",1933 "unsupported CastKind {s}",
1928 .{@tagName(kind)},1934 .{@tagName(kind)},
1929 ),1935 ),
1930 }1936 }
1931}1937}
19321938
1933fn isBuiltinDefined(name: []const u8) bool {1939fn isBuiltinDefined(name: []const u8) bool {
1934 inline for (meta.declarations(c_builtins)) |decl| {1940 inline for (meta.declarations(std.zig.c_builtins)) |decl| {
1935 if (std.mem.eql(u8, name, decl.name)) return true;1941 if (std.mem.eql(u8, name, decl.name)) return true;
1936 }1942 }
1937 return false;1943 return false;
...@@ -2358,8 +2364,10 @@ fn transCCast(...@@ -2358,8 +2364,10 @@ fn transCCast(
2358 return Tag.float_to_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr });2364 return Tag.float_to_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2359 }2365 }
2360 if (!cIsFloating(src_type) and cIsFloating(dst_type)) {2366 if (!cIsFloating(src_type) and cIsFloating(dst_type)) {
2367 var rhs = expr;
2368 if (qualTypeIsBoolean(src_type)) rhs = try Tag.bool_to_int.create(c.arena, expr);
2361 // @intToFloat(dest_type, val)2369 // @intToFloat(dest_type, val)
2362 return Tag.int_to_float.create(c.arena, .{ .lhs = dst_node, .rhs = expr });2370 return Tag.int_to_float.create(c.arena, .{ .lhs = dst_node, .rhs = rhs });
2363 }2371 }
2364 if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) {2372 if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) {
2365 // @boolToInt returns either a comptime_int or a u12373 // @boolToInt returns either a comptime_int or a u1
...@@ -2370,7 +2378,7 @@ fn transCCast(...@@ -2370,7 +2378,7 @@ fn transCCast(
2370 }2378 }
2371 if (cIsEnum(dst_type)) {2379 if (cIsEnum(dst_type)) {
2372 // import("std").meta.cast(dest_type, val)2380 // import("std").meta.cast(dest_type, val)
2373 return Tag.std_meta_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });2381 return Tag.helpers_cast.create(c.arena, .{ .lhs = dst_node, .rhs = expr });
2374 }2382 }
2375 if (cIsEnum(src_type) and !cIsEnum(dst_type)) {2383 if (cIsEnum(src_type) and !cIsEnum(dst_type)) {
2376 // @enumToInt(val)2384 // @enumToInt(val)
...@@ -4547,6 +4555,10 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan...@@ -4547,6 +4555,10 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
4547 .rhs = try transQualType(c, scope, element_qt, source_loc),4555 .rhs = try transQualType(c, scope, element_qt, source_loc),
4548 });4556 });
4549 },4557 },
4558 .ExtInt, .ExtVector => {
4559 const type_name = c.str(ty.getTypeClassName());
4560 return fail(c, error.UnsupportedType, source_loc, "TODO implement translation of type: '{s}'", .{type_name});
4561 },
4550 else => {4562 else => {
4551 const type_name = c.str(ty.getTypeClassName());4563 const type_name = c.str(ty.getTypeClassName());
4552 return fail(c, error.UnsupportedType, source_loc, "unsupported type: '{s}'", .{type_name});4564 return fail(c, error.UnsupportedType, source_loc, "unsupported type: '{s}'", .{type_name});
...@@ -4982,7 +4994,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {...@@ -4982,7 +4994,7 @@ fn transMacroFnDefine(c: *Context, m: *MacroCtx) ParseError!void {
4982 break :blk br.data.val;4994 break :blk br.data.val;
4983 } else expr;4995 } else expr;
49844996
4985 const return_type = if (typeof_arg.castTag(.std_meta_cast) orelse typeof_arg.castTag(.std_mem_zeroinit)) |some|4997 const return_type = if (typeof_arg.castTag(.helpers_cast) orelse typeof_arg.castTag(.std_mem_zeroinit)) |some|
4986 some.data.lhs4998 some.data.lhs
4987 else if (typeof_arg.castTag(.std_mem_zeroes)) |some|4999 else if (typeof_arg.castTag(.std_mem_zeroes)) |some|
4988 some.data5000 some.data
...@@ -5095,7 +5107,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {...@@ -5095,7 +5107,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
5095 if (guaranteed_to_fit) {5107 if (guaranteed_to_fit) {
5096 return Tag.as.create(c.arena, .{ .lhs = type_node, .rhs = literal_node });5108 return Tag.as.create(c.arena, .{ .lhs = type_node, .rhs = literal_node });
5097 } else {5109 } else {
5098 return Tag.std_meta_promoteIntLiteral.create(c.arena, .{5110 return Tag.helpers_promoteIntLiteral.create(c.arena, .{
5099 .type = type_node,5111 .type = type_node,
5100 .value = literal_node,5112 .value = literal_node,
5101 .radix = try Tag.enum_literal.create(c.arena, radix),5113 .radix = try Tag.enum_literal.create(c.arena, radix),
...@@ -5578,7 +5590,7 @@ fn parseCCastExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {...@@ -5578,7 +5590,7 @@ fn parseCCastExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5578 return parseCPostfixExpr(c, m, scope, type_name);5590 return parseCPostfixExpr(c, m, scope, type_name);
5579 }5591 }
5580 const node_to_cast = try parseCCastExpr(c, m, scope);5592 const node_to_cast = try parseCCastExpr(c, m, scope);
5581 return Tag.std_meta_cast.create(c.arena, .{ .lhs = type_name, .rhs = node_to_cast });5593 return Tag.helpers_cast.create(c.arena, .{ .lhs = type_name, .rhs = node_to_cast });
5582 }5594 }
5583 },5595 },
5584 else => {},5596 else => {},
...@@ -5925,7 +5937,7 @@ fn parseCUnaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {...@@ -5925,7 +5937,7 @@ fn parseCUnaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
5925 break :blk inner;5937 break :blk inner;
5926 } else try parseCUnaryExpr(c, m, scope);5938 } else try parseCUnaryExpr(c, m, scope);
59275939
5928 return Tag.std_meta_sizeof.create(c.arena, operand);5940 return Tag.helpers_sizeof.create(c.arena, operand);
5929 },5941 },
5930 .Keyword_alignof => {5942 .Keyword_alignof => {
5931 // TODO this won't work if using <stdalign.h>'s5943 // TODO this won't work if using <stdalign.h>'s
src/translate_c/ast.zig+44-43
...@@ -74,7 +74,7 @@ pub const Node = extern union {...@@ -74,7 +74,7 @@ pub const Node = extern union {
74 tuple,74 tuple,
75 container_init,75 container_init,
76 container_init_dot,76 container_init_dot,
77 std_meta_cast,77 helpers_cast,
78 /// _ = operand;78 /// _ = operand;
79 discard,79 discard,
8080
...@@ -124,8 +124,8 @@ pub const Node = extern union {...@@ -124,8 +124,8 @@ pub const Node = extern union {
124 std_math_Log2Int,124 std_math_Log2Int,
125 /// @intCast(lhs, rhs)125 /// @intCast(lhs, rhs)
126 int_cast,126 int_cast,
127 /// @import("std").meta.promoteIntLiteral(value, type, radix)127 /// @import("std").zig.c_translation.promoteIntLiteral(value, type, radix)
128 std_meta_promoteIntLiteral,128 helpers_promoteIntLiteral,
129 /// @import("std").meta.alignment(value)129 /// @import("std").meta.alignment(value)
130 std_meta_alignment,130 std_meta_alignment,
131 /// @rem(lhs, rhs)131 /// @rem(lhs, rhs)
...@@ -193,12 +193,12 @@ pub const Node = extern union {...@@ -193,12 +193,12 @@ pub const Node = extern union {
193 array_type,193 array_type,
194 null_sentinel_array_type,194 null_sentinel_array_type,
195195
196 /// @import("std").meta.sizeof(operand)196 /// @import("std").zig.c_translation.sizeof(operand)
197 std_meta_sizeof,197 helpers_sizeof,
198 /// @import("std").meta.FlexibleArrayType(lhs, rhs)198 /// @import("std").zig.c_translation.FlexibleArrayType(lhs, rhs)
199 std_meta_flexible_array_type,199 helpers_flexible_array_type,
200 /// @import("std").meta.shuffleVectorIndex(lhs, rhs)200 /// @import("std").zig.c_translation.shuffleVectorIndex(lhs, rhs)
201 std_meta_shuffle_vector_index,201 helpers_shuffle_vector_index,
202 /// @import("std").meta.Vector(lhs, rhs)202 /// @import("std").meta.Vector(lhs, rhs)
203 std_meta_vector,203 std_meta_vector,
204 /// @import("std").mem.zeroes(operand)204 /// @import("std").mem.zeroes(operand)
...@@ -272,7 +272,7 @@ pub const Node = extern union {...@@ -272,7 +272,7 @@ pub const Node = extern union {
272 .if_not_break,272 .if_not_break,
273 .switch_else,273 .switch_else,
274 .block_single,274 .block_single,
275 .std_meta_sizeof,275 .helpers_sizeof,
276 .std_meta_alignment,276 .std_meta_alignment,
277 .bool_to_int,277 .bool_to_int,
278 .sizeof,278 .sizeof,
...@@ -332,13 +332,13 @@ pub const Node = extern union {...@@ -332,13 +332,13 @@ pub const Node = extern union {
332 .align_cast,332 .align_cast,
333 .array_access,333 .array_access,
334 .std_mem_zeroinit,334 .std_mem_zeroinit,
335 .std_meta_flexible_array_type,335 .helpers_flexible_array_type,
336 .std_meta_shuffle_vector_index,336 .helpers_shuffle_vector_index,
337 .std_meta_vector,337 .std_meta_vector,
338 .ptr_cast,338 .ptr_cast,
339 .div_exact,339 .div_exact,
340 .offset_of,340 .offset_of,
341 .std_meta_cast,341 .helpers_cast,
342 => Payload.BinOp,342 => Payload.BinOp,
343343
344 .integer_literal,344 .integer_literal,
...@@ -362,7 +362,7 @@ pub const Node = extern union {...@@ -362,7 +362,7 @@ pub const Node = extern union {
362 .tuple => Payload.TupleInit,362 .tuple => Payload.TupleInit,
363 .container_init => Payload.ContainerInit,363 .container_init => Payload.ContainerInit,
364 .container_init_dot => Payload.ContainerInitDot,364 .container_init_dot => Payload.ContainerInitDot,
365 .std_meta_promoteIntLiteral => Payload.PromoteIntLiteral,365 .helpers_promoteIntLiteral => Payload.PromoteIntLiteral,
366 .block => Payload.Block,366 .block => Payload.Block,
367 .c_pointer, .single_pointer => Payload.Pointer,367 .c_pointer, .single_pointer => Payload.Pointer,
368 .array_type, .null_sentinel_array_type => Payload.Array,368 .array_type, .null_sentinel_array_type => Payload.Array,
...@@ -868,7 +868,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {...@@ -868,7 +868,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
868 // pub usingnamespace @import("std").c.builtins;868 // pub usingnamespace @import("std").c.builtins;
869 _ = try c.addToken(.keyword_pub, "pub");869 _ = try c.addToken(.keyword_pub, "pub");
870 const usingnamespace_token = try c.addToken(.keyword_usingnamespace, "usingnamespace");870 const usingnamespace_token = try c.addToken(.keyword_usingnamespace, "usingnamespace");
871 const import_node = try renderStdImport(c, "c", "builtins");871 const import_node = try renderStdImport(c, &.{ "zig", "c_builtins" });
872 _ = try c.addToken(.semicolon, ";");872 _ = try c.addToken(.semicolon, ";");
873873
874 return c.addNode(.{874 return c.addNode(.{
...@@ -882,52 +882,52 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {...@@ -882,52 +882,52 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
882 },882 },
883 .std_math_Log2Int => {883 .std_math_Log2Int => {
884 const payload = node.castTag(.std_math_Log2Int).?.data;884 const payload = node.castTag(.std_math_Log2Int).?.data;
885 const import_node = try renderStdImport(c, "math", "Log2Int");885 const import_node = try renderStdImport(c, &.{ "math", "Log2Int" });
886 return renderCall(c, import_node, &.{payload});886 return renderCall(c, import_node, &.{payload});
887 },887 },
888 .std_meta_cast => {888 .helpers_cast => {
889 const payload = node.castTag(.std_meta_cast).?.data;889 const payload = node.castTag(.helpers_cast).?.data;
890 const import_node = try renderStdImport(c, "meta", "cast");890 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "cast" });
891 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });891 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });
892 },892 },
893 .std_meta_promoteIntLiteral => {893 .helpers_promoteIntLiteral => {
894 const payload = node.castTag(.std_meta_promoteIntLiteral).?.data;894 const payload = node.castTag(.helpers_promoteIntLiteral).?.data;
895 const import_node = try renderStdImport(c, "meta", "promoteIntLiteral");895 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "promoteIntLiteral" });
896 return renderCall(c, import_node, &.{ payload.type, payload.value, payload.radix });896 return renderCall(c, import_node, &.{ payload.type, payload.value, payload.radix });
897 },897 },
898 .std_meta_alignment => {898 .std_meta_alignment => {
899 const payload = node.castTag(.std_meta_alignment).?.data;899 const payload = node.castTag(.std_meta_alignment).?.data;
900 const import_node = try renderStdImport(c, "meta", "alignment");900 const import_node = try renderStdImport(c, &.{ "meta", "alignment" });
901 return renderCall(c, import_node, &.{payload});901 return renderCall(c, import_node, &.{payload});
902 },902 },
903 .std_meta_sizeof => {903 .helpers_sizeof => {
904 const payload = node.castTag(.std_meta_sizeof).?.data;904 const payload = node.castTag(.helpers_sizeof).?.data;
905 const import_node = try renderStdImport(c, "meta", "sizeof");905 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "sizeof" });
906 return renderCall(c, import_node, &.{payload});906 return renderCall(c, import_node, &.{payload});
907 },907 },
908 .std_mem_zeroes => {908 .std_mem_zeroes => {
909 const payload = node.castTag(.std_mem_zeroes).?.data;909 const payload = node.castTag(.std_mem_zeroes).?.data;
910 const import_node = try renderStdImport(c, "mem", "zeroes");910 const import_node = try renderStdImport(c, &.{ "mem", "zeroes" });
911 return renderCall(c, import_node, &.{payload});911 return renderCall(c, import_node, &.{payload});
912 },912 },
913 .std_mem_zeroinit => {913 .std_mem_zeroinit => {
914 const payload = node.castTag(.std_mem_zeroinit).?.data;914 const payload = node.castTag(.std_mem_zeroinit).?.data;
915 const import_node = try renderStdImport(c, "mem", "zeroInit");915 const import_node = try renderStdImport(c, &.{ "mem", "zeroInit" });
916 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });916 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });
917 },917 },
918 .std_meta_flexible_array_type => {918 .helpers_flexible_array_type => {
919 const payload = node.castTag(.std_meta_flexible_array_type).?.data;919 const payload = node.castTag(.helpers_flexible_array_type).?.data;
920 const import_node = try renderStdImport(c, "meta", "FlexibleArrayType");920 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "FlexibleArrayType" });
921 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });921 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });
922 },922 },
923 .std_meta_shuffle_vector_index => {923 .helpers_shuffle_vector_index => {
924 const payload = node.castTag(.std_meta_shuffle_vector_index).?.data;924 const payload = node.castTag(.helpers_shuffle_vector_index).?.data;
925 const import_node = try renderStdImport(c, "meta", "shuffleVectorIndex");925 const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "shuffleVectorIndex" });
926 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });926 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });
927 },927 },
928 .std_meta_vector => {928 .std_meta_vector => {
929 const payload = node.castTag(.std_meta_vector).?.data;929 const payload = node.castTag(.std_meta_vector).?.data;
930 const import_node = try renderStdImport(c, "meta", "Vector");930 const import_node = try renderStdImport(c, &.{ "meta", "Vector" });
931 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });931 return renderCall(c, import_node, &.{ payload.lhs, payload.rhs });
932 },932 },
933 .call => {933 .call => {
...@@ -2269,13 +2269,13 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {...@@ -2269,13 +2269,13 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
2269 .alignof,2269 .alignof,
2270 .typeof,2270 .typeof,
2271 .typeinfo,2271 .typeinfo,
2272 .std_meta_sizeof,
2273 .std_meta_alignment,2272 .std_meta_alignment,
2274 .std_meta_cast,
2275 .std_meta_promoteIntLiteral,
2276 .std_meta_vector,2273 .std_meta_vector,
2277 .std_meta_shuffle_vector_index,2274 .helpers_sizeof,
2278 .std_meta_flexible_array_type,2275 .helpers_cast,
2276 .helpers_promoteIntLiteral,
2277 .helpers_shuffle_vector_index,
2278 .helpers_flexible_array_type,
2279 .std_mem_zeroinit,2279 .std_mem_zeroinit,
2280 .integer_literal,2280 .integer_literal,
2281 .float_literal,2281 .float_literal,
...@@ -2442,7 +2442,7 @@ fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: Toke...@@ -2442,7 +2442,7 @@ fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: Toke
2442 });2442 });
2443}2443}
24442444
2445fn renderStdImport(c: *Context, first: []const u8, second: []const u8) !NodeIndex {2445fn renderStdImport(c: *Context, parts: []const []const u8) !NodeIndex {
2446 const import_tok = try c.addToken(.builtin, "@import");2446 const import_tok = try c.addToken(.builtin, "@import");
2447 _ = try c.addToken(.l_paren, "(");2447 _ = try c.addToken(.l_paren, "(");
2448 const std_tok = try c.addToken(.string_literal, "\"std\"");2448 const std_tok = try c.addToken(.string_literal, "\"std\"");
...@@ -2463,8 +2463,9 @@ fn renderStdImport(c: *Context, first: []const u8, second: []const u8) !NodeInde...@@ -2463,8 +2463,9 @@ fn renderStdImport(c: *Context, first: []const u8, second: []const u8) !NodeInde
2463 });2463 });
24642464
2465 var access_chain = import_node;2465 var access_chain = import_node;
2466 access_chain = try renderFieldAccess(c, access_chain, first);2466 for (parts) |part| {
2467 access_chain = try renderFieldAccess(c, access_chain, second);2467 access_chain = try renderFieldAccess(c, access_chain, part);
2468 }
2468 return access_chain;2469 return access_chain;
2469}2470}
24702471
test/translate_c.zig+33-33
...@@ -133,7 +133,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -133,7 +133,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
133 \\ const A = @enumToInt(enum_Foo.A);133 \\ const A = @enumToInt(enum_Foo.A);
134 \\ const B = @enumToInt(enum_Foo.B);134 \\ const B = @enumToInt(enum_Foo.B);
135 \\ const C = @enumToInt(enum_Foo.C);135 \\ const C = @enumToInt(enum_Foo.C);
136 \\ var a: enum_Foo = @import("std").meta.cast(enum_Foo, B);136 \\ var a: enum_Foo = @import("std").zig.c_translation.cast(enum_Foo, B);
137 \\ {137 \\ {
138 \\ const enum_Foo = extern enum(138 \\ const enum_Foo = extern enum(
139 ++ default_enum_type ++139 ++ default_enum_type ++
...@@ -146,7 +146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -146,7 +146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
146 \\ const A_2 = @enumToInt(enum_Foo.A);146 \\ const A_2 = @enumToInt(enum_Foo.A);
147 \\ const B_3 = @enumToInt(enum_Foo.B);147 \\ const B_3 = @enumToInt(enum_Foo.B);
148 \\ const C_4 = @enumToInt(enum_Foo.C);148 \\ const C_4 = @enumToInt(enum_Foo.C);
149 \\ var a_5: enum_Foo = @import("std").meta.cast(enum_Foo, B_3);149 \\ var a_5: enum_Foo = @import("std").zig.c_translation.cast(enum_Foo, B_3);
150 \\ }150 \\ }
151 \\}151 \\}
152 });152 });
...@@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
242 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED)242 \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED)
243 , &[_][]const u8{243 , &[_][]const u8{
244 \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void {244 \\pub inline fn MEM_PHYSICAL_TO_K0(x: anytype) ?*c_void {
245 \\ return @import("std").meta.cast(?*c_void, @import("std").meta.cast(u32, x) + SYS_BASE_CACHED);245 \\ return @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(u32, x) + SYS_BASE_CACHED);
246 \\}246 \\}
247 });247 });
248248
...@@ -282,8 +282,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -282,8 +282,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
282 ,282 ,
283 \\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));283 \\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));
284 ,284 ,
285 \\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))) {285 \\pub inline fn _AL_READ3BYTES(p: anytype) @TypeOf((@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16))) {
286 \\ 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));286 \\ return (@import("std").zig.c_translation.cast([*c]u8, p).* | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 1)).* << @as(c_int, 8))) | ((@import("std").zig.c_translation.cast([*c]u8, p) + @as(c_int, 2)).* << @as(c_int, 16));
287 \\}287 \\}
288 });288 });
289289
...@@ -438,17 +438,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -438,17 +438,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
438 , &[_][]const u8{438 , &[_][]const u8{
439 \\pub const struct_foo = extern struct {439 \\pub const struct_foo = extern struct {
440 \\ x: c_int align(4),440 \\ x: c_int align(4),
441 \\ pub fn y(self: anytype) @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int) {441 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
442 \\ const Intermediate = @import("std").meta.FlexibleArrayType(@TypeOf(self), u8);442 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
443 \\ const ReturnType = @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int);443 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
444 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));444 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));
445 \\ }445 \\ }
446 \\};446 \\};
447 \\pub const struct_bar = extern struct {447 \\pub const struct_bar = extern struct {
448 \\ x: c_int align(4),448 \\ x: c_int align(4),
449 \\ pub fn y(self: anytype) @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int) {449 \\ pub fn y(self: anytype) @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int) {
450 \\ const Intermediate = @import("std").meta.FlexibleArrayType(@TypeOf(self), u8);450 \\ const Intermediate = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8);
451 \\ const ReturnType = @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int);451 \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int);
452 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));452 \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4));
453 \\ }453 \\ }
454 \\};454 \\};
...@@ -583,7 +583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -583,7 +583,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
583 cases.add("#define hex literal with capital X",583 cases.add("#define hex literal with capital X",
584 \\#define VAL 0XF00D584 \\#define VAL 0XF00D
585 , &[_][]const u8{585 , &[_][]const u8{
586 \\pub const VAL = @import("std").meta.promoteIntLiteral(c_int, 0xF00D, .hexadecimal);586 \\pub const VAL = @import("std").zig.c_translation.promoteIntLiteral(c_int, 0xF00D, .hexadecimal);
587 });587 });
588588
589 cases.add("anonymous struct & unions",589 cases.add("anonymous struct & unions",
...@@ -1738,7 +1738,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1738,7 +1738,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1738 \\pub const e = @enumToInt(enum_unnamed_1.e);1738 \\pub const e = @enumToInt(enum_unnamed_1.e);
1739 \\pub const f = @enumToInt(enum_unnamed_1.f);1739 \\pub const f = @enumToInt(enum_unnamed_1.f);
1740 \\pub const g = @enumToInt(enum_unnamed_1.g);1740 \\pub const g = @enumToInt(enum_unnamed_1.g);
1741 \\pub export var h: enum_unnamed_1 = @import("std").meta.cast(enum_unnamed_1, e);1741 \\pub export var h: enum_unnamed_1 = @import("std").zig.c_translation.cast(enum_unnamed_1, e);
1742 \\const enum_unnamed_2 = extern enum(1742 \\const enum_unnamed_2 = extern enum(
1743 ++ default_enum_type ++1743 ++ default_enum_type ++
1744 \\) {1744 \\) {
...@@ -1882,7 +1882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1882,7 +1882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1882 \\typedef struct { int dummy; } NRF_GPIO_Type;1882 \\typedef struct { int dummy; } NRF_GPIO_Type;
1883 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)1883 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
1884 , &[_][]const u8{1884 , &[_][]const u8{
1885 \\pub const NRF_GPIO = @import("std").meta.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE);1885 \\pub const NRF_GPIO = @import("std").zig.c_translation.cast([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
1886 });1886 });
18871887
1888 cases.add("basic macro function",1888 cases.add("basic macro function",
...@@ -2379,7 +2379,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2379,7 +2379,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2379 \\ var a = arg_a;2379 \\ var a = arg_a;
2380 \\ var b = arg_b;2380 \\ var b = arg_b;
2381 \\ var c = arg_c;2381 \\ var c = arg_c;
2382 \\ var d: enum_Foo = @import("std").meta.cast(enum_Foo, FooA);2382 \\ var d: enum_Foo = @import("std").zig.c_translation.cast(enum_Foo, FooA);
2383 \\ var e: c_int = @boolToInt((a != 0) and (b != 0));2383 \\ var e: c_int = @boolToInt((a != 0) and (b != 0));
2384 \\ var f: c_int = @boolToInt((b != 0) and (c != null));2384 \\ var f: c_int = @boolToInt((b != 0) and (c != null));
2385 \\ var g: c_int = @boolToInt((a != 0) and (c != null));2385 \\ var g: c_int = @boolToInt((a != 0) and (c != null));
...@@ -3182,13 +3182,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3182,13 +3182,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3182 \\#define BAR (void*) a3182 \\#define BAR (void*) a
3183 \\#define BAZ (uint32_t)(2)3183 \\#define BAZ (uint32_t)(2)
3184 , &[_][]const u8{3184 , &[_][]const u8{
3185 \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) {3185 \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*c_void, baz))) {
3186 \\ return baz(@import("std").meta.cast(?*c_void, baz));3186 \\ return baz(@import("std").zig.c_translation.cast(?*c_void, baz));
3187 \\}3187 \\}
3188 ,3188 ,
3189 \\pub const BAR = @import("std").meta.cast(?*c_void, a);3189 \\pub const BAR = @import("std").zig.c_translation.cast(?*c_void, a);
3190 ,3190 ,
3191 \\pub const BAZ = @import("std").meta.cast(u32, @as(c_int, 2));3191 \\pub const BAZ = @import("std").zig.c_translation.cast(u32, @as(c_int, 2));
3192 });3192 });
31933193
3194 cases.add("macro with cast to unsigned short, long, and long long",3194 cases.add("macro with cast to unsigned short, long, and long long",
...@@ -3196,9 +3196,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3196,9 +3196,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3196 \\#define CURLAUTH_BASIC ((unsigned long) 1)3196 \\#define CURLAUTH_BASIC ((unsigned long) 1)
3197 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)3197 \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1)
3198 , &[_][]const u8{3198 , &[_][]const u8{
3199 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, @as(c_int, 1));3199 \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").zig.c_translation.cast(c_ushort, @as(c_int, 1));
3200 \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, @as(c_int, 1));3200 \\pub const CURLAUTH_BASIC = @import("std").zig.c_translation.cast(c_ulong, @as(c_int, 1));
3201 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, @as(c_int, 1));3201 \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").zig.c_translation.cast(c_ulonglong, @as(c_int, 1));
3202 });3202 });
32033203
3204 cases.add("macro conditional operator",3204 cases.add("macro conditional operator",
...@@ -3413,8 +3413,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3413,8 +3413,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3413 \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen)3413 \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen)
3414 \\3414 \\
3415 , &[_][]const u8{3415 , &[_][]const u8{
3416 \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) {3416 \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen) {
3417 \\ return @import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen;3417 \\ return @import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen;
3418 \\}3418 \\}
3419 });3419 });
34203420
...@@ -3422,9 +3422,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3422,9 +3422,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3422 \\#define NULL ((void*)0)3422 \\#define NULL ((void*)0)
3423 \\#define FOO ((int)0x8000)3423 \\#define FOO ((int)0x8000)
3424 , &[_][]const u8{3424 , &[_][]const u8{
3425 \\pub const NULL = @import("std").meta.cast(?*c_void, @as(c_int, 0));3425 \\pub const NULL = @import("std").zig.c_translation.cast(?*c_void, @as(c_int, 0));
3426 ,3426 ,
3427 \\pub const FOO = @import("std").meta.cast(c_int, @import("std").meta.promoteIntLiteral(c_int, 0x8000, .hexadecimal));3427 \\pub const FOO = @import("std").zig.c_translation.cast(c_int, @import("std").zig.c_translation.promoteIntLiteral(c_int, 0x8000, .hexadecimal));
3428 });3428 });
34293429
3430 if (std.Target.current.abi == .msvc) {3430 if (std.Target.current.abi == .msvc) {
...@@ -3503,11 +3503,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3503,11 +3503,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3503 \\pub const GUARANTEED_TO_FIT_1 = @as(c_int, 1024);3503 \\pub const GUARANTEED_TO_FIT_1 = @as(c_int, 1024);
3504 \\pub const GUARANTEED_TO_FIT_2 = @as(c_long, 10241024);3504 \\pub const GUARANTEED_TO_FIT_2 = @as(c_long, 10241024);
3505 \\pub const GUARANTEED_TO_FIT_3 = @as(c_ulong, 20482048);3505 \\pub const GUARANTEED_TO_FIT_3 = @as(c_ulong, 20482048);
3506 \\pub const MAY_NEED_PROMOTION_1 = @import("std").meta.promoteIntLiteral(c_int, 10241024, .decimal);3506 \\pub const MAY_NEED_PROMOTION_1 = @import("std").zig.c_translation.promoteIntLiteral(c_int, 10241024, .decimal);
3507 \\pub const MAY_NEED_PROMOTION_2 = @import("std").meta.promoteIntLiteral(c_long, 307230723072, .decimal);3507 \\pub const MAY_NEED_PROMOTION_2 = @import("std").zig.c_translation.promoteIntLiteral(c_long, 307230723072, .decimal);
3508 \\pub const MAY_NEED_PROMOTION_3 = @import("std").meta.promoteIntLiteral(c_ulong, 819281928192, .decimal);3508 \\pub const MAY_NEED_PROMOTION_3 = @import("std").zig.c_translation.promoteIntLiteral(c_ulong, 819281928192, .decimal);
3509 \\pub const MAY_NEED_PROMOTION_HEX = @import("std").meta.promoteIntLiteral(c_int, 0x80000000, .hexadecimal);3509 \\pub const MAY_NEED_PROMOTION_HEX = @import("std").zig.c_translation.promoteIntLiteral(c_int, 0x80000000, .hexadecimal);
3510 \\pub const MAY_NEED_PROMOTION_OCT = @import("std").meta.promoteIntLiteral(c_int, 0o20000000000, .octal);3510 \\pub const MAY_NEED_PROMOTION_OCT = @import("std").zig.c_translation.promoteIntLiteral(c_int, 0o20000000000, .octal);
3511 });3511 });
35123512
3513 // See __builtin_alloca_with_align comment in std.c.builtins3513 // See __builtin_alloca_with_align comment in std.c.builtins
...@@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3642 \\typedef long long LONG_PTR;3642 \\typedef long long LONG_PTR;
3643 \\#define INVALID_HANDLE_VALUE ((void *)(LONG_PTR)-1)3643 \\#define INVALID_HANDLE_VALUE ((void *)(LONG_PTR)-1)
3644 , &[_][]const u8{3644 , &[_][]const u8{
3645 \\pub const MAP_FAILED = @import("std").meta.cast(?*c_void, -@as(c_int, 1));3645 \\pub const MAP_FAILED = @import("std").zig.c_translation.cast(?*c_void, -@as(c_int, 1));
3646 \\pub const INVALID_HANDLE_VALUE = @import("std").meta.cast(?*c_void, @import("std").meta.cast(LONG_PTR, -@as(c_int, 1)));3646 \\pub const INVALID_HANDLE_VALUE = @import("std").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1)));
3647 });3647 });
3648}3648}