Skip to main content

struct

LegacyPointer

Defines a LegacyPointer struct that contains the address of a register passable type.

Parameters

  • type (AnyRegType): Type of the underlying data.
  • address_space (AddressSpace): The address space the pointer is in.

Fields

  • address (pointer<*"type", #lit.struct.extract<:@stdlib::@builtin::@int::@Int #lit.struct.extract<:@stdlib::@memory::@reference::@AddressSpace address_space, "_value">, "value">>): The pointed-to address.

Implemented traits

AnyType, Boolable, CollectionElement, Copyable, EqualityComparable, Intable, Movable, Stringable

Methods

__init__

__init__() -> Self

Constructs a null LegacyPointer from the value of pop.pointer type.

Returns:

Constructed LegacyPointer object.

__init__(address: pointer<*"type", #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>) -> Self

Constructs a LegacyPointer from the address.

Args:

  • address (pointer<*"type", #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>): The input pointer address.

Returns:

Constructed LegacyPointer object.

__init__(value: SIMD[address, 1]) -> Self

Constructs a LegacyPointer from the value of scalar address.

Args:

  • value (SIMD[address, 1]): The input pointer index.

Returns:

Constructed LegacyPointer object.

__init__(*, address: Int) -> Self

Constructs a Pointer from an address in an integer.

Args:

  • address (Int): The input address.

Returns:

Constructed Pointer object.

__bool__

__bool__(self: Self) -> Bool

Checks if the LegacyPointer is null.

Returns:

Returns False if the LegacyPointer is null and True otherwise.

__lt__

__lt__(self: Self, rhs: Self) -> Bool

Returns True if this pointer represents a lower address than rhs.

Args:

  • rhs (Self): The value of the other pointer.

Returns:

True if this pointer represents a lower address and False otherwise.

__eq__

__eq__(self: Self, rhs: Self) -> Bool

Returns True if the two pointers are equal.

Args:

  • rhs (Self): The value of the other pointer.

Returns:

True if the two pointers are equal and False otherwise.

__ne__

__ne__(self: Self, rhs: Self) -> Bool

Returns True if the two pointers are not equal.

Args:

  • rhs (Self): The value of the other pointer.

Returns:

True if the two pointers are not equal and False otherwise.

__add__

__add__[T: Intable](self: Self, rhs: T) -> Self

Returns a new pointer shifted by the specified offset.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • rhs (T): The offset.

Returns:

The new LegacyPointer shifted by the offset.

__sub__

__sub__[T: Intable](self: Self, rhs: T) -> Self

Returns a new pointer shifted back by the specified offset.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • rhs (T): The offset.

Returns:

The new LegacyPointer shifted back by the offset.

__iadd__

__iadd__[T: Intable](inout self: Self, rhs: T)

Shifts the current pointer by the specified offset.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • rhs (T): The offset.

__isub__

__isub__[T: Intable](inout self: Self, rhs: T)

Shifts back the current pointer by the specified offset.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • rhs (T): The offset.

get_null

static get_null() -> Self

Constructs a LegacyPointer representing nullptr.

Returns:

Constructed nullptr LegacyPointer object.

__str__

__str__(self: Self) -> String

Format this pointer as a hexadecimal string.

Returns:

A String containing the hexadecimal representation of the memory location destination of this pointer.

address_of

static address_of(arg: Reference[type, is_mutable, lifetime, address_space]) -> Self

Gets the address of the argument.

Args:

  • arg (Reference[type, is_mutable, lifetime, address_space]): The value to get the address of.

Returns:

A LegacyPointer struct which contains the address of the argument.

__refitem__

__refitem__(self: Self) -> !lit.ref<*"type", mut #lit.lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>

Enable subscript syntax ref[] to access the element.

Returns:

The MLIR reference for the Mojo compiler to use.

__refitem__[T: Intable](self: Self, offset: T) -> !lit.ref<*"type", mut #lit.lifetime, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>

Enable subscript syntax ref[idx] to access the element.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • offset (T): The offset to load from.

Returns:

The MLIR reference for the Mojo compiler to use.

load

load[*, alignment: Int = alignof[AnyRegType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1](self: Self) -> type

Loads the value the LegacyPointer object points to.

Constraints:

The alignment must be a positive integer value.

Parameters:

  • alignment (Int): The minimal alignment of the address.

Returns:

The loaded value.

load[T: Intable, *, alignment: Int = alignof[AnyRegType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1](self: Self, offset: T) -> type

Loads the value the LegacyPointer object points to with the given offset.

Constraints:

The alignment must be a positive integer value.

Parameters:

  • T (Intable): The Intable type of the offset.
  • alignment (Int): The minimal alignment of the address.

Args:

  • offset (T): The offset to load from.

Returns:

The loaded value.

store

store[T: Intable, /, *, alignment: Int = alignof[AnyRegType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1](self: Self, offset: T, value: type)

Stores the specified value to the location the LegacyPointer object points to with the given offset.

Constraints:

The alignment must be a positive integer value.

Parameters:

  • T (Intable): The Intable type of the offset.
  • alignment (Int): The minimal alignment of the address.

Args:

  • offset (T): The offset to store to.
  • value (type): The value to store.

store[*, alignment: Int = alignof[AnyRegType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1](self: Self, value: type)

Stores the specified value to the location the LegacyPointer object points to.

Constraints:

The alignment value must be a positive integer.

Parameters:

  • alignment (Int): The minimal alignment of the address.

Args:

  • value (type): The value to store.

nt_store

nt_store(self: Self, value: type)

Stores a value using non-temporal store.

The address must be properly aligned, 64B for avx512, 32B for avx2, and 16B for avx.

Args:

  • value (type): The value to store.

__int__

__int__(self: Self) -> Int

Returns the pointer address as an integer.

Returns:

The address of the pointer as an Int.

alloc

static alloc(count: Int, /, *, alignment: Int = alignof[AnyRegType,__mlir_type.!kgen.target]()) -> Self

Heap-allocates a number of element of the specified type using the specified alignment.

Args:

  • count (Int): The number of elements to allocate (note that this is not the bytecount).
  • alignment (Int): The alignment used for the allocation.

Returns:

A new LegacyPointer object which has been allocated on the heap.

free

free(self: Self)

Frees the heap allocated memory.

bitcast

bitcast[new_type: AnyRegType = type, /, address_space: AddressSpace = address_space](self: Self) -> LegacyPointer[$0, $1]

Bitcasts a LegacyPointer to a different type.

Parameters:

  • new_type (AnyRegType): The target type.
  • address_space (AddressSpace): The address space of the result.

Returns:

A new LegacyPointer object with the specified type and the same address, as the original LegacyPointer.

offset

offset[T: Intable](self: Self, idx: T) -> Self

Returns a new pointer shifted by the specified offset.

Parameters:

  • T (Intable): The Intable type of the offset.

Args:

  • idx (T): The offset.

Returns:

The new LegacyPointer shifted by the offset.