Skip to main content

IAR Embedded Workbench for RISC-V 3.40

Summary of intrinsic functions

In this section:

The intrinsic functions provide direct access to low-level processor operations and can be very useful in, for example, time-critical routines. The intrinsic functions compile into inline code, either as a single instruction or as a short sequence of instructions.

The IAR C/C++ Compiler for RISC-V can be used with more than one set of intrinsic functions.

To use the IAR generic intrinsic functions in an application, include the header file intrinsics.h.

Note that the intrinsic function names start with double underscores, for example:

__disable_interrupt

This table summarizes the generic intrinsic functions:

Intrinsic function

Description

__clear_bits_csr

Clears bits in a control and status register.

__disable_interrupt

Disables interrupts

__enable_interrupt

Enables interrupts

__fp_absNN

Returns the absolute value.

__fp_classNN

Classifies a floating-point value.

__fp_copy_signNN

Returns an argument value with the sign of another argument.

__fp_maxNN

Returns the largest of two values.

__fp_minNN

Returns the smallest of two values.

__fp_negate_signNN

Returns an argument value with the inverted sign of another argument.

__fp_sqrtNN

Returns the square root of an argument.

__fp_xor_signNN

Returns an argument value with the sign bit combined from the sign bits of that argument and another argument.

__get_interrupt_state

Returns the interrupt state

__iar_riscv_cbo_clean

Inserts the cbo.clean instructions.

__iar_riscv_cbo_flush

Inserts the cbo.flush instructions.

__iar_riscv_cbo_inval

Inserts the cbo.inval instructions.

__iar_riscv_cbo_zero

Inserts the cbo.zero instructions.

__iar_riscv_prefetch_i

Inserts the prefetch.i instructions.

__iar_riscv_prefetch_r

Inserts the prefetch.r instructions.

__iar_riscv_prefetch_w

Inserts the prefetch.w instructions.

__nds__clrov

Clears the Xandesdsp extension overflow bit.

__nds__rdov

Reads the Xandesdsp extension overflow bit.

__no_operation

Inserts a nop instruction

__read_csr

Reads a control and status register.

__return_address

Returns the return address.

__riscv_ffb

Inserts an ffb instruction

__riscv_ffmism

Inserts an ffmism instruction

__riscv_ffzmism

Inserts an ffzmism instruction

__riscv_flmism

Inserts an flmism instruction

__set_bits_csr

Sets bits in a control and status register.

__set_interrupt_state

Restores the interrupt state

__wait_for_interrupt

Inserts a wfi instruction

__write_csr

Writes a value to a control and status register.

Table 82. Intrinsic functions summary  


Intrinsic functions for bit manipulation

The header file iar_bitmanip_intrinsics.h defines three groups of bitmanip intrinsic functions:

  • __rv_XXX functions that operate on the long data type

  • __rv32_XXX functions that operate on the int32_t data type

  • __rv64_XXX functions that operate on the int64_t data type

The __rv64_XXX functions are only available on RV64.

These bitmanip functions are taken from the header file rvintrin.h.

Intrinsic functions for the P extension

The header file pext_intrinsic.h defines intrinsic functions for Packed-SIMD Instructions (the P extension). The P extension intrinsic functions use the prefix __rv_.

Intrinsic functions for the Cache Management extensions

By including the header file intrinsics.h, you also get access to intrinsic functions for CMO instructions (the standard extensions Zicbom, Zicbop, and Zicboz). The cache management extensions intrinsic functions use the prefix __iar_riscv_.

Intrinsic functions for Scalar cryptography

The header file iar_cryptography_intrinsics.h, defines __rv_xxx_ functions that operate on the long data type, with the exceptions __rv_sm4e and __rv_sm4ks, whose parameters are unsigned int on all architectures. Depending on the target architecture, that is RV32 or RV64, the appropriate intrinsic functions will be enabled, using the corresponding parameter sizes.

Intrinsic functions for AndeStar™ extensions

The instructions in the Xandesdsp (AndeStar™ DSP) instruction set extension can be accessed directly in your code, via a set of intrinsic functions, by including the header file nds_intrinsic.h. For information about the functions and instructions, see the AndeStar V5 DSP ISA Extension Specification, available at www.andestech.com. The IAR C/C++ Compiler for RISC-V supports the intrinsic functions on the formats __nds__instruction() and __nds__v_instruction().

The __nds__v_instruction() functions use vector types, for example uint8xt_t, which behave like arrays, but which can be placed in processor registers. In addition, arithmetical operations like + can be applied to vector types.

The header file iar_andesperf_intrinsics.h contains a small number of intrinsic functions that can be used when the Andes Performance Extension is enabled. Include this file if you want to use these functions.

Intrinsic functions for Nuclei DSP (Xxldsp)

The header file iar_nuclei_intrinsic.h defines two groups of intrinsic functions:

  • __nuclei_expdNN functions are defined in terms of the unsigned long data type

  • __nuclei_v_expdNN functions are defined in terms of the SIMD vector type uint8x4_t (RV32) or uint8x8_t (RV64).