Skip to content

Commit 78af62a

Browse files
committed
Pack big.Int sign and length fields
This effectively takes one-bit from the length field and uses it as the sign bit. It reduces the size of an Int from 40 bits to 32 bits on a 64-bit arch. This also reduces std.Rational from 80 bits to 64 bits.
1 parent 87d8ecd commit 78af62a

File tree

3 files changed

+203
-185
lines changed

3 files changed

+203
-185
lines changed

src-self-hosted/value.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,21 +538,21 @@ pub const Value = struct {
538538
switch (self.base.typ.id) {
539539
Type.Id.Int => {
540540
const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
541-
if (self.big_int.len == 0) {
541+
if (self.big_int.len() == 0) {
542542
return llvm.ConstNull(type_ref);
543543
}
544-
const unsigned_val = if (self.big_int.len == 1) blk: {
544+
const unsigned_val = if (self.big_int.len() == 1) blk: {
545545
break :blk llvm.ConstInt(type_ref, self.big_int.limbs[0], @boolToInt(false));
546546
} else if (@sizeOf(std.math.big.Limb) == @sizeOf(u64)) blk: {
547547
break :blk llvm.ConstIntOfArbitraryPrecision(
548548
type_ref,
549-
@intCast(c_uint, self.big_int.len),
549+
@intCast(c_uint, self.big_int.len()),
550550
@ptrCast([*]u64, self.big_int.limbs.ptr),
551551
);
552552
} else {
553553
@compileError("std.math.Big.Int.Limb size does not match LLVM");
554554
};
555-
return if (self.big_int.positive) unsigned_val else llvm.ConstNeg(unsigned_val);
555+
return if (self.big_int.isPositive()) unsigned_val else llvm.ConstNeg(unsigned_val);
556556
},
557557
Type.Id.ComptimeInt => unreachable,
558558
else => unreachable,

0 commit comments

Comments
 (0)