Open DemiMarie opened 5 years ago
@DemiMarie I think this issue is out of scope. Ewasm does not intend to make any changes to the WebAssembly specification. Even then, it is up to the implementer of the Wasm virtual machine if they want to optimize CTZ by implementing it in terms of CLZ natively.
@jakelang I was thinking of the gas prices that Ewasm specifies for these operations, which should be representative of their computational consts on actual hardware.
For both ctz/clz we have decided to take a fairly naive implementation for calculating the cost to suit all VM implementations.
@DemiMarie I think this would then be more of a research topic, in that someone should look into whether the major WASM implementations have this optimization.
Edit: I am guessing most (compiled) implementations have it, as modern optimizing compilers may introduce such optimizations during compilation even if not specified in the source.
CTZ can be implemented in terms of CLZ and some form of bit swapping operation. I suspect that there is a faster way of doing this.