ppu_intrinsics.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /* PPU intrinsics as defined by the C/C++ Language extension for Cell BEA.
  2. Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. This file is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 3 of the License, or (at your option)
  6. any later version.
  7. This file is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10. for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. /* TODO:
  19. misc ops (traps)
  20. supervisor/hypervisor mode ops. */
  21. #ifndef _PPU_INTRINSICS_H
  22. #define _PPU_INTRINSICS_H
  23. #if !defined(__PPU__) && !defined(__ppc__) && !defined(__ppc64__) \
  24. && !defined(__GNUC__)
  25. #error ppu_intrinsics.h included on wrong platform/compiler
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /*
  31. * unsigned int __cntlzw(unsigned int)
  32. * unsigned int __cntlzd(unsigned long long)
  33. * int __mulhw(int, int)
  34. * unsigned int __mulhwu(unsigned int, unsigned int)
  35. * long long __mulhd(long long, long long)
  36. * unsigned long long __mulhdu(unsigned long long, unsigned long long)
  37. *
  38. * void __sync(void)
  39. * void __isync(void)
  40. * void __lwsync(void)
  41. * void __eieio(void)
  42. *
  43. * void __nop(void)
  44. * void __cctpl(void)
  45. * void __cctpm(void)
  46. * void __cctph(void)
  47. * void __db8cyc(void)
  48. * void __db10cyc(void)
  49. * void __db12cyc(void)
  50. * void __db16cyc(void)
  51. *
  52. * void __mtspr(unsigned int spr, unsigned long long value)
  53. * unsigned long long __mfspr(unsigned int spr)
  54. * unsigned long long __mftb(void)
  55. *
  56. * void __icbi(void *base)
  57. * void __dcbi(void *base)
  58. *
  59. * void __dcbf(void *base)
  60. * void __dcbz(void *base)
  61. * void __dcbst(void *base)
  62. * void __dcbtst(void *base)
  63. * void __dcbt(void *base)
  64. * void __dcbt_TH1000(void *EATRUNC, bool D, bool UG, int ID)
  65. * void __dcbt_TH1010(bool GO, int S, int UNITCNT, bool T, bool U, int ID)
  66. *
  67. * unsigned __lwarx(void *base)
  68. * unsigned long long __ldarx(void *base)
  69. * bool __stwcx(void *base, unsigned value)
  70. * bool __stdcx(void *base, unsigned long long value)
  71. *
  72. * unsigned short __lhbrx(void *base)
  73. * unsigned int __lwbrx(void *base)
  74. * unsigned long long __ldbrx(void *base)
  75. * void __sthbrx(void *base, unsigned short value)
  76. * void __stwbrx(void *base, unsigned int value)
  77. * void __stdbrx(void *base, unsigned long long value)
  78. *
  79. * double __fabs(double x)
  80. * float __fabsf(float x)
  81. * double __fnabs(double x)
  82. * float __fnabsf(float x)
  83. * double __fmadd(double x, double y, double z)
  84. * double __fmsub(double x, double y, double z)
  85. * double __fnmadd(double x, double y, double z)
  86. * double __fnmsub(double x, double y, double z)
  87. * float __fmadds(float x, float y, float z)
  88. * float __fmsubs(float x, float y, float z)
  89. * float __fnmadds(float x, float y, float z)
  90. * float __fnmsubs(float x, float y, float z)
  91. * double __fsel(double x, double y, double z)
  92. * float __fsels(float x, float y, float z)
  93. * double __frsqrte(double x)
  94. * float __fres(float x)
  95. * double __fsqrt(double x)
  96. * float __fsqrts(float x)
  97. * long long __fctid(double x)
  98. * long long __fctiw(double x)
  99. * double __fcfid(long long x)
  100. * double __mffs(void)
  101. * void __mtfsf(int mask, double value)
  102. * void __mtfsfi(int bits, int field)
  103. * void __mtfsb0(int)
  104. * void __mtfsb1(int)
  105. * double __setflm(double)
  106. *
  107. * dcbt intrinsics
  108. * void __protected_unlimited_stream_set (unsigned int direction, const void *add, unsigned int ID)
  109. * void __protected_stream_set (unsigned int direction, const void *add, unsigned int ID)
  110. * void __protected_stream_stop_all (void)
  111. * void __protected_stream_stop (unsigned int ID)
  112. * void __protected_stream_count (unsigned int unit_cnt, unsigned int ID)
  113. * void __protected_stream_go (void)
  114. */
  115. typedef int __V4SI __attribute__((vector_size(16)));
  116. #define __cntlzw(v) __builtin_clz(v)
  117. #define __cntlzd(v) __builtin_clzll(v)
  118. #define __mulhw(a,b) __extension__ \
  119. ({int result; \
  120. __asm__ ("mulhw %0,%1,%2" \
  121. : "=r" (result) \
  122. : "r" ((int) (a)), \
  123. "r" ((int) (b))); \
  124. result; })
  125. #define __mulhwu(a,b) __extension__ \
  126. ({unsigned int result; \
  127. __asm__ ("mulhwu %0,%1,%2" \
  128. : "=r" (result) \
  129. : "r" ((unsigned int) (a)), \
  130. "r" ((unsigned int) (b))); \
  131. result; })
  132. #ifdef __powerpc64__
  133. #define __mulhd(a,b) __extension__ \
  134. ({ long long result; \
  135. __asm__ ("mulhd %0,%1,%2" \
  136. : "=r" (result) \
  137. : "r" ((long long) (a)), \
  138. "r" ((long long) (b))); \
  139. result; })
  140. #define __mulhdu(a,b) __extension__ \
  141. ({unsigned long long result; \
  142. __asm__ ("mulhdu %0,%1,%2" \
  143. : "=r" (result) \
  144. : "r" ((unsigned long long) (a)), \
  145. "r" ((unsigned long long) (b))); \
  146. result; })
  147. #endif /* __powerpc64__ */
  148. #define __sync() __asm__ volatile ("sync" : : : "memory")
  149. #define __isync() __asm__ volatile ("isync" : : : "memory")
  150. #define __lwsync() __asm__ volatile ("lwsync" : : : "memory")
  151. #define __eieio() __asm__ volatile ("eieio" : : : "memory")
  152. #define __nop() __asm__ volatile ("ori 0,0,0" : : : "memory")
  153. #define __cctpl() __asm__ volatile ("or 1,1,1" : : : "memory")
  154. #define __cctpm() __asm__ volatile ("or 2,2,2" : : : "memory")
  155. #define __cctph() __asm__ volatile ("or 3,3,3" : : : "memory")
  156. #define __db8cyc() __asm__ volatile ("or 28,28,28" : : : "memory")
  157. #define __db10cyc() __asm__ volatile ("or 29,29,29" : : : "memory")
  158. #define __db12cyc() __asm__ volatile ("or 30,30,30" : : : "memory")
  159. #define __db16cyc() __asm__ volatile ("or 31,31,31" : : : "memory")
  160. #ifdef __powerpc64__
  161. #define __mtspr(spr, value) \
  162. __asm__ volatile ("mtspr %0,%1" : : "n" (spr), "r" (value))
  163. #define __mfspr(spr) __extension__ \
  164. ({ unsigned long long result; \
  165. __asm__ volatile ("mfspr %0,%1" : "=r" (result) : "n" (spr)); \
  166. result; })
  167. #endif /* __powerpc64__ */
  168. #ifdef __powerpc64__
  169. /* Work around the hardware bug in the current Cell implementation. */
  170. #define __mftb() __extension__ \
  171. ({ unsigned long long result; \
  172. __asm__ volatile ("1: mftb %[current_tb]\n" \
  173. "\tcmpwi 7, %[current_tb], 0\n" \
  174. "\tbeq- 7, 1b" \
  175. : [current_tb] "=r" (result): \
  176. :"cr7"); \
  177. result; })
  178. #else
  179. #define __mftb() __extension__ \
  180. ({ unsigned long long result; \
  181. unsigned long t; \
  182. __asm__ volatile ("1:\n" \
  183. "\tmftbu %0\n" \
  184. "\tmftb %L0\n" \
  185. "\tmftbu %1\n" \
  186. "\tcmpw %0,%1\n" \
  187. "\tbne 1b" \
  188. : "=r" (result), "=r" (t)); \
  189. result; })
  190. #endif /* __powerpc64__ */
  191. #define __dcbf(base) \
  192. __asm__ volatile ("dcbf %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  193. #define __dcbz(base) \
  194. __asm__ volatile ("dcbz %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  195. #define __dcbst(base) \
  196. __asm__ volatile ("dcbst %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  197. #define __dcbtst(base) \
  198. __asm__ volatile ("dcbtst %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  199. #define __dcbt(base) \
  200. __asm__ volatile ("dcbt %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  201. #define __icbi(base) \
  202. __asm__ volatile ("icbi %y0" : "=Z" (*(__V4SI*) (base)) : : "memory")
  203. #define __dcbt_TH1000(EATRUNC, D, UG, ID) \
  204. __asm__ volatile ("dcbt %y0,8" \
  205. : "=Z" (*(__V4SI*) (__SIZE_TYPE__)((((__SIZE_TYPE__) (EATRUNC)) & ~0x7F) \
  206. | ((((D) & 1) << 6) \
  207. | (((UG) & 1) << 5) \
  208. | ((ID) & 0xF)))) : : "memory")
  209. #define __dcbt_TH1010(GO, S, UNITCNT, T, U, ID) \
  210. __asm__ volatile ("dcbt %y0,10" \
  211. : "=Z" (*(__V4SI*) (__SIZE_TYPE__)((((__SIZE_TYPE__) (GO) & 1) << 31) \
  212. | (((S) & 0x3) << 29) \
  213. | (((UNITCNT) & 0x3FF) << 7) \
  214. | (((T) & 1) << 6) \
  215. | (((U) & 1) << 5) \
  216. | ((ID) & 0xF))) : : "memory")
  217. #define __protected_unlimited_stream_set(DIRECTION, ADDR, ID) \
  218. __dcbt_TH1000 ((ADDR), (DIRECTION)>>1, 1, (ID))
  219. #define __protected_stream_set(DIRECTION, ADDR, ID) \
  220. __dcbt_TH1000 ((ADDR), (DIRECTION)>>1, 0, (ID))
  221. #define __protected_stream_stop_all() \
  222. __dcbt_TH1010 (0, 3, 0, 0, 0, 0)
  223. #define __protected_stream_stop(ID) \
  224. __dcbt_TH1010 (0, 2, 0, 0, 0, (ID))
  225. #define __protected_stream_count(COUNT, ID) \
  226. __dcbt_TH1010 (0, 0, (COUNT), 0, 0, (ID))
  227. #define __protected_stream_go() \
  228. __dcbt_TH1010 (1, 0, 0, 0, 0, 0)
  229. #define __lhbrx(base) __extension__ \
  230. ({unsigned short result; \
  231. typedef struct {char a[2];} halfwordsize; \
  232. halfwordsize *ptrp = (halfwordsize*)(void*)(base); \
  233. __asm__ ("lhbrx %0,%y1" \
  234. : "=r" (result) \
  235. : "Z" (*ptrp)); \
  236. result; })
  237. #define __lwbrx(base) __extension__ \
  238. ({unsigned int result; \
  239. typedef struct {char a[4];} wordsize; \
  240. wordsize *ptrp = (wordsize*)(void*)(base); \
  241. __asm__ ("lwbrx %0,%y1" \
  242. : "=r" (result) \
  243. : "Z" (*ptrp)); \
  244. result; })
  245. #ifdef __powerpc64__
  246. #define __ldbrx(base) __extension__ \
  247. ({unsigned long long result; \
  248. typedef struct {char a[8];} doublewordsize; \
  249. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  250. __asm__ ("ldbrx %0,%y1" \
  251. : "=r" (result) \
  252. : "Z" (*ptrp)); \
  253. result; })
  254. #else
  255. #define __ldbrx(base) __extension__ \
  256. ({unsigned long long result; \
  257. typedef struct {char a[8];} doublewordsize; \
  258. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  259. __asm__ ("lwbrx %L0,%y1\n" \
  260. "\tlwbrx %0,%y2" \
  261. : "=&r" (result) \
  262. : "Z" (*ptrp), "Z" (*((char *) ptrp + 4))); \
  263. result; })
  264. #endif /* __powerpc64__ */
  265. #define __sthbrx(base, value) do { \
  266. typedef struct {char a[2];} halfwordsize; \
  267. halfwordsize *ptrp = (halfwordsize*)(void*)(base); \
  268. __asm__ ("sthbrx %1,%y0" \
  269. : "=Z" (*ptrp) \
  270. : "r" (value)); \
  271. } while (0)
  272. #define __stwbrx(base, value) do { \
  273. typedef struct {char a[4];} wordsize; \
  274. wordsize *ptrp = (wordsize*)(void*)(base); \
  275. __asm__ ("stwbrx %1,%y0" \
  276. : "=Z" (*ptrp) \
  277. : "r" (value)); \
  278. } while (0)
  279. #ifdef __powerpc64__
  280. #define __stdbrx(base, value) do { \
  281. typedef struct {char a[8];} doublewordsize; \
  282. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  283. __asm__ ("stdbrx %1,%y0" \
  284. : "=Z" (*ptrp) \
  285. : "r" (value)); \
  286. } while (0)
  287. #else
  288. #define __stdbrx(base, value) do { \
  289. typedef struct {char a[8];} doublewordsize; \
  290. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  291. __asm__ ("stwbrx %L2,%y0\n" \
  292. "\tstwbrx %2,%y1" \
  293. : "=Z" (*ptrp), "=Z" (*((char *) ptrp + 4)) \
  294. : "r" (value)); \
  295. } while (0)
  296. #endif /* __powerpc64__ */
  297. #define __lwarx(base) __extension__ \
  298. ({unsigned int result; \
  299. typedef struct {char a[4];} wordsize; \
  300. wordsize *ptrp = (wordsize*)(void*)(base); \
  301. __asm__ volatile ("lwarx %0,%y1" \
  302. : "=r" (result) \
  303. : "Z" (*ptrp)); \
  304. result; })
  305. #ifdef __powerpc64__
  306. #define __ldarx(base) __extension__ \
  307. ({unsigned long long result; \
  308. typedef struct {char a[8];} doublewordsize; \
  309. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  310. __asm__ volatile ("ldarx %0,%y1" \
  311. : "=r" (result) \
  312. : "Z" (*ptrp)); \
  313. result; })
  314. #endif /* __powerpc64__ */
  315. #define __stwcx(base, value) __extension__ \
  316. ({unsigned int result; \
  317. typedef struct {char a[4];} wordsize; \
  318. wordsize *ptrp = (wordsize*)(void*)(base); \
  319. __asm__ volatile ("stwcx. %2,%y1\n" \
  320. "\tmfocrf %0,0x80" \
  321. : "=r" (result), \
  322. "=Z" (*ptrp) \
  323. : "r" (value) : "cr0"); \
  324. ((result & 0x20000000) >> 29); })
  325. #ifdef __powerpc64__
  326. #define __stdcx(base, value) __extension__ \
  327. ({unsigned long long result; \
  328. typedef struct {char a[8];} doublewordsize; \
  329. doublewordsize *ptrp = (doublewordsize*)(void*)(base); \
  330. __asm__ volatile ("stdcx. %2,%y1\n" \
  331. "\tmfocrf %0,0x80" \
  332. : "=r" (result), \
  333. "=Z" (*ptrp) \
  334. : "r" (value) : "cr0"); \
  335. ((result & 0x20000000) >> 29); })
  336. #endif /* __powerpc64__ */
  337. #define __mffs() __extension__ \
  338. ({double result; \
  339. __asm__ volatile ("mffs %0" : "=d" (result)); \
  340. result; })
  341. #define __mtfsf(mask,value) \
  342. __asm__ volatile ("mtfsf %0,%1" : : "n" (mask), "d" ((double) (value)))
  343. #define __mtfsfi(bits,field) \
  344. __asm__ volatile ("mtfsfi %0,%1" : : "n" (bits), "n" (field))
  345. #define __mtfsb0(bit) __asm__ volatile ("mtfsb0 %0" : : "n" (bit))
  346. #define __mtfsb1(bit) __asm__ volatile ("mtfsb1 %0" : : "n" (bit))
  347. #define __setflm(v) __extension__ \
  348. ({double result; \
  349. __asm__ volatile ("mffs %0\n\tmtfsf 255,%1" \
  350. : "=&d" (result) \
  351. : "d" ((double) (v))); \
  352. result; })
  353. /* __builtin_fabs may perform unnecessary rounding. */
  354. /* Rename __fabs and __fabsf to work around internal prototypes defined
  355. in bits/mathcalls.h with some glibc versions. */
  356. #define __fabs __ppu_fabs
  357. #define __fabsf __ppu_fabsf
  358. static __inline__ double __fabs(double x) __attribute__((always_inline));
  359. static __inline__ double
  360. __fabs(double x)
  361. {
  362. double r;
  363. __asm__("fabs %0,%1" : "=d"(r) : "d"(x));
  364. return r;
  365. }
  366. static __inline__ float __fabsf(float x) __attribute__((always_inline));
  367. static __inline__ float
  368. __fabsf(float x)
  369. {
  370. float r;
  371. __asm__("fabs %0,%1" : "=f"(r) : "f"(x));
  372. return r;
  373. }
  374. static __inline__ double __fnabs(double x) __attribute__((always_inline));
  375. static __inline__ double
  376. __fnabs(double x)
  377. {
  378. double r;
  379. __asm__("fnabs %0,%1" : "=d"(r) : "d"(x));
  380. return r;
  381. }
  382. static __inline__ float __fnabsf(float x) __attribute__((always_inline));
  383. static __inline__ float
  384. __fnabsf(float x)
  385. {
  386. float r;
  387. __asm__("fnabs %0,%1" : "=f"(r) : "f"(x));
  388. return r;
  389. }
  390. static __inline__ double __fmadd(double x, double y, double z)
  391. __attribute__((always_inline));
  392. static __inline__ double
  393. __fmadd(double x, double y, double z)
  394. {
  395. double r;
  396. __asm__("fmadd %0,%1,%2,%3" : "=d"(r) : "d"(x),"d"(y),"d"(z));
  397. return r;
  398. }
  399. static __inline__ double __fmsub(double x, double y, double z)
  400. __attribute__((always_inline));
  401. static __inline__ double
  402. __fmsub(double x, double y, double z)
  403. {
  404. double r;
  405. __asm__("fmsub %0,%1,%2,%3" : "=d"(r) : "d"(x),"d"(y),"d"(z));
  406. return r;
  407. }
  408. static __inline__ double __fnmadd(double x, double y, double z)
  409. __attribute__((always_inline));
  410. static __inline__ double
  411. __fnmadd(double x, double y, double z)
  412. {
  413. double r;
  414. __asm__("fnmadd %0,%1,%2,%3" : "=d"(r) : "d"(x),"d"(y),"d"(z));
  415. return r;
  416. }
  417. static __inline__ double __fnmsub(double x, double y, double z)
  418. __attribute__((always_inline));
  419. static __inline__ double
  420. __fnmsub(double x, double y, double z)
  421. {
  422. double r;
  423. __asm__("fnmsub %0,%1,%2,%3" : "=d"(r) : "d"(x),"d"(y),"d"(z));
  424. return r;
  425. }
  426. static __inline__ float __fmadds(float x, float y, float z)
  427. __attribute__((always_inline));
  428. static __inline__ float
  429. __fmadds(float x, float y, float z)
  430. {
  431. float r;
  432. __asm__("fmadds %0,%1,%2,%3" : "=f"(r) : "f"(x),"f"(y),"f"(z));
  433. return r;
  434. }
  435. static __inline__ float __fmsubs(float x, float y, float z)
  436. __attribute__((always_inline));
  437. static __inline__ float
  438. __fmsubs(float x, float y, float z)
  439. {
  440. float r;
  441. __asm__("fmsubs %0,%1,%2,%3" : "=f"(r) : "f"(x),"f"(y),"f"(z));
  442. return r;
  443. }
  444. static __inline__ float __fnmadds(float x, float y, float z)
  445. __attribute__((always_inline));
  446. static __inline__ float
  447. __fnmadds(float x, float y, float z)
  448. {
  449. float r;
  450. __asm__("fnmadds %0,%1,%2,%3" : "=f"(r) : "f"(x),"f"(y),"f"(z));
  451. return r;
  452. }
  453. static __inline__ float __fnmsubs(float x, float y, float z)
  454. __attribute__((always_inline));
  455. static __inline__ float
  456. __fnmsubs(float x, float y, float z)
  457. {
  458. float r;
  459. __asm__("fnmsubs %0,%1,%2,%3" : "=f"(r) : "f"(x),"f"(y),"f"(z));
  460. return r;
  461. }
  462. static __inline__ double __fsel(double x, double y, double z)
  463. __attribute__((always_inline));
  464. static __inline__ double
  465. __fsel(double x, double y, double z)
  466. {
  467. double r;
  468. __asm__("fsel %0,%1,%2,%3" : "=d"(r) : "d"(x),"d"(y),"d"(z));
  469. return r;
  470. }
  471. static __inline__ float __fsels(float x, float y, float z)
  472. __attribute__((always_inline));
  473. static __inline__ float
  474. __fsels(float x, float y, float z)
  475. {
  476. float r;
  477. __asm__("fsel %0,%1,%2,%3" : "=f"(r) : "f"(x),"f"(y),"f"(z));
  478. return r;
  479. }
  480. static __inline__ double __frsqrte(double x) __attribute__((always_inline));
  481. static __inline__ double
  482. __frsqrte(double x)
  483. {
  484. double r;
  485. __asm__("frsqrte %0,%1" : "=d" (r) : "d" (x));
  486. return r;
  487. }
  488. static __inline__ float __fres(float x) __attribute__((always_inline));
  489. static __inline__ float
  490. __fres(float x)
  491. {
  492. float r;
  493. __asm__("fres %0,%1" : "=f"(r) : "f"(x));
  494. return r;
  495. }
  496. static __inline__ double __fsqrt(double x) __attribute__((always_inline));
  497. static __inline__ double
  498. __fsqrt(double x)
  499. {
  500. double r;
  501. __asm__("fsqrt %0,%1" : "=d"(r) : "d"(x));
  502. return r;
  503. }
  504. static __inline__ float __fsqrts(float x) __attribute__((always_inline));
  505. static __inline__ float
  506. __fsqrts(float x)
  507. {
  508. float r;
  509. __asm__("fsqrts %0,%1" : "=f"(r) : "f"(x));
  510. return r;
  511. }
  512. static __inline__ double __fmul (double a, double b) __attribute__ ((always_inline));
  513. static __inline__ double
  514. __fmul(double a, double b)
  515. {
  516. double d;
  517. __asm__ ("fmul %0,%1,%2" : "=d" (d) : "d" (a), "d" (b));
  518. return d;
  519. }
  520. static __inline__ float __fmuls (float a, float b) __attribute__ ((always_inline));
  521. static __inline__ float
  522. __fmuls (float a, float b)
  523. {
  524. float d;
  525. __asm__ ("fmuls %0,%1,%2" : "=d" (d) : "f" (a), "f" (b));
  526. return d;
  527. }
  528. static __inline__ float __frsp (float a) __attribute__ ((always_inline));
  529. static __inline__ float
  530. __frsp (float a)
  531. {
  532. float d;
  533. __asm__ ("frsp %0,%1" : "=d" (d) : "f" (a));
  534. return d;
  535. }
  536. static __inline__ double __fcfid (long long a) __attribute__((always_inline));
  537. static __inline__ double
  538. __fcfid (long long a)
  539. {
  540. double d;
  541. __asm__ ("fcfid %0,%1" : "=d" (d) : "d" (a));
  542. return d;
  543. }
  544. static __inline__ long long __fctid (double a) __attribute__ ((always_inline));
  545. static __inline__ long long
  546. __fctid (double a)
  547. {
  548. long long d;
  549. __asm__ ("fctid %0,%1" : "=d" (d) : "d" (a));
  550. return d;
  551. }
  552. static __inline__ long long __fctidz (double a) __attribute__ ((always_inline));
  553. static __inline__ long long
  554. __fctidz (double a)
  555. {
  556. long long d;
  557. __asm__ ("fctidz %0,%1" : "=d" (d) : "d" (a));
  558. return d;
  559. }
  560. static __inline__ int __fctiw (double a) __attribute__ ((always_inline));
  561. static __inline__ int
  562. __fctiw (double a)
  563. {
  564. unsigned long long d;
  565. __asm__ ("fctiw %0,%1" : "=d" (d) : "d" (a));
  566. return (int) d;
  567. }
  568. static __inline__ int __fctiwz (double a) __attribute__ ((always_inline));
  569. static __inline__ int
  570. __fctiwz (double a)
  571. {
  572. long long d;
  573. __asm__ ("fctiwz %0,%1" : "=d" (d) : "d" (a));
  574. return (int) d;
  575. }
  576. #ifdef __powerpc64__
  577. #define __rldcl(a,b,mb) __extension__ \
  578. ({ \
  579. unsigned long long d; \
  580. __asm__ ("rldcl %0,%1,%2,%3" : "=r" (d) : "r" (a), "r" (b), "i" (mb)); \
  581. d; \
  582. })
  583. #define __rldcr(a,b,me) __extension__ \
  584. ({ \
  585. unsigned long long d; \
  586. __asm__ ("rldcr %0,%1,%2,%3" : "=r" (d) : "r" (a), "r" (b), "i" (me)); \
  587. d; \
  588. })
  589. #define __rldic(a,sh,mb) __extension__ \
  590. ({ \
  591. unsigned long long d; \
  592. __asm__ ("rldic %0,%1,%2,%3" : "=r" (d) : "r" (a), "i" (sh), "i" (mb)); \
  593. d; \
  594. })
  595. #define __rldicl(a,sh,mb) __extension__ \
  596. ({ \
  597. unsigned long long d; \
  598. __asm__ ("rldicl %0,%1,%2,%3" : "=r" (d) : "r" (a), "i" (sh), "i" (mb)); \
  599. d; \
  600. })
  601. #define __rldicr(a,sh,me) __extension__ \
  602. ({ \
  603. unsigned long long d; \
  604. __asm__ ("rldicr %0,%1,%2,%3" : "=r" (d) : "r" (a), "i" (sh), "i" (me)); \
  605. d; \
  606. })
  607. #define __rldimi(a,b,sh,mb) __extension__ \
  608. ({ \
  609. unsigned long long d; \
  610. __asm__ ("rldimi %0,%1,%2,%3" : "=r" (d) : "r" (b), "i" (sh), "i" (mb), "0" (a)); \
  611. d; \
  612. })
  613. #endif /* __powerpc64__ */
  614. #define __rlwimi(a,b,sh,mb,me) __extension__ \
  615. ({ \
  616. unsigned int d; \
  617. __asm__ ("rlwimi %0,%1,%2,%3,%4" : "=r" (d) : "r" (b), "i" (sh), "i" (mb), "i" (me), "0" (a)); \
  618. d; \
  619. })
  620. #define __rlwinm(a,sh,mb,me) __extension__ \
  621. ({ \
  622. unsigned int d; \
  623. __asm__ ("rlwinm %0,%1,%2,%3,%4" : "=r" (d) : "r" (a), "i" (sh), "i" (mb), "i" (me)); \
  624. d; \
  625. })
  626. #define __rlwnm(a,b,mb,me) __extension__ \
  627. ({ \
  628. unsigned int d; \
  629. __asm__ ("rlwnm %0,%1,%2,%3,%4" : "=r" (d) : "r" (a), "r" (b), "i" (mb), "i" (me)); \
  630. d; \
  631. })
  632. #ifdef __cplusplus
  633. }
  634. #endif
  635. #endif /* _PPU_INTRINSICS_H */