The MCI defines a number of built-in functions that can be called by any program compiled with the infrastructure. These all reside in the mci module, which is actually implemented in D code inside the mci.vm library.
All intrinsics are thread safe.
This module is given special treatment by the assembler, so you do not need to provide a physical module that implements it.
This is an opaque type which is useful for representing an arbitrary reference type:
type Object
{
}
This is an opaque wrapper type given special treatment by garbage collector implementations that support it. It facilitates so-called weak references:
type Weak
{
}
Instances of this type should not be manipulated directly. The layout of this type is completely unspecified and any reliance on it is unsupported. To work with instances of Weak, use the related intrinsics.
These intrinsics retrieve information about the environment the MCI was compiled in.
Gets a value indicating which compiler was used to build the MCI.
Possible values:
Value | Description |
---|---|
0 | Unknown compiler. |
1 | Digital Mars D (DMD). |
2 | GNU D Compiler (GDC). |
3 | LLVM D Compiler (LDC). |
Gets a value indicating which architecture the MCI was compiled for.
Possible values:
Value | Description |
---|---|
0 | x86 (32-bit or 64-bit). |
1 | ARM (32-bit). |
2 | PowerPC (32-bit or 64-bit). |
3 | Itanium (64-bit). |
4 | MIPS (32-bit or 64-bit). |
Gets a value indicating which operating system the MCI was compiled on.
Possible values:
Value | Description |
---|---|
0 | All Windows systems. |
1 | All Linux systems. |
2 | Mac OS X (and other Darwin systems). |
3 | FreeBSD. |
4 | Solaris. |
5 | AIX. |
Gets a value indicating which endianness the MCI was compiled for.
Possible values:
Value | Description |
---|---|
0 | Little endian. |
1 | Big endian. |
Gets a value indicating which emulation layer the MCI is compiled under.
Possible values:
Value | Description |
---|---|
0 | No emulation layer. |
1 | Cygwin. |
2 | MinGW. |
Gets a value indicating whether the MCI is compiled for 32-bit pointers.
This function returns 0 if the MCI is compiled for 64-bit pointers; 1 if it’s compiled for 32-bit pointers.
Atomically loads the reference from the memory location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically sets the location pointed to by the first argument to the reference in the second argument.
Full sequential consistency is guaranteed.
Stores the reference in the third argument to the location pointed to by the first argument if the reference pointed to by the first argument is equal to the second argument. All of this happens atomically.
Returns 1 if the store happened; otherwise, returns 0.
Full sequential consistency is guaranteed.
Atomically loads the value from the memory location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically sets the location pointed to by the first argument to the value in the second argument.
Full sequential consistency is guaranteed.
Stores the value in the third argument to the location pointed to by the first argument if the value pointed to by the first argument is equal to the second argument. All of this happens atomically.
Returns 1 if the store happened; otherwise, returns 0.
Full sequential consistency is guaranteed.
Atomically adds the value in the second argument to the value pointed to by the first argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically subtracts the value in the second argument from the value pointed to by the first argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically multiplies the value pointed to by the first argument with the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically divides the value pointed to by the first argument with the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically computes the remainder from dividing the value pointed to by the first argument by the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Aotmically computes bit-wise AND between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Aotmically computes bit-wise OR between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Aotmically computes bit-wise XOR between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically loads the value from the memory location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically sets the location pointed to by the first argument to the value in the second argument.
Full sequential consistency is guaranteed.
Stores the value in the third argument to the location pointed to by the first argument if the value pointed to by the first argument is equal to the second argument. All of this happens atomically.
Returns 1 if the store happened; otherwise, returns 0.
Full sequential consistency is guaranteed.
Atomically adds the value in the second argument to the value pointed to by the first argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically subtracts the value in the second argument from the value pointed to by the first argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically multiplies the value pointed to by the first argument with the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically divides the value pointed to by the first argument with the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Atomically computes the remainder from dividing the value pointed to by the first argument by the value in the second argument and returns the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Aotmically computes bit-wise AND between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Aotmically computes bit-wise OR between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Aotmically computes bit-wise XOR between the value pointed to by the first argument and the value in the second argument and return the result.
The result is also assigned to the location pointed to by the first argument.
Full sequential consistency is guaranteed.
Instructs the GC to perform a full collection. This may cause a stop of the world.
Instructs the GC to do minimal GC work. This function is appropriate for tight loops, and is relatively cheap.
Gets a value indicating the amount of collections the GC has performed.
Informs the GC that a significant amount of unmanaged memory (given by the argument) is about to be allocated.
Informs the GC that a significant amount of unmanaged memory (given by the argument) is about to be freed.
Gets a value indicating whether the GC is generational.
Gets the amount of generations managed by the GC. This is guaranteed to be a constant number.
Calling this function if the GC is not generational results in undefined behavior.
Instructs the GC generation given by the ID in the argument to perform a full collection. This may cause a stop of the world.
Calling this function if the GC is not generational results in undefined behavior.
Instructs the GC generation given by the ID in the argument to perform as much cleanup work as it can without stopping the world.
Calling this function if the GC is not generational results in undefined behavior.
Gets a value indicating the amount of collections the GC has performed in the generation given by the ID in the argument.
Calling this function if the GC is not generational results in undefined behavior.
Gets a value indicating whether the GC is interactive (i.e. supports allocate and free callbacks). Returns 1 if the GC is interactive; otherwise, returns 0.
Adds a callback to the GC which will be called on every allocation made in the program. The parameter given to the function pointer is the newly allocated object. Note that the callback will be triggered right after the memory has been allocated.
Calling this function if the GC is not interactive or with a null callback pointer results in undefined behavior.
Removes a callback previously added with gc_add_allocate_callback. If the given callback was not registered previously, nothing happens.
Calling this function if the GC is not interactive or with a null callback pointer results in undefined behavior.
Adds a callback to the GC which will be called on the given object when it is no longer reachable (i.e. considered garbage). Note that this callback will be triggered just before the memory is actually freed. Passing a null value as the second argument will remove any existing callback for the given object. Passing any other value when a callback is already registered simply overwrites the existing callback.
The callback is automatically removed when the object is freed.
Calling this function if the GC is not interactive or with a null object results in undefined behavior.
Blocks the current thread until all free callbacks that are currently enqueued have been processed by the finalization thread.
Gets a value indicating whether the GC is atomic (i.e. requires read or write barriers). Returns 1 if the GC is atomic; otherwise, returns 0.
Returns flags indicating which barriers the current GC requires.
Possible flags:
0x0 | No barriers are required. |
0x1 | Read barriers are required for memory loads. |
0x2 | Write barriers are required for memory stores. |
Produces a NaN (not a number) value with a given user payload. This abuses an obscure feature of IEEE 754 that allows 22 bits of a NaN value to be set to a user-specified value. This does of course mean that only 22 bits of the given payload will be inserted in the NaN value.
Produces a NaN (not a number) value with a given user payload. This abuses an obscure feature of IEEE 754 that allows 51 bits of a NaN value to be set to a user-specified value. This does of course mean that only 51 bits of the given payload will be inserted in the NaN value.
Extracts the 22-bit payload stored in a NaN (not a number) value.
Extracts the 51-bit payload stored in a NaN (not a number) value.
Returns 1 if the given value is NaN (not a number); otherwise, returns 0. This function is payload-aware, so NaNs with payloads will correctly be regarded NaN.
Returns 1 if the given value is NaN (not a number); otherwise, returns 0. This function is payload-aware, so NaNs with payloads will correctly be regarded NaN.
Returns 1 if the given value is positive or negative infinity; otherwise, returns 0.
Returns 1 if the given value is positive or negative infinity; otherwise, returns 0.
Creates a weak reference to an object given in the first parameter. Calling this function with a null parameter results in undefined behavior.
This function returns null if insufficient memory is available. The weak reference returned by this intrinsic must not be freed with mem.free or any other deallocation mechanism.
Gets the target of a given weak reference. Calling this function with a null weak reference results in undefined behavior.
The returned object may be null, since the target of the weak reference could have been collected since it was set.
Sets the target of a given weak reference. Calling this function with a null weak reference results in undefined behavior.