Skip to content

Commit cf98f11

Browse files
committed
fmt
1 parent e8aad7d commit cf98f11

File tree

21 files changed

+39
-161
lines changed

21 files changed

+39
-161
lines changed

crates/base64-simd/src/decode.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,7 @@ pub unsafe fn decode_raw_fallback(
129129
}
130130

131131
#[inline(always)]
132-
unsafe fn decode_extra(
133-
extra: usize,
134-
src: *const u8,
135-
dst: *mut u8,
136-
table: *const u8,
137-
) -> Result<(), Error> {
132+
unsafe fn decode_extra(extra: usize, src: *const u8, dst: *mut u8, table: *const u8) -> Result<(), Error> {
138133
match extra {
139134
0 => {}
140135
1 => core::hint::unreachable_unchecked(),

crates/base64-simd/src/encode.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ pub unsafe fn encode_raw_fallback(base64: &Base64, src: &[u8], dst: *mut u8) {
5656
}
5757

5858
#[inline(always)]
59-
unsafe fn encode_extra(
60-
extra: usize,
61-
src: *const u8,
62-
dst: *mut u8,
63-
charset: *const u8,
64-
padding: bool,
65-
) {
59+
unsafe fn encode_extra(extra: usize, src: *const u8, dst: *mut u8, charset: *const u8, padding: bool) {
6660
match extra {
6761
0 => {}
6862
1 => {

crates/base64-simd/src/lib.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ enum Base64Kind {
6767
UrlSafe,
6868
}
6969

70-
const STANDARD_CHARSET: &[u8; 64] =
71-
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
70+
const STANDARD_CHARSET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7271

73-
const URL_SAFE_CHARSET: &[u8; 64] =
74-
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
72+
const URL_SAFE_CHARSET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
7573

7674
/// Base64 variants
7775
///
@@ -186,11 +184,7 @@ impl Base64 {
186184
/// # Panics
187185
/// This function will panic if the length of `dst` is not enough.
188186
#[inline]
189-
pub fn decode<'s, 'd>(
190-
&'_ self,
191-
src: &'s [u8],
192-
mut dst: OutBuf<'d, u8>,
193-
) -> Result<&'d mut [u8], Error> {
187+
pub fn decode<'s, 'd>(&'_ self, src: &'s [u8], mut dst: OutBuf<'d, u8>) -> Result<&'d mut [u8], Error> {
194188
unsafe {
195189
let (n, m) = crate::decode::decoded_length(src, self.padding)?;
196190

crates/base64-simd/src/spec.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ mod wasm {
157157
unsafe impl SIMDExt for SIMD128 {}
158158
}
159159

160-
#[cfg(all(
161-
feature = "unstable",
162-
any(target_arch = "arm", target_arch = "aarch64")
163-
))]
160+
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
164161
mod arm {
165162
use super::SIMDExt;
166163

crates/hex-simd/src/decode.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ pub unsafe fn decode_raw_fallback(src: *const u8, len: usize, dst: *mut u8) -> R
2424
}
2525

2626
#[inline]
27-
pub unsafe fn decode_raw_simd<S: SIMD256>(
28-
s: S,
29-
mut src: *const u8,
30-
len: usize,
31-
mut dst: *mut u8,
32-
) -> Result<(), Error> {
27+
pub unsafe fn decode_raw_simd<S: SIMD256>(s: S, mut src: *const u8, len: usize, mut dst: *mut u8) -> Result<(), Error> {
3328
let end = src.add(len / 32 * 32);
3429
while src < end {
3530
let x = s.v256_load_unaligned(src);

crates/hex-simd/src/tests.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ fn safety_unit_test(
5555
for n in 0..256usize {
5656
dbgmsg!("generating ok case n = {}", n);
5757

58-
let iter = (0..16)
59-
.cycle()
60-
.take(n)
61-
.map(|x| char::from_digit(x, 16).unwrap() as u8);
58+
let iter = (0..16).cycle().take(n).map(|x| char::from_digit(x, 16).unwrap() as u8);
6259
ans.push(iter.collect())
6360
}
6461

@@ -143,10 +140,5 @@ fn safety_unit_test(
143140

144141
#[test]
145142
fn test_safety() {
146-
safety_unit_test(
147-
crate::check,
148-
crate::decode,
149-
crate::encode,
150-
crate::decode_inplace,
151-
);
143+
safety_unit_test(crate::check, crate::decode, crate::encode, crate::decode_inplace);
152144
}

crates/simd-abstraction/src/common/ascii.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ mod spec {
214214
}
215215
}
216216

217-
#[cfg(all(
218-
feature = "unstable",
219-
any(target_arch = "arm", target_arch = "aarch64")
220-
))]
217+
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
221218
mod arm {
222219
use super::*;
223220

crates/simd-abstraction/src/common/bswap.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ unsafe impl BSwapExt for u64 {
7070
}
7171
}
7272

73-
unsafe fn unroll_ptr<T>(
74-
mut src: *const T,
75-
len: usize,
76-
chunk_size: usize,
77-
mut f: impl FnMut(*const T),
78-
) {
73+
unsafe fn unroll_ptr<T>(mut src: *const T, len: usize, chunk_size: usize, mut f: impl FnMut(*const T)) {
7974
let chunks_end = src.add(len / chunk_size * chunk_size);
8075
let end = src.add(len);
8176

@@ -94,9 +89,7 @@ unsafe fn unroll_ptr<T>(
9489

9590
type SliceRawParts<T> = (*const T, usize);
9691

97-
fn raw_align32<T: Scalar>(
98-
slice: &[T],
99-
) -> (SliceRawParts<T>, SliceRawParts<Bytes32>, SliceRawParts<T>) {
92+
fn raw_align32<T: Scalar>(slice: &[T]) -> (SliceRawParts<T>, SliceRawParts<Bytes32>, SliceRawParts<T>) {
10093
let (p, m, s) = align32(slice);
10194
let p = (p.as_ptr(), p.len());
10295
let m = (m.as_ptr(), m.len());

crates/simd-abstraction/src/isa/mock256.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ fn vmap<S: SIMD256>(s: S, a: S::V256, f: impl Fn(S, S::V128) -> S::V128) -> S::V
88
}
99

1010
#[inline(always)]
11-
fn vmerge<S: SIMD256>(
12-
s: S,
13-
a: S::V256,
14-
b: S::V256,
15-
f: impl Fn(S, S::V128, S::V128) -> S::V128,
16-
) -> S::V256 {
11+
fn vmerge<S: SIMD256>(s: S, a: S::V256, b: S::V256, f: impl Fn(S, S::V128, S::V128) -> S::V128) -> S::V256 {
1712
let a = s.v256_to_v128x2(a);
1813
let b = s.v256_to_v128x2(b);
1914
let c = (f(s, a.0, b.0), f(s, a.1, b.1));

crates/simd-abstraction/src/isa/simd256.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,12 @@ pub unsafe trait SIMD256: SIMD128 {
4848

4949
#[inline(always)]
5050
fn v256_or(self, a: Self::V256, b: Self::V256) -> Self::V256 {
51-
split_merge(self, a, b, |a, b| {
52-
(self.v128_or(a.0, b.0), self.v128_or(a.1, b.1))
53-
})
51+
split_merge(self, a, b, |a, b| (self.v128_or(a.0, b.0), self.v128_or(a.1, b.1)))
5452
}
5553

5654
#[inline(always)]
5755
fn v256_and(self, a: Self::V256, b: Self::V256) -> Self::V256 {
58-
split_merge(self, a, b, |a, b| {
59-
(self.v128_and(a.0, b.0), self.v128_and(a.1, b.1))
60-
})
56+
split_merge(self, a, b, |a, b| (self.v128_and(a.0, b.0), self.v128_and(a.1, b.1)))
6157
}
6258

6359
#[inline(always)]
@@ -69,9 +65,7 @@ pub unsafe trait SIMD256: SIMD128 {
6965

7066
#[inline(always)]
7167
fn v256_xor(self, a: Self::V256, b: Self::V256) -> Self::V256 {
72-
split_merge(self, a, b, |a, b| {
73-
(self.v128_xor(a.0, b.0), self.v128_xor(a.1, b.1))
74-
})
68+
split_merge(self, a, b, |a, b| (self.v128_xor(a.0, b.0), self.v128_xor(a.1, b.1)))
7569
}
7670

7771
#[inline(always)]
@@ -120,16 +114,12 @@ pub unsafe trait SIMD256: SIMD128 {
120114

121115
#[inline(always)]
122116
fn i8x32_lt(self, a: Self::V256, b: Self::V256) -> Self::V256 {
123-
split_merge(self, a, b, |a, b| {
124-
(self.i8x16_lt(a.0, b.0), self.i8x16_lt(a.1, b.1))
125-
})
117+
split_merge(self, a, b, |a, b| (self.i8x16_lt(a.0, b.0), self.i8x16_lt(a.1, b.1)))
126118
}
127119

128120
#[inline(always)]
129121
fn i8x32_eq(self, a: Self::V256, b: Self::V256) -> Self::V256 {
130-
split_merge(self, a, b, |a, b| {
131-
(self.i8x16_eq(a.0, b.1), self.i8x16_eq(a.1, b.1))
132-
})
122+
split_merge(self, a, b, |a, b| (self.i8x16_eq(a.0, b.1), self.i8x16_eq(a.1, b.1)))
133123
}
134124

135125
#[inline(always)]
@@ -175,23 +165,17 @@ pub unsafe trait SIMD256: SIMD128 {
175165

176166
#[inline(always)]
177167
fn u32x8_max(self, a: Self::V256, b: Self::V256) -> Self::V256 {
178-
split_merge(self, a, b, |a, b| {
179-
(self.u32x4_max(a.0, b.0), self.u32x4_max(a.1, b.1))
180-
})
168+
split_merge(self, a, b, |a, b| (self.u32x4_max(a.0, b.0), self.u32x4_max(a.1, b.1)))
181169
}
182170

183171
#[inline(always)]
184172
fn u32x8_lt(self, a: Self::V256, b: Self::V256) -> Self::V256 {
185-
split_merge(self, a, b, |a, b| {
186-
(self.u32x4_lt(a.0, b.0), self.u32x4_lt(a.1, b.1))
187-
})
173+
split_merge(self, a, b, |a, b| (self.u32x4_lt(a.0, b.0), self.u32x4_lt(a.1, b.1)))
188174
}
189175

190176
#[inline(always)]
191177
fn i32x8_lt(self, a: Self::V256, b: Self::V256) -> Self::V256 {
192-
split_merge(self, a, b, |a, b| {
193-
(self.i32x4_lt(a.0, b.0), self.i32x4_lt(a.1, b.1))
194-
})
178+
split_merge(self, a, b, |a, b| (self.i32x4_lt(a.0, b.0), self.i32x4_lt(a.1, b.1)))
195179
}
196180

197181
// ----refactor----

crates/simd-abstraction/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ pub mod arch {
3535
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3636
pub mod x86;
3737

38-
#[cfg(all(
39-
feature = "unstable",
40-
any(target_arch = "arm", target_arch = "aarch64")
41-
))]
38+
#[cfg(all(feature = "unstable", any(target_arch = "arm", target_arch = "aarch64")))]
4239
pub mod arm;
4340

4441
#[cfg(target_arch = "wasm32")]

crates/simd-benches/benches/base64.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ pub fn bench_decode(c: &mut Criterion) {
6767
}),
6868
("radix64/auto", |b, src, dst| {
6969
b.iter(|| {
70-
radix64::STD
71-
.decode_slice(black_box(src), black_box(dst))
72-
.unwrap();
70+
radix64::STD.decode_slice(black_box(src), black_box(dst)).unwrap();
7371
})
7472
}),
7573
("base64/fallback", |b, src, dst| {

crates/simd-benches/benches/hex.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ pub fn bench_decode(c: &mut Criterion) {
8888
pub fn bench_encode(c: &mut Criterion) {
8989
let mut group = c.benchmark_group("hex-simd-encode");
9090

91-
let inputs: Vec<Vec<u8>> = [16, 32, 64, 256, 1024, 4096]
92-
.iter()
93-
.copied()
94-
.map(rand_bytes)
95-
.collect();
91+
let inputs: Vec<Vec<u8>> = [16, 32, 64, 256, 1024, 4096].iter().copied().map(rand_bytes).collect();
9692

9793
#[allow(clippy::type_complexity)]
9894
let functions: &[(&str, fn(&mut Bencher, &[u8], &mut [u8]))] = &[

crates/simd-benches/benches/uuid.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub fn bench_parse(c: &mut Criterion) {
2424

2525
for &(name, f) in functions {
2626
for (tag, input) in inputs {
27-
group.bench_with_input(BenchmarkId::new(name, tag), input, |b, s| {
28-
b.iter(|| f(black_box(s)))
29-
});
27+
group.bench_with_input(BenchmarkId::new(name, tag), input, |b, s| b.iter(|| f(black_box(s))));
3028
}
3129
}
3230
}

crates/unicode-simd/src/utf32.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ pub unsafe fn utf32_swap_endianness_raw_fallback(src: *const u32, len: usize, ds
4343
}
4444

4545
#[inline]
46-
pub unsafe fn utf32_swap_endianness_raw_simd<S: SIMD256>(
47-
s: S,
48-
src: *const u32,
49-
len: usize,
50-
dst: *mut u32,
51-
) {
46+
pub unsafe fn utf32_swap_endianness_raw_simd<S: SIMD256>(s: S, src: *const u32, len: usize, dst: *mut u32) {
5247
crate::sa_bswap::bswap_raw_simd(s, src, len, dst)
5348
}

crates/uuid-simd/src/format.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ pub unsafe fn format_simple_raw_fallback(src: *const u8, dst: *mut u8, case: Asc
3838
}
3939

4040
#[inline]
41-
pub unsafe fn format_simple_raw_simd<S: SIMD256>(
42-
s: S,
43-
src: *const u8,
44-
dst: *mut u8,
45-
case: AsciiCase,
46-
) {
41+
pub unsafe fn format_simple_raw_simd<S: SIMD256>(s: S, src: *const u8, dst: *mut u8, case: AsciiCase) {
4742
let lut = s.load(char_lut_simd(case));
4843
let a = s.v128_load_unaligned(src);
4944
let ans = sa_hex::encode_u8x16(s, a, lut);
@@ -72,12 +67,7 @@ pub unsafe fn format_hyphenated_raw_fallback(src: *const u8, dst: *mut u8, case:
7267
}
7368

7469
#[inline]
75-
pub unsafe fn format_hyphenated_raw_simd<S: SIMDExt>(
76-
s: S,
77-
src: *const u8,
78-
dst: *mut u8,
79-
case: AsciiCase,
80-
) {
70+
pub unsafe fn format_hyphenated_raw_simd<S: SIMDExt>(s: S, src: *const u8, dst: *mut u8, case: AsciiCase) {
8171
const SWIZZLE: &Bytes32 = &Bytes32([
8272
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //
8373
0x80, 0x08, 0x09, 0x0a, 0x0b, 0x80, 0x0c, 0x0d, //

crates/uuid-simd/src/lib.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ use simd_abstraction::tools::read;
5353
/// + The length of `src` doesn't match any UUID format variants.
5454
/// + The content of `src` is invalid.
5555
#[inline]
56-
pub fn parse<'s, 'd>(
57-
src: &'s [u8],
58-
mut dst: OutRef<'d, [u8; 16]>,
59-
) -> Result<&'d mut [u8; 16], Error> {
56+
pub fn parse<'s, 'd>(src: &'s [u8], mut dst: OutRef<'d, [u8; 16]>) -> Result<&'d mut [u8; 16], Error> {
6057
let n = src.len();
6158

6259
if n == 32 {
@@ -97,10 +94,7 @@ pub fn parse<'s, 'd>(
9794
/// + The length of `src` doesn't match the "simple" format.
9895
/// + The content of `src` is invalid.
9996
#[inline]
100-
pub fn parse_simple<'s, 'd>(
101-
src: &'s [u8],
102-
mut dst: OutRef<'d, [u8; 16]>,
103-
) -> Result<&'d mut [u8; 16], Error> {
97+
pub fn parse_simple<'s, 'd>(src: &'s [u8], mut dst: OutRef<'d, [u8; 16]>) -> Result<&'d mut [u8; 16], Error> {
10498
if src.len() != 32 {
10599
return Err(ERROR);
106100
}
@@ -120,10 +114,7 @@ pub fn parse_simple<'s, 'd>(
120114
/// + The length of `src` doesn't match the "hyphenated" format.
121115
/// + The content of `src` is invalid.
122116
#[inline]
123-
pub fn parse_hyphenated<'s, 'd>(
124-
src: &'s [u8],
125-
mut dst: OutRef<'d, [u8; 16]>,
126-
) -> Result<&'d mut [u8; 16], Error> {
117+
pub fn parse_hyphenated<'s, 'd>(src: &'s [u8], mut dst: OutRef<'d, [u8; 16]>) -> Result<&'d mut [u8; 16], Error> {
127118
if src.len() != 36 {
128119
return Err(ERROR);
129120
}
@@ -137,11 +128,7 @@ pub fn parse_hyphenated<'s, 'd>(
137128

138129
/// Formats `src` to a simple UUID string.
139130
#[inline]
140-
pub fn format_simple<'s, 'd>(
141-
src: &'s [u8; 16],
142-
mut dst: OutRef<'d, [u8; 32]>,
143-
case: AsciiCase,
144-
) -> &'d mut [u8; 32] {
131+
pub fn format_simple<'s, 'd>(src: &'s [u8; 16], mut dst: OutRef<'d, [u8; 32]>, case: AsciiCase) -> &'d mut [u8; 32] {
145132
unsafe {
146133
let src = src.as_ptr();
147134
let dst = dst.as_mut_ptr().cast::<u8>();

crates/uuid-simd/src/parse.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ pub unsafe fn parse_simple_raw_fallback(src: *const u8, dst: *mut u8) -> Result<
2727
}
2828

2929
#[inline]
30-
pub unsafe fn parse_simple_raw_simd<S: SIMD256>(
31-
s: S,
32-
src: *const u8,
33-
dst: *mut u8,
34-
) -> Result<(), Error> {
30+
pub unsafe fn parse_simple_raw_simd<S: SIMD256>(s: S, src: *const u8, dst: *mut u8) -> Result<(), Error> {
3531
let a = s.v256_load_unaligned(src);
3632
let ans = sa_hex::decode_u8x32(s, a).map_err(|()| ERROR)?;
3733
s.v128_store_unaligned(dst, ans);
@@ -63,11 +59,7 @@ pub unsafe fn parse_hyphenated_raw_fallback(src: *const u8, dst: *mut u8) -> Res
6359
}
6460

6561
#[inline]
66-
pub unsafe fn parse_hyphenated_raw_simd<S: SIMDExt>(
67-
s: S,
68-
src: *const u8,
69-
dst: *mut u8,
70-
) -> Result<(), Error> {
62+
pub unsafe fn parse_hyphenated_raw_simd<S: SIMDExt>(s: S, src: *const u8, dst: *mut u8) -> Result<(), Error> {
7163
match [read(src, 8), read(src, 13), read(src, 18), read(src, 23)] {
7264
[b'-', b'-', b'-', b'-'] => {}
7365
_ => return Err(ERROR),

0 commit comments

Comments
 (0)