Cortex-M KEIL特殊用法
2016-08-20 03:34
246 查看
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); }
相关文章推荐
- CONNECT BY(ROWNUM|LEVEL) 特殊用法解释(试着解释)
- shell中$0,$?,$!等的特殊用法
- javascript中 "||", "&&" 特殊用法
- java手记---break,continu的特殊用法
- XPath学习笔记---2(特殊用法)
- #define的特殊用法
- shell中括号的特殊用法
- Javascript 特殊用法
- 68.if逻辑判断以及判断文件目录属性 if特殊用法 case判断
- 20.5 shell脚本中的逻辑判断 20.6 文件目录属性判断 20.7 if特殊用法 20.8/20.9 case判断
- Shell 特殊用法续
- scanf的特殊用法 const用法、数值型数-字符串转换、可变长参数
- bgsound 背景音乐 的一些常用方法及特殊用法小结
- Flash学习笔记--特殊用法
- android 特殊用法琐碎(转)
- [Groovy] *符号在Groovy里的一种特殊用法
- Oracle行级锁的特殊用法简析
- css中伪元素before或after中content的特殊用法attr
- android 特殊用法一
- 转:DataTable的一些特殊用法:Select