csi_gcc.h 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. */
  4. /******************************************************************************
  5. * @file csi_gcc.h
  6. * @brief CSI Header File for GCC.
  7. * @version V1.0
  8. * @date 02. June 2020
  9. ******************************************************************************/
  10. #ifndef _CSI_GCC_H_
  11. #define _CSI_GCC_H_
  12. #include <stdlib.h>
  13. #include <stdint.h>
  14. #ifndef __ASM
  15. #define __ASM __asm /*!< asm keyword for GNU Compiler */
  16. #endif
  17. #ifndef __INLINE
  18. #define __INLINE inline /*!< inline keyword for GNU Compiler */
  19. #endif
  20. #ifndef __ALWAYS_STATIC_INLINE
  21. #define __ALWAYS_STATIC_INLINE __attribute__((always_inline)) static inline
  22. #endif
  23. #ifndef __STATIC_INLINE
  24. #define __STATIC_INLINE static inline
  25. #endif
  26. #ifndef __NO_RETURN
  27. #define __NO_RETURN __attribute__((__noreturn__))
  28. #endif
  29. #ifndef __USED
  30. #define __USED __attribute__((used))
  31. #endif
  32. #ifndef __WEAK
  33. #define __WEAK __attribute__((weak))
  34. #endif
  35. #ifndef __PACKED
  36. #define __PACKED __attribute__((packed, aligned(1)))
  37. #endif
  38. #ifndef __PACKED_STRUCT
  39. #define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
  40. #endif
  41. #ifndef __PACKED_UNION
  42. #define __PACKED_UNION union __attribute__((packed, aligned(1)))
  43. #endif
  44. /* ########################### Core Function Access ########################### */
  45. /** \ingroup CSI_Core_FunctionInterface
  46. \defgroup CSI_Core_RegAccFunctions CSI Core Register Access Functions
  47. @{
  48. */
  49. /**
  50. \brief Enable IRQ Interrupts
  51. \details Enables IRQ interrupts by setting the IE-bit in the PSR.
  52. Can only be executed in Privileged modes.
  53. */
  54. __ALWAYS_STATIC_INLINE void __enable_irq(void)
  55. {
  56. __ASM volatile("psrset ie");
  57. }
  58. /**
  59. \brief Disable IRQ Interrupts
  60. \details Disables IRQ interrupts by clearing the IE-bit in the PSR.
  61. Can only be executed in Privileged modes.
  62. */
  63. __ALWAYS_STATIC_INLINE void __disable_irq(void)
  64. {
  65. __ASM volatile("psrclr ie");
  66. }
  67. /**
  68. \brief Get PSR
  69. \details Returns the content of the PSR Register.
  70. \return PSR Register value
  71. */
  72. __ALWAYS_STATIC_INLINE uint32_t __get_PSR(void)
  73. {
  74. uint32_t result;
  75. __ASM volatile("mfcr %0, psr" : "=r"(result));
  76. return (result);
  77. }
  78. /**
  79. \brief Set PSR
  80. \details Writes the given value to the PSR Register.
  81. \param [in] psr PSR Register value to set
  82. */
  83. __ALWAYS_STATIC_INLINE void __set_PSR(uint32_t psr)
  84. {
  85. __ASM volatile("mtcr %0, psr" : : "r"(psr));
  86. }
  87. /**
  88. \brief Get SP
  89. \details Returns the content of the SP Register.
  90. \return SP Register value
  91. */
  92. __ALWAYS_STATIC_INLINE uint32_t __get_SP(void)
  93. {
  94. uint32_t result;
  95. __ASM volatile("mov %0, sp" : "=r"(result));
  96. return (result);
  97. }
  98. /**
  99. \brief Set SP
  100. \details Writes the given value to the SP Register.
  101. \param [in] sp SP Register value to set
  102. */
  103. __ALWAYS_STATIC_INLINE void __set_SP(uint32_t sp)
  104. {
  105. __ASM volatile("mov sp, %0" : : "r"(sp): "sp");
  106. }
  107. /**
  108. \brief Get Int SP
  109. \details Returns the content of the Int SP Register.
  110. \return Int SP Register value
  111. */
  112. __ALWAYS_STATIC_INLINE uint32_t __get_Int_SP(void)
  113. {
  114. uint32_t result;
  115. __ASM volatile("mfcr %0, cr<15, 1>" : "=r"(result));
  116. return (result);
  117. }
  118. /**
  119. \brief Set Int SP
  120. \details Writes the given value to the Int SP Register.
  121. \param [in] sp Int SP Register value to set
  122. */
  123. __ALWAYS_STATIC_INLINE void __set_Int_SP(uint32_t sp)
  124. {
  125. __ASM volatile("mtcr %0, cr<15, 1>" : : "r"(sp));
  126. }
  127. /**
  128. \brief Get VBR Register
  129. \details Returns the content of the VBR Register.
  130. \return VBR Register value
  131. */
  132. __ALWAYS_STATIC_INLINE uint32_t __get_VBR(void)
  133. {
  134. uint32_t result;
  135. __ASM volatile("mfcr %0, vbr" : "=r"(result));
  136. return (result);
  137. }
  138. /**
  139. \brief Set VBR
  140. \details Writes the given value to the VBR Register.
  141. \param [in] vbr VBR Register value to set
  142. */
  143. __ALWAYS_STATIC_INLINE void __set_VBR(uint32_t vbr)
  144. {
  145. __ASM volatile("mtcr %0, vbr" : : "r"(vbr));
  146. }
  147. /**
  148. \brief Get EPC Register
  149. \details Returns the content of the EPC Register.
  150. \return EPC Register value
  151. */
  152. __ALWAYS_STATIC_INLINE uint32_t __get_EPC(void)
  153. {
  154. uint32_t result;
  155. __ASM volatile("mfcr %0, epc" : "=r"(result));
  156. return (result);
  157. }
  158. /**
  159. \brief Set EPC
  160. \details Writes the given value to the EPC Register.
  161. \param [in] epc EPC Register value to set
  162. */
  163. __ALWAYS_STATIC_INLINE void __set_EPC(uint32_t epc)
  164. {
  165. __ASM volatile("mtcr %0, epc" : : "r"(epc));
  166. }
  167. /**
  168. \brief Get EPSR
  169. \details Returns the content of the EPSR Register.
  170. \return EPSR Register value
  171. */
  172. __ALWAYS_STATIC_INLINE uint32_t __get_EPSR(void)
  173. {
  174. uint32_t result;
  175. __ASM volatile("mfcr %0, epsr" : "=r"(result));
  176. return (result);
  177. }
  178. /**
  179. \brief Set EPSR
  180. \details Writes the given value to the EPSR Register.
  181. \param [in] epsr EPSR Register value to set
  182. */
  183. __ALWAYS_STATIC_INLINE void __set_EPSR(uint32_t epsr)
  184. {
  185. __ASM volatile("mtcr %0, epsr" : : "r"(epsr));
  186. }
  187. /**
  188. \brief Get CPUID Register
  189. \details Returns the content of the CPUID Register.
  190. \return CPUID Register value
  191. */
  192. __ALWAYS_STATIC_INLINE uint32_t __get_CPUID(void)
  193. {
  194. uint32_t result;
  195. #ifdef __CK610
  196. __ASM volatile("mfcr %0, cr13" : "=r"(result));
  197. #else
  198. __ASM volatile("mfcr %0, cr<13, 0>" : "=r"(result));
  199. #endif
  200. return (result);
  201. }
  202. /**
  203. \brief Get CCR
  204. \details Returns the current value of the CCR.
  205. \return CCR Register value
  206. */
  207. __ALWAYS_STATIC_INLINE uint32_t __get_CCR(void)
  208. {
  209. register uint32_t result;
  210. #ifdef __CK610
  211. __ASM volatile("mfcr %0, cr18\n" : "=r"(result));
  212. #else
  213. __ASM volatile("mfcr %0, cr<18, 0>\n" : "=r"(result));
  214. #endif
  215. return (result);
  216. }
  217. /**
  218. \brief Set CCR
  219. \details Assigns the given value to the CCR.
  220. \param [in] ccr CCR value to set
  221. */
  222. __ALWAYS_STATIC_INLINE void __set_CCR(uint32_t ccr)
  223. {
  224. #ifdef __CK610
  225. __ASM volatile("mtcr %0, cr18\n" : : "r"(ccr));
  226. #else
  227. __ASM volatile("mtcr %0, cr<18, 0>\n" : : "r"(ccr));
  228. #endif
  229. }
  230. /**
  231. \brief Get CCR2
  232. \details Returns the current value of the CCR2.
  233. \return CCR2 Register value
  234. */
  235. __ALWAYS_STATIC_INLINE uint32_t __get_CCR2(void)
  236. {
  237. register uint32_t result;
  238. __ASM volatile("mfcr %0, cr<31, 0>\n" : "=r"(result));
  239. return (result);
  240. }
  241. /**
  242. \brief Set CCR2
  243. \details Assigns the given value to the CCR2.
  244. \param [in] ccr2 CCR2 value to set
  245. */
  246. __ALWAYS_STATIC_INLINE void __set_CCR2(uint32_t ccr2)
  247. {
  248. __ASM volatile("mtcr %0, cr<31, 0>\n" : : "r"(ccr2));
  249. }
  250. /**
  251. \brief Get DCSR
  252. \details Returns the content of the DCSR Register.
  253. \return DCSR Register value
  254. */
  255. __ALWAYS_STATIC_INLINE uint32_t __get_DCSR(void)
  256. {
  257. uint32_t result;
  258. #ifdef __CK610
  259. __ASM volatile("mfcr %0, cr14" : "=r"(result));
  260. #else
  261. __ASM volatile("mfcr %0, cr<14, 0>" : "=r"(result));
  262. #endif
  263. return (result);
  264. }
  265. /**
  266. \brief Set DCSR
  267. \details Writes the given value to the DCSR Register.
  268. \param [in] dcsr DCSR Register value to set
  269. */
  270. __ALWAYS_STATIC_INLINE void __set_DCSR(uint32_t dcsr)
  271. {
  272. #ifdef __CK610
  273. __ASM volatile("mtcr %0, cr14" : : "r"(dcsr));
  274. #else
  275. __ASM volatile("mtcr %0, cr<14, 0>" : : "r"(dcsr));
  276. #endif
  277. }
  278. /**
  279. \brief Get CFR
  280. \details Returns the content of the CFR Register.
  281. \return CFR Register value
  282. */
  283. __ALWAYS_STATIC_INLINE uint32_t __get_CFR(void)
  284. {
  285. uint32_t result;
  286. #ifdef __CK610
  287. __ASM volatile("mfcr %0, cr17" : "=r"(result));
  288. #else
  289. __ASM volatile("mfcr %0, cr<17, 0>" : "=r"(result));
  290. #endif
  291. return (result);
  292. }
  293. /**
  294. \brief Set CFR
  295. \details Writes the given value to the CFR Register.
  296. \param [in] cfr CFR Register value to set
  297. */
  298. __ALWAYS_STATIC_INLINE void __set_CFR(uint32_t cfr)
  299. {
  300. #ifdef __CK610
  301. __ASM volatile("mtcr %0, cr17" : : "r"(cfr));
  302. #else
  303. __ASM volatile("mtcr %0, cr<17, 0>" : : "r"(cfr));
  304. #endif
  305. }
  306. /**
  307. \brief Get CIR
  308. \details Returns the content of the CIR Register.
  309. \return CIR Register value
  310. */
  311. __ALWAYS_STATIC_INLINE uint32_t __get_CIR(void)
  312. {
  313. uint32_t result;
  314. #ifdef __CK610
  315. __ASM volatile("mfcr %0, cr22" : "=r"(result));
  316. #else
  317. __ASM volatile("mfcr %0, cr<22, 0>" : "=r"(result));
  318. #endif
  319. return (result);
  320. }
  321. /**
  322. \brief Set CIR
  323. \details Writes the given value to the CIR Register.
  324. \param [in] cir CIR Register value to set
  325. */
  326. __ALWAYS_STATIC_INLINE void __set_CIR(uint32_t cir)
  327. {
  328. #ifdef __CK610
  329. __ASM volatile("mtcr %0, cr22" : : "r"(cir));
  330. #else
  331. __ASM volatile("mtcr %0, cr<22, 0>" : : "r"(cir));
  332. #endif
  333. }
  334. /**
  335. \brief Get ERRLC
  336. \details Returns the current value of the ERRLC.
  337. \return ERRLC Register value
  338. */
  339. __ALWAYS_STATIC_INLINE uint32_t __get_ERRLC(void)
  340. {
  341. register uint32_t result;
  342. __ASM volatile("mfcr %0, cr<6, 1>\n" : "=r"(result));
  343. return (result);
  344. }
  345. /**
  346. \brief Set ERRLC
  347. \details Assigns the given value to the ERRLC.
  348. \param [in] errlc ERRLC value to set
  349. */
  350. __ALWAYS_STATIC_INLINE void __set_ERRLC(uint32_t errlc)
  351. {
  352. __ASM volatile("mtcr %0, cr<6, 1>\n" : : "r"(errlc));
  353. }
  354. /**
  355. \brief Get ERRADDR
  356. \details Returns the current value of the ERRADDR.
  357. \return ERRADDR Register value
  358. */
  359. __ALWAYS_STATIC_INLINE uint32_t __get_ERRADDR(void)
  360. {
  361. register uint32_t result;
  362. __ASM volatile("mfcr %0, cr<7, 1>\n" : "=r"(result));
  363. return (result);
  364. }
  365. /**
  366. \brief Set ERRADDR
  367. \details Assigns the given value to the ERRADDR.
  368. \param [in] erraddr ERRADDR value to set
  369. */
  370. __ALWAYS_STATIC_INLINE void __set_ERRADDR(uint32_t erraddr)
  371. {
  372. __ASM volatile("mtcr %0, cr<7, 1>\n" : : "r"(erraddr));
  373. }
  374. /**
  375. \brief Get ERRSTS
  376. \details Returns the current value of the ERRSTS.
  377. \return ERRSTS Register value
  378. */
  379. __ALWAYS_STATIC_INLINE uint32_t __get_ERRSTS(void)
  380. {
  381. register uint32_t result;
  382. __ASM volatile("mfcr %0, cr<8, 1>\n" : "=r"(result));
  383. return (result);
  384. }
  385. /**
  386. \brief Set ERRSTS
  387. \details Assigns the given value to the ERRSTS.
  388. \param [in] errsts ERRSTS value to set
  389. */
  390. __ALWAYS_STATIC_INLINE void __set_ERRSTS(uint32_t errsts)
  391. {
  392. __ASM volatile("mtcr %0, cr<8, 1>\n" : : "r"(errsts));
  393. }
  394. /**
  395. \brief Get ERRINJCR
  396. \details Returns the current value of the ERRINJCR.
  397. \return ERRINJCR Register value
  398. */
  399. __ALWAYS_STATIC_INLINE uint32_t __get_ERRINJCR(void)
  400. {
  401. register uint32_t result;
  402. __ASM volatile("mfcr %0, cr<9, 1>\n" : "=r"(result));
  403. return (result);
  404. }
  405. /**
  406. \brief Set ERRINJCR
  407. \details Assigns the given value to the ERRINJCR.
  408. \param [in] errinjcr ERRINJCR value to set
  409. */
  410. __ALWAYS_STATIC_INLINE void __set_ERRINJCR(uint32_t errinjcr)
  411. {
  412. __ASM volatile("mtcr %0, cr<9, 1>\n" : : "r"(errinjcr));
  413. }
  414. /**
  415. \brief Get ERRINJCNT
  416. \details Returns the current value of the ERRINJCNT.
  417. \return ERRINJCNT Register value
  418. */
  419. __ALWAYS_STATIC_INLINE uint32_t __get_ERRINJCNT(void)
  420. {
  421. register uint32_t result;
  422. __ASM volatile("mfcr %0, cr<10, 1>\n" : "=r"(result));
  423. return (result);
  424. }
  425. /**
  426. \brief Set ERRINJCNT
  427. \details Assigns the given value to the ERRINJCNT.
  428. \param [in] errinjcnt ERRINJCNT value to set
  429. */
  430. __ALWAYS_STATIC_INLINE void __set_ERRINJCNT(uint32_t errinjcnt)
  431. {
  432. __ASM volatile("mtcr %0, cr<10, 1>\n" : : "r"(errinjcnt));
  433. }
  434. /**
  435. \brief Get ITCMCR
  436. \details Returns the content of the ITCMCR Register.
  437. \return ITCMCR Register value
  438. */
  439. __ALWAYS_STATIC_INLINE uint32_t __get_ITCMCR(void)
  440. {
  441. uint32_t result;
  442. __ASM volatile("mfcr %0, cr<22, 1>" : "=r"(result));
  443. return (result);
  444. }
  445. /**
  446. \brief Set ITCMCR
  447. \details Writes the given value to the ITCMCR Register.
  448. \param [in] itcmcr ITCMCR Register value to set
  449. */
  450. __ALWAYS_STATIC_INLINE void __set_ITCMCR(uint32_t itcmcr)
  451. {
  452. __ASM volatile("mtcr %0, cr<22, 1>" : : "r"(itcmcr));
  453. }
  454. /**
  455. \brief Get DTCMCR
  456. \details Returns the content of the DTCMCR Register.
  457. \return DTCMCR Register value
  458. */
  459. __ALWAYS_STATIC_INLINE uint32_t __get_DTCMCR(void)
  460. {
  461. uint32_t result;
  462. __ASM volatile("mfcr %0, cr<23, 1>" : "=r"(result));
  463. return (result);
  464. }
  465. /**
  466. \brief Set DTCMCR
  467. \details Writes the given value to the DTCMCR Register.
  468. \param [in] dtcmcr DTCMCR Register value to set
  469. */
  470. __ALWAYS_STATIC_INLINE void __set_DTCMCR(uint32_t dtcmcr)
  471. {
  472. __ASM volatile("mtcr %0, cr<23, 1>" : : "r"(dtcmcr));
  473. }
  474. /**
  475. \brief Get CINDEX
  476. \details Returns the current value of the CINDEX.
  477. \return CINDEX Register value
  478. */
  479. __ALWAYS_STATIC_INLINE uint32_t __get_CINDEX(void)
  480. {
  481. register uint32_t result;
  482. __ASM volatile("mfcr %0, cr<26, 1>\n" : "=r"(result));
  483. return (result);
  484. }
  485. /**
  486. \brief Set CINDEX
  487. \details Assigns the given value to the CINDEX.
  488. \param [in] cindex CINDEX value to set
  489. */
  490. __ALWAYS_STATIC_INLINE void __set_CINDEX(uint32_t cindex)
  491. {
  492. __ASM volatile("mtcr %0, cr<26, 1>\n" : : "r"(cindex));
  493. }
  494. /**
  495. \brief Get CDATAx
  496. \details Returns the current value of the CDATAx.
  497. \return CDATAx Register value
  498. */
  499. __ALWAYS_STATIC_INLINE uint32_t __get_CDATA0(void)
  500. {
  501. register uint32_t result;
  502. __ASM volatile("mfcr %0, cr<27, 1>\n" : "=r"(result));
  503. return (result);
  504. }
  505. __ALWAYS_STATIC_INLINE uint32_t __get_CDATA1(void)
  506. {
  507. register uint32_t result;
  508. __ASM volatile("mfcr %0, cr<28, 1>\n" : "=r"(result));
  509. return (result);
  510. }
  511. __ALWAYS_STATIC_INLINE uint32_t __get_CDATA2(void)
  512. {
  513. register uint32_t result;
  514. __ASM volatile("mfcr %0, cr<29, 1>\n" : "=r"(result));
  515. return (result);
  516. }
  517. /**
  518. \brief Set CDATAx
  519. \details Assigns the given value to the CDATAx.
  520. \param [in] cdata CDATAx value to set
  521. */
  522. __ALWAYS_STATIC_INLINE void __set_CDATA0(uint32_t cdata)
  523. {
  524. __ASM volatile("mtcr %0, cr<27, 1>\n" : : "r"(cdata));
  525. }
  526. __ALWAYS_STATIC_INLINE void __set_CDATA1(uint32_t cdata)
  527. {
  528. __ASM volatile("mtcr %0, cr<28, 1>\n" : : "r"(cdata));
  529. }
  530. __ALWAYS_STATIC_INLINE void __set_CDATA2(uint32_t cdata)
  531. {
  532. __ASM volatile("mtcr %0, cr<29, 1>\n" : : "r"(cdata));
  533. }
  534. /**
  535. \brief Get CINS
  536. \details Returns the current value of the CINS.
  537. \return CINS Register value
  538. */
  539. __ALWAYS_STATIC_INLINE uint32_t __get_CINS(void)
  540. {
  541. register uint32_t result;
  542. __ASM volatile("mfcr %0, cr<31, 1>\n" : "=r"(result));
  543. return (result);
  544. }
  545. /**
  546. \brief Set CINS
  547. \details Assigns the given value to the CINS.
  548. \param [in] cins CINS value to set
  549. */
  550. __ALWAYS_STATIC_INLINE void __set_CINS(uint32_t cins)
  551. {
  552. __ASM volatile("mtcr %0, cr<31, 1>\n" : : "r"(cins));
  553. }
  554. /**
  555. \brief Get CAPR
  556. \details Returns the current value of the CAPR.
  557. \return CAPR Register value
  558. */
  559. __ALWAYS_STATIC_INLINE uint32_t __get_CAPR(void)
  560. {
  561. register uint32_t result;
  562. #ifdef __CK610
  563. __ASM volatile("mfcr %0, cr19\n" : "=r"(result));
  564. #else
  565. __ASM volatile("mfcr %0, cr<19, 0>\n" : "=r"(result));
  566. #endif
  567. return (result);
  568. }
  569. /**
  570. \brief Set CAPR
  571. \details Assigns the given value to the CAPR.
  572. \param [in] capr CAPR value to set
  573. */
  574. __ALWAYS_STATIC_INLINE void __set_CAPR(uint32_t capr)
  575. {
  576. #ifdef __CK610
  577. __ASM volatile("mtcr %0, cr19\n" : : "r"(capr));
  578. #else
  579. __ASM volatile("mtcr %0, cr<19, 0>\n" : : "r"(capr));
  580. #endif
  581. }
  582. /**
  583. \brief Get CAPR1
  584. \details Returns the current value of the CAPR1.
  585. \return CAPR1 Register value
  586. */
  587. __ALWAYS_STATIC_INLINE uint32_t __get_CAPR1(void)
  588. {
  589. register uint32_t result;
  590. __ASM volatile("mfcr %0, cr<16, 0>\n" : "=r"(result));
  591. return (result);
  592. }
  593. /**
  594. \brief Set CAPR1
  595. \details Assigns the given value to the CAPR1.
  596. \param [in] capr1 CAPR1 value to set
  597. */
  598. __ALWAYS_STATIC_INLINE void __set_CAPR1(uint32_t capr1)
  599. {
  600. __ASM volatile("mtcr %0, cr<16, 0>\n" : : "r"(capr1));
  601. }
  602. /**
  603. \brief Set PACR
  604. \details Assigns the given value to the PACR.
  605. \param [in] pacr PACR value to set
  606. */
  607. __ALWAYS_STATIC_INLINE void __set_PACR(uint32_t pacr)
  608. {
  609. #ifdef __CK610
  610. __ASM volatile("mtcr %0, cr20\n" : : "r"(pacr));
  611. #else
  612. __ASM volatile("mtcr %0, cr<20, 0>\n" : : "r"(pacr));
  613. #endif
  614. }
  615. /**
  616. \brief Get PACR
  617. \details Returns the current value of PACR.
  618. \return PACR value
  619. */
  620. __ALWAYS_STATIC_INLINE uint32_t __get_PACR(void)
  621. {
  622. uint32_t result;
  623. #ifdef __CK610
  624. __ASM volatile("mfcr %0, cr20" : "=r"(result));
  625. #else
  626. __ASM volatile("mfcr %0, cr<20, 0>" : "=r"(result));
  627. #endif
  628. return (result);
  629. }
  630. /**
  631. \brief Set PRSR
  632. \details Assigns the given value to the PRSR.
  633. \param [in] prsr PRSR value to set
  634. */
  635. __ALWAYS_STATIC_INLINE void __set_PRSR(uint32_t prsr)
  636. {
  637. #ifdef __CK610
  638. __ASM volatile("mtcr %0, cr21\n" : : "r"(prsr));
  639. #else
  640. __ASM volatile("mtcr %0, cr<21, 0>\n" : : "r"(prsr));
  641. #endif
  642. }
  643. /**
  644. \brief Get PRSR
  645. \details Returns the current value of PRSR.
  646. \return PRSR value
  647. */
  648. __ALWAYS_STATIC_INLINE uint32_t __get_PRSR(void)
  649. {
  650. uint32_t result;
  651. #ifdef __CK610
  652. __ASM volatile("mfcr %0, cr21" : "=r"(result));
  653. #else
  654. __ASM volatile("mfcr %0, cr<21, 0>" : "=r"(result));
  655. #endif
  656. return (result);
  657. }
  658. /**
  659. \brief Set ATTR0
  660. \details Assigns the given value to the ATTR0.
  661. \param [in] attr0 ATTR0 value to set
  662. */
  663. __ALWAYS_STATIC_INLINE void __set_ATTR0(uint32_t attr0)
  664. {
  665. __ASM volatile("mtcr %0, cr<26, 0>\n" : : "r"(attr0));
  666. }
  667. /**
  668. \brief Get ATTR0
  669. \details Returns the current value of ATTR0.
  670. \return ATTR0 value
  671. */
  672. __ALWAYS_STATIC_INLINE uint32_t __get_ATTR0(void)
  673. {
  674. uint32_t result;
  675. __ASM volatile("mfcr %0, cr<26, 0>" : "=r"(result));
  676. return (result);
  677. }
  678. /**
  679. \brief Set ATTR1
  680. \details Assigns the given value to the ATTR1.
  681. \param [in] attr0 ATTR1 value to set
  682. */
  683. __ALWAYS_STATIC_INLINE void __set_ATTR1(uint32_t attr1)
  684. {
  685. __ASM volatile("mtcr %0, cr<27, 0>\n" : : "r"(attr1));
  686. }
  687. /**
  688. \brief Get ATTR1
  689. \details Returns the current value of ATTR1.
  690. \return ATTR1 value
  691. */
  692. __ALWAYS_STATIC_INLINE uint32_t __get_ATTR1(void)
  693. {
  694. uint32_t result;
  695. __ASM volatile("mfcr %0, cr<27, 0>" : "=r"(result));
  696. return (result);
  697. }
  698. /**
  699. \brief Get user sp
  700. \details Returns the current value of user r14.
  701. \return UR14 value
  702. */
  703. __ALWAYS_STATIC_INLINE uint32_t __get_UR14(void)
  704. {
  705. uint32_t result;
  706. #ifdef __CK610
  707. __ASM volatile("mov %0, sp" : "=r"(result));
  708. #else
  709. __ASM volatile("mfcr %0, cr<14, 1>" : "=r"(result));
  710. #endif
  711. return (result);
  712. }
  713. /**
  714. \brief Set UR14
  715. \details Assigns the given value to the UR14.
  716. \param [in] ur14 UR14 value to set
  717. */
  718. __ALWAYS_STATIC_INLINE void __set_UR14(uint32_t ur14)
  719. {
  720. #ifdef __CK610
  721. __ASM volatile("mov sp, %0" : "=r"(ur14));
  722. #else
  723. __ASM volatile("mtcr %0, cr<14, 1>\n" : : "r"(ur14));
  724. #endif
  725. }
  726. /**
  727. \brief Get CHR Register
  728. \details Returns the content of the CHR Register.
  729. \return CHR Register value
  730. */
  731. __ALWAYS_STATIC_INLINE uint32_t __get_CHR(void)
  732. {
  733. uint32_t result;
  734. __ASM volatile("mfcr %0, cr<31, 0>\n" :"=r"(result));
  735. return (result);
  736. }
  737. /**
  738. \brief Set CHR
  739. \details Assigns the given value to the CHR.
  740. \param [in] chr CHR value to set
  741. */
  742. __ALWAYS_STATIC_INLINE void __set_CHR(uint32_t chr)
  743. {
  744. __ASM volatile("mtcr %0, cr<31, 0>\n" : : "r"(chr));
  745. }
  746. /**
  747. \brief Get HINT
  748. \details Returns the content of the HINT Register.
  749. \return HINT Register value
  750. */
  751. __ALWAYS_STATIC_INLINE uint32_t __get_HINT(void)
  752. {
  753. uint32_t result;
  754. #ifdef __CK610
  755. __ASM volatile("mfcr %0, cr<30, 0>" : "=r"(result));
  756. #else
  757. __ASM volatile("mfcr %0, cr<31, 0>" : "=r"(result));
  758. #endif
  759. return (result);
  760. }
  761. /**
  762. \brief Set HINT
  763. \details Writes the given value to the HINT Register.
  764. \param [in] hint HINT Register value to set
  765. */
  766. __ALWAYS_STATIC_INLINE void __set_HINT(uint32_t hint)
  767. {
  768. #ifdef __CK610
  769. __ASM volatile("mtcr %0, cr<30, 0>" : "=r"(hint));
  770. #else
  771. __ASM volatile("mtcr %0, cr<31, 0>" : : "r"(hint));
  772. #endif
  773. }
  774. /**
  775. \brief Get MIR
  776. \details Returns the content of the MIR Register.
  777. \return MIR Register value
  778. */
  779. __ALWAYS_STATIC_INLINE uint32_t __get_MIR(void)
  780. {
  781. uint32_t result;
  782. #ifdef __CK610
  783. __ASM volatile("cpseti 15");
  784. __ASM volatile("cprcr %0, cpcr0" : "=r"(result));
  785. #else
  786. __ASM volatile("mfcr %0, cr<0, 15>" : "=r"(result));
  787. #endif
  788. return (result);
  789. }
  790. /**
  791. \brief Set MIR
  792. \details Writes the given value to the MIR Register.
  793. \param [in] mir MIR Register value to set
  794. */
  795. __ALWAYS_STATIC_INLINE void __set_MIR(uint32_t mir)
  796. {
  797. #ifdef __CK610
  798. __ASM volatile("cpseti 15");
  799. __ASM volatile("cpwcr %0, cpcr0" : : "b"(mir));
  800. #else
  801. __ASM volatile("mtcr %0, cr<0, 15>" : : "r"(mir));
  802. #endif
  803. }
  804. /**
  805. \brief Get MEL0
  806. \details Returns the content of the MEL0 Register.
  807. \return MEL0 Register value
  808. */
  809. __ALWAYS_STATIC_INLINE uint32_t __get_MEL0(void)
  810. {
  811. uint32_t result;
  812. #ifdef __CK610
  813. __ASM volatile("cpseti 15");
  814. __ASM volatile("cprcr %0, cpcr2" : "=r"(result));
  815. #else
  816. __ASM volatile("mfcr %0, cr<2, 15>" : "=r"(result));
  817. #endif
  818. return (result);
  819. }
  820. /**
  821. \brief Set MEL0
  822. \details Writes the given value to the MEL0 Register.
  823. \param [in] mel0 MEL0 Register value to set
  824. */
  825. __ALWAYS_STATIC_INLINE void __set_MEL0(uint32_t mel0)
  826. {
  827. #ifdef __CK610
  828. __ASM volatile("cpseti 15");
  829. __ASM volatile("cpwcr %0, cpcr2" : : "b"(mel0));
  830. #else
  831. __ASM volatile("mtcr %0, cr<2, 15>" : : "r"(mel0));
  832. #endif
  833. }
  834. /**
  835. \brief Get MEL1
  836. \details Returns the content of the MEL1 Register.
  837. \return MEL1 Register value
  838. */
  839. __ALWAYS_STATIC_INLINE uint32_t __get_MEL1(void)
  840. {
  841. uint32_t result;
  842. #ifdef __CK610
  843. __ASM volatile("cpseti 15");
  844. __ASM volatile("cprcr %0, cpcr3" : "=r"(result));
  845. #else
  846. __ASM volatile("mfcr %0, cr<3, 15>" : "=r"(result));
  847. #endif
  848. return (result);
  849. }
  850. /**
  851. \brief Set MEL1
  852. \details Writes the given value to the MEL1 Register.
  853. \param [in] mel1 MEL1 Register value to set
  854. */
  855. __ALWAYS_STATIC_INLINE void __set_MEL1(uint32_t mel1)
  856. {
  857. #ifdef __CK610
  858. __ASM volatile("cpseti 15");
  859. __ASM volatile("cpwcr %0, cpcr3" : : "b"(mel1));
  860. #else
  861. __ASM volatile("mtcr %0, cr<3, 15>" : : "r"(mel1));
  862. #endif
  863. }
  864. /**
  865. \brief Get MEH
  866. \details Returns the content of the MEH Register.
  867. \return MEH Register value
  868. */
  869. __ALWAYS_STATIC_INLINE uint32_t __get_MEH(void)
  870. {
  871. uint32_t result;
  872. #ifdef __CK610
  873. __ASM volatile("cpseti 15");
  874. __ASM volatile("cprcr %0, cpcr4" : "=r"(result));
  875. #else
  876. __ASM volatile("mfcr %0, cr<4, 15>" : "=r"(result));
  877. #endif
  878. return (result);
  879. }
  880. /**
  881. \brief Set MEH
  882. \details Writes the given value to the MEH Register.
  883. \param [in] meh MEH Register value to set
  884. */
  885. __ALWAYS_STATIC_INLINE void __set_MEH(uint32_t meh)
  886. {
  887. #ifdef __CK610
  888. __ASM volatile("cpseti 15");
  889. __ASM volatile("cpwcr %0, cpcr4" : : "b"(meh));
  890. #else
  891. __ASM volatile("mtcr %0, cr<4, 15>" : : "r"(meh));
  892. #endif
  893. }
  894. /**
  895. \brief Get MPR
  896. \details Returns the content of the MPR Register.
  897. \return MPR Register value
  898. */
  899. __ALWAYS_STATIC_INLINE uint32_t __get_MPR(void)
  900. {
  901. uint32_t result;
  902. #ifdef __CK610
  903. __ASM volatile("cpseti 15");
  904. __ASM volatile("cprcr %0, cpcr6" : "=r"(result));
  905. #else
  906. __ASM volatile("mfcr %0, cr<6, 15>" : "=r"(result));
  907. #endif
  908. return (result);
  909. }
  910. /**
  911. \brief Set MPR
  912. \details Writes the given value to the MPR Register.
  913. \param [in] mpr MPR Register value to set
  914. */
  915. __ALWAYS_STATIC_INLINE void __set_MPR(uint32_t mpr)
  916. {
  917. #ifdef __CK610
  918. __ASM volatile("cpseti 15");
  919. __ASM volatile("cpwcr %0, cpcr6" : : "b"(mpr));
  920. #else
  921. __ASM volatile("mtcr %0, cr<6, 15>" : : "r"(mpr));
  922. #endif
  923. }
  924. /**
  925. \brief Get MCIR
  926. \details Returns the content of the MCIR Register.
  927. \return MCIR Register value
  928. */
  929. __ALWAYS_STATIC_INLINE uint32_t __get_MCIR(void)
  930. {
  931. uint32_t result;
  932. #ifdef __CK610
  933. __ASM volatile("cpseti 15");
  934. __ASM volatile("cprcr %0, cpcr8" : "=r"(result));
  935. #else
  936. __ASM volatile("mfcr %0, cr<8, 15>" : "=r"(result));
  937. #endif
  938. return (result);
  939. }
  940. /**
  941. \brief Set MCIR
  942. \details Writes the given value to the MCIR Register.
  943. \param [in] mcir MCIR Register value to set
  944. */
  945. __ALWAYS_STATIC_INLINE void __set_MCIR(uint32_t mcir)
  946. {
  947. #ifdef __CK610
  948. __ASM volatile("cpseti 15");
  949. __ASM volatile("cpwcr %0, cpcr8" : : "b"(mcir));
  950. #else
  951. __ASM volatile("mtcr %0, cr<8, 15>" : : "r"(mcir));
  952. #endif
  953. }
  954. /**
  955. \brief Get MPGD
  956. \details Returns the content of the MPGD Register.
  957. \return MPGD Register value
  958. */
  959. __ALWAYS_STATIC_INLINE uint32_t __get_MPGD(void)
  960. {
  961. uint32_t result;
  962. #ifdef __CK610
  963. __ASM volatile("cpseti 15");
  964. __ASM volatile("cprcr %0, cpcr29" : "=r"(result));
  965. #else
  966. __ASM volatile("mfcr %0, cr<29, 15>" : "=r"(result));
  967. #endif
  968. return (result);
  969. }
  970. /**
  971. \brief Set MPGD
  972. \details Writes the given value to the MPGD Register.
  973. \param [in] mpgd MPGD Register value to set
  974. */
  975. __ALWAYS_STATIC_INLINE void __set_MPGD(uint32_t mpgd)
  976. {
  977. #ifdef __CK610
  978. __ASM volatile("cpseti 15");
  979. __ASM volatile("cpwcr %0, cpcr29" : : "b"(mpgd));
  980. #else
  981. __ASM volatile("mtcr %0, cr<29, 15>" : : "r"(mpgd));
  982. #endif
  983. }
  984. /**
  985. \brief Get MSA0
  986. \details Returns the content of the MSA0 Register.
  987. \return MSA0 Register value
  988. */
  989. __ALWAYS_STATIC_INLINE uint32_t __get_MSA0(void)
  990. {
  991. uint32_t result;
  992. #ifdef __CK610
  993. __ASM volatile("cpseti 15");
  994. __ASM volatile("cprcr %0, cpcr30" : "=r"(result));
  995. #else
  996. __ASM volatile("mfcr %0, cr<30, 15>" : "=r"(result));
  997. #endif
  998. return (result);
  999. }
  1000. /**
  1001. \brief Set MSA0
  1002. \details Writes the given value to the MSA0 Register.
  1003. \param [in] msa0 MSA0 Register value to set
  1004. */
  1005. __ALWAYS_STATIC_INLINE void __set_MSA0(uint32_t msa0)
  1006. {
  1007. #ifdef __CK610
  1008. __ASM volatile("cpseti 15");
  1009. __ASM volatile("cpwcr %0, cpcr30" : : "b"(msa0));
  1010. #else
  1011. __ASM volatile("mtcr %0, cr<30, 15>" : : "r"(msa0));
  1012. #endif
  1013. }
  1014. /**
  1015. \brief Get MSA1
  1016. \details Returns the content of the MSA1 Register.
  1017. \return MSA1 Register value
  1018. */
  1019. __ALWAYS_STATIC_INLINE uint32_t __get_MSA1(void)
  1020. {
  1021. uint32_t result;
  1022. #ifdef __CK610
  1023. __ASM volatile("cpseti 15");
  1024. __ASM volatile("cprcr %0, cpcr31" : "=r"(result));
  1025. #else
  1026. __ASM volatile("mfcr %0, cr<31, 15>" : "=r"(result));
  1027. #endif
  1028. return (result);
  1029. }
  1030. /**
  1031. \brief Set MSA1
  1032. \details Writes the given value to the MSA1 Register.
  1033. \param [in] msa1 MSA1 Register value to set
  1034. */
  1035. __ALWAYS_STATIC_INLINE void __set_MSA1(uint32_t msa1)
  1036. {
  1037. #ifdef __CK610
  1038. __ASM volatile("cpseti 15");
  1039. __ASM volatile("cpwcr %0, cpcr31" : : "b"(msa1));
  1040. #else
  1041. __ASM volatile("mtcr %0, cr<31, 15>" : : "r"(msa1));
  1042. #endif
  1043. }
  1044. /**
  1045. \brief Enable interrupts and exceptions
  1046. \details Enables interrupts and exceptions by setting the IE-bit and EE-bit in the PSR.
  1047. Can only be executed in Privileged modes.
  1048. */
  1049. __ALWAYS_STATIC_INLINE void __enable_excp_irq(void)
  1050. {
  1051. __ASM volatile("psrset ee, ie");
  1052. }
  1053. /**
  1054. \brief Disable interrupts and exceptions
  1055. \details Disables interrupts and exceptions by clearing the IE-bit and EE-bit in the PSR.
  1056. Can only be executed in Privileged modes.
  1057. */
  1058. __ALWAYS_STATIC_INLINE void __disable_excp_irq(void)
  1059. {
  1060. __ASM volatile("psrclr ee, ie");
  1061. }
  1062. /**
  1063. \brief Get GSR
  1064. \details Returns the content of the GSR Register.
  1065. \return GSR Register value
  1066. */
  1067. __ALWAYS_STATIC_INLINE uint32_t __get_GSR(void)
  1068. {
  1069. uint32_t result;
  1070. #ifdef __CK610
  1071. __ASM volatile("mfcr %0, cr12" : "=r"(result));
  1072. #else
  1073. __ASM volatile("mfcr %0, cr<12, 0>" : "=r"(result));
  1074. #endif
  1075. return (result);
  1076. }
  1077. /**
  1078. \brief Get GCR
  1079. \details Returns the content of the GCR Register.
  1080. \return GCR Register value
  1081. */
  1082. __ALWAYS_STATIC_INLINE uint32_t __get_GCR(void)
  1083. {
  1084. uint32_t result;
  1085. #ifdef __CK610
  1086. __ASM volatile("mfcr %0, cr11" : "=r"(result));
  1087. #else
  1088. __ASM volatile("mfcr %0, cr<11, 0>" : "=r"(result));
  1089. #endif
  1090. return (result);
  1091. }
  1092. /**
  1093. \brief Set GCR
  1094. \details Writes the given value to the GCR Register.
  1095. \param [in] gcr GCR Register value to set
  1096. */
  1097. __ALWAYS_STATIC_INLINE void __set_GCR(uint32_t gcr)
  1098. {
  1099. #ifdef __CK610
  1100. __ASM volatile("mtcr %0, cr11" : : "r"(gcr));
  1101. #else
  1102. __ASM volatile("mtcr %0, cr<11, 0>" : : "r"(gcr));
  1103. #endif
  1104. }
  1105. /**
  1106. \brief Get WSSR
  1107. \details Returns the content of the WSSR Register, must be accessed in TEE
  1108. \return WSSR Register value
  1109. */
  1110. __ALWAYS_STATIC_INLINE uint32_t __get_WSSR(void)
  1111. {
  1112. uint32_t result;
  1113. __ASM volatile("mfcr %0, cr<0, 3>" : "=r"(result));
  1114. return (result);
  1115. }
  1116. /**
  1117. \brief Get WRCR
  1118. \details Returns the content of the WRCR Register, must be accessed in TEE
  1119. \return WRCR Register value
  1120. */
  1121. __ALWAYS_STATIC_INLINE uint32_t __get_WRCR(void)
  1122. {
  1123. uint32_t result;
  1124. __ASM volatile("mfcr %0, cr<1, 3>" : "=r"(result));
  1125. return (result);
  1126. }
  1127. /**
  1128. \brief Set WRCR
  1129. \details Writes the given value to the WRCR Register, must be accessed in TEE
  1130. \param [in] wrcr WRCR Register value to set
  1131. */
  1132. __ALWAYS_STATIC_INLINE void __set_WRCR(uint32_t wrcr)
  1133. {
  1134. __ASM volatile("mtcr %0, cr<1, 3>" : : "r"(wrcr));
  1135. }
  1136. /**
  1137. \brief Get DCR
  1138. \details Returns the content of the DCR Register, must be accessed in TEE
  1139. \return DCR Register value
  1140. */
  1141. __ALWAYS_STATIC_INLINE uint32_t __get_DCR(void)
  1142. {
  1143. uint32_t result;
  1144. __ASM volatile("mfcr %0, cr<8, 3>" : "=r"(result));
  1145. return (result);
  1146. }
  1147. /**
  1148. \brief Set DCR
  1149. \details Writes the given value to the DCR Register, must be accessed in TEE
  1150. \param [in] dcr DCR Register value to set
  1151. */
  1152. __ALWAYS_STATIC_INLINE void __set_DCR(uint32_t dcr)
  1153. {
  1154. __ASM volatile("mtcr %0, cr<8, 3>" : : "r"(dcr));
  1155. }
  1156. /**
  1157. \brief Get PCR
  1158. \details Returns the content of the PCR Register, must be accessed in TEE
  1159. \return PCR Register value
  1160. */
  1161. __ALWAYS_STATIC_INLINE uint32_t __get_PCR(void)
  1162. {
  1163. uint32_t result;
  1164. __ASM volatile("mfcr %0, cr<9, 3>" : "=r"(result));
  1165. return (result);
  1166. }
  1167. /**
  1168. \brief Set PCR
  1169. \details Writes the given value to the PCR Register, must be accessed in TEE
  1170. \param [in] pcr PCR Register value to set
  1171. */
  1172. __ALWAYS_STATIC_INLINE void __set_PCR(uint32_t pcr)
  1173. {
  1174. __ASM volatile("mtcr %0, cr<9, 3>" : : "r"(pcr));
  1175. }
  1176. /**
  1177. \brief Get EBR
  1178. \details Returns the content of the EBR Register.
  1179. \return EBR Register value
  1180. */
  1181. __ALWAYS_STATIC_INLINE uint32_t __get_EBR(void)
  1182. {
  1183. uint32_t result;
  1184. __ASM volatile("mfcr %0, cr<1, 1>" : "=r"(result));
  1185. return (result);
  1186. }
  1187. /**
  1188. \brief Set EBR
  1189. \details Writes the given value to the EBR Register.
  1190. \param [in] ebr EBR Register value to set
  1191. */
  1192. __ALWAYS_STATIC_INLINE void __set_EBR(uint32_t ebr)
  1193. {
  1194. __ASM volatile("mtcr %0, cr<1, 1>" : : "r"(ebr));
  1195. }
  1196. /*@} end of CSI_Core_RegAccFunctions */
  1197. /* ########################## Core Instruction Access ######################### */
  1198. /** \defgroup CSI_Core_InstructionInterface CSI Core Instruction Interface
  1199. Access to dedicated instructions
  1200. @{
  1201. */
  1202. #define __CSI_GCC_OUT_REG(r) "=r" (r)
  1203. #define __CSI_GCC_USE_REG(r) "r" (r)
  1204. /**
  1205. \brief No Operation
  1206. \details No Operation does nothing. This instruction can be used for code alignment purposes.
  1207. */
  1208. __ALWAYS_STATIC_INLINE void __NOP(void)
  1209. {
  1210. __ASM volatile("nop");
  1211. }
  1212. /**
  1213. \brief Wait For Interrupt
  1214. \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
  1215. */
  1216. __ALWAYS_STATIC_INLINE void __WFI(void)
  1217. {
  1218. __ASM volatile("wait");
  1219. }
  1220. /**
  1221. \brief Wait For Interrupt
  1222. \details Wait For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
  1223. */
  1224. __ALWAYS_STATIC_INLINE void __WAIT(void)
  1225. {
  1226. __ASM volatile("wait");
  1227. }
  1228. /**
  1229. \brief Doze For Interrupt
  1230. \details Doze For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
  1231. */
  1232. __ALWAYS_STATIC_INLINE void __DOZE(void)
  1233. {
  1234. __ASM volatile("doze");
  1235. }
  1236. /**
  1237. \brief Stop For Interrupt
  1238. \details Stop For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
  1239. */
  1240. __ALWAYS_STATIC_INLINE void __STOP(void)
  1241. {
  1242. __ASM volatile("stop");
  1243. }
  1244. /**
  1245. \brief Instruction Synchronization Barrier
  1246. \details Instruction Synchronization Barrier flushes the pipeline in the processor,
  1247. so that all instructions following the ISB are fetched from cache or memory,
  1248. after the instruction has been completed.
  1249. */
  1250. __ALWAYS_STATIC_INLINE void __ISB(void)
  1251. {
  1252. __ASM volatile("sync"::: "memory");
  1253. }
  1254. /**
  1255. \brief Data Synchronization Barrier
  1256. \details Acts as a special kind of Data Memory Barrier.
  1257. It completes when all explicit memory accesses before this instruction complete.
  1258. */
  1259. __ALWAYS_STATIC_INLINE void __DSB(void)
  1260. {
  1261. __ASM volatile("sync"::: "memory");
  1262. }
  1263. /**
  1264. \brief Data Memory Barrier
  1265. \details Ensures the apparent order of the explicit memory operations before
  1266. and after the instruction, without ensuring their completion.
  1267. */
  1268. __ALWAYS_STATIC_INLINE void __DMB(void)
  1269. {
  1270. __ASM volatile("sync"::: "memory");
  1271. }
  1272. /**
  1273. \brief Search from the highest bit that the very first bit which's value is 1.
  1274. \param [in] value Value to bit search.
  1275. \return if the highest bit' value is 1, return 0, and if lowest bit's value is 1, return 31, otherwise return 32.
  1276. */
  1277. #if !defined(__CK610) || !(__CK80X == 1)
  1278. __ALWAYS_STATIC_INLINE uint32_t __FF0(uint32_t value)
  1279. {
  1280. uint32_t ret;
  1281. __ASM volatile("ff0 %0, %1" : "=r"(ret) : "r"(value));
  1282. return ret;
  1283. }
  1284. #endif
  1285. /**
  1286. \brief Search from the highest bit that the very first bit which's value is 0.
  1287. \param [in] value Value to bit search.
  1288. \return if the highest bit' value is 0, return 0, and if lowest bit's value is 0, return 31, otherwise return 32.
  1289. */
  1290. #if !(__CK80X == 1)
  1291. __ALWAYS_STATIC_INLINE uint32_t __FF1(uint32_t value)
  1292. {
  1293. uint32_t ret;
  1294. #if !defined (__CK610)
  1295. __ASM volatile("ff1 %0, %1" : "=r"(ret) : "r"(value));
  1296. #else
  1297. ret = value;
  1298. __ASM volatile("ff1 %0" : "=r"(ret):);
  1299. #endif
  1300. return ret;
  1301. }
  1302. #endif
  1303. /**
  1304. \brief Reverse byte order (32 bit)
  1305. \details Reverses the byte order in integer value.
  1306. \param [in] value Value to reverse
  1307. \return Reversed value
  1308. */
  1309. __ALWAYS_STATIC_INLINE uint32_t __REV(uint32_t value)
  1310. {
  1311. return __builtin_bswap32(value);
  1312. }
  1313. /**
  1314. \brief Reverse byte order (16 bit)
  1315. \details Reverses the byte order in two unsigned short values.
  1316. \param [in] value Value to reverse
  1317. \return Reversed value
  1318. */
  1319. __ALWAYS_STATIC_INLINE uint32_t __REV16(uint32_t value)
  1320. {
  1321. uint32_t result;
  1322. #if (__CK80X >= 2)
  1323. __ASM volatile("revh %0, %1" : __CSI_GCC_OUT_REG(result) : __CSI_GCC_USE_REG(value));
  1324. #else
  1325. result = ((value & 0xFF000000) >> 8) | ((value & 0x00FF0000) << 8) |
  1326. ((value & 0x0000FF00) >> 8) | ((value & 0x000000FF) << 8);
  1327. #endif
  1328. return (result);
  1329. }
  1330. /**
  1331. \brief Reverse byte order in signed short value
  1332. \details Reverses the byte order in a signed short value with sign extension to integer.
  1333. \param [in] value Value to reverse
  1334. \return Reversed value
  1335. */
  1336. __ALWAYS_STATIC_INLINE int32_t __REVSH(int32_t value)
  1337. {
  1338. return (short)(((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8));
  1339. }
  1340. /**
  1341. \brief Rotate Right in unsigned value (32 bit)
  1342. \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
  1343. \param [in] op1 Value to rotate
  1344. \param [in] op2 Number of Bits to rotate
  1345. \return Rotated value
  1346. */
  1347. __ALWAYS_STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
  1348. {
  1349. return (op1 >> op2) | (op1 << (32U - op2));
  1350. }
  1351. /**
  1352. \brief Breakpoint
  1353. \details Causes the processor to enter Debug state
  1354. Debug tools can use this to investigate system state when the instruction at a particular address is reached.
  1355. */
  1356. __ALWAYS_STATIC_INLINE void __BKPT(void)
  1357. {
  1358. __ASM volatile("bkpt");
  1359. }
  1360. /**
  1361. \brief Reverse bit order of value
  1362. \details Reverses the bit order of the given value.
  1363. \param [in] value Value to reverse
  1364. \return Reversed value
  1365. */
  1366. __ALWAYS_STATIC_INLINE uint32_t __RBIT(uint32_t value)
  1367. {
  1368. uint32_t result;
  1369. #if (__CK80X >= 0x03U)
  1370. __ASM volatile("brev %0, %1" : "=r"(result) : "r"(value));
  1371. #else
  1372. int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
  1373. result = value; /* r will be reversed bits of v; first get LSB of v */
  1374. for (value >>= 1U; value; value >>= 1U) {
  1375. result <<= 1U;
  1376. result |= value & 1U;
  1377. s--;
  1378. }
  1379. result <<= s; /* shift when v's highest bits are zero */
  1380. #endif
  1381. return (result);
  1382. }
  1383. /**
  1384. \brief Count leading zeros
  1385. \details Counts the number of leading zeros of a data value.
  1386. \param [in] value Value to count the leading zeros
  1387. \return number of leading zeros in value
  1388. */
  1389. #define __CLZ __builtin_clz
  1390. /**
  1391. \details This function saturates a signed value.
  1392. \param [in] x Value to be saturated
  1393. \param [in] y Bit position to saturate to [1..32]
  1394. \return Saturated value.
  1395. */
  1396. __ALWAYS_STATIC_INLINE int32_t __SSAT(int32_t x, uint32_t y)
  1397. {
  1398. int32_t posMax, negMin;
  1399. uint32_t i;
  1400. posMax = 1;
  1401. for (i = 0; i < (y - 1); i++) {
  1402. posMax = posMax * 2;
  1403. }
  1404. if (x > 0) {
  1405. posMax = (posMax - 1);
  1406. if (x > posMax) {
  1407. x = posMax;
  1408. }
  1409. // x &= (posMax * 2 + 1);
  1410. } else {
  1411. negMin = -posMax;
  1412. if (x < negMin) {
  1413. x = negMin;
  1414. }
  1415. // x &= (posMax * 2 - 1);
  1416. }
  1417. return (x);
  1418. }
  1419. /**
  1420. \brief Unsigned Saturate
  1421. \details Saturates an unsigned value.
  1422. \param [in] value Value to be saturated
  1423. \param [in] sat Bit position to saturate to (0..31)
  1424. \return Saturated value
  1425. */
  1426. __ALWAYS_STATIC_INLINE uint32_t __USAT(uint32_t value, uint32_t sat)
  1427. {
  1428. uint32_t result;
  1429. if ((((0xFFFFFFFF >> sat) << sat) & value) != 0) {
  1430. result = 0xFFFFFFFF >> (32 - sat);
  1431. } else {
  1432. result = value;
  1433. }
  1434. return (result);
  1435. }
  1436. /**
  1437. \brief Unsigned Saturate for internal use
  1438. \details Saturates an unsigned value, should not call directly.
  1439. \param [in] value Value to be saturated
  1440. \param [in] sat Bit position to saturate to (0..31)
  1441. \return Saturated value
  1442. */
  1443. __ALWAYS_STATIC_INLINE uint32_t __IUSAT(uint32_t value, uint32_t sat)
  1444. {
  1445. uint32_t result;
  1446. if (value & 0x80000000) { /* only overflow set bit-31 */
  1447. result = 0;
  1448. } else if ((((0xFFFFFFFF >> sat) << sat) & value) != 0) {
  1449. result = 0xFFFFFFFF >> (32 - sat);
  1450. } else {
  1451. result = value;
  1452. }
  1453. return (result);
  1454. }
  1455. /**
  1456. \brief Rotate Right with Extend
  1457. \details This function moves each bit of a bitstring right by one bit.
  1458. The carry input is shifted in at the left end of the bitstring.
  1459. \note carry input will always 0.
  1460. \param [in] op1 Value to rotate
  1461. \return Rotated value
  1462. */
  1463. __ALWAYS_STATIC_INLINE uint32_t __RRX(uint32_t op1)
  1464. {
  1465. #if (__CK80X >= 2)
  1466. uint32_t res = 0;
  1467. __ASM volatile("bgeni t0, 31\n\t"
  1468. "lsri %0, 1\n\t"
  1469. "movt %1, t0\n\t"
  1470. "or %1, %1, %0\n\t"
  1471. : "=r"(op1), "=r"(res): "0"(op1), "1"(res): "t0");
  1472. return res;
  1473. #else
  1474. uint32_t res = 0;
  1475. __ASM volatile("movi r7, 0\n\t"
  1476. "bseti r7, 31\n\t"
  1477. "lsri %0, 1\n\t"
  1478. "bf 1f\n\t"
  1479. "mov %1, r7\n\t"
  1480. "1:\n\t"
  1481. "or %1, %1, %0\n\t"
  1482. : "=r"(op1), "=r"(res): "0"(op1), "1"(res): "r7");
  1483. return res;
  1484. #endif
  1485. }
  1486. /**
  1487. \brief LDRT Unprivileged (8 bit)
  1488. \details Executes a Unprivileged LDRT instruction for 8 bit value.
  1489. \param [in] addr Pointer to location
  1490. \return value of type uint8_t at (*ptr)
  1491. */
  1492. __ALWAYS_STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr)
  1493. {
  1494. uint32_t result;
  1495. //#warning "__LDRBT"
  1496. __ASM volatile("ldb %0, (%1, 0)" : "=r"(result) : "r"(addr));
  1497. return ((uint8_t) result); /* Add explicit type cast here */
  1498. }
  1499. /**
  1500. \brief LDRT Unprivileged (16 bit)
  1501. \details Executes a Unprivileged LDRT instruction for 16 bit values.
  1502. \param [in] addr Pointer to location
  1503. \return value of type uint16_t at (*ptr)
  1504. */
  1505. __ALWAYS_STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr)
  1506. {
  1507. uint32_t result;
  1508. //#warning "__LDRHT"
  1509. __ASM volatile("ldh %0, (%1, 0)" : "=r"(result) : "r"(addr));
  1510. return ((uint16_t) result); /* Add explicit type cast here */
  1511. }
  1512. /**
  1513. \brief LDRT Unprivileged (32 bit)
  1514. \details Executes a Unprivileged LDRT instruction for 32 bit values.
  1515. \param [in] addr Pointer to location
  1516. \return value of type uint32_t at (*ptr)
  1517. */
  1518. __ALWAYS_STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr)
  1519. {
  1520. uint32_t result;
  1521. //#warning "__LDRT"
  1522. __ASM volatile("ldw %0, (%1, 0)" : "=r"(result) : "r"(addr));
  1523. return (result);
  1524. }
  1525. /**
  1526. \brief STRT Unprivileged (8 bit)
  1527. \details Executes a Unprivileged STRT instruction for 8 bit values.
  1528. \param [in] value Value to store
  1529. \param [in] addr Pointer to location
  1530. */
  1531. __ALWAYS_STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr)
  1532. {
  1533. //#warning "__STRBT"
  1534. __ASM volatile("stb %1, (%0, 0)" :: "r"(addr), "r"((uint32_t)value) : "memory");
  1535. }
  1536. /**
  1537. \brief STRT Unprivileged (16 bit)
  1538. \details Executes a Unprivileged STRT instruction for 16 bit values.
  1539. \param [in] value Value to store
  1540. \param [in] addr Pointer to location
  1541. */
  1542. __ALWAYS_STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr)
  1543. {
  1544. //#warning "__STRHT"
  1545. __ASM volatile("sth %1, (%0, 0)" :: "r"(addr), "r"((uint32_t)value) : "memory");
  1546. }
  1547. /**
  1548. \brief STRT Unprivileged (32 bit)
  1549. \details Executes a Unprivileged STRT instruction for 32 bit values.
  1550. \param [in] value Value to store
  1551. \param [in] addr Pointer to location
  1552. */
  1553. __ALWAYS_STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr)
  1554. {
  1555. //#warning "__STRT"
  1556. __ASM volatile("stw %1, (%0, 0)" :: "r"(addr), "r"(value) : "memory");
  1557. }
  1558. /*@}*/ /* end of group CSI_Core_InstructionInterface */
  1559. /* ########################## FPU functions #################################### */
  1560. /**
  1561. \ingroup CSI_Core_FunctionInterface
  1562. \defgroup CSI_Core_FpuFunctions FPU Functions
  1563. \brief Function that provides FPU type.
  1564. @{
  1565. */
  1566. /**
  1567. \brief get FPU type
  1568. \details returns the FPU type, always 0.
  1569. \returns
  1570. - \b 0: No FPU
  1571. - \b 1: Single precision FPU
  1572. - \b 2: Double + Single precision FPU
  1573. */
  1574. __ALWAYS_STATIC_INLINE uint32_t __get_FPUType(void)
  1575. {
  1576. //FIXME:
  1577. return 0;
  1578. }
  1579. /*@} end of CSI_Core_FpuFunctions */
  1580. /* ################### Compiler specific Intrinsics ########################### */
  1581. /** \defgroup CSI_SIMD_intrinsics CSI SIMD Intrinsics
  1582. Access to dedicated SIMD instructions \n
  1583. Single Instruction Multiple Data (SIMD) extensions are provided to simplify development of application software. SIMD extensions increase the processing capability without materially increasing the power consumption. The SIMD extensions are completely transparent to the operating system (OS), allowing existing OS ports to be used.
  1584. @{
  1585. */
  1586. /**
  1587. \brief Halfword packing instruction. Combines bits[15:0] of val1 with bits[31:16]
  1588. of val2 levitated with the val3.
  1589. \details Combine a halfword from one register with a halfword from another register.
  1590. The second argument can be left-shifted before extraction of the halfword.
  1591. \param [in] val1 first 16-bit operands
  1592. \param [in] val2 second 16-bit operands
  1593. \param [in] val3 value for left-shifting val2. Value range [0..31].
  1594. \return the combination of halfwords.
  1595. \remark
  1596. res[15:0] = val1[15:0] \n
  1597. res[31:16] = val2[31:16] << val3
  1598. */
  1599. __ALWAYS_STATIC_INLINE uint32_t __PKHBT(uint32_t val1, uint32_t val2, uint32_t val3)
  1600. {
  1601. return ((((int32_t)(val1) << 0) & (int32_t)0x0000FFFF) | (((int32_t)(val2) << val3) & (int32_t)0xFFFF0000));
  1602. }
  1603. /**
  1604. \brief Halfword packing instruction. Combines bits[31:16] of val1 with bits[15:0]
  1605. of val2 right-shifted with the val3.
  1606. \details Combine a halfword from one register with a halfword from another register.
  1607. The second argument can be right-shifted before extraction of the halfword.
  1608. \param [in] val1 first 16-bit operands
  1609. \param [in] val2 second 16-bit operands
  1610. \param [in] val3 value for right-shifting val2. Value range [1..32].
  1611. \return the combination of halfwords.
  1612. \remark
  1613. res[15:0] = val2[15:0] >> val3 \n
  1614. res[31:16] = val1[31:16]
  1615. */
  1616. __ALWAYS_STATIC_INLINE uint32_t __PKHTB(uint32_t val1, uint32_t val2, uint32_t val3)
  1617. {
  1618. return ((((int32_t)(val1) << 0) & (int32_t)0xFFFF0000) | (((int32_t)(val2) >> val3) & (int32_t)0x0000FFFF));
  1619. }
  1620. /**
  1621. \brief Dual 16-bit signed saturate.
  1622. \details This function saturates a signed value.
  1623. \param [in] x two signed 16-bit values to be saturated.
  1624. \param [in] y bit position for saturation, an integral constant expression in the range 1 to 16.
  1625. \return the sum of the absolute differences of the following bytes, added to the accumulation value:\n
  1626. the signed saturation of the low halfword in val1, saturated to the bit position specified in
  1627. val2 and returned in the low halfword of the return value.\n
  1628. the signed saturation of the high halfword in val1, saturated to the bit position specified in
  1629. val2 and returned in the high halfword of the return value.
  1630. */
  1631. __ALWAYS_STATIC_INLINE uint32_t __SSAT16(int32_t x, const uint32_t y)
  1632. {
  1633. int32_t r = 0, s = 0;
  1634. r = __SSAT((((int32_t)x << 16) >> 16), y) & (int32_t)0x0000FFFF;
  1635. s = __SSAT((((int32_t)x) >> 16), y) & (int32_t)0x0000FFFF;
  1636. return ((uint32_t)((s << 16) | (r)));
  1637. }
  1638. /**
  1639. \brief Dual 16-bit unsigned saturate.
  1640. \details This function enables you to saturate two signed 16-bit values to a selected unsigned range.
  1641. \param [in] x two signed 16-bit values to be saturated.
  1642. \param [in] y bit position for saturation, an integral constant expression in the range 1 to 16.
  1643. \return the saturation of the two signed 16-bit values, as non-negative values:
  1644. the saturation of the low halfword in val1, saturated to the bit position specified in
  1645. val2 and returned in the low halfword of the return value.\n
  1646. the saturation of the high halfword in val1, saturated to the bit position specified in
  1647. val2 and returned in the high halfword of the return value.
  1648. */
  1649. __ALWAYS_STATIC_INLINE uint32_t __USAT16(uint32_t x, const uint32_t y)
  1650. {
  1651. int32_t r = 0, s = 0;
  1652. r = __IUSAT(((x << 16) >> 16), y) & 0x0000FFFF;
  1653. s = __IUSAT(((x) >> 16), y) & 0x0000FFFF;
  1654. return ((s << 16) | (r));
  1655. }
  1656. /**
  1657. \brief Quad 8-bit saturating addition.
  1658. \details This function enables you to perform four 8-bit integer additions,
  1659. saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
  1660. \param [in] x first four 8-bit summands.
  1661. \param [in] y second four 8-bit summands.
  1662. \return the saturated addition of the first byte of each operand in the first byte of the return value.\n
  1663. the saturated addition of the second byte of each operand in the second byte of the return value.\n
  1664. the saturated addition of the third byte of each operand in the third byte of the return value.\n
  1665. the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
  1666. The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
  1667. \remark
  1668. res[7:0] = val1[7:0] + val2[7:0] \n
  1669. res[15:8] = val1[15:8] + val2[15:8] \n
  1670. res[23:16] = val1[23:16] + val2[23:16] \n
  1671. res[31:24] = val1[31:24] + val2[31:24]
  1672. */
  1673. __ALWAYS_STATIC_INLINE uint32_t __QADD8(uint32_t x, uint32_t y)
  1674. {
  1675. int32_t r, s, t, u;
  1676. r = __SSAT(((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1677. s = __SSAT(((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1678. t = __SSAT(((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1679. u = __SSAT(((((int32_t)x) >> 24) + (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
  1680. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  1681. }
  1682. /**
  1683. \brief Quad 8-bit unsigned saturating addition.
  1684. \details This function enables you to perform four unsigned 8-bit integer additions,
  1685. saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
  1686. \param [in] x first four 8-bit summands.
  1687. \param [in] y second four 8-bit summands.
  1688. \return the saturated addition of the first byte of each operand in the first byte of the return value.\n
  1689. the saturated addition of the second byte of each operand in the second byte of the return value.\n
  1690. the saturated addition of the third byte of each operand in the third byte of the return value.\n
  1691. the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
  1692. The returned results are saturated to the 8-bit signed integer range 0 <= x <= 2^8 - 1.
  1693. \remark
  1694. res[7:0] = val1[7:0] + val2[7:0] \n
  1695. res[15:8] = val1[15:8] + val2[15:8] \n
  1696. res[23:16] = val1[23:16] + val2[23:16] \n
  1697. res[31:24] = val1[31:24] + val2[31:24]
  1698. */
  1699. __ALWAYS_STATIC_INLINE uint32_t __UQADD8(uint32_t x, uint32_t y)
  1700. {
  1701. int32_t r, s, t, u;
  1702. r = __IUSAT((((x << 24) >> 24) + ((y << 24) >> 24)), 8) & 0x000000FF;
  1703. s = __IUSAT((((x << 16) >> 24) + ((y << 16) >> 24)), 8) & 0x000000FF;
  1704. t = __IUSAT((((x << 8) >> 24) + ((y << 8) >> 24)), 8) & 0x000000FF;
  1705. u = __IUSAT((((x) >> 24) + ((y) >> 24)), 8) & 0x000000FF;
  1706. return ((u << 24) | (t << 16) | (s << 8) | (r));
  1707. }
  1708. /**
  1709. \brief Quad 8-bit signed addition.
  1710. \details This function performs four 8-bit signed integer additions.
  1711. \param [in] x first four 8-bit summands.
  1712. \param [in] y second four 8-bit summands.
  1713. \return the addition of the first bytes from each operand, in the first byte of the return value.\n
  1714. the addition of the second bytes of each operand, in the second byte of the return value.\n
  1715. the addition of the third bytes of each operand, in the third byte of the return value.\n
  1716. the addition of the fourth bytes of each operand, in the fourth byte of the return value.
  1717. \remark
  1718. res[7:0] = val1[7:0] + val2[7:0] \n
  1719. res[15:8] = val1[15:8] + val2[15:8] \n
  1720. res[23:16] = val1[23:16] + val2[23:16] \n
  1721. res[31:24] = val1[31:24] + val2[31:24]
  1722. */
  1723. __ALWAYS_STATIC_INLINE uint32_t __SADD8(uint32_t x, uint32_t y)
  1724. {
  1725. int32_t r, s, t, u;
  1726. r = ((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
  1727. s = ((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
  1728. t = ((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)) & (int32_t)0x000000FF;
  1729. u = ((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
  1730. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  1731. }
  1732. /**
  1733. \brief Quad 8-bit unsigned addition.
  1734. \details This function performs four unsigned 8-bit integer additions.
  1735. \param [in] x first four 8-bit summands.
  1736. \param [in] y second four 8-bit summands.
  1737. \return the addition of the first bytes from each operand, in the first byte of the return value.\n
  1738. the addition of the second bytes of each operand, in the second byte of the return value.\n
  1739. the addition of the third bytes of each operand, in the third byte of the return value.\n
  1740. the addition of the fourth bytes of each operand, in the fourth byte of the return value.
  1741. \remark
  1742. res[7:0] = val1[7:0] + val2[7:0] \n
  1743. res[15:8] = val1[15:8] + val2[15:8] \n
  1744. res[23:16] = val1[23:16] + val2[23:16] \n
  1745. res[31:24] = val1[31:24] + val2[31:24]
  1746. */
  1747. __ALWAYS_STATIC_INLINE uint32_t __UADD8(uint32_t x, uint32_t y)
  1748. {
  1749. int32_t r, s, t, u;
  1750. r = (((x << 24) >> 24) + ((y << 24) >> 24)) & 0x000000FF;
  1751. s = (((x << 16) >> 24) + ((y << 16) >> 24)) & 0x000000FF;
  1752. t = (((x << 8) >> 24) + ((y << 8) >> 24)) & 0x000000FF;
  1753. u = (((x) >> 24) + ((y) >> 24)) & 0x000000FF;
  1754. return ((u << 24) | (t << 16) | (s << 8) | (r));
  1755. }
  1756. /**
  1757. \brief Quad 8-bit saturating subtract.
  1758. \details This function enables you to perform four 8-bit integer subtractions,
  1759. saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
  1760. \param [in] x first four 8-bit summands.
  1761. \param [in] y second four 8-bit summands.
  1762. \return the subtraction of the first byte of each operand in the first byte of the return value.\n
  1763. the subtraction of the second byte of each operand in the second byte of the return value.\n
  1764. the subtraction of the third byte of each operand in the third byte of the return value.\n
  1765. the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
  1766. The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
  1767. \remark
  1768. res[7:0] = val1[7:0] - val2[7:0] \n
  1769. res[15:8] = val1[15:8] - val2[15:8] \n
  1770. res[23:16] = val1[23:16] - val2[23:16] \n
  1771. res[31:24] = val1[31:24] - val2[31:24]
  1772. */
  1773. __ALWAYS_STATIC_INLINE uint32_t __QSUB8(uint32_t x, uint32_t y)
  1774. {
  1775. int32_t r, s, t, u;
  1776. r = __SSAT(((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1777. s = __SSAT(((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1778. t = __SSAT(((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1779. u = __SSAT(((((int32_t)x) >> 24) - (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
  1780. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  1781. }
  1782. /**
  1783. \brief Quad 8-bit unsigned saturating subtraction.
  1784. \details This function enables you to perform four unsigned 8-bit integer subtractions,
  1785. saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
  1786. \param [in] x first four 8-bit summands.
  1787. \param [in] y second four 8-bit summands.
  1788. \return the subtraction of the first byte of each operand in the first byte of the return value.\n
  1789. the subtraction of the second byte of each operand in the second byte of the return value.\n
  1790. the subtraction of the third byte of each operand in the third byte of the return value.\n
  1791. the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
  1792. The returned results are saturated to the 8-bit unsigned integer range 0 <= x <= 2^8 - 1.
  1793. \remark
  1794. res[7:0] = val1[7:0] - val2[7:0] \n
  1795. res[15:8] = val1[15:8] - val2[15:8] \n
  1796. res[23:16] = val1[23:16] - val2[23:16] \n
  1797. res[31:24] = val1[31:24] - val2[31:24]
  1798. */
  1799. __ALWAYS_STATIC_INLINE uint32_t __UQSUB8(uint32_t x, uint32_t y)
  1800. {
  1801. int32_t r, s, t, u;
  1802. r = __IUSAT((((x << 24) >> 24) - ((y << 24) >> 24)), 8) & 0x000000FF;
  1803. s = __IUSAT((((x << 16) >> 24) - ((y << 16) >> 24)), 8) & 0x000000FF;
  1804. t = __IUSAT((((x << 8) >> 24) - ((y << 8) >> 24)), 8) & 0x000000FF;
  1805. u = __IUSAT((((x) >> 24) - ((y) >> 24)), 8) & 0x000000FF;
  1806. return ((u << 24) | (t << 16) | (s << 8) | (r));
  1807. }
  1808. /**
  1809. \brief Quad 8-bit signed subtraction.
  1810. \details This function enables you to perform four 8-bit signed integer subtractions.
  1811. \param [in] x first four 8-bit operands of each subtraction.
  1812. \param [in] y second four 8-bit operands of each subtraction.
  1813. \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
  1814. the subtraction of the second bytes of each operand, in the second byte of the return value.\n
  1815. the subtraction of the third bytes of each operand, in the third byte of the return value.\n
  1816. the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
  1817. \remark
  1818. res[7:0] = val1[7:0] - val2[7:0] \n
  1819. res[15:8] = val1[15:8] - val2[15:8] \n
  1820. res[23:16] = val1[23:16] - val2[23:16] \n
  1821. res[31:24] = val1[31:24] - val2[31:24]
  1822. */
  1823. __ALWAYS_STATIC_INLINE uint32_t __SSUB8(uint32_t x, uint32_t y)
  1824. {
  1825. int32_t r, s, t, u;
  1826. r = ((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
  1827. s = ((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
  1828. t = ((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)) & (int32_t)0x000000FF;
  1829. u = ((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
  1830. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  1831. }
  1832. /**
  1833. \brief Quad 8-bit unsigned subtract.
  1834. \details This function enables you to perform four 8-bit unsigned integer subtractions.
  1835. \param [in] x first four 8-bit operands of each subtraction.
  1836. \param [in] y second four 8-bit operands of each subtraction.
  1837. \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
  1838. the subtraction of the second bytes of each operand, in the second byte of the return value.\n
  1839. the subtraction of the third bytes of each operand, in the third byte of the return value.\n
  1840. the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
  1841. \remark
  1842. res[7:0] = val1[7:0] - val2[7:0] \n
  1843. res[15:8] = val1[15:8] - val2[15:8] \n
  1844. res[23:16] = val1[23:16] - val2[23:16] \n
  1845. res[31:24] = val1[31:24] - val2[31:24]
  1846. */
  1847. __ALWAYS_STATIC_INLINE uint32_t __USUB8(uint32_t x, uint32_t y)
  1848. {
  1849. int32_t r, s, t, u;
  1850. r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
  1851. s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
  1852. t = (((x << 8) >> 24) - ((y << 8) >> 24)) & 0x000000FF;
  1853. u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
  1854. return ((u << 24) | (t << 16) | (s << 8) | (r));
  1855. }
  1856. /**
  1857. \brief Unsigned sum of quad 8-bit unsigned absolute difference.
  1858. \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
  1859. of the differences together, returning the result as a single unsigned integer.
  1860. \param [in] x first four 8-bit operands of each subtraction.
  1861. \param [in] y second four 8-bit operands of each subtraction.
  1862. \return the subtraction of the first bytes from each operand, in the first byte of the return value.\n
  1863. the subtraction of the second bytes of each operand, in the second byte of the return value.\n
  1864. the subtraction of the third bytes of each operand, in the third byte of the return value.\n
  1865. the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.\n
  1866. The sum is returned as a single unsigned integer.
  1867. \remark
  1868. absdiff1 = val1[7:0] - val2[7:0] \n
  1869. absdiff2 = val1[15:8] - val2[15:8] \n
  1870. absdiff3 = val1[23:16] - val2[23:16] \n
  1871. absdiff4 = val1[31:24] - val2[31:24] \n
  1872. res[31:0] = absdiff1 + absdiff2 + absdiff3 + absdiff4
  1873. */
  1874. __ALWAYS_STATIC_INLINE uint32_t __USAD8(uint32_t x, uint32_t y)
  1875. {
  1876. int32_t r, s, t, u;
  1877. r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
  1878. s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
  1879. t = (((x << 8) >> 24) - ((y << 8) >> 24)) & 0x000000FF;
  1880. u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
  1881. return (u + t + s + r);
  1882. }
  1883. /**
  1884. \brief Unsigned sum of quad 8-bit unsigned absolute difference with 32-bit accumulate.
  1885. \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
  1886. of the differences to a 32-bit accumulate operand.
  1887. \param [in] x first four 8-bit operands of each subtraction.
  1888. \param [in] y second four 8-bit operands of each subtraction.
  1889. \param [in] sum accumulation value.
  1890. \return the sum of the absolute differences of the following bytes, added to the accumulation value:
  1891. the subtraction of the first bytes from each operand, in the first byte of the return value.\n
  1892. the subtraction of the second bytes of each operand, in the second byte of the return value.\n
  1893. the subtraction of the third bytes of each operand, in the third byte of the return value.\n
  1894. the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
  1895. \remark
  1896. absdiff1 = val1[7:0] - val2[7:0] \n
  1897. absdiff2 = val1[15:8] - val2[15:8] \n
  1898. absdiff3 = val1[23:16] - val2[23:16] \n
  1899. absdiff4 = val1[31:24] - val2[31:24] \n
  1900. sum = absdiff1 + absdiff2 + absdiff3 + absdiff4 \n
  1901. res[31:0] = sum[31:0] + val3[31:0]
  1902. */
  1903. __ALWAYS_STATIC_INLINE uint32_t __USADA8(uint32_t x, uint32_t y, uint32_t sum)
  1904. {
  1905. int32_t r, s, t, u;
  1906. #ifdef __cplusplus
  1907. r = (abs((long long)((x << 24) >> 24) - ((y << 24) >> 24))) & 0x000000FF;
  1908. s = (abs((long long)((x << 16) >> 24) - ((y << 16) >> 24))) & 0x000000FF;
  1909. t = (abs((long long)((x << 8) >> 24) - ((y << 8) >> 24))) & 0x000000FF;
  1910. u = (abs((long long)((x) >> 24) - ((y) >> 24))) & 0x000000FF;
  1911. #else
  1912. r = (abs(((x << 24) >> 24) - ((y << 24) >> 24))) & 0x000000FF;
  1913. s = (abs(((x << 16) >> 24) - ((y << 16) >> 24))) & 0x000000FF;
  1914. t = (abs(((x << 8) >> 24) - ((y << 8) >> 24))) & 0x000000FF;
  1915. u = (abs(((x) >> 24) - ((y) >> 24))) & 0x000000FF;
  1916. #endif
  1917. return (u + t + s + r + sum);
  1918. }
  1919. /**
  1920. \brief Dual 16-bit saturating addition.
  1921. \details This function enables you to perform two 16-bit integer arithmetic additions in parallel,
  1922. saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  1923. \param [in] x first two 16-bit summands.
  1924. \param [in] y second two 16-bit summands.
  1925. \return the saturated addition of the low halfwords, in the low halfword of the return value.\n
  1926. the saturated addition of the high halfwords, in the high halfword of the return value.\n
  1927. The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  1928. \remark
  1929. res[15:0] = val1[15:0] + val2[15:0] \n
  1930. res[31:16] = val1[31:16] + val2[31:16]
  1931. */
  1932. __ALWAYS_STATIC_INLINE uint32_t __QADD16(uint32_t x, uint32_t y)
  1933. {
  1934. int32_t r = 0, s = 0;
  1935. r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1936. s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
  1937. return ((uint32_t)((s << 16) | (r)));
  1938. }
  1939. /**
  1940. \brief Dual 16-bit unsigned saturating addition.
  1941. \details This function enables you to perform two unsigned 16-bit integer additions, saturating
  1942. the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
  1943. \param [in] x first two 16-bit summands.
  1944. \param [in] y second two 16-bit summands.
  1945. \return the saturated addition of the low halfwords, in the low halfword of the return value.\n
  1946. the saturated addition of the high halfwords, in the high halfword of the return value.\n
  1947. The results are saturated to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
  1948. \remark
  1949. res[15:0] = val1[15:0] + val2[15:0] \n
  1950. res[31:16] = val1[31:16] + val2[31:16]
  1951. */
  1952. __ALWAYS_STATIC_INLINE uint32_t __UQADD16(uint32_t x, uint32_t y)
  1953. {
  1954. int32_t r = 0, s = 0;
  1955. r = __IUSAT((((x << 16) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
  1956. s = __IUSAT((((x) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
  1957. return ((s << 16) | (r));
  1958. }
  1959. /**
  1960. \brief Dual 16-bit signed addition.
  1961. \details This function enables you to perform two 16-bit signed integer additions.
  1962. \param [in] x first two 16-bit summands.
  1963. \param [in] y second two 16-bit summands.
  1964. \return the addition of the low halfwords in the low halfword of the return value.\n
  1965. the addition of the high halfwords in the high halfword of the return value.
  1966. \remark
  1967. res[15:0] = val1[15:0] + val2[15:0] \n
  1968. res[31:16] = val1[31:16] + val2[31:16]
  1969. */
  1970. __ALWAYS_STATIC_INLINE uint32_t __SADD16(uint32_t x, uint32_t y)
  1971. {
  1972. int32_t r = 0, s = 0;
  1973. r = ((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
  1974. s = ((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
  1975. return ((uint32_t)((s << 16) | (r)));
  1976. }
  1977. /**
  1978. \brief Dual 16-bit unsigned addition
  1979. \details This function enables you to perform two 16-bit unsigned integer additions.
  1980. \param [in] x first two 16-bit summands for each addition.
  1981. \param [in] y second two 16-bit summands for each addition.
  1982. \return the addition of the low halfwords in the low halfword of the return value.\n
  1983. the addition of the high halfwords in the high halfword of the return value.
  1984. \remark
  1985. res[15:0] = val1[15:0] + val2[15:0] \n
  1986. res[31:16] = val1[31:16] + val2[31:16]
  1987. */
  1988. __ALWAYS_STATIC_INLINE uint32_t __UADD16(uint32_t x, uint32_t y)
  1989. {
  1990. int32_t r = 0, s = 0;
  1991. r = (((x << 16) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
  1992. s = (((x) >> 16) + ((y) >> 16)) & 0x0000FFFF;
  1993. return ((s << 16) | (r));
  1994. }
  1995. /**
  1996. \brief Dual 16-bit signed addition with halved results.
  1997. \details This function enables you to perform two signed 16-bit integer additions, halving the results.
  1998. \param [in] x first two 16-bit summands.
  1999. \param [in] y second two 16-bit summands.
  2000. \return the halved addition of the low halfwords, in the low halfword of the return value.\n
  2001. the halved addition of the high halfwords, in the high halfword of the return value.
  2002. \remark
  2003. res[15:0] = (val1[15:0] + val2[15:0]) >> 1 \n
  2004. res[31:16] = (val1[31:16] + val2[31:16]) >> 1
  2005. */
  2006. __ALWAYS_STATIC_INLINE uint32_t __SHADD16(uint32_t x, uint32_t y)
  2007. {
  2008. int32_t r, s;
  2009. r = (((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2010. s = (((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2011. return ((uint32_t)((s << 16) | (r)));
  2012. }
  2013. /**
  2014. \brief Dual 16-bit unsigned addition with halved results.
  2015. \details This function enables you to perform two unsigned 16-bit integer additions, halving the results.
  2016. \param [in] x first two 16-bit summands.
  2017. \param [in] y second two 16-bit summands.
  2018. \return the halved addition of the low halfwords, in the low halfword of the return value.\n
  2019. the halved addition of the high halfwords, in the high halfword of the return value.
  2020. \remark
  2021. res[15:0] = (val1[15:0] + val2[15:0]) >> 1 \n
  2022. res[31:16] = (val1[31:16] + val2[31:16]) >> 1
  2023. */
  2024. __ALWAYS_STATIC_INLINE uint32_t __UHADD16(uint32_t x, uint32_t y)
  2025. {
  2026. int32_t r, s;
  2027. r = ((((x << 16) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
  2028. s = ((((x) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
  2029. return ((s << 16) | (r));
  2030. }
  2031. /**
  2032. \brief Quad 8-bit signed addition with halved results.
  2033. \details This function enables you to perform four signed 8-bit integer additions, halving the results.
  2034. \param [in] x first four 8-bit summands.
  2035. \param [in] y second four 8-bit summands.
  2036. \return the halved addition of the first bytes from each operand, in the first byte of the return value.\n
  2037. the halved addition of the second bytes from each operand, in the second byte of the return value.\n
  2038. the halved addition of the third bytes from each operand, in the third byte of the return value.\n
  2039. the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
  2040. \remark
  2041. res[7:0] = (val1[7:0] + val2[7:0] ) >> 1 \n
  2042. res[15:8] = (val1[15:8] + val2[15:8] ) >> 1 \n
  2043. res[23:16] = (val1[23:16] + val2[23:16]) >> 1 \n
  2044. res[31:24] = (val1[31:24] + val2[31:24]) >> 1
  2045. */
  2046. __ALWAYS_STATIC_INLINE uint32_t __SHADD8(uint32_t x, uint32_t y)
  2047. {
  2048. int32_t r, s, t, u;
  2049. r = (((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
  2050. s = (((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
  2051. t = (((((int32_t)x << 8) >> 24) + (((int32_t)y << 8) >> 24)) >> 1) & (int32_t)0x000000FF;
  2052. u = (((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
  2053. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  2054. }
  2055. /**
  2056. \brief Quad 8-bit unsigned addition with halved results.
  2057. \details This function enables you to perform four unsigned 8-bit integer additions, halving the results.
  2058. \param [in] x first four 8-bit summands.
  2059. \param [in] y second four 8-bit summands.
  2060. \return the halved addition of the first bytes from each operand, in the first byte of the return value.\n
  2061. the halved addition of the second bytes from each operand, in the second byte of the return value.\n
  2062. the halved addition of the third bytes from each operand, in the third byte of the return value.\n
  2063. the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
  2064. \remark
  2065. res[7:0] = (val1[7:0] + val2[7:0] ) >> 1 \n
  2066. res[15:8] = (val1[15:8] + val2[15:8] ) >> 1 \n
  2067. res[23:16] = (val1[23:16] + val2[23:16]) >> 1 \n
  2068. res[31:24] = (val1[31:24] + val2[31:24]) >> 1
  2069. */
  2070. __ALWAYS_STATIC_INLINE uint32_t __UHADD8(uint32_t x, uint32_t y)
  2071. {
  2072. int32_t r, s, t, u;
  2073. r = ((((x << 24) >> 24) + ((y << 24) >> 24)) >> 1) & 0x000000FF;
  2074. s = ((((x << 16) >> 24) + ((y << 16) >> 24)) >> 1) & 0x000000FF;
  2075. t = ((((x << 8) >> 24) + ((y << 8) >> 24)) >> 1) & 0x000000FF;
  2076. u = ((((x) >> 24) + ((y) >> 24)) >> 1) & 0x000000FF;
  2077. return ((u << 24) | (t << 16) | (s << 8) | (r));
  2078. }
  2079. /**
  2080. \brief Dual 16-bit saturating subtract.
  2081. \details This function enables you to perform two 16-bit integer subtractions in parallel,
  2082. saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2083. \param [in] x first two 16-bit summands.
  2084. \param [in] y second two 16-bit summands.
  2085. \return the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
  2086. the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
  2087. The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2088. \remark
  2089. res[15:0] = val1[15:0] - val2[15:0] \n
  2090. res[31:16] = val1[31:16] - val2[31:16]
  2091. */
  2092. __ALWAYS_STATIC_INLINE uint32_t __QSUB16(uint32_t x, uint32_t y)
  2093. {
  2094. int32_t r, s;
  2095. r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  2096. s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
  2097. return ((uint32_t)((s << 16) | (r)));
  2098. }
  2099. /**
  2100. \brief Dual 16-bit unsigned saturating subtraction.
  2101. \details This function enables you to perform two unsigned 16-bit integer subtractions,
  2102. saturating the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
  2103. \param [in] x first two 16-bit operands for each subtraction.
  2104. \param [in] y second two 16-bit operands for each subtraction.
  2105. \return the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
  2106. the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
  2107. The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2108. \remark
  2109. res[15:0] = val1[15:0] - val2[15:0] \n
  2110. res[31:16] = val1[31:16] - val2[31:16]
  2111. */
  2112. __ALWAYS_STATIC_INLINE uint32_t __UQSUB16(uint32_t x, uint32_t y)
  2113. {
  2114. int32_t r, s;
  2115. r = __IUSAT((((x << 16) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
  2116. s = __IUSAT((((x) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
  2117. return ((s << 16) | (r));
  2118. }
  2119. /**
  2120. \brief Dual 16-bit signed subtraction.
  2121. \details This function enables you to perform two 16-bit signed integer subtractions.
  2122. \param [in] x first two 16-bit operands of each subtraction.
  2123. \param [in] y second two 16-bit operands of each subtraction.
  2124. \return the subtraction of the low halfword in the second operand from the low
  2125. halfword in the first operand, in the low halfword of the return value. \n
  2126. the subtraction of the high halfword in the second operand from the high
  2127. halfword in the first operand, in the high halfword of the return value.
  2128. \remark
  2129. res[15:0] = val1[15:0] - val2[15:0] \n
  2130. res[31:16] = val1[31:16] - val2[31:16]
  2131. */
  2132. __ALWAYS_STATIC_INLINE uint32_t __SSUB16(uint32_t x, uint32_t y)
  2133. {
  2134. int32_t r, s;
  2135. r = ((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
  2136. s = ((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
  2137. return ((uint32_t)((s << 16) | (r)));
  2138. }
  2139. /**
  2140. \brief Dual 16-bit unsigned subtract.
  2141. \details This function enables you to perform two 16-bit unsigned integer subtractions.
  2142. \param [in] x first two 16-bit operands of each subtraction.
  2143. \param [in] y second two 16-bit operands of each subtraction.
  2144. \return the subtraction of the low halfword in the second operand from the low
  2145. halfword in the first operand, in the low halfword of the return value. \n
  2146. the subtraction of the high halfword in the second operand from the high
  2147. halfword in the first operand, in the high halfword of the return value.
  2148. \remark
  2149. res[15:0] = val1[15:0] - val2[15:0] \n
  2150. res[31:16] = val1[31:16] - val2[31:16]
  2151. */
  2152. __ALWAYS_STATIC_INLINE uint32_t __USUB16(uint32_t x, uint32_t y)
  2153. {
  2154. int32_t r, s;
  2155. r = (((x << 16) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
  2156. s = (((x) >> 16) - ((y) >> 16)) & 0x0000FFFF;
  2157. return ((s << 16) | (r));
  2158. }
  2159. /**
  2160. \brief Dual 16-bit signed subtraction with halved results.
  2161. \details This function enables you to perform two signed 16-bit integer subtractions, halving the results.
  2162. \param [in] x first two 16-bit summands.
  2163. \param [in] y second two 16-bit summands.
  2164. \return the halved subtraction of the low halfwords, in the low halfword of the return value.\n
  2165. the halved subtraction of the high halfwords, in the high halfword of the return value.
  2166. \remark
  2167. res[15:0] = (val1[15:0] - val2[15:0]) >> 1 \n
  2168. res[31:16] = (val1[31:16] - val2[31:16]) >> 1
  2169. */
  2170. __ALWAYS_STATIC_INLINE uint32_t __SHSUB16(uint32_t x, uint32_t y)
  2171. {
  2172. int32_t r, s;
  2173. r = (((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2174. s = (((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2175. return ((uint32_t)((s << 16) | (r)));
  2176. }
  2177. /**
  2178. \brief Dual 16-bit unsigned subtraction with halved results.
  2179. \details This function enables you to perform two unsigned 16-bit integer subtractions, halving the results.
  2180. \param [in] x first two 16-bit summands.
  2181. \param [in] y second two 16-bit summands.
  2182. \return the halved subtraction of the low halfwords, in the low halfword of the return value.\n
  2183. the halved subtraction of the high halfwords, in the high halfword of the return value.
  2184. \remark
  2185. res[15:0] = (val1[15:0] - val2[15:0]) >> 1 \n
  2186. res[31:16] = (val1[31:16] - val2[31:16]) >> 1
  2187. */
  2188. __ALWAYS_STATIC_INLINE uint32_t __UHSUB16(uint32_t x, uint32_t y)
  2189. {
  2190. int32_t r, s;
  2191. r = ((((x << 16) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
  2192. s = ((((x) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
  2193. return ((s << 16) | (r));
  2194. }
  2195. /**
  2196. \brief Quad 8-bit signed addition with halved results.
  2197. \details This function enables you to perform four signed 8-bit integer subtractions, halving the results.
  2198. \param [in] x first four 8-bit summands.
  2199. \param [in] y second four 8-bit summands.
  2200. \return the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
  2201. the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
  2202. the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
  2203. the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
  2204. \remark
  2205. res[7:0] = (val1[7:0] - val2[7:0] ) >> 1 \n
  2206. res[15:8] = (val1[15:8] - val2[15:8] ) >> 1 \n
  2207. res[23:16] = (val1[23:16] - val2[23:16]) >> 1 \n
  2208. res[31:24] = (val1[31:24] - val2[31:24]) >> 1
  2209. */
  2210. __ALWAYS_STATIC_INLINE uint32_t __SHSUB8(uint32_t x, uint32_t y)
  2211. {
  2212. int32_t r, s, t, u;
  2213. r = (((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
  2214. s = (((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
  2215. t = (((((int32_t)x << 8) >> 24) - (((int32_t)y << 8) >> 24)) >> 1) & (int32_t)0x000000FF;
  2216. u = (((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
  2217. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r)));
  2218. }
  2219. /**
  2220. \brief Quad 8-bit unsigned subtraction with halved results.
  2221. \details This function enables you to perform four unsigned 8-bit integer subtractions, halving the results.
  2222. \param [in] x first four 8-bit summands.
  2223. \param [in] y second four 8-bit summands.
  2224. \return the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
  2225. the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
  2226. the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
  2227. the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
  2228. \remark
  2229. res[7:0] = (val1[7:0] - val2[7:0] ) >> 1 \n
  2230. res[15:8] = (val1[15:8] - val2[15:8] ) >> 1 \n
  2231. res[23:16] = (val1[23:16] - val2[23:16]) >> 1 \n
  2232. res[31:24] = (val1[31:24] - val2[31:24]) >> 1
  2233. */
  2234. __ALWAYS_STATIC_INLINE uint32_t __UHSUB8(uint32_t x, uint32_t y)
  2235. {
  2236. int32_t r, s, t, u;
  2237. r = ((((x << 24) >> 24) - ((y << 24) >> 24)) >> 1) & 0x000000FF;
  2238. s = ((((x << 16) >> 24) - ((y << 16) >> 24)) >> 1) & 0x000000FF;
  2239. t = ((((x << 8) >> 24) - ((y << 8) >> 24)) >> 1) & 0x000000FF;
  2240. u = ((((x) >> 24) - ((y) >> 24)) >> 1) & 0x000000FF;
  2241. return ((u << 24) | (t << 16) | (s << 8) | (r));
  2242. }
  2243. /**
  2244. \brief Dual 16-bit add and subtract with exchange.
  2245. \details This function enables you to exchange the halfwords of the one operand,
  2246. then add the high halfwords and subtract the low halfwords,
  2247. saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2248. \param [in] x first operand for the subtraction in the low halfword,
  2249. and the first operand for the addition in the high halfword.
  2250. \param [in] y second operand for the subtraction in the high halfword,
  2251. and the second operand for the addition in the low halfword.
  2252. \return the saturated subtraction of the high halfword in the second operand from the
  2253. low halfword in the first operand, in the low halfword of the return value.\n
  2254. the saturated addition of the high halfword in the first operand and the
  2255. low halfword in the second operand, in the high halfword of the return value.\n
  2256. The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2257. \remark
  2258. res[15:0] = val1[15:0] - val2[31:16] \n
  2259. res[31:16] = val1[31:16] + val2[15:0]
  2260. */
  2261. __ALWAYS_STATIC_INLINE uint32_t __QASX(uint32_t x, uint32_t y)
  2262. {
  2263. int32_t r, s;
  2264. r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
  2265. s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  2266. return ((uint32_t)((s << 16) | (r)));
  2267. }
  2268. /**
  2269. \brief Dual 16-bit unsigned saturating addition and subtraction with exchange.
  2270. \details This function enables you to exchange the halfwords of the second operand and
  2271. perform one unsigned 16-bit integer addition and one unsigned 16-bit subtraction,
  2272. saturating the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
  2273. \param [in] x first operand for the subtraction in the low halfword,
  2274. and the first operand for the addition in the high halfword.
  2275. \param [in] y second operand for the subtraction in the high halfword,
  2276. and the second operand for the addition in the low halfword.
  2277. \return the saturated subtraction of the high halfword in the second operand from the
  2278. low halfword in the first operand, in the low halfword of the return value.\n
  2279. the saturated addition of the high halfword in the first operand and the
  2280. low halfword in the second operand, in the high halfword of the return value.\n
  2281. The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
  2282. \remark
  2283. res[15:0] = val1[15:0] - val2[31:16] \n
  2284. res[31:16] = val1[31:16] + val2[15:0]
  2285. */
  2286. __ALWAYS_STATIC_INLINE uint32_t __UQASX(uint32_t x, uint32_t y)
  2287. {
  2288. int32_t r, s;
  2289. r = __IUSAT((((x << 16) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
  2290. s = __IUSAT((((x) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
  2291. return ((s << 16) | (r));
  2292. }
  2293. /**
  2294. \brief Dual 16-bit addition and subtraction with exchange.
  2295. \details It enables you to exchange the halfwords of the second operand, add the high halfwords
  2296. and subtract the low halfwords.
  2297. \param [in] x first operand for the subtraction in the low halfword,
  2298. and the first operand for the addition in the high halfword.
  2299. \param [in] y second operand for the subtraction in the high halfword,
  2300. and the second operand for the addition in the low halfword.
  2301. \return the subtraction of the high halfword in the second operand from the
  2302. low halfword in the first operand, in the low halfword of the return value.\n
  2303. the addition of the high halfword in the first operand and the
  2304. low halfword in the second operand, in the high halfword of the return value.
  2305. \remark
  2306. res[15:0] = val1[15:0] - val2[31:16] \n
  2307. res[31:16] = val1[31:16] + val2[15:0]
  2308. */
  2309. __ALWAYS_STATIC_INLINE uint32_t __SASX(uint32_t x, uint32_t y)
  2310. {
  2311. int32_t r, s;
  2312. r = ((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
  2313. s = ((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
  2314. return ((uint32_t)((s << 16) | (r)));
  2315. }
  2316. /**
  2317. \brief Dual 16-bit unsigned addition and subtraction with exchange.
  2318. \details This function enables you to exchange the two halfwords of the second operand,
  2319. add the high halfwords and subtract the low halfwords.
  2320. \param [in] x first operand for the subtraction in the low halfword,
  2321. and the first operand for the addition in the high halfword.
  2322. \param [in] y second operand for the subtraction in the high halfword,
  2323. and the second operand for the addition in the low halfword.
  2324. \return the subtraction of the high halfword in the second operand from the
  2325. low halfword in the first operand, in the low halfword of the return value.\n
  2326. the addition of the high halfword in the first operand and the
  2327. low halfword in the second operand, in the high halfword of the return value.
  2328. \remark
  2329. res[15:0] = val1[15:0] - val2[31:16] \n
  2330. res[31:16] = val1[31:16] + val2[15:0]
  2331. */
  2332. __ALWAYS_STATIC_INLINE uint32_t __UASX(uint32_t x, uint32_t y)
  2333. {
  2334. int32_t r, s;
  2335. r = (((x << 16) >> 16) - ((y) >> 16)) & 0x0000FFFF;
  2336. s = (((x) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
  2337. return ((s << 16) | (r));
  2338. }
  2339. /**
  2340. \brief Dual 16-bit signed addition and subtraction with halved results.
  2341. \details This function enables you to exchange the two halfwords of one operand, perform one
  2342. signed 16-bit integer addition and one signed 16-bit subtraction, and halve the results.
  2343. \param [in] x first 16-bit operands.
  2344. \param [in] y second 16-bit operands.
  2345. \return the halved subtraction of the high halfword in the second operand from the
  2346. low halfword in the first operand, in the low halfword of the return value.\n
  2347. the halved addition of the low halfword in the second operand from the high
  2348. halfword in the first operand, in the high halfword of the return value.
  2349. \remark
  2350. res[15:0] = (val1[15:0] - val2[31:16]) >> 1 \n
  2351. res[31:16] = (val1[31:16] + val2[15:0]) >> 1
  2352. */
  2353. __ALWAYS_STATIC_INLINE uint32_t __SHASX(uint32_t x, uint32_t y)
  2354. {
  2355. int32_t r, s;
  2356. r = (((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2357. s = (((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2358. return ((uint32_t)((s << 16) | (r)));
  2359. }
  2360. /**
  2361. \brief Dual 16-bit unsigned addition and subtraction with halved results and exchange.
  2362. \details This function enables you to exchange the halfwords of the second operand,
  2363. add the high halfwords and subtract the low halfwords, halving the results.
  2364. \param [in] x first operand for the subtraction in the low halfword, and
  2365. the first operand for the addition in the high halfword.
  2366. \param [in] y second operand for the subtraction in the high halfword, and
  2367. the second operand for the addition in the low halfword.
  2368. \return the halved subtraction of the high halfword in the second operand from the
  2369. low halfword in the first operand, in the low halfword of the return value.\n
  2370. the halved addition of the low halfword in the second operand from the high
  2371. halfword in the first operand, in the high halfword of the return value.
  2372. \remark
  2373. res[15:0] = (val1[15:0] - val2[31:16]) >> 1 \n
  2374. res[31:16] = (val1[31:16] + val2[15:0]) >> 1
  2375. */
  2376. __ALWAYS_STATIC_INLINE uint32_t __UHASX(uint32_t x, uint32_t y)
  2377. {
  2378. int32_t r, s;
  2379. r = ((((x << 16) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
  2380. s = ((((x) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
  2381. return ((s << 16) | (r));
  2382. }
  2383. /**
  2384. \brief Dual 16-bit subtract and add with exchange.
  2385. \details This function enables you to exchange the halfwords of one operand,
  2386. then subtract the high halfwords and add the low halfwords,
  2387. saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2388. \param [in] x first operand for the addition in the low halfword,
  2389. and the first operand for the subtraction in the high halfword.
  2390. \param [in] y second operand for the addition in the high halfword,
  2391. and the second operand for the subtraction in the low halfword.
  2392. \return the saturated addition of the low halfword of the first operand and the high
  2393. halfword of the second operand, in the low halfword of the return value.\n
  2394. the saturated subtraction of the low halfword of the second operand from the
  2395. high halfword of the first operand, in the high halfword of the return value.\n
  2396. The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
  2397. \remark
  2398. res[15:0] = val1[15:0] + val2[31:16] \n
  2399. res[31:16] = val1[31:16] - val2[15:0]
  2400. */
  2401. __ALWAYS_STATIC_INLINE uint32_t __QSAX(uint32_t x, uint32_t y)
  2402. {
  2403. int32_t r, s;
  2404. r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
  2405. s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  2406. return ((uint32_t)((s << 16) | (r)));
  2407. }
  2408. /**
  2409. \brief Dual 16-bit unsigned saturating subtraction and addition with exchange.
  2410. \details This function enables you to exchange the halfwords of the second operand and perform
  2411. one unsigned 16-bit integer subtraction and one unsigned 16-bit addition, saturating
  2412. the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
  2413. \param [in] x first operand for the addition in the low halfword,
  2414. and the first operand for the subtraction in the high halfword.
  2415. \param [in] y second operand for the addition in the high halfword,
  2416. and the second operand for the subtraction in the low halfword.
  2417. \return the saturated addition of the low halfword of the first operand and the high
  2418. halfword of the second operand, in the low halfword of the return value.\n
  2419. the saturated subtraction of the low halfword of the second operand from the
  2420. high halfword of the first operand, in the high halfword of the return value.\n
  2421. The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
  2422. \remark
  2423. res[15:0] = val1[15:0] + val2[31:16] \n
  2424. res[31:16] = val1[31:16] - val2[15:0]
  2425. */
  2426. __ALWAYS_STATIC_INLINE uint32_t __UQSAX(uint32_t x, uint32_t y)
  2427. {
  2428. int32_t r, s;
  2429. r = __IUSAT((((x << 16) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
  2430. s = __IUSAT((((x) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
  2431. return ((s << 16) | (r));
  2432. }
  2433. /**
  2434. \brief Dual 16-bit unsigned subtract and add with exchange.
  2435. \details This function enables you to exchange the halfwords of the second operand,
  2436. subtract the high halfwords and add the low halfwords.
  2437. \param [in] x first operand for the addition in the low halfword,
  2438. and the first operand for the subtraction in the high halfword.
  2439. \param [in] y second operand for the addition in the high halfword,
  2440. and the second operand for the subtraction in the low halfword.
  2441. \return the addition of the low halfword of the first operand and the high
  2442. halfword of the second operand, in the low halfword of the return value.\n
  2443. the subtraction of the low halfword of the second operand from the
  2444. high halfword of the first operand, in the high halfword of the return value.\n
  2445. \remark
  2446. res[15:0] = val1[15:0] + val2[31:16] \n
  2447. res[31:16] = val1[31:16] - val2[15:0]
  2448. */
  2449. __ALWAYS_STATIC_INLINE uint32_t __USAX(uint32_t x, uint32_t y)
  2450. {
  2451. int32_t r, s;
  2452. r = (((x << 16) >> 16) + ((y) >> 16)) & 0x0000FFFF;
  2453. s = (((x) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
  2454. return ((s << 16) | (r));
  2455. }
  2456. /**
  2457. \brief Dual 16-bit signed subtraction and addition with exchange.
  2458. \details This function enables you to exchange the two halfwords of one operand and perform one
  2459. 16-bit integer subtraction and one 16-bit addition.
  2460. \param [in] x first operand for the addition in the low halfword, and the first operand
  2461. for the subtraction in the high halfword.
  2462. \param [in] y second operand for the addition in the high halfword, and the second
  2463. operand for the subtraction in the low halfword.
  2464. \return the addition of the low halfword of the first operand and the high
  2465. halfword of the second operand, in the low halfword of the return value.\n
  2466. the subtraction of the low halfword of the second operand from the
  2467. high halfword of the first operand, in the high halfword of the return value.\n
  2468. \remark
  2469. res[15:0] = val1[15:0] + val2[31:16] \n
  2470. res[31:16] = val1[31:16] - val2[15:0]
  2471. */
  2472. __ALWAYS_STATIC_INLINE uint32_t __SSAX(uint32_t x, uint32_t y)
  2473. {
  2474. int32_t r, s;
  2475. r = ((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
  2476. s = ((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
  2477. return ((uint32_t)((s << 16) | (r)));
  2478. }
  2479. /**
  2480. \brief Dual 16-bit signed subtraction and addition with halved results.
  2481. \details This function enables you to exchange the two halfwords of one operand, perform one signed
  2482. 16-bit integer subtraction and one signed 16-bit addition, and halve the results.
  2483. \param [in] x first 16-bit operands.
  2484. \param [in] y second 16-bit operands.
  2485. \return the halved addition of the low halfword in the first operand and the
  2486. high halfword in the second operand, in the low halfword of the return value.\n
  2487. the halved subtraction of the low halfword in the second operand from the
  2488. high halfword in the first operand, in the high halfword of the return value.
  2489. \remark
  2490. res[15:0] = (val1[15:0] + val2[31:16]) >> 1 \n
  2491. res[31:16] = (val1[31:16] - val2[15:0]) >> 1
  2492. */
  2493. __ALWAYS_STATIC_INLINE uint32_t __SHSAX(uint32_t x, uint32_t y)
  2494. {
  2495. int32_t r, s;
  2496. r = (((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2497. s = (((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  2498. return ((uint32_t)((s << 16) | (r)));
  2499. }
  2500. /**
  2501. \brief Dual 16-bit unsigned subtraction and addition with halved results and exchange.
  2502. \details This function enables you to exchange the halfwords of the second operand,
  2503. subtract the high halfwords and add the low halfwords, halving the results.
  2504. \param [in] x first operand for the addition in the low halfword, and
  2505. the first operand for the subtraction in the high halfword.
  2506. \param [in] y second operand for the addition in the high halfword, and
  2507. the second operand for the subtraction in the low halfword.
  2508. \return the halved addition of the low halfword in the first operand and the
  2509. high halfword in the second operand, in the low halfword of the return value.\n
  2510. the halved subtraction of the low halfword in the second operand from the
  2511. high halfword in the first operand, in the high halfword of the return value.
  2512. \remark
  2513. res[15:0] = (val1[15:0] + val2[31:16]) >> 1 \n
  2514. res[31:16] = (val1[31:16] - val2[15:0]) >> 1
  2515. */
  2516. __ALWAYS_STATIC_INLINE uint32_t __UHSAX(uint32_t x, uint32_t y)
  2517. {
  2518. int32_t r, s;
  2519. r = ((((x << 16) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
  2520. s = ((((x) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
  2521. return ((s << 16) | (r));
  2522. }
  2523. /**
  2524. \brief Dual 16-bit signed multiply with exchange returning difference.
  2525. \details This function enables you to perform two 16-bit signed multiplications, subtracting
  2526. one of the products from the other. The halfwords of the second operand are exchanged
  2527. before performing the arithmetic. This produces top * bottom and bottom * top multiplication.
  2528. \param [in] x first 16-bit operands for each multiplication.
  2529. \param [in] y second 16-bit operands for each multiplication.
  2530. \return the difference of the products of the two 16-bit signed multiplications.
  2531. \remark
  2532. p1 = val1[15:0] * val2[31:16] \n
  2533. p2 = val1[31:16] * val2[15:0] \n
  2534. res[31:0] = p1 - p2
  2535. */
  2536. __ALWAYS_STATIC_INLINE uint32_t __SMUSDX(uint32_t x, uint32_t y)
  2537. {
  2538. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
  2539. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
  2540. }
  2541. /**
  2542. \brief Sum of dual 16-bit signed multiply with exchange.
  2543. \details This function enables you to perform two 16-bit signed multiplications with exchanged
  2544. halfwords of the second operand, adding the products together.
  2545. \param [in] x first 16-bit operands for each multiplication.
  2546. \param [in] y second 16-bit operands for each multiplication.
  2547. \return the sum of the products of the two 16-bit signed multiplications with exchanged halfwords of the second operand.
  2548. \remark
  2549. p1 = val1[15:0] * val2[31:16] \n
  2550. p2 = val1[31:16] * val2[15:0] \n
  2551. res[31:0] = p1 + p2
  2552. */
  2553. __ALWAYS_STATIC_INLINE uint32_t __SMUADX(uint32_t x, uint32_t y)
  2554. {
  2555. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
  2556. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
  2557. }
  2558. /**
  2559. \brief Saturating add.
  2560. \details This function enables you to obtain the saturating add of two integers.
  2561. \param [in] x first summand of the saturating add operation.
  2562. \param [in] y second summand of the saturating add operation.
  2563. \return the saturating addition of val1 and val2.
  2564. \remark
  2565. res[31:0] = SAT(val1 + SAT(val2))
  2566. */
  2567. __ALWAYS_STATIC_INLINE int32_t __QADD(int32_t x, int32_t y)
  2568. {
  2569. int32_t result;
  2570. if (y >= 0) {
  2571. if (x + y >= x) {
  2572. result = x + y;
  2573. } else {
  2574. result = 0x7FFFFFFF;
  2575. }
  2576. } else {
  2577. if (x + y < x) {
  2578. result = x + y;
  2579. } else {
  2580. result = 0x80000000;
  2581. }
  2582. }
  2583. return result;
  2584. }
  2585. /**
  2586. \brief Saturating subtract.
  2587. \details This function enables you to obtain the saturating add of two integers.
  2588. \param [in] x first summand of the saturating add operation.
  2589. \param [in] y second summand of the saturating add operation.
  2590. \return the saturating addition of val1 and val2.
  2591. \remark
  2592. res[31:0] = SAT(val1 - SAT(val2))
  2593. */
  2594. __ALWAYS_STATIC_INLINE int32_t __QSUB(int32_t x, int32_t y)
  2595. {
  2596. int64_t tmp;
  2597. int32_t result;
  2598. tmp = (int64_t)x - (int64_t)y;
  2599. if (tmp > 0x7fffffff) {
  2600. tmp = 0x7fffffff;
  2601. } else if (tmp < (-2147483647 - 1)) {
  2602. tmp = -2147483647 - 1;
  2603. }
  2604. result = tmp;
  2605. return result;
  2606. }
  2607. /**
  2608. \brief Dual 16-bit signed multiply with single 32-bit accumulator.
  2609. \details This function enables you to perform two signed 16-bit multiplications,
  2610. adding both results to a 32-bit accumulate operand.
  2611. \param [in] x first 16-bit operands for each multiplication.
  2612. \param [in] y second 16-bit operands for each multiplication.
  2613. \param [in] sum accumulate value.
  2614. \return the product of each multiplication added to the accumulate value, as a 32-bit integer.
  2615. \remark
  2616. p1 = val1[15:0] * val2[15:0] \n
  2617. p2 = val1[31:16] * val2[31:16] \n
  2618. res[31:0] = p1 + p2 + val3[31:0]
  2619. */
  2620. __ALWAYS_STATIC_INLINE uint32_t __SMLAD(uint32_t x, uint32_t y, uint32_t sum)
  2621. {
  2622. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
  2623. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
  2624. (((int32_t)sum))));
  2625. }
  2626. /**
  2627. \brief Pre-exchanged dual 16-bit signed multiply with single 32-bit accumulator.
  2628. \details This function enables you to perform two signed 16-bit multiplications with exchanged
  2629. halfwords of the second operand, adding both results to a 32-bit accumulate operand.
  2630. \param [in] x first 16-bit operands for each multiplication.
  2631. \param [in] y second 16-bit operands for each multiplication.
  2632. \param [in] sum accumulate value.
  2633. \return the product of each multiplication with exchanged halfwords of the second
  2634. operand added to the accumulate value, as a 32-bit integer.
  2635. \remark
  2636. p1 = val1[15:0] * val2[31:16] \n
  2637. p2 = val1[31:16] * val2[15:0] \n
  2638. res[31:0] = p1 + p2 + val3[31:0]
  2639. */
  2640. __ALWAYS_STATIC_INLINE uint32_t __SMLADX(uint32_t x, uint32_t y, uint32_t sum)
  2641. {
  2642. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
  2643. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
  2644. (((int32_t)sum))));
  2645. }
  2646. /**
  2647. \brief Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
  2648. \details This function enables you to perform two 16-bit signed multiplications, take the
  2649. difference of the products, subtracting the high halfword product from the low
  2650. halfword product, and add the difference to a 32-bit accumulate operand.
  2651. \param [in] x first 16-bit operands for each multiplication.
  2652. \param [in] y second 16-bit operands for each multiplication.
  2653. \param [in] sum accumulate value.
  2654. \return the difference of the product of each multiplication, added to the accumulate value.
  2655. \remark
  2656. p1 = val1[15:0] * val2[15:0] \n
  2657. p2 = val1[31:16] * val2[31:16] \n
  2658. res[31:0] = p1 - p2 + val3[31:0]
  2659. */
  2660. __ALWAYS_STATIC_INLINE uint32_t __SMLSD(uint32_t x, uint32_t y, uint32_t sum)
  2661. {
  2662. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
  2663. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
  2664. (((int32_t)sum))));
  2665. }
  2666. /**
  2667. \brief Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
  2668. \details This function enables you to exchange the halfwords in the second operand, then perform two 16-bit
  2669. signed multiplications. The difference of the products is added to a 32-bit accumulate operand.
  2670. \param [in] x first 16-bit operands for each multiplication.
  2671. \param [in] y second 16-bit operands for each multiplication.
  2672. \param [in] sum accumulate value.
  2673. \return the difference of the product of each multiplication, added to the accumulate value.
  2674. \remark
  2675. p1 = val1[15:0] * val2[31:16] \n
  2676. p2 = val1[31:16] * val2[15:0] \n
  2677. res[31:0] = p1 - p2 + val3[31:0]
  2678. */
  2679. __ALWAYS_STATIC_INLINE uint32_t __SMLSDX(uint32_t x, uint32_t y, uint32_t sum)
  2680. {
  2681. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
  2682. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
  2683. (((int32_t)sum))));
  2684. }
  2685. /**
  2686. \brief Dual 16-bit signed multiply with single 64-bit accumulator.
  2687. \details This function enables you to perform two signed 16-bit multiplications, adding both results
  2688. to a 64-bit accumulate operand. Overflow is only possible as a result of the 64-bit addition.
  2689. This overflow is not detected if it occurs. Instead, the result wraps around modulo2^64.
  2690. \param [in] x first 16-bit operands for each multiplication.
  2691. \param [in] y second 16-bit operands for each multiplication.
  2692. \param [in] sum accumulate value.
  2693. \return the product of each multiplication added to the accumulate value.
  2694. \remark
  2695. p1 = val1[15:0] * val2[15:0] \n
  2696. p2 = val1[31:16] * val2[31:16] \n
  2697. sum = p1 + p2 + val3[63:32][31:0] \n
  2698. res[63:32] = sum[63:32] \n
  2699. res[31:0] = sum[31:0]
  2700. */
  2701. __ALWAYS_STATIC_INLINE uint64_t __SMLALD(uint32_t x, uint32_t y, uint64_t sum)
  2702. {
  2703. return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
  2704. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
  2705. (((uint64_t)sum))));
  2706. }
  2707. /**
  2708. \brief Dual 16-bit signed multiply with exchange with single 64-bit accumulator.
  2709. \details This function enables you to exchange the halfwords of the second operand, and perform two
  2710. signed 16-bit multiplications, adding both results to a 64-bit accumulate operand. Overflow
  2711. is only possible as a result of the 64-bit addition. This overflow is not detected if it occurs.
  2712. Instead, the result wraps around modulo2^64.
  2713. \param [in] x first 16-bit operands for each multiplication.
  2714. \param [in] y second 16-bit operands for each multiplication.
  2715. \param [in] sum accumulate value.
  2716. \return the product of each multiplication added to the accumulate value.
  2717. \remark
  2718. p1 = val1[15:0] * val2[31:16] \n
  2719. p2 = val1[31:16] * val2[15:0] \n
  2720. sum = p1 + p2 + val3[63:32][31:0] \n
  2721. res[63:32] = sum[63:32] \n
  2722. res[31:0] = sum[31:0]
  2723. */
  2724. __ALWAYS_STATIC_INLINE uint64_t __SMLALDX(uint32_t x, uint32_t y, uint64_t sum)
  2725. {
  2726. return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
  2727. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
  2728. (((uint64_t)sum))));
  2729. }
  2730. /**
  2731. \brief dual 16-bit signed multiply subtract with 64-bit accumulate.
  2732. \details This function It enables you to perform two 16-bit signed multiplications, take the difference
  2733. of the products, subtracting the high halfword product from the low halfword product, and add the
  2734. difference to a 64-bit accumulate operand. Overflow cannot occur during the multiplications or the
  2735. subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow is not
  2736. detected. Instead, the result wraps round to modulo2^64.
  2737. \param [in] x first 16-bit operands for each multiplication.
  2738. \param [in] y second 16-bit operands for each multiplication.
  2739. \param [in] sum accumulate value.
  2740. \return the difference of the product of each multiplication, added to the accumulate value.
  2741. \remark
  2742. p1 = val1[15:0] * val2[15:0] \n
  2743. p2 = val1[31:16] * val2[31:16] \n
  2744. res[63:32][31:0] = p1 - p2 + val3[63:32][31:0]
  2745. */
  2746. __ALWAYS_STATIC_INLINE uint64_t __SMLSLD(uint32_t x, uint32_t y, uint64_t sum)
  2747. {
  2748. return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
  2749. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
  2750. (((uint64_t)sum))));
  2751. }
  2752. /**
  2753. \brief Dual 16-bit signed multiply with exchange subtract with 64-bit accumulate.
  2754. \details This function enables you to exchange the halfwords of the second operand, perform two 16-bit multiplications,
  2755. adding the difference of the products to a 64-bit accumulate operand. Overflow cannot occur during the
  2756. multiplications or the subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow
  2757. is not detected. Instead, the result wraps round to modulo2^64.
  2758. \param [in] x first 16-bit operands for each multiplication.
  2759. \param [in] y second 16-bit operands for each multiplication.
  2760. \param [in] sum accumulate value.
  2761. \return the difference of the product of each multiplication, added to the accumulate value.
  2762. \remark
  2763. p1 = val1[15:0] * val2[31:16] \n
  2764. p2 = val1[31:16] * val2[15:0] \n
  2765. res[63:32][31:0] = p1 - p2 + val3[63:32][31:0]
  2766. */
  2767. __ALWAYS_STATIC_INLINE uint64_t __SMLSLDX(uint32_t x, uint32_t y, uint64_t sum)
  2768. {
  2769. return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
  2770. ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
  2771. (((uint64_t)sum))));
  2772. }
  2773. /**
  2774. \brief 32-bit signed multiply with 32-bit truncated accumulator.
  2775. \details This function enables you to perform a signed 32-bit multiplications, adding the most
  2776. significant 32 bits of the 64-bit result to a 32-bit accumulate operand.
  2777. \param [in] x first operand for multiplication.
  2778. \param [in] y second operand for multiplication.
  2779. \param [in] sum accumulate value.
  2780. \return the product of multiplication (most significant 32 bits) is added to the accumulate value, as a 32-bit integer.
  2781. \remark
  2782. p = val1 * val2 \n
  2783. res[31:0] = p[63:32] + val3[31:0]
  2784. */
  2785. __ALWAYS_STATIC_INLINE uint32_t __SMMLA(int32_t x, int32_t y, int32_t sum)
  2786. {
  2787. return (uint32_t)((int32_t)((int64_t)((int64_t)x * (int64_t)y) >> 32) + sum);
  2788. }
  2789. /**
  2790. \brief Sum of dual 16-bit signed multiply.
  2791. \details This function enables you to perform two 16-bit signed multiplications, adding the products together.
  2792. \param [in] x first 16-bit operands for each multiplication.
  2793. \param [in] y second 16-bit operands for each multiplication.
  2794. \return the sum of the products of the two 16-bit signed multiplications.
  2795. \remark
  2796. p1 = val1[15:0] * val2[15:0] \n
  2797. p2 = val1[31:16] * val2[31:16] \n
  2798. res[31:0] = p1 + p2
  2799. */
  2800. __ALWAYS_STATIC_INLINE uint32_t __SMUAD(uint32_t x, uint32_t y)
  2801. {
  2802. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
  2803. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
  2804. }
  2805. /**
  2806. \brief Dual 16-bit signed multiply returning difference.
  2807. \details This function enables you to perform two 16-bit signed multiplications, taking the difference
  2808. of the products by subtracting the high halfword product from the low halfword product.
  2809. \param [in] x first 16-bit operands for each multiplication.
  2810. \param [in] y second 16-bit operands for each multiplication.
  2811. \return the difference of the products of the two 16-bit signed multiplications.
  2812. \remark
  2813. p1 = val1[15:0] * val2[15:0] \n
  2814. p2 = val1[31:16] * val2[31:16] \n
  2815. res[31:0] = p1 - p2
  2816. */
  2817. __ALWAYS_STATIC_INLINE uint32_t __SMUSD(uint32_t x, uint32_t y)
  2818. {
  2819. return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
  2820. ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
  2821. }
  2822. /**
  2823. \brief Dual extracted 8-bit to 16-bit signed addition.
  2824. \details This function enables you to extract two 8-bit values from the second operand (at bit positions
  2825. [7:0] and [23:16]), sign-extend them to 16-bits each, and add the results to the first operand.
  2826. \param [in] x values added to the sign-extended to 16-bit values.
  2827. \param [in] y two 8-bit values to be extracted and sign-extended.
  2828. \return the addition of val1 and val2, where the 8-bit values in val2[7:0] and
  2829. val2[23:16] have been extracted and sign-extended prior to the addition.
  2830. \remark
  2831. res[15:0] = val1[15:0] + SignExtended(val2[7:0]) \n
  2832. res[31:16] = val1[31:16] + SignExtended(val2[23:16])
  2833. */
  2834. __ALWAYS_STATIC_INLINE uint32_t __SXTAB16(uint32_t x, uint32_t y)
  2835. {
  2836. return ((uint32_t)((((((int32_t)y << 24) >> 24) + (((int32_t)x << 16) >> 16)) & (int32_t)0x0000FFFF) |
  2837. (((((int32_t)y << 8) >> 8) + (((int32_t)x >> 16) << 16)) & (int32_t)0xFFFF0000)));
  2838. }
  2839. /**
  2840. \brief Extracted 16-bit to 32-bit unsigned addition.
  2841. \details This function enables you to extract two 8-bit values from one operand, zero-extend
  2842. them to 16 bits each, and add the results to two 16-bit values from another operand.
  2843. \param [in] x values added to the zero-extended to 16-bit values.
  2844. \param [in] y two 8-bit values to be extracted and zero-extended.
  2845. \return the addition of val1 and val2, where the 8-bit values in val2[7:0] and
  2846. val2[23:16] have been extracted and zero-extended prior to the addition.
  2847. \remark
  2848. res[15:0] = ZeroExt(val2[7:0] to 16 bits) + val1[15:0] \n
  2849. res[31:16] = ZeroExt(val2[31:16] to 16 bits) + val1[31:16]
  2850. */
  2851. __ALWAYS_STATIC_INLINE uint32_t __UXTAB16(uint32_t x, uint32_t y)
  2852. {
  2853. return ((uint32_t)(((((y << 24) >> 24) + ((x << 16) >> 16)) & 0x0000FFFF) |
  2854. ((((y << 8) >> 8) + ((x >> 16) << 16)) & 0xFFFF0000)));
  2855. }
  2856. /**
  2857. \brief Dual extract 8-bits and sign extend each to 16-bits.
  2858. \details This function enables you to extract two 8-bit values from an operand and sign-extend them to 16 bits each.
  2859. \param [in] x two 8-bit values in val[7:0] and val[23:16] to be sign-extended.
  2860. \return the 8-bit values sign-extended to 16-bit values.\n
  2861. sign-extended value of val[7:0] in the low halfword of the return value.\n
  2862. sign-extended value of val[23:16] in the high halfword of the return value.
  2863. \remark
  2864. res[15:0] = SignExtended(val[7:0]) \n
  2865. res[31:16] = SignExtended(val[23:16])
  2866. */
  2867. __ALWAYS_STATIC_INLINE uint32_t __SXTB16(uint32_t x)
  2868. {
  2869. return ((uint32_t)(((((int32_t)x << 24) >> 24) & (int32_t)0x0000FFFF) |
  2870. ((((int32_t)x << 8) >> 8) & (int32_t)0xFFFF0000)));
  2871. }
  2872. /**
  2873. \brief Dual extract 8-bits and zero-extend to 16-bits.
  2874. \details This function enables you to extract two 8-bit values from an operand and zero-extend them to 16 bits each.
  2875. \param [in] x two 8-bit values in val[7:0] and val[23:16] to be zero-extended.
  2876. \return the 8-bit values sign-extended to 16-bit values.\n
  2877. sign-extended value of val[7:0] in the low halfword of the return value.\n
  2878. sign-extended value of val[23:16] in the high halfword of the return value.
  2879. \remark
  2880. res[15:0] = SignExtended(val[7:0]) \n
  2881. res[31:16] = SignExtended(val[23:16])
  2882. */
  2883. __ALWAYS_STATIC_INLINE uint32_t __UXTB16(uint32_t x)
  2884. {
  2885. return ((uint32_t)((((x << 24) >> 24) & 0x0000FFFF) |
  2886. (((x << 8) >> 8) & 0xFFFF0000)));
  2887. }
  2888. #endif /* _CSI_GCC_H_ */