On 4/3/20 3:13 PM, Johan wrote:
On Thursday, 2 April 2020 at 12:41:28 UTC, Steven Schveighoffer wrote:


Hm... I thought there was precedent for providing fallback implementations for intrinsics. That is, you define the function, which is only used if the intrinsic is not available.

I can't remember where I saw this. But you could try this by simply implementing the bitops in core.bitop, and see if they are used outside ctfe.

There are a bunch of functions implemented with `if (!__ctfe)`. DMD and LDC are smart enough to elide `if(false/true)` control flow completely even in debug code, so there is no penalty to using `if (!__ctfe)`. See for example: https://github.com/ldc-developers/druntime/blob/ldc/src/core/bitop.d#L85

Nice!

I'm trying to understand that. It looks like you are calling the intrinsic that llvm recognizes. What can you do when bsf *is* the intrinsic? Does DMD have to change its intrinsic to something that's not core.bitop.bsf so we can call it? Or would that code as written work if ported to druntime mainline? I.e. the compiler replaces the bsf with the intrinsic and ignores the implementation in runtime code, but works at comiple time.

-Steve

Reply via email to