From 9f4dc3464e7e95b3e56f3bb2b6f65a416ce50d50 Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Thu, 3 Nov 2022 20:04:57 -0700 Subject: [PATCH] fix: add architecture gating for inline-assembly Signed-off-by: Brandon H. Gomes --- field/src/goldilocks_field.rs | 3 +-- util/Cargo.toml | 2 -- util/src/lib.rs | 24 ++++++++++++------------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/field/src/goldilocks_field.rs b/field/src/goldilocks_field.rs index 12c8da3a..9f0b0519 100644 --- a/field/src/goldilocks_field.rs +++ b/field/src/goldilocks_field.rs @@ -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 diff --git a/util/Cargo.toml b/util/Cargo.toml index a1ab402a..0e3a68f0 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -3,5 +3,3 @@ name = "plonky2_util" description = "Utilities used by Plonky2" version = "0.1.0" edition = "2021" - -[dependencies] diff --git a/util/src/lib.rs b/util/src/lib.rs index c840bc69..ab1e8d8d 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -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(result: Result) -> 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)); } }