View source code
Display the source code in core/builtins.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Module core.builtins

To provide access to features that would be otherwise counterproductive or difficult to implement, compilers provide an interface consisting of a set of builtins (also called intrinsics) which can be called like normal functions.

This module exposes builtins both common to all D compilers (those provided by the frontend) and specific to the host compiler i.e. those specific to either LLVM or GCC (ldc.intrinsics and gcc.builtins are publicly imported, respectively). Host-specific intrinsics cannot be reliably listed here, however listings can be found at the documentation for the relevant backends, i.e. GCC and LLVM. It should be noted that not all builtins listed are necessarily supported by the host compiler, please file a bug if this is the case for your workload.

Use of this module reduces the amount of conditional compilation needed to use a given builtin. For example, to write a target independent function that uses prefetching we can write the following:

float usePrefetch(float[] x)
{
    // There is only one import statement required rather than two (versioned) imports
    import 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;
}

Authors

Walter Bright

License

Boost License 1.0