summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2024-04-26 10:52:25 -0700
committerMaciej Żenczykowski <maze@google.com>2024-04-26 11:16:44 -0700
commit7ad0a6be962a29c68b3533acfb3dcec6b269b3db (patch)
tree886162f14eb4a05d529b72f38296ed6c844494cb
parenta13437415fa9f39a0a5389ce4b4de35563bb4fce (diff)
downloadapf-7ad0a6be962a29c68b3533acfb3dcec6b269b3db.tar.gz
v5: support even set multiples in JBSMATCH
shrinks code size by 4 After: text data bss dec hex filename 4296 0 0 4296 10c8 apf_interpreter.arm.o text data bss dec hex filename 5581 0 0 5581 15cd apf_interpreter.x86.o Test: TreeHugger, manual Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I85fef1a55cb0c00776c8563cb78110cf7c4023cb
-rw-r--r--v5/apf_interpreter.c6
-rw-r--r--v5/apf_interpreter_source.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c
index ce95963..001aad9 100644
--- a/v5/apf_interpreter.c
+++ b/v5/apf_interpreter.c
@@ -824,7 +824,7 @@ static int do_apf_run(apf_context* ctx) {
u32 len = cmp_imm & 2047; /* 0..2047 */
u32 bytes = cnt * len;
const u32 last_packet_offs = ctx->R[0] + len - 1;
- Boolean do_jump = !reg_num;
+ Boolean matched = False;
/* bytes = cnt * len is size in bytes of data to compare. */
/* pc is offset of program bytes to compare. */
/* imm is jump target offset. */
@@ -837,11 +837,11 @@ static int do_apf_run(apf_context* ctx) {
ASSERT_RETURN(last_packet_offs >= ctx->R[0]);
ASSERT_IN_PACKET_BOUNDS(last_packet_offs);
while (cnt--) {
- do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], len);
+ matched |= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], len);
/* skip past comparison bytes */
ctx->pc += len;
}
- if (do_jump) ctx->pc += imm;
+ if (matched ^ !reg_num) ctx->pc += imm;
break;
}
/* There is a difference in APFv4 and APFv6 arithmetic behaviour! */
diff --git a/v5/apf_interpreter_source.c b/v5/apf_interpreter_source.c
index e9708d7..68af15b 100644
--- a/v5/apf_interpreter_source.c
+++ b/v5/apf_interpreter_source.c
@@ -280,7 +280,7 @@ static int do_apf_run(apf_context* ctx) {
u32 len = cmp_imm & 2047; // 0..2047
u32 bytes = cnt * len;
const u32 last_packet_offs = ctx->R[0] + len - 1;
- bool do_jump = !reg_num;
+ bool matched = false;
// bytes = cnt * len is size in bytes of data to compare.
// pc is offset of program bytes to compare.
// imm is jump target offset.
@@ -293,11 +293,11 @@ static int do_apf_run(apf_context* ctx) {
ASSERT_RETURN(last_packet_offs >= ctx->R[0]);
ASSERT_IN_PACKET_BOUNDS(last_packet_offs);
while (cnt--) {
- do_jump ^= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], len);
+ matched |= !memcmp(ctx->program + ctx->pc, ctx->packet + ctx->R[0], len);
// skip past comparison bytes
ctx->pc += len;
}
- if (do_jump) ctx->pc += imm;
+ if (matched ^ !reg_num) ctx->pc += imm;
break;
}
// There is a difference in APFv4 and APFv6 arithmetic behaviour!