稍微改进一点点
This commit is contained in:
parent
4ebe5aada9
commit
636820071f
@ -1,3 +1,5 @@
|
||||
#![feature(portable_simd)]
|
||||
|
||||
mod name;
|
||||
|
||||
use base16384::Base16384Utf8;
|
||||
|
41
src/name.rs
41
src/name.rs
@ -1,3 +1,6 @@
|
||||
|
||||
use std::simd::{u32x16, u8x16, u8x64};
|
||||
|
||||
use tracing::warn;
|
||||
|
||||
#[inline(always)]
|
||||
@ -130,6 +133,7 @@ impl Namer {
|
||||
|
||||
let name_bytes = name.as_bytes();
|
||||
let name_len = name_bytes.len();
|
||||
// let b_name_len = name_len + 1;
|
||||
// 转到 256 长度 的 u8 数组
|
||||
let name_bytes = {
|
||||
let mut bytes = [0_u8; 256];
|
||||
@ -156,14 +160,29 @@ impl Namer {
|
||||
if (j == len) j = -1;
|
||||
}
|
||||
} */
|
||||
// for _ in 0..2 {
|
||||
// // 手动处理 0 的问题
|
||||
// // 手动swap
|
||||
// let mut s = val[0];
|
||||
// let mut j = 0;
|
||||
// val.swap(s as usize, 0);
|
||||
// for i in 1..256 {
|
||||
// j += 1;
|
||||
// if j == name_len {
|
||||
// j = 0;
|
||||
// }
|
||||
// s = s.wrapping_add(index_name(j, name_bytes));
|
||||
// s = s.wrapping_add(val[i]);
|
||||
// val.swap(i, s as usize);
|
||||
// }
|
||||
// }
|
||||
// let mut s = 0;
|
||||
let mut s = 0_u32;
|
||||
for _ in 0..2 {
|
||||
for j in 0..256 {
|
||||
s += name_bytes[j % (name_len + 1)] as u32 + val[j] as u32;
|
||||
s %= 256;
|
||||
let tmp = val[j];
|
||||
val[j] = val[s as usize];
|
||||
val[s as usize] = tmp;
|
||||
val.swap(j, s as usize);
|
||||
}
|
||||
s = 0;
|
||||
}
|
||||
@ -209,6 +228,22 @@ impl Namer {
|
||||
s += 1;
|
||||
}
|
||||
}
|
||||
// simd 优化
|
||||
// let x_a = u32x16::splat(181);
|
||||
// let x_b = u32x16::splat(160);
|
||||
// for i in (0..256).step_by(16) {
|
||||
// // 一次性加载4个数字
|
||||
// let mut x: u32x16 = u32x16::from_array(
|
||||
// val[i..i + 16]
|
||||
// .to_vec()
|
||||
// .iter()
|
||||
// .map(|x| *x as u32)
|
||||
// .collect::<Vec<u32>>()
|
||||
// .try_into()
|
||||
// .unwrap(),
|
||||
// );
|
||||
// x = x * x_a + x_b;
|
||||
// }
|
||||
// let mut q_len = 0;
|
||||
// for i in (0..256).step_by(8) {
|
||||
// val[i] = ((val[i] as u32 * 181 + 160) % 256) as u8;
|
||||
|
Loading…
Reference in New Issue
Block a user