diff options
author | Maciej Żenczykowski <maze@google.com> | 2024-03-19 12:49:55 -0700 |
---|---|---|
committer | Maciej Żenczykowski <maze@google.com> | 2024-03-19 14:37:18 -0700 |
commit | 82326fbd6b3b3cdb4b16cad70f502f9d69586fb7 (patch) | |
tree | e3323e06eef7e5bdc34feac60c2b740088860237 | |
parent | 808340cd0fe586c76d263816d8f3db04feead00e (diff) | |
download | apf-82326fbd6b3b3cdb4b16cad70f502f9d69586fb7.tar.gz |
v5: JBSMATCH - always use R0 as offset
Since we use R bit to negate the condition, it's not logical
for it to also switch the register we use as the offset...
After:
text data bss dec hex filename
3880 0 0 3880 f28 apf_interpreter.arm.o
text data bss dec hex filename
4897 0 0 4897 1321 apf_interpreter.x86.o
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia6ec580968450a679d12e53cab266846336ad326
-rw-r--r-- | v5/apf_interpreter.c | 10 | ||||
-rw-r--r-- | v5/apf_interpreter_source.c | 10 |
2 files changed, 10 insertions, 10 deletions
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c index d668445..84afca8 100644 --- a/v5/apf_interpreter.c +++ b/v5/apf_interpreter.c @@ -799,16 +799,16 @@ static int do_apf_run(apf_context* ctx) { /* cmp_imm is size in bytes of data to compare. */ /* pc is offset of program bytes to compare. */ /* imm is jump target offset. */ - /* REG is offset of packet bytes to compare. */ + /* R0 is offset of packet bytes to compare. */ if (cmp_imm > 0xFFFF) return PASS_PACKET; Boolean do_jump = !reg_num; /* pc < program_len < ram_len < 2GiB, thus pc + cmp_imm cannot wrap */ if (!IN_RAM_BOUNDS(ctx->pc + cmp_imm - 1)) return PASS_PACKET; - ASSERT_IN_PACKET_BOUNDS(REG); - const u32 last_packet_offs = REG + cmp_imm - 1; - ASSERT_RETURN(last_packet_offs >= REG); + ASSERT_IN_PACKET_BOUNDS(ctx->R[0]); + const u32 last_packet_offs = ctx->R[0] + cmp_imm - 1; + ASSERT_RETURN(last_packet_offs >= ctx->R[0]); ASSERT_IN_PACKET_BOUNDS(last_packet_offs); - do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + REG, cmp_imm); + do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], cmp_imm); /* skip past comparison bytes */ ctx->pc += cmp_imm; if (do_jump) ctx->pc += imm; diff --git a/v5/apf_interpreter_source.c b/v5/apf_interpreter_source.c index 6c510d8..5951bfe 100644 --- a/v5/apf_interpreter_source.c +++ b/v5/apf_interpreter_source.c @@ -265,16 +265,16 @@ static int do_apf_run(apf_context* ctx) { // cmp_imm is size in bytes of data to compare. // pc is offset of program bytes to compare. // imm is jump target offset. - // REG is offset of packet bytes to compare. + // R0 is offset of packet bytes to compare. if (cmp_imm > 0xFFFF) return PASS_PACKET; bool do_jump = !reg_num; // pc < program_len < ram_len < 2GiB, thus pc + cmp_imm cannot wrap if (!IN_RAM_BOUNDS(ctx->pc + cmp_imm - 1)) return PASS_PACKET; - ASSERT_IN_PACKET_BOUNDS(REG); - const u32 last_packet_offs = REG + cmp_imm - 1; - ASSERT_RETURN(last_packet_offs >= REG); + ASSERT_IN_PACKET_BOUNDS(ctx->R[0]); + const u32 last_packet_offs = ctx->R[0] + cmp_imm - 1; + ASSERT_RETURN(last_packet_offs >= ctx->R[0]); ASSERT_IN_PACKET_BOUNDS(last_packet_offs); - do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + REG, cmp_imm); + do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], cmp_imm); // skip past comparison bytes ctx->pc += cmp_imm; if (do_jump) ctx->pc += imm; |