From ca5925745acb7a7c38144d4c8239cfb3ba0846ce Mon Sep 17 00:00:00 2001 From: Arayi Date: Wed, 11 Dec 2024 11:35:23 -0500 Subject: [PATCH] chore: make extern function names more unique --- src/add.rs | 8 ++++---- src/bits.rs | 40 +++++++++++++++++++++++++++++----------- src/cmp.rs | 4 ++-- src/mul.rs | 4 ++-- src/support/zkvm.rs | 28 ++++++++++++++-------------- 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/add.rs b/src/add.rs index cfb312d..d4f352b 100644 --- a/src/add.rs +++ b/src/add.rs @@ -155,10 +155,10 @@ impl Uint { #[inline(always)] #[must_use] pub fn wrapping_add(mut self, rhs: Self) -> Self { - use crate::support::zkvm::wrapping_add_impl; + use crate::support::zkvm::zkvm_u256_wrapping_add_impl; if BITS == 256 { unsafe { - wrapping_add_impl( + zkvm_u256_wrapping_add_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, rhs.limbs.as_ptr() as *const u8, @@ -198,10 +198,10 @@ impl Uint { #[inline(always)] #[must_use] pub fn wrapping_sub(mut self, rhs: Self) -> Self { - use crate::support::zkvm::wrapping_sub_impl; + use crate::support::zkvm::zkvm_u256_wrapping_sub_impl; if BITS == 256 { unsafe { - wrapping_sub_impl( + zkvm_u256_wrapping_sub_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, rhs.limbs.as_ptr() as *const u8, diff --git a/src/bits.rs b/src/bits.rs index fc0c76a..001eece 100644 --- a/src/bits.rs +++ b/src/bits.rs @@ -299,10 +299,10 @@ impl Uint { if rhs >= 256 { return Self::ZERO; } - use crate::support::zkvm::wrapping_shl_impl; + use crate::support::zkvm::zkvm_u256_wrapping_shl_impl; let rhs = rhs as u64; unsafe { - wrapping_shl_impl( + zkvm_u256_wrapping_shl_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, [rhs].as_ptr() as *const u8, @@ -398,10 +398,10 @@ impl Uint { if rhs >= 256 { return Self::ZERO; } - use crate::support::zkvm::wrapping_shr_impl; + use crate::support::zkvm::zkvm_u256_wrapping_shr_impl; let rhs = rhs as u64; unsafe { - wrapping_shr_impl( + zkvm_u256_wrapping_shr_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, [rhs].as_ptr() as *const u8, @@ -436,10 +436,10 @@ impl Uint { pub fn arithmetic_shr(mut self, rhs: usize) -> Self { if BITS == 256 { let rhs = if rhs >= 256 { 255 } else { rhs }; - use crate::support::zkvm::arithmetic_shr_impl; + use crate::support::zkvm::zkvm_u256_arithmetic_shr_impl; let rhs = rhs as u64; unsafe { - arithmetic_shr_impl( + zkvm_u256_arithmetic_shr_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, [rhs].as_ptr() as *const u8, @@ -504,10 +504,10 @@ impl Not for Uint { #[cfg(target_os = "zkvm")] #[inline(always)] fn not(mut self) -> Self::Output { - use crate::support::zkvm::wrapping_sub_impl; + use crate::support::zkvm::zkvm_u256_wrapping_sub_impl; if BITS == 256 { unsafe { - wrapping_sub_impl( + zkvm_u256_wrapping_sub_impl( self.limbs.as_mut_ptr() as *mut u8, Self::MAX.limbs.as_ptr() as *const u8, self.limbs.as_ptr() as *const u8, @@ -621,9 +621,27 @@ macro_rules! impl_bit_op { }; } -impl_bit_op!(BitOr, bitor, BitOrAssign, bitor_assign, bitor_impl); -impl_bit_op!(BitAnd, bitand, BitAndAssign, bitand_assign, bitand_impl); -impl_bit_op!(BitXor, bitxor, BitXorAssign, bitxor_assign, bitxor_impl); +impl_bit_op!( + BitOr, + bitor, + BitOrAssign, + bitor_assign, + zkvm_u256_bitor_impl +); +impl_bit_op!( + BitAnd, + bitand, + BitAndAssign, + bitand_assign, + zkvm_u256_bitand_impl +); +impl_bit_op!( + BitXor, + bitxor, + BitXorAssign, + bitxor_assign, + zkvm_u256_bitxor_impl +); impl Shl for Uint { type Output = Self; diff --git a/src/cmp.rs b/src/cmp.rs index 6b4e710..c1b6940 100644 --- a/src/cmp.rs +++ b/src/cmp.rs @@ -18,10 +18,10 @@ impl Ord for Uint { #[cfg(target_os = "zkvm")] #[inline] fn cmp(&self, rhs: &Self) -> Ordering { - use crate::support::zkvm::cmp_impl; + use crate::support::zkvm::zkvm_u256_cmp_impl; if BITS == 256 { return unsafe { - cmp_impl( + zkvm_u256_cmp_impl( self.limbs.as_ptr() as *const u8, rhs.limbs.as_ptr() as *const u8, ) diff --git a/src/mul.rs b/src/mul.rs index 0f31ecc..de0f4a2 100644 --- a/src/mul.rs +++ b/src/mul.rs @@ -75,10 +75,10 @@ impl Uint { #[inline(always)] #[must_use] pub fn wrapping_mul(mut self, rhs: Self) -> Self { - use crate::support::zkvm::wrapping_mul_impl; + use crate::support::zkvm::zkvm_u256_wrapping_mul_impl; if BITS == 256 { unsafe { - wrapping_mul_impl( + zkvm_u256_wrapping_mul_impl( self.limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, rhs.limbs.as_ptr() as *const u8, diff --git a/src/support/zkvm.rs b/src/support/zkvm.rs index 518aae1..27833f7 100644 --- a/src/support/zkvm.rs +++ b/src/support/zkvm.rs @@ -14,29 +14,29 @@ use crate::Uint; extern "C" { /// Add two 256-bit numbers and store in `result`. - pub fn wrapping_add_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_wrapping_add_impl(result: *mut u8, a: *const u8, b: *const u8); /// Subtract two 256-bit numbers and store in `result`. - pub fn wrapping_sub_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_wrapping_sub_impl(result: *mut u8, a: *const u8, b: *const u8); /// Multiply two 256-bit numbers and store in `result`. - pub fn wrapping_mul_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_wrapping_mul_impl(result: *mut u8, a: *const u8, b: *const u8); /// Bitwise XOR two 256-bit numbers and store in `result`. - pub fn bitxor_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_bitxor_impl(result: *mut u8, a: *const u8, b: *const u8); /// Bitwise AND two 256-bit numbers and store in `result`. - pub fn bitand_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_bitand_impl(result: *mut u8, a: *const u8, b: *const u8); /// Bitwise OR two 256-bit numbers and store in `result`. - pub fn bitor_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_bitor_impl(result: *mut u8, a: *const u8, b: *const u8); /// Shift left two 256-bit numbers and store in `result`. - pub fn wrapping_shl_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_wrapping_shl_impl(result: *mut u8, a: *const u8, b: *const u8); /// Shift right two 256-bit numbers and store in `result`. - pub fn wrapping_shr_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_wrapping_shr_impl(result: *mut u8, a: *const u8, b: *const u8); /// Arithmetic shift right two 256-bit numbers and store in `result`. - pub fn arithmetic_shr_impl(result: *mut u8, a: *const u8, b: *const u8); + pub fn zkvm_u256_arithmetic_shr_impl(result: *mut u8, a: *const u8, b: *const u8); /// Check if two 256-bit numbers are equal. - pub fn eq_impl(a: *const u8, b: *const u8) -> bool; + pub fn zkvm_u256_eq_impl(a: *const u8, b: *const u8) -> bool; /// Compare two 256-bit numbers. - pub fn cmp_impl(a: *const u8, b: *const u8) -> Ordering; + pub fn zkvm_u256_cmp_impl(a: *const u8, b: *const u8) -> Ordering; /// Clone a 256-bit number into `result`. `zero` has to - pub fn clone_impl(result: *mut u8, a: *const u8, zero: *const u8); + pub fn zkvm_u256_clone_impl(result: *mut u8, a: *const u8, zero: *const u8); } impl Copy for Uint {} @@ -46,7 +46,7 @@ impl Clone for Uint { if BITS == 256 { let mut uninit: MaybeUninit = MaybeUninit::uninit(); unsafe { - clone_impl( + zkvm_u256_clone_impl( (*uninit.as_mut_ptr()).limbs.as_mut_ptr() as *mut u8, self.limbs.as_ptr() as *const u8, Self::ZERO.limbs.as_ptr() as *const u8, @@ -62,7 +62,7 @@ impl PartialEq for Uint { fn eq(&self, other: &Self) -> bool { if BITS == 256 { unsafe { - eq_impl( + zkvm_u256_eq_impl( self.limbs.as_ptr() as *const u8, other.limbs.as_ptr() as *const u8, )