pmax: Wasm SIMD Arithmetische Anweisung
Die pmax-Anweisung vergleicht zwei v128 Gleitkommawertinterpretationen und gibt eine neue Interpretation zurück, bei der jeder Ausgabelane auf den größeren der entsprechenden Eingabelanes gesetzt wird. Sie ist definiert als a < b ? b : a, was bedeutet, dass NaN im ersten Operand an die Ausgabe weitergegeben wird, jedoch nicht NaN im zweiten Operanden — im Gegensatz zu max, das NaN von einem der beiden Operanden weitergibt.
Probieren Sie es aus
(module
(import "console" "log" (func $log (param f32)))
(func $main
;; load two v128 f32x4s onto the stack
v128.const f32x4 52.6 101.2 78.0 9.9
v128.const f32x4 51.9 102.0 78.1 -0.9
;; return a f32x4 containing the largest values from each input lane
f32x4.pmax
f32x4.extract_lane 3 ;; Extract a single lane
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
Syntax
value_type.pmax
value_type-
Der Wertetyp, auf dem die Anweisung ausgeführt wird. Die folgenden Typen unterstützen
pmax:f32x4f64x2
pmax-
Die
pmax-Anweisung. Muss immer nach demvalue_typeund einem Punkt (.) eingefügt werden.
Typ
[input1, input2] -> [output]
Binärcodierung
| Anweisung | Binärformat | Beispieltext => binär |
|---|---|---|
f32x4.pmax |
0xfd 235:u32 |
f32x4.pmax => 0xfd 0xeb 0x01 |
f64x2.pmax |
0xfd 247:u32 |
f64x2.pmax => 0xfd 0xf7 0x01 |