Cortex-M KEIL特殊用法

KEIL armcc编译器特殊功能

9.143 __usat intrinsic

This intrinsic inserts a USAT instruction into the instruction stream generated by the compiler.

It enables you to saturate an unsigned value from within your C or C++ code.

Syntax

int __usat(unsigned int val, unsigned int sat)
Where:
val
Is the value to be saturated.specific
sat
Is the bit position to saturate to.
usat must be in the range 0 to 31.

Return value

The __usat intrinsic returns val saturated to the unsigned range 0 ≤ x ≤ 2sat –1.

理解

val为输入变量,sat为饱和参数,取值范围为 0~31;
返回值为 return (val < 0) ? 0 : (val > 2^sat-1 ? 2^sat-1 : val); 
例如:y = __usat(x,8);
则y的取值范围为 0 < y < 255.

9.138 __ssat intrinsic

This intrinsic inserts an SSAT instruction into the instruction stream generated by the compiler.

It enables you to saturate a signed value from within your C or C++ code.

Syntax

int __ssat(int val, unsigned int sat)
Where:
val
Is the value to be saturated.
sat
Is the bit position to saturate to.
sat must be in the range 1 to 32.

Return value

The __ssat intrinsic returns val saturated to the signed range –2sat–1 ≤ x ≤ 2sat–1 –1.

理解

val为输入变量,sat为饱和参数,取值范围为 1~32;
返回值为 return (val < –2^(sat–1)) ? –2^(sat–1) : (val > 2^(sat–1) –1 ? 2^(sat–1) –1 : val); 
例如:y = __ssat(x,9);
则y的取值范围为 -256 < y < 255.

9.129 __rbit intrinsic

This intrinsic inserts an RBIT instruction into the instruction stream generated by the compiler. It enables you to reverse the bit order in a 32-bit word from within your C or C++ code.

Syntax

unsigned int __rbit(unsigned int val)
Where:
val
is the data value whose bit order is to be reversed.
Return value
The __rbit intrinsic returns the value obtained from val by reversing its bit order.

9.130 __rev intrinsic

This intrinsic inserts a REV instruction or an equivalent code sequence into the instruction stream generated by the compiler. It enables you to convert a 32-bit big-endian data value into a little-endian data value, or a 32-bit little-endian data value into a big-endian data value from within your C or C++ code.

Note
The __rev intrinsic is available irrespective of the target processor or architecture you are compiling for. However, if the REV instruction is not available on the target, the compiler compensates with an alternative code sequence that could increase the number of instructions, effectively expanding the intrinsic into a function.
Note
The compiler introduces REV automatically when it recognizes certain expressions.

Syntax

unsigned int __rev(unsigned int val)
Where:
val
is an unsigned int.
Return value
The __rev intrinsic returns the value obtained from val by reversing its byte order.

9.132 __ror intrinsic

This intrinsic inserts a ROR instruction or operand rotation into the instruction stream generated by the compiler. It enables you to rotate a value right by a specified number of places from within your C or C++ code.

Note
The compiler introduces ROR automatically when it recognizes certain expressions.

Syntax

unsigned int __ror(unsigned int val, unsigned int shift)
Where:
val
is the value to be shifted right
shift
is a constant shift in the range 1-31.
Return value
The __ror intrinsic returns the value of val rotated right by shift number of places.
Related information

9.21 __writeonly

The __writeonly type qualifier indicates that a data object cannot be read from.

In the C and C++ type system it behaves as a cv-qualifier like const or volatile. Its specific effect is that an lvalue with __writeonly type cannot be converted to an rvalue.
Assignment to a __writeonly bitfield is not allowed if the assignment is implemented as read-modify-write. This is implementation-dependent.

Example

void foo(__writeonly int *ptr)
{
    *ptr = 0;                         // allowed
    printf("ptr value = %d\n", *ptr); // error
}

9.24 __declspec(noreturn)

Informs the compiler that the function does not return. The compiler can then perform optimizations by removing code that is never reached.

Note
This attribute has the GNU-style equivalent attribute((noreturn)).
If the function reaches an explicit or implicit return, __declspec(noreturn) is ignored and the compiler generates a warning:
Warning: #1461-D: function declared with “noreturn” does return
Usage
Use this attribute to reduce the cost of calling a function that never returns, such as exit().
Best practice is to always terminate non-returning functions with while(1);.

Example

__declspec(noreturn) void overflow(void); // called on overflow

int negate(int x) 
{
    if (x == 0x80000000) overflow();
    return -x;
}

void overflow(void)
{
    __asm {
        SVC 0x123; // hypothetical exception-throwing system service
    }
    while (1);
}

9.41 attribute((noreturn)) function attribute

Informs the compiler that the function does not return. The compiler can then perform optimizations by removing code that is never reached.

Note
This function attribute is a GNU compiler extension that the ARM compiler supports. It has the __declspec equivalent __declspec(noreturn).
If the function reaches an explicit or implicit return, attribute((noreturn)) is ignored and the compiler generates a warning:
Warning: #1461-D: function declared with “noreturn” does return
Usage
Use this attribute to reduce the cost of calling a function that never returns, such as exit().
Best practice is to always terminate non-returning functions with while(1);.

Example

void overflow(void) __attribute__((noreturn)); // called on overflow

int negate(int x) 
{
    if (x == 0x80000000) overflow();
    return -x;
}

void overflow(void)
{
    __asm {
        SVC 0x123; // hypothetical exception-throwing system service
    }
    while (1);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值