diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2025-11-19 19:52:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-19 19:52:18 +0100 |
| commit | 43371cf388c66721d9ce1ef6ab397113b5e72608 (patch) | |
| tree | 5e3b06c53077ec1648fed5c313f091b57e3aff8f /src/codegen/llvm.zig | |
| parent | 806470b492f15c4e3350ce4a48e607f2c8e94ff8 (diff) | |
| parent | abd05b38195dd8b258505433555e52e3631edcfc (diff) | |
| download | zig-43371cf388c66721d9ce1ef6ab397113b5e72608.tar.gz zig-43371cf388c66721d9ce1ef6ab397113b5e72608.zip | |
Merge pull request #25965 from alexrp/s390x
`s390x-linux` and general big-endian stuff
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 450e446d8a..8d51fea0c3 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3651,35 +3651,22 @@ pub const Object = struct { .opt => {}, // pointer like optional expected else => unreachable, } - const bits = ty.bitSize(zcu); - const bytes: usize = @intCast(std.mem.alignForward(u64, bits, 8) / 8); - var stack = std.heap.stackFallback(32, o.gpa); const allocator = stack.get(); - const limbs = try allocator.alloc( - std.math.big.Limb, - std.mem.alignForward(usize, bytes, @sizeOf(std.math.big.Limb)) / - @sizeOf(std.math.big.Limb), - ); + const bits: usize = @intCast(ty.bitSize(zcu)); + + const buffer = try allocator.alloc(u8, (bits + 7) / 8); + defer allocator.free(buffer); + const limbs = try allocator.alloc(std.math.big.Limb, std.math.big.int.calcTwosCompLimbCount(bits)); defer allocator.free(limbs); - @memset(limbs, 0); - val.writeToPackedMemory(ty, pt, std.mem.sliceAsBytes(limbs)[0..bytes], 0) catch unreachable; + val.writeToPackedMemory(ty, pt, buffer, 0) catch unreachable; - if (builtin.target.cpu.arch.endian() == .little) { - if (target.cpu.arch.endian() == .big) - std.mem.reverse(u8, std.mem.sliceAsBytes(limbs)[0..bytes]); - } else if (target.cpu.arch.endian() == .little) { - for (limbs) |*limb| { - limb.* = std.mem.nativeToLittle(usize, limb.*); - } - } + var big: std.math.big.int.Mutable = .init(limbs, 0); + big.readTwosComplement(buffer, bits, target.cpu.arch.endian(), .unsigned); - return o.builder.bigIntConst(llvm_int_ty, .{ - .limbs = limbs, - .positive = true, - }); + return o.builder.bigIntConst(llvm_int_ty, big.toConst()); } fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant { |
