cmsis_gcc.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. /**************************************************************************//**
  2. * @file cmsis_gcc.h
  3. * @brief CMSIS Cortex-M Core Function/Instruction Header File
  4. * @version V4.30
  5. * @date 20. October 2015
  6. ******************************************************************************/
  7. /* Copyright (c) 2009 - 2015 ARM LIMITED
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. - Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. - Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. - Neither the name of ARM nor the names of its contributors may be used
  17. to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. *
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. ---------------------------------------------------------------------------*/
  32. #ifndef __CMSIS_GCC_H
  33. #define __CMSIS_GCC_H
  34. /* ignore some GCC warnings */
  35. #if defined ( __GNUC__ )
  36. #pragma GCC diagnostic push
  37. #pragma GCC diagnostic ignored "-Wsign-conversion"
  38. #pragma GCC diagnostic ignored "-Wconversion"
  39. #pragma GCC diagnostic ignored "-Wunused-parameter"
  40. #endif
  41. /* ########################### Core Function Access ########################### */
  42. /** \ingroup CMSIS_Core_FunctionInterface
  43. \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
  44. @{
  45. */
  46. /**
  47. \brief Enable IRQ Interrupts
  48. \details Enables IRQ interrupts by clearing the I-bit in the CPSR.
  49. Can only be executed in Privileged modes.
  50. */
  51. __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void)
  52. {
  53. __ASM volatile ("cpsie i" : : : "memory");
  54. }
  55. /**
  56. \brief Disable IRQ Interrupts
  57. \details Disables IRQ interrupts by setting the I-bit in the CPSR.
  58. Can only be executed in Privileged modes.
  59. */
  60. __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void)
  61. {
  62. __ASM volatile ("cpsid i" : : : "memory");
  63. }
  64. /**
  65. \brief Get Control Register
  66. \details Returns the content of the Control Register.
  67. \return Control Register value
  68. */
  69. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void)
  70. {
  71. uint32_t result;
  72. __ASM volatile ("MRS %0, control" : "=r" (result) );
  73. return(result);
  74. }
  75. /**
  76. \brief Set Control Register
  77. \details Writes the given value to the Control Register.
  78. \param [in] control Control Register value to set
  79. */
  80. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control)
  81. {
  82. __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
  83. }
  84. /**
  85. \brief Get IPSR Register
  86. \details Returns the content of the IPSR Register.
  87. \return IPSR Register value
  88. */
  89. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void)
  90. {
  91. uint32_t result;
  92. __ASM volatile ("MRS %0, ipsr" : "=r" (result) );
  93. return(result);
  94. }
  95. /**
  96. \brief Get APSR Register
  97. \details Returns the content of the APSR Register.
  98. \return APSR Register value
  99. */
  100. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void)
  101. {
  102. uint32_t result;
  103. __ASM volatile ("MRS %0, apsr" : "=r" (result) );
  104. return(result);
  105. }
  106. /**
  107. \brief Get xPSR Register
  108. \details Returns the content of the xPSR Register.
  109. \return xPSR Register value
  110. */
  111. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void)
  112. {
  113. uint32_t result;
  114. __ASM volatile ("MRS %0, xpsr" : "=r" (result) );
  115. return(result);
  116. }
  117. /**
  118. \brief Get Process Stack Pointer
  119. \details Returns the current value of the Process Stack Pointer (PSP).
  120. \return PSP Register value
  121. */
  122. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void)
  123. {
  124. register uint32_t result;
  125. __ASM volatile ("MRS %0, psp\n" : "=r" (result) );
  126. return(result);
  127. }
  128. /**
  129. \brief Set Process Stack Pointer
  130. \details Assigns the given value to the Process Stack Pointer (PSP).
  131. \param [in] topOfProcStack Process Stack Pointer value to set
  132. */
  133. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
  134. {
  135. __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
  136. }
  137. /**
  138. \brief Get Main Stack Pointer
  139. \details Returns the current value of the Main Stack Pointer (MSP).
  140. \return MSP Register value
  141. */
  142. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
  143. {
  144. register uint32_t result;
  145. __ASM volatile ("MRS %0, msp\n" : "=r" (result) );
  146. return(result);
  147. }
  148. /**
  149. \brief Set Main Stack Pointer
  150. \details Assigns the given value to the Main Stack Pointer (MSP).
  151. \param [in] topOfMainStack Main Stack Pointer value to set
  152. */
  153. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
  154. {
  155. __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
  156. }
  157. /**
  158. \brief Get Priority Mask
  159. \details Returns the current state of the priority mask bit from the Priority Mask Register.
  160. \return Priority Mask value
  161. */
  162. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void)
  163. {
  164. uint32_t result;
  165. __ASM volatile ("MRS %0, primask" : "=r" (result) );
  166. return(result);
  167. }
  168. /**
  169. \brief Set Priority Mask
  170. \details Assigns the given value to the Priority Mask Register.
  171. \param [in] priMask Priority Mask
  172. */
  173. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
  174. {
  175. __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory");
  176. }
  177. #if (__CORTEX_M >= 0x03U)
  178. /**
  179. \brief Enable FIQ
  180. \details Enables FIQ interrupts by clearing the F-bit in the CPSR.
  181. Can only be executed in Privileged modes.
  182. */
  183. __attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void)
  184. {
  185. __ASM volatile ("cpsie f" : : : "memory");
  186. }
  187. /**
  188. \brief Disable FIQ
  189. \details Disables FIQ interrupts by setting the F-bit in the CPSR.
  190. Can only be executed in Privileged modes.
  191. */
  192. __attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void)
  193. {
  194. __ASM volatile ("cpsid f" : : : "memory");
  195. }
  196. /**
  197. \brief Get Base Priority
  198. \details Returns the current value of the Base Priority register.
  199. \return Base Priority register value
  200. */
  201. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void)
  202. {
  203. uint32_t result;
  204. __ASM volatile ("MRS %0, basepri" : "=r" (result) );
  205. return(result);
  206. }
  207. /**
  208. \brief Set Base Priority
  209. \details Assigns the given value to the Base Priority register.
  210. \param [in] basePri Base Priority value to set
  211. */
  212. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value)
  213. {
  214. __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory");
  215. }
  216. /**
  217. \brief Set Base Priority with condition
  218. \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
  219. or the new value increases the BASEPRI priority level.
  220. \param [in] basePri Base Priority value to set
  221. */
  222. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value)
  223. {
  224. __ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory");
  225. }
  226. /**
  227. \brief Get Fault Mask
  228. \details Returns the current value of the Fault Mask register.
  229. \return Fault Mask register value
  230. */
  231. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void)
  232. {
  233. uint32_t result;
  234. __ASM volatile ("MRS %0, faultmask" : "=r" (result) );
  235. return(result);
  236. }
  237. /**
  238. \brief Set Fault Mask
  239. \details Assigns the given value to the Fault Mask register.
  240. \param [in] faultMask Fault Mask value to set
  241. */
  242. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
  243. {
  244. __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory");
  245. }
  246. #endif /* (__CORTEX_M >= 0x03U) */
  247. #if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U)
  248. /**
  249. \brief Get FPSCR
  250. \details Returns the current value of the Floating Point Status/Control register.
  251. \return Floating Point Status/Control register value
  252. */
  253. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void)
  254. {
  255. #if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
  256. uint32_t result;
  257. /* Empty asm statement works as a scheduling barrier */
  258. __ASM volatile ("");
  259. __ASM volatile ("VMRS %0, fpscr" : "=r" (result) );
  260. __ASM volatile ("");
  261. return(result);
  262. #else
  263. return(0);
  264. #endif
  265. }
  266. /**
  267. \brief Set FPSCR
  268. \details Assigns the given value to the Floating Point Status/Control register.
  269. \param [in] fpscr Floating Point Status/Control value to set
  270. */
  271. __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
  272. {
  273. #if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
  274. /* Empty asm statement works as a scheduling barrier */
  275. __ASM volatile ("");
  276. __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc");
  277. __ASM volatile ("");
  278. #endif
  279. }
  280. #endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */
  281. /*@} end of CMSIS_Core_RegAccFunctions */
  282. /* ########################## Core Instruction Access ######################### */
  283. /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
  284. Access to dedicated instructions
  285. @{
  286. */
  287. /* Define macros for porting to both thumb1 and thumb2.
  288. * For thumb1, use low register (r0-r7), specified by constraint "l"
  289. * Otherwise, use general registers, specified by constraint "r" */
  290. #if defined (__thumb__) && !defined (__thumb2__)
  291. #define __CMSIS_GCC_OUT_REG(r) "=l" (r)
  292. #define __CMSIS_GCC_USE_REG(r) "l" (r)
  293. #else
  294. #define __CMSIS_GCC_OUT_REG(r) "=r" (r)
  295. #define __CMSIS_GCC_USE_REG(r) "r" (r)
  296. #endif
  297. /**
  298. \brief No Operation
  299. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  300. */
  301. __attribute__((always_inline)) __STATIC_INLINE void __NOP(void)
  302. {
  303. __ASM volatile ("nop");
  304. }
  305. /**
  306. \brief Wait For Interrupt
  307. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  308. */
  309. __attribute__((always_inline)) __STATIC_INLINE void __WFI(void)
  310. {
  311. __ASM volatile ("wfi");
  312. }
  313. /**
  314. \brief Wait For Event
  315. \details Wait For Event is a hint instruction that permits the processor to enter
  316. a low-power state until one of a number of events occurs.
  317. */
  318. __attribute__((always_inline)) __STATIC_INLINE void __WFE(void)
  319. {
  320. __ASM volatile ("wfe");
  321. }
  322. /**
  323. \brief Send Event
  324. \details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
  325. */
  326. __attribute__((always_inline)) __STATIC_INLINE void __SEV(void)
  327. {
  328. __ASM volatile ("sev");
  329. }
  330. /**
  331. \brief Instruction Synchronization Barrier
  332. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  333. so that all instructions following the ISB are fetched from cache or memory,
  334. after the instruction has been completed.
  335. */
  336. __attribute__((always_inline)) __STATIC_INLINE void __ISB(void)
  337. {
  338. __ASM volatile ("isb 0xF":::"memory");
  339. }
  340. /**
  341. \brief Data Synchronization Barrier
  342. \details Acts as a special kind of Data Memory Barrier.
  343. It completes when all explicit memory accesses before this instruction complete.
  344. */
  345. __attribute__((always_inline)) __STATIC_INLINE void __DSB(void)
  346. {
  347. __ASM volatile ("dsb 0xF":::"memory");
  348. }
  349. /**
  350. \brief Data Memory Barrier
  351. \details Ensures the apparent order of the explicit memory operations before
  352. and after the instruction, without ensuring their completion.
  353. */
  354. __attribute__((always_inline)) __STATIC_INLINE void __DMB(void)
  355. {
  356. __ASM volatile ("dmb 0xF":::"memory");
  357. }
  358. /**
  359. \brief Reverse byte order (32 bit)
  360. \details Reverses the byte order in integer value.
  361. \param [in] value Value to reverse
  362. \return Reversed value
  363. */
  364. __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value)
  365. {
  366. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
  367. return __builtin_bswap32(value);
  368. #else
  369. uint32_t result;
  370. __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
  371. return(result);
  372. #endif
  373. }
  374. /**
  375. \brief Reverse byte order (16 bit)
  376. \details Reverses the byte order in two unsigned short values.
  377. \param [in] value Value to reverse
  378. \return Reversed value
  379. */
  380. __attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value)
  381. {
  382. uint32_t result;
  383. __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
  384. return(result);
  385. }
  386. /**
  387. \brief Reverse byte order in signed short value
  388. \details Reverses the byte order in a signed short value with sign extension to integer.
  389. \param [in] value Value to reverse
  390. \return Reversed value
  391. */
  392. __attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value)
  393. {
  394. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  395. return (short)__builtin_bswap16(value);
  396. #else
  397. int32_t result;
  398. __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
  399. return(result);
  400. #endif
  401. }
  402. /**
  403. \brief Rotate Right in unsigned value (32 bit)
  404. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  405. \param [in] value Value to rotate
  406. \param [in] value Number of Bits to rotate
  407. \return Rotated value
  408. */
  409. __attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  410. {
  411. return (op1 >> op2) | (op1 << (32U - op2));
  412. }
  413. /**
  414. \brief Breakpoint
  415. \details Causes the processor to enter Debug state.
  416. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  417. \param [in] value is ignored by the processor.
  418. If required, a debugger can use it to store additional information about the breakpoint.
  419. */
  420. #define __BKPT(value) __ASM volatile ("bkpt "#value)
  421. /**
  422. \brief Reverse bit order of value
  423. \details Reverses the bit order of the given value.
  424. \param [in] value Value to reverse
  425. \return Reversed value
  426. */
  427. __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
  428. {
  429. uint32_t result;
  430. #if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
  431. __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
  432. #else
  433. int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
  434. result = value; /* r will be reversed bits of v; first get LSB of v */
  435. for (value >>= 1U; value; value >>= 1U)
  436. {
  437. result <<= 1U;
  438. result |= value & 1U;
  439. s--;
  440. }
  441. result <<= s; /* shift when v's highest bits are zero */
  442. #endif
  443. return(result);
  444. }
  445. /**
  446. \brief Count leading zeros
  447. \details Counts the number of leading zeros of a data value.
  448. \param [in] value Value to count the leading zeros
  449. \return number of leading zeros in value
  450. */
  451. #define __CLZ __builtin_clz
  452. #if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
  453. /**
  454. \brief LDR Exclusive (8 bit)
  455. \details Executes a exclusive LDR instruction for 8 bit value.
  456. \param [in] ptr Pointer to data
  457. \return value of type uint8_t at (*ptr)
  458. */
  459. __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)
  460. {
  461. uint32_t result;
  462. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  463. __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) );
  464. #else
  465. /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
  466. accepted by assembler. So has to use following less efficient pattern.
  467. */
  468. __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
  469. #endif
  470. return ((uint8_t) result); /* Add explicit type cast here */
  471. }
  472. /**
  473. \brief LDR Exclusive (16 bit)
  474. \details Executes a exclusive LDR instruction for 16 bit values.
  475. \param [in] ptr Pointer to data
  476. \return value of type uint16_t at (*ptr)
  477. */
  478. __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)
  479. {
  480. uint32_t result;
  481. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  482. __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) );
  483. #else
  484. /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
  485. accepted by assembler. So has to use following less efficient pattern.
  486. */
  487. __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
  488. #endif
  489. return ((uint16_t) result); /* Add explicit type cast here */
  490. }
  491. /**
  492. \brief LDR Exclusive (32 bit)
  493. \details Executes a exclusive LDR instruction for 32 bit values.
  494. \param [in] ptr Pointer to data
  495. \return value of type uint32_t at (*ptr)
  496. */
  497. __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)
  498. {
  499. uint32_t result;
  500. __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) );
  501. return(result);
  502. }
  503. /**
  504. \brief STR Exclusive (8 bit)
  505. \details Executes a exclusive STR instruction for 8 bit values.
  506. \param [in] value Value to store
  507. \param [in] ptr Pointer to location
  508. \return 0 Function succeeded
  509. \return 1 Function failed
  510. */
  511. __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
  512. {
  513. uint32_t result;
  514. __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
  515. return(result);
  516. }
  517. /**
  518. \brief STR Exclusive (16 bit)
  519. \details Executes a exclusive STR instruction for 16 bit values.
  520. \param [in] value Value to store
  521. \param [in] ptr Pointer to location
  522. \return 0 Function succeeded
  523. \return 1 Function failed
  524. */
  525. __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
  526. {
  527. uint32_t result;
  528. __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) );
  529. return(result);
  530. }
  531. /**
  532. \brief STR Exclusive (32 bit)
  533. \details Executes a exclusive STR instruction for 32 bit values.
  534. \param [in] value Value to store
  535. \param [in] ptr Pointer to location
  536. \return 0 Function succeeded
  537. \return 1 Function failed
  538. */
  539. __attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
  540. {
  541. uint32_t result;
  542. __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) );
  543. return(result);
  544. }
  545. /**
  546. \brief Remove the exclusive lock
  547. \details Removes the exclusive lock which is created by LDREX.
  548. */
  549. __attribute__((always_inline)) __STATIC_INLINE void __CLREX(void)
  550. {
  551. __ASM volatile ("clrex" ::: "memory");
  552. }
  553. /**
  554. \brief Signed Saturate
  555. \details Saturates a signed value.
  556. \param [in] value Value to be saturated
  557. \param [in] sat Bit position to saturate to (1..32)
  558. \return Saturated value
  559. */
  560. #define __SSAT(ARG1,ARG2) \
  561. ({ \
  562. uint32_t __RES, __ARG1 = (ARG1); \
  563. __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  564. __RES; \
  565. })
  566. /**
  567. \brief Unsigned Saturate
  568. \details Saturates an unsigned value.
  569. \param [in] value Value to be saturated
  570. \param [in] sat Bit position to saturate to (0..31)
  571. \return Saturated value
  572. */
  573. #define __USAT(ARG1,ARG2) \
  574. ({ \
  575. uint32_t __RES, __ARG1 = (ARG1); \
  576. __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  577. __RES; \
  578. })
  579. /**
  580. \brief Rotate Right with Extend (32 bit)
  581. \details Moves each bit of a bitstring right by one bit.
  582. The carry input is shifted in at the left end of the bitstring.
  583. \param [in] value Value to rotate
  584. \return Rotated value
  585. */
  586. __attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value)
  587. {
  588. uint32_t result;
  589. __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) );
  590. return(result);
  591. }
  592. /**
  593. \brief LDRT Unprivileged (8 bit)
  594. \details Executes a Unprivileged LDRT instruction for 8 bit value.
  595. \param [in] ptr Pointer to data
  596. \return value of type uint8_t at (*ptr)
  597. */
  598. __attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr)
  599. {
  600. uint32_t result;
  601. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  602. __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) );
  603. #else
  604. /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
  605. accepted by assembler. So has to use following less efficient pattern.
  606. */
  607. __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
  608. #endif
  609. return ((uint8_t) result); /* Add explicit type cast here */
  610. }
  611. /**
  612. \brief LDRT Unprivileged (16 bit)
  613. \details Executes a Unprivileged LDRT instruction for 16 bit values.
  614. \param [in] ptr Pointer to data
  615. \return value of type uint16_t at (*ptr)
  616. */
  617. __attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr)
  618. {
  619. uint32_t result;
  620. #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  621. __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) );
  622. #else
  623. /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not
  624. accepted by assembler. So has to use following less efficient pattern.
  625. */
  626. __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" );
  627. #endif
  628. return ((uint16_t) result); /* Add explicit type cast here */
  629. }
  630. /**
  631. \brief LDRT Unprivileged (32 bit)
  632. \details Executes a Unprivileged LDRT instruction for 32 bit values.
  633. \param [in] ptr Pointer to data
  634. \return value of type uint32_t at (*ptr)
  635. */
  636. __attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr)
  637. {
  638. uint32_t result;
  639. __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) );
  640. return(result);
  641. }
  642. /**
  643. \brief STRT Unprivileged (8 bit)
  644. \details Executes a Unprivileged STRT instruction for 8 bit values.
  645. \param [in] value Value to store
  646. \param [in] ptr Pointer to location
  647. */
  648. __attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr)
  649. {
  650. __ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
  651. }
  652. /**
  653. \brief STRT Unprivileged (16 bit)
  654. \details Executes a Unprivileged STRT instruction for 16 bit values.
  655. \param [in] value Value to store
  656. \param [in] ptr Pointer to location
  657. */
  658. __attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr)
  659. {
  660. __ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) );
  661. }
  662. /**
  663. \brief STRT Unprivileged (32 bit)
  664. \details Executes a Unprivileged STRT instruction for 32 bit values.
  665. \param [in] value Value to store
  666. \param [in] ptr Pointer to location
  667. */
  668. __attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr)
  669. {
  670. __ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) );
  671. }
  672. #endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
  673. /*@}*/ /* end of group CMSIS_Core_InstructionInterface */
  674. /* ################### Compiler specific Intrinsics ########################### */
  675. /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
  676. Access to dedicated SIMD instructions
  677. @{
  678. */
  679. #if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */
  680. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2)
  681. {
  682. uint32_t result;
  683. __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  684. return(result);
  685. }
  686. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2)
  687. {
  688. uint32_t result;
  689. __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  690. return(result);
  691. }
  692. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2)
  693. {
  694. uint32_t result;
  695. __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  696. return(result);
  697. }
  698. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2)
  699. {
  700. uint32_t result;
  701. __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  702. return(result);
  703. }
  704. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2)
  705. {
  706. uint32_t result;
  707. __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  708. return(result);
  709. }
  710. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2)
  711. {
  712. uint32_t result;
  713. __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  714. return(result);
  715. }
  716. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2)
  717. {
  718. uint32_t result;
  719. __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  720. return(result);
  721. }
  722. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2)
  723. {
  724. uint32_t result;
  725. __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  726. return(result);
  727. }
  728. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2)
  729. {
  730. uint32_t result;
  731. __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  732. return(result);
  733. }
  734. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2)
  735. {
  736. uint32_t result;
  737. __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  738. return(result);
  739. }
  740. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2)
  741. {
  742. uint32_t result;
  743. __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  744. return(result);
  745. }
  746. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2)
  747. {
  748. uint32_t result;
  749. __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  750. return(result);
  751. }
  752. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2)
  753. {
  754. uint32_t result;
  755. __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  756. return(result);
  757. }
  758. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2)
  759. {
  760. uint32_t result;
  761. __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  762. return(result);
  763. }
  764. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2)
  765. {
  766. uint32_t result;
  767. __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  768. return(result);
  769. }
  770. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2)
  771. {
  772. uint32_t result;
  773. __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  774. return(result);
  775. }
  776. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2)
  777. {
  778. uint32_t result;
  779. __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  780. return(result);
  781. }
  782. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2)
  783. {
  784. uint32_t result;
  785. __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  786. return(result);
  787. }
  788. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2)
  789. {
  790. uint32_t result;
  791. __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  792. return(result);
  793. }
  794. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2)
  795. {
  796. uint32_t result;
  797. __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  798. return(result);
  799. }
  800. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2)
  801. {
  802. uint32_t result;
  803. __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  804. return(result);
  805. }
  806. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2)
  807. {
  808. uint32_t result;
  809. __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  810. return(result);
  811. }
  812. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2)
  813. {
  814. uint32_t result;
  815. __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  816. return(result);
  817. }
  818. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2)
  819. {
  820. uint32_t result;
  821. __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  822. return(result);
  823. }
  824. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2)
  825. {
  826. uint32_t result;
  827. __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  828. return(result);
  829. }
  830. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2)
  831. {
  832. uint32_t result;
  833. __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  834. return(result);
  835. }
  836. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2)
  837. {
  838. uint32_t result;
  839. __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  840. return(result);
  841. }
  842. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2)
  843. {
  844. uint32_t result;
  845. __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  846. return(result);
  847. }
  848. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2)
  849. {
  850. uint32_t result;
  851. __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  852. return(result);
  853. }
  854. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2)
  855. {
  856. uint32_t result;
  857. __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  858. return(result);
  859. }
  860. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2)
  861. {
  862. uint32_t result;
  863. __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  864. return(result);
  865. }
  866. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2)
  867. {
  868. uint32_t result;
  869. __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  870. return(result);
  871. }
  872. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2)
  873. {
  874. uint32_t result;
  875. __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  876. return(result);
  877. }
  878. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2)
  879. {
  880. uint32_t result;
  881. __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  882. return(result);
  883. }
  884. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2)
  885. {
  886. uint32_t result;
  887. __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  888. return(result);
  889. }
  890. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2)
  891. {
  892. uint32_t result;
  893. __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  894. return(result);
  895. }
  896. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2)
  897. {
  898. uint32_t result;
  899. __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  900. return(result);
  901. }
  902. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3)
  903. {
  904. uint32_t result;
  905. __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
  906. return(result);
  907. }
  908. #define __SSAT16(ARG1,ARG2) \
  909. ({ \
  910. int32_t __RES, __ARG1 = (ARG1); \
  911. __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  912. __RES; \
  913. })
  914. #define __USAT16(ARG1,ARG2) \
  915. ({ \
  916. uint32_t __RES, __ARG1 = (ARG1); \
  917. __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
  918. __RES; \
  919. })
  920. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1)
  921. {
  922. uint32_t result;
  923. __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1));
  924. return(result);
  925. }
  926. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2)
  927. {
  928. uint32_t result;
  929. __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  930. return(result);
  931. }
  932. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1)
  933. {
  934. uint32_t result;
  935. __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1));
  936. return(result);
  937. }
  938. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2)
  939. {
  940. uint32_t result;
  941. __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  942. return(result);
  943. }
  944. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2)
  945. {
  946. uint32_t result;
  947. __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  948. return(result);
  949. }
  950. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2)
  951. {
  952. uint32_t result;
  953. __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  954. return(result);
  955. }
  956. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3)
  957. {
  958. uint32_t result;
  959. __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
  960. return(result);
  961. }
  962. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3)
  963. {
  964. uint32_t result;
  965. __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
  966. return(result);
  967. }
  968. __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc)
  969. {
  970. union llreg_u{
  971. uint32_t w32[2];
  972. uint64_t w64;
  973. } llr;
  974. llr.w64 = acc;
  975. #ifndef __ARMEB__ /* Little endian */
  976. __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]) );
  977. #else /* Big endian */
  978. __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]) );
  979. #endif
  980. return(llr.w64);
  981. }
  982. __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc)
  983. {
  984. union llreg_u{
  985. uint32_t w32[2];
  986. uint64_t w64;
  987. } llr;
  988. llr.w64 = acc;
  989. #ifndef __ARMEB__ /* Little endian */
  990. __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]) );
  991. #else /* Big endian */
  992. __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]) );
  993. #endif
  994. return(llr.w64);
  995. }
  996. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2)
  997. {
  998. uint32_t result;
  999. __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  1000. return(result);
  1001. }
  1002. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2)
  1003. {
  1004. uint32_t result;
  1005. __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  1006. return(result);
  1007. }
  1008. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3)
  1009. {
  1010. uint32_t result;
  1011. __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
  1012. return(result);
  1013. }
  1014. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3)
  1015. {
  1016. uint32_t result;
  1017. __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) );
  1018. return(result);
  1019. }
  1020. __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc)
  1021. {
  1022. union llreg_u{
  1023. uint32_t w32[2];
  1024. uint64_t w64;
  1025. } llr;
  1026. llr.w64 = acc;
  1027. #ifndef __ARMEB__ /* Little endian */
  1028. __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]) );
  1029. #else /* Big endian */
  1030. __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]) );
  1031. #endif
  1032. return(llr.w64);
  1033. }
  1034. __attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc)
  1035. {
  1036. union llreg_u{
  1037. uint32_t w32[2];
  1038. uint64_t w64;
  1039. } llr;
  1040. llr.w64 = acc;
  1041. #ifndef __ARMEB__ /* Little endian */
  1042. __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]) );
  1043. #else /* Big endian */
  1044. __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]) );
  1045. #endif
  1046. return(llr.w64);
  1047. }
  1048. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2)
  1049. {
  1050. uint32_t result;
  1051. __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  1052. return(result);
  1053. }
  1054. __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2)
  1055. {
  1056. int32_t result;
  1057. __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  1058. return(result);
  1059. }
  1060. __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2)
  1061. {
  1062. int32_t result;
  1063. __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) );
  1064. return(result);
  1065. }
  1066. #define __PKHBT(ARG1,ARG2,ARG3) \
  1067. ({ \
  1068. uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
  1069. __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
  1070. __RES; \
  1071. })
  1072. #define __PKHTB(ARG1,ARG2,ARG3) \
  1073. ({ \
  1074. uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \
  1075. if (ARG3 == 0) \
  1076. __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \
  1077. else \
  1078. __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \
  1079. __RES; \
  1080. })
  1081. __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3)
  1082. {
  1083. int32_t result;
  1084. __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) );
  1085. return(result);
  1086. }
  1087. #endif /* (__CORTEX_M >= 0x04) */
  1088. /*@} end of group CMSIS_SIMD_intrinsics */
  1089. #if defined ( __GNUC__ )
  1090. #pragma GCC diagnostic pop
  1091. #endif
  1092. #endif /* __CMSIS_GCC_H */