bitselect: Wasm SIMD bitweise Anweisung
Die bitselect SIMD bitweise Anweisung nimmt drei v128-Werte als Eingaben — zwei Eingabewerte und einen Maskenwert — und gibt einen neuen v128-Wert zurück, wobei jedes Byte mit der Formel output = (input1 AND mask) OR (input2 AND NOT mask) berechnet wird.
Probieren Sie es aus
(module
(import "console" "log" (func $log (param i32)))
(func $main
v128.const i8x16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
v128.const i8x16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
v128.const i8x16 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
v128.bitselect
i8x16.extract_lane_u 15
call $log ;; log the result
)
(start $main)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { console });
Im obigen Beispiel haben wir alle Eingabewert-Spuren zur Vereinfachung auf denselben Wert gesetzt. Der Ablauf zur Berechnung des Ausgabewerts (9) anhand der Formel output = (input1 AND mask) OR (input2 AND NOT mask) sieht folgendermaßen aus:
-
Die erste Eingabe ist
1, was in binärer Form0 0 0 0 0 0 0 1ist. -
Die zweite Eingabe ist
15, was in binärer Form0 0 0 0 1 1 1 1ist. -
Die Maske ist
6, was in binärer Form0 0 0 0 0 1 1 0ist. -
input1 AND maskwird wie folgt berechnet:input1 0 0 0 0 0 0 0 1 mask 0 0 0 0 0 1 1 0 input1 AND mask 0 0 0 0 0 0 0 0
-
input2 AND NOT maskwird wie folgt berechnet:input2 0 0 0 0 1 1 1 1 NOT mask 1 1 1 1 1 0 0 1 input2 AND NOT mask 0 0 0 0 1 0 0 1
-
Dann verwenden wir OR auf die beiden Ergebnisse aus den Schritten 4. und 5.:
result1 0 0 0 0 0 0 0 0 result2 0 0 0 0 1 0 0 1 OR 0 0 0 0 1 0 0 1
0 0 0 0 1 0 0 1 ist das binäre Äquivalent von 9.
Syntax
v128.bitselect
v128.bitselect-
Die
v128.bitselect-Anweisung.
Typ
[input1, input2, mask] -> [output]
Binäre Codierung
| Anweisung | Binärformat | Beispieltext => binär |
|---|---|---|
v128.bitselect |
0xfd 82:u32 |
v128.bitselect => 0xfd 0x52 |
Spezifikationen
| Spezifikation |
|---|
| WebAssembly Core Specification> # vector-instructions%E2%91%A8> |