| author | |
| committer | |
| log | 21aa55d34e432b677f71cbb377aa89c8cdbd1483 |
| tree | 87b831f51d09d923bfaf9f7a44477e50e773ae73 |
| parent | c7067ef6e823a0eaa87880e7a4b8bc89c0b31ab2 |
| parent | f5cf732659d1bf3112c828ef9798db445ff53f3c |
| signature |
cbe: enable CI for std tests38 files changed, 1339 insertions(+), 1189 deletions(-)
lib/std/Thread.zig+1-1| ... | @@ -1141,7 +1141,7 @@ test "setName, getName" { | ... | @@ -1141,7 +1141,7 @@ test "setName, getName" { |
| 1141 | thread.join(); | 1141 | thread.join(); |
| 1142 | } | 1142 | } |
| 1143 | 1143 | ||
| 1144 | test "std.Thread" { | 1144 | test { |
| 1145 | // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint. | 1145 | // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint. |
| 1146 | _ = Futex; | 1146 | _ = Futex; |
| 1147 | _ = ResetEvent; | 1147 | _ = ResetEvent; |
lib/std/atomic.zig+1-1| ... | @@ -7,7 +7,7 @@ pub const Stack = @import("atomic/stack.zig").Stack; | ... | @@ -7,7 +7,7 @@ pub const Stack = @import("atomic/stack.zig").Stack; |
| 7 | pub const Queue = @import("atomic/queue.zig").Queue; | 7 | pub const Queue = @import("atomic/queue.zig").Queue; |
| 8 | pub const Atomic = @import("atomic/Atomic.zig").Atomic; | 8 | pub const Atomic = @import("atomic/Atomic.zig").Atomic; |
| 9 | 9 | ||
| 10 | test "std.atomic" { | 10 | test { |
| 11 | _ = @import("atomic/stack.zig"); | 11 | _ = @import("atomic/stack.zig"); |
| 12 | _ = @import("atomic/queue.zig"); | 12 | _ = @import("atomic/queue.zig"); |
| 13 | _ = @import("atomic/Atomic.zig"); | 13 | _ = @import("atomic/Atomic.zig"); |
lib/std/bit_set.zig+2| ... | @@ -1635,6 +1635,8 @@ fn testStaticBitSet(comptime Set: type) !void { | ... | @@ -1635,6 +1635,8 @@ fn testStaticBitSet(comptime Set: type) !void { |
| 1635 | } | 1635 | } |
| 1636 | 1636 | ||
| 1637 | test "IntegerBitSet" { | 1637 | test "IntegerBitSet" { |
| 1638 | if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1639 | |||
| 1638 | try testStaticBitSet(IntegerBitSet(0)); | 1640 | try testStaticBitSet(IntegerBitSet(0)); |
| 1639 | try testStaticBitSet(IntegerBitSet(1)); | 1641 | try testStaticBitSet(IntegerBitSet(1)); |
| 1640 | try testStaticBitSet(IntegerBitSet(2)); | 1642 | try testStaticBitSet(IntegerBitSet(2)); |
lib/std/crypto/aes.zig+3-2| ... | @@ -5,9 +5,10 @@ const testing = std.testing; | ... | @@ -5,9 +5,10 @@ const testing = std.testing; |
| 5 | const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes); | 5 | const has_aesni = std.Target.x86.featureSetHas(builtin.cpu.features, .aes); |
| 6 | const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); | 6 | const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); |
| 7 | const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); | 7 | const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); |
| 8 | const impl = if (builtin.cpu.arch == .x86_64 and has_aesni and has_avx) impl: { | 8 | // C backend doesn't currently support passing vectors to inline asm. |
| 9 | const impl = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c and has_aesni and has_avx) impl: { | ||
| 9 | break :impl @import("aes/aesni.zig"); | 10 | break :impl @import("aes/aesni.zig"); |
| 10 | } else if (builtin.cpu.arch == .aarch64 and has_armaes) | 11 | } else if (builtin.cpu.arch == .aarch64 and builtin.zig_backend != .stage2_c and has_armaes) |
| 11 | impl: { | 12 | impl: { |
| 12 | break :impl @import("aes/armcrypto.zig"); | 13 | break :impl @import("aes/armcrypto.zig"); |
| 13 | } else impl: { | 14 | } else impl: { |
lib/std/crypto/aes_ocb.zig+8| ... | @@ -257,6 +257,8 @@ inline fn xorWith(x: *Block, y: Block) void { | ... | @@ -257,6 +257,8 @@ inline fn xorWith(x: *Block, y: Block) void { |
| 257 | const hexToBytes = std.fmt.hexToBytes; | 257 | const hexToBytes = std.fmt.hexToBytes; |
| 258 | 258 | ||
| 259 | test "AesOcb test vector 1" { | 259 | test "AesOcb test vector 1" { |
| 260 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 261 | |||
| 260 | var k: [Aes128Ocb.key_length]u8 = undefined; | 262 | var k: [Aes128Ocb.key_length]u8 = undefined; |
| 261 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; | 263 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; |
| 262 | var tag: [Aes128Ocb.tag_length]u8 = undefined; | 264 | var tag: [Aes128Ocb.tag_length]u8 = undefined; |
| ... | @@ -274,6 +276,8 @@ test "AesOcb test vector 1" { | ... | @@ -274,6 +276,8 @@ test "AesOcb test vector 1" { |
| 274 | } | 276 | } |
| 275 | 277 | ||
| 276 | test "AesOcb test vector 2" { | 278 | test "AesOcb test vector 2" { |
| 279 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 280 | |||
| 277 | var k: [Aes128Ocb.key_length]u8 = undefined; | 281 | var k: [Aes128Ocb.key_length]u8 = undefined; |
| 278 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; | 282 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; |
| 279 | var tag: [Aes128Ocb.tag_length]u8 = undefined; | 283 | var tag: [Aes128Ocb.tag_length]u8 = undefined; |
| ... | @@ -293,6 +297,8 @@ test "AesOcb test vector 2" { | ... | @@ -293,6 +297,8 @@ test "AesOcb test vector 2" { |
| 293 | } | 297 | } |
| 294 | 298 | ||
| 295 | test "AesOcb test vector 3" { | 299 | test "AesOcb test vector 3" { |
| 300 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 301 | |||
| 296 | var k: [Aes128Ocb.key_length]u8 = undefined; | 302 | var k: [Aes128Ocb.key_length]u8 = undefined; |
| 297 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; | 303 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; |
| 298 | var tag: [Aes128Ocb.tag_length]u8 = undefined; | 304 | var tag: [Aes128Ocb.tag_length]u8 = undefined; |
| ... | @@ -315,6 +321,8 @@ test "AesOcb test vector 3" { | ... | @@ -315,6 +321,8 @@ test "AesOcb test vector 3" { |
| 315 | } | 321 | } |
| 316 | 322 | ||
| 317 | test "AesOcb test vector 4" { | 323 | test "AesOcb test vector 4" { |
| 324 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 325 | |||
| 318 | var k: [Aes128Ocb.key_length]u8 = undefined; | 326 | var k: [Aes128Ocb.key_length]u8 = undefined; |
| 319 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; | 327 | var nonce: [Aes128Ocb.nonce_length]u8 = undefined; |
| 320 | var tag: [Aes128Ocb.tag_length]u8 = undefined; | 328 | var tag: [Aes128Ocb.tag_length]u8 = undefined; |
lib/std/crypto/ecdsa.zig+13| ... | @@ -1,3 +1,4 @@ | ... | @@ -1,3 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | ||
| 1 | const std = @import("std"); | 2 | const std = @import("std"); |
| 2 | const crypto = std.crypto; | 3 | const crypto = std.crypto; |
| 3 | const fmt = std.fmt; | 4 | const fmt = std.fmt; |
| ... | @@ -373,6 +374,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -373,6 +374,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 373 | } | 374 | } |
| 374 | 375 | ||
| 375 | test "ECDSA - Basic operations over EcdsaP384Sha384" { | 376 | test "ECDSA - Basic operations over EcdsaP384Sha384" { |
| 377 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 378 | |||
| 376 | const Scheme = EcdsaP384Sha384; | 379 | const Scheme = EcdsaP384Sha384; |
| 377 | const kp = try Scheme.KeyPair.create(null); | 380 | const kp = try Scheme.KeyPair.create(null); |
| 378 | const msg = "test"; | 381 | const msg = "test"; |
| ... | @@ -387,6 +390,8 @@ test "ECDSA - Basic operations over EcdsaP384Sha384" { | ... | @@ -387,6 +390,8 @@ test "ECDSA - Basic operations over EcdsaP384Sha384" { |
| 387 | } | 390 | } |
| 388 | 391 | ||
| 389 | test "ECDSA - Basic operations over Secp256k1" { | 392 | test "ECDSA - Basic operations over Secp256k1" { |
| 393 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 394 | |||
| 390 | const Scheme = EcdsaSecp256k1Sha256oSha256; | 395 | const Scheme = EcdsaSecp256k1Sha256oSha256; |
| 391 | const kp = try Scheme.KeyPair.create(null); | 396 | const kp = try Scheme.KeyPair.create(null); |
| 392 | const msg = "test"; | 397 | const msg = "test"; |
| ... | @@ -401,6 +406,8 @@ test "ECDSA - Basic operations over Secp256k1" { | ... | @@ -401,6 +406,8 @@ test "ECDSA - Basic operations over Secp256k1" { |
| 401 | } | 406 | } |
| 402 | 407 | ||
| 403 | test "ECDSA - Basic operations over EcdsaP384Sha256" { | 408 | test "ECDSA - Basic operations over EcdsaP384Sha256" { |
| 409 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 410 | |||
| 404 | const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); | 411 | const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); |
| 405 | const kp = try Scheme.KeyPair.create(null); | 412 | const kp = try Scheme.KeyPair.create(null); |
| 406 | const msg = "test"; | 413 | const msg = "test"; |
| ... | @@ -415,6 +422,8 @@ test "ECDSA - Basic operations over EcdsaP384Sha256" { | ... | @@ -415,6 +422,8 @@ test "ECDSA - Basic operations over EcdsaP384Sha256" { |
| 415 | } | 422 | } |
| 416 | 423 | ||
| 417 | test "ECDSA - Verifying a existing signature with EcdsaP384Sha256" { | 424 | test "ECDSA - Verifying a existing signature with EcdsaP384Sha256" { |
| 425 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 426 | |||
| 418 | const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); | 427 | const Scheme = Ecdsa(crypto.ecc.P384, crypto.hash.sha2.Sha256); |
| 419 | // zig fmt: off | 428 | // zig fmt: off |
| 420 | const sk_bytes = [_]u8{ | 429 | const sk_bytes = [_]u8{ |
| ... | @@ -457,6 +466,8 @@ const TestVector = struct { | ... | @@ -457,6 +466,8 @@ const TestVector = struct { |
| 457 | }; | 466 | }; |
| 458 | 467 | ||
| 459 | test "ECDSA - Test vectors from Project Wycheproof" { | 468 | test "ECDSA - Test vectors from Project Wycheproof" { |
| 469 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 470 | |||
| 460 | const vectors = [_]TestVector{ | 471 | const vectors = [_]TestVector{ |
| 461 | .{ .key = "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e", .msg = "313233343030", .sig = "304402202ba3a8be6b94d5ec80a6d9d1190a436effe50d85a1eee859b8cc6af9bd5c2e1802204cd60b855d442f5b3c7b11eb6c4e0ae7525fe710fab9aa7c77a67f79e6fadd76", .result = .valid }, | 472 | .{ .key = "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e", .msg = "313233343030", .sig = "304402202ba3a8be6b94d5ec80a6d9d1190a436effe50d85a1eee859b8cc6af9bd5c2e1802204cd60b855d442f5b3c7b11eb6c4e0ae7525fe710fab9aa7c77a67f79e6fadd76", .result = .valid }, |
| 462 | .{ .key = "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e", .msg = "313233343030", .sig = "304402202ba3a8be6b94d5ec80a6d9d1190a436effe50d85a1eee859b8cc6af9bd5c2e180220b329f479a2bbd0a5c384ee1493b1f5186a87139cac5df4087c134b49156847db", .result = .acceptable }, | 473 | .{ .key = "042927b10512bae3eddcfe467828128bad2903269919f7086069c8c4df6c732838c7787964eaac00e5921fb1498a60f4606766b3d9685001558d1a974e7341513e", .msg = "313233343030", .sig = "304402202ba3a8be6b94d5ec80a6d9d1190a436effe50d85a1eee859b8cc6af9bd5c2e180220b329f479a2bbd0a5c384ee1493b1f5186a87139cac5df4087c134b49156847db", .result = .acceptable }, |
| ... | @@ -869,6 +880,8 @@ fn tvTry(vector: TestVector) !void { | ... | @@ -869,6 +880,8 @@ fn tvTry(vector: TestVector) !void { |
| 869 | } | 880 | } |
| 870 | 881 | ||
| 871 | test "ECDSA - Sec1 encoding/decoding" { | 882 | test "ECDSA - Sec1 encoding/decoding" { |
| 883 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 884 | |||
| 872 | const Scheme = EcdsaP384Sha384; | 885 | const Scheme = EcdsaP384Sha384; |
| 873 | const kp = try Scheme.KeyPair.create(null); | 886 | const kp = try Scheme.KeyPair.create(null); |
| 874 | const pk = kp.public_key; | 887 | const pk = kp.public_key; |
lib/std/crypto/ghash_polyval.zig+3-2| ... | @@ -248,9 +248,10 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -248,9 +248,10 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 248 | const has_pclmul = std.Target.x86.featureSetHas(builtin.cpu.features, .pclmul); | 248 | const has_pclmul = std.Target.x86.featureSetHas(builtin.cpu.features, .pclmul); |
| 249 | const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); | 249 | const has_avx = std.Target.x86.featureSetHas(builtin.cpu.features, .avx); |
| 250 | const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); | 250 | const has_armaes = std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes); |
| 251 | const clmul = if (builtin.cpu.arch == .x86_64 and has_pclmul and has_avx) impl: { | 251 | // C backend doesn't currently support passing vectors to inline asm. |
| 252 | const clmul = if (builtin.cpu.arch == .x86_64 and builtin.zig_backend != .stage2_c and has_pclmul and has_avx) impl: { | ||
| 252 | break :impl clmulPclmul; | 253 | break :impl clmulPclmul; |
| 253 | } else if (builtin.cpu.arch == .aarch64 and has_armaes) impl: { | 254 | } else if (builtin.cpu.arch == .aarch64 and builtin.zig_backend != .stage2_c and has_armaes) impl: { |
| 254 | break :impl clmulPmull; | 255 | break :impl clmulPmull; |
| 255 | } else impl: { | 256 | } else impl: { |
| 256 | break :impl clmulSoft; | 257 | break :impl clmulSoft; |
lib/std/crypto/pcurves/p256.zig+1-1| ... | @@ -473,6 +473,6 @@ pub const AffineCoordinates = struct { | ... | @@ -473,6 +473,6 @@ pub const AffineCoordinates = struct { |
| 473 | } | 473 | } |
| 474 | }; | 474 | }; |
| 475 | 475 | ||
| 476 | test "p256" { | 476 | test { |
| 477 | _ = @import("tests/p256.zig"); | 477 | _ = @import("tests/p256.zig"); |
| 478 | } | 478 | } |
lib/std/crypto/pcurves/p384.zig+3-1| ... | @@ -473,6 +473,8 @@ pub const AffineCoordinates = struct { | ... | @@ -473,6 +473,8 @@ pub const AffineCoordinates = struct { |
| 473 | } | 473 | } |
| 474 | }; | 474 | }; |
| 475 | 475 | ||
| 476 | test "p384" { | 476 | test { |
| 477 | if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 478 | |||
| 477 | _ = @import("tests/p384.zig"); | 479 | _ = @import("tests/p384.zig"); |
| 478 | } | 480 | } |
lib/std/crypto/pcurves/secp256k1.zig+3-1| ... | @@ -551,6 +551,8 @@ pub const AffineCoordinates = struct { | ... | @@ -551,6 +551,8 @@ pub const AffineCoordinates = struct { |
| 551 | } | 551 | } |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | test "secp256k1" { | 554 | test { |
| 555 | if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 556 | |||
| 555 | _ = @import("tests/secp256k1.zig"); | 557 | _ = @import("tests/secp256k1.zig"); |
| 556 | } | 558 | } |
lib/std/crypto/sha2.zig+3-2| ... | @@ -205,7 +205,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -205,7 +205,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 205 | 205 | ||
| 206 | if (!isComptime()) { | 206 | if (!isComptime()) { |
| 207 | switch (builtin.cpu.arch) { | 207 | switch (builtin.cpu.arch) { |
| 208 | .aarch64 => if (comptime std.Target.aarch64.featureSetHas(builtin.cpu.features, .sha2)) { | 208 | .aarch64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.aarch64.featureSetHas(builtin.cpu.features, .sha2)) { |
| 209 | var x: v4u32 = d.s[0..4].*; | 209 | var x: v4u32 = d.s[0..4].*; |
| 210 | var y: v4u32 = d.s[4..8].*; | 210 | var y: v4u32 = d.s[4..8].*; |
| 211 | const s_v = @ptrCast(*[16]v4u32, &s); | 211 | const s_v = @ptrCast(*[16]v4u32, &s); |
| ... | @@ -242,7 +242,8 @@ fn Sha2x32(comptime params: Sha2Params32) type { | ... | @@ -242,7 +242,8 @@ fn Sha2x32(comptime params: Sha2Params32) type { |
| 242 | d.s[4..8].* = y +% @as(v4u32, d.s[4..8].*); | 242 | d.s[4..8].* = y +% @as(v4u32, d.s[4..8].*); |
| 243 | return; | 243 | return; |
| 244 | }, | 244 | }, |
| 245 | .x86_64 => if (comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sha)) { | 245 | // C backend doesn't currently support passing vectors to inline asm. |
| 246 | .x86_64 => if (builtin.zig_backend != .stage2_c and comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sha)) { | ||
| 246 | var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] }; | 247 | var x: v4u32 = [_]u32{ d.s[5], d.s[4], d.s[1], d.s[0] }; |
| 247 | var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] }; | 248 | var y: v4u32 = [_]u32{ d.s[7], d.s[6], d.s[3], d.s[2] }; |
| 248 | const s_v = @ptrCast(*[16]v4u32, &s); | 249 | const s_v = @ptrCast(*[16]v4u32, &s); |
lib/std/debug.zig+2| ... | @@ -2189,6 +2189,8 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { | ... | @@ -2189,6 +2189,8 @@ pub fn dumpStackPointerAddr(prefix: []const u8) void { |
| 2189 | } | 2189 | } |
| 2190 | 2190 | ||
| 2191 | test "manage resources correctly" { | 2191 | test "manage resources correctly" { |
| 2192 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // error.UnsupportedBackend | ||
| 2193 | |||
| 2192 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 2194 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 2193 | 2195 | ||
| 2194 | if (builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) { | 2196 | if (builtin.os.tag == .windows and builtin.cpu.arch == .x86_64) { |
lib/std/hash.zig+1-1| ... | @@ -36,7 +36,7 @@ const xxhash = @import("hash/xxhash.zig"); | ... | @@ -36,7 +36,7 @@ const xxhash = @import("hash/xxhash.zig"); |
| 36 | pub const XxHash64 = xxhash.XxHash64; | 36 | pub const XxHash64 = xxhash.XxHash64; |
| 37 | pub const XxHash32 = xxhash.XxHash32; | 37 | pub const XxHash32 = xxhash.XxHash32; |
| 38 | 38 | ||
| 39 | test "hash" { | 39 | test { |
| 40 | _ = adler; | 40 | _ = adler; |
| 41 | _ = auto_hash; | 41 | _ = auto_hash; |
| 42 | _ = crc; | 42 | _ = crc; |
lib/std/math/big/int_test.zig+26| ... | @@ -915,6 +915,8 @@ test "big.int mul multi-single" { | ... | @@ -915,6 +915,8 @@ test "big.int mul multi-single" { |
| 915 | } | 915 | } |
| 916 | 916 | ||
| 917 | test "big.int mul multi-multi" { | 917 | test "big.int mul multi-multi" { |
| 918 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 919 | |||
| 918 | var op1: u256 = 0x998888efefefefefefefef; | 920 | var op1: u256 = 0x998888efefefefefefefef; |
| 919 | var op2: u256 = 0x333000abababababababab; | 921 | var op2: u256 = 0x333000abababababababab; |
| 920 | var a = try Managed.initSet(testing.allocator, op1); | 922 | var a = try Managed.initSet(testing.allocator, op1); |
| ... | @@ -1034,6 +1036,8 @@ test "big.int mulWrap single-single signed" { | ... | @@ -1034,6 +1036,8 @@ test "big.int mulWrap single-single signed" { |
| 1034 | } | 1036 | } |
| 1035 | 1037 | ||
| 1036 | test "big.int mulWrap multi-multi unsigned" { | 1038 | test "big.int mulWrap multi-multi unsigned" { |
| 1039 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1040 | |||
| 1037 | var op1: u256 = 0x998888efefefefefefefef; | 1041 | var op1: u256 = 0x998888efefefefefefefef; |
| 1038 | var op2: u256 = 0x333000abababababababab; | 1042 | var op2: u256 = 0x333000abababababababab; |
| 1039 | var a = try Managed.initSet(testing.allocator, op1); | 1043 | var a = try Managed.initSet(testing.allocator, op1); |
| ... | @@ -1049,6 +1053,8 @@ test "big.int mulWrap multi-multi unsigned" { | ... | @@ -1049,6 +1053,8 @@ test "big.int mulWrap multi-multi unsigned" { |
| 1049 | } | 1053 | } |
| 1050 | 1054 | ||
| 1051 | test "big.int mulWrap multi-multi signed" { | 1055 | test "big.int mulWrap multi-multi signed" { |
| 1056 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1057 | |||
| 1052 | var a = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb) - 1); | 1058 | var a = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb) - 1); |
| 1053 | defer a.deinit(); | 1059 | defer a.deinit(); |
| 1054 | var b = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); | 1060 | var b = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); |
| ... | @@ -1252,6 +1258,8 @@ test "big.int div q=0 alias" { | ... | @@ -1252,6 +1258,8 @@ test "big.int div q=0 alias" { |
| 1252 | } | 1258 | } |
| 1253 | 1259 | ||
| 1254 | test "big.int div multi-multi q < r" { | 1260 | test "big.int div multi-multi q < r" { |
| 1261 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1262 | |||
| 1255 | const op1 = 0x1ffffffff0078f432; | 1263 | const op1 = 0x1ffffffff0078f432; |
| 1256 | const op2 = 0x1ffffffff01000000; | 1264 | const op2 = 0x1ffffffff01000000; |
| 1257 | var a = try Managed.initSet(testing.allocator, op1); | 1265 | var a = try Managed.initSet(testing.allocator, op1); |
| ... | @@ -1608,6 +1616,8 @@ test "big.int div floor positive close to zero" { | ... | @@ -1608,6 +1616,8 @@ test "big.int div floor positive close to zero" { |
| 1608 | } | 1616 | } |
| 1609 | 1617 | ||
| 1610 | test "big.int div multi-multi with rem" { | 1618 | test "big.int div multi-multi with rem" { |
| 1619 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1620 | |||
| 1611 | var a = try Managed.initSet(testing.allocator, 0x8888999911110000ffffeeeeddddccccbbbbaaaa9999); | 1621 | var a = try Managed.initSet(testing.allocator, 0x8888999911110000ffffeeeeddddccccbbbbaaaa9999); |
| 1612 | defer a.deinit(); | 1622 | defer a.deinit(); |
| 1613 | var b = try Managed.initSet(testing.allocator, 0x99990000111122223333); | 1623 | var b = try Managed.initSet(testing.allocator, 0x99990000111122223333); |
| ... | @@ -1624,6 +1634,8 @@ test "big.int div multi-multi with rem" { | ... | @@ -1624,6 +1634,8 @@ test "big.int div multi-multi with rem" { |
| 1624 | } | 1634 | } |
| 1625 | 1635 | ||
| 1626 | test "big.int div multi-multi no rem" { | 1636 | test "big.int div multi-multi no rem" { |
| 1637 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1638 | |||
| 1627 | var a = try Managed.initSet(testing.allocator, 0x8888999911110000ffffeeeedb4fec200ee3a4286361); | 1639 | var a = try Managed.initSet(testing.allocator, 0x8888999911110000ffffeeeedb4fec200ee3a4286361); |
| 1628 | defer a.deinit(); | 1640 | defer a.deinit(); |
| 1629 | var b = try Managed.initSet(testing.allocator, 0x99990000111122223333); | 1641 | var b = try Managed.initSet(testing.allocator, 0x99990000111122223333); |
| ... | @@ -1640,6 +1652,8 @@ test "big.int div multi-multi no rem" { | ... | @@ -1640,6 +1652,8 @@ test "big.int div multi-multi no rem" { |
| 1640 | } | 1652 | } |
| 1641 | 1653 | ||
| 1642 | test "big.int div multi-multi (2 branch)" { | 1654 | test "big.int div multi-multi (2 branch)" { |
| 1655 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1656 | |||
| 1643 | var a = try Managed.initSet(testing.allocator, 0x866666665555555588888887777777761111111111111111); | 1657 | var a = try Managed.initSet(testing.allocator, 0x866666665555555588888887777777761111111111111111); |
| 1644 | defer a.deinit(); | 1658 | defer a.deinit(); |
| 1645 | var b = try Managed.initSet(testing.allocator, 0x86666666555555554444444433333333); | 1659 | var b = try Managed.initSet(testing.allocator, 0x86666666555555554444444433333333); |
| ... | @@ -1656,6 +1670,8 @@ test "big.int div multi-multi (2 branch)" { | ... | @@ -1656,6 +1670,8 @@ test "big.int div multi-multi (2 branch)" { |
| 1656 | } | 1670 | } |
| 1657 | 1671 | ||
| 1658 | test "big.int div multi-multi (3.1/3.3 branch)" { | 1672 | test "big.int div multi-multi (3.1/3.3 branch)" { |
| 1673 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1674 | |||
| 1659 | var a = try Managed.initSet(testing.allocator, 0x11111111111111111111111111111111111111111111111111111111111111); | 1675 | var a = try Managed.initSet(testing.allocator, 0x11111111111111111111111111111111111111111111111111111111111111); |
| 1660 | defer a.deinit(); | 1676 | defer a.deinit(); |
| 1661 | var b = try Managed.initSet(testing.allocator, 0x1111111111111111111111111111111111111111171); | 1677 | var b = try Managed.initSet(testing.allocator, 0x1111111111111111111111111111111111111111171); |
| ... | @@ -1672,6 +1688,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" { | ... | @@ -1672,6 +1688,8 @@ test "big.int div multi-multi (3.1/3.3 branch)" { |
| 1672 | } | 1688 | } |
| 1673 | 1689 | ||
| 1674 | test "big.int div multi-single zero-limb trailing" { | 1690 | test "big.int div multi-single zero-limb trailing" { |
| 1691 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1692 | |||
| 1675 | var a = try Managed.initSet(testing.allocator, 0x60000000000000000000000000000000000000000000000000000000000000000); | 1693 | var a = try Managed.initSet(testing.allocator, 0x60000000000000000000000000000000000000000000000000000000000000000); |
| 1676 | defer a.deinit(); | 1694 | defer a.deinit(); |
| 1677 | var b = try Managed.initSet(testing.allocator, 0x10000000000000000); | 1695 | var b = try Managed.initSet(testing.allocator, 0x10000000000000000); |
| ... | @@ -1690,6 +1708,8 @@ test "big.int div multi-single zero-limb trailing" { | ... | @@ -1690,6 +1708,8 @@ test "big.int div multi-single zero-limb trailing" { |
| 1690 | } | 1708 | } |
| 1691 | 1709 | ||
| 1692 | test "big.int div multi-multi zero-limb trailing (with rem)" { | 1710 | test "big.int div multi-multi zero-limb trailing (with rem)" { |
| 1711 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1712 | |||
| 1693 | var a = try Managed.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000); | 1713 | var a = try Managed.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000); |
| 1694 | defer a.deinit(); | 1714 | defer a.deinit(); |
| 1695 | var b = try Managed.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000); | 1715 | var b = try Managed.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000); |
| ... | @@ -1709,6 +1729,8 @@ test "big.int div multi-multi zero-limb trailing (with rem)" { | ... | @@ -1709,6 +1729,8 @@ test "big.int div multi-multi zero-limb trailing (with rem)" { |
| 1709 | } | 1729 | } |
| 1710 | 1730 | ||
| 1711 | test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" { | 1731 | test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" { |
| 1732 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1733 | |||
| 1712 | var a = try Managed.initSet(testing.allocator, 0x8666666655555555888888877777777611111111111111110000000000000000); | 1734 | var a = try Managed.initSet(testing.allocator, 0x8666666655555555888888877777777611111111111111110000000000000000); |
| 1713 | defer a.deinit(); | 1735 | defer a.deinit(); |
| 1714 | var b = try Managed.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000); | 1736 | var b = try Managed.initSet(testing.allocator, 0x8666666655555555444444443333333300000000000000000000000000000000); |
| ... | @@ -1728,6 +1750,8 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li | ... | @@ -1728,6 +1750,8 @@ test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-li |
| 1728 | } | 1750 | } |
| 1729 | 1751 | ||
| 1730 | test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" { | 1752 | test "big.int div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" { |
| 1753 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1754 | |||
| 1731 | var a = try Managed.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000); | 1755 | var a = try Managed.initSet(testing.allocator, 0x86666666555555558888888777777776111111111111111100000000000000000000000000000000); |
| 1732 | defer a.deinit(); | 1756 | defer a.deinit(); |
| 1733 | var b = try Managed.initSet(testing.allocator, 0x866666665555555544444444333333330000000000000000); | 1757 | var b = try Managed.initSet(testing.allocator, 0x866666665555555544444444333333330000000000000000); |
| ... | @@ -2486,6 +2510,8 @@ test "big.int gcd non-one large" { | ... | @@ -2486,6 +2510,8 @@ test "big.int gcd non-one large" { |
| 2486 | } | 2510 | } |
| 2487 | 2511 | ||
| 2488 | test "big.int gcd large multi-limb result" { | 2512 | test "big.int gcd large multi-limb result" { |
| 2513 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 2514 | |||
| 2489 | var a = try Managed.initSet(testing.allocator, 0x12345678123456781234567812345678123456781234567812345678); | 2515 | var a = try Managed.initSet(testing.allocator, 0x12345678123456781234567812345678123456781234567812345678); |
| 2490 | defer a.deinit(); | 2516 | defer a.deinit(); |
| 2491 | var b = try Managed.initSet(testing.allocator, 0x12345671234567123456712345671234567123456712345671234567); | 2517 | var b = try Managed.initSet(testing.allocator, 0x12345671234567123456712345671234567123456712345671234567); |
lib/std/math/complex.zig+1-1| ... | @@ -189,7 +189,7 @@ test "complex.magnitude" { | ... | @@ -189,7 +189,7 @@ test "complex.magnitude" { |
| 189 | try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); | 189 | try testing.expect(math.approxEqAbs(f32, c, 5.83095, epsilon)); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | test "complex.cmath" { | 192 | test { |
| 193 | _ = @import("complex/abs.zig"); | 193 | _ = @import("complex/abs.zig"); |
| 194 | _ = @import("complex/acosh.zig"); | 194 | _ = @import("complex/acosh.zig"); |
| 195 | _ = @import("complex/acos.zig"); | 195 | _ = @import("complex/acos.zig"); |
lib/std/mem.zig+6| ... | @@ -1504,6 +1504,8 @@ test "comptime read/write int" { | ... | @@ -1504,6 +1504,8 @@ test "comptime read/write int" { |
| 1504 | } | 1504 | } |
| 1505 | 1505 | ||
| 1506 | test "readIntBig and readIntLittle" { | 1506 | test "readIntBig and readIntLittle" { |
| 1507 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1508 | |||
| 1507 | try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); | 1509 | try testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0); |
| 1508 | try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); | 1510 | try testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0); |
| 1509 | 1511 | ||
| ... | @@ -1795,6 +1797,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value | ... | @@ -1795,6 +1797,8 @@ pub fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value |
| 1795 | } | 1797 | } |
| 1796 | 1798 | ||
| 1797 | test "writeIntBig and writeIntLittle" { | 1799 | test "writeIntBig and writeIntLittle" { |
| 1800 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 1801 | |||
| 1798 | var buf0: [0]u8 = undefined; | 1802 | var buf0: [0]u8 = undefined; |
| 1799 | var buf1: [1]u8 = undefined; | 1803 | var buf1: [1]u8 = undefined; |
| 1800 | var buf2: [2]u8 = undefined; | 1804 | var buf2: [2]u8 = undefined; |
| ... | @@ -4011,6 +4015,8 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice | ... | @@ -4011,6 +4015,8 @@ pub fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice |
| 4011 | } | 4015 | } |
| 4012 | 4016 | ||
| 4013 | test "read/write(Var)PackedInt" { | 4017 | test "read/write(Var)PackedInt" { |
| 4018 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 4019 | |||
| 4014 | switch (builtin.cpu.arch) { | 4020 | switch (builtin.cpu.arch) { |
| 4015 | // This test generates too much code to execute on WASI. | 4021 | // This test generates too much code to execute on WASI. |
| 4016 | // LLVM backend fails with "too many locals: locals exceed maximum" | 4022 | // LLVM backend fails with "too many locals: locals exceed maximum" |
lib/std/meta.zig+1-1| ... | @@ -10,7 +10,7 @@ pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags; | ... | @@ -10,7 +10,7 @@ pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags; |
| 10 | 10 | ||
| 11 | const Type = std.builtin.Type; | 11 | const Type = std.builtin.Type; |
| 12 | 12 | ||
| 13 | test "std.meta.TrailerFlags" { | 13 | test { |
| 14 | _ = TrailerFlags; | 14 | _ = TrailerFlags; |
| 15 | } | 15 | } |
| 16 | 16 |
lib/std/os/test.zig+6-2| ... | @@ -502,8 +502,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void { | ... | @@ -502,8 +502,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void { |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | test "dl_iterate_phdr" { | 504 | test "dl_iterate_phdr" { |
| 505 | if (native_os == .windows or native_os == .wasi or native_os == .macos) | 505 | if (builtin.object_format != .elf) return error.SkipZigTest; |
| 506 | return error.SkipZigTest; | ||
| 507 | 506 | ||
| 508 | var counter: usize = 0; | 507 | var counter: usize = 0; |
| 509 | try os.dl_iterate_phdr(&counter, IterFnError, iter_fn); | 508 | try os.dl_iterate_phdr(&counter, IterFnError, iter_fn); |
| ... | @@ -797,6 +796,11 @@ test "sigaction" { | ... | @@ -797,6 +796,11 @@ test "sigaction" { |
| 797 | if (native_os == .linux and builtin.target.cpu.arch == .x86) | 796 | if (native_os == .linux and builtin.target.cpu.arch == .x86) |
| 798 | return error.SkipZigTest; | 797 | return error.SkipZigTest; |
| 799 | 798 | ||
| 799 | // https://github.com/ziglang/zig/issues/15381 | ||
| 800 | if (native_os == .macos and builtin.target.cpu.arch == .x86_64) { | ||
| 801 | return error.SkipZigTest; | ||
| 802 | } | ||
| 803 | |||
| 800 | const S = struct { | 804 | const S = struct { |
| 801 | var handler_called_count: u32 = 0; | 805 | var handler_called_count: u32 = 0; |
| 802 | 806 |
lib/std/rand/Xoshiro256.zig+2| ... | @@ -90,6 +90,8 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void { | ... | @@ -90,6 +90,8 @@ pub fn fill(self: *Xoshiro256, buf: []u8) void { |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | test "xoroshiro sequence" { | 92 | test "xoroshiro sequence" { |
| 93 | if (@import("builtin").zig_backend == .stage2_c) return error.SkipZigTest; | ||
| 94 | |||
| 93 | var r = Xoshiro256.init(0); | 95 | var r = Xoshiro256.init(0); |
| 94 | 96 | ||
| 95 | const seq1 = [_]u64{ | 97 | const seq1 = [_]u64{ |
lib/zig.h+619-349| ... | @@ -253,97 +253,6 @@ typedef char bool; | ... | @@ -253,97 +253,6 @@ typedef char bool; |
| 253 | #define zig_concat(lhs, rhs) lhs##rhs | 253 | #define zig_concat(lhs, rhs) lhs##rhs |
| 254 | #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) | 254 | #define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs) |
| 255 | 255 | ||
| 256 | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) | ||
| 257 | #include <stdatomic.h> | ||
| 258 | #define zig_atomic(type) _Atomic(type) | ||
| 259 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) | ||
| 260 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) | ||
| 261 | #define zig_atomicrmw_xchg(obj, arg, order, type) atomic_exchange_explicit (obj, arg, order) | ||
| 262 | #define zig_atomicrmw_add(obj, arg, order, type) atomic_fetch_add_explicit (obj, arg, order) | ||
| 263 | #define zig_atomicrmw_sub(obj, arg, order, type) atomic_fetch_sub_explicit (obj, arg, order) | ||
| 264 | #define zig_atomicrmw_or(obj, arg, order, type) atomic_fetch_or_explicit (obj, arg, order) | ||
| 265 | #define zig_atomicrmw_xor(obj, arg, order, type) atomic_fetch_xor_explicit (obj, arg, order) | ||
| 266 | #define zig_atomicrmw_and(obj, arg, order, type) atomic_fetch_and_explicit (obj, arg, order) | ||
| 267 | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand (obj, arg, order) | ||
| 268 | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) | ||
| 269 | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) | ||
| 270 | #define zig_atomic_store(obj, arg, order, type) atomic_store_explicit (obj, arg, order) | ||
| 271 | #define zig_atomic_load(obj, order, type) atomic_load_explicit (obj, order) | ||
| 272 | #define zig_fence(order) atomic_thread_fence(order) | ||
| 273 | #elif defined(__GNUC__) | ||
| 274 | #define memory_order_relaxed __ATOMIC_RELAXED | ||
| 275 | #define memory_order_consume __ATOMIC_CONSUME | ||
| 276 | #define memory_order_acquire __ATOMIC_ACQUIRE | ||
| 277 | #define memory_order_release __ATOMIC_RELEASE | ||
| 278 | #define memory_order_acq_rel __ATOMIC_ACQ_REL | ||
| 279 | #define memory_order_seq_cst __ATOMIC_SEQ_CST | ||
| 280 | #define zig_atomic(type) type | ||
| 281 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) __atomic_compare_exchange_n(obj, &(expected), desired, false, succ, fail) | ||
| 282 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) __atomic_compare_exchange_n(obj, &(expected), desired, true , succ, fail) | ||
| 283 | #define zig_atomicrmw_xchg(obj, arg, order, type) __atomic_exchange_n(obj, arg, order) | ||
| 284 | #define zig_atomicrmw_add(obj, arg, order, type) __atomic_fetch_add (obj, arg, order) | ||
| 285 | #define zig_atomicrmw_sub(obj, arg, order, type) __atomic_fetch_sub (obj, arg, order) | ||
| 286 | #define zig_atomicrmw_or(obj, arg, order, type) __atomic_fetch_or (obj, arg, order) | ||
| 287 | #define zig_atomicrmw_xor(obj, arg, order, type) __atomic_fetch_xor (obj, arg, order) | ||
| 288 | #define zig_atomicrmw_and(obj, arg, order, type) __atomic_fetch_and (obj, arg, order) | ||
| 289 | #define zig_atomicrmw_nand(obj, arg, order, type) __atomic_fetch_nand(obj, arg, order) | ||
| 290 | #define zig_atomicrmw_min(obj, arg, order, type) __atomic_fetch_min (obj, arg, order) | ||
| 291 | #define zig_atomicrmw_max(obj, arg, order, type) __atomic_fetch_max (obj, arg, order) | ||
| 292 | #define zig_atomic_store(obj, arg, order, type) __atomic_store_n (obj, arg, order) | ||
| 293 | #define zig_atomic_load(obj, order, type) __atomic_load_n (obj, order) | ||
| 294 | #define zig_fence(order) __atomic_thread_fence(order) | ||
| 295 | #elif _MSC_VER && (_M_IX86 || _M_X64) | ||
| 296 | #define memory_order_relaxed 0 | ||
| 297 | #define memory_order_consume 1 | ||
| 298 | #define memory_order_acquire 2 | ||
| 299 | #define memory_order_release 3 | ||
| 300 | #define memory_order_acq_rel 4 | ||
| 301 | #define memory_order_seq_cst 5 | ||
| 302 | #define zig_atomic(type) type | ||
| 303 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_expand_concat(zig_msvc_cmpxchg_, type)(obj, &(expected), desired) | ||
| 304 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) | ||
| 305 | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xchg_, type)(obj, arg) | ||
| 306 | #define zig_atomicrmw_add(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_add_, type)(obj, arg) | ||
| 307 | #define zig_atomicrmw_sub(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_sub_, type)(obj, arg) | ||
| 308 | #define zig_atomicrmw_or(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_or_, type)(obj, arg) | ||
| 309 | #define zig_atomicrmw_xor(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_xor_, type)(obj, arg) | ||
| 310 | #define zig_atomicrmw_and(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_and_, type)(obj, arg) | ||
| 311 | #define zig_atomicrmw_nand(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_nand_, type)(obj, arg) | ||
| 312 | #define zig_atomicrmw_min(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_min_, type)(obj, arg) | ||
| 313 | #define zig_atomicrmw_max(obj, arg, order, type) zig_expand_concat(zig_msvc_atomicrmw_max_, type)(obj, arg) | ||
| 314 | #define zig_atomic_store(obj, arg, order, type) zig_expand_concat(zig_msvc_atomic_store_, type)(obj, arg) | ||
| 315 | #define zig_atomic_load(obj, order, type) zig_expand_concat(zig_msvc_atomic_load_, type)(obj) | ||
| 316 | #if _M_X64 | ||
| 317 | #define zig_fence(order) __faststorefence() | ||
| 318 | #else | ||
| 319 | #define zig_fence(order) zig_msvc_atomic_barrier() | ||
| 320 | #endif | ||
| 321 | |||
| 322 | // TODO: _MSC_VER && (_M_ARM || _M_ARM64) | ||
| 323 | #else | ||
| 324 | #define memory_order_relaxed 0 | ||
| 325 | #define memory_order_consume 1 | ||
| 326 | #define memory_order_acquire 2 | ||
| 327 | #define memory_order_release 3 | ||
| 328 | #define memory_order_acq_rel 4 | ||
| 329 | #define memory_order_seq_cst 5 | ||
| 330 | #define zig_atomic(type) type | ||
| 331 | #define zig_cmpxchg_strong(obj, expected, desired, succ, fail, type) zig_unimplemented() | ||
| 332 | #define zig_cmpxchg_weak(obj, expected, desired, succ, fail, type) zig_unimplemented() | ||
| 333 | #define zig_atomicrmw_xchg(obj, arg, order, type) zig_unimplemented() | ||
| 334 | #define zig_atomicrmw_add(obj, arg, order, type) zig_unimplemented() | ||
| 335 | #define zig_atomicrmw_sub(obj, arg, order, type) zig_unimplemented() | ||
| 336 | #define zig_atomicrmw_or(obj, arg, order, type) zig_unimplemented() | ||
| 337 | #define zig_atomicrmw_xor(obj, arg, order, type) zig_unimplemented() | ||
| 338 | #define zig_atomicrmw_and(obj, arg, order, type) zig_unimplemented() | ||
| 339 | #define zig_atomicrmw_nand(obj, arg, order, type) zig_unimplemented() | ||
| 340 | #define zig_atomicrmw_min(obj, arg, order, type) zig_unimplemented() | ||
| 341 | #define zig_atomicrmw_max(obj, arg, order, type) zig_unimplemented() | ||
| 342 | #define zig_atomic_store(obj, arg, order, type) zig_unimplemented() | ||
| 343 | #define zig_atomic_load(obj, order, type) zig_unimplemented() | ||
| 344 | #define zig_fence(order) zig_unimplemented() | ||
| 345 | #endif | ||
| 346 | |||
| 347 | #if __STDC_VERSION__ >= 201112L | 256 | #if __STDC_VERSION__ >= 201112L |
| 348 | #define zig_noreturn _Noreturn | 257 | #define zig_noreturn _Noreturn |
| 349 | #elif zig_has_attribute(noreturn) || defined(zig_gnuc) | 258 | #elif zig_has_attribute(noreturn) || defined(zig_gnuc) |
| ... | @@ -502,15 +411,6 @@ typedef ptrdiff_t intptr_t; | ... | @@ -502,15 +411,6 @@ typedef ptrdiff_t intptr_t; |
| 502 | 411 | ||
| 503 | #endif | 412 | #endif |
| 504 | 413 | ||
| 505 | #define zig_make_small_i8(val) INT8_C(val) | ||
| 506 | #define zig_make_small_u8(val) UINT8_C(val) | ||
| 507 | #define zig_make_small_i16(val) INT16_C(val) | ||
| 508 | #define zig_make_small_u16(val) UINT16_C(val) | ||
| 509 | #define zig_make_small_i32(val) INT32_C(val) | ||
| 510 | #define zig_make_small_u32(val) UINT32_C(val) | ||
| 511 | #define zig_make_small_i64(val) INT64_C(val) | ||
| 512 | #define zig_make_small_u64(val) UINT64_C(val) | ||
| 513 | |||
| 514 | #define zig_minInt_i8 INT8_MIN | 414 | #define zig_minInt_i8 INT8_MIN |
| 515 | #define zig_maxInt_i8 INT8_MAX | 415 | #define zig_maxInt_i8 INT8_MAX |
| 516 | #define zig_minInt_u8 UINT8_C(0) | 416 | #define zig_minInt_u8 UINT8_C(0) |
| ... | @@ -534,24 +434,24 @@ typedef ptrdiff_t intptr_t; | ... | @@ -534,24 +434,24 @@ typedef ptrdiff_t intptr_t; |
| 534 | #define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits) | 434 | #define zig_minInt_u(w, bits) zig_intLimit(u, w, min, bits) |
| 535 | #define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits) | 435 | #define zig_maxInt_u(w, bits) zig_intLimit(u, w, max, bits) |
| 536 | 436 | ||
| 537 | #define zig_int_operator(Type, RhsType, operation, operator) \ | 437 | #define zig_operator(Type, RhsType, operation, operator) \ |
| 538 | static inline Type zig_##operation(Type lhs, RhsType rhs) { \ | 438 | static inline Type zig_##operation(Type lhs, RhsType rhs) { \ |
| 539 | return lhs operator rhs; \ | 439 | return lhs operator rhs; \ |
| 540 | } | 440 | } |
| 541 | #define zig_int_basic_operator(Type, operation, operator) \ | 441 | #define zig_basic_operator(Type, operation, operator) \ |
| 542 | zig_int_operator(Type, Type, operation, operator) | 442 | zig_operator(Type, Type, operation, operator) |
| 543 | #define zig_int_shift_operator(Type, operation, operator) \ | 443 | #define zig_shift_operator(Type, operation, operator) \ |
| 544 | zig_int_operator(Type, uint8_t, operation, operator) | 444 | zig_operator(Type, uint8_t, operation, operator) |
| 545 | #define zig_int_helpers(w) \ | 445 | #define zig_int_helpers(w) \ |
| 546 | zig_int_basic_operator(uint##w##_t, and_u##w, &) \ | 446 | zig_basic_operator(uint##w##_t, and_u##w, &) \ |
| 547 | zig_int_basic_operator( int##w##_t, and_i##w, &) \ | 447 | zig_basic_operator( int##w##_t, and_i##w, &) \ |
| 548 | zig_int_basic_operator(uint##w##_t, or_u##w, |) \ | 448 | zig_basic_operator(uint##w##_t, or_u##w, |) \ |
| 549 | zig_int_basic_operator( int##w##_t, or_i##w, |) \ | 449 | zig_basic_operator( int##w##_t, or_i##w, |) \ |
| 550 | zig_int_basic_operator(uint##w##_t, xor_u##w, ^) \ | 450 | zig_basic_operator(uint##w##_t, xor_u##w, ^) \ |
| 551 | zig_int_basic_operator( int##w##_t, xor_i##w, ^) \ | 451 | zig_basic_operator( int##w##_t, xor_i##w, ^) \ |
| 552 | zig_int_shift_operator(uint##w##_t, shl_u##w, <<) \ | 452 | zig_shift_operator(uint##w##_t, shl_u##w, <<) \ |
| 553 | zig_int_shift_operator( int##w##_t, shl_i##w, <<) \ | 453 | zig_shift_operator( int##w##_t, shl_i##w, <<) \ |
| 554 | zig_int_shift_operator(uint##w##_t, shr_u##w, >>) \ | 454 | zig_shift_operator(uint##w##_t, shr_u##w, >>) \ |
| 555 | \ | 455 | \ |
| 556 | static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \ | 456 | static inline int##w##_t zig_shr_i##w(int##w##_t lhs, uint8_t rhs) { \ |
| 557 | int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \ | 457 | int##w##_t sign_mask = lhs < INT##w##_C(0) ? -INT##w##_C(1) : INT##w##_C(0); \ |
| ... | @@ -576,13 +476,13 @@ typedef ptrdiff_t intptr_t; | ... | @@ -576,13 +476,13 @@ typedef ptrdiff_t intptr_t; |
| 576 | ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \ | 476 | ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \ |
| 577 | } \ | 477 | } \ |
| 578 | \ | 478 | \ |
| 579 | zig_int_basic_operator(uint##w##_t, div_floor_u##w, /) \ | 479 | zig_basic_operator(uint##w##_t, div_floor_u##w, /) \ |
| 580 | \ | 480 | \ |
| 581 | static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \ | 481 | static inline int##w##_t zig_div_floor_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 582 | return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \ | 482 | return lhs / rhs - (((lhs ^ rhs) & (lhs % rhs)) < INT##w##_C(0)); \ |
| 583 | } \ | 483 | } \ |
| 584 | \ | 484 | \ |
| 585 | zig_int_basic_operator(uint##w##_t, mod_u##w, %) \ | 485 | zig_basic_operator(uint##w##_t, mod_u##w, %) \ |
| 586 | \ | 486 | \ |
| 587 | static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \ | 487 | static inline int##w##_t zig_mod_i##w(int##w##_t lhs, int##w##_t rhs) { \ |
| 588 | int##w##_t rem = lhs % rhs; \ | 488 | int##w##_t rem = lhs % rhs; \ |
| ... | @@ -1253,8 +1153,8 @@ typedef signed __int128 zig_i128; | ... | @@ -1253,8 +1153,8 @@ typedef signed __int128 zig_i128; |
| 1253 | #define zig_lo_u128(val) ((uint64_t)((val) >> 0)) | 1153 | #define zig_lo_u128(val) ((uint64_t)((val) >> 0)) |
| 1254 | #define zig_hi_i128(val) (( int64_t)((val) >> 64)) | 1154 | #define zig_hi_i128(val) (( int64_t)((val) >> 64)) |
| 1255 | #define zig_lo_i128(val) ((uint64_t)((val) >> 0)) | 1155 | #define zig_lo_i128(val) ((uint64_t)((val) >> 0)) |
| 1256 | #define zig_bitcast_u128(val) ((zig_u128)(val)) | 1156 | #define zig_bitCast_u128(val) ((zig_u128)(val)) |
| 1257 | #define zig_bitcast_i128(val) ((zig_i128)(val)) | 1157 | #define zig_bitCast_i128(val) ((zig_i128)(val)) |
| 1258 | #define zig_cmp_int128(Type) \ | 1158 | #define zig_cmp_int128(Type) \ |
| 1259 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 1159 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1260 | return (lhs > rhs) - (lhs < rhs); \ | 1160 | return (lhs > rhs) - (lhs < rhs); \ |
| ... | @@ -1288,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; | ... | @@ -1288,8 +1188,8 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1288 | #define zig_lo_u128(val) ((val).lo) | 1188 | #define zig_lo_u128(val) ((val).lo) |
| 1289 | #define zig_hi_i128(val) ((val).hi) | 1189 | #define zig_hi_i128(val) ((val).hi) |
| 1290 | #define zig_lo_i128(val) ((val).lo) | 1190 | #define zig_lo_i128(val) ((val).lo) |
| 1291 | #define zig_bitcast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo) | 1191 | #define zig_bitCast_u128(val) zig_make_u128((uint64_t)(val).hi, (val).lo) |
| 1292 | #define zig_bitcast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo) | 1192 | #define zig_bitCast_i128(val) zig_make_i128(( int64_t)(val).hi, (val).lo) |
| 1293 | #define zig_cmp_int128(Type) \ | 1193 | #define zig_cmp_int128(Type) \ |
| 1294 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 1194 | static inline int32_t zig_cmp_##Type(zig_##Type lhs, zig_##Type rhs) { \ |
| 1295 | return (lhs.hi == rhs.hi) \ | 1195 | return (lhs.hi == rhs.hi) \ |
| ... | @@ -1303,9 +1203,6 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; | ... | @@ -1303,9 +1203,6 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1303 | 1203 | ||
| 1304 | #endif /* zig_has_int128 */ | 1204 | #endif /* zig_has_int128 */ |
| 1305 | 1205 | ||
| 1306 | #define zig_make_small_u128(val) zig_make_u128(0, val) | ||
| 1307 | #define zig_make_small_i128(val) zig_make_i128((val) < 0 ? -INT64_C(1) : INT64_C(0), val) | ||
| 1308 | |||
| 1309 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) | 1206 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) |
| 1310 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) | 1207 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) |
| 1311 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) | 1208 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) |
| ... | @@ -1466,18 +1363,18 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) { | ... | @@ -1466,18 +1363,18 @@ static zig_i128 zig_mul_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1466 | } | 1363 | } |
| 1467 | 1364 | ||
| 1468 | static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) { | 1365 | static zig_u128 zig_mul_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1469 | return zig_bitcast_u128(zig_mul_i128(zig_bitcast_i128(lhs), zig_bitcast_i128(rhs))); | 1366 | return zig_bitCast_u128(zig_mul_i128(zig_bitCast_i128(lhs), zig_bitCast_i128(rhs))); |
| 1470 | } | 1367 | } |
| 1471 | 1368 | ||
| 1472 | zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs); | 1369 | zig_extern zig_u128 __udivti3(zig_u128 lhs, zig_u128 rhs); |
| 1473 | static zig_u128 zig_div_trunc_u128(zig_u128 lhs, zig_u128 rhs) { | 1370 | static zig_u128 zig_div_trunc_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1474 | return __udivti3(lhs, rhs); | 1371 | return __udivti3(lhs, rhs); |
| 1475 | }; | 1372 | } |
| 1476 | 1373 | ||
| 1477 | zig_extern zig_i128 __divti3(zig_i128 lhs, zig_i128 rhs); | 1374 | zig_extern zig_i128 __divti3(zig_i128 lhs, zig_i128 rhs); |
| 1478 | static zig_i128 zig_div_trunc_i128(zig_i128 lhs, zig_i128 rhs) { | 1375 | static zig_i128 zig_div_trunc_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1479 | return __divti3(lhs, rhs); | 1376 | return __divti3(lhs, rhs); |
| 1480 | }; | 1377 | } |
| 1481 | 1378 | ||
| 1482 | zig_extern zig_u128 __umodti3(zig_u128 lhs, zig_u128 rhs); | 1379 | zig_extern zig_u128 __umodti3(zig_u128 lhs, zig_u128 rhs); |
| 1483 | static zig_u128 zig_rem_u128(zig_u128 lhs, zig_u128 rhs) { | 1380 | static zig_u128 zig_rem_u128(zig_u128 lhs, zig_u128 rhs) { |
| ... | @@ -1503,10 +1400,6 @@ static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { | ... | @@ -1503,10 +1400,6 @@ static inline zig_i128 zig_div_floor_i128(zig_i128 lhs, zig_i128 rhs) { |
| 1503 | #define zig_div_floor_u128 zig_div_trunc_u128 | 1400 | #define zig_div_floor_u128 zig_div_trunc_u128 |
| 1504 | #define zig_mod_u128 zig_rem_u128 | 1401 | #define zig_mod_u128 zig_rem_u128 |
| 1505 | 1402 | ||
| 1506 | static inline zig_u128 zig_nand_u128(zig_u128 lhs, zig_u128 rhs) { | ||
| 1507 | return zig_not_u128(zig_and_u128(lhs, rhs), 128); | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { | 1403 | static inline zig_u128 zig_min_u128(zig_u128 lhs, zig_u128 rhs) { |
| 1511 | return zig_cmp_u128(lhs, rhs) < INT32_C(0) ? lhs : rhs; | 1404 | return zig_cmp_u128(lhs, rhs) < INT32_C(0) ? lhs : rhs; |
| 1512 | } | 1405 | } |
| ... | @@ -1538,7 +1431,7 @@ static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) { | ... | @@ -1538,7 +1431,7 @@ static inline zig_u128 zig_shlw_u128(zig_u128 lhs, uint8_t rhs, uint8_t bits) { |
| 1538 | } | 1431 | } |
| 1539 | 1432 | ||
| 1540 | static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) { | 1433 | static inline zig_i128 zig_shlw_i128(zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1541 | return zig_wrap_i128(zig_bitcast_i128(zig_shl_u128(zig_bitcast_u128(lhs), rhs)), bits); | 1434 | return zig_wrap_i128(zig_bitCast_i128(zig_shl_u128(zig_bitCast_u128(lhs), rhs)), bits); |
| 1542 | } | 1435 | } |
| 1543 | 1436 | ||
| 1544 | static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | 1437 | static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | @@ -1546,7 +1439,7 @@ static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | ... | @@ -1546,7 +1439,7 @@ static inline zig_u128 zig_addw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1546 | } | 1439 | } |
| 1547 | 1440 | ||
| 1548 | static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { | 1441 | static inline zig_i128 zig_addw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1549 | return zig_wrap_i128(zig_bitcast_i128(zig_add_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1442 | return zig_wrap_i128(zig_bitCast_i128(zig_add_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1550 | } | 1443 | } |
| 1551 | 1444 | ||
| 1552 | static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | 1445 | static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | @@ -1554,7 +1447,7 @@ static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | ... | @@ -1554,7 +1447,7 @@ static inline zig_u128 zig_subw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1554 | } | 1447 | } |
| 1555 | 1448 | ||
| 1556 | static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { | 1449 | static inline zig_i128 zig_subw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1557 | return zig_wrap_i128(zig_bitcast_i128(zig_sub_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1450 | return zig_wrap_i128(zig_bitCast_i128(zig_sub_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1558 | } | 1451 | } |
| 1559 | 1452 | ||
| 1560 | static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | 1453 | static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| ... | @@ -1562,7 +1455,7 @@ static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | ... | @@ -1562,7 +1455,7 @@ static inline zig_u128 zig_mulw_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1562 | } | 1455 | } |
| 1563 | 1456 | ||
| 1564 | static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { | 1457 | static inline zig_i128 zig_mulw_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1565 | return zig_wrap_i128(zig_bitcast_i128(zig_mul_u128(zig_bitcast_u128(lhs), zig_bitcast_u128(rhs))), bits); | 1458 | return zig_wrap_i128(zig_bitCast_i128(zig_mul_u128(zig_bitCast_u128(lhs), zig_bitCast_u128(rhs))), bits); |
| 1566 | } | 1459 | } |
| 1567 | 1460 | ||
| 1568 | #if zig_has_int128 | 1461 | #if zig_has_int128 |
| ... | @@ -1697,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8 | ... | @@ -1697,7 +1590,7 @@ static inline bool zig_shlo_u128(zig_u128 *res, zig_u128 lhs, uint8_t rhs, uint8 |
| 1697 | 1590 | ||
| 1698 | static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) { | 1591 | static inline bool zig_shlo_i128(zig_i128 *res, zig_i128 lhs, uint8_t rhs, uint8_t bits) { |
| 1699 | *res = zig_shlw_i128(lhs, rhs, bits); | 1592 | *res = zig_shlw_i128(lhs, rhs, bits); |
| 1700 | zig_i128 mask = zig_bitcast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1))); | 1593 | zig_i128 mask = zig_bitCast_i128(zig_shl_u128(zig_maxInt_u128, bits - rhs - UINT8_C(1))); |
| 1701 | return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) && | 1594 | return zig_cmp_i128(zig_and_i128(lhs, mask), zig_make_i128(0, 0)) != INT32_C(0) && |
| 1702 | zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0); | 1595 | zig_cmp_i128(zig_and_i128(lhs, mask), mask) != INT32_C(0); |
| 1703 | } | 1596 | } |
| ... | @@ -1711,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { | ... | @@ -1711,7 +1604,7 @@ static inline zig_u128 zig_shls_u128(zig_u128 lhs, zig_u128 rhs, uint8_t bits) { |
| 1711 | 1604 | ||
| 1712 | static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { | 1605 | static inline zig_i128 zig_shls_i128(zig_i128 lhs, zig_i128 rhs, uint8_t bits) { |
| 1713 | zig_i128 res; | 1606 | zig_i128 res; |
| 1714 | if (zig_cmp_u128(zig_bitcast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res; | 1607 | if (zig_cmp_u128(zig_bitCast_u128(rhs), zig_make_u128(0, bits)) < INT32_C(0) && !zig_shlo_i128(&res, lhs, (uint8_t)zig_lo_i128(rhs), bits)) return res; |
| 1715 | return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); | 1608 | return zig_cmp_i128(lhs, zig_make_i128(0, 0)) < INT32_C(0) ? zig_minInt_i(128, bits) : zig_maxInt_i(128, bits); |
| 1716 | } | 1609 | } |
| 1717 | 1610 | ||
| ... | @@ -1755,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) { | ... | @@ -1755,7 +1648,7 @@ static inline uint8_t zig_clz_u128(zig_u128 val, uint8_t bits) { |
| 1755 | } | 1648 | } |
| 1756 | 1649 | ||
| 1757 | static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) { | 1650 | static inline uint8_t zig_clz_i128(zig_i128 val, uint8_t bits) { |
| 1758 | return zig_clz_u128(zig_bitcast_u128(val), bits); | 1651 | return zig_clz_u128(zig_bitCast_u128(val), bits); |
| 1759 | } | 1652 | } |
| 1760 | 1653 | ||
| 1761 | static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { | 1654 | static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { |
| ... | @@ -1764,7 +1657,7 @@ static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { | ... | @@ -1764,7 +1657,7 @@ static inline uint8_t zig_ctz_u128(zig_u128 val, uint8_t bits) { |
| 1764 | } | 1657 | } |
| 1765 | 1658 | ||
| 1766 | static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) { | 1659 | static inline uint8_t zig_ctz_i128(zig_i128 val, uint8_t bits) { |
| 1767 | return zig_ctz_u128(zig_bitcast_u128(val), bits); | 1660 | return zig_ctz_u128(zig_bitCast_u128(val), bits); |
| 1768 | } | 1661 | } |
| 1769 | 1662 | ||
| 1770 | static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { | 1663 | static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { |
| ... | @@ -1773,7 +1666,7 @@ static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { | ... | @@ -1773,7 +1666,7 @@ static inline uint8_t zig_popcount_u128(zig_u128 val, uint8_t bits) { |
| 1773 | } | 1666 | } |
| 1774 | 1667 | ||
| 1775 | static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) { | 1668 | static inline uint8_t zig_popcount_i128(zig_i128 val, uint8_t bits) { |
| 1776 | return zig_popcount_u128(zig_bitcast_u128(val), bits); | 1669 | return zig_popcount_u128(zig_bitCast_u128(val), bits); |
| 1777 | } | 1670 | } |
| 1778 | 1671 | ||
| 1779 | static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { | 1672 | static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { |
| ... | @@ -1788,7 +1681,7 @@ static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { | ... | @@ -1788,7 +1681,7 @@ static inline zig_u128 zig_byte_swap_u128(zig_u128 val, uint8_t bits) { |
| 1788 | } | 1681 | } |
| 1789 | 1682 | ||
| 1790 | static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) { | 1683 | static inline zig_i128 zig_byte_swap_i128(zig_i128 val, uint8_t bits) { |
| 1791 | return zig_bitcast_i128(zig_byte_swap_u128(zig_bitcast_u128(val), bits)); | 1684 | return zig_bitCast_i128(zig_byte_swap_u128(zig_bitCast_u128(val), bits)); |
| 1792 | } | 1685 | } |
| 1793 | 1686 | ||
| 1794 | static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { | 1687 | static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { |
| ... | @@ -1798,7 +1691,7 @@ static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { | ... | @@ -1798,7 +1691,7 @@ static inline zig_u128 zig_bit_reverse_u128(zig_u128 val, uint8_t bits) { |
| 1798 | } | 1691 | } |
| 1799 | 1692 | ||
| 1800 | static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) { | 1693 | static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, uint8_t bits) { |
| 1801 | return zig_bitcast_i128(zig_bit_reverse_u128(zig_bitcast_u128(val), bits)); | 1694 | return zig_bitCast_i128(zig_bit_reverse_u128(zig_bitCast_u128(val), bits)); |
| 1802 | } | 1695 | } |
| 1803 | 1696 | ||
| 1804 | /* ========================== Big Integer Support =========================== */ | 1697 | /* ========================== Big Integer Support =========================== */ |
| ... | @@ -1972,6 +1865,243 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign | ... | @@ -1972,6 +1865,243 @@ static inline int32_t zig_cmp_big(const void *lhs, const void *rhs, bool is_sign |
| 1972 | return 0; | 1865 | return 0; |
| 1973 | } | 1866 | } |
| 1974 | 1867 | ||
| 1868 | static inline void zig_and_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { | ||
| 1869 | uint8_t *res_bytes = res; | ||
| 1870 | const uint8_t *lhs_bytes = lhs; | ||
| 1871 | const uint8_t *rhs_bytes = rhs; | ||
| 1872 | uint16_t byte_offset = 0; | ||
| 1873 | uint16_t remaining_bytes = zig_int_bytes(bits); | ||
| 1874 | (void)is_signed; | ||
| 1875 | |||
| 1876 | while (remaining_bytes >= 128 / CHAR_BIT) { | ||
| 1877 | zig_u128 res_limb; | ||
| 1878 | zig_u128 lhs_limb; | ||
| 1879 | zig_u128 rhs_limb; | ||
| 1880 | |||
| 1881 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1882 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1883 | res_limb = zig_and_u128(lhs_limb, rhs_limb); | ||
| 1884 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1885 | |||
| 1886 | remaining_bytes -= 128 / CHAR_BIT; | ||
| 1887 | byte_offset += 128 / CHAR_BIT; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | while (remaining_bytes >= 64 / CHAR_BIT) { | ||
| 1891 | uint64_t res_limb; | ||
| 1892 | uint64_t lhs_limb; | ||
| 1893 | uint64_t rhs_limb; | ||
| 1894 | |||
| 1895 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1896 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1897 | res_limb = zig_and_u64(lhs_limb, rhs_limb); | ||
| 1898 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1899 | |||
| 1900 | remaining_bytes -= 64 / CHAR_BIT; | ||
| 1901 | byte_offset += 64 / CHAR_BIT; | ||
| 1902 | } | ||
| 1903 | |||
| 1904 | while (remaining_bytes >= 32 / CHAR_BIT) { | ||
| 1905 | uint32_t res_limb; | ||
| 1906 | uint32_t lhs_limb; | ||
| 1907 | uint32_t rhs_limb; | ||
| 1908 | |||
| 1909 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1910 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1911 | res_limb = zig_and_u32(lhs_limb, rhs_limb); | ||
| 1912 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1913 | |||
| 1914 | remaining_bytes -= 32 / CHAR_BIT; | ||
| 1915 | byte_offset += 32 / CHAR_BIT; | ||
| 1916 | } | ||
| 1917 | |||
| 1918 | while (remaining_bytes >= 16 / CHAR_BIT) { | ||
| 1919 | uint16_t res_limb; | ||
| 1920 | uint16_t lhs_limb; | ||
| 1921 | uint16_t rhs_limb; | ||
| 1922 | |||
| 1923 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1924 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1925 | res_limb = zig_and_u16(lhs_limb, rhs_limb); | ||
| 1926 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1927 | |||
| 1928 | remaining_bytes -= 16 / CHAR_BIT; | ||
| 1929 | byte_offset += 16 / CHAR_BIT; | ||
| 1930 | } | ||
| 1931 | |||
| 1932 | while (remaining_bytes >= 8 / CHAR_BIT) { | ||
| 1933 | uint8_t res_limb; | ||
| 1934 | uint8_t lhs_limb; | ||
| 1935 | uint8_t rhs_limb; | ||
| 1936 | |||
| 1937 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1938 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1939 | res_limb = zig_and_u8(lhs_limb, rhs_limb); | ||
| 1940 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1941 | |||
| 1942 | remaining_bytes -= 8 / CHAR_BIT; | ||
| 1943 | byte_offset += 8 / CHAR_BIT; | ||
| 1944 | } | ||
| 1945 | } | ||
| 1946 | |||
| 1947 | static inline void zig_or_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { | ||
| 1948 | uint8_t *res_bytes = res; | ||
| 1949 | const uint8_t *lhs_bytes = lhs; | ||
| 1950 | const uint8_t *rhs_bytes = rhs; | ||
| 1951 | uint16_t byte_offset = 0; | ||
| 1952 | uint16_t remaining_bytes = zig_int_bytes(bits); | ||
| 1953 | (void)is_signed; | ||
| 1954 | |||
| 1955 | while (remaining_bytes >= 128 / CHAR_BIT) { | ||
| 1956 | zig_u128 res_limb; | ||
| 1957 | zig_u128 lhs_limb; | ||
| 1958 | zig_u128 rhs_limb; | ||
| 1959 | |||
| 1960 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1961 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1962 | res_limb = zig_or_u128(lhs_limb, rhs_limb); | ||
| 1963 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1964 | |||
| 1965 | remaining_bytes -= 128 / CHAR_BIT; | ||
| 1966 | byte_offset += 128 / CHAR_BIT; | ||
| 1967 | } | ||
| 1968 | |||
| 1969 | while (remaining_bytes >= 64 / CHAR_BIT) { | ||
| 1970 | uint64_t res_limb; | ||
| 1971 | uint64_t lhs_limb; | ||
| 1972 | uint64_t rhs_limb; | ||
| 1973 | |||
| 1974 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1975 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1976 | res_limb = zig_or_u64(lhs_limb, rhs_limb); | ||
| 1977 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1978 | |||
| 1979 | remaining_bytes -= 64 / CHAR_BIT; | ||
| 1980 | byte_offset += 64 / CHAR_BIT; | ||
| 1981 | } | ||
| 1982 | |||
| 1983 | while (remaining_bytes >= 32 / CHAR_BIT) { | ||
| 1984 | uint32_t res_limb; | ||
| 1985 | uint32_t lhs_limb; | ||
| 1986 | uint32_t rhs_limb; | ||
| 1987 | |||
| 1988 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 1989 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 1990 | res_limb = zig_or_u32(lhs_limb, rhs_limb); | ||
| 1991 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 1992 | |||
| 1993 | remaining_bytes -= 32 / CHAR_BIT; | ||
| 1994 | byte_offset += 32 / CHAR_BIT; | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | while (remaining_bytes >= 16 / CHAR_BIT) { | ||
| 1998 | uint16_t res_limb; | ||
| 1999 | uint16_t lhs_limb; | ||
| 2000 | uint16_t rhs_limb; | ||
| 2001 | |||
| 2002 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2003 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2004 | res_limb = zig_or_u16(lhs_limb, rhs_limb); | ||
| 2005 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2006 | |||
| 2007 | remaining_bytes -= 16 / CHAR_BIT; | ||
| 2008 | byte_offset += 16 / CHAR_BIT; | ||
| 2009 | } | ||
| 2010 | |||
| 2011 | while (remaining_bytes >= 8 / CHAR_BIT) { | ||
| 2012 | uint8_t res_limb; | ||
| 2013 | uint8_t lhs_limb; | ||
| 2014 | uint8_t rhs_limb; | ||
| 2015 | |||
| 2016 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2017 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2018 | res_limb = zig_or_u8(lhs_limb, rhs_limb); | ||
| 2019 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2020 | |||
| 2021 | remaining_bytes -= 8 / CHAR_BIT; | ||
| 2022 | byte_offset += 8 / CHAR_BIT; | ||
| 2023 | } | ||
| 2024 | } | ||
| 2025 | |||
| 2026 | static inline void zig_xor_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { | ||
| 2027 | uint8_t *res_bytes = res; | ||
| 2028 | const uint8_t *lhs_bytes = lhs; | ||
| 2029 | const uint8_t *rhs_bytes = rhs; | ||
| 2030 | uint16_t byte_offset = 0; | ||
| 2031 | uint16_t remaining_bytes = zig_int_bytes(bits); | ||
| 2032 | (void)is_signed; | ||
| 2033 | |||
| 2034 | while (remaining_bytes >= 128 / CHAR_BIT) { | ||
| 2035 | zig_u128 res_limb; | ||
| 2036 | zig_u128 lhs_limb; | ||
| 2037 | zig_u128 rhs_limb; | ||
| 2038 | |||
| 2039 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2040 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2041 | res_limb = zig_xor_u128(lhs_limb, rhs_limb); | ||
| 2042 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2043 | |||
| 2044 | remaining_bytes -= 128 / CHAR_BIT; | ||
| 2045 | byte_offset += 128 / CHAR_BIT; | ||
| 2046 | } | ||
| 2047 | |||
| 2048 | while (remaining_bytes >= 64 / CHAR_BIT) { | ||
| 2049 | uint64_t res_limb; | ||
| 2050 | uint64_t lhs_limb; | ||
| 2051 | uint64_t rhs_limb; | ||
| 2052 | |||
| 2053 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2054 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2055 | res_limb = zig_xor_u64(lhs_limb, rhs_limb); | ||
| 2056 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2057 | |||
| 2058 | remaining_bytes -= 64 / CHAR_BIT; | ||
| 2059 | byte_offset += 64 / CHAR_BIT; | ||
| 2060 | } | ||
| 2061 | |||
| 2062 | while (remaining_bytes >= 32 / CHAR_BIT) { | ||
| 2063 | uint32_t res_limb; | ||
| 2064 | uint32_t lhs_limb; | ||
| 2065 | uint32_t rhs_limb; | ||
| 2066 | |||
| 2067 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2068 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2069 | res_limb = zig_xor_u32(lhs_limb, rhs_limb); | ||
| 2070 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2071 | |||
| 2072 | remaining_bytes -= 32 / CHAR_BIT; | ||
| 2073 | byte_offset += 32 / CHAR_BIT; | ||
| 2074 | } | ||
| 2075 | |||
| 2076 | while (remaining_bytes >= 16 / CHAR_BIT) { | ||
| 2077 | uint16_t res_limb; | ||
| 2078 | uint16_t lhs_limb; | ||
| 2079 | uint16_t rhs_limb; | ||
| 2080 | |||
| 2081 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2082 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2083 | res_limb = zig_xor_u16(lhs_limb, rhs_limb); | ||
| 2084 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2085 | |||
| 2086 | remaining_bytes -= 16 / CHAR_BIT; | ||
| 2087 | byte_offset += 16 / CHAR_BIT; | ||
| 2088 | } | ||
| 2089 | |||
| 2090 | while (remaining_bytes >= 8 / CHAR_BIT) { | ||
| 2091 | uint8_t res_limb; | ||
| 2092 | uint8_t lhs_limb; | ||
| 2093 | uint8_t rhs_limb; | ||
| 2094 | |||
| 2095 | memcpy(&lhs_limb, &lhs_bytes[byte_offset], sizeof(lhs_limb)); | ||
| 2096 | memcpy(&rhs_limb, &rhs_bytes[byte_offset], sizeof(rhs_limb)); | ||
| 2097 | res_limb = zig_xor_u8(lhs_limb, rhs_limb); | ||
| 2098 | memcpy(&res_bytes[byte_offset], &res_limb, sizeof(res_limb)); | ||
| 2099 | |||
| 2100 | remaining_bytes -= 8 / CHAR_BIT; | ||
| 2101 | byte_offset += 8 / CHAR_BIT; | ||
| 2102 | } | ||
| 2103 | } | ||
| 2104 | |||
| 1975 | static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { | 2105 | static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, bool is_signed, uint16_t bits) { |
| 1976 | uint8_t *res_bytes = res; | 2106 | uint8_t *res_bytes = res; |
| 1977 | const uint8_t *lhs_bytes = lhs; | 2107 | const uint8_t *lhs_bytes = lhs; |
| ... | @@ -2827,24 +2957,20 @@ long double __cdecl nanl(char const* input); | ... | @@ -2827,24 +2957,20 @@ long double __cdecl nanl(char const* input); |
| 2827 | #endif | 2957 | #endif |
| 2828 | 2958 | ||
| 2829 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) | 2959 | #if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc) |
| 2830 | #define zig_has_float_builtins 1 | 2960 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg) |
| 2831 | #define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16(__builtin_##name, )(arg) | 2961 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg) |
| 2832 | #define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32(__builtin_##name, )(arg) | 2962 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg) |
| 2833 | #define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64(__builtin_##name, )(arg) | 2963 | #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80 (__builtin_##name, )(arg) |
| 2834 | #define zig_make_special_f80(sign, name, arg, repr) sign zig_make_f80(__builtin_##name, )(arg) | ||
| 2835 | #define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg) | 2964 | #define zig_make_special_f128(sign, name, arg, repr) sign zig_make_f128(__builtin_##name, )(arg) |
| 2836 | #else | 2965 | #else |
| 2837 | #define zig_has_float_builtins 0 | 2966 | #define zig_make_special_f16(sign, name, arg, repr) zig_bitCast_f16 (repr) |
| 2838 | #define zig_make_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr) | 2967 | #define zig_make_special_f32(sign, name, arg, repr) zig_bitCast_f32 (repr) |
| 2839 | #define zig_make_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr) | 2968 | #define zig_make_special_f64(sign, name, arg, repr) zig_bitCast_f64 (repr) |
| 2840 | #define zig_make_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr) | 2969 | #define zig_make_special_f80(sign, name, arg, repr) zig_bitCast_f80 (repr) |
| 2841 | #define zig_make_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr) | 2970 | #define zig_make_special_f128(sign, name, arg, repr) zig_bitCast_f128(repr) |
| 2842 | #define zig_make_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr) | ||
| 2843 | #endif | 2971 | #endif |
| 2844 | 2972 | ||
| 2845 | #define zig_has_f16 1 | 2973 | #define zig_has_f16 1 |
| 2846 | #define zig_bitSizeOf_f16 16 | ||
| 2847 | typedef uint16_t zig_repr_f16; | ||
| 2848 | #define zig_libc_name_f16(name) __##name##h | 2974 | #define zig_libc_name_f16(name) __##name##h |
| 2849 | #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) | 2975 | #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) |
| 2850 | #if FLT_MANT_DIG == 11 | 2976 | #if FLT_MANT_DIG == 11 |
| ... | @@ -2854,10 +2980,6 @@ typedef float zig_f16; | ... | @@ -2854,10 +2980,6 @@ typedef float zig_f16; |
| 2854 | typedef double zig_f16; | 2980 | typedef double zig_f16; |
| 2855 | #define zig_make_f16(fp, repr) fp | 2981 | #define zig_make_f16(fp, repr) fp |
| 2856 | #elif LDBL_MANT_DIG == 11 | 2982 | #elif LDBL_MANT_DIG == 11 |
| 2857 | #define zig_bitSizeOf_c_longdouble 16 | ||
| 2858 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 2859 | typedef zig_repr_f16 zig_repr_c_longdouble; | ||
| 2860 | #endif | ||
| 2861 | typedef long double zig_f16; | 2983 | typedef long double zig_f16; |
| 2862 | #define zig_make_f16(fp, repr) fp##l | 2984 | #define zig_make_f16(fp, repr) fp##l |
| 2863 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) | 2985 | #elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc)) |
| ... | @@ -2869,8 +2991,8 @@ typedef __fp16 zig_f16; | ... | @@ -2869,8 +2991,8 @@ typedef __fp16 zig_f16; |
| 2869 | #else | 2991 | #else |
| 2870 | #undef zig_has_f16 | 2992 | #undef zig_has_f16 |
| 2871 | #define zig_has_f16 0 | 2993 | #define zig_has_f16 0 |
| 2872 | #define zig_bitSizeOf_repr_f16 16 | 2994 | #define zig_repr_f16 u16 |
| 2873 | typedef zig_repr_f16 zig_f16; | 2995 | typedef uint16_t zig_f16; |
| 2874 | #define zig_make_f16(fp, repr) repr | 2996 | #define zig_make_f16(fp, repr) repr |
| 2875 | #undef zig_make_special_f16 | 2997 | #undef zig_make_special_f16 |
| 2876 | #define zig_make_special_f16(sign, name, arg, repr) repr | 2998 | #define zig_make_special_f16(sign, name, arg, repr) repr |
| ... | @@ -2878,15 +3000,12 @@ typedef zig_repr_f16 zig_f16; | ... | @@ -2878,15 +3000,12 @@ typedef zig_repr_f16 zig_f16; |
| 2878 | #define zig_init_special_f16(sign, name, arg, repr) repr | 3000 | #define zig_init_special_f16(sign, name, arg, repr) repr |
| 2879 | #endif | 3001 | #endif |
| 2880 | #if __APPLE__ && (defined(__i386__) || defined(__x86_64__)) | 3002 | #if __APPLE__ && (defined(__i386__) || defined(__x86_64__)) |
| 2881 | typedef zig_repr_f16 zig_compiler_rt_f16; | 3003 | typedef uint16_t zig_compiler_rt_f16; |
| 2882 | #else | 3004 | #else |
| 2883 | typedef zig_f16 zig_compiler_rt_f16; | 3005 | typedef zig_f16 zig_compiler_rt_f16; |
| 2884 | #endif | 3006 | #endif |
| 2885 | #define zig_compiler_rt_abbrev_zig_compiler_rt_f16 zig_compiler_rt_abbrev_zig_f16 | ||
| 2886 | 3007 | ||
| 2887 | #define zig_has_f32 1 | 3008 | #define zig_has_f32 1 |
| 2888 | #define zig_bitSizeOf_f32 32 | ||
| 2889 | typedef uint32_t zig_repr_f32; | ||
| 2890 | #define zig_libc_name_f32(name) name##f | 3009 | #define zig_libc_name_f32(name) name##f |
| 2891 | #if _MSC_VER | 3010 | #if _MSC_VER |
| 2892 | #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) | 3011 | #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) |
| ... | @@ -2900,10 +3019,6 @@ typedef float zig_f32; | ... | @@ -2900,10 +3019,6 @@ typedef float zig_f32; |
| 2900 | typedef double zig_f32; | 3019 | typedef double zig_f32; |
| 2901 | #define zig_make_f32(fp, repr) fp | 3020 | #define zig_make_f32(fp, repr) fp |
| 2902 | #elif LDBL_MANT_DIG == 24 | 3021 | #elif LDBL_MANT_DIG == 24 |
| 2903 | #define zig_bitSizeOf_c_longdouble 32 | ||
| 2904 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 2905 | typedef zig_repr_f32 zig_repr_c_longdouble; | ||
| 2906 | #endif | ||
| 2907 | typedef long double zig_f32; | 3022 | typedef long double zig_f32; |
| 2908 | #define zig_make_f32(fp, repr) fp##l | 3023 | #define zig_make_f32(fp, repr) fp##l |
| 2909 | #elif FLT32_MANT_DIG == 24 | 3024 | #elif FLT32_MANT_DIG == 24 |
| ... | @@ -2912,8 +3027,8 @@ typedef _Float32 zig_f32; | ... | @@ -2912,8 +3027,8 @@ typedef _Float32 zig_f32; |
| 2912 | #else | 3027 | #else |
| 2913 | #undef zig_has_f32 | 3028 | #undef zig_has_f32 |
| 2914 | #define zig_has_f32 0 | 3029 | #define zig_has_f32 0 |
| 2915 | #define zig_bitSizeOf_repr_f32 32 | 3030 | #define zig_repr_f32 u32 |
| 2916 | typedef zig_repr_f32 zig_f32; | 3031 | ypedef uint32_t zig_f32; |
| 2917 | #define zig_make_f32(fp, repr) repr | 3032 | #define zig_make_f32(fp, repr) repr |
| 2918 | #undef zig_make_special_f32 | 3033 | #undef zig_make_special_f32 |
| 2919 | #define zig_make_special_f32(sign, name, arg, repr) repr | 3034 | #define zig_make_special_f32(sign, name, arg, repr) repr |
| ... | @@ -2922,20 +3037,12 @@ typedef zig_repr_f32 zig_f32; | ... | @@ -2922,20 +3037,12 @@ typedef zig_repr_f32 zig_f32; |
| 2922 | #endif | 3037 | #endif |
| 2923 | 3038 | ||
| 2924 | #define zig_has_f64 1 | 3039 | #define zig_has_f64 1 |
| 2925 | #define zig_bitSizeOf_f64 64 | ||
| 2926 | typedef uint64_t zig_repr_f64; | ||
| 2927 | #define zig_libc_name_f64(name) name | 3040 | #define zig_libc_name_f64(name) name |
| 2928 | #if _MSC_VER | 3041 | #if _MSC_VER |
| 2929 | #ifdef ZIG_TARGET_ABI_MSVC | ||
| 2930 | #define zig_bitSizeOf_c_longdouble 64 | ||
| 2931 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 2932 | typedef zig_repr_f64 zig_repr_c_longdouble; | ||
| 2933 | #endif | ||
| 2934 | #endif | ||
| 2935 | #define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) | 3042 | #define zig_init_special_f64(sign, name, arg, repr) sign zig_make_f64(zig_msvc_flt_##name, ) |
| 2936 | #else /* _MSC_VER */ | 3043 | #else |
| 2937 | #define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) | 3044 | #define zig_init_special_f64(sign, name, arg, repr) zig_make_special_f64(sign, name, arg, repr) |
| 2938 | #endif /* _MSC_VER */ | 3045 | #endif |
| 2939 | #if FLT_MANT_DIG == 53 | 3046 | #if FLT_MANT_DIG == 53 |
| 2940 | typedef float zig_f64; | 3047 | typedef float zig_f64; |
| 2941 | #define zig_make_f64(fp, repr) fp##f | 3048 | #define zig_make_f64(fp, repr) fp##f |
| ... | @@ -2943,10 +3050,6 @@ typedef float zig_f64; | ... | @@ -2943,10 +3050,6 @@ typedef float zig_f64; |
| 2943 | typedef double zig_f64; | 3050 | typedef double zig_f64; |
| 2944 | #define zig_make_f64(fp, repr) fp | 3051 | #define zig_make_f64(fp, repr) fp |
| 2945 | #elif LDBL_MANT_DIG == 53 | 3052 | #elif LDBL_MANT_DIG == 53 |
| 2946 | #define zig_bitSizeOf_c_longdouble 64 | ||
| 2947 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 2948 | typedef zig_repr_f64 zig_repr_c_longdouble; | ||
| 2949 | #endif | ||
| 2950 | typedef long double zig_f64; | 3053 | typedef long double zig_f64; |
| 2951 | #define zig_make_f64(fp, repr) fp##l | 3054 | #define zig_make_f64(fp, repr) fp##l |
| 2952 | #elif FLT64_MANT_DIG == 53 | 3055 | #elif FLT64_MANT_DIG == 53 |
| ... | @@ -2958,8 +3061,8 @@ typedef _Float32x zig_f64; | ... | @@ -2958,8 +3061,8 @@ typedef _Float32x zig_f64; |
| 2958 | #else | 3061 | #else |
| 2959 | #undef zig_has_f64 | 3062 | #undef zig_has_f64 |
| 2960 | #define zig_has_f64 0 | 3063 | #define zig_has_f64 0 |
| 2961 | #define zig_bitSizeOf_repr_f64 64 | 3064 | #define zig_repr_f64 u64 |
| 2962 | typedef zig_repr_f64 zig_f64; | 3065 | typedef uint64_t zig_f64; |
| 2963 | #define zig_make_f64(fp, repr) repr | 3066 | #define zig_make_f64(fp, repr) repr |
| 2964 | #undef zig_make_special_f64 | 3067 | #undef zig_make_special_f64 |
| 2965 | #define zig_make_special_f64(sign, name, arg, repr) repr | 3068 | #define zig_make_special_f64(sign, name, arg, repr) repr |
| ... | @@ -2968,8 +3071,6 @@ typedef zig_repr_f64 zig_f64; | ... | @@ -2968,8 +3071,6 @@ typedef zig_repr_f64 zig_f64; |
| 2968 | #endif | 3071 | #endif |
| 2969 | 3072 | ||
| 2970 | #define zig_has_f80 1 | 3073 | #define zig_has_f80 1 |
| 2971 | #define zig_bitSizeOf_f80 80 | ||
| 2972 | typedef zig_u128 zig_repr_f80; | ||
| 2973 | #define zig_libc_name_f80(name) __##name##x | 3074 | #define zig_libc_name_f80(name) __##name##x |
| 2974 | #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) | 3075 | #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) |
| 2975 | #if FLT_MANT_DIG == 64 | 3076 | #if FLT_MANT_DIG == 64 |
| ... | @@ -2979,10 +3080,6 @@ typedef float zig_f80; | ... | @@ -2979,10 +3080,6 @@ typedef float zig_f80; |
| 2979 | typedef double zig_f80; | 3080 | typedef double zig_f80; |
| 2980 | #define zig_make_f80(fp, repr) fp | 3081 | #define zig_make_f80(fp, repr) fp |
| 2981 | #elif LDBL_MANT_DIG == 64 | 3082 | #elif LDBL_MANT_DIG == 64 |
| 2982 | #define zig_bitSizeOf_c_longdouble 80 | ||
| 2983 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 2984 | typedef zig_repr_f80 zig_repr_c_longdouble; | ||
| 2985 | #endif | ||
| 2986 | typedef long double zig_f80; | 3083 | typedef long double zig_f80; |
| 2987 | #define zig_make_f80(fp, repr) fp##l | 3084 | #define zig_make_f80(fp, repr) fp##l |
| 2988 | #elif FLT80_MANT_DIG == 64 | 3085 | #elif FLT80_MANT_DIG == 64 |
| ... | @@ -2997,8 +3094,8 @@ typedef __float80 zig_f80; | ... | @@ -2997,8 +3094,8 @@ typedef __float80 zig_f80; |
| 2997 | #else | 3094 | #else |
| 2998 | #undef zig_has_f80 | 3095 | #undef zig_has_f80 |
| 2999 | #define zig_has_f80 0 | 3096 | #define zig_has_f80 0 |
| 3000 | #define zig_bitSizeOf_repr_f80 128 | 3097 | #define zig_repr_f80 u128 |
| 3001 | typedef zig_repr_f80 zig_f80; | 3098 | typedef zig_u128 zig_f80; |
| 3002 | #define zig_make_f80(fp, repr) repr | 3099 | #define zig_make_f80(fp, repr) repr |
| 3003 | #undef zig_make_special_f80 | 3100 | #undef zig_make_special_f80 |
| 3004 | #define zig_make_special_f80(sign, name, arg, repr) repr | 3101 | #define zig_make_special_f80(sign, name, arg, repr) repr |
| ... | @@ -3007,8 +3104,6 @@ typedef zig_repr_f80 zig_f80; | ... | @@ -3007,8 +3104,6 @@ typedef zig_repr_f80 zig_f80; |
| 3007 | #endif | 3104 | #endif |
| 3008 | 3105 | ||
| 3009 | #define zig_has_f128 1 | 3106 | #define zig_has_f128 1 |
| 3010 | #define zig_bitSizeOf_f128 128 | ||
| 3011 | typedef zig_u128 zig_repr_f128; | ||
| 3012 | #define zig_libc_name_f128(name) name##q | 3107 | #define zig_libc_name_f128(name) name##q |
| 3013 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) | 3108 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) |
| 3014 | #if FLT_MANT_DIG == 113 | 3109 | #if FLT_MANT_DIG == 113 |
| ... | @@ -3018,10 +3113,6 @@ typedef float zig_f128; | ... | @@ -3018,10 +3113,6 @@ typedef float zig_f128; |
| 3018 | typedef double zig_f128; | 3113 | typedef double zig_f128; |
| 3019 | #define zig_make_f128(fp, repr) fp | 3114 | #define zig_make_f128(fp, repr) fp |
| 3020 | #elif LDBL_MANT_DIG == 113 | 3115 | #elif LDBL_MANT_DIG == 113 |
| 3021 | #define zig_bitSizeOf_c_longdouble 128 | ||
| 3022 | #ifndef ZIG_TARGET_ABI_MSVC | ||
| 3023 | typedef zig_repr_f128 zig_repr_c_longdouble; | ||
| 3024 | #endif | ||
| 3025 | typedef long double zig_f128; | 3116 | typedef long double zig_f128; |
| 3026 | #define zig_make_f128(fp, repr) fp##l | 3117 | #define zig_make_f128(fp, repr) fp##l |
| 3027 | #elif FLT128_MANT_DIG == 113 | 3118 | #elif FLT128_MANT_DIG == 113 |
| ... | @@ -3038,50 +3129,49 @@ typedef __float128 zig_f128; | ... | @@ -3038,50 +3129,49 @@ typedef __float128 zig_f128; |
| 3038 | #else | 3129 | #else |
| 3039 | #undef zig_has_f128 | 3130 | #undef zig_has_f128 |
| 3040 | #define zig_has_f128 0 | 3131 | #define zig_has_f128 0 |
| 3041 | #define zig_bitSizeOf_repr_f128 128 | ||
| 3042 | typedef zig_repr_f128 zig_f128; | ||
| 3043 | #define zig_make_f128(fp, repr) repr | ||
| 3044 | #undef zig_make_special_f128 | 3132 | #undef zig_make_special_f128 |
| 3045 | #define zig_make_special_f128(sign, name, arg, repr) repr | ||
| 3046 | #undef zig_init_special_f128 | 3133 | #undef zig_init_special_f128 |
| 3134 | #if __APPLE__ || defined(__aarch64__) | ||
| 3135 | typedef __attribute__((__vector_size__(2 * sizeof(uint64_t)))) uint64_t zig_v2u64; | ||
| 3136 | zig_basic_operator(zig_v2u64, xor_v2u64, ^) | ||
| 3137 | #define zig_repr_f128 v2u64 | ||
| 3138 | typedef zig_v2u64 zig_f128; | ||
| 3139 | #define zig_make_f128_zig_make_u128(hi, lo) (zig_f128){ lo, hi } | ||
| 3140 | #define zig_make_f128_zig_init_u128 zig_make_f128_zig_make_u128 | ||
| 3141 | #define zig_make_f128(fp, repr) zig_make_f128_##repr | ||
| 3142 | #define zig_make_special_f128(sign, name, arg, repr) zig_make_f128_##repr | ||
| 3143 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_f128_##repr | ||
| 3144 | #else | ||
| 3145 | #define zig_repr_f128 u128 | ||
| 3146 | typedef zig_u128 zig_f128; | ||
| 3147 | #define zig_make_f128(fp, repr) repr | ||
| 3148 | #define zig_make_special_f128(sign, name, arg, repr) repr | ||
| 3047 | #define zig_init_special_f128(sign, name, arg, repr) repr | 3149 | #define zig_init_special_f128(sign, name, arg, repr) repr |
| 3048 | #endif | 3150 | #endif |
| 3151 | #endif | ||
| 3049 | 3152 | ||
| 3050 | #ifdef zig_bitSizeOf_c_longdouble | 3153 | #if !_MSC_VER && defined(ZIG_TARGET_ABI_MSVC) |
| 3051 | 3154 | /* Emulate msvc abi on a gnu compiler */ | |
| 3052 | #define zig_has_c_longdouble 1 | ||
| 3053 | #ifdef ZIG_TARGET_ABI_MSVC | ||
| 3054 | #undef zig_bitSizeOf_c_longdouble | ||
| 3055 | #define zig_bitSizeOf_c_longdouble 64 | ||
| 3056 | typedef zig_f64 zig_c_longdouble; | 3155 | typedef zig_f64 zig_c_longdouble; |
| 3057 | typedef zig_repr_f64 zig_repr_c_longdouble; | 3156 | #elif _MSC_VER && !defined(ZIG_TARGET_ABI_MSVC) |
| 3157 | /* Emulate gnu abi on an msvc compiler */ | ||
| 3158 | typedef zig_f128 zig_c_longdouble; | ||
| 3058 | #else | 3159 | #else |
| 3160 | /* Target and compiler abi match */ | ||
| 3059 | typedef long double zig_c_longdouble; | 3161 | typedef long double zig_c_longdouble; |
| 3060 | #endif | 3162 | #endif |
| 3061 | 3163 | ||
| 3062 | #else /* zig_bitSizeOf_c_longdouble */ | 3164 | #define zig_bitCast_float(Type, ReprType) \ |
| 3063 | 3165 | static inline zig_##Type zig_bitCast_##Type(ReprType repr) { \ | |
| 3064 | #define zig_has_c_longdouble 0 | ||
| 3065 | #define zig_bitSizeOf_repr_c_longdouble 128 | ||
| 3066 | typedef zig_f128 zig_c_longdouble; | ||
| 3067 | typedef zig_repr_f128 zig_repr_c_longdouble; | ||
| 3068 | |||
| 3069 | #endif /* zig_bitSizeOf_c_longdouble */ | ||
| 3070 | |||
| 3071 | #if !zig_has_float_builtins | ||
| 3072 | #define zig_float_from_repr(Type) \ | ||
| 3073 | static inline zig_##Type zig_float_from_repr_##Type(zig_repr_##Type repr) { \ | ||
| 3074 | zig_##Type result; \ | 3166 | zig_##Type result; \ |
| 3075 | memcpy(&result, &repr, sizeof(result)); \ | 3167 | memcpy(&result, &repr, sizeof(result)); \ |
| 3076 | return result; \ | 3168 | return result; \ |
| 3077 | } | 3169 | } |
| 3078 | 3170 | zig_bitCast_float(f16, uint16_t) | |
| 3079 | zig_float_from_repr(f16) | 3171 | zig_bitCast_float(f32, uint32_t) |
| 3080 | zig_float_from_repr(f32) | 3172 | zig_bitCast_float(f64, uint64_t) |
| 3081 | zig_float_from_repr(f64) | 3173 | zig_bitCast_float(f80, zig_u128) |
| 3082 | zig_float_from_repr(f80) | 3174 | zig_bitCast_float(f128, zig_u128) |
| 3083 | zig_float_from_repr(f128) | ||
| 3084 | #endif | ||
| 3085 | 3175 | ||
| 3086 | #define zig_cast_f16 (zig_f16) | 3176 | #define zig_cast_f16 (zig_f16) |
| 3087 | #define zig_cast_f32 (zig_f32) | 3177 | #define zig_cast_f32 (zig_f32) |
| ... | @@ -3095,44 +3185,53 @@ zig_float_from_repr(f128) | ... | @@ -3095,44 +3185,53 @@ zig_float_from_repr(f128) |
| 3095 | #define zig_cast_f128 (zig_f128) | 3185 | #define zig_cast_f128 (zig_f128) |
| 3096 | #endif | 3186 | #endif |
| 3097 | 3187 | ||
| 3098 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ | 3188 | #define zig_convert_builtin(ExternResType, ResType, operation, ExternArgType, ArgType, version) \ |
| 3099 | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ | 3189 | zig_extern ExternResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3100 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); | 3190 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ExternArgType); \ |
| 3101 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2) | 3191 | static inline ResType zig_expand_concat(zig_expand_concat(zig_##operation, \ |
| 3102 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2) | 3192 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType)(ArgType arg) { \ |
| 3103 | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) | 3193 | ResType res; \ |
| 3104 | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) | 3194 | ExternResType extern_res; \ |
| 3105 | zig_convert_builtin(zig_f32, extend, zig_compiler_rt_f16, 2) | 3195 | ExternArgType extern_arg; \ |
| 3106 | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) | 3196 | memcpy(&extern_arg, &arg, sizeof(extern_arg)); \ |
| 3107 | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) | 3197 | extern_res = zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3108 | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) | 3198 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(extern_arg); \ |
| 3109 | zig_convert_builtin(zig_f64, extend, zig_compiler_rt_f16, 2) | 3199 | memcpy(&res, &extern_res, sizeof(res)); \ |
| 3110 | zig_convert_builtin(zig_f64, extend, zig_f32, 2) | 3200 | return extern_res; \ |
| 3111 | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) | 3201 | } |
| 3112 | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) | 3202 | zig_convert_builtin(zig_compiler_rt_f16, zig_f16, trunc, zig_f32, zig_f32, 2) |
| 3113 | zig_convert_builtin(zig_f80, extend, zig_f16, 2) | 3203 | zig_convert_builtin(zig_compiler_rt_f16, zig_f16, trunc, zig_f64, zig_f64, 2) |
| 3114 | zig_convert_builtin(zig_f80, extend, zig_f32, 2) | 3204 | zig_convert_builtin(zig_f16, zig_f16, trunc, zig_f80, zig_f80, 2) |
| 3115 | zig_convert_builtin(zig_f80, extend, zig_f64, 2) | 3205 | zig_convert_builtin(zig_f16, zig_f16, trunc, zig_f128, zig_f128, 2) |
| 3116 | zig_convert_builtin(zig_f80, trunc, zig_f128, 2) | 3206 | zig_convert_builtin(zig_f32, zig_f32, extend, zig_compiler_rt_f16, zig_f16, 2) |
| 3117 | zig_convert_builtin(zig_f128, extend, zig_f16, 2) | 3207 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f64, zig_f64, 2) |
| 3118 | zig_convert_builtin(zig_f128, extend, zig_f32, 2) | 3208 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f80, zig_f80, 2) |
| 3119 | zig_convert_builtin(zig_f128, extend, zig_f64, 2) | 3209 | zig_convert_builtin(zig_f32, zig_f32, trunc, zig_f128, zig_f128, 2) |
| 3120 | zig_convert_builtin(zig_f128, extend, zig_f80, 2) | 3210 | zig_convert_builtin(zig_f64, zig_f64, extend, zig_compiler_rt_f16, zig_f16, 2) |
| 3121 | 3211 | zig_convert_builtin(zig_f64, zig_f64, extend, zig_f32, zig_f32, 2) | |
| 3122 | #define zig_float_negate_builtin_0(w) \ | 3212 | zig_convert_builtin(zig_f64, zig_f64, trunc, zig_f80, zig_f80, 2) |
| 3123 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ | 3213 | zig_convert_builtin(zig_f64, zig_f64, trunc, zig_f128, zig_f128, 2) |
| 3124 | return zig_expand_concat(zig_xor_u, zig_bitSizeOf_repr_f##w)( \ | 3214 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f16, zig_f16, 2) |
| 3125 | arg, \ | 3215 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f32, zig_f32, 2) |
| 3126 | zig_expand_concat(zig_shl_u, zig_bitSizeOf_repr_f##w)( \ | 3216 | zig_convert_builtin(zig_f80, zig_f80, extend, zig_f64, zig_f64, 2) |
| 3127 | zig_expand_concat(zig_make_small_u, zig_bitSizeOf_repr_f##w)(1), \ | 3217 | zig_convert_builtin(zig_f80, zig_f80, trunc, zig_f128, zig_f128, 2) |
| 3128 | UINT8_C(w - 1) \ | 3218 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f16, zig_f16, 2) |
| 3129 | ) \ | 3219 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f32, zig_f32, 2) |
| 3130 | ); \ | 3220 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f64, zig_f64, 2) |
| 3131 | } | 3221 | zig_convert_builtin(zig_f128, zig_f128, extend, zig_f80, zig_f80, 2) |
| 3132 | #define zig_float_negate_builtin_1(w) \ | 3222 | |
| 3223 | #define zig_float_negate_builtin_0(w, c, sb) \ | ||
| 3224 | zig_expand_concat(zig_xor_, zig_repr_f##w)(arg, zig_make_f##w(-0x0.0p0, c sb)) | ||
| 3225 | #define zig_float_negate_builtin_1(w, c, sb) -arg | ||
| 3226 | #define zig_float_negate_builtin(w, c, sb) \ | ||
| 3133 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ | 3227 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ |
| 3134 | return -arg; \ | 3228 | return zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w, c, sb); \ |
| 3135 | } | 3229 | } |
| 3230 | zig_float_negate_builtin(16, , UINT16_C(1) << 15 ) | ||
| 3231 | zig_float_negate_builtin(32, , UINT32_C(1) << 31 ) | ||
| 3232 | zig_float_negate_builtin(64, , UINT64_C(1) << 63 ) | ||
| 3233 | zig_float_negate_builtin(80, zig_make_u128, (UINT64_C(1) << 15, UINT64_C(0))) | ||
| 3234 | zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0))) | ||
| 3136 | 3235 | ||
| 3137 | #define zig_float_less_builtin_0(Type, operation) \ | 3236 | #define zig_float_less_builtin_0(Type, operation) \ |
| 3138 | zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \ | 3237 | zig_extern int32_t zig_expand_concat(zig_expand_concat(__##operation, \ |
| ... | @@ -3164,19 +3263,18 @@ zig_convert_builtin(zig_f128, extend, zig_f80, 2) | ... | @@ -3164,19 +3263,18 @@ zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 3164 | } | 3263 | } |
| 3165 | 3264 | ||
| 3166 | #define zig_float_builtins(w) \ | 3265 | #define zig_float_builtins(w) \ |
| 3167 | zig_convert_builtin( int32_t, fix, zig_f##w, ) \ | 3266 | zig_convert_builtin( int32_t, int32_t, fix, zig_f##w, zig_f##w, ) \ |
| 3168 | zig_convert_builtin(uint32_t, fixuns, zig_f##w, ) \ | 3267 | zig_convert_builtin(uint32_t, uint32_t, fixuns, zig_f##w, zig_f##w, ) \ |
| 3169 | zig_convert_builtin( int64_t, fix, zig_f##w, ) \ | 3268 | zig_convert_builtin( int64_t, int64_t, fix, zig_f##w, zig_f##w, ) \ |
| 3170 | zig_convert_builtin(uint64_t, fixuns, zig_f##w, ) \ | 3269 | zig_convert_builtin(uint64_t, uint64_t, fixuns, zig_f##w, zig_f##w, ) \ |
| 3171 | zig_convert_builtin(zig_i128, fix, zig_f##w, ) \ | 3270 | zig_convert_builtin(zig_i128, zig_i128, fix, zig_f##w, zig_f##w, ) \ |
| 3172 | zig_convert_builtin(zig_u128, fixuns, zig_f##w, ) \ | 3271 | zig_convert_builtin(zig_u128, zig_u128, fixuns, zig_f##w, zig_f##w, ) \ |
| 3173 | zig_convert_builtin(zig_f##w, float, int32_t, ) \ | 3272 | zig_convert_builtin(zig_f##w, zig_f##w, float, int32_t, int32_t, ) \ |
| 3174 | zig_convert_builtin(zig_f##w, floatun, uint32_t, ) \ | 3273 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, uint32_t, uint32_t, ) \ |
| 3175 | zig_convert_builtin(zig_f##w, float, int64_t, ) \ | 3274 | zig_convert_builtin(zig_f##w, zig_f##w, float, int64_t, int64_t, ) \ |
| 3176 | zig_convert_builtin(zig_f##w, floatun, uint64_t, ) \ | 3275 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, uint64_t, uint64_t, ) \ |
| 3177 | zig_convert_builtin(zig_f##w, float, zig_i128, ) \ | 3276 | zig_convert_builtin(zig_f##w, zig_f##w, float, zig_i128, zig_i128, ) \ |
| 3178 | zig_convert_builtin(zig_f##w, floatun, zig_u128, ) \ | 3277 | zig_convert_builtin(zig_f##w, zig_f##w, floatun, zig_u128, zig_u128, ) \ |
| 3179 | zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w) \ | ||
| 3180 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, cmp) \ | 3278 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, cmp) \ |
| 3181 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, ne) \ | 3279 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, ne) \ |
| 3182 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, eq) \ | 3280 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, eq) \ |
| ... | @@ -3224,9 +3322,238 @@ zig_float_builtins(64) | ... | @@ -3224,9 +3322,238 @@ zig_float_builtins(64) |
| 3224 | zig_float_builtins(80) | 3322 | zig_float_builtins(80) |
| 3225 | zig_float_builtins(128) | 3323 | zig_float_builtins(128) |
| 3226 | 3324 | ||
| 3325 | /* ============================ Atomics Support ============================= */ | ||
| 3326 | |||
| 3327 | /* Note that atomics should be implemented as macros because most | ||
| 3328 | compilers silently discard runtime atomic order information. */ | ||
| 3329 | |||
| 3330 | /* Define fallback implementations first that can later be undef'd on compilers with builtin support. */ | ||
| 3331 | /* Note that zig_atomicrmw_expected is needed to handle aliasing between res and arg. */ | ||
| 3332 | #define zig_atomicrmw_xchg_float(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3333 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3334 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3335 | while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3336 | res = zig_atomicrmw_expected; \ | ||
| 3337 | } while (0) | ||
| 3338 | #define zig_atomicrmw_add_float(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3339 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3340 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3341 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3342 | do { \ | ||
| 3343 | zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3344 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3345 | res = zig_atomicrmw_expected; \ | ||
| 3346 | } while (0) | ||
| 3347 | #define zig_atomicrmw_sub_float(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3348 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3349 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3350 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3351 | do { \ | ||
| 3352 | zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3353 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3354 | res = zig_atomicrmw_expected; \ | ||
| 3355 | } while (0) | ||
| 3356 | #define zig_atomicrmw_min_float(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3357 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3358 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3359 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3360 | do { \ | ||
| 3361 | zig_atomicrmw_desired = zig_libc_name_##Type(fmin)(zig_atomicrmw_expected, arg); \ | ||
| 3362 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3363 | res = zig_atomicrmw_expected; \ | ||
| 3364 | } while (0) | ||
| 3365 | #define zig_atomicrmw_max_float(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3366 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3367 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3368 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3369 | do { \ | ||
| 3370 | zig_atomicrmw_desired = zig_libc_name_##Type(fmax)(zig_atomicrmw_expected, arg); \ | ||
| 3371 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3372 | res = zig_atomicrmw_expected; \ | ||
| 3373 | } while (0) | ||
| 3374 | |||
| 3375 | #define zig_atomicrmw_xchg_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3376 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3377 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3378 | while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3379 | res = zig_atomicrmw_expected; \ | ||
| 3380 | } while (0) | ||
| 3381 | #define zig_atomicrmw_add_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3382 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3383 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3384 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3385 | do { \ | ||
| 3386 | zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3387 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3388 | res = zig_atomicrmw_expected; \ | ||
| 3389 | } while (0) | ||
| 3390 | #define zig_atomicrmw_sub_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3391 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3392 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3393 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3394 | do { \ | ||
| 3395 | zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3396 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3397 | res = zig_atomicrmw_expected; \ | ||
| 3398 | } while (0) | ||
| 3399 | #define zig_atomicrmw_and_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3400 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3401 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3402 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3403 | do { \ | ||
| 3404 | zig_atomicrmw_desired = zig_and_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3405 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3406 | res = zig_atomicrmw_expected; \ | ||
| 3407 | } while (0) | ||
| 3408 | #define zig_atomicrmw_nand_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3409 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3410 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3411 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3412 | do { \ | ||
| 3413 | zig_atomicrmw_desired = zig_not_##Type(zig_and_##Type(zig_atomicrmw_expected, arg), 128); \ | ||
| 3414 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3415 | res = zig_atomicrmw_expected; \ | ||
| 3416 | } while (0) | ||
| 3417 | #define zig_atomicrmw_or_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3418 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3419 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3420 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3421 | do { \ | ||
| 3422 | zig_atomicrmw_desired = zig_or_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3423 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3424 | res = zig_atomicrmw_expected; \ | ||
| 3425 | } while (0) | ||
| 3426 | #define zig_atomicrmw_xor_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3427 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3428 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3429 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3430 | do { \ | ||
| 3431 | zig_atomicrmw_desired = zig_xor_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3432 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3433 | res = zig_atomicrmw_expected; \ | ||
| 3434 | } while (0) | ||
| 3435 | #define zig_atomicrmw_min_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3436 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3437 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3438 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3439 | do { \ | ||
| 3440 | zig_atomicrmw_desired = zig_min_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3441 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3442 | res = zig_atomicrmw_expected; \ | ||
| 3443 | } while (0) | ||
| 3444 | #define zig_atomicrmw_max_int128(res, obj, arg, order, Type, ReprType) do { \ | ||
| 3445 | zig_##Type zig_atomicrmw_expected; \ | ||
| 3446 | zig_##Type zig_atomicrmw_desired; \ | ||
| 3447 | zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \ | ||
| 3448 | do { \ | ||
| 3449 | zig_atomicrmw_desired = zig_max_##Type(zig_atomicrmw_expected, arg); \ | ||
| 3450 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \ | ||
| 3451 | res = zig_atomicrmw_expected; \ | ||
| 3452 | } while (0) | ||
| 3453 | |||
| 3454 | #if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) | ||
| 3455 | #include <stdatomic.h> | ||
| 3456 | typedef enum memory_order zig_memory_order; | ||
| 3457 | #define zig_atomic(Type) _Atomic(Type) | ||
| 3458 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail) | ||
| 3459 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail) | ||
| 3460 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) res = atomic_exchange_explicit (obj, arg, order) | ||
| 3461 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = atomic_fetch_add_explicit (obj, arg, order) | ||
| 3462 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = atomic_fetch_sub_explicit (obj, arg, order) | ||
| 3463 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = atomic_fetch_or_explicit (obj, arg, order) | ||
| 3464 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = atomic_fetch_xor_explicit (obj, arg, order) | ||
| 3465 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = atomic_fetch_and_explicit (obj, arg, order) | ||
| 3466 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) | ||
| 3467 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) | ||
| 3468 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) | ||
| 3469 | #define zig_atomic_store( obj, arg, order, Type, ReprType) atomic_store_explicit (obj, arg, order) | ||
| 3470 | #define zig_atomic_load(res, obj, order, Type, ReprType) res = atomic_load_explicit (obj, order) | ||
| 3471 | #undef zig_atomicrmw_xchg_float | ||
| 3472 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg | ||
| 3473 | #undef zig_atomicrmw_add_float | ||
| 3474 | #define zig_atomicrmw_add_float zig_atomicrmw_add | ||
| 3475 | #undef zig_atomicrmw_sub_float | ||
| 3476 | #define zig_atomicrmw_sub_float zig_atomicrmw_sub | ||
| 3477 | #define zig_fence(order) atomic_thread_fence(order) | ||
| 3478 | #elif defined(__GNUC__) | ||
| 3479 | typedef int zig_memory_order; | ||
| 3480 | #define memory_order_relaxed __ATOMIC_RELAXED | ||
| 3481 | #define memory_order_consume __ATOMIC_CONSUME | ||
| 3482 | #define memory_order_acquire __ATOMIC_ACQUIRE | ||
| 3483 | #define memory_order_release __ATOMIC_RELEASE | ||
| 3484 | #define memory_order_acq_rel __ATOMIC_ACQ_REL | ||
| 3485 | #define memory_order_seq_cst __ATOMIC_SEQ_CST | ||
| 3486 | #define zig_atomic(Type) Type | ||
| 3487 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail) | ||
| 3488 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail) | ||
| 3489 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order) | ||
| 3490 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) | ||
| 3491 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) | ||
| 3492 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order) | ||
| 3493 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_xor (obj, arg, order) | ||
| 3494 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_and (obj, arg, order) | ||
| 3495 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) | ||
| 3496 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) | ||
| 3497 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) | ||
| 3498 | #define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, &(arg), order) | ||
| 3499 | #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) | ||
| 3500 | #undef zig_atomicrmw_xchg_float | ||
| 3501 | #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg | ||
| 3502 | #define zig_fence(order) __atomic_thread_fence(order) | ||
| 3503 | #elif _MSC_VER && (_M_IX86 || _M_X64) | ||
| 3504 | #define memory_order_relaxed 0 | ||
| 3505 | #define memory_order_consume 1 | ||
| 3506 | #define memory_order_acquire 2 | ||
| 3507 | #define memory_order_release 3 | ||
| 3508 | #define memory_order_acq_rel 4 | ||
| 3509 | #define memory_order_seq_cst 5 | ||
| 3510 | #define zig_atomic(Type) Type | ||
| 3511 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_msvc_cmpxchg_##Type(obj, &(expected), desired) | ||
| 3512 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_cmpxchg_strong(obj, expected, desired, succ, fail, Type, ReprType) | ||
| 3513 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_xchg_##Type(obj, arg) | ||
| 3514 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_add_ ##Type(obj, arg) | ||
| 3515 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_sub_ ##Type(obj, arg) | ||
| 3516 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_or_ ##Type(obj, arg) | ||
| 3517 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_xor_ ##Type(obj, arg) | ||
| 3518 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_and_ ##Type(obj, arg) | ||
| 3519 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_nand_##Type(obj, arg) | ||
| 3520 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg) | ||
| 3521 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg) | ||
| 3522 | #define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg) | ||
| 3523 | #define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj) | ||
| 3524 | #if _M_X64 | ||
| 3525 | #define zig_fence(order) __faststorefence() | ||
| 3526 | #else | ||
| 3527 | #define zig_fence(order) zig_msvc_atomic_barrier() | ||
| 3528 | #endif | ||
| 3529 | /* TODO: _MSC_VER && (_M_ARM || _M_ARM64) */ | ||
| 3530 | #else | ||
| 3531 | #define memory_order_relaxed 0 | ||
| 3532 | #define memory_order_consume 1 | ||
| 3533 | #define memory_order_acquire 2 | ||
| 3534 | #define memory_order_release 3 | ||
| 3535 | #define memory_order_acq_rel 4 | ||
| 3536 | #define memory_order_seq_cst 5 | ||
| 3537 | #define zig_atomic(Type) Type | ||
| 3538 | #define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable | ||
| 3539 | #define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable | ||
| 3540 | #define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3541 | #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3542 | #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3543 | #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3544 | #define zig_atomicrmw_xor(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3545 | #define zig_atomicrmw_and(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3546 | #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3547 | #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3548 | #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3549 | #define zig_atomic_store( obj, arg, order, Type, ReprType) zig_atomics_unavailable | ||
| 3550 | #define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable | ||
| 3551 | #define zig_fence(order) zig_fence_unavailable | ||
| 3552 | #endif | ||
| 3553 | |||
| 3227 | #if _MSC_VER && (_M_IX86 || _M_X64) | 3554 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| 3228 | 3555 | ||
| 3229 | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 | 3556 | /* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */ |
| 3230 | 3557 | ||
| 3231 | #define zig_msvc_atomics(ZigType, Type, SigType, suffix) \ | 3558 | #define zig_msvc_atomics(ZigType, Type, SigType, suffix) \ |
| 3232 | static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \ | 3559 | static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \ |
| ... | @@ -3316,51 +3643,30 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64) | ... | @@ -3316,51 +3643,30 @@ zig_msvc_atomics(u64, uint64_t, __int64, 64) |
| 3316 | zig_msvc_atomics(i64, int64_t, __int64, 64) | 3643 | zig_msvc_atomics(i64, int64_t, __int64, 64) |
| 3317 | #endif | 3644 | #endif |
| 3318 | 3645 | ||
| 3319 | #define zig_msvc_flt_atomics(Type, ReprType, suffix) \ | 3646 | #define zig_msvc_flt_atomics(Type, SigType, suffix) \ |
| 3320 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ | 3647 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ |
| 3321 | ReprType exchange; \ | 3648 | SigType exchange; \ |
| 3322 | ReprType comparand; \ | 3649 | SigType comparand; \ |
| 3323 | ReprType initial; \ | 3650 | SigType initial; \ |
| 3324 | bool success; \ | 3651 | bool success; \ |
| 3325 | memcpy(&comparand, expected, sizeof(comparand)); \ | 3652 | memcpy(&comparand, expected, sizeof(comparand)); \ |
| 3326 | memcpy(&exchange, &desired, sizeof(exchange)); \ | 3653 | memcpy(&exchange, &desired, sizeof(exchange)); \ |
| 3327 | initial = _InterlockedCompareExchange##suffix((ReprType volatile*)obj, exchange, comparand); \ | 3654 | initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, exchange, comparand); \ |
| 3328 | success = initial == comparand; \ | 3655 | success = initial == comparand; \ |
| 3329 | if (!success) memcpy(expected, &initial, sizeof(*expected)); \ | 3656 | if (!success) memcpy(expected, &initial, sizeof(*expected)); \ |
| 3330 | return success; \ | 3657 | return success; \ |
| 3331 | } \ | 3658 | } \ |
| 3332 | static inline zig_##Type zig_msvc_atomicrmw_xchg_##Type(zig_##Type volatile* obj, zig_##Type value) { \ | 3659 | static inline void zig_msvc_atomic_store_##Type(zig_##Type volatile* obj, zig_##Type arg) { \ |
| 3333 | ReprType repr; \ | 3660 | SigType value; \ |
| 3334 | ReprType initial; \ | 3661 | memcpy(&value, &arg, sizeof(value)); \ |
| 3662 | (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \ | ||
| 3663 | } \ | ||
| 3664 | static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \ | ||
| 3335 | zig_##Type result; \ | 3665 | zig_##Type result; \ |
| 3336 | memcpy(&repr, &value, sizeof(repr)); \ | 3666 | SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \ |
| 3337 | initial = _InterlockedExchange##suffix((ReprType volatile*)obj, repr); \ | ||
| 3338 | memcpy(&result, &initial, sizeof(result)); \ | 3667 | memcpy(&result, &initial, sizeof(result)); \ |
| 3339 | return result; \ | 3668 | return result; \ |
| 3340 | } \ | ||
| 3341 | static inline zig_##Type zig_msvc_atomicrmw_add_##Type(zig_##Type volatile* obj, zig_##Type value) { \ | ||
| 3342 | ReprType repr; \ | ||
| 3343 | zig_##Type expected; \ | ||
| 3344 | zig_##Type desired; \ | ||
| 3345 | repr = *(ReprType volatile*)obj; \ | ||
| 3346 | memcpy(&expected, &repr, sizeof(expected)); \ | ||
| 3347 | do { \ | ||
| 3348 | desired = expected + value; \ | ||
| 3349 | } while (!zig_msvc_cmpxchg_##Type(obj, &expected, desired)); \ | ||
| 3350 | return expected; \ | ||
| 3351 | } \ | ||
| 3352 | static inline zig_##Type zig_msvc_atomicrmw_sub_##Type(zig_##Type volatile* obj, zig_##Type value) { \ | ||
| 3353 | ReprType repr; \ | ||
| 3354 | zig_##Type expected; \ | ||
| 3355 | zig_##Type desired; \ | ||
| 3356 | repr = *(ReprType volatile*)obj; \ | ||
| 3357 | memcpy(&expected, &repr, sizeof(expected)); \ | ||
| 3358 | do { \ | ||
| 3359 | desired = expected - value; \ | ||
| 3360 | } while (!zig_msvc_cmpxchg_##Type(obj, &expected, desired)); \ | ||
| 3361 | return expected; \ | ||
| 3362 | } | 3669 | } |
| 3363 | |||
| 3364 | zig_msvc_flt_atomics(f32, long, ) | 3670 | zig_msvc_flt_atomics(f32, long, ) |
| 3365 | #if _M_X64 | 3671 | #if _M_X64 |
| 3366 | zig_msvc_flt_atomics(f64, int64_t, 64) | 3672 | zig_msvc_flt_atomics(f64, int64_t, 64) |
| ... | @@ -3421,42 +3727,6 @@ static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expec | ... | @@ -3421,42 +3727,6 @@ static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expec |
| 3421 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { | 3727 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { |
| 3422 | return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_i128(desired), (__int64)zig_lo_i128(desired), (__int64*)expected); | 3728 | return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_i128(desired), (__int64)zig_lo_i128(desired), (__int64*)expected); |
| 3423 | } | 3729 | } |
| 3424 | |||
| 3425 | #define zig_msvc_atomics_128xchg(Type) \ | ||
| 3426 | static inline zig_##Type zig_msvc_atomicrmw_xchg_##Type(zig_##Type volatile* obj, zig_##Type value) { \ | ||
| 3427 | bool success = false; \ | ||
| 3428 | zig_##Type prev; \ | ||
| 3429 | while (!success) { \ | ||
| 3430 | prev = *obj; \ | ||
| 3431 | success = zig_msvc_cmpxchg_##Type(obj, &prev, value); \ | ||
| 3432 | } \ | ||
| 3433 | return prev; \ | ||
| 3434 | } | ||
| 3435 | |||
| 3436 | zig_msvc_atomics_128xchg(u128) | ||
| 3437 | zig_msvc_atomics_128xchg(i128) | ||
| 3438 | |||
| 3439 | #define zig_msvc_atomics_128op(Type, operation) \ | ||
| 3440 | static inline zig_##Type zig_msvc_atomicrmw_##operation##_##Type(zig_##Type volatile* obj, zig_##Type value) { \ | ||
| 3441 | bool success = false; \ | ||
| 3442 | zig_##Type new; \ | ||
| 3443 | zig_##Type prev; \ | ||
| 3444 | while (!success) { \ | ||
| 3445 | prev = *obj; \ | ||
| 3446 | new = zig_##operation##_##Type(prev, value); \ | ||
| 3447 | success = zig_msvc_cmpxchg_##Type(obj, &prev, new); \ | ||
| 3448 | } \ | ||
| 3449 | return prev; \ | ||
| 3450 | } | ||
| 3451 | |||
| 3452 | zig_msvc_atomics_128op(u128, add) | ||
| 3453 | zig_msvc_atomics_128op(u128, sub) | ||
| 3454 | zig_msvc_atomics_128op(u128, or) | ||
| 3455 | zig_msvc_atomics_128op(u128, xor) | ||
| 3456 | zig_msvc_atomics_128op(u128, and) | ||
| 3457 | zig_msvc_atomics_128op(u128, nand) | ||
| 3458 | zig_msvc_atomics_128op(u128, min) | ||
| 3459 | zig_msvc_atomics_128op(u128, max) | ||
| 3460 | #endif /* _M_IX86 */ | 3730 | #endif /* _M_IX86 */ |
| 3461 | 3731 | ||
| 3462 | #endif /* _MSC_VER && (_M_IX86 || _M_X64) */ | 3732 | #endif /* _MSC_VER && (_M_IX86 || _M_X64) */ |
src/Sema.zig+2-2| ... | @@ -21319,8 +21319,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -21319,8 +21319,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 21319 | return sema.fail(block, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); | 21319 | return sema.fail(block, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); |
| 21320 | }, | 21320 | }, |
| 21321 | .Float => switch (op) { | 21321 | .Float => switch (op) { |
| 21322 | .Xchg, .Add, .Sub => {}, | 21322 | .Xchg, .Add, .Sub, .Max, .Min => {}, |
| 21323 | else => return sema.fail(block, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}), | 21323 | else => return sema.fail(block, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, .Sub, .Max, and .Min", .{}), |
| 21324 | }, | 21324 | }, |
| 21325 | else => {}, | 21325 | else => {}, |
| 21326 | } | 21326 | } |
src/codegen/c.zig+559-550| ... | @@ -45,9 +45,6 @@ pub const CValue = union(enum) { | ... | @@ -45,9 +45,6 @@ pub const CValue = union(enum) { |
| 45 | identifier: []const u8, | 45 | identifier: []const u8, |
| 46 | /// Render the slice as an payload.identifier (using fmtIdent) | 46 | /// Render the slice as an payload.identifier (using fmtIdent) |
| 47 | payload_identifier: []const u8, | 47 | payload_identifier: []const u8, |
| 48 | /// Render these bytes literally. | ||
| 49 | /// TODO make this a [*:0]const u8 to save memory | ||
| 50 | bytes: []const u8, | ||
| 51 | }; | 48 | }; |
| 52 | 49 | ||
| 53 | const BlockData = struct { | 50 | const BlockData = struct { |
| ... | @@ -434,7 +431,7 @@ pub const Function = struct { | ... | @@ -434,7 +431,7 @@ pub const Function = struct { |
| 434 | return f.object.dg.renderCType(w, t); | 431 | return f.object.dg.renderCType(w, t); |
| 435 | } | 432 | } |
| 436 | 433 | ||
| 437 | fn renderIntCast(f: *Function, w: anytype, dest_ty: Type, src: CValue, v: Vectorizer, src_ty: Type, location: ValueRenderLocation) !void { | 434 | fn renderIntCast(f: *Function, w: anytype, dest_ty: Type, src: CValue, v: Vectorize, src_ty: Type, location: ValueRenderLocation) !void { |
| 438 | return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location); | 435 | return f.object.dg.renderIntCast(w, dest_ty, .{ .c_value = .{ .f = f, .value = src, .v = v } }, src_ty, location); |
| 439 | } | 436 | } |
| 440 | 437 | ||
| ... | @@ -811,11 +808,13 @@ pub const DeclGen = struct { | ... | @@ -811,11 +808,13 @@ pub const DeclGen = struct { |
| 811 | 808 | ||
| 812 | try writer.writeByte('{'); | 809 | try writer.writeByte('{'); |
| 813 | var empty = true; | 810 | var empty = true; |
| 814 | for (ty.structFields().values()) |field| { | 811 | for (0..ty.structFieldCount()) |field_i| { |
| 815 | if (!field.ty.hasRuntimeBits()) continue; | 812 | if (ty.structFieldIsComptime(field_i)) continue; |
| 813 | const field_ty = ty.structFieldType(field_i); | ||
| 814 | if (!field_ty.hasRuntimeBits()) continue; | ||
| 816 | 815 | ||
| 817 | if (!empty) try writer.writeByte(','); | 816 | if (!empty) try writer.writeByte(','); |
| 818 | try dg.renderValue(writer, field.ty, val, initializer_type); | 817 | try dg.renderValue(writer, field_ty, val, initializer_type); |
| 819 | 818 | ||
| 820 | empty = false; | 819 | empty = false; |
| 821 | } | 820 | } |
| ... | @@ -837,19 +836,27 @@ pub const DeclGen = struct { | ... | @@ -837,19 +836,27 @@ pub const DeclGen = struct { |
| 837 | if (layout.tag_size != 0) { | 836 | if (layout.tag_size != 0) { |
| 838 | try writer.writeAll(" .tag = "); | 837 | try writer.writeAll(" .tag = "); |
| 839 | try dg.renderValue(writer, tag_ty, val, initializer_type); | 838 | try dg.renderValue(writer, tag_ty, val, initializer_type); |
| 840 | try writer.writeByte(','); | ||
| 841 | } | 839 | } |
| 840 | if (ty.unionHasAllZeroBitFieldTypes()) return try writer.writeByte('}'); | ||
| 841 | if (layout.tag_size != 0) try writer.writeByte(','); | ||
| 842 | try writer.writeAll(" .payload = {"); | 842 | try writer.writeAll(" .payload = {"); |
| 843 | } | 843 | } |
| 844 | for (ty.unionFields().values()) |field| { | 844 | for (ty.unionFields().values()) |field| { |
| 845 | if (!field.ty.hasRuntimeBits()) continue; | 845 | if (!field.ty.hasRuntimeBits()) continue; |
| 846 | try dg.renderValue(writer, field.ty, val, initializer_type); | 846 | try dg.renderValue(writer, field.ty, val, initializer_type); |
| 847 | break; | 847 | break; |
| 848 | } else try writer.print("{x}", .{try dg.fmtIntLiteral(Type.u8, Value.undef, .Other)}); | 848 | } |
| 849 | if (ty.unionTagTypeSafety()) |_| try writer.writeByte('}'); | 849 | if (ty.unionTagTypeSafety()) |_| try writer.writeByte('}'); |
| 850 | return writer.writeByte('}'); | 850 | return writer.writeByte('}'); |
| 851 | }, | 851 | }, |
| 852 | .ErrorUnion => { | 852 | .ErrorUnion => { |
| 853 | const payload_ty = ty.errorUnionPayload(); | ||
| 854 | const error_ty = ty.errorUnionSet(); | ||
| 855 | |||
| 856 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { | ||
| 857 | return dg.renderValue(writer, error_ty, val, location); | ||
| 858 | } | ||
| 859 | |||
| 853 | if (!location.isInitializer()) { | 860 | if (!location.isInitializer()) { |
| 854 | try writer.writeByte('('); | 861 | try writer.writeByte('('); |
| 855 | try dg.renderType(writer, ty); | 862 | try dg.renderType(writer, ty); |
| ... | @@ -857,18 +864,12 @@ pub const DeclGen = struct { | ... | @@ -857,18 +864,12 @@ pub const DeclGen = struct { |
| 857 | } | 864 | } |
| 858 | 865 | ||
| 859 | try writer.writeAll("{ .payload = "); | 866 | try writer.writeAll("{ .payload = "); |
| 860 | try dg.renderValue(writer, ty.errorUnionPayload(), val, initializer_type); | 867 | try dg.renderValue(writer, payload_ty, val, initializer_type); |
| 861 | return writer.print(", .error = {x} }}", .{ | 868 | try writer.writeAll(", .error = "); |
| 862 | try dg.fmtIntLiteral(ty.errorUnionSet(), val, .Other), | 869 | try dg.renderValue(writer, error_ty, val, initializer_type); |
| 863 | }); | 870 | return writer.writeAll(" }"); |
| 864 | }, | 871 | }, |
| 865 | .Array, .Vector => { | 872 | .Array, .Vector => { |
| 866 | if (!location.isInitializer()) { | ||
| 867 | try writer.writeByte('('); | ||
| 868 | try dg.renderType(writer, ty); | ||
| 869 | try writer.writeByte(')'); | ||
| 870 | } | ||
| 871 | |||
| 872 | const ai = ty.arrayInfo(); | 873 | const ai = ty.arrayInfo(); |
| 873 | if (ai.elem_type.eql(Type.u8, dg.module)) { | 874 | if (ai.elem_type.eql(Type.u8, dg.module)) { |
| 874 | var literal = stringLiteral(writer); | 875 | var literal = stringLiteral(writer); |
| ... | @@ -879,6 +880,12 @@ pub const DeclGen = struct { | ... | @@ -879,6 +880,12 @@ pub const DeclGen = struct { |
| 879 | try literal.writeChar(0xaa); | 880 | try literal.writeChar(0xaa); |
| 880 | return literal.end(); | 881 | return literal.end(); |
| 881 | } else { | 882 | } else { |
| 883 | if (!location.isInitializer()) { | ||
| 884 | try writer.writeByte('('); | ||
| 885 | try dg.renderType(writer, ty); | ||
| 886 | try writer.writeByte(')'); | ||
| 887 | } | ||
| 888 | |||
| 882 | try writer.writeByte('{'); | 889 | try writer.writeByte('{'); |
| 883 | const c_len = ty.arrayLenIncludingSentinel(); | 890 | const c_len = ty.arrayLenIncludingSentinel(); |
| 884 | var index: u64 = 0; | 891 | var index: u64 = 0; |
| ... | @@ -1199,23 +1206,20 @@ pub const DeclGen = struct { | ... | @@ -1199,23 +1206,20 @@ pub const DeclGen = struct { |
| 1199 | try writer.writeAll(" }"); | 1206 | try writer.writeAll(" }"); |
| 1200 | }, | 1207 | }, |
| 1201 | .ErrorSet => { | 1208 | .ErrorSet => { |
| 1202 | const error_name = if (val.castTag(.@"error")) |error_pl| | 1209 | if (val.castTag(.@"error")) |error_pl| { |
| 1203 | error_pl.data.name | 1210 | // Error values are already defined by genErrDecls. |
| 1204 | else | 1211 | try writer.print("zig_error_{}", .{fmtIdent(error_pl.data.name)}); |
| 1205 | dg.module.error_name_list.items[0]; | 1212 | } else { |
| 1206 | // Error values are already defined by genErrDecls. | 1213 | try writer.print("{}", .{try dg.fmtIntLiteral(ty, val, .Other)}); |
| 1207 | try writer.print("zig_error_{}", .{fmtIdent(error_name)}); | 1214 | } |
| 1208 | }, | 1215 | }, |
| 1209 | .ErrorUnion => { | 1216 | .ErrorUnion => { |
| 1210 | const error_ty = ty.errorUnionSet(); | ||
| 1211 | const payload_ty = ty.errorUnionPayload(); | 1217 | const payload_ty = ty.errorUnionPayload(); |
| 1218 | const error_ty = ty.errorUnionSet(); | ||
| 1219 | const error_val = if (val.errorUnionIsPayload()) Value.zero else val; | ||
| 1212 | 1220 | ||
| 1213 | if (!payload_ty.hasRuntimeBits()) { | 1221 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { |
| 1214 | // We use the error type directly as the type. | 1222 | return dg.renderValue(writer, error_ty, error_val, location); |
| 1215 | if (val.errorUnionIsPayload()) { | ||
| 1216 | return try writer.writeByte('0'); | ||
| 1217 | } | ||
| 1218 | return dg.renderValue(writer, error_ty, val, location); | ||
| 1219 | } | 1223 | } |
| 1220 | 1224 | ||
| 1221 | if (!location.isInitializer()) { | 1225 | if (!location.isInitializer()) { |
| ... | @@ -1225,8 +1229,6 @@ pub const DeclGen = struct { | ... | @@ -1225,8 +1229,6 @@ pub const DeclGen = struct { |
| 1225 | } | 1229 | } |
| 1226 | 1230 | ||
| 1227 | const payload_val = if (val.castTag(.eu_payload)) |pl| pl.data else Value.undef; | 1231 | const payload_val = if (val.castTag(.eu_payload)) |pl| pl.data else Value.undef; |
| 1228 | const error_val = if (val.errorUnionIsPayload()) Value.zero else val; | ||
| 1229 | |||
| 1230 | try writer.writeAll("{ .payload = "); | 1232 | try writer.writeAll("{ .payload = "); |
| 1231 | try dg.renderValue(writer, payload_ty, payload_val, initializer_type); | 1233 | try dg.renderValue(writer, payload_ty, payload_val, initializer_type); |
| 1232 | try writer.writeAll(", .error = "); | 1234 | try writer.writeAll(", .error = "); |
| ... | @@ -1290,9 +1292,10 @@ pub const DeclGen = struct { | ... | @@ -1290,9 +1292,10 @@ pub const DeclGen = struct { |
| 1290 | 1292 | ||
| 1291 | try writer.writeByte('{'); | 1293 | try writer.writeByte('{'); |
| 1292 | var empty = true; | 1294 | var empty = true; |
| 1293 | for (field_vals, 0..) |field_val, field_index| { | 1295 | for (field_vals, 0..) |field_val, field_i| { |
| 1294 | const field_ty = ty.structFieldType(field_index); | 1296 | if (ty.structFieldIsComptime(field_i)) continue; |
| 1295 | if (!field_ty.hasRuntimeBits()) continue; | 1297 | const field_ty = ty.structFieldType(field_i); |
| 1298 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | ||
| 1296 | 1299 | ||
| 1297 | if (!empty) try writer.writeByte(','); | 1300 | if (!empty) try writer.writeByte(','); |
| 1298 | try dg.renderValue(writer, field_ty, field_val, initializer_type); | 1301 | try dg.renderValue(writer, field_ty, field_val, initializer_type); |
| ... | @@ -1315,8 +1318,9 @@ pub const DeclGen = struct { | ... | @@ -1315,8 +1318,9 @@ pub const DeclGen = struct { |
| 1315 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); | 1318 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); |
| 1316 | 1319 | ||
| 1317 | var eff_num_fields: usize = 0; | 1320 | var eff_num_fields: usize = 0; |
| 1318 | for (0..field_vals.len) |index| { | 1321 | for (0..field_vals.len) |field_i| { |
| 1319 | const field_ty = ty.structFieldType(index); | 1322 | if (ty.structFieldIsComptime(field_i)) continue; |
| 1323 | const field_ty = ty.structFieldType(field_i); | ||
| 1320 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1324 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1321 | 1325 | ||
| 1322 | eff_num_fields += 1; | 1326 | eff_num_fields += 1; |
| ... | @@ -1337,8 +1341,9 @@ pub const DeclGen = struct { | ... | @@ -1337,8 +1341,9 @@ pub const DeclGen = struct { |
| 1337 | 1341 | ||
| 1338 | var eff_index: usize = 0; | 1342 | var eff_index: usize = 0; |
| 1339 | var needs_closing_paren = false; | 1343 | var needs_closing_paren = false; |
| 1340 | for (field_vals, 0..) |field_val, index| { | 1344 | for (field_vals, 0..) |field_val, field_i| { |
| 1341 | const field_ty = ty.structFieldType(index); | 1345 | if (ty.structFieldIsComptime(field_i)) continue; |
| 1346 | const field_ty = ty.structFieldType(field_i); | ||
| 1342 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1347 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1343 | 1348 | ||
| 1344 | const cast_context = IntCastContext{ .value = .{ .value = field_val } }; | 1349 | const cast_context = IntCastContext{ .value = .{ .value = field_val } }; |
| ... | @@ -1365,8 +1370,9 @@ pub const DeclGen = struct { | ... | @@ -1365,8 +1370,9 @@ pub const DeclGen = struct { |
| 1365 | try writer.writeByte('('); | 1370 | try writer.writeByte('('); |
| 1366 | // a << a_off | b << b_off | c << c_off | 1371 | // a << a_off | b << b_off | c << c_off |
| 1367 | var empty = true; | 1372 | var empty = true; |
| 1368 | for (field_vals, 0..) |field_val, index| { | 1373 | for (field_vals, 0..) |field_val, field_i| { |
| 1369 | const field_ty = ty.structFieldType(index); | 1374 | if (ty.structFieldIsComptime(field_i)) continue; |
| 1375 | const field_ty = ty.structFieldType(field_i); | ||
| 1370 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 1376 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 1371 | 1377 | ||
| 1372 | if (!empty) try writer.writeAll(" | "); | 1378 | if (!empty) try writer.writeAll(" | "); |
| ... | @@ -1398,9 +1404,9 @@ pub const DeclGen = struct { | ... | @@ -1398,9 +1404,9 @@ pub const DeclGen = struct { |
| 1398 | try writer.writeByte(')'); | 1404 | try writer.writeByte(')'); |
| 1399 | } | 1405 | } |
| 1400 | 1406 | ||
| 1401 | const index = ty.unionTagFieldIndex(union_obj.tag, dg.module).?; | 1407 | const field_i = ty.unionTagFieldIndex(union_obj.tag, dg.module).?; |
| 1402 | const field_ty = ty.unionFields().values()[index].ty; | 1408 | const field_ty = ty.unionFields().values()[field_i].ty; |
| 1403 | const field_name = ty.unionFields().keys()[index]; | 1409 | const field_name = ty.unionFields().keys()[field_i]; |
| 1404 | if (ty.containerLayout() == .Packed) { | 1410 | if (ty.containerLayout() == .Packed) { |
| 1405 | if (field_ty.hasRuntimeBits()) { | 1411 | if (field_ty.hasRuntimeBits()) { |
| 1406 | if (field_ty.isPtrAtRuntime()) { | 1412 | if (field_ty.isPtrAtRuntime()) { |
| ... | @@ -1419,32 +1425,27 @@ pub const DeclGen = struct { | ... | @@ -1419,32 +1425,27 @@ pub const DeclGen = struct { |
| 1419 | return; | 1425 | return; |
| 1420 | } | 1426 | } |
| 1421 | 1427 | ||
| 1422 | var has_payload_init = false; | ||
| 1423 | try writer.writeByte('{'); | 1428 | try writer.writeByte('{'); |
| 1424 | if (ty.unionTagTypeSafety()) |tag_ty| { | 1429 | if (ty.unionTagTypeSafety()) |tag_ty| { |
| 1425 | const layout = ty.unionGetLayout(target); | 1430 | const layout = ty.unionGetLayout(target); |
| 1426 | if (layout.tag_size != 0) { | 1431 | if (layout.tag_size != 0) { |
| 1427 | try writer.writeAll(".tag = "); | 1432 | try writer.writeAll(" .tag = "); |
| 1428 | try dg.renderValue(writer, tag_ty, union_obj.tag, initializer_type); | 1433 | try dg.renderValue(writer, tag_ty, union_obj.tag, initializer_type); |
| 1429 | try writer.writeAll(", "); | ||
| 1430 | } | ||
| 1431 | if (!ty.unionHasAllZeroBitFieldTypes()) { | ||
| 1432 | try writer.writeAll(".payload = {"); | ||
| 1433 | has_payload_init = true; | ||
| 1434 | } | 1434 | } |
| 1435 | if (ty.unionHasAllZeroBitFieldTypes()) return try writer.writeByte('}'); | ||
| 1436 | if (layout.tag_size != 0) try writer.writeByte(','); | ||
| 1437 | try writer.writeAll(" .payload = {"); | ||
| 1435 | } | 1438 | } |
| 1436 | |||
| 1437 | var it = ty.unionFields().iterator(); | ||
| 1438 | if (field_ty.hasRuntimeBits()) { | 1439 | if (field_ty.hasRuntimeBits()) { |
| 1439 | try writer.print(".{ } = ", .{fmtIdent(field_name)}); | 1440 | try writer.print(" .{ } = ", .{fmtIdent(field_name)}); |
| 1440 | try dg.renderValue(writer, field_ty, union_obj.val, initializer_type); | 1441 | try dg.renderValue(writer, field_ty, union_obj.val, initializer_type); |
| 1441 | } else while (it.next()) |field| { | 1442 | try writer.writeByte(' '); |
| 1442 | if (!field.value_ptr.ty.hasRuntimeBits()) continue; | 1443 | } else for (ty.unionFields().values()) |field| { |
| 1443 | try writer.print(".{ } = ", .{fmtIdent(field.key_ptr.*)}); | 1444 | if (!field.ty.hasRuntimeBits()) continue; |
| 1444 | try dg.renderValue(writer, field.value_ptr.ty, Value.undef, initializer_type); | 1445 | try dg.renderValue(writer, field.ty, Value.undef, initializer_type); |
| 1445 | break; | 1446 | break; |
| 1446 | } | 1447 | } |
| 1447 | if (has_payload_init) try writer.writeByte('}'); | 1448 | if (ty.unionTagTypeSafety()) |_| try writer.writeByte('}'); |
| 1448 | try writer.writeByte('}'); | 1449 | try writer.writeByte('}'); |
| 1449 | }, | 1450 | }, |
| 1450 | 1451 | ||
| ... | @@ -1585,7 +1586,7 @@ pub const DeclGen = struct { | ... | @@ -1585,7 +1586,7 @@ pub const DeclGen = struct { |
| 1585 | c_value: struct { | 1586 | c_value: struct { |
| 1586 | f: *Function, | 1587 | f: *Function, |
| 1587 | value: CValue, | 1588 | value: CValue, |
| 1588 | v: Vectorizer, | 1589 | v: Vectorize, |
| 1589 | }, | 1590 | }, |
| 1590 | value: struct { | 1591 | value: struct { |
| 1591 | value: Value, | 1592 | value: Value, |
| ... | @@ -1766,7 +1767,6 @@ pub const DeclGen = struct { | ... | @@ -1766,7 +1767,6 @@ pub const DeclGen = struct { |
| 1766 | fmtIdent("payload"), | 1767 | fmtIdent("payload"), |
| 1767 | fmtIdent(ident), | 1768 | fmtIdent(ident), |
| 1768 | }), | 1769 | }), |
| 1769 | .bytes => |bytes| return w.writeAll(bytes), | ||
| 1770 | } | 1770 | } |
| 1771 | } | 1771 | } |
| 1772 | 1772 | ||
| ... | @@ -1795,11 +1795,6 @@ pub const DeclGen = struct { | ... | @@ -1795,11 +1795,6 @@ pub const DeclGen = struct { |
| 1795 | fmtIdent("payload"), | 1795 | fmtIdent("payload"), |
| 1796 | fmtIdent(ident), | 1796 | fmtIdent(ident), |
| 1797 | }), | 1797 | }), |
| 1798 | .bytes => |bytes| { | ||
| 1799 | try w.writeAll("(*"); | ||
| 1800 | try w.writeAll(bytes); | ||
| 1801 | return w.writeByte(')'); | ||
| 1802 | }, | ||
| 1803 | } | 1798 | } |
| 1804 | } | 1799 | } |
| 1805 | 1800 | ||
| ... | @@ -1812,7 +1807,7 @@ pub const DeclGen = struct { | ... | @@ -1812,7 +1807,7 @@ pub const DeclGen = struct { |
| 1812 | fn writeCValueDerefMember(dg: *DeclGen, writer: anytype, c_value: CValue, member: CValue) !void { | 1807 | fn writeCValueDerefMember(dg: *DeclGen, writer: anytype, c_value: CValue, member: CValue) !void { |
| 1813 | switch (c_value) { | 1808 | switch (c_value) { |
| 1814 | .none, .constant, .field, .undef => unreachable, | 1809 | .none, .constant, .field, .undef => unreachable, |
| 1815 | .new_local, .local, .arg, .arg_array, .decl, .identifier, .payload_identifier, .bytes => { | 1810 | .new_local, .local, .arg, .arg_array, .decl, .identifier, .payload_identifier => { |
| 1816 | try dg.writeCValue(writer, c_value); | 1811 | try dg.writeCValue(writer, c_value); |
| 1817 | try writer.writeAll("->"); | 1812 | try writer.writeAll("->"); |
| 1818 | }, | 1813 | }, |
| ... | @@ -3073,15 +3068,17 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [ | ... | @@ -3073,15 +3068,17 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [ |
| 3073 | const inst_ty = f.air.typeOfIndex(inst); | 3068 | const inst_ty = f.air.typeOfIndex(inst); |
| 3074 | const operand = try f.resolveInst(ty_op.operand); | 3069 | const operand = try f.resolveInst(ty_op.operand); |
| 3075 | try reap(f, inst, &.{ty_op.operand}); | 3070 | try reap(f, inst, &.{ty_op.operand}); |
| 3071 | |||
| 3076 | const writer = f.object.writer(); | 3072 | const writer = f.object.writer(); |
| 3077 | const local = try f.allocLocal(inst, inst_ty); | 3073 | const local = try f.allocLocal(inst, inst_ty); |
| 3074 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 3078 | try f.writeCValue(writer, local, .Other); | 3075 | try f.writeCValue(writer, local, .Other); |
| 3079 | try writer.writeAll(" = "); | 3076 | try a.assign(f, writer); |
| 3080 | if (is_ptr) { | 3077 | if (is_ptr) { |
| 3081 | try writer.writeByte('&'); | 3078 | try writer.writeByte('&'); |
| 3082 | try f.writeCValueDerefMember(writer, operand, .{ .identifier = field_name }); | 3079 | try f.writeCValueDerefMember(writer, operand, .{ .identifier = field_name }); |
| 3083 | } else try f.writeCValueMember(writer, operand, .{ .identifier = field_name }); | 3080 | } else try f.writeCValueMember(writer, operand, .{ .identifier = field_name }); |
| 3084 | try writer.writeAll(";\n"); | 3081 | try a.end(f, writer); |
| 3085 | return local; | 3082 | return local; |
| 3086 | } | 3083 | } |
| 3087 | 3084 | ||
| ... | @@ -3097,29 +3094,16 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3097,29 +3094,16 @@ fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3097 | const index = try f.resolveInst(bin_op.rhs); | 3094 | const index = try f.resolveInst(bin_op.rhs); |
| 3098 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3095 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3099 | 3096 | ||
| 3100 | const target = f.object.dg.module.getTarget(); | ||
| 3101 | const is_array = lowersToArray(inst_ty, target); | ||
| 3102 | |||
| 3103 | const local = try f.allocLocal(inst, inst_ty); | ||
| 3104 | const writer = f.object.writer(); | 3097 | const writer = f.object.writer(); |
| 3105 | if (is_array) { | 3098 | const local = try f.allocLocal(inst, inst_ty); |
| 3106 | try writer.writeAll("memcpy("); | 3099 | const a = try Assignment.start(f, writer, inst_ty); |
| 3107 | try f.writeCValue(writer, local, .FunctionArgument); | 3100 | try f.writeCValue(writer, local, .Other); |
| 3108 | try writer.writeAll(", "); | 3101 | try a.assign(f, writer); |
| 3109 | } else { | ||
| 3110 | try f.writeCValue(writer, local, .Other); | ||
| 3111 | try writer.writeAll(" = "); | ||
| 3112 | } | ||
| 3113 | try f.writeCValue(writer, ptr, .Other); | 3102 | try f.writeCValue(writer, ptr, .Other); |
| 3114 | try writer.writeByte('['); | 3103 | try writer.writeByte('['); |
| 3115 | try f.writeCValue(writer, index, .Other); | 3104 | try f.writeCValue(writer, index, .Other); |
| 3116 | try writer.writeByte(']'); | 3105 | try writer.writeByte(']'); |
| 3117 | if (is_array) { | 3106 | try a.end(f, writer); |
| 3118 | try writer.writeAll(", sizeof("); | ||
| 3119 | try f.renderType(writer, inst_ty); | ||
| 3120 | try writer.writeAll("))"); | ||
| 3121 | } | ||
| 3122 | try writer.writeAll(";\n"); | ||
| 3123 | return local; | 3107 | return local; |
| 3124 | } | 3108 | } |
| 3125 | 3109 | ||
| ... | @@ -3129,35 +3113,32 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3129,35 +3113,32 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3129 | 3113 | ||
| 3130 | const inst_ty = f.air.typeOfIndex(inst); | 3114 | const inst_ty = f.air.typeOfIndex(inst); |
| 3131 | const ptr_ty = f.air.typeOf(bin_op.lhs); | 3115 | const ptr_ty = f.air.typeOf(bin_op.lhs); |
| 3132 | const child_ty = ptr_ty.childType(); | 3116 | const elem_ty = ptr_ty.childType(); |
| 3117 | const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(); | ||
| 3133 | 3118 | ||
| 3134 | const ptr = try f.resolveInst(bin_op.lhs); | 3119 | const ptr = try f.resolveInst(bin_op.lhs); |
| 3135 | const index = try f.resolveInst(bin_op.rhs); | 3120 | const index = try f.resolveInst(bin_op.rhs); |
| 3136 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3121 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3137 | 3122 | ||
| 3138 | const writer = f.object.writer(); | 3123 | const writer = f.object.writer(); |
| 3139 | const local = try f.allocLocal(inst, f.air.typeOfIndex(inst)); | 3124 | const local = try f.allocLocal(inst, inst_ty); |
| 3125 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 3140 | try f.writeCValue(writer, local, .Other); | 3126 | try f.writeCValue(writer, local, .Other); |
| 3141 | try writer.writeAll(" = "); | 3127 | try a.assign(f, writer); |
| 3142 | |||
| 3143 | if (!child_ty.hasRuntimeBitsIgnoreComptime()) { | ||
| 3144 | try f.writeCValue(writer, ptr, .Initializer); | ||
| 3145 | try writer.writeAll(";\n"); | ||
| 3146 | return local; | ||
| 3147 | } | ||
| 3148 | |||
| 3149 | try writer.writeByte('('); | 3128 | try writer.writeByte('('); |
| 3150 | try f.renderType(writer, inst_ty); | 3129 | try f.renderType(writer, inst_ty); |
| 3151 | try writer.writeAll(")&("); | 3130 | try writer.writeByte(')'); |
| 3152 | if (ptr_ty.ptrSize() == .One) { | 3131 | if (elem_has_bits) try writer.writeByte('&'); |
| 3132 | if (elem_has_bits and ptr_ty.ptrSize() == .One) { | ||
| 3153 | // It's a pointer to an array, so we need to de-reference. | 3133 | // It's a pointer to an array, so we need to de-reference. |
| 3154 | try f.writeCValueDeref(writer, ptr); | 3134 | try f.writeCValueDeref(writer, ptr); |
| 3155 | } else { | 3135 | } else try f.writeCValue(writer, ptr, .Other); |
| 3156 | try f.writeCValue(writer, ptr, .Other); | 3136 | if (elem_has_bits) { |
| 3137 | try writer.writeByte('['); | ||
| 3138 | try f.writeCValue(writer, index, .Other); | ||
| 3139 | try writer.writeByte(']'); | ||
| 3157 | } | 3140 | } |
| 3158 | try writer.writeAll(")["); | 3141 | try a.end(f, writer); |
| 3159 | try f.writeCValue(writer, index, .Other); | ||
| 3160 | try writer.writeAll("];\n"); | ||
| 3161 | return local; | 3142 | return local; |
| 3162 | } | 3143 | } |
| 3163 | 3144 | ||
| ... | @@ -3173,29 +3154,16 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3173,29 +3154,16 @@ fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3173 | const index = try f.resolveInst(bin_op.rhs); | 3154 | const index = try f.resolveInst(bin_op.rhs); |
| 3174 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3155 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3175 | 3156 | ||
| 3176 | const target = f.object.dg.module.getTarget(); | ||
| 3177 | const is_array = lowersToArray(inst_ty, target); | ||
| 3178 | |||
| 3179 | const local = try f.allocLocal(inst, inst_ty); | ||
| 3180 | const writer = f.object.writer(); | 3157 | const writer = f.object.writer(); |
| 3181 | if (is_array) { | 3158 | const local = try f.allocLocal(inst, inst_ty); |
| 3182 | try writer.writeAll("memcpy("); | 3159 | const a = try Assignment.start(f, writer, inst_ty); |
| 3183 | try f.writeCValue(writer, local, .FunctionArgument); | 3160 | try f.writeCValue(writer, local, .Other); |
| 3184 | try writer.writeAll(", "); | 3161 | try a.assign(f, writer); |
| 3185 | } else { | 3162 | try f.writeCValueMember(writer, slice, .{ .identifier = "ptr" }); |
| 3186 | try f.writeCValue(writer, local, .Other); | 3163 | try writer.writeByte('['); |
| 3187 | try writer.writeAll(" = "); | ||
| 3188 | } | ||
| 3189 | try f.writeCValue(writer, slice, .Other); | ||
| 3190 | try writer.writeAll(".ptr["); | ||
| 3191 | try f.writeCValue(writer, index, .Other); | 3164 | try f.writeCValue(writer, index, .Other); |
| 3192 | try writer.writeByte(']'); | 3165 | try writer.writeByte(']'); |
| 3193 | if (is_array) { | 3166 | try a.end(f, writer); |
| 3194 | try writer.writeAll(", sizeof("); | ||
| 3195 | try f.renderType(writer, inst_ty); | ||
| 3196 | try writer.writeAll("))"); | ||
| 3197 | } | ||
| 3198 | try writer.writeAll(";\n"); | ||
| 3199 | return local; | 3167 | return local; |
| 3200 | } | 3168 | } |
| 3201 | 3169 | ||
| ... | @@ -3203,25 +3171,28 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3203,25 +3171,28 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3203 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | 3171 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; |
| 3204 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; | 3172 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 3205 | 3173 | ||
| 3174 | const inst_ty = f.air.typeOfIndex(inst); | ||
| 3206 | const slice_ty = f.air.typeOf(bin_op.lhs); | 3175 | const slice_ty = f.air.typeOf(bin_op.lhs); |
| 3207 | const child_ty = slice_ty.elemType2(); | 3176 | const elem_ty = slice_ty.elemType2(); |
| 3177 | const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(); | ||
| 3178 | |||
| 3208 | const slice = try f.resolveInst(bin_op.lhs); | 3179 | const slice = try f.resolveInst(bin_op.lhs); |
| 3209 | const index = try f.resolveInst(bin_op.rhs); | 3180 | const index = try f.resolveInst(bin_op.rhs); |
| 3210 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3181 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3211 | 3182 | ||
| 3212 | const writer = f.object.writer(); | 3183 | const writer = f.object.writer(); |
| 3213 | const local = try f.allocLocal(inst, f.air.typeOfIndex(inst)); | 3184 | const local = try f.allocLocal(inst, inst_ty); |
| 3185 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 3214 | try f.writeCValue(writer, local, .Other); | 3186 | try f.writeCValue(writer, local, .Other); |
| 3215 | try writer.writeAll(" = "); | 3187 | try a.assign(f, writer); |
| 3216 | if (child_ty.hasRuntimeBitsIgnoreComptime()) try writer.writeByte('&'); | 3188 | if (elem_has_bits) try writer.writeByte('&'); |
| 3217 | try f.writeCValue(writer, slice, .Other); | 3189 | try f.writeCValueMember(writer, slice, .{ .identifier = "ptr" }); |
| 3218 | try writer.writeAll(".ptr"); | 3190 | if (elem_has_bits) { |
| 3219 | if (child_ty.hasRuntimeBitsIgnoreComptime()) { | ||
| 3220 | try writer.writeByte('['); | 3191 | try writer.writeByte('['); |
| 3221 | try f.writeCValue(writer, index, .Other); | 3192 | try f.writeCValue(writer, index, .Other); |
| 3222 | try writer.writeByte(']'); | 3193 | try writer.writeByte(']'); |
| 3223 | } | 3194 | } |
| 3224 | try writer.writeAll(";\n"); | 3195 | try a.end(f, writer); |
| 3225 | return local; | 3196 | return local; |
| 3226 | } | 3197 | } |
| 3227 | 3198 | ||
| ... | @@ -3237,29 +3208,16 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3237,29 +3208,16 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3237 | const index = try f.resolveInst(bin_op.rhs); | 3208 | const index = try f.resolveInst(bin_op.rhs); |
| 3238 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3209 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3239 | 3210 | ||
| 3240 | const target = f.object.dg.module.getTarget(); | ||
| 3241 | const is_array = lowersToArray(inst_ty, target); | ||
| 3242 | |||
| 3243 | const local = try f.allocLocal(inst, inst_ty); | ||
| 3244 | const writer = f.object.writer(); | 3211 | const writer = f.object.writer(); |
| 3245 | if (is_array) { | 3212 | const local = try f.allocLocal(inst, inst_ty); |
| 3246 | try writer.writeAll("memcpy("); | 3213 | const a = try Assignment.start(f, writer, inst_ty); |
| 3247 | try f.writeCValue(writer, local, .FunctionArgument); | 3214 | try f.writeCValue(writer, local, .Other); |
| 3248 | try writer.writeAll(", "); | 3215 | try a.assign(f, writer); |
| 3249 | } else { | ||
| 3250 | try f.writeCValue(writer, local, .Other); | ||
| 3251 | try writer.writeAll(" = "); | ||
| 3252 | } | ||
| 3253 | try f.writeCValue(writer, array, .Other); | 3216 | try f.writeCValue(writer, array, .Other); |
| 3254 | try writer.writeByte('['); | 3217 | try writer.writeByte('['); |
| 3255 | try f.writeCValue(writer, index, .Other); | 3218 | try f.writeCValue(writer, index, .Other); |
| 3256 | try writer.writeByte(']'); | 3219 | try writer.writeByte(']'); |
| 3257 | if (is_array) { | 3220 | try a.end(f, writer); |
| 3258 | try writer.writeAll(", sizeof("); | ||
| 3259 | try f.renderType(writer, inst_ty); | ||
| 3260 | try writer.writeAll("))"); | ||
| 3261 | } | ||
| 3262 | try writer.writeAll(";\n"); | ||
| 3263 | return local; | 3221 | return local; |
| 3264 | } | 3222 | } |
| 3265 | 3223 | ||
| ... | @@ -3343,7 +3301,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3343,7 +3301,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3343 | 3301 | ||
| 3344 | const writer = f.object.writer(); | 3302 | const writer = f.object.writer(); |
| 3345 | const local = try f.allocLocal(inst, src_ty); | 3303 | const local = try f.allocLocal(inst, src_ty); |
| 3346 | const v = try Vectorizer.start(f, inst, writer, ptr_ty); | 3304 | const v = try Vectorize.start(f, inst, writer, ptr_ty); |
| 3347 | 3305 | ||
| 3348 | if (need_memcpy) { | 3306 | if (need_memcpy) { |
| 3349 | try writer.writeAll("memcpy("); | 3307 | try writer.writeAll("memcpy("); |
| ... | @@ -3484,12 +3442,13 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3484,12 +3442,13 @@ fn airIntCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3484 | 3442 | ||
| 3485 | const writer = f.object.writer(); | 3443 | const writer = f.object.writer(); |
| 3486 | const local = try f.allocLocal(inst, inst_ty); | 3444 | const local = try f.allocLocal(inst, inst_ty); |
| 3487 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 3445 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 3446 | const a = try Assignment.start(f, writer, scalar_ty); | ||
| 3488 | try f.writeCValue(writer, local, .Other); | 3447 | try f.writeCValue(writer, local, .Other); |
| 3489 | try v.elem(f, writer); | 3448 | try v.elem(f, writer); |
| 3490 | try writer.writeAll(" = "); | 3449 | try a.assign(f, writer); |
| 3491 | try f.renderIntCast(writer, inst_scalar_ty, operand, v, scalar_ty, .Other); | 3450 | try f.renderIntCast(writer, inst_scalar_ty, operand, v, scalar_ty, .Other); |
| 3492 | try writer.writeAll(";\n"); | 3451 | try a.end(f, writer); |
| 3493 | try v.end(f, inst, writer); | 3452 | try v.end(f, inst, writer); |
| 3494 | 3453 | ||
| 3495 | return local; | 3454 | return local; |
| ... | @@ -3513,7 +3472,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3513,7 +3472,7 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3513 | 3472 | ||
| 3514 | const writer = f.object.writer(); | 3473 | const writer = f.object.writer(); |
| 3515 | const local = try f.allocLocal(inst, inst_ty); | 3474 | const local = try f.allocLocal(inst, inst_ty); |
| 3516 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 3475 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 3517 | 3476 | ||
| 3518 | try f.writeCValue(writer, local, .Other); | 3477 | try f.writeCValue(writer, local, .Other); |
| 3519 | try v.elem(f, writer); | 3478 | try v.elem(f, writer); |
| ... | @@ -3564,13 +3523,13 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3564,13 +3523,13 @@ fn airTrunc(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3564 | try writer.writeAll("zig_shr_"); | 3523 | try writer.writeAll("zig_shr_"); |
| 3565 | try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty); | 3524 | try f.object.dg.renderTypeForBuiltinFnName(writer, scalar_ty); |
| 3566 | if (c_bits == 128) { | 3525 | if (c_bits == 128) { |
| 3567 | try writer.print("(zig_bitcast_i{d}(", .{c_bits}); | 3526 | try writer.print("(zig_bitCast_i{d}(", .{c_bits}); |
| 3568 | } else { | 3527 | } else { |
| 3569 | try writer.print("((int{d}_t)", .{c_bits}); | 3528 | try writer.print("((int{d}_t)", .{c_bits}); |
| 3570 | } | 3529 | } |
| 3571 | try writer.print("zig_shl_u{d}(", .{c_bits}); | 3530 | try writer.print("zig_shl_u{d}(", .{c_bits}); |
| 3572 | if (c_bits == 128) { | 3531 | if (c_bits == 128) { |
| 3573 | try writer.print("zig_bitcast_u{d}(", .{c_bits}); | 3532 | try writer.print("zig_bitCast_u{d}(", .{c_bits}); |
| 3574 | } else { | 3533 | } else { |
| 3575 | try writer.print("(uint{d}_t)", .{c_bits}); | 3534 | try writer.print("(uint{d}_t)", .{c_bits}); |
| 3576 | } | 3535 | } |
| ... | @@ -3597,10 +3556,11 @@ fn airBoolToInt(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3597,10 +3556,11 @@ fn airBoolToInt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3597 | const writer = f.object.writer(); | 3556 | const writer = f.object.writer(); |
| 3598 | const inst_ty = f.air.typeOfIndex(inst); | 3557 | const inst_ty = f.air.typeOfIndex(inst); |
| 3599 | const local = try f.allocLocal(inst, inst_ty); | 3558 | const local = try f.allocLocal(inst, inst_ty); |
| 3559 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 3600 | try f.writeCValue(writer, local, .Other); | 3560 | try f.writeCValue(writer, local, .Other); |
| 3601 | try writer.writeAll(" = "); | 3561 | try a.assign(f, writer); |
| 3602 | try f.writeCValue(writer, operand, .Other); | 3562 | try f.writeCValue(writer, operand, .Other); |
| 3603 | try writer.writeAll(";\n"); | 3563 | try a.end(f, writer); |
| 3604 | return local; | 3564 | return local; |
| 3605 | } | 3565 | } |
| 3606 | 3566 | ||
| ... | @@ -3632,8 +3592,13 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3632,8 +3592,13 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3632 | const src_val_is_undefined = | 3592 | const src_val_is_undefined = |
| 3633 | if (f.air.value(bin_op.rhs)) |v| v.isUndefDeep() else false; | 3593 | if (f.air.value(bin_op.rhs)) |v| v.isUndefDeep() else false; |
| 3634 | if (src_val_is_undefined) { | 3594 | if (src_val_is_undefined) { |
| 3635 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3595 | if (ptr_info.host_size == 0) { |
| 3636 | return try storeUndefined(f, ptr_info.pointee_type, ptr_val); | 3596 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3597 | return try storeUndefined(f, ptr_info.pointee_type, ptr_val); | ||
| 3598 | } else if (!f.wantSafety()) { | ||
| 3599 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | ||
| 3600 | return .none; | ||
| 3601 | } | ||
| 3637 | } | 3602 | } |
| 3638 | 3603 | ||
| 3639 | const target = f.object.dg.module.getTarget(); | 3604 | const target = f.object.dg.module.getTarget(); |
| ... | @@ -3646,7 +3611,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3646,7 +3611,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3646 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 3611 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 3647 | 3612 | ||
| 3648 | const writer = f.object.writer(); | 3613 | const writer = f.object.writer(); |
| 3649 | const v = try Vectorizer.start(f, inst, writer, ptr_ty); | 3614 | const v = try Vectorize.start(f, inst, writer, ptr_ty); |
| 3650 | 3615 | ||
| 3651 | if (need_memcpy) { | 3616 | if (need_memcpy) { |
| 3652 | // For this memcpy to safely work we need the rhs to have the same | 3617 | // For this memcpy to safely work we need the rhs to have the same |
| ... | @@ -3775,7 +3740,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: | ... | @@ -3775,7 +3740,7 @@ fn airOverflow(f: *Function, inst: Air.Inst.Index, operation: []const u8, info: |
| 3775 | 3740 | ||
| 3776 | const w = f.object.writer(); | 3741 | const w = f.object.writer(); |
| 3777 | const local = try f.allocLocal(inst, inst_ty); | 3742 | const local = try f.allocLocal(inst, inst_ty); |
| 3778 | const v = try Vectorizer.start(f, inst, w, operand_ty); | 3743 | const v = try Vectorize.start(f, inst, w, operand_ty); |
| 3779 | try f.writeCValueMember(w, local, .{ .field = 1 }); | 3744 | try f.writeCValueMember(w, local, .{ .field = 1 }); |
| 3780 | try v.elem(f, w); | 3745 | try v.elem(f, w); |
| 3781 | try w.writeAll(" = zig_"); | 3746 | try w.writeAll(" = zig_"); |
| ... | @@ -3811,7 +3776,7 @@ fn airNot(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -3811,7 +3776,7 @@ fn airNot(f: *Function, inst: Air.Inst.Index) !CValue { |
| 3811 | 3776 | ||
| 3812 | const writer = f.object.writer(); | 3777 | const writer = f.object.writer(); |
| 3813 | const local = try f.allocLocal(inst, inst_ty); | 3778 | const local = try f.allocLocal(inst, inst_ty); |
| 3814 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 3779 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 3815 | try f.writeCValue(writer, local, .Other); | 3780 | try f.writeCValue(writer, local, .Other); |
| 3816 | try v.elem(f, writer); | 3781 | try v.elem(f, writer); |
| 3817 | try writer.writeAll(" = "); | 3782 | try writer.writeAll(" = "); |
| ... | @@ -3846,7 +3811,7 @@ fn airBinOp( | ... | @@ -3846,7 +3811,7 @@ fn airBinOp( |
| 3846 | 3811 | ||
| 3847 | const writer = f.object.writer(); | 3812 | const writer = f.object.writer(); |
| 3848 | const local = try f.allocLocal(inst, inst_ty); | 3813 | const local = try f.allocLocal(inst, inst_ty); |
| 3849 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 3814 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 3850 | try f.writeCValue(writer, local, .Other); | 3815 | try f.writeCValue(writer, local, .Other); |
| 3851 | try v.elem(f, writer); | 3816 | try v.elem(f, writer); |
| 3852 | try writer.writeAll(" = "); | 3817 | try writer.writeAll(" = "); |
| ... | @@ -3893,7 +3858,7 @@ fn airCmpOp( | ... | @@ -3893,7 +3858,7 @@ fn airCmpOp( |
| 3893 | 3858 | ||
| 3894 | const writer = f.object.writer(); | 3859 | const writer = f.object.writer(); |
| 3895 | const local = try f.allocLocal(inst, inst_ty); | 3860 | const local = try f.allocLocal(inst, inst_ty); |
| 3896 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 3861 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 3897 | try f.writeCValue(writer, local, .Other); | 3862 | try f.writeCValue(writer, local, .Other); |
| 3898 | try v.elem(f, writer); | 3863 | try v.elem(f, writer); |
| 3899 | try writer.writeAll(" = "); | 3864 | try writer.writeAll(" = "); |
| ... | @@ -3942,7 +3907,7 @@ fn airEquality( | ... | @@ -3942,7 +3907,7 @@ fn airEquality( |
| 3942 | try f.writeCValue(writer, local, .Other); | 3907 | try f.writeCValue(writer, local, .Other); |
| 3943 | try writer.writeAll(" = "); | 3908 | try writer.writeAll(" = "); |
| 3944 | 3909 | ||
| 3945 | if (operand_ty.zigTypeTag() == .Optional and !operand_ty.isPtrLikeOptional()) { | 3910 | if (operand_ty.zigTypeTag() == .Optional and !operand_ty.optionalReprIsPayload()) { |
| 3946 | // (A && B) || (C && (A == B)) | 3911 | // (A && B) || (C && (A == B)) |
| 3947 | // A = lhs.is_null ; B = rhs.is_null ; C = rhs.payload == lhs.payload | 3912 | // A = lhs.is_null ; B = rhs.is_null ; C = rhs.payload == lhs.payload |
| 3948 | 3913 | ||
| ... | @@ -4008,7 +3973,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue { | ... | @@ -4008,7 +3973,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue { |
| 4008 | 3973 | ||
| 4009 | const local = try f.allocLocal(inst, inst_ty); | 3974 | const local = try f.allocLocal(inst, inst_ty); |
| 4010 | const writer = f.object.writer(); | 3975 | const writer = f.object.writer(); |
| 4011 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 3976 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 4012 | try f.writeCValue(writer, local, .Other); | 3977 | try f.writeCValue(writer, local, .Other); |
| 4013 | try v.elem(f, writer); | 3978 | try v.elem(f, writer); |
| 4014 | try writer.writeAll(" = "); | 3979 | try writer.writeAll(" = "); |
| ... | @@ -4059,7 +4024,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons | ... | @@ -4059,7 +4024,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons |
| 4059 | 4024 | ||
| 4060 | const writer = f.object.writer(); | 4025 | const writer = f.object.writer(); |
| 4061 | const local = try f.allocLocal(inst, inst_ty); | 4026 | const local = try f.allocLocal(inst, inst_ty); |
| 4062 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 4027 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 4063 | try f.writeCValue(writer, local, .Other); | 4028 | try f.writeCValue(writer, local, .Other); |
| 4064 | try v.elem(f, writer); | 4029 | try v.elem(f, writer); |
| 4065 | // (lhs <> rhs) ? lhs : rhs | 4030 | // (lhs <> rhs) ? lhs : rhs |
| ... | @@ -4091,21 +4056,29 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4091,21 +4056,29 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4091 | const len = try f.resolveInst(bin_op.rhs); | 4056 | const len = try f.resolveInst(bin_op.rhs); |
| 4092 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 4057 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 4093 | 4058 | ||
| 4094 | const writer = f.object.writer(); | ||
| 4095 | const inst_ty = f.air.typeOfIndex(inst); | 4059 | const inst_ty = f.air.typeOfIndex(inst); |
| 4096 | const local = try f.allocLocal(inst, inst_ty); | ||
| 4097 | try f.writeCValue(writer, local, .Other); | ||
| 4098 | try writer.writeAll(".ptr = ("); | ||
| 4099 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; | 4060 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 4100 | try f.renderType(writer, inst_ty.slicePtrFieldType(&buf)); | 4061 | const ptr_ty = inst_ty.slicePtrFieldType(&buf); |
| 4101 | try writer.writeByte(')'); | ||
| 4102 | try f.writeCValue(writer, ptr, .Other); | ||
| 4103 | try writer.writeAll("; "); | ||
| 4104 | try f.writeCValue(writer, local, .Other); | ||
| 4105 | try writer.writeAll(".len = "); | ||
| 4106 | try f.writeCValue(writer, len, .Initializer); | ||
| 4107 | try writer.writeAll(";\n"); | ||
| 4108 | 4062 | ||
| 4063 | const writer = f.object.writer(); | ||
| 4064 | const local = try f.allocLocal(inst, inst_ty); | ||
| 4065 | { | ||
| 4066 | const a = try Assignment.start(f, writer, ptr_ty); | ||
| 4067 | try f.writeCValueMember(writer, local, .{ .identifier = "ptr" }); | ||
| 4068 | try a.assign(f, writer); | ||
| 4069 | try writer.writeByte('('); | ||
| 4070 | try f.renderType(writer, ptr_ty); | ||
| 4071 | try writer.writeByte(')'); | ||
| 4072 | try f.writeCValue(writer, ptr, .Other); | ||
| 4073 | try a.end(f, writer); | ||
| 4074 | } | ||
| 4075 | { | ||
| 4076 | const a = try Assignment.start(f, writer, Type.usize); | ||
| 4077 | try f.writeCValueMember(writer, local, .{ .identifier = "len" }); | ||
| 4078 | try a.assign(f, writer); | ||
| 4079 | try f.writeCValue(writer, len, .Other); | ||
| 4080 | try a.end(f, writer); | ||
| 4081 | } | ||
| 4109 | return local; | 4082 | return local; |
| 4110 | } | 4083 | } |
| 4111 | 4084 | ||
| ... | @@ -4346,10 +4319,10 @@ fn lowerTry( | ... | @@ -4346,10 +4319,10 @@ fn lowerTry( |
| 4346 | operand: Air.Inst.Ref, | 4319 | operand: Air.Inst.Ref, |
| 4347 | body: []const Air.Inst.Index, | 4320 | body: []const Air.Inst.Index, |
| 4348 | err_union_ty: Type, | 4321 | err_union_ty: Type, |
| 4349 | operand_is_ptr: bool, | 4322 | is_ptr: bool, |
| 4350 | ) !CValue { | 4323 | ) !CValue { |
| 4351 | const err_union = try f.resolveInst(operand); | 4324 | const err_union = try f.resolveInst(operand); |
| 4352 | const result_ty = f.air.typeOfIndex(inst); | 4325 | const inst_ty = f.air.typeOfIndex(inst); |
| 4353 | const liveness_condbr = f.liveness.getCondBr(inst); | 4326 | const liveness_condbr = f.liveness.getCondBr(inst); |
| 4354 | const writer = f.object.writer(); | 4327 | const writer = f.object.writer(); |
| 4355 | const payload_ty = err_union_ty.errorUnionPayload(); | 4328 | const payload_ty = err_union_ty.errorUnionPayload(); |
| ... | @@ -4358,7 +4331,7 @@ fn lowerTry( | ... | @@ -4358,7 +4331,7 @@ fn lowerTry( |
| 4358 | if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) { | 4331 | if (!err_union_ty.errorUnionSet().errorSetIsEmpty()) { |
| 4359 | try writer.writeAll("if ("); | 4332 | try writer.writeAll("if ("); |
| 4360 | if (!payload_has_bits) { | 4333 | if (!payload_has_bits) { |
| 4361 | if (operand_is_ptr) | 4334 | if (is_ptr) |
| 4362 | try f.writeCValueDeref(writer, err_union) | 4335 | try f.writeCValueDeref(writer, err_union) |
| 4363 | else | 4336 | else |
| 4364 | try f.writeCValue(writer, err_union, .Other); | 4337 | try f.writeCValue(writer, err_union, .Other); |
| ... | @@ -4367,7 +4340,7 @@ fn lowerTry( | ... | @@ -4367,7 +4340,7 @@ fn lowerTry( |
| 4367 | // Remember we must avoid calling reap() twice for the same operand | 4340 | // Remember we must avoid calling reap() twice for the same operand |
| 4368 | // in this function. | 4341 | // in this function. |
| 4369 | try reap(f, inst, &.{operand}); | 4342 | try reap(f, inst, &.{operand}); |
| 4370 | if (operand_is_ptr or isByRef(err_union_ty)) | 4343 | if (is_ptr) |
| 4371 | try f.writeCValueDerefMember(writer, err_union, .{ .identifier = "error" }) | 4344 | try f.writeCValueDerefMember(writer, err_union, .{ .identifier = "error" }) |
| 4372 | else | 4345 | else |
| 4373 | try f.writeCValueMember(writer, err_union, .{ .identifier = "error" }); | 4346 | try f.writeCValueMember(writer, err_union, .{ .identifier = "error" }); |
| ... | @@ -4384,7 +4357,7 @@ fn lowerTry( | ... | @@ -4384,7 +4357,7 @@ fn lowerTry( |
| 4384 | } | 4357 | } |
| 4385 | 4358 | ||
| 4386 | if (!payload_has_bits) { | 4359 | if (!payload_has_bits) { |
| 4387 | if (!operand_is_ptr) { | 4360 | if (!is_ptr) { |
| 4388 | return .none; | 4361 | return .none; |
| 4389 | } else { | 4362 | } else { |
| 4390 | return err_union; | 4363 | return err_union; |
| ... | @@ -4397,26 +4370,15 @@ fn lowerTry( | ... | @@ -4397,26 +4370,15 @@ fn lowerTry( |
| 4397 | return .none; | 4370 | return .none; |
| 4398 | } | 4371 | } |
| 4399 | 4372 | ||
| 4400 | const target = f.object.dg.module.getTarget(); | 4373 | const local = try f.allocLocal(inst, inst_ty); |
| 4401 | const is_array = lowersToArray(payload_ty, target); | 4374 | const a = try Assignment.start(f, writer, inst_ty); |
| 4402 | const local = try f.allocLocal(inst, result_ty); | 4375 | try f.writeCValue(writer, local, .Other); |
| 4403 | if (is_array) { | 4376 | try a.assign(f, writer); |
| 4404 | try writer.writeAll("memcpy("); | 4377 | if (is_ptr) { |
| 4405 | try f.writeCValue(writer, local, .FunctionArgument); | 4378 | try writer.writeByte('&'); |
| 4406 | try writer.writeAll(", "); | 4379 | try f.writeCValueDerefMember(writer, err_union, .{ .identifier = "payload" }); |
| 4407 | try f.writeCValueMember(writer, err_union, .{ .identifier = "payload" }); | 4380 | } else try f.writeCValueMember(writer, err_union, .{ .identifier = "payload" }); |
| 4408 | try writer.writeAll(", sizeof("); | 4381 | try a.end(f, writer); |
| 4409 | try f.renderType(writer, payload_ty); | ||
| 4410 | try writer.writeAll("));\n"); | ||
| 4411 | } else { | ||
| 4412 | try f.writeCValue(writer, local, .Other); | ||
| 4413 | try writer.writeAll(" = "); | ||
| 4414 | if (operand_is_ptr or isByRef(payload_ty)) { | ||
| 4415 | try writer.writeByte('&'); | ||
| 4416 | try f.writeCValueDerefMember(writer, err_union, .{ .identifier = "payload" }); | ||
| 4417 | } else try f.writeCValueMember(writer, err_union, .{ .identifier = "payload" }); | ||
| 4418 | try writer.writeAll(";\n"); | ||
| 4419 | } | ||
| 4420 | return local; | 4382 | return local; |
| 4421 | } | 4383 | } |
| 4422 | 4384 | ||
| ... | @@ -4428,25 +4390,15 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4428,25 +4390,15 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4428 | 4390 | ||
| 4429 | // If result is .none then the value of the block is unused. | 4391 | // If result is .none then the value of the block is unused. |
| 4430 | if (result != .none) { | 4392 | if (result != .none) { |
| 4393 | const operand_ty = f.air.typeOf(branch.operand); | ||
| 4431 | const operand = try f.resolveInst(branch.operand); | 4394 | const operand = try f.resolveInst(branch.operand); |
| 4432 | try reap(f, inst, &.{branch.operand}); | 4395 | try reap(f, inst, &.{branch.operand}); |
| 4433 | 4396 | ||
| 4434 | const operand_ty = f.air.typeOf(branch.operand); | 4397 | const a = try Assignment.start(f, writer, operand_ty); |
| 4435 | const target = f.object.dg.module.getTarget(); | 4398 | try f.writeCValue(writer, result, .Other); |
| 4436 | if (lowersToArray(operand_ty, target)) { | 4399 | try a.assign(f, writer); |
| 4437 | try writer.writeAll("memcpy("); | 4400 | try f.writeCValue(writer, operand, .Other); |
| 4438 | try f.writeCValue(writer, result, .FunctionArgument); | 4401 | try a.end(f, writer); |
| 4439 | try writer.writeAll(", "); | ||
| 4440 | try f.writeCValue(writer, operand, .FunctionArgument); | ||
| 4441 | try writer.writeAll(", sizeof("); | ||
| 4442 | try f.renderType(writer, operand_ty); | ||
| 4443 | try writer.writeAll("))"); | ||
| 4444 | } else { | ||
| 4445 | try f.writeCValue(writer, result, .Other); | ||
| 4446 | try writer.writeAll(" = "); | ||
| 4447 | try f.writeCValue(writer, operand, .Other); | ||
| 4448 | } | ||
| 4449 | try writer.writeAll(";\n"); | ||
| 4450 | } | 4402 | } |
| 4451 | 4403 | ||
| 4452 | try writer.print("goto zig_block_{d};\n", .{block.block_id}); | 4404 | try writer.print("goto zig_block_{d};\n", .{block.block_id}); |
| ... | @@ -4532,7 +4484,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4532,7 +4484,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4532 | } | 4484 | } |
| 4533 | try writer.writeAll(" = "); | 4485 | try writer.writeAll(" = "); |
| 4534 | if (need_bitcasts) { | 4486 | if (need_bitcasts) { |
| 4535 | try writer.writeAll("zig_bitcast_"); | 4487 | try writer.writeAll("zig_bitCast_"); |
| 4536 | try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned()); | 4488 | try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?.toUnsigned()); |
| 4537 | try writer.writeByte('('); | 4489 | try writer.writeByte('('); |
| 4538 | } | 4490 | } |
| ... | @@ -4544,7 +4496,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4544,7 +4496,7 @@ fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4544 | try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty); | 4496 | try f.object.dg.renderTypeForBuiltinFnName(writer, info_ty); |
| 4545 | try writer.writeByte('('); | 4497 | try writer.writeByte('('); |
| 4546 | if (need_bitcasts) { | 4498 | if (need_bitcasts) { |
| 4547 | try writer.writeAll("zig_bitcast_"); | 4499 | try writer.writeAll("zig_bitCast_"); |
| 4548 | try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?); | 4500 | try f.object.dg.renderCTypeForBuiltinFnName(writer, wrap_cty.?); |
| 4549 | try writer.writeByte('('); | 4501 | try writer.writeByte('('); |
| 4550 | } | 4502 | } |
| ... | @@ -4771,7 +4723,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4771,7 +4723,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4771 | if (f.wantSafety()) { | 4723 | if (f.wantSafety()) { |
| 4772 | try f.writeCValue(writer, local, .Other); | 4724 | try f.writeCValue(writer, local, .Other); |
| 4773 | try writer.writeAll(" = "); | 4725 | try writer.writeAll(" = "); |
| 4774 | try f.writeCValue(writer, .{ .undef = inst_ty }, .Initializer); | 4726 | try f.writeCValue(writer, .{ .undef = inst_ty }, .Other); |
| 4775 | try writer.writeAll(";\n"); | 4727 | try writer.writeAll(";\n"); |
| 4776 | } | 4728 | } |
| 4777 | break :local local; | 4729 | break :local local; |
| ... | @@ -4806,7 +4758,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4806,7 +4758,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4806 | try writer.writeAll("\")"); | 4758 | try writer.writeAll("\")"); |
| 4807 | if (f.wantSafety()) { | 4759 | if (f.wantSafety()) { |
| 4808 | try writer.writeAll(" = "); | 4760 | try writer.writeAll(" = "); |
| 4809 | try f.writeCValue(writer, .{ .undef = output_ty }, .Initializer); | 4761 | try f.writeCValue(writer, .{ .undef = output_ty }, .Other); |
| 4810 | } | 4762 | } |
| 4811 | try writer.writeAll(";\n"); | 4763 | try writer.writeAll(";\n"); |
| 4812 | } | 4764 | } |
| ... | @@ -4840,7 +4792,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4840,7 +4792,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4840 | try writer.writeAll("\")"); | 4792 | try writer.writeAll("\")"); |
| 4841 | } | 4793 | } |
| 4842 | try writer.writeAll(" = "); | 4794 | try writer.writeAll(" = "); |
| 4843 | try f.writeCValue(writer, input_val, .Initializer); | 4795 | try f.writeCValue(writer, input_val, .Other); |
| 4844 | try writer.writeAll(";\n"); | 4796 | try writer.writeAll(";\n"); |
| 4845 | } | 4797 | } |
| 4846 | } | 4798 | } |
| ... | @@ -5072,8 +5024,8 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5072,8 +5024,8 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5072 | } | 5024 | } |
| 5073 | 5025 | ||
| 5074 | const inst_ty = f.air.typeOfIndex(inst); | 5026 | const inst_ty = f.air.typeOfIndex(inst); |
| 5075 | const local = try f.allocLocal(inst, inst_ty); | ||
| 5076 | const writer = f.object.writer(); | 5027 | const writer = f.object.writer(); |
| 5028 | const local = try f.allocLocal(inst, inst_ty); | ||
| 5077 | 5029 | ||
| 5078 | if (opt_ty.optionalReprIsPayload()) { | 5030 | if (opt_ty.optionalReprIsPayload()) { |
| 5079 | try f.writeCValue(writer, local, .Other); | 5031 | try f.writeCValue(writer, local, .Other); |
| ... | @@ -5083,24 +5035,11 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5083,24 +5035,11 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5083 | return local; | 5035 | return local; |
| 5084 | } | 5036 | } |
| 5085 | 5037 | ||
| 5086 | const target = f.object.dg.module.getTarget(); | 5038 | const a = try Assignment.start(f, writer, inst_ty); |
| 5087 | const is_array = lowersToArray(inst_ty, target); | 5039 | try f.writeCValue(writer, local, .Other); |
| 5088 | 5040 | try a.assign(f, writer); | |
| 5089 | if (is_array) { | ||
| 5090 | try writer.writeAll("memcpy("); | ||
| 5091 | try f.writeCValue(writer, local, .FunctionArgument); | ||
| 5092 | try writer.writeAll(", "); | ||
| 5093 | } else { | ||
| 5094 | try f.writeCValue(writer, local, .Other); | ||
| 5095 | try writer.writeAll(" = "); | ||
| 5096 | } | ||
| 5097 | try f.writeCValueMember(writer, operand, .{ .identifier = "payload" }); | 5041 | try f.writeCValueMember(writer, operand, .{ .identifier = "payload" }); |
| 5098 | if (is_array) { | 5042 | try a.end(f, writer); |
| 5099 | try writer.writeAll(", sizeof("); | ||
| 5100 | try f.renderType(writer, inst_ty); | ||
| 5101 | try writer.writeAll("))"); | ||
| 5102 | } | ||
| 5103 | try writer.writeAll(";\n"); | ||
| 5104 | return local; | 5043 | return local; |
| 5105 | } | 5044 | } |
| 5106 | 5045 | ||
| ... | @@ -5193,6 +5132,7 @@ fn fieldLocation( | ... | @@ -5193,6 +5132,7 @@ fn fieldLocation( |
| 5193 | if (container_ty.structFieldIsComptime(next_field_index)) continue; | 5132 | if (container_ty.structFieldIsComptime(next_field_index)) continue; |
| 5194 | const field_ty = container_ty.structFieldType(next_field_index); | 5133 | const field_ty = container_ty.structFieldType(next_field_index); |
| 5195 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 5134 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 5135 | |||
| 5196 | break .{ .field = if (container_ty.isSimpleTuple()) | 5136 | break .{ .field = if (container_ty.isSimpleTuple()) |
| 5197 | .{ .field = next_field_index } | 5137 | .{ .field = next_field_index } |
| 5198 | else | 5138 | else |
| ... | @@ -5437,13 +5377,17 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5437,13 +5377,17 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5437 | try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty); | 5377 | try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty); |
| 5438 | try writer.writeByte('('); | 5378 | try writer.writeByte('('); |
| 5439 | } | 5379 | } |
| 5440 | try writer.writeAll("zig_shr_"); | 5380 | if (bit_offset_val_pl.data > 0) { |
| 5441 | try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty); | 5381 | try writer.writeAll("zig_shr_"); |
| 5442 | try writer.writeByte('('); | 5382 | try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty); |
| 5383 | try writer.writeByte('('); | ||
| 5384 | } | ||
| 5443 | try f.writeCValue(writer, struct_byval, .Other); | 5385 | try f.writeCValue(writer, struct_byval, .Other); |
| 5444 | try writer.writeAll(", "); | 5386 | if (bit_offset_val_pl.data > 0) { |
| 5445 | try f.object.dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument); | 5387 | try writer.writeAll(", "); |
| 5446 | try writer.writeByte(')'); | 5388 | try f.object.dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument); |
| 5389 | try writer.writeByte(')'); | ||
| 5390 | } | ||
| 5447 | if (cant_cast) try writer.writeByte(')'); | 5391 | if (cant_cast) try writer.writeByte(')'); |
| 5448 | try f.object.dg.renderBuiltinInfo(writer, field_int_ty, .bits); | 5392 | try f.object.dg.renderBuiltinInfo(writer, field_int_ty, .bits); |
| 5449 | try writer.writeAll(");\n"); | 5393 | try writer.writeAll(");\n"); |
| ... | @@ -5473,9 +5417,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5473,9 +5417,9 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5473 | 5417 | ||
| 5474 | const local = try f.allocLocal(inst, inst_ty); | 5418 | const local = try f.allocLocal(inst, inst_ty); |
| 5475 | try writer.writeAll("memcpy(&"); | 5419 | try writer.writeAll("memcpy(&"); |
| 5476 | try f.writeCValue(writer, local, .FunctionArgument); | 5420 | try f.writeCValue(writer, local, .Other); |
| 5477 | try writer.writeAll(", &"); | 5421 | try writer.writeAll(", &"); |
| 5478 | try f.writeCValue(writer, operand_lval, .FunctionArgument); | 5422 | try f.writeCValue(writer, operand_lval, .Other); |
| 5479 | try writer.writeAll(", sizeof("); | 5423 | try writer.writeAll(", sizeof("); |
| 5480 | try f.renderType(writer, inst_ty); | 5424 | try f.renderType(writer, inst_ty); |
| 5481 | try writer.writeAll("));\n"); | 5425 | try writer.writeAll("));\n"); |
| ... | @@ -5496,20 +5440,11 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5496,20 +5440,11 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5496 | }; | 5440 | }; |
| 5497 | 5441 | ||
| 5498 | const local = try f.allocLocal(inst, inst_ty); | 5442 | const local = try f.allocLocal(inst, inst_ty); |
| 5499 | if (lowersToArray(inst_ty, target)) { | 5443 | const a = try Assignment.start(f, writer, inst_ty); |
| 5500 | try writer.writeAll("memcpy("); | 5444 | try f.writeCValue(writer, local, .Other); |
| 5501 | try f.writeCValue(writer, local, .FunctionArgument); | 5445 | try a.assign(f, writer); |
| 5502 | try writer.writeAll(", "); | 5446 | try f.writeCValueMember(writer, struct_byval, field_name); |
| 5503 | try f.writeCValueMember(writer, struct_byval, field_name); | 5447 | try a.end(f, writer); |
| 5504 | try writer.writeAll(", sizeof("); | ||
| 5505 | try f.renderType(writer, inst_ty); | ||
| 5506 | try writer.writeAll("))"); | ||
| 5507 | } else { | ||
| 5508 | try f.writeCValue(writer, local, .Other); | ||
| 5509 | try writer.writeAll(" = "); | ||
| 5510 | try f.writeCValueMember(writer, struct_byval, field_name); | ||
| 5511 | } | ||
| 5512 | try writer.writeAll(";\n"); | ||
| 5513 | return local; | 5448 | return local; |
| 5514 | } | 5449 | } |
| 5515 | 5450 | ||
| ... | @@ -5554,33 +5489,31 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu | ... | @@ -5554,33 +5489,31 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu |
| 5554 | const operand = try f.resolveInst(ty_op.operand); | 5489 | const operand = try f.resolveInst(ty_op.operand); |
| 5555 | try reap(f, inst, &.{ty_op.operand}); | 5490 | try reap(f, inst, &.{ty_op.operand}); |
| 5556 | const operand_ty = f.air.typeOf(ty_op.operand); | 5491 | const operand_ty = f.air.typeOf(ty_op.operand); |
| 5557 | const operand_is_ptr = operand_ty.zigTypeTag() == .Pointer; | 5492 | const error_union_ty = if (is_ptr) operand_ty.childType() else operand_ty; |
| 5558 | const error_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; | ||
| 5559 | 5493 | ||
| 5494 | const writer = f.object.writer(); | ||
| 5560 | if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) { | 5495 | if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) { |
| 5561 | if (!is_ptr) return .none; | 5496 | if (!is_ptr) return .none; |
| 5562 | 5497 | ||
| 5563 | const w = f.object.writer(); | ||
| 5564 | const local = try f.allocLocal(inst, inst_ty); | 5498 | const local = try f.allocLocal(inst, inst_ty); |
| 5565 | try f.writeCValue(w, local, .Other); | 5499 | try f.writeCValue(writer, local, .Other); |
| 5566 | try w.writeAll(" = ("); | 5500 | try writer.writeAll(" = ("); |
| 5567 | try f.renderType(w, inst_ty); | 5501 | try f.renderType(writer, inst_ty); |
| 5568 | try w.writeByte(')'); | 5502 | try writer.writeByte(')'); |
| 5569 | try f.writeCValue(w, operand, .Initializer); | 5503 | try f.writeCValue(writer, operand, .Initializer); |
| 5570 | try w.writeAll(";\n"); | 5504 | try writer.writeAll(";\n"); |
| 5571 | return local; | 5505 | return local; |
| 5572 | } | 5506 | } |
| 5573 | 5507 | ||
| 5574 | const writer = f.object.writer(); | ||
| 5575 | const local = try f.allocLocal(inst, inst_ty); | 5508 | const local = try f.allocLocal(inst, inst_ty); |
| 5509 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 5576 | try f.writeCValue(writer, local, .Other); | 5510 | try f.writeCValue(writer, local, .Other); |
| 5577 | try writer.writeAll(" = "); | 5511 | try a.assign(f, writer); |
| 5578 | if (is_ptr) try writer.writeByte('&'); | 5512 | if (is_ptr) { |
| 5579 | if (operand_is_ptr) | 5513 | try writer.writeByte('&'); |
| 5580 | try f.writeCValueDerefMember(writer, operand, .{ .identifier = "payload" }) | 5514 | try f.writeCValueDerefMember(writer, operand, .{ .identifier = "payload" }); |
| 5581 | else | 5515 | } else try f.writeCValueMember(writer, operand, .{ .identifier = "payload" }); |
| 5582 | try f.writeCValueMember(writer, operand, .{ .identifier = "payload" }); | 5516 | try a.end(f, writer); |
| 5583 | try writer.writeAll(";\n"); | ||
| 5584 | return local; | 5517 | return local; |
| 5585 | } | 5518 | } |
| 5586 | 5519 | ||
| ... | @@ -5588,40 +5521,29 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5588,40 +5521,29 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5588 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | 5521 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 5589 | 5522 | ||
| 5590 | const inst_ty = f.air.typeOfIndex(inst); | 5523 | const inst_ty = f.air.typeOfIndex(inst); |
| 5524 | const repr_is_payload = inst_ty.optionalReprIsPayload(); | ||
| 5525 | const payload_ty = f.air.typeOf(ty_op.operand); | ||
| 5591 | const payload = try f.resolveInst(ty_op.operand); | 5526 | const payload = try f.resolveInst(ty_op.operand); |
| 5592 | try reap(f, inst, &.{ty_op.operand}); | 5527 | try reap(f, inst, &.{ty_op.operand}); |
| 5593 | const writer = f.object.writer(); | ||
| 5594 | |||
| 5595 | if (inst_ty.optionalReprIsPayload()) { | ||
| 5596 | const local = try f.allocLocal(inst, inst_ty); | ||
| 5597 | try f.writeCValue(writer, local, .Other); | ||
| 5598 | try writer.writeAll(" = "); | ||
| 5599 | try f.writeCValue(writer, payload, .Other); | ||
| 5600 | try writer.writeAll(";\n"); | ||
| 5601 | return local; | ||
| 5602 | } | ||
| 5603 | |||
| 5604 | const payload_ty = f.air.typeOf(ty_op.operand); | ||
| 5605 | const target = f.object.dg.module.getTarget(); | ||
| 5606 | const is_array = lowersToArray(payload_ty, target); | ||
| 5607 | 5528 | ||
| 5529 | const writer = f.object.writer(); | ||
| 5608 | const local = try f.allocLocal(inst, inst_ty); | 5530 | const local = try f.allocLocal(inst, inst_ty); |
| 5609 | if (!is_array) { | 5531 | { |
| 5610 | try f.writeCValue(writer, local, .Other); | 5532 | const a = try Assignment.start(f, writer, payload_ty); |
| 5611 | try writer.writeAll(".payload = "); | 5533 | if (repr_is_payload) |
| 5534 | try f.writeCValue(writer, local, .Other) | ||
| 5535 | else | ||
| 5536 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); | ||
| 5537 | try a.assign(f, writer); | ||
| 5612 | try f.writeCValue(writer, payload, .Other); | 5538 | try f.writeCValue(writer, payload, .Other); |
| 5613 | try writer.writeAll("; "); | 5539 | try a.end(f, writer); |
| 5614 | } | 5540 | } |
| 5615 | try f.writeCValue(writer, local, .Other); | 5541 | if (!repr_is_payload) { |
| 5616 | try writer.writeAll(".is_null = false;\n"); | 5542 | const a = try Assignment.start(f, writer, Type.bool); |
| 5617 | if (is_array) { | 5543 | try f.writeCValueMember(writer, local, .{ .identifier = "is_null" }); |
| 5618 | try writer.writeAll("memcpy("); | 5544 | try a.assign(f, writer); |
| 5619 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); | 5545 | try f.object.dg.renderValue(writer, Type.bool, Value.false, .Other); |
| 5620 | try writer.writeAll(", "); | 5546 | try a.end(f, writer); |
| 5621 | try f.writeCValue(writer, payload, .FunctionArgument); | ||
| 5622 | try writer.writeAll(", sizeof("); | ||
| 5623 | try f.renderType(writer, payload_ty); | ||
| 5624 | try writer.writeAll("));\n"); | ||
| 5625 | } | 5547 | } |
| 5626 | return local; | 5548 | return local; |
| 5627 | } | 5549 | } |
| ... | @@ -5629,29 +5551,32 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5629,29 +5551,32 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5629 | fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { | 5551 | fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5630 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; | 5552 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 5631 | 5553 | ||
| 5632 | const writer = f.object.writer(); | 5554 | const inst_ty = f.air.typeOfIndex(inst); |
| 5633 | const operand = try f.resolveInst(ty_op.operand); | 5555 | const payload_ty = inst_ty.errorUnionPayload(); |
| 5556 | const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(); | ||
| 5557 | const err_ty = inst_ty.errorUnionSet(); | ||
| 5558 | const err = try f.resolveInst(ty_op.operand); | ||
| 5634 | try reap(f, inst, &.{ty_op.operand}); | 5559 | try reap(f, inst, &.{ty_op.operand}); |
| 5635 | const error_union_ty = f.air.typeOfIndex(inst); | ||
| 5636 | const payload_ty = error_union_ty.errorUnionPayload(); | ||
| 5637 | const local = try f.allocLocal(inst, error_union_ty); | ||
| 5638 | 5560 | ||
| 5639 | if (!payload_ty.hasRuntimeBits()) { | 5561 | const writer = f.object.writer(); |
| 5640 | try f.writeCValue(writer, local, .Other); | 5562 | const local = try f.allocLocal(inst, inst_ty); |
| 5641 | try writer.writeAll(" = "); | 5563 | if (!repr_is_err) { |
| 5642 | try f.writeCValue(writer, operand, .Other); | 5564 | const a = try Assignment.start(f, writer, payload_ty); |
| 5643 | try writer.writeAll(";\n"); | 5565 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); |
| 5644 | return local; | 5566 | try a.assign(f, writer); |
| 5567 | try f.object.dg.renderValue(writer, payload_ty, Value.undef, .Other); | ||
| 5568 | try a.end(f, writer); | ||
| 5645 | } | 5569 | } |
| 5646 | |||
| 5647 | { | 5570 | { |
| 5648 | // TODO: set the payload to undefined | 5571 | const a = try Assignment.start(f, writer, err_ty); |
| 5649 | //try f.writeCValue(writer, local, .Other); | 5572 | if (repr_is_err) |
| 5573 | try f.writeCValue(writer, local, .Other) | ||
| 5574 | else | ||
| 5575 | try f.writeCValueMember(writer, local, .{ .identifier = "error" }); | ||
| 5576 | try a.assign(f, writer); | ||
| 5577 | try f.writeCValue(writer, err, .Other); | ||
| 5578 | try a.end(f, writer); | ||
| 5650 | } | 5579 | } |
| 5651 | try f.writeCValue(writer, local, .Other); | ||
| 5652 | try writer.writeAll(".error = "); | ||
| 5653 | try f.writeCValue(writer, operand, .Other); | ||
| 5654 | try writer.writeAll(";\n"); | ||
| 5655 | return local; | 5580 | return local; |
| 5656 | } | 5581 | } |
| 5657 | 5582 | ||
| ... | @@ -5711,29 +5636,28 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5711,29 +5636,28 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5711 | const inst_ty = f.air.typeOfIndex(inst); | 5636 | const inst_ty = f.air.typeOfIndex(inst); |
| 5712 | const payload_ty = inst_ty.errorUnionPayload(); | 5637 | const payload_ty = inst_ty.errorUnionPayload(); |
| 5713 | const payload = try f.resolveInst(ty_op.operand); | 5638 | const payload = try f.resolveInst(ty_op.operand); |
| 5639 | const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(); | ||
| 5640 | const err_ty = inst_ty.errorUnionSet(); | ||
| 5714 | try reap(f, inst, &.{ty_op.operand}); | 5641 | try reap(f, inst, &.{ty_op.operand}); |
| 5715 | 5642 | ||
| 5716 | const target = f.object.dg.module.getTarget(); | ||
| 5717 | const is_array = lowersToArray(payload_ty, target); | ||
| 5718 | |||
| 5719 | const writer = f.object.writer(); | 5643 | const writer = f.object.writer(); |
| 5720 | const local = try f.allocLocal(inst, inst_ty); | 5644 | const local = try f.allocLocal(inst, inst_ty); |
| 5721 | if (!is_array) { | 5645 | if (!repr_is_err) { |
| 5722 | try f.writeCValue(writer, local, .Other); | 5646 | const a = try Assignment.start(f, writer, payload_ty); |
| 5723 | try writer.writeAll(".payload = "); | 5647 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); |
| 5648 | try a.assign(f, writer); | ||
| 5724 | try f.writeCValue(writer, payload, .Other); | 5649 | try f.writeCValue(writer, payload, .Other); |
| 5725 | try writer.writeAll("; "); | 5650 | try a.end(f, writer); |
| 5726 | } | 5651 | } |
| 5727 | try f.writeCValue(writer, local, .Other); | 5652 | { |
| 5728 | try writer.writeAll(".error = 0;\n"); | 5653 | const a = try Assignment.start(f, writer, err_ty); |
| 5729 | if (is_array) { | 5654 | if (repr_is_err) |
| 5730 | try writer.writeAll("memcpy("); | 5655 | try f.writeCValue(writer, local, .Other) |
| 5731 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); | 5656 | else |
| 5732 | try writer.writeAll(", "); | 5657 | try f.writeCValueMember(writer, local, .{ .identifier = "error" }); |
| 5733 | try f.writeCValue(writer, payload, .FunctionArgument); | 5658 | try a.assign(f, writer); |
| 5734 | try writer.writeAll(", sizeof("); | 5659 | try f.object.dg.renderValue(writer, err_ty, Value.zero, .Other); |
| 5735 | try f.renderType(writer, payload_ty); | 5660 | try a.end(f, writer); |
| 5736 | try writer.writeAll("));\n"); | ||
| 5737 | } | 5661 | } |
| 5738 | return local; | 5662 | return local; |
| 5739 | } | 5663 | } |
| ... | @@ -5831,11 +5755,10 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -5831,11 +5755,10 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5831 | try f.object.dg.renderTypeForBuiltinFnName(writer, inst_ty); | 5755 | try f.object.dg.renderTypeForBuiltinFnName(writer, inst_ty); |
| 5832 | try writer.writeByte('('); | 5756 | try writer.writeByte('('); |
| 5833 | } | 5757 | } |
| 5834 | try writer.writeAll("__"); | 5758 | try writer.writeAll("zig_"); |
| 5835 | try writer.writeAll(operation); | 5759 | try writer.writeAll(operation); |
| 5836 | try writer.writeAll(compilerRtAbbrev(operand_ty, target)); | 5760 | try writer.writeAll(compilerRtAbbrev(operand_ty, target)); |
| 5837 | try writer.writeAll(compilerRtAbbrev(inst_ty, target)); | 5761 | try writer.writeAll(compilerRtAbbrev(inst_ty, target)); |
| 5838 | if (inst_ty.isRuntimeFloat() and operand_ty.isRuntimeFloat()) try writer.writeByte('2'); | ||
| 5839 | try writer.writeByte('('); | 5762 | try writer.writeByte('('); |
| 5840 | try f.writeCValue(writer, operand, .FunctionArgument); | 5763 | try f.writeCValue(writer, operand, .FunctionArgument); |
| 5841 | try writer.writeByte(')'); | 5764 | try writer.writeByte(')'); |
| ... | @@ -5885,7 +5808,7 @@ fn airUnBuiltinCall( | ... | @@ -5885,7 +5808,7 @@ fn airUnBuiltinCall( |
| 5885 | 5808 | ||
| 5886 | const writer = f.object.writer(); | 5809 | const writer = f.object.writer(); |
| 5887 | const local = try f.allocLocal(inst, inst_ty); | 5810 | const local = try f.allocLocal(inst, inst_ty); |
| 5888 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 5811 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 5889 | if (!ref_ret) { | 5812 | if (!ref_ret) { |
| 5890 | try f.writeCValue(writer, local, .Other); | 5813 | try f.writeCValue(writer, local, .Other); |
| 5891 | try v.elem(f, writer); | 5814 | try v.elem(f, writer); |
| ... | @@ -5934,7 +5857,7 @@ fn airBinBuiltinCall( | ... | @@ -5934,7 +5857,7 @@ fn airBinBuiltinCall( |
| 5934 | const writer = f.object.writer(); | 5857 | const writer = f.object.writer(); |
| 5935 | const local = try f.allocLocal(inst, inst_ty); | 5858 | const local = try f.allocLocal(inst, inst_ty); |
| 5936 | if (is_big) try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 5859 | if (is_big) try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 5937 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 5860 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 5938 | if (!ref_ret) { | 5861 | if (!ref_ret) { |
| 5939 | try f.writeCValue(writer, local, .Other); | 5862 | try f.writeCValue(writer, local, .Other); |
| 5940 | try v.elem(f, writer); | 5863 | try v.elem(f, writer); |
| ... | @@ -5982,7 +5905,7 @@ fn airCmpBuiltinCall( | ... | @@ -5982,7 +5905,7 @@ fn airCmpBuiltinCall( |
| 5982 | 5905 | ||
| 5983 | const writer = f.object.writer(); | 5906 | const writer = f.object.writer(); |
| 5984 | const local = try f.allocLocal(inst, inst_ty); | 5907 | const local = try f.allocLocal(inst, inst_ty); |
| 5985 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 5908 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 5986 | if (!ref_ret) { | 5909 | if (!ref_ret) { |
| 5987 | try f.writeCValue(writer, local, .Other); | 5910 | try f.writeCValue(writer, local, .Other); |
| 5988 | try v.elem(f, writer); | 5911 | try v.elem(f, writer); |
| ... | @@ -6023,18 +5946,33 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue | ... | @@ -6023,18 +5946,33 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue |
| 6023 | const ptr = try f.resolveInst(extra.ptr); | 5946 | const ptr = try f.resolveInst(extra.ptr); |
| 6024 | const expected_value = try f.resolveInst(extra.expected_value); | 5947 | const expected_value = try f.resolveInst(extra.expected_value); |
| 6025 | const new_value = try f.resolveInst(extra.new_value); | 5948 | const new_value = try f.resolveInst(extra.new_value); |
| 6026 | try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value }); | ||
| 6027 | const writer = f.object.writer(); | ||
| 6028 | const ptr_ty = f.air.typeOf(extra.ptr); | 5949 | const ptr_ty = f.air.typeOf(extra.ptr); |
| 5950 | const ty = ptr_ty.childType(); | ||
| 5951 | |||
| 5952 | const writer = f.object.writer(); | ||
| 5953 | const new_value_mat = try Materialize.start(f, inst, writer, ty, new_value); | ||
| 5954 | try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value }); | ||
| 5955 | |||
| 5956 | const target = f.object.dg.module.getTarget(); | ||
| 5957 | var repr_pl = Type.Payload.Bits{ | ||
| 5958 | .base = .{ .tag = .int_unsigned }, | ||
| 5959 | .data = @intCast(u16, ty.abiSize(target) * 8), | ||
| 5960 | }; | ||
| 5961 | const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty; | ||
| 5962 | |||
| 6029 | const local = try f.allocLocal(inst, inst_ty); | 5963 | const local = try f.allocLocal(inst, inst_ty); |
| 6030 | if (inst_ty.isPtrLikeOptional()) { | 5964 | if (inst_ty.isPtrLikeOptional()) { |
| 6031 | try f.writeCValue(writer, local, .Other); | 5965 | { |
| 6032 | try writer.writeAll(" = "); | 5966 | const a = try Assignment.start(f, writer, ty); |
| 6033 | try f.writeCValue(writer, expected_value, .Initializer); | 5967 | try f.writeCValue(writer, local, .Other); |
| 6034 | try writer.writeAll(";\n"); | 5968 | try a.assign(f, writer); |
| 5969 | try f.writeCValue(writer, expected_value, .Other); | ||
| 5970 | try a.end(f, writer); | ||
| 5971 | } | ||
| 5972 | |||
| 6035 | try writer.writeAll("if ("); | 5973 | try writer.writeAll("if ("); |
| 6036 | try writer.print("zig_cmpxchg_{s}((zig_atomic(", .{flavor}); | 5974 | try writer.print("zig_cmpxchg_{s}((zig_atomic(", .{flavor}); |
| 6037 | try f.renderType(writer, ptr_ty.childType()); | 5975 | try f.renderType(writer, ty); |
| 6038 | try writer.writeByte(')'); | 5976 | try writer.writeByte(')'); |
| 6039 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); | 5977 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); |
| 6040 | try writer.writeAll(" *)"); | 5978 | try writer.writeAll(" *)"); |
| ... | @@ -6042,45 +5980,62 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue | ... | @@ -6042,45 +5980,62 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue |
| 6042 | try writer.writeAll(", "); | 5980 | try writer.writeAll(", "); |
| 6043 | try f.writeCValue(writer, local, .FunctionArgument); | 5981 | try f.writeCValue(writer, local, .FunctionArgument); |
| 6044 | try writer.writeAll(", "); | 5982 | try writer.writeAll(", "); |
| 6045 | try f.writeCValue(writer, new_value, .FunctionArgument); | 5983 | try new_value_mat.mat(f, writer); |
| 6046 | try writer.writeAll(", "); | 5984 | try writer.writeAll(", "); |
| 6047 | try writeMemoryOrder(writer, extra.successOrder()); | 5985 | try writeMemoryOrder(writer, extra.successOrder()); |
| 6048 | try writer.writeAll(", "); | 5986 | try writer.writeAll(", "); |
| 6049 | try writeMemoryOrder(writer, extra.failureOrder()); | 5987 | try writeMemoryOrder(writer, extra.failureOrder()); |
| 6050 | try writer.writeAll(", "); | 5988 | try writer.writeAll(", "); |
| 6051 | try f.object.dg.renderTypeForBuiltinFnName(writer, ptr_ty.childType()); | 5989 | try f.object.dg.renderTypeForBuiltinFnName(writer, ty); |
| 5990 | try writer.writeAll(", "); | ||
| 5991 | try f.object.dg.renderType(writer, repr_ty); | ||
| 6052 | try writer.writeByte(')'); | 5992 | try writer.writeByte(')'); |
| 6053 | try writer.writeAll(") {\n"); | 5993 | try writer.writeAll(") {\n"); |
| 6054 | f.object.indent_writer.pushIndent(); | 5994 | f.object.indent_writer.pushIndent(); |
| 6055 | try f.writeCValue(writer, local, .Other); | 5995 | { |
| 6056 | try writer.writeAll(" = NULL;\n"); | 5996 | const a = try Assignment.start(f, writer, ty); |
| 5997 | try f.writeCValue(writer, local, .Other); | ||
| 5998 | try a.assign(f, writer); | ||
| 5999 | try writer.writeAll("NULL"); | ||
| 6000 | try a.end(f, writer); | ||
| 6001 | } | ||
| 6057 | f.object.indent_writer.popIndent(); | 6002 | f.object.indent_writer.popIndent(); |
| 6058 | try writer.writeAll("}\n"); | 6003 | try writer.writeAll("}\n"); |
| 6059 | } else { | 6004 | } else { |
| 6060 | try f.writeCValue(writer, local, .Other); | 6005 | { |
| 6061 | try writer.writeAll(".payload = "); | 6006 | const a = try Assignment.start(f, writer, ty); |
| 6062 | try f.writeCValue(writer, expected_value, .Other); | 6007 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); |
| 6063 | try writer.writeAll(";\n"); | 6008 | try a.assign(f, writer); |
| 6064 | try f.writeCValue(writer, local, .Other); | 6009 | try f.writeCValue(writer, expected_value, .Other); |
| 6065 | try writer.print(".is_null = zig_cmpxchg_{s}((zig_atomic(", .{flavor}); | 6010 | try a.end(f, writer); |
| 6066 | try f.renderType(writer, ptr_ty.childType()); | 6011 | } |
| 6067 | try writer.writeByte(')'); | 6012 | { |
| 6068 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); | 6013 | const a = try Assignment.start(f, writer, Type.bool); |
| 6069 | try writer.writeAll(" *)"); | 6014 | try f.writeCValueMember(writer, local, .{ .identifier = "is_null" }); |
| 6070 | try f.writeCValue(writer, ptr, .Other); | 6015 | try a.assign(f, writer); |
| 6071 | try writer.writeAll(", "); | 6016 | try writer.print("zig_cmpxchg_{s}((zig_atomic(", .{flavor}); |
| 6072 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); | 6017 | try f.renderType(writer, ty); |
| 6073 | try writer.writeAll(", "); | 6018 | try writer.writeByte(')'); |
| 6074 | try f.writeCValue(writer, new_value, .FunctionArgument); | 6019 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); |
| 6075 | try writer.writeAll(", "); | 6020 | try writer.writeAll(" *)"); |
| 6076 | try writeMemoryOrder(writer, extra.successOrder()); | 6021 | try f.writeCValue(writer, ptr, .Other); |
| 6077 | try writer.writeAll(", "); | 6022 | try writer.writeAll(", "); |
| 6078 | try writeMemoryOrder(writer, extra.failureOrder()); | 6023 | try f.writeCValueMember(writer, local, .{ .identifier = "payload" }); |
| 6079 | try writer.writeAll(", "); | 6024 | try writer.writeAll(", "); |
| 6080 | try f.object.dg.renderTypeForBuiltinFnName(writer, ptr_ty.childType()); | 6025 | try new_value_mat.mat(f, writer); |
| 6081 | try writer.writeByte(')'); | 6026 | try writer.writeAll(", "); |
| 6082 | try writer.writeAll(";\n"); | 6027 | try writeMemoryOrder(writer, extra.successOrder()); |
| 6028 | try writer.writeAll(", "); | ||
| 6029 | try writeMemoryOrder(writer, extra.failureOrder()); | ||
| 6030 | try writer.writeAll(", "); | ||
| 6031 | try f.object.dg.renderTypeForBuiltinFnName(writer, ty); | ||
| 6032 | try writer.writeAll(", "); | ||
| 6033 | try f.object.dg.renderType(writer, repr_ty); | ||
| 6034 | try writer.writeByte(')'); | ||
| 6035 | try a.end(f, writer); | ||
| 6036 | } | ||
| 6083 | } | 6037 | } |
| 6038 | try new_value_mat.end(f, inst); | ||
| 6084 | 6039 | ||
| 6085 | if (f.liveness.isUnused(inst)) { | 6040 | if (f.liveness.isUnused(inst)) { |
| 6086 | try freeLocal(f, inst, local.new_local, 0); | 6041 | try freeLocal(f, inst, local.new_local, 0); |
| ... | @@ -6095,35 +6050,50 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6095,35 +6050,50 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6095 | const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data; | 6050 | const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data; |
| 6096 | const inst_ty = f.air.typeOfIndex(inst); | 6051 | const inst_ty = f.air.typeOfIndex(inst); |
| 6097 | const ptr_ty = f.air.typeOf(pl_op.operand); | 6052 | const ptr_ty = f.air.typeOf(pl_op.operand); |
| 6053 | const ty = ptr_ty.childType(); | ||
| 6098 | const ptr = try f.resolveInst(pl_op.operand); | 6054 | const ptr = try f.resolveInst(pl_op.operand); |
| 6099 | const operand = try f.resolveInst(extra.operand); | 6055 | const operand = try f.resolveInst(extra.operand); |
| 6100 | try reap(f, inst, &.{ pl_op.operand, extra.operand }); | 6056 | |
| 6101 | const writer = f.object.writer(); | 6057 | const writer = f.object.writer(); |
| 6102 | const local = try f.allocLocal(inst, inst_ty); | 6058 | const operand_mat = try Materialize.start(f, inst, writer, ty, operand); |
| 6059 | try reap(f, inst, &.{ pl_op.operand, extra.operand }); | ||
| 6103 | 6060 | ||
| 6061 | const target = f.object.dg.module.getTarget(); | ||
| 6062 | var repr_pl = Type.Payload.Bits{ | ||
| 6063 | .base = .{ .tag = .int_unsigned }, | ||
| 6064 | .data = @intCast(u16, ty.abiSize(target) * 8), | ||
| 6065 | }; | ||
| 6066 | const is_float = ty.isRuntimeFloat(); | ||
| 6067 | const is_128 = repr_pl.data == 128; | ||
| 6068 | const repr_ty = if (is_float) Type.initPayload(&repr_pl.base) else ty; | ||
| 6069 | |||
| 6070 | const local = try f.allocLocal(inst, inst_ty); | ||
| 6071 | try writer.print("zig_atomicrmw_{s}", .{toAtomicRmwSuffix(extra.op())}); | ||
| 6072 | if (is_float) try writer.writeAll("_float") else if (is_128) try writer.writeAll("_int128"); | ||
| 6073 | try writer.writeByte('('); | ||
| 6104 | try f.writeCValue(writer, local, .Other); | 6074 | try f.writeCValue(writer, local, .Other); |
| 6105 | try writer.print(" = zig_atomicrmw_{s}((", .{toAtomicRmwSuffix(extra.op())}); | 6075 | try writer.writeAll(", ("); |
| 6106 | switch (extra.op()) { | 6076 | const use_atomic = switch (extra.op()) { |
| 6107 | else => { | 6077 | else => true, |
| 6108 | try writer.writeAll("zig_atomic("); | 6078 | // These are missing from stdatomic.h, so no atomic types unless a fallback is used. |
| 6109 | try f.renderType(writer, ptr_ty.elemType()); | 6079 | .Nand, .Min, .Max => is_float or is_128, |
| 6110 | try writer.writeByte(')'); | 6080 | }; |
| 6111 | }, | 6081 | if (use_atomic) try writer.writeAll("zig_atomic("); |
| 6112 | .Nand, .Min, .Max => { | 6082 | try f.renderType(writer, ty); |
| 6113 | // These are missing from stdatomic.h, so no atomic types for now. | 6083 | if (use_atomic) try writer.writeByte(')'); |
| 6114 | try f.renderType(writer, ptr_ty.elemType()); | ||
| 6115 | }, | ||
| 6116 | } | ||
| 6117 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); | 6084 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); |
| 6118 | try writer.writeAll(" *)"); | 6085 | try writer.writeAll(" *)"); |
| 6119 | try f.writeCValue(writer, ptr, .Other); | 6086 | try f.writeCValue(writer, ptr, .Other); |
| 6120 | try writer.writeAll(", "); | 6087 | try writer.writeAll(", "); |
| 6121 | try f.writeCValue(writer, operand, .FunctionArgument); | 6088 | try operand_mat.mat(f, writer); |
| 6122 | try writer.writeAll(", "); | 6089 | try writer.writeAll(", "); |
| 6123 | try writeMemoryOrder(writer, extra.ordering()); | 6090 | try writeMemoryOrder(writer, extra.ordering()); |
| 6124 | try writer.writeAll(", "); | 6091 | try writer.writeAll(", "); |
| 6125 | try f.object.dg.renderTypeForBuiltinFnName(writer, ptr_ty.childType()); | 6092 | try f.object.dg.renderTypeForBuiltinFnName(writer, ty); |
| 6093 | try writer.writeAll(", "); | ||
| 6094 | try f.object.dg.renderType(writer, repr_ty); | ||
| 6126 | try writer.writeAll(");\n"); | 6095 | try writer.writeAll(");\n"); |
| 6096 | try operand_mat.end(f, inst); | ||
| 6127 | 6097 | ||
| 6128 | if (f.liveness.isUnused(inst)) { | 6098 | if (f.liveness.isUnused(inst)) { |
| 6129 | try freeLocal(f, inst, local.new_local, 0); | 6099 | try freeLocal(f, inst, local.new_local, 0); |
| ... | @@ -6138,14 +6108,23 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6138,14 +6108,23 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6138 | const ptr = try f.resolveInst(atomic_load.ptr); | 6108 | const ptr = try f.resolveInst(atomic_load.ptr); |
| 6139 | try reap(f, inst, &.{atomic_load.ptr}); | 6109 | try reap(f, inst, &.{atomic_load.ptr}); |
| 6140 | const ptr_ty = f.air.typeOf(atomic_load.ptr); | 6110 | const ptr_ty = f.air.typeOf(atomic_load.ptr); |
| 6111 | const ty = ptr_ty.childType(); | ||
| 6112 | |||
| 6113 | const target = f.object.dg.module.getTarget(); | ||
| 6114 | var repr_pl = Type.Payload.Bits{ | ||
| 6115 | .base = .{ .tag = .int_unsigned }, | ||
| 6116 | .data = @intCast(u16, ty.abiSize(target) * 8), | ||
| 6117 | }; | ||
| 6118 | const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty; | ||
| 6141 | 6119 | ||
| 6142 | const inst_ty = f.air.typeOfIndex(inst); | 6120 | const inst_ty = f.air.typeOfIndex(inst); |
| 6143 | const writer = f.object.writer(); | 6121 | const writer = f.object.writer(); |
| 6144 | const local = try f.allocLocal(inst, inst_ty); | 6122 | const local = try f.allocLocal(inst, inst_ty); |
| 6145 | try f.writeCValue(writer, local, .Other); | ||
| 6146 | 6123 | ||
| 6147 | try writer.writeAll(" = zig_atomic_load((zig_atomic("); | 6124 | try writer.writeAll("zig_atomic_load("); |
| 6148 | try f.renderType(writer, ptr_ty.elemType()); | 6125 | try f.writeCValue(writer, local, .Other); |
| 6126 | try writer.writeAll(", (zig_atomic("); | ||
| 6127 | try f.renderType(writer, ty); | ||
| 6149 | try writer.writeByte(')'); | 6128 | try writer.writeByte(')'); |
| 6150 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); | 6129 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); |
| 6151 | try writer.writeAll(" *)"); | 6130 | try writer.writeAll(" *)"); |
| ... | @@ -6153,7 +6132,9 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6153,7 +6132,9 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6153 | try writer.writeAll(", "); | 6132 | try writer.writeAll(", "); |
| 6154 | try writeMemoryOrder(writer, atomic_load.order); | 6133 | try writeMemoryOrder(writer, atomic_load.order); |
| 6155 | try writer.writeAll(", "); | 6134 | try writer.writeAll(", "); |
| 6156 | try f.object.dg.renderTypeForBuiltinFnName(writer, ptr_ty.childType()); | 6135 | try f.object.dg.renderTypeForBuiltinFnName(writer, ty); |
| 6136 | try writer.writeAll(", "); | ||
| 6137 | try f.object.dg.renderType(writer, repr_ty); | ||
| 6157 | try writer.writeAll(");\n"); | 6138 | try writer.writeAll(");\n"); |
| 6158 | 6139 | ||
| 6159 | return local; | 6140 | return local; |
| ... | @@ -6162,22 +6143,35 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6162,22 +6143,35 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6162 | fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue { | 6143 | fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CValue { |
| 6163 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; | 6144 | const bin_op = f.air.instructions.items(.data)[inst].bin_op; |
| 6164 | const ptr_ty = f.air.typeOf(bin_op.lhs); | 6145 | const ptr_ty = f.air.typeOf(bin_op.lhs); |
| 6146 | const ty = ptr_ty.childType(); | ||
| 6165 | const ptr = try f.resolveInst(bin_op.lhs); | 6147 | const ptr = try f.resolveInst(bin_op.lhs); |
| 6166 | const element = try f.resolveInst(bin_op.rhs); | 6148 | const element = try f.resolveInst(bin_op.rhs); |
| 6167 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 6149 | |
| 6168 | const writer = f.object.writer(); | 6150 | const writer = f.object.writer(); |
| 6151 | const element_mat = try Materialize.start(f, inst, writer, ty, element); | ||
| 6152 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | ||
| 6153 | |||
| 6154 | const target = f.object.dg.module.getTarget(); | ||
| 6155 | var repr_pl = Type.Payload.Bits{ | ||
| 6156 | .base = .{ .tag = .int_unsigned }, | ||
| 6157 | .data = @intCast(u16, ty.abiSize(target) * 8), | ||
| 6158 | }; | ||
| 6159 | const repr_ty = if (ty.isRuntimeFloat()) Type.initPayload(&repr_pl.base) else ty; | ||
| 6169 | 6160 | ||
| 6170 | try writer.writeAll("zig_atomic_store((zig_atomic("); | 6161 | try writer.writeAll("zig_atomic_store((zig_atomic("); |
| 6171 | try f.renderType(writer, ptr_ty.elemType()); | 6162 | try f.renderType(writer, ty); |
| 6172 | try writer.writeByte(')'); | 6163 | try writer.writeByte(')'); |
| 6173 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); | 6164 | if (ptr_ty.isVolatilePtr()) try writer.writeAll(" volatile"); |
| 6174 | try writer.writeAll(" *)"); | 6165 | try writer.writeAll(" *)"); |
| 6175 | try f.writeCValue(writer, ptr, .Other); | 6166 | try f.writeCValue(writer, ptr, .Other); |
| 6176 | try writer.writeAll(", "); | 6167 | try writer.writeAll(", "); |
| 6177 | try f.writeCValue(writer, element, .FunctionArgument); | 6168 | try element_mat.mat(f, writer); |
| 6178 | try writer.print(", {s}, ", .{order}); | 6169 | try writer.print(", {s}, ", .{order}); |
| 6179 | try f.object.dg.renderTypeForBuiltinFnName(writer, ptr_ty.childType()); | 6170 | try f.object.dg.renderTypeForBuiltinFnName(writer, ty); |
| 6171 | try writer.writeAll(", "); | ||
| 6172 | try f.object.dg.renderType(writer, repr_ty); | ||
| 6180 | try writer.writeAll(");\n"); | 6173 | try writer.writeAll(");\n"); |
| 6174 | try element_mat.end(f, inst); | ||
| 6181 | 6175 | ||
| 6182 | return .none; | 6176 | return .none; |
| 6183 | } | 6177 | } |
| ... | @@ -6262,19 +6256,19 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6262,19 +6256,19 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6262 | const union_ptr = try f.resolveInst(bin_op.lhs); | 6256 | const union_ptr = try f.resolveInst(bin_op.lhs); |
| 6263 | const new_tag = try f.resolveInst(bin_op.rhs); | 6257 | const new_tag = try f.resolveInst(bin_op.rhs); |
| 6264 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); | 6258 | try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs }); |
| 6265 | const writer = f.object.writer(); | ||
| 6266 | 6259 | ||
| 6267 | const union_ty = f.air.typeOf(bin_op.lhs).childType(); | ||
| 6268 | const target = f.object.dg.module.getTarget(); | 6260 | const target = f.object.dg.module.getTarget(); |
| 6261 | const union_ty = f.air.typeOf(bin_op.lhs).childType(); | ||
| 6269 | const layout = union_ty.unionGetLayout(target); | 6262 | const layout = union_ty.unionGetLayout(target); |
| 6270 | if (layout.tag_size == 0) return .none; | 6263 | if (layout.tag_size == 0) return .none; |
| 6264 | const tag_ty = union_ty.unionTagTypeSafety().?; | ||
| 6271 | 6265 | ||
| 6272 | try writer.writeByte('('); | 6266 | const writer = f.object.writer(); |
| 6273 | try f.writeCValue(writer, union_ptr, .Other); | 6267 | const a = try Assignment.start(f, writer, tag_ty); |
| 6274 | try writer.writeAll(")->tag = "); | 6268 | try f.writeCValueDerefMember(writer, union_ptr, .{ .identifier = "tag" }); |
| 6269 | try a.assign(f, writer); | ||
| 6275 | try f.writeCValue(writer, new_tag, .Other); | 6270 | try f.writeCValue(writer, new_tag, .Other); |
| 6276 | try writer.writeAll(";\n"); | 6271 | try a.end(f, writer); |
| 6277 | |||
| 6278 | return .none; | 6272 | return .none; |
| 6279 | } | 6273 | } |
| 6280 | 6274 | ||
| ... | @@ -6284,20 +6278,19 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6284,20 +6278,19 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6284 | const operand = try f.resolveInst(ty_op.operand); | 6278 | const operand = try f.resolveInst(ty_op.operand); |
| 6285 | try reap(f, inst, &.{ty_op.operand}); | 6279 | try reap(f, inst, &.{ty_op.operand}); |
| 6286 | 6280 | ||
| 6287 | const un_ty = f.air.typeOf(ty_op.operand); | 6281 | const union_ty = f.air.typeOf(ty_op.operand); |
| 6288 | |||
| 6289 | const target = f.object.dg.module.getTarget(); | 6282 | const target = f.object.dg.module.getTarget(); |
| 6290 | const layout = un_ty.unionGetLayout(target); | 6283 | const layout = union_ty.unionGetLayout(target); |
| 6291 | if (layout.tag_size == 0) return .none; | 6284 | if (layout.tag_size == 0) return .none; |
| 6292 | 6285 | ||
| 6293 | const inst_ty = f.air.typeOfIndex(inst); | 6286 | const inst_ty = f.air.typeOfIndex(inst); |
| 6294 | const writer = f.object.writer(); | 6287 | const writer = f.object.writer(); |
| 6295 | const local = try f.allocLocal(inst, inst_ty); | 6288 | const local = try f.allocLocal(inst, inst_ty); |
| 6289 | const a = try Assignment.start(f, writer, inst_ty); | ||
| 6296 | try f.writeCValue(writer, local, .Other); | 6290 | try f.writeCValue(writer, local, .Other); |
| 6297 | 6291 | try a.assign(f, writer); | |
| 6298 | try writer.writeAll(" = "); | 6292 | try f.writeCValueMember(writer, operand, .{ .identifier = "tag" }); |
| 6299 | try f.writeCValue(writer, operand, .Other); | 6293 | try a.end(f, writer); |
| 6300 | try writer.writeAll(".tag;\n"); | ||
| 6301 | return local; | 6294 | return local; |
| 6302 | } | 6295 | } |
| 6303 | 6296 | ||
| ... | @@ -6350,7 +6343,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6350,7 +6343,7 @@ fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6350 | 6343 | ||
| 6351 | const writer = f.object.writer(); | 6344 | const writer = f.object.writer(); |
| 6352 | const local = try f.allocLocal(inst, inst_ty); | 6345 | const local = try f.allocLocal(inst, inst_ty); |
| 6353 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 6346 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 6354 | if (need_memcpy) try writer.writeAll("memcpy(&"); | 6347 | if (need_memcpy) try writer.writeAll("memcpy(&"); |
| 6355 | try f.writeCValue(writer, local, .Other); | 6348 | try f.writeCValue(writer, local, .Other); |
| 6356 | try v.elem(f, writer); | 6349 | try v.elem(f, writer); |
| ... | @@ -6380,7 +6373,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6380,7 +6373,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6380 | 6373 | ||
| 6381 | const writer = f.object.writer(); | 6374 | const writer = f.object.writer(); |
| 6382 | const local = try f.allocLocal(inst, inst_ty); | 6375 | const local = try f.allocLocal(inst, inst_ty); |
| 6383 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 6376 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 6384 | try f.writeCValue(writer, local, .Other); | 6377 | try f.writeCValue(writer, local, .Other); |
| 6385 | try v.elem(f, writer); | 6378 | try v.elem(f, writer); |
| 6386 | try writer.writeAll(" = "); | 6379 | try writer.writeAll(" = "); |
| ... | @@ -6547,7 +6540,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6547,7 +6540,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6547 | }, .Initializer); | 6540 | }, .Initializer); |
| 6548 | try writer.writeAll(";\n"); | 6541 | try writer.writeAll(";\n"); |
| 6549 | 6542 | ||
| 6550 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 6543 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 6551 | try f.writeCValue(writer, accum, .Other); | 6544 | try f.writeCValue(writer, accum, .Other); |
| 6552 | switch (op) { | 6545 | switch (op) { |
| 6553 | .float_op => |func| { | 6546 | .float_op => |func| { |
| ... | @@ -6621,87 +6614,38 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6621,87 +6614,38 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6621 | switch (inst_ty.zigTypeTag()) { | 6614 | switch (inst_ty.zigTypeTag()) { |
| 6622 | .Array, .Vector => { | 6615 | .Array, .Vector => { |
| 6623 | const elem_ty = inst_ty.childType(); | 6616 | const elem_ty = inst_ty.childType(); |
| 6624 | 6617 | const a = try Assignment.init(f, elem_ty); | |
| 6625 | const is_array = lowersToArray(elem_ty, target); | 6618 | for (resolved_elements, 0..) |element, i| { |
| 6626 | const need_memcpy = is_array; | 6619 | try a.restart(f, writer); |
| 6627 | if (need_memcpy) { | 6620 | try f.writeCValue(writer, local, .Other); |
| 6628 | for (resolved_elements, 0..) |element, i| { | 6621 | try writer.print("[{d}]", .{i}); |
| 6629 | try writer.writeAll("memcpy("); | 6622 | try a.assign(f, writer); |
| 6630 | try f.writeCValue(writer, local, .Other); | 6623 | try f.writeCValue(writer, element, .Other); |
| 6631 | try writer.print("[{d}]", .{i}); | 6624 | try a.end(f, writer); |
| 6632 | try writer.writeAll(", "); | 6625 | } |
| 6633 | try f.writeCValue(writer, element, .Other); | 6626 | if (inst_ty.sentinel()) |sentinel| { |
| 6634 | try writer.writeAll(", sizeof("); | 6627 | try a.restart(f, writer); |
| 6635 | try f.renderType(writer, elem_ty); | 6628 | try f.writeCValue(writer, local, .Other); |
| 6636 | try writer.writeAll("))"); | 6629 | try writer.print("[{d}]", .{resolved_elements.len}); |
| 6637 | try writer.writeAll(";\n"); | 6630 | try a.assign(f, writer); |
| 6638 | } | 6631 | try f.object.dg.renderValue(writer, elem_ty, sentinel, .Other); |
| 6639 | assert(inst_ty.sentinel() == null); | 6632 | try a.end(f, writer); |
| 6640 | } else { | ||
| 6641 | for (resolved_elements, 0..) |element, i| { | ||
| 6642 | try f.writeCValue(writer, local, .Other); | ||
| 6643 | try writer.print("[{d}] = ", .{i}); | ||
| 6644 | try f.writeCValue(writer, element, .Other); | ||
| 6645 | try writer.writeAll(";\n"); | ||
| 6646 | } | ||
| 6647 | if (inst_ty.sentinel()) |sentinel| { | ||
| 6648 | try f.writeCValue(writer, local, .Other); | ||
| 6649 | try writer.print("[{d}] = ", .{resolved_elements.len}); | ||
| 6650 | try f.object.dg.renderValue(writer, elem_ty, sentinel, .Other); | ||
| 6651 | try writer.writeAll(";\n"); | ||
| 6652 | } | ||
| 6653 | } | 6633 | } |
| 6654 | }, | 6634 | }, |
| 6655 | .Struct => switch (inst_ty.containerLayout()) { | 6635 | .Struct => switch (inst_ty.containerLayout()) { |
| 6656 | .Auto, .Extern => { | 6636 | .Auto, .Extern => for (resolved_elements, 0..) |element, field_i| { |
| 6657 | try f.writeCValue(writer, local, .Other); | 6637 | if (inst_ty.structFieldIsComptime(field_i)) continue; |
| 6658 | try writer.writeAll(" = ("); | 6638 | const field_ty = inst_ty.structFieldType(field_i); |
| 6659 | try f.renderType(writer, inst_ty); | 6639 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 6660 | try writer.writeAll(")"); | ||
| 6661 | try writer.writeByte('{'); | ||
| 6662 | var empty = true; | ||
| 6663 | for (elements, resolved_elements, 0..) |element, resolved_element, field_i| { | ||
| 6664 | if (inst_ty.structFieldValueComptime(field_i)) |_| continue; | ||
| 6665 | |||
| 6666 | if (!empty) try writer.writeAll(", "); | ||
| 6667 | |||
| 6668 | const field_name: CValue = if (inst_ty.isSimpleTuple()) | ||
| 6669 | .{ .field = field_i } | ||
| 6670 | else | ||
| 6671 | .{ .identifier = inst_ty.structFieldName(field_i) }; | ||
| 6672 | try writer.writeByte('.'); | ||
| 6673 | try f.object.dg.writeCValue(writer, field_name); | ||
| 6674 | try writer.writeAll(" = "); | ||
| 6675 | |||
| 6676 | const element_ty = f.air.typeOf(element); | ||
| 6677 | try f.writeCValue(writer, switch (element_ty.zigTypeTag()) { | ||
| 6678 | .Array => .{ .undef = element_ty }, | ||
| 6679 | else => resolved_element, | ||
| 6680 | }, .Initializer); | ||
| 6681 | empty = false; | ||
| 6682 | } | ||
| 6683 | try writer.writeAll("};\n"); | ||
| 6684 | |||
| 6685 | for (elements, resolved_elements, 0..) |element, resolved_element, field_i| { | ||
| 6686 | if (inst_ty.structFieldValueComptime(field_i)) |_| continue; | ||
| 6687 | |||
| 6688 | const element_ty = f.air.typeOf(element); | ||
| 6689 | if (element_ty.zigTypeTag() != .Array) continue; | ||
| 6690 | |||
| 6691 | const field_name: CValue = if (inst_ty.isSimpleTuple()) | ||
| 6692 | .{ .field = field_i } | ||
| 6693 | else | ||
| 6694 | .{ .identifier = inst_ty.structFieldName(field_i) }; | ||
| 6695 | 6640 | ||
| 6696 | try writer.writeAll(";\n"); | 6641 | const a = try Assignment.start(f, writer, field_ty); |
| 6697 | try writer.writeAll("memcpy("); | 6642 | try f.writeCValueMember(writer, local, if (inst_ty.isSimpleTuple()) |
| 6698 | try f.writeCValueMember(writer, local, field_name); | 6643 | .{ .field = field_i } |
| 6699 | try writer.writeAll(", "); | 6644 | else |
| 6700 | try f.writeCValue(writer, resolved_element, .FunctionArgument); | 6645 | .{ .identifier = inst_ty.structFieldName(field_i) }); |
| 6701 | try writer.writeAll(", sizeof("); | 6646 | try a.assign(f, writer); |
| 6702 | try f.renderType(writer, element_ty); | 6647 | try f.writeCValue(writer, element, .Other); |
| 6703 | try writer.writeAll("));\n"); | 6648 | try a.end(f, writer); |
| 6704 | } | ||
| 6705 | }, | 6649 | }, |
| 6706 | .Packed => { | 6650 | .Packed => { |
| 6707 | try f.writeCValue(writer, local, .Other); | 6651 | try f.writeCValue(writer, local, .Other); |
| ... | @@ -6718,8 +6662,9 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6718,8 +6662,9 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6718 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); | 6662 | const bit_offset_val = Value.initPayload(&bit_offset_val_pl.base); |
| 6719 | 6663 | ||
| 6720 | var empty = true; | 6664 | var empty = true; |
| 6721 | for (0..elements.len) |index| { | 6665 | for (0..elements.len) |field_i| { |
| 6722 | const field_ty = inst_ty.structFieldType(index); | 6666 | if (inst_ty.structFieldIsComptime(field_i)) continue; |
| 6667 | const field_ty = inst_ty.structFieldType(field_i); | ||
| 6723 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 6668 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 6724 | 6669 | ||
| 6725 | if (!empty) { | 6670 | if (!empty) { |
| ... | @@ -6730,8 +6675,9 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6730,8 +6675,9 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6730 | empty = false; | 6675 | empty = false; |
| 6731 | } | 6676 | } |
| 6732 | empty = true; | 6677 | empty = true; |
| 6733 | for (resolved_elements, 0..) |element, index| { | 6678 | for (resolved_elements, 0..) |element, field_i| { |
| 6734 | const field_ty = inst_ty.structFieldType(index); | 6679 | if (inst_ty.structFieldIsComptime(field_i)) continue; |
| 6680 | const field_ty = inst_ty.structFieldType(field_i); | ||
| 6735 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; | 6681 | if (!field_ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 6736 | 6682 | ||
| 6737 | if (!empty) try writer.writeAll(", "); | 6683 | if (!empty) try writer.writeAll(", "); |
| ... | @@ -6784,6 +6730,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6784,6 +6730,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6784 | const target = f.object.dg.module.getTarget(); | 6730 | const target = f.object.dg.module.getTarget(); |
| 6785 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 6731 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 6786 | const field_name = union_obj.fields.keys()[extra.field_index]; | 6732 | const field_name = union_obj.fields.keys()[extra.field_index]; |
| 6733 | const payload_ty = f.air.typeOf(extra.init); | ||
| 6787 | const payload = try f.resolveInst(extra.init); | 6734 | const payload = try f.resolveInst(extra.init); |
| 6788 | try reap(f, inst, &.{extra.init}); | 6735 | try reap(f, inst, &.{extra.init}); |
| 6789 | 6736 | ||
| ... | @@ -6811,16 +6758,20 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6811,16 +6758,20 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6811 | var int_pl: Value.Payload.U64 = undefined; | 6758 | var int_pl: Value.Payload.U64 = undefined; |
| 6812 | const int_val = tag_val.enumToInt(tag_ty, &int_pl); | 6759 | const int_val = tag_val.enumToInt(tag_ty, &int_pl); |
| 6813 | 6760 | ||
| 6814 | try f.writeCValue(writer, local, .Other); | 6761 | const a = try Assignment.start(f, writer, tag_ty); |
| 6815 | try writer.print(".tag = {}; ", .{try f.fmtIntLiteral(tag_ty, int_val)}); | 6762 | try f.writeCValueMember(writer, local, .{ .identifier = "tag" }); |
| 6763 | try a.assign(f, writer); | ||
| 6764 | try writer.print("{}", .{try f.fmtIntLiteral(tag_ty, int_val)}); | ||
| 6765 | try a.end(f, writer); | ||
| 6816 | } | 6766 | } |
| 6817 | break :field .{ .payload_identifier = field_name }; | 6767 | break :field .{ .payload_identifier = field_name }; |
| 6818 | } else .{ .identifier = field_name }; | 6768 | } else .{ .identifier = field_name }; |
| 6819 | 6769 | ||
| 6770 | const a = try Assignment.start(f, writer, payload_ty); | ||
| 6820 | try f.writeCValueMember(writer, local, field); | 6771 | try f.writeCValueMember(writer, local, field); |
| 6821 | try writer.writeAll(" = "); | 6772 | try a.assign(f, writer); |
| 6822 | try f.writeCValue(writer, payload, .Other); | 6773 | try f.writeCValue(writer, payload, .Other); |
| 6823 | try writer.writeAll(";\n"); | 6774 | try a.end(f, writer); |
| 6824 | return local; | 6775 | return local; |
| 6825 | } | 6776 | } |
| 6826 | 6777 | ||
| ... | @@ -6887,7 +6838,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6887,7 +6838,7 @@ fn airFloatNeg(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6887 | 6838 | ||
| 6888 | const writer = f.object.writer(); | 6839 | const writer = f.object.writer(); |
| 6889 | const local = try f.allocLocal(inst, operand_ty); | 6840 | const local = try f.allocLocal(inst, operand_ty); |
| 6890 | const v = try Vectorizer.start(f, inst, writer, operand_ty); | 6841 | const v = try Vectorize.start(f, inst, writer, operand_ty); |
| 6891 | try f.writeCValue(writer, local, .Other); | 6842 | try f.writeCValue(writer, local, .Other); |
| 6892 | try v.elem(f, writer); | 6843 | try v.elem(f, writer); |
| 6893 | try writer.writeAll(" = zig_neg_"); | 6844 | try writer.writeAll(" = zig_neg_"); |
| ... | @@ -6912,7 +6863,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal | ... | @@ -6912,7 +6863,7 @@ fn airUnFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVal |
| 6912 | 6863 | ||
| 6913 | const writer = f.object.writer(); | 6864 | const writer = f.object.writer(); |
| 6914 | const local = try f.allocLocal(inst, inst_ty); | 6865 | const local = try f.allocLocal(inst, inst_ty); |
| 6915 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 6866 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 6916 | try f.writeCValue(writer, local, .Other); | 6867 | try f.writeCValue(writer, local, .Other); |
| 6917 | try v.elem(f, writer); | 6868 | try v.elem(f, writer); |
| 6918 | try writer.writeAll(" = zig_libc_name_"); | 6869 | try writer.writeAll(" = zig_libc_name_"); |
| ... | @@ -6940,7 +6891,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa | ... | @@ -6940,7 +6891,7 @@ fn airBinFloatOp(f: *Function, inst: Air.Inst.Index, operation: []const u8) !CVa |
| 6940 | 6891 | ||
| 6941 | const writer = f.object.writer(); | 6892 | const writer = f.object.writer(); |
| 6942 | const local = try f.allocLocal(inst, inst_ty); | 6893 | const local = try f.allocLocal(inst, inst_ty); |
| 6943 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 6894 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 6944 | try f.writeCValue(writer, local, .Other); | 6895 | try f.writeCValue(writer, local, .Other); |
| 6945 | try v.elem(f, writer); | 6896 | try v.elem(f, writer); |
| 6946 | try writer.writeAll(" = zig_libc_name_"); | 6897 | try writer.writeAll(" = zig_libc_name_"); |
| ... | @@ -6973,7 +6924,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -6973,7 +6924,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6973 | 6924 | ||
| 6974 | const writer = f.object.writer(); | 6925 | const writer = f.object.writer(); |
| 6975 | const local = try f.allocLocal(inst, inst_ty); | 6926 | const local = try f.allocLocal(inst, inst_ty); |
| 6976 | const v = try Vectorizer.start(f, inst, writer, inst_ty); | 6927 | const v = try Vectorize.start(f, inst, writer, inst_ty); |
| 6977 | try f.writeCValue(writer, local, .Other); | 6928 | try f.writeCValue(writer, local, .Other); |
| 6978 | try v.elem(f, writer); | 6929 | try v.elem(f, writer); |
| 6979 | try writer.writeAll(" = zig_libc_name_"); | 6930 | try writer.writeAll(" = zig_libc_name_"); |
| ... | @@ -7480,10 +7431,96 @@ fn formatIntLiteral( | ... | @@ -7480,10 +7431,96 @@ fn formatIntLiteral( |
| 7480 | try data.cty.renderLiteralSuffix(writer); | 7431 | try data.cty.renderLiteralSuffix(writer); |
| 7481 | } | 7432 | } |
| 7482 | 7433 | ||
| 7483 | const Vectorizer = struct { | 7434 | const Materialize = struct { |
| 7435 | local: CValue, | ||
| 7436 | |||
| 7437 | pub fn start( | ||
| 7438 | f: *Function, | ||
| 7439 | inst: Air.Inst.Index, | ||
| 7440 | writer: anytype, | ||
| 7441 | ty: Type, | ||
| 7442 | value: CValue, | ||
| 7443 | ) !Materialize { | ||
| 7444 | switch (value) { | ||
| 7445 | .local_ref, .constant, .decl_ref, .undef => { | ||
| 7446 | const local = try f.allocLocal(inst, ty); | ||
| 7447 | |||
| 7448 | const a = try Assignment.start(f, writer, ty); | ||
| 7449 | try f.writeCValue(writer, local, .Other); | ||
| 7450 | try a.assign(f, writer); | ||
| 7451 | try f.writeCValue(writer, value, .Other); | ||
| 7452 | try a.end(f, writer); | ||
| 7453 | |||
| 7454 | return .{ .local = local }; | ||
| 7455 | }, | ||
| 7456 | .new_local => |local| return .{ .local = .{ .local = local } }, | ||
| 7457 | else => return .{ .local = value }, | ||
| 7458 | } | ||
| 7459 | } | ||
| 7460 | |||
| 7461 | pub fn mat(self: Materialize, f: *Function, writer: anytype) !void { | ||
| 7462 | try f.writeCValue(writer, self.local, .Other); | ||
| 7463 | } | ||
| 7464 | |||
| 7465 | pub fn end(self: Materialize, f: *Function, inst: Air.Inst.Index) !void { | ||
| 7466 | switch (self.local) { | ||
| 7467 | .new_local => |local| try freeLocal(f, inst, local, 0), | ||
| 7468 | else => {}, | ||
| 7469 | } | ||
| 7470 | } | ||
| 7471 | }; | ||
| 7472 | |||
| 7473 | const Assignment = struct { | ||
| 7474 | cty: CType.Index, | ||
| 7475 | |||
| 7476 | pub fn init(f: *Function, ty: Type) !Assignment { | ||
| 7477 | return .{ .cty = try f.typeToIndex(ty, .complete) }; | ||
| 7478 | } | ||
| 7479 | |||
| 7480 | pub fn start(f: *Function, writer: anytype, ty: Type) !Assignment { | ||
| 7481 | const self = try init(f, ty); | ||
| 7482 | try self.restart(f, writer); | ||
| 7483 | return self; | ||
| 7484 | } | ||
| 7485 | |||
| 7486 | pub fn restart(self: Assignment, f: *Function, writer: anytype) !void { | ||
| 7487 | switch (self.strategy(f)) { | ||
| 7488 | .assign => {}, | ||
| 7489 | .memcpy => try writer.writeAll("memcpy("), | ||
| 7490 | } | ||
| 7491 | } | ||
| 7492 | |||
| 7493 | pub fn assign(self: Assignment, f: *Function, writer: anytype) !void { | ||
| 7494 | switch (self.strategy(f)) { | ||
| 7495 | .assign => try writer.writeAll(" = "), | ||
| 7496 | .memcpy => try writer.writeAll(", "), | ||
| 7497 | } | ||
| 7498 | } | ||
| 7499 | |||
| 7500 | pub fn end(self: Assignment, f: *Function, writer: anytype) !void { | ||
| 7501 | switch (self.strategy(f)) { | ||
| 7502 | .assign => {}, | ||
| 7503 | .memcpy => { | ||
| 7504 | try writer.writeAll(", sizeof("); | ||
| 7505 | try f.renderCType(writer, self.cty); | ||
| 7506 | try writer.writeAll("))"); | ||
| 7507 | }, | ||
| 7508 | } | ||
| 7509 | try writer.writeAll(";\n"); | ||
| 7510 | } | ||
| 7511 | |||
| 7512 | fn strategy(self: Assignment, f: *Function) enum { assign, memcpy } { | ||
| 7513 | return switch (f.indexToCType(self.cty).tag()) { | ||
| 7514 | else => .assign, | ||
| 7515 | .array, .vector => .memcpy, | ||
| 7516 | }; | ||
| 7517 | } | ||
| 7518 | }; | ||
| 7519 | |||
| 7520 | const Vectorize = struct { | ||
| 7484 | index: CValue = .none, | 7521 | index: CValue = .none, |
| 7485 | 7522 | ||
| 7486 | pub fn start(f: *Function, inst: Air.Inst.Index, writer: anytype, ty: Type) !Vectorizer { | 7523 | pub fn start(f: *Function, inst: Air.Inst.Index, writer: anytype, ty: Type) !Vectorize { |
| 7487 | return if (ty.zigTypeTag() == .Vector) index: { | 7524 | return if (ty.zigTypeTag() == .Vector) index: { |
| 7488 | var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = ty.vectorLen() }; | 7525 | var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = ty.vectorLen() }; |
| 7489 | 7526 | ||
| ... | @@ -7504,7 +7541,7 @@ const Vectorizer = struct { | ... | @@ -7504,7 +7541,7 @@ const Vectorizer = struct { |
| 7504 | } else .{}; | 7541 | } else .{}; |
| 7505 | } | 7542 | } |
| 7506 | 7543 | ||
| 7507 | pub fn elem(self: Vectorizer, f: *Function, writer: anytype) !void { | 7544 | pub fn elem(self: Vectorize, f: *Function, writer: anytype) !void { |
| 7508 | if (self.index != .none) { | 7545 | if (self.index != .none) { |
| 7509 | try writer.writeByte('['); | 7546 | try writer.writeByte('['); |
| 7510 | try f.writeCValue(writer, self.index, .Other); | 7547 | try f.writeCValue(writer, self.index, .Other); |
| ... | @@ -7512,7 +7549,7 @@ const Vectorizer = struct { | ... | @@ -7512,7 +7549,7 @@ const Vectorizer = struct { |
| 7512 | } | 7549 | } |
| 7513 | } | 7550 | } |
| 7514 | 7551 | ||
| 7515 | pub fn end(self: Vectorizer, f: *Function, inst: Air.Inst.Index, writer: anytype) !void { | 7552 | pub fn end(self: Vectorize, f: *Function, inst: Air.Inst.Index, writer: anytype) !void { |
| 7516 | if (self.index != .none) { | 7553 | if (self.index != .none) { |
| 7517 | f.object.indent_writer.popIndent(); | 7554 | f.object.indent_writer.popIndent(); |
| 7518 | try writer.writeAll("}\n"); | 7555 | try writer.writeAll("}\n"); |
| ... | @@ -7521,11 +7558,6 @@ const Vectorizer = struct { | ... | @@ -7521,11 +7558,6 @@ const Vectorizer = struct { |
| 7521 | } | 7558 | } |
| 7522 | }; | 7559 | }; |
| 7523 | 7560 | ||
| 7524 | fn isByRef(ty: Type) bool { | ||
| 7525 | _ = ty; | ||
| 7526 | return false; | ||
| 7527 | } | ||
| 7528 | |||
| 7529 | const LowerFnRetTyBuffer = struct { | 7561 | const LowerFnRetTyBuffer = struct { |
| 7530 | names: [1][]const u8, | 7562 | names: [1][]const u8, |
| 7531 | types: [1]Type, | 7563 | types: [1]Type, |
| ... | @@ -7557,29 +7589,6 @@ fn lowersToArray(ty: Type, target: std.Target) bool { | ... | @@ -7557,29 +7589,6 @@ fn lowersToArray(ty: Type, target: std.Target) bool { |
| 7557 | }; | 7589 | }; |
| 7558 | } | 7590 | } |
| 7559 | 7591 | ||
| 7560 | fn loweredArrayInfo(ty: Type, target: std.Target) ?Type.ArrayInfo { | ||
| 7561 | if (!lowersToArray(ty, target)) return null; | ||
| 7562 | |||
| 7563 | switch (ty.zigTypeTag()) { | ||
| 7564 | .Array, .Vector => return ty.arrayInfo(), | ||
| 7565 | else => { | ||
| 7566 | const abi_size = ty.abiSize(target); | ||
| 7567 | const abi_align = ty.abiAlignment(target); | ||
| 7568 | return Type.ArrayInfo{ | ||
| 7569 | .elem_type = switch (abi_align) { | ||
| 7570 | 1 => Type.u8, | ||
| 7571 | 2 => Type.u16, | ||
| 7572 | 4 => Type.u32, | ||
| 7573 | 8 => Type.u64, | ||
| 7574 | 16 => Type.initTag(.u128), | ||
| 7575 | else => unreachable, | ||
| 7576 | }, | ||
| 7577 | .len = @divExact(abi_size, abi_align), | ||
| 7578 | }; | ||
| 7579 | }, | ||
| 7580 | } | ||
| 7581 | } | ||
| 7582 | |||
| 7583 | fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !void { | 7592 | fn reap(f: *Function, inst: Air.Inst.Index, operands: []const Air.Inst.Ref) !void { |
| 7584 | assert(operands.len <= Liveness.bpi - 1); | 7593 | assert(operands.len <= Liveness.bpi - 1); |
| 7585 | var tomb_bits = f.liveness.getTombBits(inst); | 7594 | var tomb_bits = f.liveness.getTombBits(inst); |
src/codegen/llvm.zig+4-4| ... | @@ -10135,14 +10135,14 @@ fn toLlvmAtomicRmwBinOp( | ... | @@ -10135,14 +10135,14 @@ fn toLlvmAtomicRmwBinOp( |
| 10135 | ) llvm.AtomicRMWBinOp { | 10135 | ) llvm.AtomicRMWBinOp { |
| 10136 | return switch (op) { | 10136 | return switch (op) { |
| 10137 | .Xchg => .Xchg, | 10137 | .Xchg => .Xchg, |
| 10138 | .Add => if (is_float) llvm.AtomicRMWBinOp.FAdd else return .Add, | 10138 | .Add => if (is_float) .FAdd else return .Add, |
| 10139 | .Sub => if (is_float) llvm.AtomicRMWBinOp.FSub else return .Sub, | 10139 | .Sub => if (is_float) .FSub else return .Sub, |
| 10140 | .And => .And, | 10140 | .And => .And, |
| 10141 | .Nand => .Nand, | 10141 | .Nand => .Nand, |
| 10142 | .Or => .Or, | 10142 | .Or => .Or, |
| 10143 | .Xor => .Xor, | 10143 | .Xor => .Xor, |
| 10144 | .Max => if (is_signed) llvm.AtomicRMWBinOp.Max else return .UMax, | 10144 | .Max => if (is_float) .FMax else if (is_signed) .Max else return .UMax, |
| 10145 | .Min => if (is_signed) llvm.AtomicRMWBinOp.Min else return .UMin, | 10145 | .Min => if (is_float) .FMin else if (is_signed) .Min else return .UMin, |
| 10146 | }; | 10146 | }; |
| 10147 | } | 10147 | } |
| 10148 | 10148 |
src/codegen/llvm/bindings.zig+2| ... | @@ -1436,6 +1436,8 @@ pub const AtomicRMWBinOp = enum(c_int) { | ... | @@ -1436,6 +1436,8 @@ pub const AtomicRMWBinOp = enum(c_int) { |
| 1436 | UMin, | 1436 | UMin, |
| 1437 | FAdd, | 1437 | FAdd, |
| 1438 | FSub, | 1438 | FSub, |
| 1439 | FMax, | ||
| 1440 | FMin, | ||
| 1439 | }; | 1441 | }; |
| 1440 | 1442 | ||
| 1441 | pub const TypeKind = enum(c_int) { | 1443 | pub const TypeKind = enum(c_int) { |
src/target.zig+6-4| ... | @@ -575,9 +575,6 @@ pub fn atomicPtrAlignment( | ... | @@ -575,9 +575,6 @@ pub fn atomicPtrAlignment( |
| 575 | .xtensa, | 575 | .xtensa, |
| 576 | => 32, | 576 | => 32, |
| 577 | 577 | ||
| 578 | .aarch64, | ||
| 579 | .aarch64_be, | ||
| 580 | .aarch64_32, | ||
| 581 | .amdgcn, | 578 | .amdgcn, |
| 582 | .bpfel, | 579 | .bpfel, |
| 583 | .bpfeb, | 580 | .bpfeb, |
| ... | @@ -600,7 +597,12 @@ pub fn atomicPtrAlignment( | ... | @@ -600,7 +597,12 @@ pub fn atomicPtrAlignment( |
| 600 | .loongarch64, | 597 | .loongarch64, |
| 601 | => 64, | 598 | => 64, |
| 602 | 599 | ||
| 603 | .x86_64 => 128, | 600 | .aarch64, |
| 601 | .aarch64_be, | ||
| 602 | .aarch64_32, | ||
| 603 | => 128, | ||
| 604 | |||
| 605 | .x86_64 => if (std.Target.x86.featureSetHas(target.cpu.features, .cx16)) 128 else 64, | ||
| 604 | }; | 606 | }; |
| 605 | 607 | ||
| 606 | var buffer: Type.Payload.Bits = undefined; | 608 | var buffer: Type.Payload.Bits = undefined; |
test/behavior/align.zig+1-10| ... | @@ -286,20 +286,11 @@ test "page aligned array on stack" { | ... | @@ -286,20 +286,11 @@ test "page aligned array on stack" { |
| 286 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 286 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 287 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 287 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 288 | 288 | ||
| 289 | if (builtin.zig_backend == .stage2_llvm and | 289 | if (builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) { |
| 290 | builtin.cpu.arch == .aarch64 and builtin.os.tag == .windows) | ||
| 291 | { | ||
| 292 | // https://github.com/ziglang/zig/issues/13679 | 290 | // https://github.com/ziglang/zig/issues/13679 |
| 293 | return error.SkipZigTest; | 291 | return error.SkipZigTest; |
| 294 | } | 292 | } |
| 295 | 293 | ||
| 296 | if (builtin.zig_backend == .stage2_c and | ||
| 297 | builtin.os.tag == .windows and builtin.cpu.arch == .aarch64) | ||
| 298 | { | ||
| 299 | // https://github.com/ziglang/zig/issues/13876 | ||
| 300 | return error.SkipZigTest; | ||
| 301 | } | ||
| 302 | |||
| 303 | // Large alignment value to make it hard to accidentally pass. | 294 | // Large alignment value to make it hard to accidentally pass. |
| 304 | var array align(0x1000) = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; | 295 | var array align(0x1000) = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 305 | var number1: u8 align(16) = 42; | 296 | var number1: u8 align(16) = 42; |
test/behavior/atomics.zig+21-26| ... | @@ -3,6 +3,13 @@ const builtin = @import("builtin"); | ... | @@ -3,6 +3,13 @@ const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; | 3 | const expect = std.testing.expect; |
| 4 | const expectEqual = std.testing.expectEqual; | 4 | const expectEqual = std.testing.expectEqual; |
| 5 | 5 | ||
| 6 | const supports_128_bit_atomics = switch (builtin.cpu.arch) { | ||
| 7 | // TODO: Ideally this could be sync'd with the logic in Sema. | ||
| 8 | .aarch64, .aarch64_be, .aarch64_32 => true, | ||
| 9 | .x86_64 => std.Target.x86.featureSetHas(builtin.cpu.features, .cx16), | ||
| 10 | else => false, | ||
| 11 | }; | ||
| 12 | |||
| 6 | test "cmpxchg" { | 13 | test "cmpxchg" { |
| 7 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 14 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 8 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 15 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| ... | @@ -107,15 +114,14 @@ test "cmpxchg with ignored result" { | ... | @@ -107,15 +114,14 @@ test "cmpxchg with ignored result" { |
| 107 | } | 114 | } |
| 108 | 115 | ||
| 109 | test "128-bit cmpxchg" { | 116 | test "128-bit cmpxchg" { |
| 117 | if (!supports_128_bit_atomics) return error.SkipZigTest; | ||
| 118 | |||
| 110 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 119 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 111 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 120 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 112 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 121 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 113 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 122 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 114 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 123 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 115 | 124 | ||
| 116 | if (builtin.cpu.arch != .x86_64) return error.SkipZigTest; | ||
| 117 | if (comptime !std.Target.x86.featureSetHas(builtin.cpu.features, .cx16)) return error.SkipZigTest; | ||
| 118 | |||
| 119 | try test_u128_cmpxchg(); | 125 | try test_u128_cmpxchg(); |
| 120 | comptime try test_u128_cmpxchg(); | 126 | comptime try test_u128_cmpxchg(); |
| 121 | } | 127 | } |
| ... | @@ -209,15 +215,7 @@ test "atomicrmw with floats" { | ... | @@ -209,15 +215,7 @@ test "atomicrmw with floats" { |
| 209 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 215 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 210 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 216 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 211 | 217 | ||
| 212 | if (builtin.zig_backend == .stage2_c) { | 218 | if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .aarch64) { |
| 213 | // TODO: test.c:34929:7: error: address argument to atomic operation must be a pointer to integer or pointer ('zig_f32 *' (aka 'float *') invalid | ||
| 214 | // when compiling with -std=c99 -pedantic | ||
| 215 | return error.SkipZigTest; | ||
| 216 | } | ||
| 217 | |||
| 218 | if ((builtin.zig_backend == .stage2_llvm or builtin.zig_backend == .stage2_c) and | ||
| 219 | builtin.cpu.arch == .aarch64) | ||
| 220 | { | ||
| 221 | // https://github.com/ziglang/zig/issues/10627 | 219 | // https://github.com/ziglang/zig/issues/10627 |
| 222 | return error.SkipZigTest; | 220 | return error.SkipZigTest; |
| 223 | } | 221 | } |
| ... | @@ -234,6 +232,10 @@ fn testAtomicRmwFloat() !void { | ... | @@ -234,6 +232,10 @@ fn testAtomicRmwFloat() !void { |
| 234 | try expect(x == 6); | 232 | try expect(x == 6); |
| 235 | _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst); | 233 | _ = @atomicRmw(f32, &x, .Sub, 2, .SeqCst); |
| 236 | try expect(x == 4); | 234 | try expect(x == 4); |
| 235 | _ = @atomicRmw(f32, &x, .Max, 13, .SeqCst); | ||
| 236 | try expect(x == 13); | ||
| 237 | _ = @atomicRmw(f32, &x, .Min, 42, .SeqCst); | ||
| 238 | try expect(x == 13); | ||
| 237 | } | 239 | } |
| 238 | 240 | ||
| 239 | test "atomicrmw with ints" { | 241 | test "atomicrmw with ints" { |
| ... | @@ -242,10 +244,6 @@ test "atomicrmw with ints" { | ... | @@ -242,10 +244,6 @@ test "atomicrmw with ints" { |
| 242 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 244 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 243 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 245 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 244 | 246 | ||
| 245 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 246 | return error.SkipZigTest; | ||
| 247 | } | ||
| 248 | |||
| 249 | try testAtomicRmwInts(); | 247 | try testAtomicRmwInts(); |
| 250 | comptime try testAtomicRmwInts(); | 248 | comptime try testAtomicRmwInts(); |
| 251 | } | 249 | } |
| ... | @@ -311,24 +309,25 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi | ... | @@ -311,24 +309,25 @@ fn testAtomicRmwInt(comptime signedness: std.builtin.Signedness, comptime N: usi |
| 311 | } | 309 | } |
| 312 | 310 | ||
| 313 | test "atomicrmw with 128-bit ints" { | 311 | test "atomicrmw with 128-bit ints" { |
| 314 | if (builtin.cpu.arch != .x86_64) { | 312 | if (!supports_128_bit_atomics) return error.SkipZigTest; |
| 315 | // TODO: Ideally this could use target.atomicPtrAlignment and check for IntTooBig | ||
| 316 | return error.SkipZigTest; | ||
| 317 | } | ||
| 318 | 313 | ||
| 314 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 319 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 315 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 320 | 316 | ||
| 321 | // TODO "ld.lld: undefined symbol: __sync_lock_test_and_set_16" on -mcpu x86_64 | 317 | // TODO "ld.lld: undefined symbol: __sync_lock_test_and_set_16" on -mcpu x86_64 |
| 322 | if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; | 318 | if (builtin.cpu.arch == .x86_64 and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; |
| 323 | 319 | ||
| 320 | try testAtomicRmwInt128(.signed); | ||
| 324 | try testAtomicRmwInt128(.unsigned); | 321 | try testAtomicRmwInt128(.unsigned); |
| 322 | comptime try testAtomicRmwInt128(.signed); | ||
| 325 | comptime try testAtomicRmwInt128(.unsigned); | 323 | comptime try testAtomicRmwInt128(.unsigned); |
| 326 | } | 324 | } |
| 327 | 325 | ||
| 328 | fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void { | 326 | fn testAtomicRmwInt128(comptime signedness: std.builtin.Signedness) !void { |
| 327 | const uint = std.meta.Int(.unsigned, 128); | ||
| 329 | const int = std.meta.Int(signedness, 128); | 328 | const int = std.meta.Int(signedness, 128); |
| 330 | 329 | ||
| 331 | const initial: int = 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd; | 330 | const initial: int = @bitCast(int, @as(uint, 0xaaaaaaaa_bbbbbbbb_cccccccc_dddddddd)); |
| 332 | const replacement: int = 0x00000000_00000005_00000000_00000003; | 331 | const replacement: int = 0x00000000_00000005_00000000_00000003; |
| 333 | 332 | ||
| 334 | var x: int align(16) = initial; | 333 | var x: int align(16) = initial; |
| ... | @@ -390,10 +389,6 @@ test "atomics with different types" { | ... | @@ -390,10 +389,6 @@ test "atomics with different types" { |
| 390 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 389 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 391 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 390 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 392 | 391 | ||
| 393 | if (builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 394 | return error.SkipZigTest; | ||
| 395 | } | ||
| 396 | |||
| 397 | try testAtomicsWithType(bool, true, false); | 392 | try testAtomicsWithType(bool, true, false); |
| 398 | 393 | ||
| 399 | try testAtomicsWithType(u1, 0, 1); | 394 | try testAtomicsWithType(u1, 0, 1); |
test/behavior/builtin_functions_returning_void_or_noreturn.zig-1| ... | @@ -7,7 +7,6 @@ var x: u8 = 1; | ... | @@ -7,7 +7,6 @@ var x: u8 = 1; |
| 7 | // This excludes builtin functions that return void or noreturn that cannot be tested. | 7 | // This excludes builtin functions that return void or noreturn that cannot be tested. |
| 8 | test { | 8 | test { |
| 9 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 9 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 10 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 11 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 10 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 12 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 11 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 12 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
test/behavior/cast.zig-27| ... | @@ -1313,16 +1313,6 @@ test "cast f16 to wider types" { | ... | @@ -1313,16 +1313,6 @@ test "cast f16 to wider types" { |
| 1313 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 1313 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 1314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1315 | 1315 | ||
| 1316 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1317 | // TODO: test is failing | ||
| 1318 | return error.SkipZigTest; | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | if (builtin.os.tag == .windows and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 1322 | // TODO: test is failing | ||
| 1323 | return error.SkipZigTest; | ||
| 1324 | } | ||
| 1325 | |||
| 1326 | const S = struct { | 1316 | const S = struct { |
| 1327 | fn doTheTest() !void { | 1317 | fn doTheTest() !void { |
| 1328 | var x: f16 = 1234.0; | 1318 | var x: f16 = 1234.0; |
| ... | @@ -1342,18 +1332,6 @@ test "cast f128 to narrower types" { | ... | @@ -1342,18 +1332,6 @@ test "cast f128 to narrower types" { |
| 1342 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 1332 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 1343 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1333 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1344 | 1334 | ||
| 1345 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 1346 | builtin.zig_backend == .stage2_c) | ||
| 1347 | { | ||
| 1348 | // https://github.com/ziglang/zig/issues/13876 | ||
| 1349 | return error.SkipZigTest; | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1353 | // TODO: test is failing | ||
| 1354 | return error.SkipZigTest; | ||
| 1355 | } | ||
| 1356 | |||
| 1357 | const S = struct { | 1335 | const S = struct { |
| 1358 | fn doTheTest() !void { | 1336 | fn doTheTest() !void { |
| 1359 | var x: f128 = 1234.0; | 1337 | var x: f128 = 1234.0; |
| ... | @@ -1444,11 +1422,6 @@ test "coerce between pointers of compatible differently-named floats" { | ... | @@ -1444,11 +1422,6 @@ test "coerce between pointers of compatible differently-named floats" { |
| 1444 | return error.SkipZigTest; | 1422 | return error.SkipZigTest; |
| 1445 | } | 1423 | } |
| 1446 | 1424 | ||
| 1447 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 1448 | // TODO: test is failing | ||
| 1449 | return error.SkipZigTest; | ||
| 1450 | } | ||
| 1451 | |||
| 1452 | const F = switch (@typeInfo(c_longdouble).Float.bits) { | 1425 | const F = switch (@typeInfo(c_longdouble).Float.bits) { |
| 1453 | 16 => f16, | 1426 | 16 => f16, |
| 1454 | 32 => f32, | 1427 | 32 => f32, |
test/behavior/floatop.zig-56| ... | @@ -535,18 +535,6 @@ test "another, possibly redundant, @fabs test" { | ... | @@ -535,18 +535,6 @@ test "another, possibly redundant, @fabs test" { |
| 535 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 535 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 536 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 536 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 537 | 537 | ||
| 538 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 539 | builtin.zig_backend == .stage2_c) | ||
| 540 | { | ||
| 541 | // https://github.com/ziglang/zig/issues/13876 | ||
| 542 | return error.SkipZigTest; | ||
| 543 | } | ||
| 544 | |||
| 545 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 546 | // TODO: test is failing | ||
| 547 | return error.SkipZigTest; | ||
| 548 | } | ||
| 549 | |||
| 550 | try testFabsLegacy(f128, 12.0); | 538 | try testFabsLegacy(f128, 12.0); |
| 551 | comptime try testFabsLegacy(f128, 12.0); | 539 | comptime try testFabsLegacy(f128, 12.0); |
| 552 | try testFabsLegacy(f64, 12.0); | 540 | try testFabsLegacy(f64, 12.0); |
| ... | @@ -584,18 +572,6 @@ test "a third @fabs test, surely there should not be three fabs tests" { | ... | @@ -584,18 +572,6 @@ test "a third @fabs test, surely there should not be three fabs tests" { |
| 584 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 572 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 585 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 573 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 586 | 574 | ||
| 587 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 588 | builtin.zig_backend == .stage2_c) | ||
| 589 | { | ||
| 590 | // https://github.com/ziglang/zig/issues/13876 | ||
| 591 | return error.SkipZigTest; | ||
| 592 | } | ||
| 593 | |||
| 594 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 595 | // TODO: test is failing | ||
| 596 | return error.SkipZigTest; | ||
| 597 | } | ||
| 598 | |||
| 599 | inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| { | 575 | inline for ([_]type{ f16, f32, f64, f80, f128, c_longdouble }) |T| { |
| 600 | // normals | 576 | // normals |
| 601 | try expect(@fabs(@as(T, 1.0)) == 1.0); | 577 | try expect(@fabs(@as(T, 1.0)) == 1.0); |
| ... | @@ -698,11 +674,6 @@ test "@floor f128" { | ... | @@ -698,11 +674,6 @@ test "@floor f128" { |
| 698 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 674 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 699 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 675 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 700 | 676 | ||
| 701 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 702 | // TODO: test is failing | ||
| 703 | return error.SkipZigTest; | ||
| 704 | } | ||
| 705 | |||
| 706 | try testFloorLegacy(f128, 12.0); | 677 | try testFloorLegacy(f128, 12.0); |
| 707 | comptime try testFloorLegacy(f128, 12.0); | 678 | comptime try testFloorLegacy(f128, 12.0); |
| 708 | } | 679 | } |
| ... | @@ -793,11 +764,6 @@ test "@ceil f128" { | ... | @@ -793,11 +764,6 @@ test "@ceil f128" { |
| 793 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 764 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 794 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 765 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 795 | 766 | ||
| 796 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .x86_64) { | ||
| 797 | // TODO: test is failing | ||
| 798 | return error.SkipZigTest; | ||
| 799 | } | ||
| 800 | |||
| 801 | try testCeilLegacy(f128, 12.0); | 767 | try testCeilLegacy(f128, 12.0); |
| 802 | comptime try testCeilLegacy(f128, 12.0); | 768 | comptime try testCeilLegacy(f128, 12.0); |
| 803 | } | 769 | } |
| ... | @@ -894,11 +860,6 @@ test "@trunc f128" { | ... | @@ -894,11 +860,6 @@ test "@trunc f128" { |
| 894 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 860 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 895 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 861 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 896 | 862 | ||
| 897 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 898 | // TODO: test is failing | ||
| 899 | return error.SkipZigTest; | ||
| 900 | } | ||
| 901 | |||
| 902 | try testTruncLegacy(f128, 12.0); | 863 | try testTruncLegacy(f128, 12.0); |
| 903 | comptime try testTruncLegacy(f128, 12.0); | 864 | comptime try testTruncLegacy(f128, 12.0); |
| 904 | } | 865 | } |
| ... | @@ -1010,18 +971,6 @@ test "negation f128" { | ... | @@ -1010,18 +971,6 @@ test "negation f128" { |
| 1010 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | 971 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 1011 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 972 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1012 | 973 | ||
| 1013 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 1014 | builtin.zig_backend == .stage2_c) | ||
| 1015 | { | ||
| 1016 | // https://github.com/ziglang/zig/issues/13876 | ||
| 1017 | return error.SkipZigTest; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1021 | // TODO: test is failing | ||
| 1022 | return error.SkipZigTest; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | const S = struct { | 974 | const S = struct { |
| 1026 | fn doTheTest() !void { | 975 | fn doTheTest() !void { |
| 1027 | var a: f128 = 1; | 976 | var a: f128 = 1; |
| ... | @@ -1065,11 +1014,6 @@ test "comptime fixed-width float zero divided by zero produces NaN" { | ... | @@ -1065,11 +1014,6 @@ test "comptime fixed-width float zero divided by zero produces NaN" { |
| 1065 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 1014 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 1066 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1015 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1067 | 1016 | ||
| 1068 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .x86_64) { | ||
| 1069 | // TODO: test is failing | ||
| 1070 | return error.SkipZigTest; | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | inline for (.{ f16, f32, f64, f80, f128 }) |F| { | 1017 | inline for (.{ f16, f32, f64, f80, f128 }) |F| { |
| 1074 | try expect(math.isNan(@as(F, 0) / @as(F, 0))); | 1018 | try expect(math.isNan(@as(F, 0) / @as(F, 0))); |
| 1075 | } | 1019 | } |
test/behavior/math.zig-63| ... | @@ -615,18 +615,6 @@ test "f128" { | ... | @@ -615,18 +615,6 @@ test "f128" { |
| 615 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 615 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 616 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 616 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 617 | 617 | ||
| 618 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 619 | builtin.zig_backend == .stage2_c) | ||
| 620 | { | ||
| 621 | // https://github.com/ziglang/zig/issues/13876 | ||
| 622 | return error.SkipZigTest; | ||
| 623 | } | ||
| 624 | |||
| 625 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 626 | // TODO: test is failing | ||
| 627 | return error.SkipZigTest; | ||
| 628 | } | ||
| 629 | |||
| 630 | try test_f128(); | 618 | try test_f128(); |
| 631 | comptime try test_f128(); | 619 | comptime try test_f128(); |
| 632 | } | 620 | } |
| ... | @@ -1297,18 +1285,6 @@ test "remainder division" { | ... | @@ -1297,18 +1285,6 @@ test "remainder division" { |
| 1297 | return error.SkipZigTest; | 1285 | return error.SkipZigTest; |
| 1298 | } | 1286 | } |
| 1299 | 1287 | ||
| 1300 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows and | ||
| 1301 | builtin.cpu.arch == .aarch64) | ||
| 1302 | { | ||
| 1303 | // https://github.com/ziglang/zig/issues/13876 | ||
| 1304 | return error.SkipZigTest; | ||
| 1305 | } | ||
| 1306 | |||
| 1307 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1308 | // TODO: test is failing | ||
| 1309 | return error.SkipZigTest; | ||
| 1310 | } | ||
| 1311 | |||
| 1312 | comptime try remdiv(f16); | 1288 | comptime try remdiv(f16); |
| 1313 | comptime try remdiv(f32); | 1289 | comptime try remdiv(f32); |
| 1314 | comptime try remdiv(f64); | 1290 | comptime try remdiv(f64); |
| ... | @@ -1340,11 +1316,6 @@ test "float remainder division using @rem" { | ... | @@ -1340,11 +1316,6 @@ test "float remainder division using @rem" { |
| 1340 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1316 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1341 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1317 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 1342 | 1318 | ||
| 1343 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .x86_64) { | ||
| 1344 | // TODO: test is failing | ||
| 1345 | return error.SkipZigTest; | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | comptime try frem(f16); | 1319 | comptime try frem(f16); |
| 1349 | comptime try frem(f32); | 1320 | comptime try frem(f32); |
| 1350 | comptime try frem(f64); | 1321 | comptime try frem(f64); |
| ... | @@ -1387,11 +1358,6 @@ test "float modulo division using @mod" { | ... | @@ -1387,11 +1358,6 @@ test "float modulo division using @mod" { |
| 1387 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1358 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 1388 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1359 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1389 | 1360 | ||
| 1390 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .x86_64) { | ||
| 1391 | // TODO: test is failing | ||
| 1392 | return error.SkipZigTest; | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | comptime try fmod(f16); | 1361 | comptime try fmod(f16); |
| 1396 | comptime try fmod(f32); | 1362 | comptime try fmod(f32); |
| 1397 | comptime try fmod(f64); | 1363 | comptime try fmod(f64); |
| ... | @@ -1465,11 +1431,6 @@ test "@round f128" { | ... | @@ -1465,11 +1431,6 @@ test "@round f128" { |
| 1465 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1431 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 1466 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1432 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1467 | 1433 | ||
| 1468 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1469 | // TODO: test is failing | ||
| 1470 | return error.SkipZigTest; | ||
| 1471 | } | ||
| 1472 | |||
| 1473 | try testRound(f128, 12.0); | 1434 | try testRound(f128, 12.0); |
| 1474 | comptime try testRound(f128, 12.0); | 1435 | comptime try testRound(f128, 12.0); |
| 1475 | } | 1436 | } |
| ... | @@ -1508,18 +1469,6 @@ test "NaN comparison" { | ... | @@ -1508,18 +1469,6 @@ test "NaN comparison" { |
| 1508 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1469 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 1509 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1470 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1510 | 1471 | ||
| 1511 | if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows and | ||
| 1512 | builtin.cpu.arch == .aarch64) | ||
| 1513 | { | ||
| 1514 | // https://github.com/ziglang/zig/issues/13876 | ||
| 1515 | return error.SkipZigTest; | ||
| 1516 | } | ||
| 1517 | |||
| 1518 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 1519 | // TODO: test is failing | ||
| 1520 | return error.SkipZigTest; | ||
| 1521 | } | ||
| 1522 | |||
| 1523 | try testNanEqNan(f16); | 1472 | try testNanEqNan(f16); |
| 1524 | try testNanEqNan(f32); | 1473 | try testNanEqNan(f32); |
| 1525 | try testNanEqNan(f64); | 1474 | try testNanEqNan(f64); |
| ... | @@ -1589,18 +1538,6 @@ test "signed zeros are represented properly" { | ... | @@ -1589,18 +1538,6 @@ test "signed zeros are represented properly" { |
| 1589 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | 1538 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 1590 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 1539 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 1591 | 1540 | ||
| 1592 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 1593 | builtin.zig_backend == .stage2_c) | ||
| 1594 | { | ||
| 1595 | // TODO: test is failing | ||
| 1596 | return error.SkipZigTest; | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 1600 | // TODO: test is failing | ||
| 1601 | return error.SkipZigTest; | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | const S = struct { | 1541 | const S = struct { |
| 1605 | fn doTheTest() !void { | 1542 | fn doTheTest() !void { |
| 1606 | try testOne(f16); | 1543 | try testOne(f16); |
test/behavior/muladd.zig-24| ... | @@ -68,18 +68,6 @@ test "@mulAdd f128" { | ... | @@ -68,18 +68,6 @@ test "@mulAdd f128" { |
| 68 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 68 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 70 | 70 | ||
| 71 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 72 | builtin.zig_backend == .stage2_c) | ||
| 73 | { | ||
| 74 | // https://github.com/ziglang/zig/issues/13876 | ||
| 75 | return error.SkipZigTest; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 79 | // TODO: test is failing | ||
| 80 | return error.SkipZigTest; | ||
| 81 | } | ||
| 82 | |||
| 83 | comptime try testMulAdd128(); | 71 | comptime try testMulAdd128(); |
| 84 | try testMulAdd128(); | 72 | try testMulAdd128(); |
| 85 | } | 73 | } |
| ... | @@ -201,18 +189,6 @@ test "vector f128" { | ... | @@ -201,18 +189,6 @@ test "vector f128" { |
| 201 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | 189 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 202 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 190 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 203 | 191 | ||
| 204 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 205 | builtin.zig_backend == .stage2_c) | ||
| 206 | { | ||
| 207 | // https://github.com/ziglang/zig/issues/13876 | ||
| 208 | return error.SkipZigTest; | ||
| 209 | } | ||
| 210 | |||
| 211 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c and builtin.cpu.arch == .aarch64) { | ||
| 212 | // TODO: test is failing | ||
| 213 | return error.SkipZigTest; | ||
| 214 | } | ||
| 215 | |||
| 216 | comptime try vector128(); | 192 | comptime try vector128(); |
| 217 | try vector128(); | 193 | try vector128(); |
| 218 | } | 194 | } |
test/behavior/packed-struct.zig+12| ... | @@ -615,3 +615,15 @@ test "pointer to container level packed struct field" { | ... | @@ -615,3 +615,15 @@ test "pointer to container level packed struct field" { |
| 615 | @ptrCast(*S, &S.arr[0]).other_bits.enable_3 = true; | 615 | @ptrCast(*S, &S.arr[0]).other_bits.enable_3 = true; |
| 616 | try expect(S.arr[0] == 0x10000000); | 616 | try expect(S.arr[0] == 0x10000000); |
| 617 | } | 617 | } |
| 618 | |||
| 619 | test "store undefined to packed result location" { | ||
| 620 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 621 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 622 | if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; | ||
| 623 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; | ||
| 624 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | ||
| 625 | |||
| 626 | var x: u4 = 0; | ||
| 627 | var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined }; | ||
| 628 | try expectEqual(x, s.x); | ||
| 629 | } |
test/behavior/vector.zig-12| ... | @@ -96,18 +96,6 @@ test "vector float operators" { | ... | @@ -96,18 +96,6 @@ test "vector float operators" { |
| 96 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 96 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 97 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 97 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 98 | 98 | ||
| 99 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 100 | builtin.zig_backend == .stage2_c) | ||
| 101 | { | ||
| 102 | // https://github.com/ziglang/zig/issues/13876 | ||
| 103 | return error.SkipZigTest; | ||
| 104 | } | ||
| 105 | |||
| 106 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 107 | // TODO: test is failing | ||
| 108 | return error.SkipZigTest; | ||
| 109 | } | ||
| 110 | |||
| 111 | inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| { | 99 | inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| { |
| 112 | const S = struct { | 100 | const S = struct { |
| 113 | fn doTheTest() !void { | 101 | fn doTheTest() !void { |
test/behavior/widening.zig-24| ... | @@ -43,18 +43,6 @@ test "float widening" { | ... | @@ -43,18 +43,6 @@ test "float widening" { |
| 43 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 43 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 44 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 44 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 45 | 45 | ||
| 46 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 47 | builtin.zig_backend == .stage2_c) | ||
| 48 | { | ||
| 49 | // https://github.com/ziglang/zig/issues/13876 | ||
| 50 | return error.SkipZigTest; | ||
| 51 | } | ||
| 52 | |||
| 53 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 54 | // TODO: test is failing | ||
| 55 | return error.SkipZigTest; | ||
| 56 | } | ||
| 57 | |||
| 58 | var a: f16 = 12.34; | 46 | var a: f16 = 12.34; |
| 59 | var b: f32 = a; | 47 | var b: f32 = a; |
| 60 | var c: f64 = b; | 48 | var c: f64 = b; |
| ... | @@ -75,18 +63,6 @@ test "float widening f16 to f128" { | ... | @@ -75,18 +63,6 @@ test "float widening f16 to f128" { |
| 75 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 63 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 76 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 64 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 77 | 65 | ||
| 78 | if (builtin.os.tag == .windows and builtin.cpu.arch == .aarch64 and | ||
| 79 | builtin.zig_backend == .stage2_c) | ||
| 80 | { | ||
| 81 | // https://github.com/ziglang/zig/issues/13876 | ||
| 82 | return error.SkipZigTest; | ||
| 83 | } | ||
| 84 | |||
| 85 | if (builtin.os.tag == .macos and builtin.zig_backend == .stage2_c) { | ||
| 86 | // TODO: test is failing | ||
| 87 | return error.SkipZigTest; | ||
| 88 | } | ||
| 89 | |||
| 90 | var x: f16 = 12.34; | 66 | var x: f16 = 12.34; |
| 91 | var y: f128 = x; | 67 | var y: f128 = x; |
| 92 | try expect(x == y); | 68 | try expect(x == y); |
test/cases/compile_errors/atomicrmw_with_float_op_not_.Xchg_.Add_.Sub_.Max_or_.Min.zig created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | var x: f32 = 0; | ||
| 3 | _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // backend=stage2 | ||
| 8 | // target=native | ||
| 9 | // | ||
| 10 | // :3:30: error: @atomicRmw with float only allowed with .Xchg, .Add, .Sub, .Max, and .Min | ||
test/cases/compile_errors/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | var x: f32 = 0; | ||
| 3 | _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // backend=stage2 | ||
| 8 | // target=native | ||
| 9 | // | ||
| 10 | // :3:30: error: @atomicRmw with float only allowed with .Xchg, .Add, and .Sub | ||
test/tests.zig+17-11| ... | @@ -962,13 +962,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -962,13 +962,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 962 | if (test_target.use_llvm == false and mem.eql(u8, options.name, "std")) | 962 | if (test_target.use_llvm == false and mem.eql(u8, options.name, "std")) |
| 963 | continue; | 963 | continue; |
| 964 | 964 | ||
| 965 | // TODO get std lib tests passing for the C backend | ||
| 966 | if (test_target.target.ofmt == std.Target.ObjectFormat.c and | ||
| 967 | mem.eql(u8, options.name, "std")) | ||
| 968 | { | ||
| 969 | continue; | ||
| 970 | } | ||
| 971 | |||
| 972 | const want_this_mode = for (options.optimize_modes) |m| { | 965 | const want_this_mode = for (options.optimize_modes) |m| { |
| 973 | if (m == test_target.optimize_mode) break true; | 966 | if (m == test_target.optimize_mode) break true; |
| 974 | } else false; | 967 | } else false; |
| ... | @@ -1033,6 +1026,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1033,6 +1026,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1033 | "-std=c99", | 1026 | "-std=c99", |
| 1034 | "-pedantic", | 1027 | "-pedantic", |
| 1035 | "-Werror", | 1028 | "-Werror", |
| 1029 | // TODO stop violating these pedantic errors. spotted everywhere | ||
| 1030 | "-Wno-builtin-requires-header", | ||
| 1036 | // TODO stop violating these pedantic errors. spotted on linux | 1031 | // TODO stop violating these pedantic errors. spotted on linux |
| 1037 | "-Wno-address-of-packed-member", | 1032 | "-Wno-address-of-packed-member", |
| 1038 | "-Wno-gnu-folding-constant", | 1033 | "-Wno-gnu-folding-constant", |
| ... | @@ -1044,10 +1039,21 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1044,10 +1039,21 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1044 | }, | 1039 | }, |
| 1045 | }); | 1040 | }); |
| 1046 | compile_c.addIncludePath("lib"); // for zig.h | 1041 | compile_c.addIncludePath("lib"); // for zig.h |
| 1047 | if (test_target.link_libc == false and test_target.target.getOsTag() == .windows) { | 1042 | if (test_target.target.getOsTag() == .windows) { |
| 1048 | compile_c.subsystem = .Console; | 1043 | if (test_target.link_libc == false) { |
| 1049 | compile_c.linkSystemLibrary("kernel32"); | 1044 | compile_c.subsystem = .Console; |
| 1050 | compile_c.linkSystemLibrary("ntdll"); | 1045 | compile_c.linkSystemLibrary("kernel32"); |
| 1046 | compile_c.linkSystemLibrary("ntdll"); | ||
| 1047 | } | ||
| 1048 | if (mem.eql(u8, options.name, "std")) { | ||
| 1049 | if (test_target.link_libc == false) { | ||
| 1050 | compile_c.linkSystemLibrary("shell32"); | ||
| 1051 | compile_c.linkSystemLibrary("advapi32"); | ||
| 1052 | } | ||
| 1053 | compile_c.linkSystemLibrary("crypt32"); | ||
| 1054 | compile_c.linkSystemLibrary("ws2_32"); | ||
| 1055 | compile_c.linkSystemLibrary("ole32"); | ||
| 1056 | } | ||
| 1051 | } | 1057 | } |
| 1052 | 1058 | ||
| 1053 | const run = b.addRunArtifact(compile_c); | 1059 | const run = b.addRunArtifact(compile_c); |