mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-02 13:53:07 +00:00
fix: add architecture gating for inline-assembly
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
This commit is contained in:
parent
fc3f63398d
commit
9f4dc3464e
@ -305,10 +305,9 @@ impl DivAssign for GoldilocksField {
|
||||
#[inline(always)]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 {
|
||||
use core::arch::asm;
|
||||
let res_wrapped: u64;
|
||||
let adjustment: u64;
|
||||
asm!(
|
||||
core::arch::asm!(
|
||||
"add {0}, {1}",
|
||||
// Trick. The carry flag is set iff the addition overflowed.
|
||||
// sbb x, y does x := x - y - CF. In our case, x and y are both {1:e}, so it simply does
|
||||
|
||||
@ -3,5 +3,3 @@ name = "plonky2_util"
|
||||
description = "Utilities used by Plonky2"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -9,8 +9,6 @@
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use core::arch::asm;
|
||||
use core::convert::Infallible;
|
||||
use core::hint::unreachable_unchecked;
|
||||
use core::mem::size_of;
|
||||
use core::ptr::{swap, swap_nonoverlapping};
|
||||
@ -19,15 +17,6 @@ use crate::transpose_util::transpose_in_place_square;
|
||||
|
||||
mod transpose_util;
|
||||
|
||||
/// Converts `result` into the [`Ok`] variant of [`Result`].
|
||||
#[inline]
|
||||
pub fn into_ok<T>(result: Result<T, Infallible>) -> T {
|
||||
match result {
|
||||
Ok(value) => value,
|
||||
_ => unreachable!("The `Infallible` value cannot be constructed."),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bits_u64(n: u64) -> usize {
|
||||
(64 - n.leading_zeros()) as usize
|
||||
}
|
||||
@ -281,8 +270,19 @@ pub fn assume(p: bool) {
|
||||
/// This function has no semantics. It is a hint only.
|
||||
#[inline(always)]
|
||||
pub fn branch_hint() {
|
||||
// NOTE: These are the currently supported assembly architectures. See the
|
||||
// [nightly reference](https://doc.rust-lang.org/nightly/reference/inline-assembly.html) for
|
||||
// the most up-to-date list.
|
||||
#[cfg(any(
|
||||
target_arch = "aarch64",
|
||||
target_arch = "arm",
|
||||
target_arch = "riscv32",
|
||||
target_arch = "riscv64",
|
||||
target_arch = "x86",
|
||||
target_arch = "x86_64",
|
||||
))]
|
||||
unsafe {
|
||||
asm!("", options(nomem, nostack, preserves_flags));
|
||||
core::arch::asm!("", options(nomem, nostack, preserves_flags));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user