design icon indicating copy to clipboard operation
design copied to clipboard

CTZ can be implemented in terms of CLZ

Open DemiMarie opened this issue 6 years ago • 4 comments

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.

DemiMarie avatar Dec 12 '18 20:12 DemiMarie

@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 avatar Dec 12 '18 21:12 jakelang

@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.

DemiMarie avatar Dec 12 '18 21:12 DemiMarie

For both ctz/clz we have decided to take a fairly naive implementation for calculating the cost to suit all VM implementations.

axic avatar Dec 12 '18 21:12 axic

@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.

jakelang avatar Dec 12 '18 21:12 jakelang