| AI Engine Intrinsics User Guide (v2026.1)

Loading...
Searching...
No Matches
Functions
Integer Operations
Intrinsics » Scalar Operations

## Overview

## Functions
int | scalar_abs (int a)

## Scalar select intrinsics
char | select (bool, char, char)
| Scalar select.
unsigned char | select (bool, unsigned char, unsigned char)
| Scalar select.
short | select (bool, short, short)
| Scalar select.
unsigned short | select (bool, unsigned short, unsigned short)
| Scalar select.
int | select (bool, int, int)
| Scalar select.
unsigned int | select (bool, unsigned int, unsigned int)
| Scalar select.
long | select (bool, long, long)
| Scalar select.
unsigned long | select (bool, unsigned long, unsigned long)
| Scalar select.
void * | select (bool, void *, void *)
| Scalar select.

## Leading bit count
unsigned | clb (int a)
| Count number of leading consecutive bits. If a is positive, count leading 0's, otherwise count leading 1's.
unsigned | clb (unsigned a)
| Count number of leading consecutive 0's.
unsigned | clb (long long a)
| Count number of leading consecutive bits. If a is positive, count leading 0's, otherwise count leading 1's.
unsigned | clb (unsigned long long a)
| Count number of leading consecutive 0's.

## Inserting nops in the micro-code
void | nop (unsigned delay)
| Insert pipeline bubbles in the micro-code.
void | nop ()
| Insert pipeline bubbles in the micro-code.

## Bit extraction/update
unsigned | bitset (unsigned src, unsigned val, unsigned idx)
unsigned | bitget (unsigned src, unsigned idx)

## Function Documentation

## ◆ bitget()

unsigned bitget | ( | unsigned | src,
|  | unsigned | idx )

Returns the value (0 or 1) of the bit at idx in src.

return (src >> idx) & 1

Parameters

  src | The value in which a bit is to be get.
  idx | The index of the bit to get. This must be a compile time constant.

## ◆ bitset()

unsigned bitset | ( | unsigned | src,
|  | unsigned | val,
|  | unsigned | idx )

Returns the updated src with the bit at idx set to val.

mask = ~(1 << idx)
newbit = ((val) ? 1 : 0) << idx
src = (src & mask) | newbit

Parameters

  src | The value in which a bit is to be set.
  val | The value to set the bit to. Treated as a 1 or 0 to be shifted into the correct position.
  idx | The index of the bit to set. This must be a compile time constant.

## ◆ clb() [1/4]

unsigned clb | ( | int | a | ) |

Count number of leading consecutive bits. If a is positive, count leading 0's, otherwise count leading 1's.

## ◆ clb() [2/4]

unsigned clb | ( | long long | a | ) |

Count number of leading consecutive bits. If a is positive, count leading 0's, otherwise count leading 1's.

## ◆ clb() [3/4]

unsigned clb | ( | unsigned | a | ) |

Count number of leading consecutive 0's.

## ◆ clb() [4/4]

unsigned clb | ( | unsigned long long | a | ) |

Count number of leading consecutive 0's.

## ◆ nop() [1/2]

void nop | ( |  | ) |

Insert pipeline bubbles in the micro-code.

Parameters

  delay | Number of cycles between two instructions. (Default = 2)

Note
  Delay must be a compile time constant.
  Subsequent nops will be collapsed into a single nop (only the maximum value will be seen).

## ◆ nop() [2/2]

void nop | ( | unsigned | delay | ) |

Insert pipeline bubbles in the micro-code.

Parameters

  delay | Number of cycles between two instructions. (Default = 2)

Note
  Delay must be a compile time constant.
  Subsequent nops will be collapsed into a single nop (only the maximum value will be seen).

## ◆ scalar_abs()

int scalar_abs | ( | int | a | ) |

## ◆ select() [1/9]

char select | ( | bool | ,
|  | char | ,
|  | char | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [2/9]

int select | ( | bool | ,
|  | int | ,
|  | int | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [3/9]

long select | ( | bool | ,
|  | long | ,
|  | long | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [4/9]

short select | ( | bool | ,
|  | short | ,
|  | short | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [5/9]

unsigned char select | ( | bool | ,
|  | unsigned char | ,
|  | unsigned char | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [6/9]

unsigned int select | ( | bool | ,
|  | unsigned int | ,
|  | unsigned int | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [7/9]

unsigned long select | ( | bool | ,
|  | unsigned long | ,
|  | unsigned long | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [8/9]

unsigned short select | ( | bool | ,
|  | unsigned short | ,
|  | unsigned short | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.

## ◆ select() [9/9]

void * select | ( | bool | ,
|  | void * | ,
|  | void * | )

Scalar select.

These instructions are equivalent to the ternary ?: operator and should normally be inferred by the compiler automatically.