ewasm / design

Ewasm Design Overview and Specification
Apache License 2.0
1.02k stars 125 forks source link

CTZ can be implemented in terms of CLZ #168

Open DemiMarie opened 5 years ago

DemiMarie commented 5 years ago

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.

jakelang commented 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.

DemiMarie commented 5 years ago

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

axic commented 5 years ago

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

jakelang commented 5 years ago

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