What does the following code taken from the Emscripten project mean?

63 views Asked by At

I was reading the following code from the Emscripten project:

// The following operations have very fast WebAssembly opcodes. Therefore they are not
// exposed as individual functions:

// Math.abs(x) -> f32.abs and f64.abs. (use fabsf() and fabs() from math.h)
// Math.ceil -> f32.ceil and f64.ceil (ceil() and ceilf() in math.h)
// Math.clz32(x) -> i32.clz and i64.clz (call __builtin_clz() and __builtin_clzll())
// Math.floor -> f32.floor and f64.floor (floor() and floorf() in math.h)
// Math.fround -> f64.promote_f32(f32.demote_f64()) (call double d = (double)(float)someDouble;)
// Math.imul(x, y) -> i32.mul and i64.mul (directly multiply two signed integers)
// Math.min -> f32.min and f64.min (fminf() and fmin() in math.h)
// Math.max -> f32.max and f64.max (fmaxf() and fmax() in math.h)
// Math.trunc -> f32.trunc and f64.trunc (truncf() and trunc() in math.h)

Can anyone please explain what exactly is meant by the statement "very fast WebAssembly opcodes".

I have a slight understanding of WebAssembly also about opcodes. However, I can't understand how come, for example, Math.floor() produces a fast opcode when it internally relies on the floor() function in C, from the math.h library.

The confusion starts off when I read the code that follows in the given link. Math.round() from JavaScript isn't considered to produce a "fast WebAssembly opcode", yet it also uses a C function, in particular round() again from math.h.

How is round() in C any different from floor() in C, and how that does difference equate to one call being able to produce a quicker opcode.

0

There are 0 answers