Description
While investigating the assembly output of const_eq, I noticed that a counter-based implementation generates significantly better code on x86_64(for U256) compared to the current boolean accumulation approach.
Current Implementation
pub const fn const_eq(&self, other: &Self) -> bool {
let a = self.as_limbs();
let b = other.as_limbs();
let mut i = 0;
let mut r = true;
while i < LIMBS {
r &= a[i] == b[i];
i += 1;
}
r
}
Alternative Implementation
pub const fn const_eq(&self, other: &Self) -> bool {
let a = self.as_limbs();
let b = other.as_limbs();
let mut equal_count = 0usize;
let mut i = 0;
while i < LIMBS {
equal_count += (a[i] == b[i]) as usize;
i += 1;
}
equal_count == LIMBS
}
Performance Impact
@prestwich I'm not reallys sure 200 cycles will translate to any diff but since it's vectorization maybe