Skip to content
CryoCryo home
Stdlibcore

intrinsics

import std::core::intrinsics; · source

Intrinsics

core::intrinsics declares the operations the compiler lowers directly to LLVM rather than to a call. Nothing here has a body, and the list below is abbreviated by width where a family repeats.

intrinsic function malloc(size: u64) -> void*;
intrinsic function realloc(ptr: void*, new_size: u64) -> void*;
intrinsic function free(ptr: void*) -> void;
intrinsic function ptr_diff(a: void*, b: void*) -> i64;

intrinsic function panic(message: string, loc: Location) -> never;
intrinsic function location() -> Location;
intrinsic function try_catch(body: void*, data: void*) -> boolean;
intrinsic function trap() -> never;
intrinsic function debugtrap() -> void;
intrinsic function frame_address(level: u32) -> void*;
intrinsic function return_address(level: u32) -> void*;

intrinsic function atomic_fence(order: u32) -> void;
intrinsic function atomic_load_u8(ptr: u8*, order: u32) -> u8;                 // ... _u32, _u64
intrinsic function atomic_store_u8(ptr: u8*, value: u8, order: u32) -> void;   // ... _u32, _u64
intrinsic function atomic_add_u8(ptr: u8*, value: u8, order: u32) -> u8;       // ... _u32, _u64
intrinsic function atomic_sub_u8(ptr: u8*, value: u8, order: u32) -> u8;       // ... _u32, _u64
intrinsic function atomic_and_u8(ptr: u8*, value: u8, order: u32) -> u8;       // ... _u32, _u64
intrinsic function atomic_or_u8(ptr: u8*, value: u8, order: u32) -> u8;        // ... _u32, _u64
intrinsic function atomic_xor_u8(ptr: u8*, value: u8, order: u32) -> u8;       // ... _u32, _u64
intrinsic function atomic_swap_u8(ptr: u8*, value: u8, order: u32) -> u8;      // ... _u32, _u64
intrinsic function atomic_cmpxchg_u8(ptr: u8*, cmp: u8, new: u8,
                                     succ: u32, fail: u32, out_ok: boolean*) -> u8;   // ... _u32, _u64

intrinsic function fpclass(value: f64, test: i32) -> boolean;
intrinsic function fabs64(value: f64) -> f64;
intrinsic function fabs32(value: f32) -> f32;
intrinsic function floor64(value: f64) -> f64;
intrinsic function ceil64(value: f64) -> f64;
intrinsic function ftrunc64(value: f64) -> f64;
intrinsic function round64(value: f64) -> f64;
intrinsic function copysign64(magnitude: f64, sign: f64) -> f64;
intrinsic function sqrt64(value: f64) -> f64;
intrinsic function sqrt32(value: f32) -> f32;
intrinsic function fma64(x: f64, y: f64, z: f64) -> f64;

intrinsic function bswap16(value: u16) -> u16;              // ... 32, 64
intrinsic function popcount32(value: u32) -> u32;           // ... 64
intrinsic function clz32(value: u32) -> u32;                // ... 64
intrinsic function ctz32(value: u32) -> u32;                // ... 64
intrinsic function rotl32(value: u32, n: u32) -> u32;       // ... 64
intrinsic function rotr32(value: u32, n: u32) -> u32;       // ... 64

intrinsic function dirent_name(entry: void*) -> string;
intrinsic function dirent_type(entry: void*) -> i32;

intrinsic function va_arg_i32(args: void*) -> i32;       // ... _u32, _i64, _u64, _f64, _ptr, _string

The memory intrinsics back alloc and core::mem; the atomics back sync::atomic; the float intrinsics back math; the bit intrinsics (byte swap, population count, leading and trailing zeros, rotates) lower to the LLVM intrinsics of the same names, count in u32 whatever the operand's width, and back the hash rounds in encoding; and the va_arg_* family backs VaArgs::next. memcpy, memset, sizeof, and alignof are keywords rather than intrinsics and need no declaration. You will rarely call any of these directly — the typed wrappers exist so you don't have to.

Unlike the rest of core, the module is not in the prelude. Its functions are exported, so bringing it in bare would make panic name both the intrinsic and core::panic; reach an intrinsic by path, intrinsics::malloc(64) after import std::core::intrinsics;, or import it by name.

Source locations

type struct Location {
    file:     string;
    line:     u32;
    column:   u32;
    function: string;
}

A place in the source, made by the compiler. Each call of location() answers the place it is written: its line and column, and the qualified name of the function it is written in (App::Main::main, never a linker symbol). Inside a function marked ![caller_location] it is the place of the call to that function instead, so a check can report its caller's line; the standard library's index bounds check is marked this way, so an out-of-range xs[i] reports the xs[i]. core::panic(message, intrinsics::location()) names all of it: panicked at <file>:<line>:<column> in <function>: <message>. The full rules are in Intrinsic Functions.

Properties

PropertyType
filestring
lineu32
columnu32
functionstring

intrinsic function location() -> Location;