Skip to content

Commit ea8f414

Browse files
committed
implement wasm boolean ops
1 parent e748aef commit ea8f414

File tree

3 files changed

+75
-94
lines changed

3 files changed

+75
-94
lines changed

fearless_simd/src/generated/wasm.rs

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ impl Simd for WasmSimd128 {
160160
}
161161
#[inline(always)]
162162
fn not_i8x16(self, a: i8x16<Self>) -> i8x16<Self> {
163-
/// TODO: If v128 is used, we need to reinterpret it.
164-
todo!()
163+
v128_not(a.into()).simd_into(self)
165164
}
166165
#[inline(always)]
167166
fn add_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
@@ -180,18 +179,15 @@ impl Simd for WasmSimd128 {
180179
}
181180
#[inline(always)]
182181
fn and_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
183-
/// TODO: If v128 is used we need to reinterpret it accurately...
184-
todo!()
182+
v128_and(a.into(), b.into()).simd_into(self)
185183
}
186184
#[inline(always)]
187185
fn or_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
188-
/// TODO: If v128 is used we need to reinterpret it accurately...
189-
todo!()
186+
v128_or(a.into(), b.into()).simd_into(self)
190187
}
191188
#[inline(always)]
192189
fn xor_i8x16(self, a: i8x16<Self>, b: i8x16<Self>) -> i8x16<Self> {
193-
/// TODO: If v128 is used we need to reinterpret it accurately...
194-
todo!()
190+
v128_xor(a.into(), b.into()).simd_into(self)
195191
}
196192
#[inline(always)]
197193
fn shr_i8x16(self, a: i8x16<Self>, shift: u32) -> i8x16<Self> {
@@ -254,8 +250,7 @@ impl Simd for WasmSimd128 {
254250
}
255251
#[inline(always)]
256252
fn not_u8x16(self, a: u8x16<Self>) -> u8x16<Self> {
257-
/// TODO: If v128 is used, we need to reinterpret it.
258-
todo!()
253+
v128_not(a.into()).simd_into(self)
259254
}
260255
#[inline(always)]
261256
fn add_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
@@ -274,18 +269,15 @@ impl Simd for WasmSimd128 {
274269
}
275270
#[inline(always)]
276271
fn and_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
277-
/// TODO: If v128 is used we need to reinterpret it accurately...
278-
todo!()
272+
v128_and(a.into(), b.into()).simd_into(self)
279273
}
280274
#[inline(always)]
281275
fn or_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
282-
/// TODO: If v128 is used we need to reinterpret it accurately...
283-
todo!()
276+
v128_or(a.into(), b.into()).simd_into(self)
284277
}
285278
#[inline(always)]
286279
fn xor_u8x16(self, a: u8x16<Self>, b: u8x16<Self>) -> u8x16<Self> {
287-
/// TODO: If v128 is used we need to reinterpret it accurately...
288-
todo!()
280+
v128_xor(a.into(), b.into()).simd_into(self)
289281
}
290282
#[inline(always)]
291283
fn shr_u8x16(self, a: u8x16<Self>, shift: u32) -> u8x16<Self> {
@@ -348,23 +340,19 @@ impl Simd for WasmSimd128 {
348340
}
349341
#[inline(always)]
350342
fn not_mask8x16(self, a: mask8x16<Self>) -> mask8x16<Self> {
351-
/// TODO: If v128 is used, we need to reinterpret it.
352-
todo!()
343+
v128_not(a.into()).simd_into(self)
353344
}
354345
#[inline(always)]
355346
fn and_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
356-
/// TODO: If v128 is used we need to reinterpret it accurately...
357-
todo!()
347+
v128_and(a.into(), b.into()).simd_into(self)
358348
}
359349
#[inline(always)]
360350
fn or_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
361-
/// TODO: If v128 is used we need to reinterpret it accurately...
362-
todo!()
351+
v128_or(a.into(), b.into()).simd_into(self)
363352
}
364353
#[inline(always)]
365354
fn xor_mask8x16(self, a: mask8x16<Self>, b: mask8x16<Self>) -> mask8x16<Self> {
366-
/// TODO: If v128 is used we need to reinterpret it accurately...
367-
todo!()
355+
v128_xor(a.into(), b.into()).simd_into(self)
368356
}
369357
#[inline(always)]
370358
fn select_mask8x16(
@@ -392,8 +380,7 @@ impl Simd for WasmSimd128 {
392380
}
393381
#[inline(always)]
394382
fn not_i16x8(self, a: i16x8<Self>) -> i16x8<Self> {
395-
/// TODO: If v128 is used, we need to reinterpret it.
396-
todo!()
383+
v128_not(a.into()).simd_into(self)
397384
}
398385
#[inline(always)]
399386
fn add_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
@@ -409,18 +396,15 @@ impl Simd for WasmSimd128 {
409396
}
410397
#[inline(always)]
411398
fn and_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
412-
/// TODO: If v128 is used we need to reinterpret it accurately...
413-
todo!()
399+
v128_and(a.into(), b.into()).simd_into(self)
414400
}
415401
#[inline(always)]
416402
fn or_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
417-
/// TODO: If v128 is used we need to reinterpret it accurately...
418-
todo!()
403+
v128_or(a.into(), b.into()).simd_into(self)
419404
}
420405
#[inline(always)]
421406
fn xor_i16x8(self, a: i16x8<Self>, b: i16x8<Self>) -> i16x8<Self> {
422-
/// TODO: If v128 is used we need to reinterpret it accurately...
423-
todo!()
407+
v128_xor(a.into(), b.into()).simd_into(self)
424408
}
425409
#[inline(always)]
426410
fn shr_i16x8(self, a: i16x8<Self>, shift: u32) -> i16x8<Self> {
@@ -483,8 +467,7 @@ impl Simd for WasmSimd128 {
483467
}
484468
#[inline(always)]
485469
fn not_u16x8(self, a: u16x8<Self>) -> u16x8<Self> {
486-
/// TODO: If v128 is used, we need to reinterpret it.
487-
todo!()
470+
v128_not(a.into()).simd_into(self)
488471
}
489472
#[inline(always)]
490473
fn add_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
@@ -500,18 +483,15 @@ impl Simd for WasmSimd128 {
500483
}
501484
#[inline(always)]
502485
fn and_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
503-
/// TODO: If v128 is used we need to reinterpret it accurately...
504-
todo!()
486+
v128_and(a.into(), b.into()).simd_into(self)
505487
}
506488
#[inline(always)]
507489
fn or_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
508-
/// TODO: If v128 is used we need to reinterpret it accurately...
509-
todo!()
490+
v128_or(a.into(), b.into()).simd_into(self)
510491
}
511492
#[inline(always)]
512493
fn xor_u16x8(self, a: u16x8<Self>, b: u16x8<Self>) -> u16x8<Self> {
513-
/// TODO: If v128 is used we need to reinterpret it accurately...
514-
todo!()
494+
v128_xor(a.into(), b.into()).simd_into(self)
515495
}
516496
#[inline(always)]
517497
fn shr_u16x8(self, a: u16x8<Self>, shift: u32) -> u16x8<Self> {
@@ -574,23 +554,19 @@ impl Simd for WasmSimd128 {
574554
}
575555
#[inline(always)]
576556
fn not_mask16x8(self, a: mask16x8<Self>) -> mask16x8<Self> {
577-
/// TODO: If v128 is used, we need to reinterpret it.
578-
todo!()
557+
v128_not(a.into()).simd_into(self)
579558
}
580559
#[inline(always)]
581560
fn and_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
582-
/// TODO: If v128 is used we need to reinterpret it accurately...
583-
todo!()
561+
v128_and(a.into(), b.into()).simd_into(self)
584562
}
585563
#[inline(always)]
586564
fn or_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
587-
/// TODO: If v128 is used we need to reinterpret it accurately...
588-
todo!()
565+
v128_or(a.into(), b.into()).simd_into(self)
589566
}
590567
#[inline(always)]
591568
fn xor_mask16x8(self, a: mask16x8<Self>, b: mask16x8<Self>) -> mask16x8<Self> {
592-
/// TODO: If v128 is used we need to reinterpret it accurately...
593-
todo!()
569+
v128_xor(a.into(), b.into()).simd_into(self)
594570
}
595571
#[inline(always)]
596572
fn select_mask16x8(
@@ -618,8 +594,7 @@ impl Simd for WasmSimd128 {
618594
}
619595
#[inline(always)]
620596
fn not_i32x4(self, a: i32x4<Self>) -> i32x4<Self> {
621-
/// TODO: If v128 is used, we need to reinterpret it.
622-
todo!()
597+
v128_not(a.into()).simd_into(self)
623598
}
624599
#[inline(always)]
625600
fn add_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
@@ -635,18 +610,15 @@ impl Simd for WasmSimd128 {
635610
}
636611
#[inline(always)]
637612
fn and_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
638-
/// TODO: If v128 is used we need to reinterpret it accurately...
639-
todo!()
613+
v128_and(a.into(), b.into()).simd_into(self)
640614
}
641615
#[inline(always)]
642616
fn or_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
643-
/// TODO: If v128 is used we need to reinterpret it accurately...
644-
todo!()
617+
v128_or(a.into(), b.into()).simd_into(self)
645618
}
646619
#[inline(always)]
647620
fn xor_i32x4(self, a: i32x4<Self>, b: i32x4<Self>) -> i32x4<Self> {
648-
/// TODO: If v128 is used we need to reinterpret it accurately...
649-
todo!()
621+
v128_xor(a.into(), b.into()).simd_into(self)
650622
}
651623
#[inline(always)]
652624
fn shr_i32x4(self, a: i32x4<Self>, shift: u32) -> i32x4<Self> {
@@ -709,8 +681,7 @@ impl Simd for WasmSimd128 {
709681
}
710682
#[inline(always)]
711683
fn not_u32x4(self, a: u32x4<Self>) -> u32x4<Self> {
712-
/// TODO: If v128 is used, we need to reinterpret it.
713-
todo!()
684+
v128_not(a.into()).simd_into(self)
714685
}
715686
#[inline(always)]
716687
fn add_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
@@ -726,18 +697,15 @@ impl Simd for WasmSimd128 {
726697
}
727698
#[inline(always)]
728699
fn and_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
729-
/// TODO: If v128 is used we need to reinterpret it accurately...
730-
todo!()
700+
v128_and(a.into(), b.into()).simd_into(self)
731701
}
732702
#[inline(always)]
733703
fn or_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
734-
/// TODO: If v128 is used we need to reinterpret it accurately...
735-
todo!()
704+
v128_or(a.into(), b.into()).simd_into(self)
736705
}
737706
#[inline(always)]
738707
fn xor_u32x4(self, a: u32x4<Self>, b: u32x4<Self>) -> u32x4<Self> {
739-
/// TODO: If v128 is used we need to reinterpret it accurately...
740-
todo!()
708+
v128_xor(a.into(), b.into()).simd_into(self)
741709
}
742710
#[inline(always)]
743711
fn shr_u32x4(self, a: u32x4<Self>, shift: u32) -> u32x4<Self> {
@@ -800,23 +768,19 @@ impl Simd for WasmSimd128 {
800768
}
801769
#[inline(always)]
802770
fn not_mask32x4(self, a: mask32x4<Self>) -> mask32x4<Self> {
803-
/// TODO: If v128 is used, we need to reinterpret it.
804-
todo!()
771+
v128_not(a.into()).simd_into(self)
805772
}
806773
#[inline(always)]
807774
fn and_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
808-
/// TODO: If v128 is used we need to reinterpret it accurately...
809-
todo!()
775+
v128_and(a.into(), b.into()).simd_into(self)
810776
}
811777
#[inline(always)]
812778
fn or_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
813-
/// TODO: If v128 is used we need to reinterpret it accurately...
814-
todo!()
779+
v128_or(a.into(), b.into()).simd_into(self)
815780
}
816781
#[inline(always)]
817782
fn xor_mask32x4(self, a: mask32x4<Self>, b: mask32x4<Self>) -> mask32x4<Self> {
818-
/// TODO: If v128 is used we need to reinterpret it accurately...
819-
todo!()
783+
v128_xor(a.into(), b.into()).simd_into(self)
820784
}
821785
#[inline(always)]
822786
fn select_mask32x4(

fearless_simd_gen/src/mk_wasm.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ fn mk_simd_impl(level: Level) -> TokenStream {
5858
}
5959
}
6060
}
61-
OpSig::Unary if method == "not" => {
62-
let args = [quote! { a.into() }];
63-
let expr = Wasm.expr(method, vec_ty, &args);
64-
quote! {
65-
#[inline(always)]
66-
fn #method_ident(self, a: #ty<Self>) -> #ret_ty {
67-
/// TODO: If v128 is used, we need to reinterpret it.
68-
todo!()
69-
}
70-
}
71-
}
7261
OpSig::Unary => {
7362
let args = [quote! { a.into() }];
7463
let expr = if method == "fract" {
@@ -94,17 +83,6 @@ fn mk_simd_impl(level: Level) -> TokenStream {
9483
}
9584
}
9685
}
97-
OpSig::Binary if method == "xor" || method == "or" || method == "and" => {
98-
let args = [quote! { a.into() }, quote! { b.into() }];
99-
let expr = Wasm.expr(method, vec_ty, &args);
100-
quote! {
101-
#[inline(always)]
102-
fn #method_ident(self, a: #ty<Self>, b: #ty<Self>) -> #ret_ty {
103-
/// TODO: If v128 is used we need to reinterpret it accurately...
104-
todo!()
105-
}
106-
}
107-
}
10886
OpSig::Binary => {
10987
let args = [quote! { a.into() }, quote! { b.into() }];
11088
match method {

fearless_simd_tests/tests/wasm.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,42 @@ test_wasm_simd_parity! {
244244
}
245245
}
246246
}
247+
248+
test_wasm_simd_parity! {
249+
fn and_i8x16() {
250+
|s| -> [i8; 16] {
251+
let a = i8x16::from_slice(s, &[-1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0]);
252+
let b = i8x16::from_slice(s, &[85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85]);
253+
(a & b).into()
254+
}
255+
}
256+
}
257+
258+
test_wasm_simd_parity! {
259+
fn or_i8x16() {
260+
|s| -> [i8; 16] {
261+
let a = i8x16::from_slice(s, &[0, 1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, -7, -8]);
262+
let b = i8x16::from_slice(s, &[1, 1, 1, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0]);
263+
(a | b).into()
264+
}
265+
}
266+
}
267+
268+
test_wasm_simd_parity! {
269+
fn xor_i8x16() {
270+
|s| -> [i8; 16] {
271+
let a = i8x16::from_slice(s, &[0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, 0, 0, 0, 0]);
272+
let b = i8x16::from_slice(s, &[-1, -1, 0, 0, 5, 4, 7, 6, -1, 0, -1, 0, -1, 0, -1, 0]);
273+
(a ^ b).into()
274+
}
275+
}
276+
}
277+
278+
test_wasm_simd_parity! {
279+
fn not_i8x16() {
280+
|s| -> [i8; 16] {
281+
let a = i8x16::from_slice(s, &[0, 1, 2, 3, 4, 5, 6, 7, -1, -2, -3, -4, -5, -6, -7, -8]);
282+
i8x16::not(a).into()
283+
}
284+
}
285+
}

0 commit comments

Comments
 (0)