| author | |
| committer | |
| log | 97946e2a41a6a44ed376b57b32a19ce9d85f0bc2 |
| tree | 5c7de4068bbb50e11ebe414bfc61540bc85b79ce |
| parent | ac42503266f27af2a4528af3ff0f1ef2cfbfe766 |
| parent | 6dbdac4b605fb56b4180b6c66154275c22954a8d |
| signature |
Translate-c: move utility functions to a separate namespace11 files changed, 999 insertions(+), 976 deletions(-)
lib/std/c.zig-1| ... | ... | @@ -10,7 +10,6 @@ const page_size = std.mem.page_size; |
| 10 | 10 | pub const tokenizer = @import("c/tokenizer.zig"); |
| 11 | 11 | pub const Token = tokenizer.Token; |
| 12 | 12 | pub const Tokenizer = tokenizer.Tokenizer; |
| 13 | pub const builtins = @import("c/builtins.zig"); | |
| 14 | 13 | |
| 15 | 14 | test { |
| 16 | 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 | ||
| 7 | const std = @import("std"); | |
| 8 | ||
| 9 | pub inline fn __builtin_bswap16(val: u16) u16 { | |
| 10 | return @byteSwap(u16, val); | |
| 11 | } | |
| 12 | pub inline fn __builtin_bswap32(val: u32) u32 { | |
| 13 | return @byteSwap(u32, val); | |
| 14 | } | |
| 15 | pub inline fn __builtin_bswap64(val: u64) u64 { | |
| 16 | return @byteSwap(u64, val); | |
| 17 | } | |
| 18 | ||
| 19 | pub inline fn __builtin_signbit(val: f64) c_int { | |
| 20 | return @boolToInt(std.math.signbit(val)); | |
| 21 | } | |
| 22 | pub inline fn __builtin_signbitf(val: f32) c_int { | |
| 23 | return @boolToInt(std.math.signbit(val)); | |
| 24 | } | |
| 25 | ||
| 26 | pub 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 | } | |
| 31 | pub 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 | } | |
| 37 | pub 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 | ||
| 44 | pub inline fn __builtin_sqrt(val: f64) f64 { | |
| 45 | return @sqrt(val); | |
| 46 | } | |
| 47 | pub inline fn __builtin_sqrtf(val: f32) f32 { | |
| 48 | return @sqrt(val); | |
| 49 | } | |
| 50 | ||
| 51 | pub inline fn __builtin_sin(val: f64) f64 { | |
| 52 | return @sin(val); | |
| 53 | } | |
| 54 | pub inline fn __builtin_sinf(val: f32) f32 { | |
| 55 | return @sin(val); | |
| 56 | } | |
| 57 | pub inline fn __builtin_cos(val: f64) f64 { | |
| 58 | return @cos(val); | |
| 59 | } | |
| 60 | pub inline fn __builtin_cosf(val: f32) f32 { | |
| 61 | return @cos(val); | |
| 62 | } | |
| 63 | ||
| 64 | pub inline fn __builtin_exp(val: f64) f64 { | |
| 65 | return @exp(val); | |
| 66 | } | |
| 67 | pub inline fn __builtin_expf(val: f32) f32 { | |
| 68 | return @exp(val); | |
| 69 | } | |
| 70 | pub inline fn __builtin_exp2(val: f64) f64 { | |
| 71 | return @exp2(val); | |
| 72 | } | |
| 73 | pub inline fn __builtin_exp2f(val: f32) f32 { | |
| 74 | return @exp2(val); | |
| 75 | } | |
| 76 | pub inline fn __builtin_log(val: f64) f64 { | |
| 77 | return @log(val); | |
| 78 | } | |
| 79 | pub inline fn __builtin_logf(val: f32) f32 { | |
| 80 | return @log(val); | |
| 81 | } | |
| 82 | pub inline fn __builtin_log2(val: f64) f64 { | |
| 83 | return @log2(val); | |
| 84 | } | |
| 85 | pub inline fn __builtin_log2f(val: f32) f32 { | |
| 86 | return @log2(val); | |
| 87 | } | |
| 88 | pub inline fn __builtin_log10(val: f64) f64 { | |
| 89 | return @log10(val); | |
| 90 | } | |
| 91 | pub 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. | |
| 96 | pub inline fn __builtin_abs(val: c_int) c_int { | |
| 97 | return std.math.absInt(val) catch std.math.minInt(c_int); | |
| 98 | } | |
| 99 | pub inline fn __builtin_fabs(val: f64) f64 { | |
| 100 | return @fabs(val); | |
| 101 | } | |
| 102 | pub inline fn __builtin_fabsf(val: f32) f32 { | |
| 103 | return @fabs(val); | |
| 104 | } | |
| 105 | ||
| 106 | pub inline fn __builtin_floor(val: f64) f64 { | |
| 107 | return @floor(val); | |
| 108 | } | |
| 109 | pub inline fn __builtin_floorf(val: f32) f32 { | |
| 110 | return @floor(val); | |
| 111 | } | |
| 112 | pub inline fn __builtin_ceil(val: f64) f64 { | |
| 113 | return @ceil(val); | |
| 114 | } | |
| 115 | pub inline fn __builtin_ceilf(val: f32) f32 { | |
| 116 | return @ceil(val); | |
| 117 | } | |
| 118 | pub inline fn __builtin_trunc(val: f64) f64 { | |
| 119 | return @trunc(val); | |
| 120 | } | |
| 121 | pub inline fn __builtin_truncf(val: f32) f32 { | |
| 122 | return @trunc(val); | |
| 123 | } | |
| 124 | pub inline fn __builtin_round(val: f64) f64 { | |
| 125 | return @round(val); | |
| 126 | } | |
| 127 | pub inline fn __builtin_roundf(val: f32) f32 { | |
| 128 | return @round(val); | |
| 129 | } | |
| 130 | ||
| 131 | pub inline fn __builtin_strlen(s: [*c]const u8) usize { | |
| 132 | return std.mem.lenZ(s); | |
| 133 | } | |
| 134 | pub 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 | ||
| 138 | pub 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 | ||
| 148 | pub 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 | ||
| 158 | pub 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 | ||
| 164 | pub 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 | ||
| 174 | pub 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. | |
| 188 | pub 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 | 18 | // if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256 |
| 19 | 19 | |
| 20 | 20 | const std = @import("std"); |
| 21 | const cast = std.meta.cast; | |
| 22 | 21 | const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels |
| 23 | 22 | |
| 24 | 23 | // The type MontgomeryDomainFieldElement is a field element in the Montgomery domain. |
| ... | ... | @@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 148 | 147 | var x17: u64 = undefined; |
| 149 | 148 | var x18: u1 = undefined; |
| 150 | 149 | addcarryxU64(&x17, &x18, x16, x8, x5); |
| 151 | const x19 = (cast(u64, x18) + x6); | |
| 150 | const x19 = (@as(u64, x18) + x6); | |
| 152 | 151 | var x20: u64 = undefined; |
| 153 | 152 | var x21: u64 = undefined; |
| 154 | 153 | mulxU64(&x20, &x21, x11, 0xffffffff00000001); |
| ... | ... | @@ -161,7 +160,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 161 | 160 | var x26: u64 = undefined; |
| 162 | 161 | var x27: u1 = undefined; |
| 163 | 162 | addcarryxU64(&x26, &x27, 0x0, x25, x22); |
| 164 | const x28 = (cast(u64, x27) + x23); | |
| 163 | const x28 = (@as(u64, x27) + x23); | |
| 165 | 164 | var x29: u64 = undefined; |
| 166 | 165 | var x30: u1 = undefined; |
| 167 | 166 | addcarryxU64(&x29, &x30, 0x0, x11, x24); |
| ... | ... | @@ -198,7 +197,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 198 | 197 | var x51: u64 = undefined; |
| 199 | 198 | var x52: u1 = undefined; |
| 200 | 199 | addcarryxU64(&x51, &x52, x50, x42, x39); |
| 201 | const x53 = (cast(u64, x52) + x40); | |
| 200 | const x53 = (@as(u64, x52) + x40); | |
| 202 | 201 | var x54: u64 = undefined; |
| 203 | 202 | var x55: u1 = undefined; |
| 204 | 203 | addcarryxU64(&x54, &x55, 0x0, x31, x45); |
| ... | ... | @@ -213,7 +212,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 213 | 212 | addcarryxU64(&x60, &x61, x59, x37, x51); |
| 214 | 213 | var x62: u64 = undefined; |
| 215 | 214 | var x63: u1 = undefined; |
| 216 | addcarryxU64(&x62, &x63, x61, cast(u64, x38), x53); | |
| 215 | addcarryxU64(&x62, &x63, x61, @as(u64, x38), x53); | |
| 217 | 216 | var x64: u64 = undefined; |
| 218 | 217 | var x65: u64 = undefined; |
| 219 | 218 | mulxU64(&x64, &x65, x54, 0xffffffff00000001); |
| ... | ... | @@ -226,7 +225,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 226 | 225 | var x70: u64 = undefined; |
| 227 | 226 | var x71: u1 = undefined; |
| 228 | 227 | addcarryxU64(&x70, &x71, 0x0, x69, x66); |
| 229 | const x72 = (cast(u64, x71) + x67); | |
| 228 | const x72 = (@as(u64, x71) + x67); | |
| 230 | 229 | var x73: u64 = undefined; |
| 231 | 230 | var x74: u1 = undefined; |
| 232 | 231 | addcarryxU64(&x73, &x74, 0x0, x54, x68); |
| ... | ... | @@ -242,7 +241,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 242 | 241 | var x81: u64 = undefined; |
| 243 | 242 | var x82: u1 = undefined; |
| 244 | 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 | 245 | var x84: u64 = undefined; |
| 247 | 246 | var x85: u64 = undefined; |
| 248 | 247 | mulxU64(&x84, &x85, x2, (arg2[3])); |
| ... | ... | @@ -264,7 +263,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 264 | 263 | var x96: u64 = undefined; |
| 265 | 264 | var x97: u1 = undefined; |
| 266 | 265 | addcarryxU64(&x96, &x97, x95, x87, x84); |
| 267 | const x98 = (cast(u64, x97) + x85); | |
| 266 | const x98 = (@as(u64, x97) + x85); | |
| 268 | 267 | var x99: u64 = undefined; |
| 269 | 268 | var x100: u1 = undefined; |
| 270 | 269 | addcarryxU64(&x99, &x100, 0x0, x75, x90); |
| ... | ... | @@ -292,7 +291,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 292 | 291 | var x115: u64 = undefined; |
| 293 | 292 | var x116: u1 = undefined; |
| 294 | 293 | addcarryxU64(&x115, &x116, 0x0, x114, x111); |
| 295 | const x117 = (cast(u64, x116) + x112); | |
| 294 | const x117 = (@as(u64, x116) + x112); | |
| 296 | 295 | var x118: u64 = undefined; |
| 297 | 296 | var x119: u1 = undefined; |
| 298 | 297 | addcarryxU64(&x118, &x119, 0x0, x99, x113); |
| ... | ... | @@ -308,7 +307,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 308 | 307 | var x126: u64 = undefined; |
| 309 | 308 | var x127: u1 = undefined; |
| 310 | 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 | 311 | var x129: u64 = undefined; |
| 313 | 312 | var x130: u64 = undefined; |
| 314 | 313 | mulxU64(&x129, &x130, x3, (arg2[3])); |
| ... | ... | @@ -330,7 +329,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 330 | 329 | var x141: u64 = undefined; |
| 331 | 330 | var x142: u1 = undefined; |
| 332 | 331 | addcarryxU64(&x141, &x142, x140, x132, x129); |
| 333 | const x143 = (cast(u64, x142) + x130); | |
| 332 | const x143 = (@as(u64, x142) + x130); | |
| 334 | 333 | var x144: u64 = undefined; |
| 335 | 334 | var x145: u1 = undefined; |
| 336 | 335 | addcarryxU64(&x144, &x145, 0x0, x120, x135); |
| ... | ... | @@ -358,7 +357,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 358 | 357 | var x160: u64 = undefined; |
| 359 | 358 | var x161: u1 = undefined; |
| 360 | 359 | addcarryxU64(&x160, &x161, 0x0, x159, x156); |
| 361 | const x162 = (cast(u64, x161) + x157); | |
| 360 | const x162 = (@as(u64, x161) + x157); | |
| 362 | 361 | var x163: u64 = undefined; |
| 363 | 362 | var x164: u1 = undefined; |
| 364 | 363 | addcarryxU64(&x163, &x164, 0x0, x144, x158); |
| ... | ... | @@ -374,7 +373,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 374 | 373 | var x171: u64 = undefined; |
| 375 | 374 | var x172: u1 = undefined; |
| 376 | 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 | 377 | var x174: u64 = undefined; |
| 379 | 378 | var x175: u1 = undefined; |
| 380 | 379 | subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff); |
| ... | ... | @@ -383,13 +382,13 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 383 | 382 | subborrowxU64(&x176, &x177, x175, x167, 0xffffffff); |
| 384 | 383 | var x178: u64 = undefined; |
| 385 | 384 | var x179: u1 = undefined; |
| 386 | subborrowxU64(&x178, &x179, x177, x169, cast(u64, 0x0)); | |
| 385 | subborrowxU64(&x178, &x179, x177, x169, @as(u64, 0x0)); | |
| 387 | 386 | var x180: u64 = undefined; |
| 388 | 387 | var x181: u1 = undefined; |
| 389 | 388 | subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001); |
| 390 | 389 | var x182: u64 = undefined; |
| 391 | 390 | var x183: u1 = undefined; |
| 392 | subborrowxU64(&x182, &x183, x181, x173, cast(u64, 0x0)); | |
| 391 | subborrowxU64(&x182, &x183, x181, x173, @as(u64, 0x0)); | |
| 393 | 392 | var x184: u64 = undefined; |
| 394 | 393 | cmovznzU64(&x184, x183, x174, x165); |
| 395 | 394 | var x185: u64 = undefined; |
| ... | ... | @@ -440,7 +439,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 440 | 439 | var x17: u64 = undefined; |
| 441 | 440 | var x18: u1 = undefined; |
| 442 | 441 | addcarryxU64(&x17, &x18, x16, x8, x5); |
| 443 | const x19 = (cast(u64, x18) + x6); | |
| 442 | const x19 = (@as(u64, x18) + x6); | |
| 444 | 443 | var x20: u64 = undefined; |
| 445 | 444 | var x21: u64 = undefined; |
| 446 | 445 | mulxU64(&x20, &x21, x11, 0xffffffff00000001); |
| ... | ... | @@ -453,7 +452,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 453 | 452 | var x26: u64 = undefined; |
| 454 | 453 | var x27: u1 = undefined; |
| 455 | 454 | addcarryxU64(&x26, &x27, 0x0, x25, x22); |
| 456 | const x28 = (cast(u64, x27) + x23); | |
| 455 | const x28 = (@as(u64, x27) + x23); | |
| 457 | 456 | var x29: u64 = undefined; |
| 458 | 457 | var x30: u1 = undefined; |
| 459 | 458 | addcarryxU64(&x29, &x30, 0x0, x11, x24); |
| ... | ... | @@ -490,7 +489,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 490 | 489 | var x51: u64 = undefined; |
| 491 | 490 | var x52: u1 = undefined; |
| 492 | 491 | addcarryxU64(&x51, &x52, x50, x42, x39); |
| 493 | const x53 = (cast(u64, x52) + x40); | |
| 492 | const x53 = (@as(u64, x52) + x40); | |
| 494 | 493 | var x54: u64 = undefined; |
| 495 | 494 | var x55: u1 = undefined; |
| 496 | 495 | addcarryxU64(&x54, &x55, 0x0, x31, x45); |
| ... | ... | @@ -505,7 +504,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 505 | 504 | addcarryxU64(&x60, &x61, x59, x37, x51); |
| 506 | 505 | var x62: u64 = undefined; |
| 507 | 506 | var x63: u1 = undefined; |
| 508 | addcarryxU64(&x62, &x63, x61, cast(u64, x38), x53); | |
| 507 | addcarryxU64(&x62, &x63, x61, @as(u64, x38), x53); | |
| 509 | 508 | var x64: u64 = undefined; |
| 510 | 509 | var x65: u64 = undefined; |
| 511 | 510 | mulxU64(&x64, &x65, x54, 0xffffffff00000001); |
| ... | ... | @@ -518,7 +517,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 518 | 517 | var x70: u64 = undefined; |
| 519 | 518 | var x71: u1 = undefined; |
| 520 | 519 | addcarryxU64(&x70, &x71, 0x0, x69, x66); |
| 521 | const x72 = (cast(u64, x71) + x67); | |
| 520 | const x72 = (@as(u64, x71) + x67); | |
| 522 | 521 | var x73: u64 = undefined; |
| 523 | 522 | var x74: u1 = undefined; |
| 524 | 523 | addcarryxU64(&x73, &x74, 0x0, x54, x68); |
| ... | ... | @@ -534,7 +533,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 534 | 533 | var x81: u64 = undefined; |
| 535 | 534 | var x82: u1 = undefined; |
| 536 | 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 | 537 | var x84: u64 = undefined; |
| 539 | 538 | var x85: u64 = undefined; |
| 540 | 539 | mulxU64(&x84, &x85, x2, (arg1[3])); |
| ... | ... | @@ -556,7 +555,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 556 | 555 | var x96: u64 = undefined; |
| 557 | 556 | var x97: u1 = undefined; |
| 558 | 557 | addcarryxU64(&x96, &x97, x95, x87, x84); |
| 559 | const x98 = (cast(u64, x97) + x85); | |
| 558 | const x98 = (@as(u64, x97) + x85); | |
| 560 | 559 | var x99: u64 = undefined; |
| 561 | 560 | var x100: u1 = undefined; |
| 562 | 561 | addcarryxU64(&x99, &x100, 0x0, x75, x90); |
| ... | ... | @@ -584,7 +583,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 584 | 583 | var x115: u64 = undefined; |
| 585 | 584 | var x116: u1 = undefined; |
| 586 | 585 | addcarryxU64(&x115, &x116, 0x0, x114, x111); |
| 587 | const x117 = (cast(u64, x116) + x112); | |
| 586 | const x117 = (@as(u64, x116) + x112); | |
| 588 | 587 | var x118: u64 = undefined; |
| 589 | 588 | var x119: u1 = undefined; |
| 590 | 589 | addcarryxU64(&x118, &x119, 0x0, x99, x113); |
| ... | ... | @@ -600,7 +599,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 600 | 599 | var x126: u64 = undefined; |
| 601 | 600 | var x127: u1 = undefined; |
| 602 | 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 | 603 | var x129: u64 = undefined; |
| 605 | 604 | var x130: u64 = undefined; |
| 606 | 605 | mulxU64(&x129, &x130, x3, (arg1[3])); |
| ... | ... | @@ -622,7 +621,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 622 | 621 | var x141: u64 = undefined; |
| 623 | 622 | var x142: u1 = undefined; |
| 624 | 623 | addcarryxU64(&x141, &x142, x140, x132, x129); |
| 625 | const x143 = (cast(u64, x142) + x130); | |
| 624 | const x143 = (@as(u64, x142) + x130); | |
| 626 | 625 | var x144: u64 = undefined; |
| 627 | 626 | var x145: u1 = undefined; |
| 628 | 627 | addcarryxU64(&x144, &x145, 0x0, x120, x135); |
| ... | ... | @@ -650,7 +649,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 650 | 649 | var x160: u64 = undefined; |
| 651 | 650 | var x161: u1 = undefined; |
| 652 | 651 | addcarryxU64(&x160, &x161, 0x0, x159, x156); |
| 653 | const x162 = (cast(u64, x161) + x157); | |
| 652 | const x162 = (@as(u64, x161) + x157); | |
| 654 | 653 | var x163: u64 = undefined; |
| 655 | 654 | var x164: u1 = undefined; |
| 656 | 655 | addcarryxU64(&x163, &x164, 0x0, x144, x158); |
| ... | ... | @@ -666,7 +665,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 666 | 665 | var x171: u64 = undefined; |
| 667 | 666 | var x172: u1 = undefined; |
| 668 | 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 | 669 | var x174: u64 = undefined; |
| 671 | 670 | var x175: u1 = undefined; |
| 672 | 671 | subborrowxU64(&x174, &x175, 0x0, x165, 0xffffffffffffffff); |
| ... | ... | @@ -675,13 +674,13 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 675 | 674 | subborrowxU64(&x176, &x177, x175, x167, 0xffffffff); |
| 676 | 675 | var x178: u64 = undefined; |
| 677 | 676 | var x179: u1 = undefined; |
| 678 | subborrowxU64(&x178, &x179, x177, x169, cast(u64, 0x0)); | |
| 677 | subborrowxU64(&x178, &x179, x177, x169, @as(u64, 0x0)); | |
| 679 | 678 | var x180: u64 = undefined; |
| 680 | 679 | var x181: u1 = undefined; |
| 681 | 680 | subborrowxU64(&x180, &x181, x179, x171, 0xffffffff00000001); |
| 682 | 681 | var x182: u64 = undefined; |
| 683 | 682 | var x183: u1 = undefined; |
| 684 | subborrowxU64(&x182, &x183, x181, x173, cast(u64, 0x0)); | |
| 683 | subborrowxU64(&x182, &x183, x181, x173, @as(u64, 0x0)); | |
| 685 | 684 | var x184: u64 = undefined; |
| 686 | 685 | cmovznzU64(&x184, x183, x174, x165); |
| 687 | 686 | var x185: u64 = undefined; |
| ... | ... | @@ -728,13 +727,13 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 728 | 727 | subborrowxU64(&x11, &x12, x10, x3, 0xffffffff); |
| 729 | 728 | var x13: u64 = undefined; |
| 730 | 729 | var x14: u1 = undefined; |
| 731 | subborrowxU64(&x13, &x14, x12, x5, cast(u64, 0x0)); | |
| 730 | subborrowxU64(&x13, &x14, x12, x5, @as(u64, 0x0)); | |
| 732 | 731 | var x15: u64 = undefined; |
| 733 | 732 | var x16: u1 = undefined; |
| 734 | 733 | subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000001); |
| 735 | 734 | var x17: u64 = undefined; |
| 736 | 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 | 737 | var x19: u64 = undefined; |
| 739 | 738 | cmovznzU64(&x19, x18, x9, x1); |
| 740 | 739 | var x20: u64 = undefined; |
| ... | ... | @@ -774,7 +773,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 774 | 773 | var x8: u1 = undefined; |
| 775 | 774 | subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3])); |
| 776 | 775 | var x9: u64 = undefined; |
| 777 | cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff); | |
| 776 | cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff); | |
| 778 | 777 | var x10: u64 = undefined; |
| 779 | 778 | var x11: u1 = undefined; |
| 780 | 779 | addcarryxU64(&x10, &x11, 0x0, x1, x9); |
| ... | ... | @@ -783,7 +782,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 783 | 782 | addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff)); |
| 784 | 783 | var x14: u64 = undefined; |
| 785 | 784 | var x15: u1 = undefined; |
| 786 | addcarryxU64(&x14, &x15, x13, x5, cast(u64, 0x0)); | |
| 785 | addcarryxU64(&x14, &x15, x13, x5, @as(u64, 0x0)); | |
| 787 | 786 | var x16: u64 = undefined; |
| 788 | 787 | var x17: u1 = undefined; |
| 789 | 788 | addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001)); |
| ... | ... | @@ -806,18 +805,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 806 | 805 | |
| 807 | 806 | var x1: u64 = undefined; |
| 808 | 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 | 809 | var x3: u64 = undefined; |
| 811 | 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 | 812 | var x5: u64 = undefined; |
| 814 | 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 | 815 | var x7: u64 = undefined; |
| 817 | 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 | 818 | var x9: u64 = undefined; |
| 820 | cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff); | |
| 819 | cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff); | |
| 821 | 820 | var x10: u64 = undefined; |
| 822 | 821 | var x11: u1 = undefined; |
| 823 | 822 | addcarryxU64(&x10, &x11, 0x0, x1, x9); |
| ... | ... | @@ -826,7 +825,7 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 826 | 825 | addcarryxU64(&x12, &x13, x11, x3, (x9 & 0xffffffff)); |
| 827 | 826 | var x14: u64 = undefined; |
| 828 | 827 | var x15: u1 = undefined; |
| 829 | addcarryxU64(&x14, &x15, x13, x5, cast(u64, 0x0)); | |
| 828 | addcarryxU64(&x14, &x15, x13, x5, @as(u64, 0x0)); | |
| 830 | 829 | var x16: u64 = undefined; |
| 831 | 830 | var x17: u1 = undefined; |
| 832 | 831 | addcarryxU64(&x16, &x17, x15, x7, (x9 & 0xffffffff00000001)); |
| ... | ... | @@ -865,7 +864,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 865 | 864 | addcarryxU64(&x10, &x11, 0x0, x1, x6); |
| 866 | 865 | var x12: u64 = undefined; |
| 867 | 866 | var x13: u1 = undefined; |
| 868 | addcarryxU64(&x12, &x13, x11, cast(u64, 0x0), x8); | |
| 867 | addcarryxU64(&x12, &x13, x11, @as(u64, 0x0), x8); | |
| 869 | 868 | var x14: u64 = undefined; |
| 870 | 869 | var x15: u1 = undefined; |
| 871 | 870 | addcarryxU64(&x14, &x15, 0x0, x12, (arg1[1])); |
| ... | ... | @@ -886,10 +885,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 886 | 885 | addcarryxU64(&x24, &x25, 0x0, x14, x20); |
| 887 | 886 | var x26: u64 = undefined; |
| 888 | 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 | 889 | var x28: u64 = undefined; |
| 891 | 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 | 892 | var x30: u64 = undefined; |
| 894 | 893 | var x31: u1 = undefined; |
| 895 | 894 | addcarryxU64(&x30, &x31, x29, x3, x16); |
| ... | ... | @@ -898,10 +897,10 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 898 | 897 | addcarryxU64(&x32, &x33, 0x0, x26, (arg1[2])); |
| 899 | 898 | var x34: u64 = undefined; |
| 900 | 899 | var x35: u1 = undefined; |
| 901 | addcarryxU64(&x34, &x35, x33, x28, cast(u64, 0x0)); | |
| 900 | addcarryxU64(&x34, &x35, x33, x28, @as(u64, 0x0)); | |
| 902 | 901 | var x36: u64 = undefined; |
| 903 | 902 | var x37: u1 = undefined; |
| 904 | addcarryxU64(&x36, &x37, x35, x30, cast(u64, 0x0)); | |
| 903 | addcarryxU64(&x36, &x37, x35, x30, @as(u64, 0x0)); | |
| 905 | 904 | var x38: u64 = undefined; |
| 906 | 905 | var x39: u64 = undefined; |
| 907 | 906 | mulxU64(&x38, &x39, x32, 0xffffffff00000001); |
| ... | ... | @@ -922,19 +921,19 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 922 | 921 | addcarryxU64(&x48, &x49, x47, x34, x44); |
| 923 | 922 | var x50: u64 = undefined; |
| 924 | 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 | 925 | var x52: u64 = undefined; |
| 927 | 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 | 928 | var x54: u64 = undefined; |
| 930 | 929 | var x55: u1 = undefined; |
| 931 | 930 | addcarryxU64(&x54, &x55, 0x0, x48, (arg1[3])); |
| 932 | 931 | var x56: u64 = undefined; |
| 933 | 932 | var x57: u1 = undefined; |
| 934 | addcarryxU64(&x56, &x57, x55, x50, cast(u64, 0x0)); | |
| 933 | addcarryxU64(&x56, &x57, x55, x50, @as(u64, 0x0)); | |
| 935 | 934 | var x58: u64 = undefined; |
| 936 | 935 | var x59: u1 = undefined; |
| 937 | addcarryxU64(&x58, &x59, x57, x52, cast(u64, 0x0)); | |
| 936 | addcarryxU64(&x58, &x59, x57, x52, @as(u64, 0x0)); | |
| 938 | 937 | var x60: u64 = undefined; |
| 939 | 938 | var x61: u64 = undefined; |
| 940 | 939 | mulxU64(&x60, &x61, x54, 0xffffffff00000001); |
| ... | ... | @@ -955,11 +954,11 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 955 | 954 | addcarryxU64(&x70, &x71, x69, x56, x66); |
| 956 | 955 | var x72: u64 = undefined; |
| 957 | 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 | 958 | var x74: u64 = undefined; |
| 960 | 959 | var x75: u1 = undefined; |
| 961 | addcarryxU64(&x74, &x75, x73, (cast(u64, x59) + (cast(u64, x53) + x39)), x60); | |
| 962 | const x76 = (cast(u64, x75) + x61); | |
| 960 | addcarryxU64(&x74, &x75, x73, (@as(u64, x59) + (@as(u64, x53) + x39)), x60); | |
| 961 | const x76 = (@as(u64, x75) + x61); | |
| 963 | 962 | var x77: u64 = undefined; |
| 964 | 963 | var x78: u1 = undefined; |
| 965 | 964 | subborrowxU64(&x77, &x78, 0x0, x70, 0xffffffffffffffff); |
| ... | ... | @@ -968,13 +967,13 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 968 | 967 | subborrowxU64(&x79, &x80, x78, x72, 0xffffffff); |
| 969 | 968 | var x81: u64 = undefined; |
| 970 | 969 | var x82: u1 = undefined; |
| 971 | subborrowxU64(&x81, &x82, x80, x74, cast(u64, 0x0)); | |
| 970 | subborrowxU64(&x81, &x82, x80, x74, @as(u64, 0x0)); | |
| 972 | 971 | var x83: u64 = undefined; |
| 973 | 972 | var x84: u1 = undefined; |
| 974 | 973 | subborrowxU64(&x83, &x84, x82, x76, 0xffffffff00000001); |
| 975 | 974 | var x85: u64 = undefined; |
| 976 | 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 | 977 | var x87: u64 = undefined; |
| 979 | 978 | cmovznzU64(&x87, x86, x77, x70); |
| 980 | 979 | var x88: u64 = undefined; |
| ... | ... | @@ -1045,13 +1044,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1045 | 1044 | addcarryxU64(&x29, &x30, x28, x13, x25); |
| 1046 | 1045 | var x31: u64 = undefined; |
| 1047 | 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 | 1048 | var x33: u64 = undefined; |
| 1050 | 1049 | var x34: u1 = undefined; |
| 1051 | 1050 | addcarryxU64(&x33, &x34, x32, x17, x19); |
| 1052 | 1051 | var x35: u64 = undefined; |
| 1053 | 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 | 1054 | var x37: u64 = undefined; |
| 1056 | 1055 | var x38: u64 = undefined; |
| 1057 | 1056 | mulxU64(&x37, &x38, x1, 0x4fffffffd); |
| ... | ... | @@ -1105,13 +1104,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1105 | 1104 | addcarryxU64(&x69, &x70, x68, x53, x65); |
| 1106 | 1105 | var x71: u64 = undefined; |
| 1107 | 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 | 1108 | var x73: u64 = undefined; |
| 1110 | 1109 | var x74: u1 = undefined; |
| 1111 | 1110 | addcarryxU64(&x73, &x74, x72, x57, x59); |
| 1112 | 1111 | var x75: u64 = undefined; |
| 1113 | 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 | 1114 | var x77: u64 = undefined; |
| 1116 | 1115 | var x78: u64 = undefined; |
| 1117 | 1116 | mulxU64(&x77, &x78, x2, 0x4fffffffd); |
| ... | ... | @@ -1165,13 +1164,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1165 | 1164 | addcarryxU64(&x109, &x110, x108, x93, x105); |
| 1166 | 1165 | var x111: u64 = undefined; |
| 1167 | 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 | 1168 | var x113: u64 = undefined; |
| 1170 | 1169 | var x114: u1 = undefined; |
| 1171 | 1170 | addcarryxU64(&x113, &x114, x112, x97, x99); |
| 1172 | 1171 | var x115: u64 = undefined; |
| 1173 | 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 | 1174 | var x117: u64 = undefined; |
| 1176 | 1175 | var x118: u64 = undefined; |
| 1177 | 1176 | mulxU64(&x117, &x118, x3, 0x4fffffffd); |
| ... | ... | @@ -1225,13 +1224,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1225 | 1224 | addcarryxU64(&x149, &x150, x148, x133, x145); |
| 1226 | 1225 | var x151: u64 = undefined; |
| 1227 | 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 | 1228 | var x153: u64 = undefined; |
| 1230 | 1229 | var x154: u1 = undefined; |
| 1231 | 1230 | addcarryxU64(&x153, &x154, x152, x137, x139); |
| 1232 | 1231 | var x155: u64 = undefined; |
| 1233 | 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 | 1234 | var x157: u64 = undefined; |
| 1236 | 1235 | var x158: u1 = undefined; |
| 1237 | 1236 | subborrowxU64(&x157, &x158, 0x0, x149, 0xffffffffffffffff); |
| ... | ... | @@ -1240,13 +1239,13 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1240 | 1239 | subborrowxU64(&x159, &x160, x158, x151, 0xffffffff); |
| 1241 | 1240 | var x161: u64 = undefined; |
| 1242 | 1241 | var x162: u1 = undefined; |
| 1243 | subborrowxU64(&x161, &x162, x160, x153, cast(u64, 0x0)); | |
| 1242 | subborrowxU64(&x161, &x162, x160, x153, @as(u64, 0x0)); | |
| 1244 | 1243 | var x163: u64 = undefined; |
| 1245 | 1244 | var x164: u1 = undefined; |
| 1246 | 1245 | subborrowxU64(&x163, &x164, x162, x155, 0xffffffff00000001); |
| 1247 | 1246 | var x165: u64 = undefined; |
| 1248 | 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 | 1249 | var x167: u64 = undefined; |
| 1251 | 1250 | cmovznzU64(&x167, x166, x157, x149); |
| 1252 | 1251 | var x168: u64 = undefined; |
| ... | ... | @@ -1325,62 +1324,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void { |
| 1325 | 1324 | const x2 = (arg1[2]); |
| 1326 | 1325 | const x3 = (arg1[1]); |
| 1327 | 1326 | const x4 = (arg1[0]); |
| 1328 | const x5 = cast(u8, (x4 & cast(u64, 0xff))); | |
| 1327 | const x5 = @truncate(u8, (x4 & @as(u64, 0xff))); | |
| 1329 | 1328 | const x6 = (x4 >> 8); |
| 1330 | const x7 = cast(u8, (x6 & cast(u64, 0xff))); | |
| 1329 | const x7 = @truncate(u8, (x6 & @as(u64, 0xff))); | |
| 1331 | 1330 | const x8 = (x6 >> 8); |
| 1332 | const x9 = cast(u8, (x8 & cast(u64, 0xff))); | |
| 1331 | const x9 = @truncate(u8, (x8 & @as(u64, 0xff))); | |
| 1333 | 1332 | const x10 = (x8 >> 8); |
| 1334 | const x11 = cast(u8, (x10 & cast(u64, 0xff))); | |
| 1333 | const x11 = @truncate(u8, (x10 & @as(u64, 0xff))); | |
| 1335 | 1334 | const x12 = (x10 >> 8); |
| 1336 | const x13 = cast(u8, (x12 & cast(u64, 0xff))); | |
| 1335 | const x13 = @truncate(u8, (x12 & @as(u64, 0xff))); | |
| 1337 | 1336 | const x14 = (x12 >> 8); |
| 1338 | const x15 = cast(u8, (x14 & cast(u64, 0xff))); | |
| 1337 | const x15 = @truncate(u8, (x14 & @as(u64, 0xff))); | |
| 1339 | 1338 | const x16 = (x14 >> 8); |
| 1340 | const x17 = cast(u8, (x16 & cast(u64, 0xff))); | |
| 1341 | const x18 = cast(u8, (x16 >> 8)); | |
| 1342 | const x19 = cast(u8, (x3 & cast(u64, 0xff))); | |
| 1339 | const x17 = @truncate(u8, (x16 & @as(u64, 0xff))); | |
| 1340 | const x18 = @truncate(u8, (x16 >> 8)); | |
| 1341 | const x19 = @truncate(u8, (x3 & @as(u64, 0xff))); | |
| 1343 | 1342 | const x20 = (x3 >> 8); |
| 1344 | const x21 = cast(u8, (x20 & cast(u64, 0xff))); | |
| 1343 | const x21 = @truncate(u8, (x20 & @as(u64, 0xff))); | |
| 1345 | 1344 | const x22 = (x20 >> 8); |
| 1346 | const x23 = cast(u8, (x22 & cast(u64, 0xff))); | |
| 1345 | const x23 = @truncate(u8, (x22 & @as(u64, 0xff))); | |
| 1347 | 1346 | const x24 = (x22 >> 8); |
| 1348 | const x25 = cast(u8, (x24 & cast(u64, 0xff))); | |
| 1347 | const x25 = @truncate(u8, (x24 & @as(u64, 0xff))); | |
| 1349 | 1348 | const x26 = (x24 >> 8); |
| 1350 | const x27 = cast(u8, (x26 & cast(u64, 0xff))); | |
| 1349 | const x27 = @truncate(u8, (x26 & @as(u64, 0xff))); | |
| 1351 | 1350 | const x28 = (x26 >> 8); |
| 1352 | const x29 = cast(u8, (x28 & cast(u64, 0xff))); | |
| 1351 | const x29 = @truncate(u8, (x28 & @as(u64, 0xff))); | |
| 1353 | 1352 | const x30 = (x28 >> 8); |
| 1354 | const x31 = cast(u8, (x30 & cast(u64, 0xff))); | |
| 1355 | const x32 = cast(u8, (x30 >> 8)); | |
| 1356 | const x33 = cast(u8, (x2 & cast(u64, 0xff))); | |
| 1353 | const x31 = @truncate(u8, (x30 & @as(u64, 0xff))); | |
| 1354 | const x32 = @truncate(u8, (x30 >> 8)); | |
| 1355 | const x33 = @truncate(u8, (x2 & @as(u64, 0xff))); | |
| 1357 | 1356 | const x34 = (x2 >> 8); |
| 1358 | const x35 = cast(u8, (x34 & cast(u64, 0xff))); | |
| 1357 | const x35 = @truncate(u8, (x34 & @as(u64, 0xff))); | |
| 1359 | 1358 | const x36 = (x34 >> 8); |
| 1360 | const x37 = cast(u8, (x36 & cast(u64, 0xff))); | |
| 1359 | const x37 = @truncate(u8, (x36 & @as(u64, 0xff))); | |
| 1361 | 1360 | const x38 = (x36 >> 8); |
| 1362 | const x39 = cast(u8, (x38 & cast(u64, 0xff))); | |
| 1361 | const x39 = @truncate(u8, (x38 & @as(u64, 0xff))); | |
| 1363 | 1362 | const x40 = (x38 >> 8); |
| 1364 | const x41 = cast(u8, (x40 & cast(u64, 0xff))); | |
| 1363 | const x41 = @truncate(u8, (x40 & @as(u64, 0xff))); | |
| 1365 | 1364 | const x42 = (x40 >> 8); |
| 1366 | const x43 = cast(u8, (x42 & cast(u64, 0xff))); | |
| 1365 | const x43 = @truncate(u8, (x42 & @as(u64, 0xff))); | |
| 1367 | 1366 | const x44 = (x42 >> 8); |
| 1368 | const x45 = cast(u8, (x44 & cast(u64, 0xff))); | |
| 1369 | const x46 = cast(u8, (x44 >> 8)); | |
| 1370 | const x47 = cast(u8, (x1 & cast(u64, 0xff))); | |
| 1367 | const x45 = @truncate(u8, (x44 & @as(u64, 0xff))); | |
| 1368 | const x46 = @truncate(u8, (x44 >> 8)); | |
| 1369 | const x47 = @truncate(u8, (x1 & @as(u64, 0xff))); | |
| 1371 | 1370 | const x48 = (x1 >> 8); |
| 1372 | const x49 = cast(u8, (x48 & cast(u64, 0xff))); | |
| 1371 | const x49 = @truncate(u8, (x48 & @as(u64, 0xff))); | |
| 1373 | 1372 | const x50 = (x48 >> 8); |
| 1374 | const x51 = cast(u8, (x50 & cast(u64, 0xff))); | |
| 1373 | const x51 = @truncate(u8, (x50 & @as(u64, 0xff))); | |
| 1375 | 1374 | const x52 = (x50 >> 8); |
| 1376 | const x53 = cast(u8, (x52 & cast(u64, 0xff))); | |
| 1375 | const x53 = @truncate(u8, (x52 & @as(u64, 0xff))); | |
| 1377 | 1376 | const x54 = (x52 >> 8); |
| 1378 | const x55 = cast(u8, (x54 & cast(u64, 0xff))); | |
| 1377 | const x55 = @truncate(u8, (x54 & @as(u64, 0xff))); | |
| 1379 | 1378 | const x56 = (x54 >> 8); |
| 1380 | const x57 = cast(u8, (x56 & cast(u64, 0xff))); | |
| 1379 | const x57 = @truncate(u8, (x56 & @as(u64, 0xff))); | |
| 1381 | 1380 | const x58 = (x56 >> 8); |
| 1382 | const x59 = cast(u8, (x58 & cast(u64, 0xff))); | |
| 1383 | const x60 = cast(u8, (x58 >> 8)); | |
| 1381 | const x59 = @truncate(u8, (x58 & @as(u64, 0xff))); | |
| 1382 | const x60 = @truncate(u8, (x58 >> 8)); | |
| 1384 | 1383 | out1[0] = x5; |
| 1385 | 1384 | out1[1] = x7; |
| 1386 | 1385 | out1[2] = x9; |
| ... | ... | @@ -1430,60 +1429,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void { |
| 1430 | 1429 | pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void { |
| 1431 | 1430 | @setRuntimeSafety(mode == .Debug); |
| 1432 | 1431 | |
| 1433 | const x1 = (cast(u64, (arg1[31])) << 56); | |
| 1434 | const x2 = (cast(u64, (arg1[30])) << 48); | |
| 1435 | const x3 = (cast(u64, (arg1[29])) << 40); | |
| 1436 | const x4 = (cast(u64, (arg1[28])) << 32); | |
| 1437 | const x5 = (cast(u64, (arg1[27])) << 24); | |
| 1438 | const x6 = (cast(u64, (arg1[26])) << 16); | |
| 1439 | const x7 = (cast(u64, (arg1[25])) << 8); | |
| 1432 | const x1 = (@as(u64, (arg1[31])) << 56); | |
| 1433 | const x2 = (@as(u64, (arg1[30])) << 48); | |
| 1434 | const x3 = (@as(u64, (arg1[29])) << 40); | |
| 1435 | const x4 = (@as(u64, (arg1[28])) << 32); | |
| 1436 | const x5 = (@as(u64, (arg1[27])) << 24); | |
| 1437 | const x6 = (@as(u64, (arg1[26])) << 16); | |
| 1438 | const x7 = (@as(u64, (arg1[25])) << 8); | |
| 1440 | 1439 | const x8 = (arg1[24]); |
| 1441 | const x9 = (cast(u64, (arg1[23])) << 56); | |
| 1442 | const x10 = (cast(u64, (arg1[22])) << 48); | |
| 1443 | const x11 = (cast(u64, (arg1[21])) << 40); | |
| 1444 | const x12 = (cast(u64, (arg1[20])) << 32); | |
| 1445 | const x13 = (cast(u64, (arg1[19])) << 24); | |
| 1446 | const x14 = (cast(u64, (arg1[18])) << 16); | |
| 1447 | const x15 = (cast(u64, (arg1[17])) << 8); | |
| 1440 | const x9 = (@as(u64, (arg1[23])) << 56); | |
| 1441 | const x10 = (@as(u64, (arg1[22])) << 48); | |
| 1442 | const x11 = (@as(u64, (arg1[21])) << 40); | |
| 1443 | const x12 = (@as(u64, (arg1[20])) << 32); | |
| 1444 | const x13 = (@as(u64, (arg1[19])) << 24); | |
| 1445 | const x14 = (@as(u64, (arg1[18])) << 16); | |
| 1446 | const x15 = (@as(u64, (arg1[17])) << 8); | |
| 1448 | 1447 | const x16 = (arg1[16]); |
| 1449 | const x17 = (cast(u64, (arg1[15])) << 56); | |
| 1450 | const x18 = (cast(u64, (arg1[14])) << 48); | |
| 1451 | const x19 = (cast(u64, (arg1[13])) << 40); | |
| 1452 | const x20 = (cast(u64, (arg1[12])) << 32); | |
| 1453 | const x21 = (cast(u64, (arg1[11])) << 24); | |
| 1454 | const x22 = (cast(u64, (arg1[10])) << 16); | |
| 1455 | const x23 = (cast(u64, (arg1[9])) << 8); | |
| 1448 | const x17 = (@as(u64, (arg1[15])) << 56); | |
| 1449 | const x18 = (@as(u64, (arg1[14])) << 48); | |
| 1450 | const x19 = (@as(u64, (arg1[13])) << 40); | |
| 1451 | const x20 = (@as(u64, (arg1[12])) << 32); | |
| 1452 | const x21 = (@as(u64, (arg1[11])) << 24); | |
| 1453 | const x22 = (@as(u64, (arg1[10])) << 16); | |
| 1454 | const x23 = (@as(u64, (arg1[9])) << 8); | |
| 1456 | 1455 | const x24 = (arg1[8]); |
| 1457 | const x25 = (cast(u64, (arg1[7])) << 56); | |
| 1458 | const x26 = (cast(u64, (arg1[6])) << 48); | |
| 1459 | const x27 = (cast(u64, (arg1[5])) << 40); | |
| 1460 | const x28 = (cast(u64, (arg1[4])) << 32); | |
| 1461 | const x29 = (cast(u64, (arg1[3])) << 24); | |
| 1462 | const x30 = (cast(u64, (arg1[2])) << 16); | |
| 1463 | const x31 = (cast(u64, (arg1[1])) << 8); | |
| 1456 | const x25 = (@as(u64, (arg1[7])) << 56); | |
| 1457 | const x26 = (@as(u64, (arg1[6])) << 48); | |
| 1458 | const x27 = (@as(u64, (arg1[5])) << 40); | |
| 1459 | const x28 = (@as(u64, (arg1[4])) << 32); | |
| 1460 | const x29 = (@as(u64, (arg1[3])) << 24); | |
| 1461 | const x30 = (@as(u64, (arg1[2])) << 16); | |
| 1462 | const x31 = (@as(u64, (arg1[1])) << 8); | |
| 1464 | 1463 | const x32 = (arg1[0]); |
| 1465 | const x33 = (x31 + cast(u64, x32)); | |
| 1464 | const x33 = (x31 + @as(u64, x32)); | |
| 1466 | 1465 | const x34 = (x30 + x33); |
| 1467 | 1466 | const x35 = (x29 + x34); |
| 1468 | 1467 | const x36 = (x28 + x35); |
| 1469 | 1468 | const x37 = (x27 + x36); |
| 1470 | 1469 | const x38 = (x26 + x37); |
| 1471 | 1470 | const x39 = (x25 + x38); |
| 1472 | const x40 = (x23 + cast(u64, x24)); | |
| 1471 | const x40 = (x23 + @as(u64, x24)); | |
| 1473 | 1472 | const x41 = (x22 + x40); |
| 1474 | 1473 | const x42 = (x21 + x41); |
| 1475 | 1474 | const x43 = (x20 + x42); |
| 1476 | 1475 | const x44 = (x19 + x43); |
| 1477 | 1476 | const x45 = (x18 + x44); |
| 1478 | 1477 | const x46 = (x17 + x45); |
| 1479 | const x47 = (x15 + cast(u64, x16)); | |
| 1478 | const x47 = (x15 + @as(u64, x16)); | |
| 1480 | 1479 | const x48 = (x14 + x47); |
| 1481 | 1480 | const x49 = (x13 + x48); |
| 1482 | 1481 | const x50 = (x12 + x49); |
| 1483 | 1482 | const x51 = (x11 + x50); |
| 1484 | 1483 | const x52 = (x10 + x51); |
| 1485 | 1484 | const x53 = (x9 + x52); |
| 1486 | const x54 = (x7 + cast(u64, x8)); | |
| 1485 | const x54 = (x7 + @as(u64, x8)); | |
| 1487 | 1486 | const x55 = (x6 + x54); |
| 1488 | 1487 | const x56 = (x5 + x55); |
| 1489 | 1488 | const x57 = (x4 + x56); |
| ... | ... | @@ -1505,7 +1504,7 @@ pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void { |
| 1505 | 1504 | pub fn setOne(out1: *MontgomeryDomainFieldElement) void { |
| 1506 | 1505 | @setRuntimeSafety(mode == .Debug); |
| 1507 | 1506 | |
| 1508 | out1[0] = cast(u64, 0x1); | |
| 1507 | out1[0] = @as(u64, 0x1); | |
| 1509 | 1508 | out1[1] = 0xffffffff00000000; |
| 1510 | 1509 | out1[2] = 0xffffffffffffffff; |
| 1511 | 1510 | out1[3] = 0xfffffffe; |
| ... | ... | @@ -1524,9 +1523,9 @@ pub fn msat(out1: *[5]u64) void { |
| 1524 | 1523 | |
| 1525 | 1524 | out1[0] = 0xffffffffffffffff; |
| 1526 | 1525 | out1[1] = 0xffffffff; |
| 1527 | out1[2] = cast(u64, 0x0); | |
| 1526 | out1[2] = @as(u64, 0x0); | |
| 1528 | 1527 | out1[3] = 0xffffffff00000001; |
| 1529 | out1[4] = cast(u64, 0x0); | |
| 1528 | out1[4] = @as(u64, 0x0); | |
| 1530 | 1529 | } |
| 1531 | 1530 | |
| 1532 | 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 | 1561 | |
| 1563 | 1562 | var x1: u64 = undefined; |
| 1564 | 1563 | var x2: u1 = undefined; |
| 1565 | addcarryxU64(&x1, &x2, 0x0, (~arg1), cast(u64, 0x1)); | |
| 1566 | const x3 = (cast(u1, (x1 >> 63)) & cast(u1, ((arg3[0]) & cast(u64, 0x1)))); | |
| 1564 | addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1)); | |
| 1565 | const x3 = (@truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & @as(u64, 0x1)))); | |
| 1567 | 1566 | var x4: u64 = undefined; |
| 1568 | 1567 | var x5: u1 = undefined; |
| 1569 | addcarryxU64(&x4, &x5, 0x0, (~arg1), cast(u64, 0x1)); | |
| 1568 | addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1)); | |
| 1570 | 1569 | var x6: u64 = undefined; |
| 1571 | 1570 | cmovznzU64(&x6, x3, arg1, x4); |
| 1572 | 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 | 1580 | cmovznzU64(&x11, x3, (arg2[4]), (arg3[4])); |
| 1582 | 1581 | var x12: u64 = undefined; |
| 1583 | 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 | 1584 | var x14: u64 = undefined; |
| 1586 | 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 | 1587 | var x16: u64 = undefined; |
| 1589 | 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 | 1590 | var x18: u64 = undefined; |
| 1592 | 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 | 1593 | var x20: u64 = undefined; |
| 1595 | 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 | 1596 | var x22: u64 = undefined; |
| 1598 | 1597 | cmovznzU64(&x22, x3, (arg3[0]), x12); |
| 1599 | 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 | 1631 | subborrowxU64(&x41, &x42, x40, x33, 0xffffffff); |
| 1633 | 1632 | var x43: u64 = undefined; |
| 1634 | 1633 | var x44: u1 = undefined; |
| 1635 | subborrowxU64(&x43, &x44, x42, x35, cast(u64, 0x0)); | |
| 1634 | subborrowxU64(&x43, &x44, x42, x35, @as(u64, 0x0)); | |
| 1636 | 1635 | var x45: u64 = undefined; |
| 1637 | 1636 | var x46: u1 = undefined; |
| 1638 | 1637 | subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000001); |
| 1639 | 1638 | var x47: u64 = undefined; |
| 1640 | 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 | 1641 | const x49 = (arg4[3]); |
| 1643 | 1642 | const x50 = (arg4[2]); |
| 1644 | 1643 | const x51 = (arg4[1]); |
| 1645 | 1644 | const x52 = (arg4[0]); |
| 1646 | 1645 | var x53: u64 = undefined; |
| 1647 | 1646 | var x54: u1 = undefined; |
| 1648 | subborrowxU64(&x53, &x54, 0x0, cast(u64, 0x0), x52); | |
| 1647 | subborrowxU64(&x53, &x54, 0x0, @as(u64, 0x0), x52); | |
| 1649 | 1648 | var x55: u64 = undefined; |
| 1650 | 1649 | var x56: u1 = undefined; |
| 1651 | subborrowxU64(&x55, &x56, x54, cast(u64, 0x0), x51); | |
| 1650 | subborrowxU64(&x55, &x56, x54, @as(u64, 0x0), x51); | |
| 1652 | 1651 | var x57: u64 = undefined; |
| 1653 | 1652 | var x58: u1 = undefined; |
| 1654 | subborrowxU64(&x57, &x58, x56, cast(u64, 0x0), x50); | |
| 1653 | subborrowxU64(&x57, &x58, x56, @as(u64, 0x0), x50); | |
| 1655 | 1654 | var x59: u64 = undefined; |
| 1656 | 1655 | var x60: u1 = undefined; |
| 1657 | subborrowxU64(&x59, &x60, x58, cast(u64, 0x0), x49); | |
| 1656 | subborrowxU64(&x59, &x60, x58, @as(u64, 0x0), x49); | |
| 1658 | 1657 | var x61: u64 = undefined; |
| 1659 | cmovznzU64(&x61, x60, cast(u64, 0x0), 0xffffffffffffffff); | |
| 1658 | cmovznzU64(&x61, x60, @as(u64, 0x0), 0xffffffffffffffff); | |
| 1660 | 1659 | var x62: u64 = undefined; |
| 1661 | 1660 | var x63: u1 = undefined; |
| 1662 | 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 | 1664 | addcarryxU64(&x64, &x65, x63, x55, (x61 & 0xffffffff)); |
| 1666 | 1665 | var x66: u64 = undefined; |
| 1667 | 1666 | var x67: u1 = undefined; |
| 1668 | addcarryxU64(&x66, &x67, x65, x57, cast(u64, 0x0)); | |
| 1667 | addcarryxU64(&x66, &x67, x65, x57, @as(u64, 0x0)); | |
| 1669 | 1668 | var x68: u64 = undefined; |
| 1670 | 1669 | var x69: u1 = undefined; |
| 1671 | 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 | 1676 | cmovznzU64(&x72, x3, (arg5[2]), x66); |
| 1678 | 1677 | var x73: u64 = undefined; |
| 1679 | 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 | 1680 | var x75: u64 = undefined; |
| 1682 | cmovznzU64(&x75, x74, cast(u64, 0x0), x7); | |
| 1681 | cmovznzU64(&x75, x74, @as(u64, 0x0), x7); | |
| 1683 | 1682 | var x76: u64 = undefined; |
| 1684 | cmovznzU64(&x76, x74, cast(u64, 0x0), x8); | |
| 1683 | cmovznzU64(&x76, x74, @as(u64, 0x0), x8); | |
| 1685 | 1684 | var x77: u64 = undefined; |
| 1686 | cmovznzU64(&x77, x74, cast(u64, 0x0), x9); | |
| 1685 | cmovznzU64(&x77, x74, @as(u64, 0x0), x9); | |
| 1687 | 1686 | var x78: u64 = undefined; |
| 1688 | cmovznzU64(&x78, x74, cast(u64, 0x0), x10); | |
| 1687 | cmovznzU64(&x78, x74, @as(u64, 0x0), x10); | |
| 1689 | 1688 | var x79: u64 = undefined; |
| 1690 | cmovznzU64(&x79, x74, cast(u64, 0x0), x11); | |
| 1689 | cmovznzU64(&x79, x74, @as(u64, 0x0), x11); | |
| 1691 | 1690 | var x80: u64 = undefined; |
| 1692 | 1691 | var x81: u1 = undefined; |
| 1693 | 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 | 1703 | var x89: u1 = undefined; |
| 1705 | 1704 | addcarryxU64(&x88, &x89, x87, x26, x79); |
| 1706 | 1705 | var x90: u64 = undefined; |
| 1707 | cmovznzU64(&x90, x74, cast(u64, 0x0), x27); | |
| 1706 | cmovznzU64(&x90, x74, @as(u64, 0x0), x27); | |
| 1708 | 1707 | var x91: u64 = undefined; |
| 1709 | cmovznzU64(&x91, x74, cast(u64, 0x0), x28); | |
| 1708 | cmovznzU64(&x91, x74, @as(u64, 0x0), x28); | |
| 1710 | 1709 | var x92: u64 = undefined; |
| 1711 | cmovznzU64(&x92, x74, cast(u64, 0x0), x29); | |
| 1710 | cmovznzU64(&x92, x74, @as(u64, 0x0), x29); | |
| 1712 | 1711 | var x93: u64 = undefined; |
| 1713 | cmovznzU64(&x93, x74, cast(u64, 0x0), x30); | |
| 1712 | cmovznzU64(&x93, x74, @as(u64, 0x0), x30); | |
| 1714 | 1713 | var x94: u64 = undefined; |
| 1715 | 1714 | var x95: u1 = undefined; |
| 1716 | 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 | 1730 | subborrowxU64(&x104, &x105, x103, x96, 0xffffffff); |
| 1732 | 1731 | var x106: u64 = undefined; |
| 1733 | 1732 | var x107: u1 = undefined; |
| 1734 | subborrowxU64(&x106, &x107, x105, x98, cast(u64, 0x0)); | |
| 1733 | subborrowxU64(&x106, &x107, x105, x98, @as(u64, 0x0)); | |
| 1735 | 1734 | var x108: u64 = undefined; |
| 1736 | 1735 | var x109: u1 = undefined; |
| 1737 | 1736 | subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000001); |
| 1738 | 1737 | var x110: u64 = undefined; |
| 1739 | 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 | 1740 | var x112: u64 = undefined; |
| 1742 | 1741 | var x113: u1 = undefined; |
| 1743 | addcarryxU64(&x112, &x113, 0x0, x6, cast(u64, 0x1)); | |
| 1742 | addcarryxU64(&x112, &x113, 0x0, x6, @as(u64, 0x1)); | |
| 1744 | 1743 | const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff)); |
| 1745 | 1744 | const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff)); |
| 1746 | 1745 | const x116 = ((x84 >> 1) | ((x86 << 63) & 0xffffffffffffffff)); |
lib/std/crypto/pcurves/p256/p256_scalar_64.zig+144-145| ... | ... | @@ -18,7 +18,6 @@ |
| 18 | 18 | // if x1 & (2^256-1) < 2^255 then x1 & (2^256-1) else (x1 & (2^256-1)) - 2^256 |
| 19 | 19 | |
| 20 | 20 | const std = @import("std"); |
| 21 | const cast = std.meta.cast; | |
| 22 | 21 | const mode = std.builtin.mode; // Checked arithmetic is disabled in non-debug modes to avoid side channels |
| 23 | 22 | |
| 24 | 23 | // The type MontgomeryDomainFieldElement is a field element in the Montgomery domain. |
| ... | ... | @@ -148,7 +147,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 148 | 147 | var x17: u64 = undefined; |
| 149 | 148 | var x18: u1 = undefined; |
| 150 | 149 | addcarryxU64(&x17, &x18, x16, x8, x5); |
| 151 | const x19 = (cast(u64, x18) + x6); | |
| 150 | const x19 = (@as(u64, x18) + x6); | |
| 152 | 151 | var x20: u64 = undefined; |
| 153 | 152 | var x21: u64 = undefined; |
| 154 | 153 | mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -173,7 +172,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 173 | 172 | var x34: u64 = undefined; |
| 174 | 173 | var x35: u1 = undefined; |
| 175 | 174 | addcarryxU64(&x34, &x35, x33, x25, x22); |
| 176 | const x36 = (cast(u64, x35) + x23); | |
| 175 | const x36 = (@as(u64, x35) + x23); | |
| 177 | 176 | var x37: u64 = undefined; |
| 178 | 177 | var x38: u1 = undefined; |
| 179 | 178 | addcarryxU64(&x37, &x38, 0x0, x11, x28); |
| ... | ... | @@ -210,7 +209,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 210 | 209 | var x59: u64 = undefined; |
| 211 | 210 | var x60: u1 = undefined; |
| 212 | 211 | addcarryxU64(&x59, &x60, x58, x50, x47); |
| 213 | const x61 = (cast(u64, x60) + x48); | |
| 212 | const x61 = (@as(u64, x60) + x48); | |
| 214 | 213 | var x62: u64 = undefined; |
| 215 | 214 | var x63: u1 = undefined; |
| 216 | 215 | addcarryxU64(&x62, &x63, 0x0, x39, x53); |
| ... | ... | @@ -225,7 +224,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 225 | 224 | addcarryxU64(&x68, &x69, x67, x45, x59); |
| 226 | 225 | var x70: u64 = undefined; |
| 227 | 226 | var x71: u1 = undefined; |
| 228 | addcarryxU64(&x70, &x71, x69, cast(u64, x46), x61); | |
| 227 | addcarryxU64(&x70, &x71, x69, @as(u64, x46), x61); | |
| 229 | 228 | var x72: u64 = undefined; |
| 230 | 229 | var x73: u64 = undefined; |
| 231 | 230 | mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -250,7 +249,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 250 | 249 | var x86: u64 = undefined; |
| 251 | 250 | var x87: u1 = undefined; |
| 252 | 251 | addcarryxU64(&x86, &x87, x85, x77, x74); |
| 253 | const x88 = (cast(u64, x87) + x75); | |
| 252 | const x88 = (@as(u64, x87) + x75); | |
| 254 | 253 | var x89: u64 = undefined; |
| 255 | 254 | var x90: u1 = undefined; |
| 256 | 255 | addcarryxU64(&x89, &x90, 0x0, x62, x80); |
| ... | ... | @@ -266,7 +265,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 266 | 265 | var x97: u64 = undefined; |
| 267 | 266 | var x98: u1 = undefined; |
| 268 | 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 | 269 | var x100: u64 = undefined; |
| 271 | 270 | var x101: u64 = undefined; |
| 272 | 271 | mulxU64(&x100, &x101, x2, (arg2[3])); |
| ... | ... | @@ -288,7 +287,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 288 | 287 | var x112: u64 = undefined; |
| 289 | 288 | var x113: u1 = undefined; |
| 290 | 289 | addcarryxU64(&x112, &x113, x111, x103, x100); |
| 291 | const x114 = (cast(u64, x113) + x101); | |
| 290 | const x114 = (@as(u64, x113) + x101); | |
| 292 | 291 | var x115: u64 = undefined; |
| 293 | 292 | var x116: u1 = undefined; |
| 294 | 293 | addcarryxU64(&x115, &x116, 0x0, x91, x106); |
| ... | ... | @@ -328,7 +327,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 328 | 327 | var x139: u64 = undefined; |
| 329 | 328 | var x140: u1 = undefined; |
| 330 | 329 | addcarryxU64(&x139, &x140, x138, x130, x127); |
| 331 | const x141 = (cast(u64, x140) + x128); | |
| 330 | const x141 = (@as(u64, x140) + x128); | |
| 332 | 331 | var x142: u64 = undefined; |
| 333 | 332 | var x143: u1 = undefined; |
| 334 | 333 | addcarryxU64(&x142, &x143, 0x0, x115, x133); |
| ... | ... | @@ -344,7 +343,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 344 | 343 | var x150: u64 = undefined; |
| 345 | 344 | var x151: u1 = undefined; |
| 346 | 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 | 347 | var x153: u64 = undefined; |
| 349 | 348 | var x154: u64 = undefined; |
| 350 | 349 | mulxU64(&x153, &x154, x3, (arg2[3])); |
| ... | ... | @@ -366,7 +365,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 366 | 365 | var x165: u64 = undefined; |
| 367 | 366 | var x166: u1 = undefined; |
| 368 | 367 | addcarryxU64(&x165, &x166, x164, x156, x153); |
| 369 | const x167 = (cast(u64, x166) + x154); | |
| 368 | const x167 = (@as(u64, x166) + x154); | |
| 370 | 369 | var x168: u64 = undefined; |
| 371 | 370 | var x169: u1 = undefined; |
| 372 | 371 | addcarryxU64(&x168, &x169, 0x0, x144, x159); |
| ... | ... | @@ -406,7 +405,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 406 | 405 | var x192: u64 = undefined; |
| 407 | 406 | var x193: u1 = undefined; |
| 408 | 407 | addcarryxU64(&x192, &x193, x191, x183, x180); |
| 409 | const x194 = (cast(u64, x193) + x181); | |
| 408 | const x194 = (@as(u64, x193) + x181); | |
| 410 | 409 | var x195: u64 = undefined; |
| 411 | 410 | var x196: u1 = undefined; |
| 412 | 411 | addcarryxU64(&x195, &x196, 0x0, x168, x186); |
| ... | ... | @@ -422,7 +421,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 422 | 421 | var x203: u64 = undefined; |
| 423 | 422 | var x204: u1 = undefined; |
| 424 | 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 | 425 | var x206: u64 = undefined; |
| 427 | 426 | var x207: u1 = undefined; |
| 428 | 427 | subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551); |
| ... | ... | @@ -437,7 +436,7 @@ pub fn mul(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 437 | 436 | subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000); |
| 438 | 437 | var x214: u64 = undefined; |
| 439 | 438 | var x215: u1 = undefined; |
| 440 | subborrowxU64(&x214, &x215, x213, x205, cast(u64, 0x0)); | |
| 439 | subborrowxU64(&x214, &x215, x213, x205, @as(u64, 0x0)); | |
| 441 | 440 | var x216: u64 = undefined; |
| 442 | 441 | cmovznzU64(&x216, x215, x206, x197); |
| 443 | 442 | var x217: u64 = undefined; |
| ... | ... | @@ -488,7 +487,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 488 | 487 | var x17: u64 = undefined; |
| 489 | 488 | var x18: u1 = undefined; |
| 490 | 489 | addcarryxU64(&x17, &x18, x16, x8, x5); |
| 491 | const x19 = (cast(u64, x18) + x6); | |
| 490 | const x19 = (@as(u64, x18) + x6); | |
| 492 | 491 | var x20: u64 = undefined; |
| 493 | 492 | var x21: u64 = undefined; |
| 494 | 493 | mulxU64(&x20, &x21, x11, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -513,7 +512,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 513 | 512 | var x34: u64 = undefined; |
| 514 | 513 | var x35: u1 = undefined; |
| 515 | 514 | addcarryxU64(&x34, &x35, x33, x25, x22); |
| 516 | const x36 = (cast(u64, x35) + x23); | |
| 515 | const x36 = (@as(u64, x35) + x23); | |
| 517 | 516 | var x37: u64 = undefined; |
| 518 | 517 | var x38: u1 = undefined; |
| 519 | 518 | addcarryxU64(&x37, &x38, 0x0, x11, x28); |
| ... | ... | @@ -550,7 +549,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 550 | 549 | var x59: u64 = undefined; |
| 551 | 550 | var x60: u1 = undefined; |
| 552 | 551 | addcarryxU64(&x59, &x60, x58, x50, x47); |
| 553 | const x61 = (cast(u64, x60) + x48); | |
| 552 | const x61 = (@as(u64, x60) + x48); | |
| 554 | 553 | var x62: u64 = undefined; |
| 555 | 554 | var x63: u1 = undefined; |
| 556 | 555 | addcarryxU64(&x62, &x63, 0x0, x39, x53); |
| ... | ... | @@ -565,7 +564,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 565 | 564 | addcarryxU64(&x68, &x69, x67, x45, x59); |
| 566 | 565 | var x70: u64 = undefined; |
| 567 | 566 | var x71: u1 = undefined; |
| 568 | addcarryxU64(&x70, &x71, x69, cast(u64, x46), x61); | |
| 567 | addcarryxU64(&x70, &x71, x69, @as(u64, x46), x61); | |
| 569 | 568 | var x72: u64 = undefined; |
| 570 | 569 | var x73: u64 = undefined; |
| 571 | 570 | mulxU64(&x72, &x73, x62, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -590,7 +589,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 590 | 589 | var x86: u64 = undefined; |
| 591 | 590 | var x87: u1 = undefined; |
| 592 | 591 | addcarryxU64(&x86, &x87, x85, x77, x74); |
| 593 | const x88 = (cast(u64, x87) + x75); | |
| 592 | const x88 = (@as(u64, x87) + x75); | |
| 594 | 593 | var x89: u64 = undefined; |
| 595 | 594 | var x90: u1 = undefined; |
| 596 | 595 | addcarryxU64(&x89, &x90, 0x0, x62, x80); |
| ... | ... | @@ -606,7 +605,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 606 | 605 | var x97: u64 = undefined; |
| 607 | 606 | var x98: u1 = undefined; |
| 608 | 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 | 609 | var x100: u64 = undefined; |
| 611 | 610 | var x101: u64 = undefined; |
| 612 | 611 | mulxU64(&x100, &x101, x2, (arg1[3])); |
| ... | ... | @@ -628,7 +627,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 628 | 627 | var x112: u64 = undefined; |
| 629 | 628 | var x113: u1 = undefined; |
| 630 | 629 | addcarryxU64(&x112, &x113, x111, x103, x100); |
| 631 | const x114 = (cast(u64, x113) + x101); | |
| 630 | const x114 = (@as(u64, x113) + x101); | |
| 632 | 631 | var x115: u64 = undefined; |
| 633 | 632 | var x116: u1 = undefined; |
| 634 | 633 | addcarryxU64(&x115, &x116, 0x0, x91, x106); |
| ... | ... | @@ -668,7 +667,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 668 | 667 | var x139: u64 = undefined; |
| 669 | 668 | var x140: u1 = undefined; |
| 670 | 669 | addcarryxU64(&x139, &x140, x138, x130, x127); |
| 671 | const x141 = (cast(u64, x140) + x128); | |
| 670 | const x141 = (@as(u64, x140) + x128); | |
| 672 | 671 | var x142: u64 = undefined; |
| 673 | 672 | var x143: u1 = undefined; |
| 674 | 673 | addcarryxU64(&x142, &x143, 0x0, x115, x133); |
| ... | ... | @@ -684,7 +683,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 684 | 683 | var x150: u64 = undefined; |
| 685 | 684 | var x151: u1 = undefined; |
| 686 | 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 | 687 | var x153: u64 = undefined; |
| 689 | 688 | var x154: u64 = undefined; |
| 690 | 689 | mulxU64(&x153, &x154, x3, (arg1[3])); |
| ... | ... | @@ -706,7 +705,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 706 | 705 | var x165: u64 = undefined; |
| 707 | 706 | var x166: u1 = undefined; |
| 708 | 707 | addcarryxU64(&x165, &x166, x164, x156, x153); |
| 709 | const x167 = (cast(u64, x166) + x154); | |
| 708 | const x167 = (@as(u64, x166) + x154); | |
| 710 | 709 | var x168: u64 = undefined; |
| 711 | 710 | var x169: u1 = undefined; |
| 712 | 711 | addcarryxU64(&x168, &x169, 0x0, x144, x159); |
| ... | ... | @@ -746,7 +745,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 746 | 745 | var x192: u64 = undefined; |
| 747 | 746 | var x193: u1 = undefined; |
| 748 | 747 | addcarryxU64(&x192, &x193, x191, x183, x180); |
| 749 | const x194 = (cast(u64, x193) + x181); | |
| 748 | const x194 = (@as(u64, x193) + x181); | |
| 750 | 749 | var x195: u64 = undefined; |
| 751 | 750 | var x196: u1 = undefined; |
| 752 | 751 | addcarryxU64(&x195, &x196, 0x0, x168, x186); |
| ... | ... | @@ -762,7 +761,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 762 | 761 | var x203: u64 = undefined; |
| 763 | 762 | var x204: u1 = undefined; |
| 764 | 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 | 765 | var x206: u64 = undefined; |
| 767 | 766 | var x207: u1 = undefined; |
| 768 | 767 | subborrowxU64(&x206, &x207, 0x0, x197, 0xf3b9cac2fc632551); |
| ... | ... | @@ -777,7 +776,7 @@ pub fn square(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEl |
| 777 | 776 | subborrowxU64(&x212, &x213, x211, x203, 0xffffffff00000000); |
| 778 | 777 | var x214: u64 = undefined; |
| 779 | 778 | var x215: u1 = undefined; |
| 780 | subborrowxU64(&x214, &x215, x213, x205, cast(u64, 0x0)); | |
| 779 | subborrowxU64(&x214, &x215, x213, x205, @as(u64, 0x0)); | |
| 781 | 780 | var x216: u64 = undefined; |
| 782 | 781 | cmovznzU64(&x216, x215, x206, x197); |
| 783 | 782 | var x217: u64 = undefined; |
| ... | ... | @@ -830,7 +829,7 @@ pub fn add(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 830 | 829 | subborrowxU64(&x15, &x16, x14, x7, 0xffffffff00000000); |
| 831 | 830 | var x17: u64 = undefined; |
| 832 | 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 | 833 | var x19: u64 = undefined; |
| 835 | 834 | cmovznzU64(&x19, x18, x9, x1); |
| 836 | 835 | var x20: u64 = undefined; |
| ... | ... | @@ -870,7 +869,7 @@ pub fn sub(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 870 | 869 | var x8: u1 = undefined; |
| 871 | 870 | subborrowxU64(&x7, &x8, x6, (arg1[3]), (arg2[3])); |
| 872 | 871 | var x9: u64 = undefined; |
| 873 | cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff); | |
| 872 | cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff); | |
| 874 | 873 | var x10: u64 = undefined; |
| 875 | 874 | var x11: u1 = undefined; |
| 876 | 875 | addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551)); |
| ... | ... | @@ -902,18 +901,18 @@ pub fn opp(out1: *MontgomeryDomainFieldElement, arg1: MontgomeryDomainFieldEleme |
| 902 | 901 | |
| 903 | 902 | var x1: u64 = undefined; |
| 904 | 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 | 905 | var x3: u64 = undefined; |
| 907 | 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 | 908 | var x5: u64 = undefined; |
| 910 | 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 | 911 | var x7: u64 = undefined; |
| 913 | 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 | 914 | var x9: u64 = undefined; |
| 916 | cmovznzU64(&x9, x8, cast(u64, 0x0), 0xffffffffffffffff); | |
| 915 | cmovznzU64(&x9, x8, @as(u64, 0x0), 0xffffffffffffffff); | |
| 917 | 916 | var x10: u64 = undefined; |
| 918 | 917 | var x11: u1 = undefined; |
| 919 | 918 | addcarryxU64(&x10, &x11, 0x0, x1, (x9 & 0xf3b9cac2fc632551)); |
| ... | ... | @@ -973,22 +972,22 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 973 | 972 | addcarryxU64(&x18, &x19, 0x0, x1, x10); |
| 974 | 973 | var x20: u64 = undefined; |
| 975 | 974 | var x21: u1 = undefined; |
| 976 | addcarryxU64(&x20, &x21, x19, cast(u64, 0x0), x12); | |
| 975 | addcarryxU64(&x20, &x21, x19, @as(u64, 0x0), x12); | |
| 977 | 976 | var x22: u64 = undefined; |
| 978 | 977 | var x23: u1 = undefined; |
| 979 | addcarryxU64(&x22, &x23, x21, cast(u64, 0x0), x14); | |
| 978 | addcarryxU64(&x22, &x23, x21, @as(u64, 0x0), x14); | |
| 980 | 979 | var x24: u64 = undefined; |
| 981 | 980 | var x25: u1 = undefined; |
| 982 | addcarryxU64(&x24, &x25, x23, cast(u64, 0x0), x16); | |
| 981 | addcarryxU64(&x24, &x25, x23, @as(u64, 0x0), x16); | |
| 983 | 982 | var x26: u64 = undefined; |
| 984 | 983 | var x27: u1 = undefined; |
| 985 | 984 | addcarryxU64(&x26, &x27, 0x0, x20, (arg1[1])); |
| 986 | 985 | var x28: u64 = undefined; |
| 987 | 986 | var x29: u1 = undefined; |
| 988 | addcarryxU64(&x28, &x29, x27, x22, cast(u64, 0x0)); | |
| 987 | addcarryxU64(&x28, &x29, x27, x22, @as(u64, 0x0)); | |
| 989 | 988 | var x30: u64 = undefined; |
| 990 | 989 | var x31: u1 = undefined; |
| 991 | addcarryxU64(&x30, &x31, x29, x24, cast(u64, 0x0)); | |
| 990 | addcarryxU64(&x30, &x31, x29, x24, @as(u64, 0x0)); | |
| 992 | 991 | var x32: u64 = undefined; |
| 993 | 992 | var x33: u64 = undefined; |
| 994 | 993 | mulxU64(&x32, &x33, x26, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -1024,16 +1023,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 1024 | 1023 | addcarryxU64(&x52, &x53, x51, x30, x44); |
| 1025 | 1024 | var x54: u64 = undefined; |
| 1026 | 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 | 1027 | var x56: u64 = undefined; |
| 1029 | 1028 | var x57: u1 = undefined; |
| 1030 | 1029 | addcarryxU64(&x56, &x57, 0x0, x50, (arg1[2])); |
| 1031 | 1030 | var x58: u64 = undefined; |
| 1032 | 1031 | var x59: u1 = undefined; |
| 1033 | addcarryxU64(&x58, &x59, x57, x52, cast(u64, 0x0)); | |
| 1032 | addcarryxU64(&x58, &x59, x57, x52, @as(u64, 0x0)); | |
| 1034 | 1033 | var x60: u64 = undefined; |
| 1035 | 1034 | var x61: u1 = undefined; |
| 1036 | addcarryxU64(&x60, &x61, x59, x54, cast(u64, 0x0)); | |
| 1035 | addcarryxU64(&x60, &x61, x59, x54, @as(u64, 0x0)); | |
| 1037 | 1036 | var x62: u64 = undefined; |
| 1038 | 1037 | var x63: u64 = undefined; |
| 1039 | 1038 | mulxU64(&x62, &x63, x56, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -1069,16 +1068,16 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 1069 | 1068 | addcarryxU64(&x82, &x83, x81, x60, x74); |
| 1070 | 1069 | var x84: u64 = undefined; |
| 1071 | 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 | 1072 | var x86: u64 = undefined; |
| 1074 | 1073 | var x87: u1 = undefined; |
| 1075 | 1074 | addcarryxU64(&x86, &x87, 0x0, x80, (arg1[3])); |
| 1076 | 1075 | var x88: u64 = undefined; |
| 1077 | 1076 | var x89: u1 = undefined; |
| 1078 | addcarryxU64(&x88, &x89, x87, x82, cast(u64, 0x0)); | |
| 1077 | addcarryxU64(&x88, &x89, x87, x82, @as(u64, 0x0)); | |
| 1079 | 1078 | var x90: u64 = undefined; |
| 1080 | 1079 | var x91: u1 = undefined; |
| 1081 | addcarryxU64(&x90, &x91, x89, x84, cast(u64, 0x0)); | |
| 1080 | addcarryxU64(&x90, &x91, x89, x84, @as(u64, 0x0)); | |
| 1082 | 1081 | var x92: u64 = undefined; |
| 1083 | 1082 | var x93: u64 = undefined; |
| 1084 | 1083 | mulxU64(&x92, &x93, x86, 0xccd1c8aaee00bc4f); |
| ... | ... | @@ -1114,8 +1113,8 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 1114 | 1113 | addcarryxU64(&x112, &x113, x111, x90, x104); |
| 1115 | 1114 | var x114: u64 = undefined; |
| 1116 | 1115 | var x115: u1 = undefined; |
| 1117 | addcarryxU64(&x114, &x115, x113, (cast(u64, x91) + (cast(u64, x85) + (cast(u64, x77) + x65))), x106); | |
| 1118 | const x116 = (cast(u64, x115) + (cast(u64, x107) + x95)); | |
| 1116 | addcarryxU64(&x114, &x115, x113, (@as(u64, x91) + (@as(u64, x85) + (@as(u64, x77) + x65))), x106); | |
| 1117 | const x116 = (@as(u64, x115) + (@as(u64, x107) + x95)); | |
| 1119 | 1118 | var x117: u64 = undefined; |
| 1120 | 1119 | var x118: u1 = undefined; |
| 1121 | 1120 | subborrowxU64(&x117, &x118, 0x0, x110, 0xf3b9cac2fc632551); |
| ... | ... | @@ -1130,7 +1129,7 @@ pub fn fromMontgomery(out1: *NonMontgomeryDomainFieldElement, arg1: MontgomeryDo |
| 1130 | 1129 | subborrowxU64(&x123, &x124, x122, x116, 0xffffffff00000000); |
| 1131 | 1130 | var x125: u64 = undefined; |
| 1132 | 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 | 1133 | var x127: u64 = undefined; |
| 1135 | 1134 | cmovznzU64(&x127, x126, x117, x110); |
| 1136 | 1135 | var x128: u64 = undefined; |
| ... | ... | @@ -1219,7 +1218,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1219 | 1218 | addcarryxU64(&x41, &x42, x40, x17, x33); |
| 1220 | 1219 | var x43: u64 = undefined; |
| 1221 | 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 | 1222 | var x45: u64 = undefined; |
| 1224 | 1223 | var x46: u64 = undefined; |
| 1225 | 1224 | mulxU64(&x45, &x46, x1, 0x66e12d94f3d95620); |
| ... | ... | @@ -1291,7 +1290,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1291 | 1290 | addcarryxU64(&x89, &x90, x88, x65, x81); |
| 1292 | 1291 | var x91: u64 = undefined; |
| 1293 | 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 | 1294 | var x93: u64 = undefined; |
| 1296 | 1295 | var x94: u64 = undefined; |
| 1297 | 1296 | mulxU64(&x93, &x94, x2, 0x66e12d94f3d95620); |
| ... | ... | @@ -1363,7 +1362,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1363 | 1362 | addcarryxU64(&x137, &x138, x136, x113, x129); |
| 1364 | 1363 | var x139: u64 = undefined; |
| 1365 | 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 | 1366 | var x141: u64 = undefined; |
| 1368 | 1367 | var x142: u64 = undefined; |
| 1369 | 1368 | mulxU64(&x141, &x142, x3, 0x66e12d94f3d95620); |
| ... | ... | @@ -1435,7 +1434,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1435 | 1434 | addcarryxU64(&x185, &x186, x184, x161, x177); |
| 1436 | 1435 | var x187: u64 = undefined; |
| 1437 | 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 | 1438 | var x189: u64 = undefined; |
| 1440 | 1439 | var x190: u1 = undefined; |
| 1441 | 1440 | subborrowxU64(&x189, &x190, 0x0, x181, 0xf3b9cac2fc632551); |
| ... | ... | @@ -1450,7 +1449,7 @@ pub fn toMontgomery(out1: *MontgomeryDomainFieldElement, arg1: NonMontgomeryDoma |
| 1450 | 1449 | subborrowxU64(&x195, &x196, x194, x187, 0xffffffff00000000); |
| 1451 | 1450 | var x197: u64 = undefined; |
| 1452 | 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 | 1453 | var x199: u64 = undefined; |
| 1455 | 1454 | cmovznzU64(&x199, x198, x189, x181); |
| 1456 | 1455 | var x200: u64 = undefined; |
| ... | ... | @@ -1529,62 +1528,62 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void { |
| 1529 | 1528 | const x2 = (arg1[2]); |
| 1530 | 1529 | const x3 = (arg1[1]); |
| 1531 | 1530 | const x4 = (arg1[0]); |
| 1532 | const x5 = cast(u8, (x4 & cast(u64, 0xff))); | |
| 1531 | const x5 = @truncate(u8, (x4 & @as(u64, 0xff))); | |
| 1533 | 1532 | const x6 = (x4 >> 8); |
| 1534 | const x7 = cast(u8, (x6 & cast(u64, 0xff))); | |
| 1533 | const x7 = @truncate(u8, (x6 & @as(u64, 0xff))); | |
| 1535 | 1534 | const x8 = (x6 >> 8); |
| 1536 | const x9 = cast(u8, (x8 & cast(u64, 0xff))); | |
| 1535 | const x9 = @truncate(u8, (x8 & @as(u64, 0xff))); | |
| 1537 | 1536 | const x10 = (x8 >> 8); |
| 1538 | const x11 = cast(u8, (x10 & cast(u64, 0xff))); | |
| 1537 | const x11 = @truncate(u8, (x10 & @as(u64, 0xff))); | |
| 1539 | 1538 | const x12 = (x10 >> 8); |
| 1540 | const x13 = cast(u8, (x12 & cast(u64, 0xff))); | |
| 1539 | const x13 = @truncate(u8, (x12 & @as(u64, 0xff))); | |
| 1541 | 1540 | const x14 = (x12 >> 8); |
| 1542 | const x15 = cast(u8, (x14 & cast(u64, 0xff))); | |
| 1541 | const x15 = @truncate(u8, (x14 & @as(u64, 0xff))); | |
| 1543 | 1542 | const x16 = (x14 >> 8); |
| 1544 | const x17 = cast(u8, (x16 & cast(u64, 0xff))); | |
| 1545 | const x18 = cast(u8, (x16 >> 8)); | |
| 1546 | const x19 = cast(u8, (x3 & cast(u64, 0xff))); | |
| 1543 | const x17 = @truncate(u8, (x16 & @as(u64, 0xff))); | |
| 1544 | const x18 = @truncate(u8, (x16 >> 8)); | |
| 1545 | const x19 = @truncate(u8, (x3 & @as(u64, 0xff))); | |
| 1547 | 1546 | const x20 = (x3 >> 8); |
| 1548 | const x21 = cast(u8, (x20 & cast(u64, 0xff))); | |
| 1547 | const x21 = @truncate(u8, (x20 & @as(u64, 0xff))); | |
| 1549 | 1548 | const x22 = (x20 >> 8); |
| 1550 | const x23 = cast(u8, (x22 & cast(u64, 0xff))); | |
| 1549 | const x23 = @truncate(u8, (x22 & @as(u64, 0xff))); | |
| 1551 | 1550 | const x24 = (x22 >> 8); |
| 1552 | const x25 = cast(u8, (x24 & cast(u64, 0xff))); | |
| 1551 | const x25 = @truncate(u8, (x24 & @as(u64, 0xff))); | |
| 1553 | 1552 | const x26 = (x24 >> 8); |
| 1554 | const x27 = cast(u8, (x26 & cast(u64, 0xff))); | |
| 1553 | const x27 = @truncate(u8, (x26 & @as(u64, 0xff))); | |
| 1555 | 1554 | const x28 = (x26 >> 8); |
| 1556 | const x29 = cast(u8, (x28 & cast(u64, 0xff))); | |
| 1555 | const x29 = @truncate(u8, (x28 & @as(u64, 0xff))); | |
| 1557 | 1556 | const x30 = (x28 >> 8); |
| 1558 | const x31 = cast(u8, (x30 & cast(u64, 0xff))); | |
| 1559 | const x32 = cast(u8, (x30 >> 8)); | |
| 1560 | const x33 = cast(u8, (x2 & cast(u64, 0xff))); | |
| 1557 | const x31 = @truncate(u8, (x30 & @as(u64, 0xff))); | |
| 1558 | const x32 = @truncate(u8, (x30 >> 8)); | |
| 1559 | const x33 = @truncate(u8, (x2 & @as(u64, 0xff))); | |
| 1561 | 1560 | const x34 = (x2 >> 8); |
| 1562 | const x35 = cast(u8, (x34 & cast(u64, 0xff))); | |
| 1561 | const x35 = @truncate(u8, (x34 & @as(u64, 0xff))); | |
| 1563 | 1562 | const x36 = (x34 >> 8); |
| 1564 | const x37 = cast(u8, (x36 & cast(u64, 0xff))); | |
| 1563 | const x37 = @truncate(u8, (x36 & @as(u64, 0xff))); | |
| 1565 | 1564 | const x38 = (x36 >> 8); |
| 1566 | const x39 = cast(u8, (x38 & cast(u64, 0xff))); | |
| 1565 | const x39 = @truncate(u8, (x38 & @as(u64, 0xff))); | |
| 1567 | 1566 | const x40 = (x38 >> 8); |
| 1568 | const x41 = cast(u8, (x40 & cast(u64, 0xff))); | |
| 1567 | const x41 = @truncate(u8, (x40 & @as(u64, 0xff))); | |
| 1569 | 1568 | const x42 = (x40 >> 8); |
| 1570 | const x43 = cast(u8, (x42 & cast(u64, 0xff))); | |
| 1569 | const x43 = @truncate(u8, (x42 & @as(u64, 0xff))); | |
| 1571 | 1570 | const x44 = (x42 >> 8); |
| 1572 | const x45 = cast(u8, (x44 & cast(u64, 0xff))); | |
| 1573 | const x46 = cast(u8, (x44 >> 8)); | |
| 1574 | const x47 = cast(u8, (x1 & cast(u64, 0xff))); | |
| 1571 | const x45 = @truncate(u8, (x44 & @as(u64, 0xff))); | |
| 1572 | const x46 = @truncate(u8, (x44 >> 8)); | |
| 1573 | const x47 = @truncate(u8, (x1 & @as(u64, 0xff))); | |
| 1575 | 1574 | const x48 = (x1 >> 8); |
| 1576 | const x49 = cast(u8, (x48 & cast(u64, 0xff))); | |
| 1575 | const x49 = @truncate(u8, (x48 & @as(u64, 0xff))); | |
| 1577 | 1576 | const x50 = (x48 >> 8); |
| 1578 | const x51 = cast(u8, (x50 & cast(u64, 0xff))); | |
| 1577 | const x51 = @truncate(u8, (x50 & @as(u64, 0xff))); | |
| 1579 | 1578 | const x52 = (x50 >> 8); |
| 1580 | const x53 = cast(u8, (x52 & cast(u64, 0xff))); | |
| 1579 | const x53 = @truncate(u8, (x52 & @as(u64, 0xff))); | |
| 1581 | 1580 | const x54 = (x52 >> 8); |
| 1582 | const x55 = cast(u8, (x54 & cast(u64, 0xff))); | |
| 1581 | const x55 = @truncate(u8, (x54 & @as(u64, 0xff))); | |
| 1583 | 1582 | const x56 = (x54 >> 8); |
| 1584 | const x57 = cast(u8, (x56 & cast(u64, 0xff))); | |
| 1583 | const x57 = @truncate(u8, (x56 & @as(u64, 0xff))); | |
| 1585 | 1584 | const x58 = (x56 >> 8); |
| 1586 | const x59 = cast(u8, (x58 & cast(u64, 0xff))); | |
| 1587 | const x60 = cast(u8, (x58 >> 8)); | |
| 1585 | const x59 = @truncate(u8, (x58 & @as(u64, 0xff))); | |
| 1586 | const x60 = @truncate(u8, (x58 >> 8)); | |
| 1588 | 1587 | out1[0] = x5; |
| 1589 | 1588 | out1[1] = x7; |
| 1590 | 1589 | out1[2] = x9; |
| ... | ... | @@ -1634,60 +1633,60 @@ pub fn toBytes(out1: *[32]u8, arg1: [4]u64) void { |
| 1634 | 1633 | pub fn fromBytes(out1: *[4]u64, arg1: [32]u8) void { |
| 1635 | 1634 | @setRuntimeSafety(mode == .Debug); |
| 1636 | 1635 | |
| 1637 | const x1 = (cast(u64, (arg1[31])) << 56); | |
| 1638 | const x2 = (cast(u64, (arg1[30])) << 48); | |
| 1639 | const x3 = (cast(u64, (arg1[29])) << 40); | |
| 1640 | const x4 = (cast(u64, (arg1[28])) << 32); | |
| 1641 | const x5 = (cast(u64, (arg1[27])) << 24); | |
| 1642 | const x6 = (cast(u64, (arg1[26])) << 16); | |
| 1643 | const x7 = (cast(u64, (arg1[25])) << 8); | |
| 1636 | const x1 = (@as(u64, (arg1[31])) << 56); | |
| 1637 | const x2 = (@as(u64, (arg1[30])) << 48); | |
| 1638 | const x3 = (@as(u64, (arg1[29])) << 40); | |
| 1639 | const x4 = (@as(u64, (arg1[28])) << 32); | |
| 1640 | const x5 = (@as(u64, (arg1[27])) << 24); | |
| 1641 | const x6 = (@as(u64, (arg1[26])) << 16); | |
| 1642 | const x7 = (@as(u64, (arg1[25])) << 8); | |
| 1644 | 1643 | const x8 = (arg1[24]); |
| 1645 | const x9 = (cast(u64, (arg1[23])) << 56); | |
| 1646 | const x10 = (cast(u64, (arg1[22])) << 48); | |
| 1647 | const x11 = (cast(u64, (arg1[21])) << 40); | |
| 1648 | const x12 = (cast(u64, (arg1[20])) << 32); | |
| 1649 | const x13 = (cast(u64, (arg1[19])) << 24); | |
| 1650 | const x14 = (cast(u64, (arg1[18])) << 16); | |
| 1651 | const x15 = (cast(u64, (arg1[17])) << 8); | |
| 1644 | const x9 = (@as(u64, (arg1[23])) << 56); | |
| 1645 | const x10 = (@as(u64, (arg1[22])) << 48); | |
| 1646 | const x11 = (@as(u64, (arg1[21])) << 40); | |
| 1647 | const x12 = (@as(u64, (arg1[20])) << 32); | |
| 1648 | const x13 = (@as(u64, (arg1[19])) << 24); | |
| 1649 | const x14 = (@as(u64, (arg1[18])) << 16); | |
| 1650 | const x15 = (@as(u64, (arg1[17])) << 8); | |
| 1652 | 1651 | const x16 = (arg1[16]); |
| 1653 | const x17 = (cast(u64, (arg1[15])) << 56); | |
| 1654 | const x18 = (cast(u64, (arg1[14])) << 48); | |
| 1655 | const x19 = (cast(u64, (arg1[13])) << 40); | |
| 1656 | const x20 = (cast(u64, (arg1[12])) << 32); | |
| 1657 | const x21 = (cast(u64, (arg1[11])) << 24); | |
| 1658 | const x22 = (cast(u64, (arg1[10])) << 16); | |
| 1659 | const x23 = (cast(u64, (arg1[9])) << 8); | |
| 1652 | const x17 = (@as(u64, (arg1[15])) << 56); | |
| 1653 | const x18 = (@as(u64, (arg1[14])) << 48); | |
| 1654 | const x19 = (@as(u64, (arg1[13])) << 40); | |
| 1655 | const x20 = (@as(u64, (arg1[12])) << 32); | |
| 1656 | const x21 = (@as(u64, (arg1[11])) << 24); | |
| 1657 | const x22 = (@as(u64, (arg1[10])) << 16); | |
| 1658 | const x23 = (@as(u64, (arg1[9])) << 8); | |
| 1660 | 1659 | const x24 = (arg1[8]); |
| 1661 | const x25 = (cast(u64, (arg1[7])) << 56); | |
| 1662 | const x26 = (cast(u64, (arg1[6])) << 48); | |
| 1663 | const x27 = (cast(u64, (arg1[5])) << 40); | |
| 1664 | const x28 = (cast(u64, (arg1[4])) << 32); | |
| 1665 | const x29 = (cast(u64, (arg1[3])) << 24); | |
| 1666 | const x30 = (cast(u64, (arg1[2])) << 16); | |
| 1667 | const x31 = (cast(u64, (arg1[1])) << 8); | |
| 1660 | const x25 = (@as(u64, (arg1[7])) << 56); | |
| 1661 | const x26 = (@as(u64, (arg1[6])) << 48); | |
| 1662 | const x27 = (@as(u64, (arg1[5])) << 40); | |
| 1663 | const x28 = (@as(u64, (arg1[4])) << 32); | |
| 1664 | const x29 = (@as(u64, (arg1[3])) << 24); | |
| 1665 | const x30 = (@as(u64, (arg1[2])) << 16); | |
| 1666 | const x31 = (@as(u64, (arg1[1])) << 8); | |
| 1668 | 1667 | const x32 = (arg1[0]); |
| 1669 | const x33 = (x31 + cast(u64, x32)); | |
| 1668 | const x33 = (x31 + @as(u64, x32)); | |
| 1670 | 1669 | const x34 = (x30 + x33); |
| 1671 | 1670 | const x35 = (x29 + x34); |
| 1672 | 1671 | const x36 = (x28 + x35); |
| 1673 | 1672 | const x37 = (x27 + x36); |
| 1674 | 1673 | const x38 = (x26 + x37); |
| 1675 | 1674 | const x39 = (x25 + x38); |
| 1676 | const x40 = (x23 + cast(u64, x24)); | |
| 1675 | const x40 = (x23 + @as(u64, x24)); | |
| 1677 | 1676 | const x41 = (x22 + x40); |
| 1678 | 1677 | const x42 = (x21 + x41); |
| 1679 | 1678 | const x43 = (x20 + x42); |
| 1680 | 1679 | const x44 = (x19 + x43); |
| 1681 | 1680 | const x45 = (x18 + x44); |
| 1682 | 1681 | const x46 = (x17 + x45); |
| 1683 | const x47 = (x15 + cast(u64, x16)); | |
| 1682 | const x47 = (x15 + @as(u64, x16)); | |
| 1684 | 1683 | const x48 = (x14 + x47); |
| 1685 | 1684 | const x49 = (x13 + x48); |
| 1686 | 1685 | const x50 = (x12 + x49); |
| 1687 | 1686 | const x51 = (x11 + x50); |
| 1688 | 1687 | const x52 = (x10 + x51); |
| 1689 | 1688 | const x53 = (x9 + x52); |
| 1690 | const x54 = (x7 + cast(u64, x8)); | |
| 1689 | const x54 = (x7 + @as(u64, x8)); | |
| 1691 | 1690 | const x55 = (x6 + x54); |
| 1692 | 1691 | const x56 = (x5 + x55); |
| 1693 | 1692 | const x57 = (x4 + x56); |
| ... | ... | @@ -1711,7 +1710,7 @@ pub fn setOne(out1: *MontgomeryDomainFieldElement) void { |
| 1711 | 1710 | |
| 1712 | 1711 | out1[0] = 0xc46353d039cdaaf; |
| 1713 | 1712 | out1[1] = 0x4319055258e8617b; |
| 1714 | out1[2] = cast(u64, 0x0); | |
| 1713 | out1[2] = @as(u64, 0x0); | |
| 1715 | 1714 | out1[3] = 0xffffffff; |
| 1716 | 1715 | } |
| 1717 | 1716 | |
| ... | ... | @@ -1730,7 +1729,7 @@ pub fn msat(out1: *[5]u64) void { |
| 1730 | 1729 | out1[1] = 0xbce6faada7179e84; |
| 1731 | 1730 | out1[2] = 0xffffffffffffffff; |
| 1732 | 1731 | out1[3] = 0xffffffff00000000; |
| 1733 | out1[4] = cast(u64, 0x0); | |
| 1732 | out1[4] = @as(u64, 0x0); | |
| 1734 | 1733 | } |
| 1735 | 1734 | |
| 1736 | 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 | 1765 | |
| 1767 | 1766 | var x1: u64 = undefined; |
| 1768 | 1767 | var x2: u1 = undefined; |
| 1769 | addcarryxU64(&x1, &x2, 0x0, (~arg1), cast(u64, 0x1)); | |
| 1770 | const x3 = (cast(u1, (x1 >> 63)) & cast(u1, ((arg3[0]) & cast(u64, 0x1)))); | |
| 1768 | addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1)); | |
| 1769 | const x3 = (@as(u1, (x1 >> 63)) & @as(u1, ((arg3[0]) & @as(u64, 0x1)))); | |
| 1771 | 1770 | var x4: u64 = undefined; |
| 1772 | 1771 | var x5: u1 = undefined; |
| 1773 | addcarryxU64(&x4, &x5, 0x0, (~arg1), cast(u64, 0x1)); | |
| 1772 | addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1)); | |
| 1774 | 1773 | var x6: u64 = undefined; |
| 1775 | 1774 | cmovznzU64(&x6, x3, arg1, x4); |
| 1776 | 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 | 1784 | cmovznzU64(&x11, x3, (arg2[4]), (arg3[4])); |
| 1786 | 1785 | var x12: u64 = undefined; |
| 1787 | 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 | 1788 | var x14: u64 = undefined; |
| 1790 | 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 | 1791 | var x16: u64 = undefined; |
| 1793 | 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 | 1794 | var x18: u64 = undefined; |
| 1796 | 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 | 1797 | var x20: u64 = undefined; |
| 1799 | 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 | 1800 | var x22: u64 = undefined; |
| 1802 | 1801 | cmovznzU64(&x22, x3, (arg3[0]), x12); |
| 1803 | 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 | 1841 | subborrowxU64(&x45, &x46, x44, x37, 0xffffffff00000000); |
| 1843 | 1842 | var x47: u64 = undefined; |
| 1844 | 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 | 1845 | const x49 = (arg4[3]); |
| 1847 | 1846 | const x50 = (arg4[2]); |
| 1848 | 1847 | const x51 = (arg4[1]); |
| 1849 | 1848 | const x52 = (arg4[0]); |
| 1850 | 1849 | var x53: u64 = undefined; |
| 1851 | 1850 | var x54: u1 = undefined; |
| 1852 | subborrowxU64(&x53, &x54, 0x0, cast(u64, 0x0), x52); | |
| 1851 | subborrowxU64(&x53, &x54, 0x0, @as(u64, 0x0), x52); | |
| 1853 | 1852 | var x55: u64 = undefined; |
| 1854 | 1853 | var x56: u1 = undefined; |
| 1855 | subborrowxU64(&x55, &x56, x54, cast(u64, 0x0), x51); | |
| 1854 | subborrowxU64(&x55, &x56, x54, @as(u64, 0x0), x51); | |
| 1856 | 1855 | var x57: u64 = undefined; |
| 1857 | 1856 | var x58: u1 = undefined; |
| 1858 | subborrowxU64(&x57, &x58, x56, cast(u64, 0x0), x50); | |
| 1857 | subborrowxU64(&x57, &x58, x56, @as(u64, 0x0), x50); | |
| 1859 | 1858 | var x59: u64 = undefined; |
| 1860 | 1859 | var x60: u1 = undefined; |
| 1861 | subborrowxU64(&x59, &x60, x58, cast(u64, 0x0), x49); | |
| 1860 | subborrowxU64(&x59, &x60, x58, @as(u64, 0x0), x49); | |
| 1862 | 1861 | var x61: u64 = undefined; |
| 1863 | cmovznzU64(&x61, x60, cast(u64, 0x0), 0xffffffffffffffff); | |
| 1862 | cmovznzU64(&x61, x60, @as(u64, 0x0), 0xffffffffffffffff); | |
| 1864 | 1863 | var x62: u64 = undefined; |
| 1865 | 1864 | var x63: u1 = undefined; |
| 1866 | 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 | 1880 | cmovznzU64(&x72, x3, (arg5[2]), x66); |
| 1882 | 1881 | var x73: u64 = undefined; |
| 1883 | 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 | 1884 | var x75: u64 = undefined; |
| 1886 | cmovznzU64(&x75, x74, cast(u64, 0x0), x7); | |
| 1885 | cmovznzU64(&x75, x74, @as(u64, 0x0), x7); | |
| 1887 | 1886 | var x76: u64 = undefined; |
| 1888 | cmovznzU64(&x76, x74, cast(u64, 0x0), x8); | |
| 1887 | cmovznzU64(&x76, x74, @as(u64, 0x0), x8); | |
| 1889 | 1888 | var x77: u64 = undefined; |
| 1890 | cmovznzU64(&x77, x74, cast(u64, 0x0), x9); | |
| 1889 | cmovznzU64(&x77, x74, @as(u64, 0x0), x9); | |
| 1891 | 1890 | var x78: u64 = undefined; |
| 1892 | cmovznzU64(&x78, x74, cast(u64, 0x0), x10); | |
| 1891 | cmovznzU64(&x78, x74, @as(u64, 0x0), x10); | |
| 1893 | 1892 | var x79: u64 = undefined; |
| 1894 | cmovznzU64(&x79, x74, cast(u64, 0x0), x11); | |
| 1893 | cmovznzU64(&x79, x74, @as(u64, 0x0), x11); | |
| 1895 | 1894 | var x80: u64 = undefined; |
| 1896 | 1895 | var x81: u1 = undefined; |
| 1897 | 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 | 1907 | var x89: u1 = undefined; |
| 1909 | 1908 | addcarryxU64(&x88, &x89, x87, x26, x79); |
| 1910 | 1909 | var x90: u64 = undefined; |
| 1911 | cmovznzU64(&x90, x74, cast(u64, 0x0), x27); | |
| 1910 | cmovznzU64(&x90, x74, @as(u64, 0x0), x27); | |
| 1912 | 1911 | var x91: u64 = undefined; |
| 1913 | cmovznzU64(&x91, x74, cast(u64, 0x0), x28); | |
| 1912 | cmovznzU64(&x91, x74, @as(u64, 0x0), x28); | |
| 1914 | 1913 | var x92: u64 = undefined; |
| 1915 | cmovznzU64(&x92, x74, cast(u64, 0x0), x29); | |
| 1914 | cmovznzU64(&x92, x74, @as(u64, 0x0), x29); | |
| 1916 | 1915 | var x93: u64 = undefined; |
| 1917 | cmovznzU64(&x93, x74, cast(u64, 0x0), x30); | |
| 1916 | cmovznzU64(&x93, x74, @as(u64, 0x0), x30); | |
| 1918 | 1917 | var x94: u64 = undefined; |
| 1919 | 1918 | var x95: u1 = undefined; |
| 1920 | 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 | 1940 | subborrowxU64(&x108, &x109, x107, x100, 0xffffffff00000000); |
| 1942 | 1941 | var x110: u64 = undefined; |
| 1943 | 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 | 1944 | var x112: u64 = undefined; |
| 1946 | 1945 | var x113: u1 = undefined; |
| 1947 | addcarryxU64(&x112, &x113, 0x0, x6, cast(u64, 0x1)); | |
| 1946 | addcarryxU64(&x112, &x113, 0x0, x6, @as(u64, 0x1)); | |
| 1948 | 1947 | const x114 = ((x80 >> 1) | ((x82 << 63) & 0xffffffffffffffff)); |
| 1949 | 1948 | const x115 = ((x82 >> 1) | ((x84 << 63) & 0xffffffffffffffff)); |
| 1950 | 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 | 884 | }); |
| 885 | 885 | } |
| 886 | 886 | |
| 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. | |
| 889 | pub 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 | ||
| 929 | fn 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 | ||
| 939 | fn 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 | ||
| 952 | fn 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 | ||
| 976 | fn 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 | ||
| 984 | test "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. | |
| 1035 | pub 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 | ||
| 1103 | test "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 | ||
| 1148 | pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal }; | |
| 1149 | ||
| 1150 | fn 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. | |
| 1174 | pub 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 | ||
| 1182 | test "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 | 887 | /// For a given function type, returns a tuple type which fields will |
| 1201 | 888 | /// correspond to the argument types. |
| 1202 | 889 | /// |
| ... | ... | @@ -1316,38 +1003,6 @@ pub fn globalOption(comptime name: []const u8, comptime T: type) ?T { |
| 1316 | 1003 | return @as(T, @field(root, name)); |
| 1317 | 1004 | } |
| 1318 | 1005 | |
| 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 | |
| 1326 | pub 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 | ||
| 1335 | test "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 | 1006 | /// Returns whether `error_union` contains an error. |
| 1352 | 1007 | pub fn isError(error_union: anytype) bool { |
| 1353 | 1008 | return if (error_union) |_| false else |_| true; |
| ... | ... | @@ -1357,34 +1012,3 @@ test "isError" { |
| 1357 | 1012 | try std.testing.expect(isError(math.absInt(@as(i8, -128)))); |
| 1358 | 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. | |
| 1364 | pub 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 | ||
| 1381 | test "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 | 16 | pub const system = @import("zig/system.zig"); |
| 17 | 17 | pub const CrossTarget = @import("zig/cross_target.zig").CrossTarget; |
| 18 | 18 | |
| 19 | // Files needed by translate-c. | |
| 20 | pub const c_builtins = @import("zig/c_builtins.zig"); | |
| 21 | pub const c_translation = @import("zig/c_translation.zig"); | |
| 22 | ||
| 19 | 23 | pub const SrcHash = [16]u8; |
| 20 | 24 | |
| 21 | 25 | pub 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 | ||
| 7 | const std = @import("std"); | |
| 8 | ||
| 9 | pub inline fn __builtin_bswap16(val: u16) u16 { | |
| 10 | return @byteSwap(u16, val); | |
| 11 | } | |
| 12 | pub inline fn __builtin_bswap32(val: u32) u32 { | |
| 13 | return @byteSwap(u32, val); | |
| 14 | } | |
| 15 | pub inline fn __builtin_bswap64(val: u64) u64 { | |
| 16 | return @byteSwap(u64, val); | |
| 17 | } | |
| 18 | ||
| 19 | pub inline fn __builtin_signbit(val: f64) c_int { | |
| 20 | return @boolToInt(std.math.signbit(val)); | |
| 21 | } | |
| 22 | pub inline fn __builtin_signbitf(val: f32) c_int { | |
| 23 | return @boolToInt(std.math.signbit(val)); | |
| 24 | } | |
| 25 | ||
| 26 | pub 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 | } | |
| 31 | pub 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 | } | |
| 37 | pub 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 | ||
| 44 | pub inline fn __builtin_sqrt(val: f64) f64 { | |
| 45 | return @sqrt(val); | |
| 46 | } | |
| 47 | pub inline fn __builtin_sqrtf(val: f32) f32 { | |
| 48 | return @sqrt(val); | |
| 49 | } | |
| 50 | ||
| 51 | pub inline fn __builtin_sin(val: f64) f64 { | |
| 52 | return @sin(val); | |
| 53 | } | |
| 54 | pub inline fn __builtin_sinf(val: f32) f32 { | |
| 55 | return @sin(val); | |
| 56 | } | |
| 57 | pub inline fn __builtin_cos(val: f64) f64 { | |
| 58 | return @cos(val); | |
| 59 | } | |
| 60 | pub inline fn __builtin_cosf(val: f32) f32 { | |
| 61 | return @cos(val); | |
| 62 | } | |
| 63 | ||
| 64 | pub inline fn __builtin_exp(val: f64) f64 { | |
| 65 | return @exp(val); | |
| 66 | } | |
| 67 | pub inline fn __builtin_expf(val: f32) f32 { | |
| 68 | return @exp(val); | |
| 69 | } | |
| 70 | pub inline fn __builtin_exp2(val: f64) f64 { | |
| 71 | return @exp2(val); | |
| 72 | } | |
| 73 | pub inline fn __builtin_exp2f(val: f32) f32 { | |
| 74 | return @exp2(val); | |
| 75 | } | |
| 76 | pub inline fn __builtin_log(val: f64) f64 { | |
| 77 | return @log(val); | |
| 78 | } | |
| 79 | pub inline fn __builtin_logf(val: f32) f32 { | |
| 80 | return @log(val); | |
| 81 | } | |
| 82 | pub inline fn __builtin_log2(val: f64) f64 { | |
| 83 | return @log2(val); | |
| 84 | } | |
| 85 | pub inline fn __builtin_log2f(val: f32) f32 { | |
| 86 | return @log2(val); | |
| 87 | } | |
| 88 | pub inline fn __builtin_log10(val: f64) f64 { | |
| 89 | return @log10(val); | |
| 90 | } | |
| 91 | pub 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. | |
| 96 | pub inline fn __builtin_abs(val: c_int) c_int { | |
| 97 | return std.math.absInt(val) catch std.math.minInt(c_int); | |
| 98 | } | |
| 99 | pub inline fn __builtin_fabs(val: f64) f64 { | |
| 100 | return @fabs(val); | |
| 101 | } | |
| 102 | pub inline fn __builtin_fabsf(val: f32) f32 { | |
| 103 | return @fabs(val); | |
| 104 | } | |
| 105 | ||
| 106 | pub inline fn __builtin_floor(val: f64) f64 { | |
| 107 | return @floor(val); | |
| 108 | } | |
| 109 | pub inline fn __builtin_floorf(val: f32) f32 { | |
| 110 | return @floor(val); | |
| 111 | } | |
| 112 | pub inline fn __builtin_ceil(val: f64) f64 { | |
| 113 | return @ceil(val); | |
| 114 | } | |
| 115 | pub inline fn __builtin_ceilf(val: f32) f32 { | |
| 116 | return @ceil(val); | |
| 117 | } | |
| 118 | pub inline fn __builtin_trunc(val: f64) f64 { | |
| 119 | return @trunc(val); | |
| 120 | } | |
| 121 | pub inline fn __builtin_truncf(val: f32) f32 { | |
| 122 | return @trunc(val); | |
| 123 | } | |
| 124 | pub inline fn __builtin_round(val: f64) f64 { | |
| 125 | return @round(val); | |
| 126 | } | |
| 127 | pub inline fn __builtin_roundf(val: f32) f32 { | |
| 128 | return @round(val); | |
| 129 | } | |
| 130 | ||
| 131 | pub inline fn __builtin_strlen(s: [*c]const u8) usize { | |
| 132 | return std.mem.lenZ(s); | |
| 133 | } | |
| 134 | pub 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 | ||
| 138 | pub 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 | ||
| 148 | pub 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 | ||
| 158 | pub 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 | ||
| 164 | pub 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 | ||
| 174 | pub 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. | |
| 188 | pub 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 | ||
| 7 | const std = @import("std"); | |
| 8 | const testing = std.testing; | |
| 9 | const math = std.math; | |
| 10 | const mem = std.mem; | |
| 11 | ||
| 12 | /// Given a type and value, cast the value to the type as c would. | |
| 13 | pub 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 | ||
| 53 | fn 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 | ||
| 63 | fn 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 | ||
| 76 | fn 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 | ||
| 100 | fn 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 | ||
| 108 | test "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. | |
| 162 | pub 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 | ||
| 230 | test "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 | ||
| 275 | pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal }; | |
| 276 | ||
| 277 | fn 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. | |
| 300 | pub 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 | ||
| 308 | test "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 | |
| 332 | pub 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 | ||
| 341 | test "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. | |
| 359 | pub 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 | ||
| 376 | test "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 | 12 | const ast = @import("translate_c/ast.zig"); |
| 13 | 13 | const Node = ast.Node; |
| 14 | 14 | const Tag = Node.Tag; |
| 15 | const c_builtins = std.c.builtins; | |
| 16 | 15 | |
| 17 | 16 | const CallingConvention = std.builtin.CallingConvention; |
| 18 | 17 | |
| ... | ... | @@ -863,7 +862,7 @@ fn buildFlexibleArrayFn( |
| 863 | 862 | defer block_scope.deinit(); |
| 864 | 863 | |
| 865 | 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 | 866 | const intermediate_type_decl = try Tag.var_simple.create(c.arena, .{ |
| 868 | 867 | .name = intermediate_type_name, |
| 869 | 868 | .init = intermediate_type, |
| ... | ... | @@ -872,7 +871,7 @@ fn buildFlexibleArrayFn( |
| 872 | 871 | const intermediate_type_ident = try Tag.identifier.create(c.arena, intermediate_type_name); |
| 873 | 872 | |
| 874 | 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 | 875 | const return_type_decl = try Tag.var_simple.create(c.arena, .{ |
| 877 | 876 | .name = return_type_name, |
| 878 | 877 | .init = return_type, |
| ... | ... | @@ -1290,9 +1289,19 @@ fn transStmt( |
| 1290 | 1289 | return maybeSuppressResult(c, scope, result_used, shuffle_vec_node); |
| 1291 | 1290 | }, |
| 1292 | 1291 | // When adding new cases here, see comment for maybeBlockify() |
| 1293 | else => { | |
| 1294 | return fail(c, error.UnsupportedTranslation, stmt.getBeginLoc(), "TODO implement translation of stmt class {s}", .{@tagName(sc)}); | |
| 1295 | }, | |
| 1292 | .GCCAsmStmtClass, | |
| 1293 | .GotoStmtClass, | |
| 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 | } |
| 1298 | 1307 | |
| ... | ... | @@ -1374,7 +1383,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE |
| 1374 | 1383 | |
| 1375 | 1384 | for (init_list) |*init, i| { |
| 1376 | 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 | 1387 | init.* = converted_index; |
| 1379 | 1388 | } |
| 1380 | 1389 | |
| ... | ... | @@ -1820,13 +1829,10 @@ fn transDeclStmtOne( |
| 1820 | 1829 | .Function => { |
| 1821 | 1830 | try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl)); |
| 1822 | 1831 | }, |
| 1823 | else => |kind| return fail( | |
| 1824 | c, | |
| 1825 | error.UnsupportedTranslation, | |
| 1826 | decl.getLocation(), | |
| 1827 | "TODO implement translation of DeclStmt kind {s}", | |
| 1828 | .{@tagName(kind)}, | |
| 1829 | ), | |
| 1832 | else => { | |
| 1833 | const decl_name = try c.str(decl.getDeclKindName()); | |
| 1834 | try warn(c, &c.global_scope.base, decl.getLocation(), "ignoring {s} declaration", .{decl_name}); | |
| 1835 | }, | |
| 1830 | 1836 | } |
| 1831 | 1837 | } |
| 1832 | 1838 | |
| ... | ... | @@ -1902,7 +1908,7 @@ fn transImplicitCastExpr( |
| 1902 | 1908 | const ne = try Tag.not_equal.create(c.arena, .{ .lhs = ptr_to_int, .rhs = Tag.zero_literal.init() }); |
| 1903 | 1909 | return maybeSuppressResult(c, scope, result_used, ne); |
| 1904 | 1910 | }, |
| 1905 | .IntegralToBoolean => { | |
| 1911 | .IntegralToBoolean, .FloatingToBoolean => { | |
| 1906 | 1912 | const sub_expr_node = try transExpr(c, scope, sub_expr, .used); |
| 1907 | 1913 | |
| 1908 | 1914 | // The expression is already a boolean one, return it as-is |
| ... | ... | @@ -1924,14 +1930,14 @@ fn transImplicitCastExpr( |
| 1924 | 1930 | c, |
| 1925 | 1931 | error.UnsupportedTranslation, |
| 1926 | 1932 | @ptrCast(*const clang.Stmt, expr).getBeginLoc(), |
| 1927 | "TODO implement translation of CastKind {s}", | |
| 1933 | "unsupported CastKind {s}", | |
| 1928 | 1934 | .{@tagName(kind)}, |
| 1929 | 1935 | ), |
| 1930 | 1936 | } |
| 1931 | 1937 | } |
| 1932 | 1938 | |
| 1933 | 1939 | fn isBuiltinDefined(name: []const u8) bool { |
| 1934 | inline for (meta.declarations(c_builtins)) |decl| { | |
| 1940 | inline for (meta.declarations(std.zig.c_builtins)) |decl| { | |
| 1935 | 1941 | if (std.mem.eql(u8, name, decl.name)) return true; |
| 1936 | 1942 | } |
| 1937 | 1943 | return false; |
| ... | ... | @@ -2358,8 +2364,10 @@ fn transCCast( |
| 2358 | 2364 | return Tag.float_to_int.create(c.arena, .{ .lhs = dst_node, .rhs = expr }); |
| 2359 | 2365 | } |
| 2360 | 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 | 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 | 2372 | if (qualTypeIsBoolean(src_type) and !qualTypeIsBoolean(dst_type)) { |
| 2365 | 2373 | // @boolToInt returns either a comptime_int or a u1 |
| ... | ... | @@ -2370,7 +2378,7 @@ fn transCCast( |
| 2370 | 2378 | } |
| 2371 | 2379 | if (cIsEnum(dst_type)) { |
| 2372 | 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 | 2383 | if (cIsEnum(src_type) and !cIsEnum(dst_type)) { |
| 2376 | 2384 | // @enumToInt(val) |
| ... | ... | @@ -4547,6 +4555,10 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan |
| 4547 | 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 | 4562 | else => { |
| 4551 | 4563 | const type_name = c.str(ty.getTypeClassName()); |
| 4552 | 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 | 4994 | break :blk br.data.val; |
| 4983 | 4995 | } else expr; |
| 4984 | 4996 | |
| 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 | 4998 | some.data.lhs |
| 4987 | 4999 | else if (typeof_arg.castTag(.std_mem_zeroes)) |some| |
| 4988 | 5000 | some.data |
| ... | ... | @@ -5095,7 +5107,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { |
| 5095 | 5107 | if (guaranteed_to_fit) { |
| 5096 | 5108 | return Tag.as.create(c.arena, .{ .lhs = type_node, .rhs = literal_node }); |
| 5097 | 5109 | } else { |
| 5098 | return Tag.std_meta_promoteIntLiteral.create(c.arena, .{ | |
| 5110 | return Tag.helpers_promoteIntLiteral.create(c.arena, .{ | |
| 5099 | 5111 | .type = type_node, |
| 5100 | 5112 | .value = literal_node, |
| 5101 | 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 | 5590 | return parseCPostfixExpr(c, m, scope, type_name); |
| 5579 | 5591 | } |
| 5580 | 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 | 5596 | else => {}, |
| ... | ... | @@ -5925,7 +5937,7 @@ fn parseCUnaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node { |
| 5925 | 5937 | break :blk inner; |
| 5926 | 5938 | } else try parseCUnaryExpr(c, m, scope); |
| 5927 | 5939 | |
| 5928 | return Tag.std_meta_sizeof.create(c.arena, operand); | |
| 5940 | return Tag.helpers_sizeof.create(c.arena, operand); | |
| 5929 | 5941 | }, |
| 5930 | 5942 | .Keyword_alignof => { |
| 5931 | 5943 | // 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 | 74 | tuple, |
| 75 | 75 | container_init, |
| 76 | 76 | container_init_dot, |
| 77 | std_meta_cast, | |
| 77 | helpers_cast, | |
| 78 | 78 | /// _ = operand; |
| 79 | 79 | discard, |
| 80 | 80 | |
| ... | ... | @@ -124,8 +124,8 @@ pub const Node = extern union { |
| 124 | 124 | std_math_Log2Int, |
| 125 | 125 | /// @intCast(lhs, rhs) |
| 126 | 126 | int_cast, |
| 127 | /// @import("std").meta.promoteIntLiteral(value, type, radix) | |
| 128 | std_meta_promoteIntLiteral, | |
| 127 | /// @import("std").zig.c_translation.promoteIntLiteral(value, type, radix) | |
| 128 | helpers_promoteIntLiteral, | |
| 129 | 129 | /// @import("std").meta.alignment(value) |
| 130 | 130 | std_meta_alignment, |
| 131 | 131 | /// @rem(lhs, rhs) |
| ... | ... | @@ -193,12 +193,12 @@ pub const Node = extern union { |
| 193 | 193 | array_type, |
| 194 | 194 | null_sentinel_array_type, |
| 195 | 195 | |
| 196 | /// @import("std").meta.sizeof(operand) | |
| 197 | std_meta_sizeof, | |
| 198 | /// @import("std").meta.FlexibleArrayType(lhs, rhs) | |
| 199 | std_meta_flexible_array_type, | |
| 200 | /// @import("std").meta.shuffleVectorIndex(lhs, rhs) | |
| 201 | std_meta_shuffle_vector_index, | |
| 196 | /// @import("std").zig.c_translation.sizeof(operand) | |
| 197 | helpers_sizeof, | |
| 198 | /// @import("std").zig.c_translation.FlexibleArrayType(lhs, rhs) | |
| 199 | helpers_flexible_array_type, | |
| 200 | /// @import("std").zig.c_translation.shuffleVectorIndex(lhs, rhs) | |
| 201 | helpers_shuffle_vector_index, | |
| 202 | 202 | /// @import("std").meta.Vector(lhs, rhs) |
| 203 | 203 | std_meta_vector, |
| 204 | 204 | /// @import("std").mem.zeroes(operand) |
| ... | ... | @@ -272,7 +272,7 @@ pub const Node = extern union { |
| 272 | 272 | .if_not_break, |
| 273 | 273 | .switch_else, |
| 274 | 274 | .block_single, |
| 275 | .std_meta_sizeof, | |
| 275 | .helpers_sizeof, | |
| 276 | 276 | .std_meta_alignment, |
| 277 | 277 | .bool_to_int, |
| 278 | 278 | .sizeof, |
| ... | ... | @@ -332,13 +332,13 @@ pub const Node = extern union { |
| 332 | 332 | .align_cast, |
| 333 | 333 | .array_access, |
| 334 | 334 | .std_mem_zeroinit, |
| 335 | .std_meta_flexible_array_type, | |
| 336 | .std_meta_shuffle_vector_index, | |
| 335 | .helpers_flexible_array_type, | |
| 336 | .helpers_shuffle_vector_index, | |
| 337 | 337 | .std_meta_vector, |
| 338 | 338 | .ptr_cast, |
| 339 | 339 | .div_exact, |
| 340 | 340 | .offset_of, |
| 341 | .std_meta_cast, | |
| 341 | .helpers_cast, | |
| 342 | 342 | => Payload.BinOp, |
| 343 | 343 | |
| 344 | 344 | .integer_literal, |
| ... | ... | @@ -362,7 +362,7 @@ pub const Node = extern union { |
| 362 | 362 | .tuple => Payload.TupleInit, |
| 363 | 363 | .container_init => Payload.ContainerInit, |
| 364 | 364 | .container_init_dot => Payload.ContainerInitDot, |
| 365 | .std_meta_promoteIntLiteral => Payload.PromoteIntLiteral, | |
| 365 | .helpers_promoteIntLiteral => Payload.PromoteIntLiteral, | |
| 366 | 366 | .block => Payload.Block, |
| 367 | 367 | .c_pointer, .single_pointer => Payload.Pointer, |
| 368 | 368 | .array_type, .null_sentinel_array_type => Payload.Array, |
| ... | ... | @@ -868,7 +868,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 868 | 868 | // pub usingnamespace @import("std").c.builtins; |
| 869 | 869 | _ = try c.addToken(.keyword_pub, "pub"); |
| 870 | 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 | 872 | _ = try c.addToken(.semicolon, ";"); |
| 873 | 873 | |
| 874 | 874 | return c.addNode(.{ |
| ... | ... | @@ -882,52 +882,52 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 882 | 882 | }, |
| 883 | 883 | .std_math_Log2Int => { |
| 884 | 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 | 886 | return renderCall(c, import_node, &.{payload}); |
| 887 | 887 | }, |
| 888 | .std_meta_cast => { | |
| 889 | const payload = node.castTag(.std_meta_cast).?.data; | |
| 890 | const import_node = try renderStdImport(c, "meta", "cast"); | |
| 888 | .helpers_cast => { | |
| 889 | const payload = node.castTag(.helpers_cast).?.data; | |
| 890 | const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "cast" }); | |
| 891 | 891 | return renderCall(c, import_node, &.{ payload.lhs, payload.rhs }); |
| 892 | 892 | }, |
| 893 | .std_meta_promoteIntLiteral => { | |
| 894 | const payload = node.castTag(.std_meta_promoteIntLiteral).?.data; | |
| 895 | const import_node = try renderStdImport(c, "meta", "promoteIntLiteral"); | |
| 893 | .helpers_promoteIntLiteral => { | |
| 894 | const payload = node.castTag(.helpers_promoteIntLiteral).?.data; | |
| 895 | const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "promoteIntLiteral" }); | |
| 896 | 896 | return renderCall(c, import_node, &.{ payload.type, payload.value, payload.radix }); |
| 897 | 897 | }, |
| 898 | 898 | .std_meta_alignment => { |
| 899 | 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 | 901 | return renderCall(c, import_node, &.{payload}); |
| 902 | 902 | }, |
| 903 | .std_meta_sizeof => { | |
| 904 | const payload = node.castTag(.std_meta_sizeof).?.data; | |
| 905 | const import_node = try renderStdImport(c, "meta", "sizeof"); | |
| 903 | .helpers_sizeof => { | |
| 904 | const payload = node.castTag(.helpers_sizeof).?.data; | |
| 905 | const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "sizeof" }); | |
| 906 | 906 | return renderCall(c, import_node, &.{payload}); |
| 907 | 907 | }, |
| 908 | 908 | .std_mem_zeroes => { |
| 909 | 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 | 911 | return renderCall(c, import_node, &.{payload}); |
| 912 | 912 | }, |
| 913 | 913 | .std_mem_zeroinit => { |
| 914 | 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 | 916 | return renderCall(c, import_node, &.{ payload.lhs, payload.rhs }); |
| 917 | 917 | }, |
| 918 | .std_meta_flexible_array_type => { | |
| 919 | const payload = node.castTag(.std_meta_flexible_array_type).?.data; | |
| 920 | const import_node = try renderStdImport(c, "meta", "FlexibleArrayType"); | |
| 918 | .helpers_flexible_array_type => { | |
| 919 | const payload = node.castTag(.helpers_flexible_array_type).?.data; | |
| 920 | const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "FlexibleArrayType" }); | |
| 921 | 921 | return renderCall(c, import_node, &.{ payload.lhs, payload.rhs }); |
| 922 | 922 | }, |
| 923 | .std_meta_shuffle_vector_index => { | |
| 924 | const payload = node.castTag(.std_meta_shuffle_vector_index).?.data; | |
| 925 | const import_node = try renderStdImport(c, "meta", "shuffleVectorIndex"); | |
| 923 | .helpers_shuffle_vector_index => { | |
| 924 | const payload = node.castTag(.helpers_shuffle_vector_index).?.data; | |
| 925 | const import_node = try renderStdImport(c, &.{ "zig", "c_translation", "shuffleVectorIndex" }); | |
| 926 | 926 | return renderCall(c, import_node, &.{ payload.lhs, payload.rhs }); |
| 927 | 927 | }, |
| 928 | 928 | .std_meta_vector => { |
| 929 | 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 | 931 | return renderCall(c, import_node, &.{ payload.lhs, payload.rhs }); |
| 932 | 932 | }, |
| 933 | 933 | .call => { |
| ... | ... | @@ -2269,13 +2269,13 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex { |
| 2269 | 2269 | .alignof, |
| 2270 | 2270 | .typeof, |
| 2271 | 2271 | .typeinfo, |
| 2272 | .std_meta_sizeof, | |
| 2273 | 2272 | .std_meta_alignment, |
| 2274 | .std_meta_cast, | |
| 2275 | .std_meta_promoteIntLiteral, | |
| 2276 | 2273 | .std_meta_vector, |
| 2277 | .std_meta_shuffle_vector_index, | |
| 2278 | .std_meta_flexible_array_type, | |
| 2274 | .helpers_sizeof, | |
| 2275 | .helpers_cast, | |
| 2276 | .helpers_promoteIntLiteral, | |
| 2277 | .helpers_shuffle_vector_index, | |
| 2278 | .helpers_flexible_array_type, | |
| 2279 | 2279 | .std_mem_zeroinit, |
| 2280 | 2280 | .integer_literal, |
| 2281 | 2281 | .float_literal, |
| ... | ... | @@ -2442,7 +2442,7 @@ fn renderBinOp(c: *Context, node: Node, tag: std.zig.ast.Node.Tag, tok_tag: Toke |
| 2442 | 2442 | }); |
| 2443 | 2443 | } |
| 2444 | 2444 | |
| 2445 | fn renderStdImport(c: *Context, first: []const u8, second: []const u8) !NodeIndex { | |
| 2445 | fn renderStdImport(c: *Context, parts: []const []const u8) !NodeIndex { | |
| 2446 | 2446 | const import_tok = try c.addToken(.builtin, "@import"); |
| 2447 | 2447 | _ = try c.addToken(.l_paren, "("); |
| 2448 | 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 | 2463 | }); |
| 2464 | 2464 | |
| 2465 | 2465 | var access_chain = import_node; |
| 2466 | access_chain = try renderFieldAccess(c, access_chain, first); | |
| 2467 | access_chain = try renderFieldAccess(c, access_chain, second); | |
| 2466 | for (parts) |part| { | |
| 2467 | access_chain = try renderFieldAccess(c, access_chain, part); | |
| 2468 | } | |
| 2468 | 2469 | return access_chain; |
| 2469 | 2470 | } |
| 2470 | 2471 |
test/translate_c.zig+33-33| ... | ... | @@ -133,7 +133,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 133 | 133 | \\ const A = @enumToInt(enum_Foo.A); |
| 134 | 134 | \\ const B = @enumToInt(enum_Foo.B); |
| 135 | 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 | 138 | \\ const enum_Foo = extern enum( |
| 139 | 139 | ++ default_enum_type ++ |
| ... | ... | @@ -146,7 +146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 146 | 146 | \\ const A_2 = @enumToInt(enum_Foo.A); |
| 147 | 147 | \\ const B_3 = @enumToInt(enum_Foo.B); |
| 148 | 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 | 242 | \\#define MEM_PHYSICAL_TO_K0(x) (void*)((uint32_t)(x) + SYS_BASE_CACHED) |
| 243 | 243 | , &[_][]const u8{ |
| 244 | 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 | }); |
| 248 | 248 | |
| ... | ... | @@ -282,8 +282,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 282 | 282 | , |
| 283 | 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))) { | |
| 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)); | |
| 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").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 | }); |
| 289 | 289 | |
| ... | ... | @@ -438,17 +438,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 438 | 438 | , &[_][]const u8{ |
| 439 | 439 | \\pub const struct_foo = extern struct { |
| 440 | 440 | \\ x: c_int align(4), |
| 441 | \\ pub fn y(self: anytype) @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int) { | |
| 442 | \\ const Intermediate = @import("std").meta.FlexibleArrayType(@TypeOf(self), u8); | |
| 443 | \\ const ReturnType = @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").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); | |
| 443 | \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int); | |
| 444 | 444 | \\ return @ptrCast(ReturnType, @alignCast(@alignOf(c_int), @ptrCast(Intermediate, self) + 4)); |
| 445 | 445 | \\ } |
| 446 | 446 | \\}; |
| 447 | 447 | \\pub const struct_bar = extern struct { |
| 448 | 448 | \\ x: c_int align(4), |
| 449 | \\ pub fn y(self: anytype) @import("std").meta.FlexibleArrayType(@TypeOf(self), c_int) { | |
| 450 | \\ const Intermediate = @import("std").meta.FlexibleArrayType(@TypeOf(self), u8); | |
| 451 | \\ const ReturnType = @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").zig.c_translation.FlexibleArrayType(@TypeOf(self), u8); | |
| 451 | \\ const ReturnType = @import("std").zig.c_translation.FlexibleArrayType(@TypeOf(self), c_int); | |
| 452 | 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 | 583 | cases.add("#define hex literal with capital X", |
| 584 | 584 | \\#define VAL 0XF00D |
| 585 | 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 | }); |
| 588 | 588 | |
| 589 | 589 | cases.add("anonymous struct & unions", |
| ... | ... | @@ -1738,7 +1738,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1738 | 1738 | \\pub const e = @enumToInt(enum_unnamed_1.e); |
| 1739 | 1739 | \\pub const f = @enumToInt(enum_unnamed_1.f); |
| 1740 | 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 | 1742 | \\const enum_unnamed_2 = extern enum( |
| 1743 | 1743 | ++ default_enum_type ++ |
| 1744 | 1744 | \\) { |
| ... | ... | @@ -1882,7 +1882,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1882 | 1882 | \\typedef struct { int dummy; } NRF_GPIO_Type; |
| 1883 | 1883 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1884 | 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 | }); |
| 1887 | 1887 | |
| 1888 | 1888 | cases.add("basic macro function", |
| ... | ... | @@ -2379,7 +2379,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2379 | 2379 | \\ var a = arg_a; |
| 2380 | 2380 | \\ var b = arg_b; |
| 2381 | 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 | 2383 | \\ var e: c_int = @boolToInt((a != 0) and (b != 0)); |
| 2384 | 2384 | \\ var f: c_int = @boolToInt((b != 0) and (c != null)); |
| 2385 | 2385 | \\ var g: c_int = @boolToInt((a != 0) and (c != null)); |
| ... | ... | @@ -3182,13 +3182,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3182 | 3182 | \\#define BAR (void*) a |
| 3183 | 3183 | \\#define BAZ (uint32_t)(2) |
| 3184 | 3184 | , &[_][]const u8{ |
| 3185 | \\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").meta.cast(?*c_void, baz))) { | |
| 3186 | \\ return 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").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 | }); |
| 3193 | 3193 | |
| 3194 | 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 | 3196 | \\#define CURLAUTH_BASIC ((unsigned long) 1) |
| 3197 | 3197 | \\#define CURLAUTH_BASIC_BUT_ULONGLONG ((unsigned long long) 1) |
| 3198 | 3198 | , &[_][]const u8{ |
| 3199 | \\pub const CURLAUTH_BASIC_BUT_USHORT = @import("std").meta.cast(c_ushort, @as(c_int, 1)); | |
| 3200 | \\pub const CURLAUTH_BASIC = @import("std").meta.cast(c_ulong, @as(c_int, 1)); | |
| 3201 | \\pub const CURLAUTH_BASIC_BUT_ULONGLONG = @import("std").meta.cast(c_ulonglong, @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").zig.c_translation.cast(c_ulong, @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 | }); |
| 3203 | 3203 | |
| 3204 | 3204 | cases.add("macro conditional operator", |
| ... | ... | @@ -3413,8 +3413,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3413 | 3413 | \\#define DefaultScreen(dpy) (((_XPrivDisplay)(dpy))->default_screen) |
| 3414 | 3414 | \\ |
| 3415 | 3415 | , &[_][]const u8{ |
| 3416 | \\pub inline fn DefaultScreen(dpy: anytype) @TypeOf(@import("std").meta.cast(_XPrivDisplay, dpy).*.default_screen) { | |
| 3417 | \\ return @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").zig.c_translation.cast(_XPrivDisplay, dpy).*.default_screen; | |
| 3418 | 3418 | \\} |
| 3419 | 3419 | }); |
| 3420 | 3420 | |
| ... | ... | @@ -3422,9 +3422,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3422 | 3422 | \\#define NULL ((void*)0) |
| 3423 | 3423 | \\#define FOO ((int)0x8000) |
| 3424 | 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 | }); |
| 3429 | 3429 | |
| 3430 | 3430 | if (std.Target.current.abi == .msvc) { |
| ... | ... | @@ -3503,11 +3503,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3503 | 3503 | \\pub const GUARANTEED_TO_FIT_1 = @as(c_int, 1024); |
| 3504 | 3504 | \\pub const GUARANTEED_TO_FIT_2 = @as(c_long, 10241024); |
| 3505 | 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); | |
| 3507 | \\pub const MAY_NEED_PROMOTION_2 = @import("std").meta.promoteIntLiteral(c_long, 307230723072, .decimal); | |
| 3508 | \\pub const MAY_NEED_PROMOTION_3 = @import("std").meta.promoteIntLiteral(c_ulong, 819281928192, .decimal); | |
| 3509 | \\pub const MAY_NEED_PROMOTION_HEX = @import("std").meta.promoteIntLiteral(c_int, 0x80000000, .hexadecimal); | |
| 3510 | \\pub const MAY_NEED_PROMOTION_OCT = @import("std").meta.promoteIntLiteral(c_int, 0o20000000000, .octal); | |
| 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").zig.c_translation.promoteIntLiteral(c_long, 307230723072, .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").zig.c_translation.promoteIntLiteral(c_int, 0x80000000, .hexadecimal); | |
| 3510 | \\pub const MAY_NEED_PROMOTION_OCT = @import("std").zig.c_translation.promoteIntLiteral(c_int, 0o20000000000, .octal); | |
| 3511 | 3511 | }); |
| 3512 | 3512 | |
| 3513 | 3513 | // See __builtin_alloca_with_align comment in std.c.builtins |
| ... | ... | @@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3642 | 3642 | \\typedef long long LONG_PTR; |
| 3643 | 3643 | \\#define INVALID_HANDLE_VALUE ((void *)(LONG_PTR)-1) |
| 3644 | 3644 | , &[_][]const u8{ |
| 3645 | \\pub const MAP_FAILED = @import("std").meta.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))); | |
| 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").zig.c_translation.cast(?*c_void, @import("std").zig.c_translation.cast(LONG_PTR, -@as(c_int, 1))); | |
| 3647 | 3647 | }); |
| 3648 | 3648 | } |