summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2024-04-24 18:10:17 -0700
committerMaciej Żenczykowski <maze@google.com>2024-04-24 18:13:10 -0700
commit7cc11e08cb8ba5f2161defe5c9a3d93bdd7f158a (patch)
tree3888ca85fa847c4de964b1c69f4e139d608c7014
parentbb3f1b0a9a2c6d5e48e2076f8ed827576b935d10 (diff)
downloadapf-7cc11e08cb8ba5f2161defe5c9a3d93bdd7f158a.tar.gz
v5: optimize for arm interpreter size (as opposed to x86)
u8's are cheaper than u32s (x86 is less efficient due to less byte registers and need for conversions, but any x86 using wifi chip would have tons of ram anyway, in practice this interpreter needs to be embedded into 32-bit arm or mips or something fw, not x86) After: text data bss dec hex filename 4072 0 0 4072 fe8 apf_interpreter.arm.o text data bss dec hex filename 5259 0 0 5259 148b apf_interpreter.x86.o Test: TreeHugger, manually Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Iccc46e9a65f638b4cd2d3f4b97c02d1a1d92b2dd
-rw-r--r--v5/apf_interpreter.c8
-rw-r--r--v5/apf_interpreter_source.c8
2 files changed, 8 insertions, 8 deletions
diff --git a/v5/apf_interpreter.c b/v5/apf_interpreter.c
index 7347886..077665b 100644
--- a/v5/apf_interpreter.c
+++ b/v5/apf_interpreter.c
@@ -699,13 +699,13 @@ static int do_apf_run(apf_context* ctx) {
{ /* half indent to avoid needless line length... */
const u8 bytecode = ctx->program[ctx->pc++];
- const u32 opcode = EXTRACT_OPCODE(bytecode);
- const u32 reg_num = EXTRACT_REGISTER(bytecode);
+ const u8 opcode = EXTRACT_OPCODE(bytecode);
+ const u8 reg_num = EXTRACT_REGISTER(bytecode);
#define REG (ctx->R[reg_num])
#define OTHER_REG (ctx->R[reg_num ^ 1])
/* All instructions have immediate fields, so load them now. */
- const u32 len_field = EXTRACT_IMM_LENGTH(bytecode);
- const u32 imm_len = ((len_field + 1u) >> 2) + len_field; /* 0,1,2,3 -> 0,1,2,4 */
+ const u8 len_field = EXTRACT_IMM_LENGTH(bytecode);
+ const u8 imm_len = ((len_field + 1u) >> 2) + len_field; /* 0,1,2,3 -> 0,1,2,4 */
u32 pktcopy_src_offset = 0; /* used for various pktdatacopy opcodes */
u32 imm = 0;
s32 signed_imm = 0;
diff --git a/v5/apf_interpreter_source.c b/v5/apf_interpreter_source.c
index 910c308..5f1d4fa 100644
--- a/v5/apf_interpreter_source.c
+++ b/v5/apf_interpreter_source.c
@@ -164,13 +164,13 @@ static int do_apf_run(apf_context* ctx) {
{ // half indent to avoid needless line length...
const u8 bytecode = ctx->program[ctx->pc++];
- const u32 opcode = EXTRACT_OPCODE(bytecode);
- const u32 reg_num = EXTRACT_REGISTER(bytecode);
+ const u8 opcode = EXTRACT_OPCODE(bytecode);
+ const u8 reg_num = EXTRACT_REGISTER(bytecode);
#define REG (ctx->R[reg_num])
#define OTHER_REG (ctx->R[reg_num ^ 1])
// All instructions have immediate fields, so load them now.
- const u32 len_field = EXTRACT_IMM_LENGTH(bytecode);
- const u32 imm_len = ((len_field + 1u) >> 2) + len_field; // 0,1,2,3 -> 0,1,2,4
+ const u8 len_field = EXTRACT_IMM_LENGTH(bytecode);
+ const u8 imm_len = ((len_field + 1u) >> 2) + len_field; // 0,1,2,3 -> 0,1,2,4
u32 pktcopy_src_offset = 0; // used for various pktdatacopy opcodes
u32 imm = 0;
s32 signed_imm = 0;