cmsis_gcc.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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 */