Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/cmov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ jobs:
strategy:
matrix:
include:
# 32-bit Linux
# `x86` Linux
- target: i686-unknown-linux-gnu
platform: ubuntu-latest
rust: 1.85.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
# `x86_64` Linux
- target: x86_64-unknown-linux-gnu
platform: ubuntu-latest
rust: 1.85.0 # MSRV

# 64-bit Windows
# `x86_64` Windows
- target: x86_64-pc-windows-msvc
platform: windows-latest
rust: 1.85.0 # MSRV

# 64-bit macOS
# `x86_64` macOS
- target: x86_64-apple-darwin
platform: macos-latest
rust: 1.85.0 # MSRV
Expand Down Expand Up @@ -138,7 +138,9 @@ jobs:
strategy:
matrix:
target:
- armv7-unknown-linux-gnueabi
- powerpc-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
- s390x-unknown-linux-gnu
- x86_64-unknown-linux-gnu
steps:
Expand Down
22 changes: 14 additions & 8 deletions cmov/src/backends/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ fn maskne64(x: u64, y: u64) -> u64 {
}

/// Return a `u32::MAX` mask if `condition` is non-zero, otherwise return zero for a zero input.
#[cfg(not(any(target_arch = "arm", target_arch = "riscv32", target_arch = "riscv64")))]
#[cfg(any(
miri,
not(any(target_arch = "arm", target_arch = "riscv32", target_arch = "riscv64"))
))]
fn masknz32(condition: u32) -> u32 {
masknz!(condition: u32)
}

/// Return a `u64::MAX` mask if `condition` is non-zero, otherwise return zero for a zero input.
#[cfg(not(any(target_arch = "arm", target_arch = "riscv32", target_arch = "riscv64")))]
#[cfg(any(
miri,
not(any(target_arch = "arm", target_arch = "riscv32", target_arch = "riscv64"))
))]
fn masknz64(condition: u64) -> u64 {
masknz!(condition: u64)
}
Expand All @@ -138,7 +144,7 @@ fn masknz64(condition: u64) -> u64 {
/// This is written in assembly both for performance and because we've had problematic code
/// generation in this routine in the past which lead to the insertion of a branch, which using
/// assembly should guarantee won't happen again in the future (CVE-2026-23519).
#[cfg(target_arch = "arm")]
#[cfg(all(target_arch = "arm", not(miri)))]
fn masknz32(condition: u32) -> u32 {
let mut mask: u32;
unsafe {
Expand All @@ -154,7 +160,7 @@ fn masknz32(condition: u32) -> u32 {
}

/// Optimized mask generation for riscv32 targets.
#[cfg(target_arch = "riscv32")]
#[cfg(all(target_arch = "riscv32", not(miri)))]
fn masknz32(condition: u32) -> u32 {
let mut mask: u32;
unsafe {
Expand All @@ -170,13 +176,13 @@ fn masknz32(condition: u32) -> u32 {
}

/// Optimized mask generation for riscv32 targets.
#[cfg(target_arch = "riscv64")]
#[cfg(all(target_arch = "riscv64", not(miri)))]
fn masknz32(condition: u32) -> u32 {
(masknz64(condition.into()) & 0xFFFF_FFFF) as u32
}

/// Optimized mask generation for riscv32 targets.
#[cfg(target_arch = "riscv64")]
/// Optimized mask generation for riscv64 targets.
#[cfg(all(target_arch = "riscv64", not(miri)))]
fn masknz64(condition: u64) -> u64 {
let mut mask: u64;
unsafe {
Expand All @@ -192,7 +198,7 @@ fn masknz64(condition: u64) -> u64 {
}

/// 64-bit wrapper for targets that implement 32-bit mask generation in assembly.
#[cfg(any(target_arch = "arm", target_arch = "riscv32"))]
#[cfg(all(any(target_arch = "arm", target_arch = "riscv32"), not(miri)))]
fn masknz64(condition: u64) -> u64 {
let lo = masknz32((condition & 0xFFFF_FFFF) as u32);
let hi = masknz32((condition >> 32) as u32);
Expand Down