I know the specification already rejects div/rem operations which is perfectly makes sense.
However, I'd like to discuss the possibility of adding not the high-level division operations themselves, but rather some of the underlying building blocks, specifically reciprocal_2by1 and possibly reciprocal_3by2.
The idea is similar to SSE's RCPSS/RCPPS, but targeted at wide integer arithmetic. Division by inversion is already used in a number of libraries that provide efficient division algorithms, and it was described in the following paper:
https://gmplib.org/~tege/division-paper.pdf
And how reciprocal_2by1 and reciprocal_3by2 looks like on practive.
btw not sure about Clang but GCC do this for loop inv divisors during compile time
reciprocal_2by1 is more important because it requires a lookup table, which costs size and performance on wasm side.
Furthermore, the reciprocal precomputation has optimization opportunities of its own. If the divisor is loop-invariant, the reciprocal step can be hoisted by LICM. Likewise, if multiple expressions use the same divisor, apply CSE. In that sense, representing the reciprocal explicitly as an IR-level or specific wasm op seems genuinely useful
WDYT?
I know the specification already rejects
div/remoperations which is perfectly makes sense.However, I'd like to discuss the possibility of adding not the high-level division operations themselves, but rather some of the underlying building blocks, specifically
reciprocal_2by1and possiblyreciprocal_3by2.The idea is similar to SSE's
RCPSS/RCPPS, but targeted at wide integer arithmetic. Division by inversion is already used in a number of libraries that provide efficient division algorithms, and it was described in the following paper:https://gmplib.org/~tege/division-paper.pdf
And how
reciprocal_2by1andreciprocal_3by2looks like on practive.btw not sure about Clang but GCC do this for loop inv divisors during compile time
reciprocal_2by1is more important because it requires a lookup table, which costs size and performance on wasm side.Furthermore, the reciprocal precomputation has optimization opportunities of its own. If the divisor is loop-invariant, the reciprocal step can be hoisted by LICM. Likewise, if multiple expressions use the same divisor, apply CSE. In that sense, representing the reciprocal explicitly as an IR-level or specific wasm op seems genuinely useful
WDYT?