YJIT: Branch directly when truthyness is known
This commit is contained in:
parent
79f50b9d02
commit
d319184390
Notes:
git
2022-09-10 12:30:03 +09:00
@ -3197,12 +3197,6 @@ fn gen_branchif(
|
|||||||
gen_check_ints(asm, side_exit);
|
gen_check_ints(asm, side_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if any bit (outside of the Qnil bit) is on
|
|
||||||
// RUBY_Qfalse /* ...0000 0000 */
|
|
||||||
// RUBY_Qnil /* ...0000 1000 */
|
|
||||||
let val_opnd = ctx.stack_pop(1);
|
|
||||||
asm.test(val_opnd, Opnd::Imm(!Qnil.as_i64()));
|
|
||||||
|
|
||||||
// Get the branch target instruction offsets
|
// Get the branch target instruction offsets
|
||||||
let next_idx = jit_next_insn_idx(jit);
|
let next_idx = jit_next_insn_idx(jit);
|
||||||
let jump_idx = (next_idx as i32) + jump_offset;
|
let jump_idx = (next_idx as i32) + jump_offset;
|
||||||
@ -3215,6 +3209,18 @@ fn gen_branchif(
|
|||||||
idx: jump_idx as u32,
|
idx: jump_idx as u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Test if any bit (outside of the Qnil bit) is on
|
||||||
|
// RUBY_Qfalse /* ...0000 0000 */
|
||||||
|
// RUBY_Qnil /* ...0000 1000 */
|
||||||
|
let val_type = ctx.get_opnd_type(StackOpnd(0));
|
||||||
|
let val_opnd = ctx.stack_pop(1);
|
||||||
|
|
||||||
|
if let Some(result) = val_type.known_truthy() {
|
||||||
|
let target = if result { jump_block } else { next_block };
|
||||||
|
gen_direct_jump(jit, ctx, target, asm);
|
||||||
|
} else {
|
||||||
|
asm.test(val_opnd.into(), Opnd::Imm(!Qnil.as_i64()));
|
||||||
|
|
||||||
// Generate the branch instructions
|
// Generate the branch instructions
|
||||||
gen_branch(
|
gen_branch(
|
||||||
jit,
|
jit,
|
||||||
@ -3227,6 +3233,7 @@ fn gen_branchif(
|
|||||||
Some(ctx),
|
Some(ctx),
|
||||||
gen_branchif_branch,
|
gen_branchif_branch,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
EndBlock
|
EndBlock
|
||||||
}
|
}
|
||||||
@ -3261,13 +3268,6 @@ fn gen_branchunless(
|
|||||||
gen_check_ints(asm, side_exit);
|
gen_check_ints(asm, side_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if any bit (outside of the Qnil bit) is on
|
|
||||||
// RUBY_Qfalse /* ...0000 0000 */
|
|
||||||
// RUBY_Qnil /* ...0000 1000 */
|
|
||||||
let val_opnd = ctx.stack_pop(1);
|
|
||||||
let not_qnil = !Qnil.as_i64();
|
|
||||||
asm.test(val_opnd, not_qnil.into());
|
|
||||||
|
|
||||||
// Get the branch target instruction offsets
|
// Get the branch target instruction offsets
|
||||||
let next_idx = jit_next_insn_idx(jit) as i32;
|
let next_idx = jit_next_insn_idx(jit) as i32;
|
||||||
let jump_idx = next_idx + jump_offset;
|
let jump_idx = next_idx + jump_offset;
|
||||||
@ -3280,6 +3280,19 @@ fn gen_branchunless(
|
|||||||
idx: jump_idx.try_into().unwrap(),
|
idx: jump_idx.try_into().unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let val_type = ctx.get_opnd_type(StackOpnd(0));
|
||||||
|
let val_opnd = ctx.stack_pop(1);
|
||||||
|
|
||||||
|
if let Some(result) = val_type.known_truthy() {
|
||||||
|
let target = if result { next_block } else { jump_block };
|
||||||
|
gen_direct_jump(jit, ctx, target, asm);
|
||||||
|
} else {
|
||||||
|
// Test if any bit (outside of the Qnil bit) is on
|
||||||
|
// RUBY_Qfalse /* ...0000 0000 */
|
||||||
|
// RUBY_Qnil /* ...0000 1000 */
|
||||||
|
let not_qnil = !Qnil.as_i64();
|
||||||
|
asm.test(val_opnd.into(), not_qnil.into());
|
||||||
|
|
||||||
// Generate the branch instructions
|
// Generate the branch instructions
|
||||||
gen_branch(
|
gen_branch(
|
||||||
jit,
|
jit,
|
||||||
@ -3292,6 +3305,7 @@ fn gen_branchunless(
|
|||||||
Some(ctx),
|
Some(ctx),
|
||||||
gen_branchunless_branch,
|
gen_branchunless_branch,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
EndBlock
|
EndBlock
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user