Skip to content

Commit 970e993

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 fe47ff0 commit 970e993

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

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
@@ -7713,13 +7713,13 @@ mod hir_opt_tests {
77137713
PatchPoint SingleRactorMode
77147714
v11:HeapBasicObject = GuardType v6, HeapBasicObject
77157715
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7716-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7716+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77177717
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
77187718
v16 = RefineType v15, CUInt64
77197719
v17:CInt64 = IntAnd v12, v14
77207720
v18:CBool = IsBitEqual v17, v16
77217721
IfTrue v18, bb5()
7722-
v23:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7722+
v23:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77237723
v24:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
77247724
v25 = RefineType v24, CUInt64
77257725
v26:CInt64 = IntAnd v12, v23
@@ -7789,13 +7789,13 @@ mod hir_opt_tests {
77897789
PatchPoint SingleRactorMode
77907790
v11:HeapBasicObject = GuardType v6, HeapBasicObject
77917791
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7792-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7792+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77937793
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
77947794
v16 = RefineType v15, CUInt64
77957795
v17:CInt64 = IntAnd v12, v14
77967796
v18:CBool = IsBitEqual v17, v16
77977797
IfTrue v18, bb5()
7798-
v22:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7798+
v22:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
77997799
v23:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
78007800
v24 = RefineType v23, CUInt64
78017801
v25:CInt64 = IntAnd v12, v22
@@ -7860,13 +7860,13 @@ mod hir_opt_tests {
78607860
PatchPoint SingleRactorMode
78617861
v11:HeapBasicObject = GuardType v6, HeapBasicObject
78627862
v12:CUInt64 = LoadField v11, :_rbasic_flags@0x1000
7863-
v14:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7863+
v14:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
78647864
v15:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
78657865
v16 = RefineType v15, CUInt64
78667866
v17:CInt64 = IntAnd v12, v14
78677867
v18:CBool = IsBitEqual v17, v16
78687868
IfTrue v18, bb5()
7869-
v22:CUInt64[18446744069414584351] = Const CUInt64(18446744069414584351)
7869+
v22:CUInt64[0xffffffff0000001f] = Const CUInt64(0xffffffff0000001f)
78707870
v23:CPtr[CPtr(0x1008)] = Const CPtr(0x1010)
78717871
v24 = RefineType v23, CUInt64
78727872
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)