Skip to content

Commit 5368ef5

Browse files
committed
ZJIT: Print CUInt64 in hex when sign bit is set
It's likely some sort of mask or flags. Hexadecimal is more compact.
1 parent e163b3c commit 5368ef5

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

zjit/src/hir.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ impl<'a> std::fmt::Display for ConstPrinter<'a> {
399399
// We'll have to resolve that first.
400400
Const::CPtr(val) => write!(f, "CPtr({:?})", self.ptr_map.map_ptr(val)),
401401
&Const::CShape(shape_id) => write!(f, "CShape({:p})", self.ptr_map.map_shape(shape_id)),
402+
&Const::CUInt64(int) => {
403+
// Print in hex if signed bit is set
404+
if 0 != int & (1 << (u64::BITS - 1)) {
405+
write!(f, "CUInt64(0x{int:x})")
406+
} else {
407+
write!(f, "CUInt64({int})")
408+
}
409+
}
402410
_ => write!(f, "{:?}", self.inner),
403411
}
404412
}

zjit/src/hir/opt_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7662,13 +7662,13 @@ mod hir_opt_tests {
76627662
PatchPoint SingleRactorMode
76637663
v11:HeapBasicObject = GuardType v6, HeapBasicObject
76647664
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7665-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7665+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
76667666
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
76677667
v16 = RefineType v15, CUInt64
76687668
v17:CInt64 = IntAnd v12, v14
76697669
v18:CBool = IsBitEqual v17, v16
76707670
IfTrue v18, bb5()
7671-
v23:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7671+
v23:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
76727672
v24:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
76737673
v25 = RefineType v24, CUInt64
76747674
v26:CInt64 = IntAnd v12, v23
@@ -7738,13 +7738,13 @@ mod hir_opt_tests {
77387738
PatchPoint SingleRactorMode
77397739
v11:HeapBasicObject = GuardType v6, HeapBasicObject
77407740
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7741-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7741+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77427742
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
77437743
v16 = RefineType v15, CUInt64
77447744
v17:CInt64 = IntAnd v12, v14
77457745
v18:CBool = IsBitEqual v17, v16
77467746
IfTrue v18, bb5()
7747-
v22:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7747+
v22:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77487748
v23:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
77497749
v24 = RefineType v23, CUInt64
77507750
v25:CInt64 = IntAnd v12, v22
@@ -7809,13 +7809,13 @@ mod hir_opt_tests {
78097809
PatchPoint SingleRactorMode
78107810
v11:HeapBasicObject = GuardType v6, HeapBasicObject
78117811
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7812-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7812+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
78137813
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
78147814
v16 = RefineType v15, CUInt64
78157815
v17:CInt64 = IntAnd v12, v14
78167816
v18:CBool = IsBitEqual v17, v16
78177817
IfTrue v18, bb5()
7818-
v22:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7818+
v22:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
78197819
v23:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
78207820
v24 = RefineType v23, CUInt64
78217821
v25:CInt64 = IntAnd v12, v22

zjit/src/hir_type/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ fn write_spec(f: &mut std::fmt::Formatter, printer: &TypePrinter) -> std::fmt::R
9999
Specialization::Int(val) if ty.is_subtype(types::CUInt8) => write!(f, "[{}]", val & u8::MAX as u64),
100100
Specialization::Int(val) if ty.is_subtype(types::CUInt16) => write!(f, "[{}]", val & u16::MAX as u64),
101101
Specialization::Int(val) if ty.is_subtype(types::CUInt32) => write!(f, "[{}]", val & u32::MAX as u64),
102-
Specialization::Int(val) if ty.is_subtype(types::CUInt64) => write!(f, "[{val}]"),
102+
Specialization::Int(val) if ty.is_subtype(types::CUInt64) => {
103+
// Print in hex if signed bit is set
104+
if 0 != val & (1 << (u64::BITS - 1)) {
105+
write!(f, "[0x{val:x}]")
106+
} else {
107+
write!(f, "[{val}]")
108+
}
109+
}
103110
Specialization::Int(val) if ty.is_subtype(types::CPtr) => write!(f, "[{}]", Const::CPtr(val as *const u8).print(printer.ptr_map)),
104111
Specialization::Int(val) => write!(f, "[{val}]"),
105112
Specialization::Double(val) => write!(f, "[{val}]"),
@@ -881,7 +888,7 @@ mod tests {
881888
assert_eq!(format!("{}", Type::from_cint(types::CInt32, -1)), "CInt32[-1]");
882889
assert_eq!(format!("{}", Type::from_cint(types::CUInt32, -1)), "CUInt32[4294967295]");
883890
assert_eq!(format!("{}", Type::from_cint(types::CInt64, -1)), "CInt64[-1]");
884-
assert_eq!(format!("{}", Type::from_cint(types::CUInt64, -1)), "CUInt64[18446744073709551615]");
891+
assert_eq!(format!("{}", Type::from_cint(types::CUInt64, -1)), "CUInt64[0xffffffffffffffff]");
885892
assert_eq!(format!("{}", Type::from_cbool(true)), "CBool[true]");
886893
assert_eq!(format!("{}", Type::from_cbool(false)), "CBool[false]");
887894
assert_eq!(format!("{}", types::Fixnum), "Fixnum");

0 commit comments

Comments
 (0)