1 /**************************************************************************//**
2 * @file cmsis_armclang.h
3 * @brief CMSIS Cortex-M Core Function/Instruction Header File
5 * @date 13. September 2016
6 ******************************************************************************/
8 * Copyright (c) 2009-2016 ARM Limited. All rights reserved.
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the License); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
25 #ifndef __CMSIS_ARMCLANG_H
26 #define __CMSIS_ARMCLANG_H
28 /* CMSIS compiler specific defines */
33 #define __INLINE __inline
35 #ifndef __STATIC_INLINE
36 #define __STATIC_INLINE static __inline
39 #define __NO_RETURN __attribute__((noreturn))
42 #define __USED __attribute__((used))
45 #define __WEAK __attribute__((weak))
47 #ifndef __UNALIGNED_UINT32
48 #pragma clang diagnostic push
49 #pragma clang diagnostic ignored "-Wpacked"
50 struct __attribute__((packed)) T_UINT32 { uint32_t v; };
51 #pragma clang diagnostic pop
52 #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
55 #define __ALIGNED(x) __attribute__((aligned(x)))
58 #define __PACKED __attribute__((packed, aligned(1)))
62 /* ########################### Core Function Access ########################### */
63 /** \ingroup CMSIS_Core_FunctionInterface
64 \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
69 \brief Enable IRQ Interrupts
70 \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
71 Can only be executed in Privileged modes.
73 __attribute__((always_inline)) __STATIC_INLINE void __enable_irq(void)
75 __ASM volatile ("cpsie i" : : : "memory");
80 \brief Disable IRQ Interrupts
81 \details Disables IRQ interrupts by setting the I-bit in the CPSR.
82 Can only be executed in Privileged modes.
84 __attribute__((always_inline)) __STATIC_INLINE void __disable_irq(void)
86 __ASM volatile ("cpsid i" : : : "memory");
91 \brief Get Control Register
92 \details Returns the content of the Control Register.
93 \return Control Register value
95 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_CONTROL(void)
99 __ASM volatile ("MRS %0, control" : "=r" (result) );
104 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
106 \brief Get Control Register (non-secure)
107 \details Returns the content of the non-secure Control Register when in secure mode.
108 \return non-secure Control Register value
110 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_CONTROL_NS(void)
114 __ASM volatile ("MRS %0, control_ns" : "=r" (result) );
121 \brief Set Control Register
122 \details Writes the given value to the Control Register.
123 \param [in] control Control Register value to set
125 __attribute__((always_inline)) __STATIC_INLINE void __set_CONTROL(uint32_t control)
127 __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
131 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
133 \brief Set Control Register (non-secure)
134 \details Writes the given value to the non-secure Control Register when in secure state.
135 \param [in] control Control Register value to set
137 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_CONTROL_NS(uint32_t control)
139 __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory");
145 \brief Get IPSR Register
146 \details Returns the content of the IPSR Register.
147 \return IPSR Register value
149 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_IPSR(void)
153 __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
159 \brief Get APSR Register
160 \details Returns the content of the APSR Register.
161 \return APSR Register value
163 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_APSR(void)
167 __ASM volatile ("MRS %0, apsr" : "=r" (result) );
173 \brief Get xPSR Register
174 \details Returns the content of the xPSR Register.
175 \return xPSR Register value
177 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_xPSR(void)
181 __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
187 \brief Get Process Stack Pointer
188 \details Returns the current value of the Process Stack Pointer (PSP).
189 \return PSP Register value
191 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSP(void)
193 register uint32_t result;
195 __ASM volatile ("MRS %0, psp" : "=r" (result) );
200 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
202 \brief Get Process Stack Pointer (non-secure)
203 \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state.
204 \return PSP Register value
206 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSP_NS(void)
208 register uint32_t result;
210 __ASM volatile ("MRS %0, psp_ns" : "=r" (result) );
217 \brief Set Process Stack Pointer
218 \details Assigns the given value to the Process Stack Pointer (PSP).
219 \param [in] topOfProcStack Process Stack Pointer value to set
221 __attribute__((always_inline)) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
223 __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : "sp");
227 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
229 \brief Set Process Stack Pointer (non-secure)
230 \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state.
231 \param [in] topOfProcStack Process Stack Pointer value to set
233 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack)
235 __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : "sp");
241 \brief Get Main Stack Pointer
242 \details Returns the current value of the Main Stack Pointer (MSP).
243 \return MSP Register value
245 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSP(void)
247 register uint32_t result;
249 __ASM volatile ("MRS %0, msp" : "=r" (result) );
254 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
256 \brief Get Main Stack Pointer (non-secure)
257 \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state.
258 \return MSP Register value
260 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSP_NS(void)
262 register uint32_t result;
264 __ASM volatile ("MRS %0, msp_ns" : "=r" (result) );
271 \brief Set Main Stack Pointer
272 \details Assigns the given value to the Main Stack Pointer (MSP).
273 \param [in] topOfMainStack Main Stack Pointer value to set
275 __attribute__((always_inline)) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
277 __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : "sp");
281 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
283 \brief Set Main Stack Pointer (non-secure)
284 \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state.
285 \param [in] topOfMainStack Main Stack Pointer value to set
287 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack)
289 __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : "sp");
295 \brief Get Priority Mask
296 \details Returns the current state of the priority mask bit from the Priority Mask Register.
297 \return Priority Mask value
299 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PRIMASK(void)
303 __ASM volatile ("MRS %0, primask" : "=r" (result) );
308 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
310 \brief Get Priority Mask (non-secure)
311 \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state.
312 \return Priority Mask value
314 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PRIMASK_NS(void)
318 __ASM volatile ("MRS %0, primask_ns" : "=r" (result) );
325 \brief Set Priority Mask
326 \details Assigns the given value to the Priority Mask Register.
327 \param [in] priMask Priority Mask
329 __attribute__((always_inline)) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
331 __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
335 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
337 \brief Set Priority Mask (non-secure)
338 \details Assigns the given value to the non-secure Priority Mask Register when in secure state.
339 \param [in] priMask Priority Mask
341 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PRIMASK_NS(uint32_t priMask)
343 __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory");
348 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
349 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
350 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
353 \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
354 Can only be executed in Privileged modes.
356 __attribute__((always_inline)) __STATIC_INLINE void __enable_fault_irq(void)
358 __ASM volatile ("cpsie f" : : : "memory");
364 \details Disables FIQ interrupts by setting the F-bit in the CPSR.
365 Can only be executed in Privileged modes.
367 __attribute__((always_inline)) __STATIC_INLINE void __disable_fault_irq(void)
369 __ASM volatile ("cpsid f" : : : "memory");
374 \brief Get Base Priority
375 \details Returns the current value of the Base Priority register.
376 \return Base Priority register value
378 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_BASEPRI(void)
382 __ASM volatile ("MRS %0, basepri" : "=r" (result) );
387 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
389 \brief Get Base Priority (non-secure)
390 \details Returns the current value of the non-secure Base Priority register when in secure state.
391 \return Base Priority register value
393 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_BASEPRI_NS(void)
397 __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) );
404 \brief Set Base Priority
405 \details Assigns the given value to the Base Priority register.
406 \param [in] basePri Base Priority value to set
408 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
410 __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory");
414 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
416 \brief Set Base Priority (non-secure)
417 \details Assigns the given value to the non-secure Base Priority register when in secure state.
418 \param [in] basePri Base Priority value to set
420 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_BASEPRI_NS(uint32_t basePri)
422 __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory");
428 \brief Set Base Priority with condition
429 \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
430 or the new value increases the BASEPRI priority level.
431 \param [in] basePri Base Priority value to set
433 __attribute__((always_inline)) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
435 __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory");
440 \brief Get Fault Mask
441 \details Returns the current value of the Fault Mask register.
442 \return Fault Mask register value
444 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
448 __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
453 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
455 \brief Get Fault Mask (non-secure)
456 \details Returns the current value of the non-secure Fault Mask register when in secure state.
457 \return Fault Mask register value
459 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_FAULTMASK_NS(void)
463 __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) );
470 \brief Set Fault Mask
471 \details Assigns the given value to the Fault Mask register.
472 \param [in] faultMask Fault Mask value to set
474 __attribute__((always_inline)) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
476 __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
480 #if (defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3))
482 \brief Set Fault Mask (non-secure)
483 \details Assigns the given value to the non-secure Fault Mask register when in secure state.
484 \param [in] faultMask Fault Mask value to set
486 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask)
488 __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory");
492 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
493 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
494 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
497 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
498 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
501 \brief Get Process Stack Pointer Limit
502 \details Returns the current value of the Process Stack Pointer Limit (PSPLIM).
503 \return PSPLIM Register value
505 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PSPLIM(void)
507 register uint32_t result;
509 __ASM volatile ("MRS %0, psplim" : "=r" (result) );
514 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
515 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
517 \brief Get Process Stack Pointer Limit (non-secure)
518 \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
519 \return PSPLIM Register value
521 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_PSPLIM_NS(void)
523 register uint32_t result;
525 __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) );
532 \brief Set Process Stack Pointer Limit
533 \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM).
534 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
536 __attribute__((always_inline)) __STATIC_INLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit)
538 __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit));
542 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
543 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
545 \brief Set Process Stack Pointer (non-secure)
546 \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state.
547 \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set
549 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit)
551 __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit));
557 \brief Get Main Stack Pointer Limit
558 \details Returns the current value of the Main Stack Pointer Limit (MSPLIM).
559 \return MSPLIM Register value
561 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_MSPLIM(void)
563 register uint32_t result;
565 __ASM volatile ("MRS %0, msplim" : "=r" (result) );
571 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
572 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
574 \brief Get Main Stack Pointer Limit (non-secure)
575 \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state.
576 \return MSPLIM Register value
578 __attribute__((always_inline)) __STATIC_INLINE uint32_t __TZ_get_MSPLIM_NS(void)
580 register uint32_t result;
582 __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) );
589 \brief Set Main Stack Pointer Limit
590 \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM).
591 \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set
593 __attribute__((always_inline)) __STATIC_INLINE void __set_MSPLIM(uint32_t MainStackPtrLimit)
595 __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit));
599 #if ((defined (__ARM_FEATURE_CMSE ) && (__ARM_FEATURE_CMSE == 3)) && \
600 (defined (__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) )
602 \brief Set Main Stack Pointer Limit (non-secure)
603 \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state.
604 \param [in] MainStackPtrLimit Main Stack Pointer value to set
606 __attribute__((always_inline)) __STATIC_INLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit)
608 __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit));
612 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
613 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
616 #if ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
617 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
621 \details Returns the current value of the Floating Point Status/Control register.
622 \return Floating Point Status/Control register value
624 /* #define __get_FPSCR __builtin_arm_get_fpscr */
625 __attribute__((always_inline)) __STATIC_INLINE uint32_t __get_FPSCR(void)
627 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
628 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
631 __ASM volatile (""); /* Empty asm statement works as a scheduling barrier */
632 __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
643 \details Assigns the given value to the Floating Point Status/Control register.
644 \param [in] fpscr Floating Point Status/Control value to set
646 /* #define __set_FPSCR __builtin_arm_set_fpscr */
647 __attribute__((always_inline)) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
649 #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
650 (defined (__FPU_USED ) && (__FPU_USED == 1U)) )
651 __ASM volatile (""); /* Empty asm statement works as a scheduling barrier */
652 /* __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc"); */
653 __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) :);
658 #endif /* ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
659 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) */
663 /*@} end of CMSIS_Core_RegAccFunctions */
666 /* ########################## Core Instruction Access ######################### */
667 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
668 Access to dedicated instructions
672 /* Define macros for porting to both thumb1 and thumb2.
673 * For thumb1, use low register (r0-r7), specified by constraint "l"
674 * Otherwise, use general registers, specified by constraint "r" */
675 #if defined (__thumb__) && !defined (__thumb2__)
676 #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
677 #define __CMSIS_GCC_USE_REG(r) "l" (r)
679 #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
680 #define __CMSIS_GCC_USE_REG(r) "r" (r)
685 \details No Operation does nothing. This instruction can be used for code alignment purposes.
687 #define __NOP __builtin_arm_nop
690 \brief Wait For Interrupt
691 \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
693 #define __WFI __builtin_arm_wfi
697 \brief Wait For Event
698 \details Wait For Event is a hint instruction that permits the processor to enter
699 a low-power state until one of a number of events occurs.
701 #define __WFE __builtin_arm_wfe
706 \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
708 #define __SEV __builtin_arm_sev
712 \brief Instruction Synchronization Barrier
713 \details Instruction Synchronization Barrier flushes the pipeline in the processor,
714 so that all instructions following the ISB are fetched from cache or memory,
715 after the instruction has been completed.
717 #define __ISB() __builtin_arm_isb(0xF);
720 \brief Data Synchronization Barrier
721 \details Acts as a special kind of Data Memory Barrier.
722 It completes when all explicit memory accesses before this instruction complete.
724 #define __DSB() __builtin_arm_dsb(0xF);
728 \brief Data Memory Barrier
729 \details Ensures the apparent order of the explicit memory operations before
730 and after the instruction, without ensuring their completion.
732 #define __DMB() __builtin_arm_dmb(0xF);
736 \brief Reverse byte order (32 bit)
737 \details Reverses the byte order in integer value.
738 \param [in] value Value to reverse
739 \return Reversed value
741 #define __REV __builtin_bswap32
745 \brief Reverse byte order (16 bit)
746 \details Reverses the byte order in two unsigned short values.
747 \param [in] value Value to reverse
748 \return Reversed value
750 #define __REV16 __builtin_bswap16 /* ToDo ARMCLANG: check if __builtin_bswap16 could be used */
752 __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value)
756 __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
763 \brief Reverse byte order in signed short value
764 \details Reverses the byte order in a signed short value with sign extension to integer.
765 \param [in] value Value to reverse
766 \return Reversed value
768 /* ToDo ARMCLANG: check if __builtin_bswap16 could be used */
769 __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
773 __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
779 \brief Rotate Right in unsigned value (32 bit)
780 \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
781 \param [in] op1 Value to rotate
782 \param [in] op2 Number of Bits to rotate
783 \return Rotated value
785 __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
787 return (op1 >> op2) | (op1 << (32U - op2));
793 \details Causes the processor to enter Debug state.
794 Debug tools can use this to investigate system state when the instruction at a particular address is reached.
795 \param [in] value is ignored by the processor.
796 If required, a debugger can use it to store additional information about the breakpoint.
798 #define __BKPT(value) __ASM volatile ("bkpt "#value)
802 \brief Reverse bit order of value
803 \details Reverses the bit order of the given value.
804 \param [in] value Value to reverse
805 \return Reversed value
807 /* ToDo ARMCLANG: check if __builtin_arm_rbit is supported */
808 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
812 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
813 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
814 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) )
815 __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
817 int32_t s = (4 /*sizeof(v)*/ * 8) - 1; /* extra shift needed at end */
819 result = value; /* r will be reversed bits of v; first get LSB of v */
820 for (value >>= 1U; value; value >>= 1U)
823 result |= value & 1U;
826 result <<= s; /* shift when v's highest bits are zero */
833 \brief Count leading zeros
834 \details Counts the number of leading zeros of a data value.
835 \param [in] value Value to count the leading zeros
836 \return number of leading zeros in value
838 #define __CLZ __builtin_clz
841 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
842 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
843 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
844 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
846 \brief LDR Exclusive (8 bit)
847 \details Executes a exclusive LDR instruction for 8 bit value.
848 \param [in] ptr Pointer to data
849 \return value of type uint8_t at (*ptr)
851 #define __LDREXB (uint8_t)__builtin_arm_ldrex
855 \brief LDR Exclusive (16 bit)
856 \details Executes a exclusive LDR instruction for 16 bit values.
857 \param [in] ptr Pointer to data
858 \return value of type uint16_t at (*ptr)
860 #define __LDREXH (uint16_t)__builtin_arm_ldrex
864 \brief LDR Exclusive (32 bit)
865 \details Executes a exclusive LDR instruction for 32 bit values.
866 \param [in] ptr Pointer to data
867 \return value of type uint32_t at (*ptr)
869 #define __LDREXW (uint32_t)__builtin_arm_ldrex
873 \brief STR Exclusive (8 bit)
874 \details Executes a exclusive STR instruction for 8 bit values.
875 \param [in] value Value to store
876 \param [in] ptr Pointer to location
877 \return 0 Function succeeded
878 \return 1 Function failed
880 #define __STREXB (uint32_t)__builtin_arm_strex
884 \brief STR Exclusive (16 bit)
885 \details Executes a exclusive STR instruction for 16 bit values.
886 \param [in] value Value to store
887 \param [in] ptr Pointer to location
888 \return 0 Function succeeded
889 \return 1 Function failed
891 #define __STREXH (uint32_t)__builtin_arm_strex
895 \brief STR Exclusive (32 bit)
896 \details Executes a exclusive STR instruction for 32 bit values.
897 \param [in] value Value to store
898 \param [in] ptr Pointer to location
899 \return 0 Function succeeded
900 \return 1 Function failed
902 #define __STREXW (uint32_t)__builtin_arm_strex
906 \brief Remove the exclusive lock
907 \details Removes the exclusive lock which is created by LDREX.
909 #define __CLREX __builtin_arm_clrex
913 \brief Signed Saturate
914 \details Saturates a signed value.
915 \param [in] value Value to be saturated
916 \param [in] sat Bit position to saturate to (1..32)
917 \return Saturated value
919 /* #define __SSAT __builtin_arm_ssat */
920 #define __SSAT(ARG1,ARG2) \
922 int32_t __RES, __ARG1 = (ARG1); \
923 __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
929 \brief Unsigned Saturate
930 \details Saturates an unsigned value.
931 \param [in] value Value to be saturated
932 \param [in] sat Bit position to saturate to (0..31)
933 \return Saturated value
935 #define __USAT __builtin_arm_usat
937 #define __USAT(ARG1,ARG2) \
939 uint32_t __RES, __ARG1 = (ARG1); \
940 __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
947 \brief Rotate Right with Extend (32 bit)
948 \details Moves each bit of a bitstring right by one bit.
949 The carry input is shifted in at the left end of the bitstring.
950 \param [in] value Value to rotate
951 \return Rotated value
953 __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
957 __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
963 \brief LDRT Unprivileged (8 bit)
964 \details Executes a Unprivileged LDRT instruction for 8 bit value.
965 \param [in] ptr Pointer to data
966 \return value of type uint8_t at (*ptr)
968 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *ptr)
972 __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) );
973 return ((uint8_t) result); /* Add explicit type cast here */
978 \brief LDRT Unprivileged (16 bit)
979 \details Executes a Unprivileged LDRT instruction for 16 bit values.
980 \param [in] ptr Pointer to data
981 \return value of type uint16_t at (*ptr)
983 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *ptr)
987 __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) );
988 return ((uint16_t) result); /* Add explicit type cast here */
993 \brief LDRT Unprivileged (32 bit)
994 \details Executes a Unprivileged LDRT instruction for 32 bit values.
995 \param [in] ptr Pointer to data
996 \return value of type uint32_t at (*ptr)
998 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *ptr)
1002 __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) );
1008 \brief STRT Unprivileged (8 bit)
1009 \details Executes a Unprivileged STRT instruction for 8 bit values.
1010 \param [in] value Value to store
1011 \param [in] ptr Pointer to location
1013 __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *ptr)
1015 __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1020 \brief STRT Unprivileged (16 bit)
1021 \details Executes a Unprivileged STRT instruction for 16 bit values.
1022 \param [in] value Value to store
1023 \param [in] ptr Pointer to location
1025 __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *ptr)
1027 __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1032 \brief STRT Unprivileged (32 bit)
1033 \details Executes a Unprivileged STRT instruction for 32 bit values.
1034 \param [in] value Value to store
1035 \param [in] ptr Pointer to location
1037 __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *ptr)
1039 __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) );
1042 #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
1043 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
1044 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1045 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1048 #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1049 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
1051 \brief Load-Acquire (8 bit)
1052 \details Executes a LDAB instruction for 8 bit value.
1053 \param [in] ptr Pointer to data
1054 \return value of type uint8_t at (*ptr)
1056 __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDAB(volatile uint8_t *ptr)
1060 __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) );
1061 return ((uint8_t) result);
1066 \brief Load-Acquire (16 bit)
1067 \details Executes a LDAH instruction for 16 bit values.
1068 \param [in] ptr Pointer to data
1069 \return value of type uint16_t at (*ptr)
1071 __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDAH(volatile uint16_t *ptr)
1075 __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) );
1076 return ((uint16_t) result);
1081 \brief Load-Acquire (32 bit)
1082 \details Executes a LDA instruction for 32 bit values.
1083 \param [in] ptr Pointer to data
1084 \return value of type uint32_t at (*ptr)
1086 __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDA(volatile uint32_t *ptr)
1090 __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) );
1096 \brief Store-Release (8 bit)
1097 \details Executes a STLB instruction for 8 bit values.
1098 \param [in] value Value to store
1099 \param [in] ptr Pointer to location
1101 __attribute__((always_inline)) __STATIC_INLINE void __STLB(uint8_t value, volatile uint8_t *ptr)
1103 __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1108 \brief Store-Release (16 bit)
1109 \details Executes a STLH instruction for 16 bit values.
1110 \param [in] value Value to store
1111 \param [in] ptr Pointer to location
1113 __attribute__((always_inline)) __STATIC_INLINE void __STLH(uint16_t value, volatile uint16_t *ptr)
1115 __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1120 \brief Store-Release (32 bit)
1121 \details Executes a STL instruction for 32 bit values.
1122 \param [in] value Value to store
1123 \param [in] ptr Pointer to location
1125 __attribute__((always_inline)) __STATIC_INLINE void __STL(uint32_t value, volatile uint32_t *ptr)
1127 __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) );
1132 \brief Load-Acquire Exclusive (8 bit)
1133 \details Executes a LDAB exclusive instruction for 8 bit value.
1134 \param [in] ptr Pointer to data
1135 \return value of type uint8_t at (*ptr)
1137 #define __LDAEXB (uint8_t)__builtin_arm_ldaex
1141 \brief Load-Acquire Exclusive (16 bit)
1142 \details Executes a LDAH exclusive instruction for 16 bit values.
1143 \param [in] ptr Pointer to data
1144 \return value of type uint16_t at (*ptr)
1146 #define __LDAEXH (uint16_t)__builtin_arm_ldaex
1150 \brief Load-Acquire Exclusive (32 bit)
1151 \details Executes a LDA exclusive instruction for 32 bit values.
1152 \param [in] ptr Pointer to data
1153 \return value of type uint32_t at (*ptr)
1155 #define __LDAEX (uint32_t)__builtin_arm_ldaex
1159 \brief Store-Release Exclusive (8 bit)
1160 \details Executes a STLB exclusive instruction for 8 bit values.
1161 \param [in] value Value to store
1162 \param [in] ptr Pointer to location
1163 \return 0 Function succeeded
1164 \return 1 Function failed
1166 #define __STLEXB (uint32_t)__builtin_arm_stlex
1170 \brief Store-Release Exclusive (16 bit)
1171 \details Executes a STLH exclusive instruction for 16 bit values.
1172 \param [in] value Value to store
1173 \param [in] ptr Pointer to location
1174 \return 0 Function succeeded
1175 \return 1 Function failed
1177 #define __STLEXH (uint32_t)__builtin_arm_stlex
1181 \brief Store-Release Exclusive (32 bit)
1182 \details Executes a STL exclusive instruction for 32 bit values.
1183 \param [in] value Value to store
1184 \param [in] ptr Pointer to location
1185 \return 0 Function succeeded
1186 \return 1 Function failed
1188 #define __STLEX (uint32_t)__builtin_arm_stlex
1190 #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
1191 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) */
1193 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
1196 /* ################### Compiler specific Intrinsics ########################### */
1197 /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
1198 Access to dedicated SIMD instructions
1202 #if (__ARM_FEATURE_DSP == 1) /* ToDo ARMCLANG: This should be ARCH >= ARMv7-M + SIMD */
1204 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
1208 __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1212 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
1216 __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1220 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
1224 __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1228 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
1232 __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1236 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
1240 __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1244 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
1248 __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1253 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
1257 __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1261 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
1265 __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1269 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
1273 __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1277 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
1281 __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1285 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
1289 __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1293 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
1297 __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1302 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
1306 __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1310 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
1314 __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1318 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
1322 __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1326 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
1330 __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1334 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
1338 __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1342 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
1346 __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1350 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
1354 __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1358 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
1362 __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1366 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
1370 __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1374 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
1378 __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1382 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
1386 __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1390 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
1394 __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1398 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
1402 __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1406 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
1410 __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1414 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
1418 __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1422 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
1426 __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1430 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
1434 __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1438 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
1442 __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1446 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
1450 __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1454 __attribute__((always_inline)) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
1458 __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1462 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
1466 __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1470 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
1474 __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1478 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
1482 __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1486 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
1490 __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1494 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
1498 __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1502 __attribute__((always_inline)) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
1506 __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1510 #define __SSAT16(ARG1,ARG2) \
1512 int32_t __RES, __ARG1 = (ARG1); \
1513 __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1517 #define __USAT16(ARG1,ARG2) \
1519 uint32_t __RES, __ARG1 = (ARG1); \
1520 __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
1524 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
1528 __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
1532 __attribute__((always_inline)) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
1536 __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1540 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
1544 __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
1548 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
1552 __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1556 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
1560 __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1564 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
1568 __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1572 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
1576 __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1580 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
1584 __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1588 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
1596 #ifndef __ARMEB__ /* Little endian */
1597 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1598 #else /* Big endian */
1599 __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1605 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
1613 #ifndef __ARMEB__ /* Little endian */
1614 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1615 #else /* Big endian */
1616 __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1622 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
1626 __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1630 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
1634 __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1638 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
1642 __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1646 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
1650 __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
1654 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
1662 #ifndef __ARMEB__ /* Little endian */
1663 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1664 #else /* Big endian */
1665 __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1671 __attribute__((always_inline)) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
1679 #ifndef __ARMEB__ /* Little endian */
1680 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) );
1681 #else /* Big endian */
1682 __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) );
1688 __attribute__((always_inline)) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
1692 __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1696 __attribute__((always_inline)) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2)
1700 __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1704 __attribute__((always_inline)) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2)
1708 __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
1713 #define __PKHBT(ARG1,ARG2,ARG3) \
1715 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1716 __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1720 #define __PKHTB(ARG1,ARG2,ARG3) \
1722 uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
1724 __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
1726 __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
1731 #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
1732 ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
1734 #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
1735 ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
1737 __attribute__((always_inline)) __STATIC_INLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
1741 __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
1745 #endif /* (__ARM_FEATURE_DSP == 1) */
1746 /*@} end of group CMSIS_SIMD_intrinsics */
1749 #endif /* __CMSIS_ARMCLANG_H */