mpz
mpz copied to clipboard
Refactor: optimize gate branching
Related Issue
- #142
Implementation
Adjusted struct field types to ensure 16-byte memory alignment and C-compatibility on frequently accessed fields.
- crates/mpz-core/src/block.rs
- crates/mpz-garble-core/src/encoding/mod.rs
#[repr(C, align(16))]
pub struct Block([u8; 16]);
Move frequently accessed struct fields outside the loop.
- crates/mpz-garble-core/src/generator.rs
- crates/mpz-garble-core/src/evaluator.rs
let labels = &mut self.labels;
let gates = &mut self.gates;
while let Some(gate) = gates.next() {
match gate {
Gate::Xor { x, y, z, } => {
let x_label = labels[x.id()];
let y_label = labels[y.id()];
labels[z.id()] = x_label ^ y_label;
Omitted field name shadowing.
- crates/mpz-garble-core/src/generator.rs
- crates/mpz-garble-core/src/evaluator.rs
Gate::Xor { x, y, z, } => {
Result
Garbling: Approximately 6-9% speed improvement Evaluation: No significant change
garble/aes128
garble/aes128_batched
garble/aes128_with_hash
evaluate/aes128