GCC builtins in LDC - compiler interoperability
cecil at cecilward.com
Wed Jul 15 23:31:39 UTC 2020
On Wednesday, 15 July 2020 at 08:20:48 UTC, kinke wrote:
> On Tuesday, 14 July 2020 at 23:37:13 UTC, Cecil Ward wrote:
>> I currently have a fair amount of code that will only run
>> under GDC because of reliance on GDC-specific library
>> routines. I’d like to ask whether I can find or implement
>> equivalents in LDC2 to the GDC routines
>> __builtin_unreachable() ?
> As Ilya already posted in another thread of yours,
> __builtin_expect is ldc.intrinsics.llvm_expect. Many other gcc
> builtins are available in ldc.gccbuiltins_<arch>. I don't think
> we expose `unreachable` though.
Oh, shame. There’s no __builtin_unreachable in ldc? I wonder if I
could work around this with LDC then.
I’m using unreachable to declare the truth of a condition in
release build so that the compiler can generate better code. The
trick I use with GCC is to mark the body of some if-statement as
unreachable. Then the compiler can remove a load of later if-test
conditions or remove if/else statements’ basic blocks.
More information about the digitalmars-d-ldc