File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,52 @@ benches! {
87
87
fn bench06_libcore( bytes: & mut [ u8 ] ) {
88
88
bytes. make_ascii_uppercase( )
89
89
}
90
+
91
+ fn bench07_fake_simd_u32( bytes: & mut [ u8 ] ) {
92
+ let ( before, aligned, after) = unsafe {
93
+ bytes. align_to_mut:: <u32 >( )
94
+ } ;
95
+ for byte in before {
96
+ * byte = branchless_to_ascii_upper_case( * byte)
97
+ }
98
+ for word in aligned {
99
+ // FIXME: this is incorrect for some byte values:
100
+ // addition within a byte can carry/overflow into the next byte.
101
+ // Test case: b"\xFFz "
102
+ * word &= !(
103
+ (
104
+ word. wrapping_add( 0x1f1f1f1f ) &
105
+ !word. wrapping_add( 0x05050505 ) &
106
+ 0x80808080
107
+ ) >> 2
108
+ )
109
+ }
110
+ for byte in after {
111
+ * byte = branchless_to_ascii_upper_case( * byte)
112
+ }
113
+ }
114
+
115
+ fn bench08_fake_simd_u64( bytes: & mut [ u8 ] ) {
116
+ let ( before, aligned, after) = unsafe {
117
+ bytes. align_to_mut:: <u64 >( )
118
+ } ;
119
+ for byte in before {
120
+ * byte = branchless_to_ascii_upper_case( * byte)
121
+ }
122
+ for word in aligned {
123
+ // FIXME: like above, this is incorrect for some byte values.
124
+ * word &= !(
125
+ (
126
+ word. wrapping_add( 0x1f1f1f1f_1f1f1f1f ) &
127
+ !word. wrapping_add( 0x05050505_05050505 ) &
128
+ 0x80808080_80808080
129
+ ) >> 2
130
+ )
131
+ }
132
+ for byte in after {
133
+ * byte = branchless_to_ascii_upper_case( * byte)
134
+ }
135
+ }
90
136
}
91
137
92
138
macro_rules! repeat {
You can’t perform that action at this time.
0 commit comments