8000 Avoid interrupt checks for forward branches (#41) · eileencodes/ruby@ef0d1ca · GitHub
[go: up one dir, main page]

Skip to content

Commit ef0d1ca

Browse files
authored
Avoid interrupt checks for forward branches (ruby#41)
1 parent b4cd126 commit ef0d1ca

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

yjit_codegen.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,10 +1722,13 @@ gen_branchif_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t
17221722
static codegen_status_t
17231723
gen_branchif(jitstate_t* jit, ctx_t* ctx)
17241724
{
1725-
// FIXME: eventually, put VM_CHECK_INTS() only on backward branch targets
1726-
// Check for interrupts
1727-
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1728-
yjit_check_ints(cb, side_exit);
1725+
int32_t jump_offset = (int32_t)jit_get_arg(jit, 0);
1726+
1727+
// Check for interrupts, but only on backward branches that may create loops
1728+
if (jump_offset < 0) {
1729+
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1730+
yjit_check_ints(cb, side_exit);
1731+
}
17291732

17301733
// Test if any bit (outside of the Qnil bit) is on
17311734
// RUBY_Qfalse /* ...0000 0000 */
@@ -1735,7 +1738,7 @@ gen_branchif(jitstate_t* jit, ctx_t* ctx)
17351738

17361739
// Get the branch target instruction offsets
17371740
uint32_t next_idx = jit_next_insn_idx(jit);
1738-
uint32_t jump_idx = next_idx + (uint32_t)jit_get_arg(jit, 0);
1741+
uint32_t jump_idx = next_idx + jump_offset;
17391742
blockid_t next_block = { jit->iseq, next_idx };
17401743
blockid_t jump_block = { jit->iseq, jump_idx };
17411744

@@ -1776,10 +1779,13 @@ gen_branchunless_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uin
17761779
static codegen_statu 8000 s_t
17771780
gen_branchunless(jitstate_t* jit, ctx_t* ctx)
17781781
{
1779-
// FIXME: eventually, put VM_CHECK_INTS() only on backward branch targets
1780-
// Check for interrupts
1781-
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1782-
yjit_check_ints(cb, side_exit);
1782+
int32_t jump_offset = (int32_t)jit_get_arg(jit, 0);
1783+
1784+
// Check for interrupts, but only on backward branches that may create loops
1785+
if (jump_offset < 0) {
1786+
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1787+
yjit_check_ints(cb, side_exit);
1788+
}
17831789

17841790
// Test if any bit (outside of the Qnil bit) is on
17851791
// RUBY_Qfalse /* ...0000 0000 */
@@ -1789,7 +1795,7 @@ gen_branchunless(jitstate_t* jit, ctx_t* ctx)
17891795

17901796
// Get the branch target instruction offsets
17911797
uint32_t next_idx = jit_next_insn_idx(jit);
1792-
uint32_t jump_idx = next_idx + (uint32_t)jit_get_arg(jit, 0);
1798+
uint32_t jump_idx = next_idx + jump_offset;
17931799
blockid_t next_block = { jit->iseq, next_idx };
17941800
blockid_t jump_block = { jit->iseq, jump_idx };
17951801

@@ -1830,10 +1836,13 @@ gen_branchnil_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_
18301836
static codegen_status_t
18311837
gen_branchnil(jitstate_t* jit, ctx_t* ctx)
18321838
{
1833-
// FIXME: eventually, put VM_CHECK_INTS() only on backward branch targets
1834-
// Check for interrupts
1835-
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1836-
yjit_check_ints(cb, side_exit);
1839+
int32_t jump_offset = (int32_t)jit_get_arg(jit, 0);
1840+
1841+
// Check for interrupts, but only on backward branches that may create loops
1842+
if (jump_offset < 0) {
1843+
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1844+
yjit_check_ints(cb, side_exit);
1845+
}
18371846

18381847
// Test if the value is Qnil
18391848
// RUBY_Qnil /* ...0000 1000 */
@@ -1842,7 +1851,7 @@ gen_branchnil(jitstate_t* jit, ctx_t* ctx)
18421851

18431852
// Get the branch target instruction offsets
18441853
uint32_t next_idx = jit_next_insn_idx(jit);
1845-
uint32_t jump_idx = next_idx + (uint32_t)jit_get_arg(jit, 0);
1854+
uint32_t jump_idx = next_idx + jump_offset;
18461855
blockid_t next_block = { jit->iseq, next_idx };
18471856
blockid_t jump_block = { jit->iseq, jump_idx };
18481857

@@ -1863,13 +1872,16 @@ gen_branchnil(jitstate_t* jit, ctx_t* ctx)
18631872
static codegen_status_t
18641873
gen_jump(jitstate_t* jit, ctx_t* ctx)
18651874
{
1866-
// FIXME: eventually, put VM_CHECK_INTS() only on backward branch targets
1867-
// Check for interrupts
1868-
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1869-
yjit_check_ints(cb, side_exit);
1875+
int32_t jump_offset = (int32_t)jit_get_arg(jit, 0);
1876+
1877+
// Check for interrupts, but only on backward branches that may create loops
1878+
if (jump_offset < 0) {
1879+
uint8_t* side_exit = yjit_side_exit(jit, ctx);
1880+
yjit_check_ints(cb, side_exit);
1881+
}
18701882

18711883
// Get the branch target instruction offsets
1872-
uint32_t jump_idx = jit_next_insn_idx(jit) + (int32_t)jit_get_arg(jit, 0);
1884+
uint32_t jump_idx = jit_next_insn_idx(jit) + jump_offset;
18731885
blockid_t jump_block = { jit->iseq, jump_idx };
18741886

18751887
// Generate the jump instruction

0 commit comments

Comments
 (0)
0