mojo intrinsics功能详解及相关说明

intrinsics

Defines intrinsics.

You can import these APIs from the complex package. For example:

from sys.intrinsics import PrefetchLocality

PrefetchLocality

The prefetch locality.

The locality, rw, and cache type correspond to LLVM prefetch intrinsic’s inputs (see LLVM prefetch locality)

Aliases:

  • NONE = PrefetchLocality(0): No locality.

  • LOW = PrefetchLocality(1): Low locality.

  • MEDIUM = PrefetchLocality(2): Medium locality.

  • HIGH = PrefetchLocality(3): Extremely local locality (keep in cache).

Fields:

  • value (SIMD[si32, 1]): The prefetch locality to use. It should be a value in [0, 3].

Implemented traits:

AnyType

Methods:

__init__

__init__(value: Int) -> Self

Constructs a prefetch locality option.

Args:

  • value (Int): An integer value representing the locality. Should be a value in the range [0, 3].

Returns:

The prefetch locality constructed.

PrefetchRW

Prefetch read or write.

Aliases:

  • READ = PrefetchRW(0): Read prefetch.

  • WRITE = PrefetchRW(1): Write prefetch.

Fields:

  • value (SIMD[si32, 1]): The read-write prefetch. It should be in [0, 1].

Implemented traits:

AnyType

Methods:

__init__

__init__(value: Int) -> Self

Constructs a prefetch read-write option.

Args:

  • value (Int): An integer value representing the prefetch read-write option to be used. Should be a value in the range [0, 1].

Returns:

The prefetch read-write option constructed.

PrefetchCache

Prefetch cache type.

Aliases:

  • INSTRUCTION = PrefetchCache(0): The instruction prefetching option.

  • DATA = PrefetchCache(1): The data prefetching option.

Fields:

  • value (SIMD[si32, 1]): The cache prefetch. It should be in [0, 1].

Implemented traits:

AnyType

Methods:

__init__

__init__(value: Int) -> Self

Constructs a prefetch option.

Args:

  • value (Int): An integer value representing the prefetch cache option to be used. Should be a value in the range [0, 1].

Returns:

The prefetch cache type that was constructed.

PrefetchOptions

Collection of configuration parameters for a prefetch intrinsic call.

The op configuration follows similar interface as LLVM intrinsic prefetch op, with a “locality” attribute that specifies the level of temporal locality in the application, that is, how soon would the same data be visited again. Possible locality values are: NONE, LOW, MEDIUM, and HIGH.

The op also takes a “cache tag” attribute giving hints on how the prefetched data will be used. Possible tags are: ReadICache, ReadDCache and WriteDCache.

Note: the actual behavior of the prefetch op and concrete interpretation of these attributes are target-dependent.

Fields:

  • rw (PrefetchRW): Indicates prefetching for read or write.

  • locality (PrefetchLocality): Indicates locality level.

  • cache (PrefetchCache): Indicates i-cache or d-cache prefetching.

Implemented traits:

AnyType

Methods:

__init__

__init__(inout self: Self)

Constructs an instance of PrefetchOptions with default params.

for_read

for_read(self: Self) -> Self

Sets the prefetch purpose to read.

Returns:

The updated prefetch parameter.

for_write

for_write(self: Self) -> Self

Sets the prefetch purpose to write.

Returns:

The updated prefetch parameter.

no_locality

no_locality(self: Self) -> Self

Sets the prefetch locality to none.

Returns:

The updated prefetch parameter.

low_locality

low_locality(self: Self) -> Self

Sets the prefetch locality to low.

Returns:

The updated prefetch parameter.

medium_locality

medium_locality(self: Self) -> Self

Sets the prefetch locality to medium.

Returns:

The updated prefetch parameter.

high_locality

high_locality(self: Self) -> Self

Sets the prefetch locality to high.

Returns:

The updated prefetch parameter.

to_data_cache

to_data_cache(self: Self) -> Self

Sets the prefetch target to data cache.

Returns:

The updated prefetch parameter.

to_instruction_cache

to_instruction_cache(self: Self) -> Self

Sets the prefetch target to instruction cache.

Returns:

The updated prefetch parameter.

llvm_intrinsic

llvm_intrinsic[intrin: StringLiteral, type: AnyRegType]() -> *"type"

Calls an LLVM intrinsic with no arguments.

Calls an LLVM intrinsic with the name intrin and return type type.

Parameters:

  • intrin (StringLiteral): The name of the llvm intrinsic.
  • type (AnyRegType): The return type of the intrinsic.

Returns:

The result of calling the llvm intrinsic with no arguments.

llvm_intrinsic[intrin: StringLiteral, type: AnyRegType, T0: AnyRegType](arg0: T0) -> *"type"

Calls an LLVM intrinsic with one argument.

Calls the intrinsic with the name intrin and return type type on argument arg0.

Parameters:

  • intrin (StringLiteral): The name of the llvm intrinsic.
  • type (AnyRegType): The return type of the intrinsic.
  • T0 (AnyRegType): The type of the first argument to the intrinsic (arg0).

Args:

  • arg0 (T0): The argument t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

启航学途

您的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值