xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/builtins.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**********************************************
2 To provide access to features that would be otherwise counterproductive or
3 difficult to implement, compilers provide an interface consisting of a set
4 of builtins (also called intrinsics) which can be called like normal functions.
5 
6 This module exposes builtins both common to all D compilers
7 (those provided by the frontend) and specific to the host compiler i.e. those
8 specific to either LLVM or GCC (`ldc.intrinsics` and `gcc.builtins` are publicly imported, respectively).
9 Host-specific intrinsics cannot be reliably listed here, however listings can be found
10 at the documentation for the relevant backends, i.e.
11 $(LINK2 https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html, GCC) and
12 $(LINK2 https://llvm.org/docs/LangRef.html, LLVM). It should be noted that not all
13 builtins listed are necessarily supported by the host compiler, please file a bug
14 if this is the case for your workload.
15 
16 Use of this module reduces the amount of conditional compilation needed
17 to use a given builtin. For example, to write a target independent function
18 that uses prefetching we can write the following:
19 ---
20 float usePrefetch(float[] x)
21 {
22     // There is only one import statement required rather than two (versioned) imports
23     import core.builtins;
24     version (GNU)
25         __builtin_prefetch(x.ptr);
26     version (LDC)
27         /+
28             For the curious: 0, 3, 1 mean `x` will only be read-from (0), it will be used
29             very often (3), and it should be fetched to the data-cache (1).
30         +/
31         llvm_prefetch(x.ptr, 0, 3, 1);
32     const doMath = blahBlahBlah;
33     return doMath;
34 }
35 ---
36 
37 
38 Copyright: Copyright © 2021, The D Language Foundation
39 License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
40 Authors:   Walter Bright
41 Source:    $(DRUNTIMESRC core/builtins.d)
42 */
43 
44 module core.builtins;
45 
46 version (GNU)
47     public import gcc.builtins;
48 
49 version (LDC)
50     public import ldc.intrinsics;
51 
52 /// Writes `s` to `stderr` during CTFE (does nothing at runtime).
__ctfeWrite(scope const (char)[]s)53 void __ctfeWrite(scope const(char)[] s) @nogc @safe pure nothrow {}
54