builtins are publicly imported, respectively).Host-specific intrinsics cannot be reliably listed here, however listings can be foundat the documentation for the relevant backends, i.e.GCC andLLVM. It should be noted that not allbuiltins listed are necessarily supported by the host compiler, please file a bugif this is the case for your workload.Use of this module reduces the amount of conditional compilation neededto use a given builtin. For example, to write a target independent functionthat uses prefetching we can write the following:float usePrefetch(float[] x){// There is only one import statement required rather than two (versioned) importsimport core.builtins;version (GNU) __builtin_prefetch(x.ptr);version (LDC)/+ For the curious: 0, 3, 1 mean `x` will only be read-from (0), it will be used very often (3), and it should be fetched to the data-cache (1). +/ llvm_prefetch(x.ptr, 0, 3, 1);const doMath = blahBlahBlah;return doMath;}
Sourcecore/builtins.d
__ctfeWrite(scope const(char)[]s);s tostderr during CTFE (does nothing at runtime).trap();likely()(boolb);unlikely()(boolb);int x = 12;expect(x, 12);if (likely(x > 0)){// ...}elseif (unlikely(x ==int.min)){// ...}