Skip to content

Commit

Permalink
remove unused montgommery reduce for 512 bit input in asm feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kilic committed Aug 3, 2023
1 parent 9a25a02 commit 9242ce3
Showing 1 changed file with 0 additions and 163 deletions.
163 changes: 0 additions & 163 deletions src/bn256/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,169 +68,6 @@ macro_rules! field_arithmetic_asm {
self.mul(self)
}

#[inline(always)]
pub(crate) fn montgomery_reduce(a: &[u64; 8]) -> $field {
let mut r0: u64;
let mut r1: u64;
let mut r2: u64;
let mut r3: u64;

unsafe {
asm!(
"mov r8, qword ptr [{a_ptr} + 0]",
"mov r9, qword ptr [{a_ptr} + 8]",
"mov r10, qword ptr [{a_ptr} + 16]",
"mov r11, qword ptr [{a_ptr} + 24]",
"mov r12, qword ptr [{a_ptr} + 32]",
"xor rcx, rcx", // clear flags and zero carry adder

// i0
// tmp @ r13
"mov rdx, {inv}",
"mulx r13, rdx, r8",

// j0
"mulx r13, rax, qword ptr [{m_ptr} + 0]",
"adox r8, rax",
"adcx r9, r13",
// j1
"mulx r13, rax, qword ptr [{m_ptr} + 8]",
"adox r9, rax",
"adcx r10, r13",
// j2
"mulx r13, rax, qword ptr [{m_ptr} + 16]",
"adox r10, rax",
"adcx r11, r13",
// j3
"mulx r13, rax, qword ptr [{m_ptr} + 24]",
"adox r11, rax",
"adcx r12, r13",
// carry @ r8
"adox r12, rcx", // add carry
"adcx r8, rcx", // save carry
"adox r8, rcx", // save carry


// i1
// tmp @ r14
"mov r13, qword ptr [{a_ptr} + 40]",
"mov rdx, {inv}",
"mulx r14, rdx, r9",

// j0
"mulx r14, rax, qword ptr [{m_ptr} + 0]",
"adox r9, rax",
"adcx r10, r14",

// j1
"mulx r14, rax, qword ptr [{m_ptr} + 8]",
"adox r10, rax",
"adcx r11, r14",
// j2
"mulx r14, rax, qword ptr [{m_ptr} + 16]",
"adox r11, rax",
"adcx r12, r14",
// j3
"mulx r14, rax, qword ptr [{m_ptr} + 24]",
"adox r12, rax",
"adcx r13, r14",
// carry @ r9
"adox r13, r8", // add carry
"adcx r9, rcx", // save carry
"adox r9, rcx", // save carrys

// i2
// tmp @ r15
"mov r14, qword ptr [{a_ptr} + 48]",
"mov rdx, {inv}",
"mulx r15, rdx, r10",

// j0
"mulx r15, rax, qword ptr [{m_ptr} + 0]",
"adox r10, rax",
"adcx r11, r15",

// j1
"mulx r15, rax, qword ptr [{m_ptr} + 8]",
"adox r11, rax",
"adcx r12, r15",

// j2
"mulx r15, rax, qword ptr [{m_ptr} + 16]",
"adox r12, rax",
"adcx r13, r15",

// j3
"mulx r15, rax, qword ptr [{m_ptr} + 24]",
"adox r13, rax",
"adcx r14, r15",
// carry @ r10
"adox r14, r9", // add carry
"adcx r10, rcx", // save carry
"adox r10, rcx", // save carry


// i3
// tmp @ r8
"mov r15, qword ptr [{a_ptr} + 56]",
"mov rdx, {inv}",
"mulx r8, rdx, r11",
// j0
"mulx r8, rax, qword ptr [{m_ptr} + 0]",
"adox r11, rax",
"adcx r12, r8",
// j1
"mulx r8, rax, qword ptr [{m_ptr} + 8]",
"adox r12, rax",
"adcx r13, r8",
// j2
"mulx r8, rax, qword ptr [{m_ptr} + 16]",
"adox r13, rax",
"adcx r14, r8",
// j3
"mulx r8, rax, qword ptr [{m_ptr} + 24]",
"adox r14, rax",
"adcx r15, r8",
// add carry
"adox r15, r10",

// final subtraction
"mov r8, r12",
"sub r8, qword ptr [{m_ptr} + 0]",
"mov r9, r13",
"sbb r9, qword ptr [{m_ptr} + 8]",
"mov r10, r14",
"sbb r10, qword ptr [{m_ptr} + 16]",
"mov r11, r15",
"sbb r11, qword ptr [{m_ptr} + 24]",

"cmovnc r12, r8",
"cmovnc r13, r9",
"cmovnc r14, r10",
"cmovnc r15, r11",


a_ptr = in(reg) a.as_ptr(),
m_ptr = in(reg) $modulus.0.as_ptr(),
inv = in(reg) $inv,
out("rax") _,
out("rcx") _,
out("rdx") _,
out("r8") _,
out("r9") _,
out("r10") _,
out("r11") _,
out("r12") r0,
out("r13") r1,
out("r14") r2,
out("r15") r3,
options(pure, readonly, nostack)
)
}

$field([r0, r1, r2, r3])
}

#[inline(always)]
pub(crate) fn montgomery_reduce_256(&self) -> $field {
let mut r0: u64;
Expand Down

0 comments on commit 9242ce3

Please sign in to comment.