IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

CompilationTarget

struct CompilationTarget[value: __mlir_type.`!kgen.target` = _current_target()]

A struct that provides information about a target architecture.

This struct encapsulates various methods to query target-specific information such as architecture features, OS details, endianness, and memory characteristics.

Parameters

  • value (__mlir_type.`!kgen.target`): The target architecture to query. Defaults to the current target.

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable

Methods

__init__

def __init__() -> Self

Initialize a CompilationTarget with the default target.

unsupported_target_error

static def unsupported_target_error[*, operation: Optional[String] = None, note: Optional[String] = None]() -> Never

Produces a constraint failure when called indicating that some operation is not supported by the current compilation target.

Parameters:

  • operation (Optional[String]): Optional name of the operation that is not supported. Should be a function name or short description.
  • note (Optional[String]): Optional additional note to print.

Returns:

Never

default_compile_options

static def default_compile_options() -> StaticString

Returns the default compile options for the compilation target.

Returns:

StaticString: The string of default compile options for the compilation target.

has_sse4

static def has_sse4() -> Bool

Checks if the target supports SSE4 instructions.

Returns:

Bool: True if the target supports SSE4, False otherwise.

has_avx

static def has_avx() -> Bool

Returns True if the host system has AVX, otherwise returns False.

Returns:

Bool: True if the host system has AVX, otherwise returns False.

has_avx2

static def has_avx2() -> Bool

Returns True if the host system has AVX2, otherwise returns False.

Returns:

Bool: True if the host system has AVX2, otherwise returns False.

has_avx512f

static def has_avx512f() -> Bool

Returns True if the host system has AVX512, otherwise returns False.

Returns:

Bool: True if the host system has AVX512, otherwise returns False.

has_intel_amx

static def has_intel_amx() -> Bool

Returns True if the host system has Intel AMX support, otherwise returns False.

Returns:

Bool: True if the host system has Intel AMX and False otherwise.

has_fma

static def has_fma() -> Bool

Returns True if the target has FMA (Fused Multiply-Add) support, otherwise returns False.

Returns:

Bool: True if the target has FMA support, otherwise returns False.

has_vnni

static def has_vnni() -> Bool

Returns True if the target has avx512_vnni, otherwise returns False.

Returns:

Bool: True if the target has avx512_vnni, otherwise returns False.

has_neon

static def has_neon() -> Bool

Returns True if the target has Neon support, otherwise returns False.

Returns:

Bool: True if the target support the Neon instruction set.

has_neon_int8_dotprod

static def has_neon_int8_dotprod() -> Bool

Returns True if the target has the Neon int8 dot product extension, otherwise returns False.

Returns:

Bool: True if the target support the Neon int8 dot product extension and False otherwise.

has_neon_int8_matmul

static def has_neon_int8_matmul() -> Bool

Returns True if the target has the Neon int8 matrix multiplication extension (I8MM), otherwise returns False.

Returns:

Bool: True if the target support the Neon int8 matrix multiplication extension (I8MM) and False otherwise.

has_riscv_extension

static def has_riscv_extension[name: StringSpan[ImmStaticOrigin]]() -> Bool

Returns True if the target implements a RISC-V ISA extension.

RISC-V has too many extensions to give each one a predicate, so this takes the extension name directly. Use the lowercase name LLVM gives the extension, which is the ISA-string spelling without the rv32/rv64 prefix and without any version: "m", "a", "f", "d", "c", "v", "zba", "zicsr", and so on. "g" is not an extension; query its members individually.

An extension implied by another one counts as present, so a target built with d also reports f, and one built with a also reports zaamo and zalrsc.

Example:

from std.sys import CompilationTarget

def triple(x: Int32) -> Int32:
comptime if CompilationTarget.has_riscv_extension["m"]():
return x * 3
return (x << 1) + x

Parameters:

Returns:

Bool: True if the target is RISC-V and implements the extension, False otherwise. Always False on a non-RISC-V target.

is_x86

static def is_x86() -> Bool

Checks if the target is an x86 architecture.

This is an architecture check, not an instruction-set check: use has_sse4(), has_avx2(), and friends to gate code on a specific extension.

Returns:

Bool: True if the target is 32- or 64-bit x86, False otherwise.

is_arm

static def is_arm() -> Bool

Checks if the target is an ARM architecture.

This is an architecture check, not an instruction-set check: use has_neon() and friends to gate code on a specific extension.

Returns:

Bool: True if the target is 32- or 64-bit ARM, False otherwise.

is_riscv

static def is_riscv() -> Bool

Checks if the target is a RISC-V architecture.

This is an architecture check, not an instruction-set check: use has_riscv_extension() to gate code on a specific extension.

Returns:

Bool: True if the target is 32- or 64-bit RISC-V, False otherwise.

is_rv32

static def is_rv32() -> Bool

Checks if the target is a 32-bit RISC-V architecture.

Returns:

Bool: True if the target is 32-bit RISC-V, False otherwise.

is_rv64

static def is_rv64() -> Bool

Checks if the target is a 64-bit RISC-V architecture.

Returns:

Bool: True if the target is 64-bit RISC-V, False otherwise.

is_apple_m1

static def is_apple_m1() -> Bool

Check if the target is an Apple M1 system.

Returns:

Bool: True if the host system is an Apple M1, False otherwise.

is_apple_m2

static def is_apple_m2() -> Bool

Check if the target is an Apple M2 system.

Returns:

Bool: True if the host system is an Apple M2, False otherwise.

is_apple_m3

static def is_apple_m3() -> Bool

Check if the target is an Apple M3 system.

Returns:

Bool: True if the host system is an Apple M3, False otherwise.

is_apple_m4

static def is_apple_m4() -> Bool

Check if the target is an Apple M4 system.

Returns:

Bool: True if the host system is an Apple M4, False otherwise.

is_apple_m5

static def is_apple_m5() -> Bool

Check if the target is an Apple M5 system.

Returns:

Bool: True if the host system is an Apple M5, False otherwise.

is_apple_silicon

static def is_apple_silicon() -> Bool

Check if the host system is an Apple Silicon with AMX support.

Returns:

Bool: True if the host system is an Apple Silicon with AMX support, and False otherwise.

is_neoverse_n1

static def is_neoverse_n1() -> Bool

Returns True if the host system is a Neoverse N1 system, otherwise returns False.

Returns:

Bool: True if the host system is a Neoverse N1 system and False otherwise.

is_linux

static def is_linux() -> Bool

Returns True if the host operating system is Linux.

Returns:

Bool: True if the host operating system is Linux and False otherwise.

is_macos

static def is_macos() -> Bool

Returns True if the host operating system is macOS.

Returns:

Bool: True if the host operating system is macOS and False otherwise.