| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Numeric/ge | [Back] [Original] |
Get to know MDN better
The ge numeric instruction, short for greater or equal, checks if a floating point number is greater than or equal to another floating point number.
Integer types have separate greater than or equal to signed (ge_s) and unsigned (ge_u) instructions.
(module
(import "env" "log_bool" (func $log_bool (param i32)))
(func $main
;; load 10.0 and 3.5 onto the stack
f32.const 10.0
f32.const 3.5
f32.ge ;; check if 10.0 is greater than or equal to 3.5
call $log_bool ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
function log_bool(value) {
console.log(Boolean(value));
// Expected output: true
}
await WebAssembly.instantiateStreaming(fetch(url), {
env: { log_bool },
});
value_type.ge
value_typeThe type of value the instruction is being run on. The following types support ge:
f32f64v128 interpretations:
f32x4f64x2geThe ge instruction. Must always be included after the value_type and a period (.).
[input1, input2] -> [output]
input1The first input value.
input2The second input value.
outputThe output value, which will be an integer type.
For a non-SIMD ge, the inputs will be basic numeric values such as 3.0 or 3.5. If the first input is greater than or equal to the second input, 1 will be pushed on to the stack as an output, otherwise 0 will be pushed on to the stack.
For a SIMD ge, the inputs will be v128 value interpretations, for example f32x4 2.0 30 86.9 120. Each lane of the output pushed to the stack is a 1 or 0 indicating whether the corresponding lane of the first input value is greater than or equal to the corresponding lane of the second input value.
| Instruction | Binary format | Example text => binary |
|---|---|---|
f32.ge |
0x60 |
f32.ge => 0x60 |
f64.ge |
0x66 |
f64.ge => 0x66 |
f32x4.ge |
0xfd 70:u32 |
f32x4.ge => 0xfd 0x46 |
f64x2.ge |
0xfd 76:u32 |
f64x2.ge => 0xfd 0x4c |
ge exampleIn this example, we demonstrate using ge to test whether one SIMD lane value is greater than or equal to the same lane value in another SIMD value.
In our script, we grab a reference to a <p> element that we will output our result to, then define an object for import into Wasm containing a single function that writes a value to the output <p>. We then compile and instantiate our Wasm module using the WebAssembly.instantiateStreaming() method, importing the object in the process.
<p></p>
const outputElem = document.querySelector("p");
const obj = {
output(val) {
outputElem.textContent += val;
},
};
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), {
obj,
});
In our Wasm module, we first import the JavaScript output() function, making sure to declare that it has an i32 parameter. We then declare two SIMD f32x4 values, then check whether the first one's lane values are greater than or equal to the second using f32x4.ge. Finally we extract the value stored in lane 3 of the output value using the extract_lane instruction, and output it to the DOM by calling the imported output() function.
(module
;; Import output function
(import "obj" "output" (func $output (param i32)))
(func $main
;; load two SIMD values onto the stack
v128.const f32x4 20 12 15 102
v128.const f32x4 20 12 15 100
;; check whether the first value is greater than or equal to the second
f32x4.ge
i32x4.extract_lane 3 ;; Extract a value from the result
call $output
)
(start $main)
)
The output is as follows:
The result is 1 because the value stored in lane 3 of the first input value is greater than or equal to the value stored in lane 3 of the second input value.
| Specification |
|---|
| WebAssembly Core Specification # numeric-instructions%E2%91%A8 |
This page was last modified on Jul 24, 2026 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |