You copied the Doc URL to your clipboard.

Why does the intrinsic function __REV16 use uint32_t rather than uint16_t as its data type?

Article ID: 155641753

Published date: 13 Feb 2018

Last updated: -

Applies to: Compilers

Problem/Question

Why does the intrinsic function __REV16 use uint32_t rather than uint16_t as its data type?

Scenario

The intrinsic function __REV16 swaps the bytes of a short type, uint16_t. Why is its argument declared as a uint32_t type rather than a uint16_t type?

Answer

The reasons are listed below:

  • According to the ARM Architecture Procedure Call Standard (AAPCS), registers R0-R3 are used to pass the first four parameters in the function call for AArch32 software. For each of these parameters, its data size must be equal to or smaller than 4 bytes (uint32_t). Each parameter occupies one register, regardless of whether its data size is equal to or smaller than 4 bytes.

    For example, consider the case that the first parameter of a __REV16 intrinsic function is of type uint16_t and the size is 2 bytes. Although its size is smaller than 4 bytes, the parameter still uses the entire R0 register.

  • According to the ARMv7-M Architecture Reference Manual, the instruction REV16 takes general-purpose registers as input and output. Even a 16-bit value must be stored in a 4-byte-wide general-purpose register when using the instruction.

Based on the reasons listed above, there is no special concern when using type uint32_t, rather than uint16_t, as the parameter data type for the intrinsic function __REV16.

Workaround

N/A

Example

N/A

Was this page helpful? Yes No