Skip to content

Commit 5f8fc9e

Browse files
committed
bb: Implement WordOps::from_u8.
1 parent eb70956 commit 5f8fc9e

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/bb/bytes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ pub fn bytes_are_equal(a: &[u8], b: &[u8]) -> BoolMask {
4646
#[allow(clippy::into_iter_on_ref)]
4747
let rem = a_rem
4848
.into_iter()
49-
.copied()
50-
.map(Word::from)
49+
.map(Word::from_u8)
5150
.zip(b_rem.into_iter().copied().map(Word::from))
5251
.fold(0, |acc, (a, b)| acc | (a ^ b));
5352
acc |= rem;

src/bb/word/aarch64.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
use super::{super::BoolMask, Word, WordOps};
2+
use crate::polyfill;
23
use core::{arch::asm, mem};
34

45
impl WordOps for Word {
6+
fn from_u8(a: &u8) -> Self {
7+
let mut r: Self;
8+
unsafe {
9+
asm!(
10+
"ldrb {r:w}, [{a_ptr}]", // zero-extended to 32-bits, then 64-bits.
11+
a_ptr = in(reg) polyfill::ptr::from_ref(a),
12+
r = lateout(reg) r,
13+
options(nostack, readonly)
14+
);
15+
}
16+
r
17+
}
18+
519
fn is_zero(self) -> BoolMask {
620
let r: u64;
721
unsafe {

src/bb/word/fallback.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use super::{super::BoolMask, Word, WordOps};
22

33
impl WordOps for Word {
4+
#[inline(always)]
5+
fn from_u8(a: &u8) -> Self {
6+
Self::from(*a)
7+
}
8+
49
#[inline]
510
fn is_zero(self) -> BoolMask {
611
use crate::limb::{Limb, LimbMask}; // XXX: Backwards dependency.

src/bb/word/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use cfg_if::cfg_if;
2929
pub(crate) type Word = LeakyWord;
3030

3131
pub(crate) trait WordOps: Copy {
32+
fn from_u8(a: &u8) -> Self;
3233
fn is_zero(self) -> BoolMask;
3334
}
3435

0 commit comments

Comments
 (0)