Skip to content

Commit cb28165

Browse files
authored
ZJIT: Enable or remove comments from YJIT (ruby#14214)
1 parent c9346a1 commit cb28165

File tree

7 files changed

+12
-466
lines changed

7 files changed

+12
-466
lines changed

zjit/src/asm/arm64/inst/branch_cond.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl From<BranchCond> for [u8; 4] {
4747
}
4848
}
4949

50-
/*
5150
#[cfg(test)]
5251
mod tests {
5352
use super::*;
@@ -77,4 +76,3 @@ mod tests {
7776
assert_eq!(0x54800000, result);
7877
}
7978
}
80-
*/

zjit/src/asm/arm64/inst/conditional.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ impl From<Conditional> for [u8; 4] {
6060
}
6161
}
6262

63-
/*
6463
#[cfg(test)]
6564
mod tests {
6665
use super::*;
@@ -72,4 +71,3 @@ mod tests {
7271
assert_eq!(0x9a821020, result);
7372
}
7473
}
75-
*/

zjit/src/asm/mod.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ pub fn uimm_num_bits(uimm: u64) -> u8
345345
return 64;
346346
}
347347

348-
/*
349348
#[cfg(test)]
350349
mod tests
351350
{
@@ -381,32 +380,5 @@ mod tests
381380
assert_eq!(uimm_num_bits((u32::MAX as u64) + 1), 64);
382381
assert_eq!(uimm_num_bits(u64::MAX), 64);
383382
}
384-
385-
#[test]
386-
fn test_code_size() {
387-
// Write 4 bytes in the first page
388-
let mut cb = CodeBlock::new_dummy(CodeBlock::PREFERRED_CODE_PAGE_SIZE * 2);
389-
cb.write_bytes(&[0, 0, 0, 0]);
390-
assert_eq!(cb.code_size(), 4);
391-
392-
// Moving to the next page should not increase code_size
393-
cb.next_page(cb.get_write_ptr(), |_, _| {});
394-
assert_eq!(cb.code_size(), 4);
395-
396-
// Write 4 bytes in the second page
397-
cb.write_bytes(&[0, 0, 0, 0]);
398-
assert_eq!(cb.code_size(), 8);
399-
400-
// Rewrite 4 bytes in the first page
401-
let old_write_pos = cb.get_write_pos();
402-
cb.set_pos(0);
403-
cb.write_bytes(&[1, 1, 1, 1]);
404-
405-
// Moving from an old page to the next page should not increase code_size
406-
cb.next_page(cb.get_write_ptr(), |_, _| {});
407-
cb.set_pos(old_write_pos);
408-
assert_eq!(cb.code_size(), 8);
409-
}
410383
}
411384

412-
*/

zjit/src/asm/x86_64/mod.rs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -317,34 +317,6 @@ pub fn mem_opnd_sib(num_bits: u8, base_opnd: X86Opnd, index_opnd: X86Opnd, scale
317317
}
318318
}
319319

320-
/*
321-
// Struct member operand
322-
#define member_opnd(base_reg, struct_type, member_name) mem_opnd( \
323-
8 * sizeof(((struct_type*)0)->member_name), \
324-
base_reg, \
325-
offsetof(struct_type, member_name) \
326-
)
327-
328-
// Struct member operand with an array index
329-
#define member_opnd_idx(base_reg, struct_type, member_name, idx) mem_opnd( \
330-
8 * sizeof(((struct_type*)0)->member_name[0]), \
331-
base_reg, \
332-
(offsetof(struct_type, member_name) + \
333-
sizeof(((struct_type*)0)->member_name[0]) * idx) \
334-
)
335-
*/
336-
337-
/*
338-
// TODO: this should be a method, X86Opnd.resize() or X86Opnd.subreg()
339-
static x86opnd_t resize_opnd(x86opnd_t opnd, uint32_t num_bits)
340-
{
341-
assert (num_bits % 8 == 0);
342-
x86opnd_t sub = opnd;
343-
sub.num_bits = num_bits;
344-
return sub;
345-
}
346-
*/
347-
348320
pub fn imm_opnd(value: i64) -> X86Opnd
349321
{
350322
X86Opnd::Imm(X86Imm { num_bits: imm_num_bits(value), value })
@@ -1103,46 +1075,6 @@ pub fn movsx(cb: &mut CodeBlock, dst: X86Opnd, src: X86Opnd) {
11031075
}
11041076
}
11051077

1106-
/*
1107-
/// movzx - Move with zero extension (unsigned values)
1108-
void movzx(codeblock_t *cb, x86opnd_t dst, x86opnd_t src)
1109-
{
1110-
cb.writeASM("movzx", dst, src);
1111-
1112-
uint32_t dstSize;
1113-
if (dst.isReg)
1114-
dstSize = dst.reg.size;
1115-
else
1116-
assert (false, "movzx dst must be a register");
1117-
1118-
uint32_t srcSize;
1119-
if (src.isReg)
1120-
srcSize = src.reg.size;
1121-
else if (src.isMem)
1122-
srcSize = src.mem.size;
1123-
else
1124-
assert (false);
1125-
1126-
assert (
1127-
srcSize < dstSize,
1128-
"movzx: srcSize >= dstSize"
1129-
);
1130-
1131-
if (srcSize is 8)
1132-
{
1133-
cb.writeRMInstr!('r', 0xFF, 0x0F, 0xB6)(dstSize is 16, dstSize is 64, dst, src);
1134-
}
1135-
else if (srcSize is 16)
1136-
{
1137-
cb.writeRMInstr!('r', 0xFF, 0x0F, 0xB7)(dstSize is 16, dstSize is 64, dst, src);
1138-
}
1139-
else
1140-
{
1141-
assert (false, "invalid src operand size for movxz");
1142-
}
1143-
}
1144-
*/
1145-
11461078
/// nop - Noop, one or multiple bytes long
11471079
pub fn nop(cb: &mut CodeBlock, length: u32) {
11481080
match length {

zjit/src/backend/arm64/mod.rs

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl Assembler
317317
asm.load(opnd)
318318
}
319319
},
320-
Opnd::None | Opnd::Value(_) /*| Opnd::Stack { .. }*/ => unreachable!()
320+
Opnd::None | Opnd::Value(_) => unreachable!()
321321
}
322322
}
323323

