Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: optimize gate branching #184

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

yawn-c111
Copy link

@yawn-c111 yawn-c111 commented Sep 20, 2024

Related Issue

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

image

garble/aes128
image

garble/aes128_batched
image

garble/aes128_with_hash
image

evaluate/aes128
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant