Skip to content

Commit

Permalink
feat: replace LOAD/STORE immediates with ADD
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Jan 10, 2025
1 parent ad5f374 commit f745778
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions extensions/native/compiler/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,22 +503,38 @@ fn convert_instruction<F: PrimeField32, EF: ExtensionField<F>>(
vec![]
}
}
AsmInstruction::ImmF(dst, val) => vec![inst(
options.opcode_with_offset(NativeLoadStoreOpcode::STOREW),
val,
F::ZERO,
i32_f(dst),
AS::Immediate,
AS::Native,
)],
AsmInstruction::CopyF(dst, src) => vec![inst(
options.opcode_with_offset(NativeLoadStoreOpcode::LOADW),
i32_f(dst),
F::ZERO,
i32_f(src),
AS::Native,
AS::Immediate,
)],
AsmInstruction::ImmF(dst, val) => if options.field_arithmetic_enabled {
vec![inst_med(
options.opcode_with_offset(FieldArithmeticOpcode::ADD),
i32_f(dst),
val,
F::ZERO,
AS::Native,
AS::Immediate,
AS::Native,
)]
} else {
panic!(
"Unsupported instruction {:?}, field arithmetic is disabled",
instruction
)
},
AsmInstruction::CopyF(dst, src) => if options.field_arithmetic_enabled {
vec![inst_med(
options.opcode_with_offset(FieldArithmeticOpcode::ADD),
i32_f(dst),
i32_f(src),
F::ZERO,
AS::Native,
AS::Native,
AS::Immediate
)]
} else {
panic!(
"Unsupported instruction {:?}, field arithmetic is disabled",
instruction
)
},
AsmInstruction::AddF(..)
| AsmInstruction::SubF(..)
| AsmInstruction::MulF(..)
Expand Down Expand Up @@ -612,13 +628,14 @@ pub fn convert_program<F: PrimeField32, EF: ExtensionField<F>>(
options: CompilerOptions,
) -> Program<F> {
// mem[0] <- 0
let init_register_0 = inst(
options.opcode_with_offset(NativeLoadStoreOpcode::STOREW),
let init_register_0 = inst_med(
options.opcode_with_offset(FieldArithmeticOpcode::ADD),
F::ZERO,
F::ZERO,
F::ZERO,
i32_f(0),
AS::Immediate,
AS::Native,
AS::Immediate,
AS::Immediate,
);
let init_debug_info = None;

Expand Down

0 comments on commit f745778

Please sign in to comment.