@@ -1742,21 +1742,19 @@ mod tests {
17421742
asm.compile_with_num_regs(&mut cb, 0);
17431743
}
17441744

1745-
/*
17461745
#[test]
17471746
fn test_emit_lea_label() {
17481747
let (mut asm, mut cb) = setup_asm();
17491748

17501749
let label = asm.new_label("label");
1751-
let opnd = asm.lea_jump_target(label);
1750+
let opnd = asm.lea_jump_target(label.clone());
17521751

17531752
asm.write_label(label);
17541753
asm.bake_string("Hello, world!");
17551754
asm.store(Opnd::mem(64, SP, 0), opnd);
17561755

17571756
asm.compile_with_num_regs(&mut cb, 1);
17581757
}
1759-
*/
17601758

17611759
#[test]
17621760
fn test_emit_load_mem_disp_fits_into_load() {
@@ -1967,48 +1965,6 @@ mod tests {
19671965
asm.compile_with_num_regs(&mut cb, 2);
19681966
}
19691967

1970-
/*
1971-
#[test]
1972-
fn test_bcond_straddling_code_pages() {
1973-
const LANDING_PAGE: usize = 65;
1974-
let mut asm = Assembler::new(0);
1975-
let mut cb = CodeBlock::new_dummy_with_freed_pages(vec![0, LANDING_PAGE]);
1976-
1977-
// Skip to near the end of the page. Room for two instructions.
1978-
cb.set_pos(cb.page_start_pos() + cb.page_end() - 8);
1979-
1980-
let end = asm.new_label("end");
1981-
// Start with a conditional jump...
1982-
asm.jz(end);
1983-
1984-
// A few instructions, enough to cause a page switch.
1985-
let sum = asm.add(399.into(), 111.into());
1986-
let xorred = asm.xor(sum, 859.into());
1987-
asm.store(Opnd::mem(64, Opnd::Reg(X2_REG), 0), xorred);
1988-
asm.store(Opnd::mem(64, Opnd::Reg(X0_REG), 0), xorred);
1989-
1990-
// The branch target. It should be in the landing page.
1991-
asm.write_label(end);
1992-
asm.cret(xorred);
1993-
1994-
// [Bug #19385]
1995-
// This used to panic with "The offset must be 19 bits or less."
1996-
// due to attempting to lower the `asm.jz` above to a `b.e` with an offset that's > 1 MiB.
1997-
let starting_pos = cb.get_write_pos();
1998-
asm.compile_with_num_regs(&mut cb, 2);
1999-
let gap = cb.get_write_pos() - starting_pos;
2000-
assert!(gap > 0b1111111111111111111);
2001-
2002-
let instruction_at_starting_pos: [u8; 4] = unsafe {
2003-
std::slice::from_raw_parts(cb.get_ptr(starting_pos).raw_ptr(&cb), 4)
2004-
}.try_into().unwrap();
2005-
assert_eq!(
2006-
0b000101 << 26_u32,
2007-
u32::from_le_bytes(instruction_at_starting_pos) & (0b111111 << 26_u32),
2008-
"starting instruction should be an unconditional branch to the new page (B)"
2009-
);
2010-
}
2011-
20121968
#[test]
20131969
fn test_emit_xor() {
20141970
let (mut asm, mut cb) = setup_asm();
@@ -2018,9 +1974,9 @@ mod tests {
20181974

20191975
asm.compile_with_num_regs(&mut cb, 1);
20201976

2021-
assert_disasm!(cb, "0b0001ca4b0000f8", "
2022-
0x0: eor x11, x0, x1
2023-
0x4: stur x11, [x2]
1977+
assert_disasm!(cb, "000001ca400000f8", "
1978+
0x0: eor x0, x0, x1
1979+
0x4: stur x0, [x2]
20241980
");
20251981
}
20261982

@@ -2082,10 +2038,10 @@ mod tests {
20822038
asm.mov(Opnd::Reg(TEMP_REGS[0]), out);
20832039
asm.compile_with_num_regs(&mut cb, 2);
20842040

2085-
assert_disasm!(cb, "8b0280d20c0080d261b18c9a", {"
2086-
0x0: mov x11, #0x14
2087-
0x4: mov x12, #0
2088-
0x8: csel x1, x11, x12, lt
2041+
assert_disasm!(cb, "800280d2010080d201b0819a", {"
2042+
0x0: mov x0, #0x14
2043+
0x4: mov x1, #0
2044+
0x8: csel x1, x0, x1, lt
20892045
"});
20902046
}
20912047

@@ -2098,11 +2054,9 @@ mod tests {
20982054
asm.mov(Opnd::Reg(TEMP_REGS[0]), out);
20992055
asm.compile_with_num_regs(&mut cb, 2);
21002056

2101-
assert_disasm!(cb, "2b0500b16b0500b1e1030baa", {"
2102-
0x0: adds x11, x9, #1
2103-
0x4: adds x11, x11, #1
2104-
0x8: mov x1, x11
2057+
assert_disasm!(cb, "200500b1010400b1", {"
2058+
0x0: adds x0, x9, #1
2059+
0x4: adds x1, x0, #1
21052060
"});
21062061
}
2107-
*/
21082062
}

0 commit comments

Comments
 (0)