ushmedia.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /* Copyright (C) 2000-2015 Free Software Foundation, Inc.
  2. This file is part of GCC.
  3. GCC is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. GCC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License 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. /* ushmedia.h: Intrinsics corresponding to SHmedia instructions that
  19. may be executed in both user and privileged mode. */
  20. #ifndef _USHMEDIA_H
  21. #define _USHMEDIA_H
  22. #if __SHMEDIA__
  23. #if ! __SH4_NO_FPU
  24. typedef float __GCC_FV __attribute__ ((vector_size (4 * sizeof (float))));
  25. typedef float __GCC_MTRX __attribute__ ((vector_size (16 * sizeof (float))));
  26. #endif
  27. static __inline unsigned long long
  28. sh_media_MABS_L (unsigned long long mm)
  29. {
  30. typedef float v2si __attribute__ ((mode(V2SI)));
  31. return (unsigned long long) __builtin_absv2si2 ((v2si) mm);
  32. }
  33. static __inline unsigned long long
  34. sh_media_MABS_W (unsigned long long mm)
  35. {
  36. typedef float v4hi __attribute__ ((mode(V4HI)));
  37. return (unsigned long long) __builtin_absv4hi2 ((v4hi) mm);
  38. }
  39. static __inline unsigned long long
  40. sh_media_MADD_L (unsigned long long mm, unsigned long long mn)
  41. {
  42. typedef float v2si __attribute__ ((mode(V2SI)));
  43. return (unsigned long long) __builtin_addv2si3 ((v2si) mm, (v2si) mn);
  44. }
  45. static __inline unsigned long long
  46. sh_media_MADD_W (unsigned long long mm, unsigned long long mn)
  47. {
  48. typedef float v4hi __attribute__ ((mode(V4HI)));
  49. return (unsigned long long) __builtin_addv4hi3 ((v4hi) mm, (v4hi) mn);
  50. }
  51. static __inline unsigned long long
  52. sh_media_MADDS_L (unsigned long long mm, unsigned long long mn)
  53. {
  54. typedef float v2si __attribute__ ((mode(V2SI)));
  55. return (unsigned long long) __builtin_ssaddv2si3 ((v2si) mm, (v2si) mn);
  56. }
  57. static __inline unsigned long long
  58. sh_media_MADDS_UB (unsigned long long mm, unsigned long long mn)
  59. {
  60. typedef float v8qi __attribute__ ((mode(V8QI)));
  61. return (unsigned long long) __builtin_usaddv8qi3 ((v8qi) mm, (v8qi) mn);
  62. }
  63. static __inline unsigned long long
  64. sh_media_MADDS_W (unsigned long long mm, unsigned long long mn)
  65. {
  66. typedef float v4hi __attribute__ ((mode(V4HI)));
  67. return (unsigned long long) __builtin_ssaddv4hi3 ((v4hi) mm, (v4hi) mn);
  68. }
  69. static __inline unsigned long long
  70. sh_media_MCMPEQ_B (unsigned long long mm, unsigned long long mn)
  71. {
  72. typedef float v8qi __attribute__ ((mode(V8QI)));
  73. return (unsigned long long) __builtin_sh_media_MCMPEQ_B ((v8qi) mm,
  74. (v8qi) mn);
  75. }
  76. static __inline unsigned long long
  77. sh_media_MCMPEQ_L (unsigned long long mm, unsigned long long mn)
  78. {
  79. typedef float v2si __attribute__ ((mode(V2SI)));
  80. return (unsigned long long) __builtin_sh_media_MCMPEQ_L ((v2si) mm,
  81. (v2si) mn);
  82. }
  83. static __inline unsigned long long
  84. sh_media_MCMPEQ_W (unsigned long long mm, unsigned long long mn)
  85. {
  86. typedef float v4hi __attribute__ ((mode(V4HI)));
  87. return (unsigned long long) __builtin_sh_media_MCMPEQ_W ((v4hi) mm,
  88. (v4hi) mn);
  89. }
  90. static __inline unsigned long long
  91. sh_media_MCMPGT_UB (unsigned long long mm, unsigned long long mn)
  92. {
  93. typedef float v8qi __attribute__ ((mode(V8QI)));
  94. return (unsigned long long) __builtin_sh_media_MCMPGT_UB ((v8qi) mm,
  95. (v8qi) mn);
  96. }
  97. static __inline unsigned long long
  98. sh_media_MCMPGT_L (unsigned long long mm, unsigned long long mn)
  99. {
  100. typedef float v2si __attribute__ ((mode(V2SI)));
  101. return (unsigned long long) __builtin_sh_media_MCMPGT_L ((v2si) mm,
  102. (v2si) mn);
  103. }
  104. static __inline unsigned long long
  105. sh_media_MCMPGT_W (unsigned long long mm, unsigned long long mn)
  106. {
  107. typedef float v4hi __attribute__ ((mode(V4HI)));
  108. return (unsigned long long) __builtin_sh_media_MCMPGT_W ((v4hi) mm,
  109. (v4hi) mn);
  110. }
  111. #define sh_media_MCMV __builtin_sh_media_MCMV
  112. static __inline unsigned long long
  113. sh_media_MCNVS_LW (unsigned long long mm, unsigned long long mn)
  114. {
  115. typedef float v2si __attribute__ ((mode(V2SI)));
  116. typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
  117. return (unsigned long long) __builtin_sh_media_MCNVS_LW ((v2si) mm,
  118. (uv2si) mn);
  119. }
  120. static __inline unsigned long long
  121. sh_media_MCNVS_WB (unsigned long long mm, unsigned long long mn)
  122. {
  123. typedef float v4hi __attribute__ ((mode(V4HI)));
  124. return (unsigned long long) __builtin_sh_media_MCNVS_WB ((v4hi) mm,
  125. (v4hi) mn);
  126. }
  127. static __inline unsigned long long
  128. sh_media_MCNVS_WUB (unsigned long long mm, unsigned long long mn)
  129. {
  130. typedef float v4hi __attribute__ ((mode(V4HI)));
  131. return (unsigned long long) __builtin_sh_media_MCNVS_WUB ((v4hi) mm,
  132. (v4hi) mn);
  133. }
  134. static __inline unsigned long long
  135. sh_media_MEXTR1 (unsigned long long mm, unsigned long long mn)
  136. {
  137. typedef float v8qi __attribute__ ((mode(V8QI)));
  138. return (unsigned long long) __builtin_sh_media_MEXTR1 ((v8qi) mm,
  139. (v8qi) mn);
  140. }
  141. static __inline unsigned long long
  142. sh_media_MEXTR2 (unsigned long long mm, unsigned long long mn)
  143. {
  144. typedef float v8qi __attribute__ ((mode(V8QI)));
  145. return (unsigned long long) __builtin_sh_media_MEXTR2 ((v8qi) mm,
  146. (v8qi) mn);
  147. }
  148. static __inline unsigned long long
  149. sh_media_MEXTR3 (unsigned long long mm, unsigned long long mn)
  150. {
  151. typedef float v8qi __attribute__ ((mode(V8QI)));
  152. return (unsigned long long) __builtin_sh_media_MEXTR3 ((v8qi) mm,
  153. (v8qi) mn);
  154. }
  155. static __inline unsigned long long
  156. sh_media_MEXTR4 (unsigned long long mm, unsigned long long mn)
  157. {
  158. typedef float v8qi __attribute__ ((mode(V8QI)));
  159. return (unsigned long long) __builtin_sh_media_MEXTR4 ((v8qi) mm,
  160. (v8qi) mn);
  161. }
  162. static __inline unsigned long long
  163. sh_media_MEXTR5 (unsigned long long mm, unsigned long long mn)
  164. {
  165. typedef float v8qi __attribute__ ((mode(V8QI)));
  166. return (unsigned long long) __builtin_sh_media_MEXTR5 ((v8qi) mm,
  167. (v8qi) mn);
  168. }
  169. static __inline unsigned long long
  170. sh_media_MEXTR6 (unsigned long long mm, unsigned long long mn)
  171. {
  172. typedef float v8qi __attribute__ ((mode(V8QI)));
  173. return (unsigned long long) __builtin_sh_media_MEXTR6 ((v8qi) mm,
  174. (v8qi) mn);
  175. }
  176. static __inline unsigned long long
  177. sh_media_MEXTR7 (unsigned long long mm, unsigned long long mn)
  178. {
  179. typedef float v8qi __attribute__ ((mode(V8QI)));
  180. return (unsigned long long) __builtin_sh_media_MEXTR7 ((v8qi) mm,
  181. (v8qi) mn);
  182. }
  183. static __inline unsigned long long
  184. sh_media_MMACFX_WL (unsigned long long mm, unsigned long long mn,
  185. unsigned long long mw)
  186. {
  187. typedef float v2hi __attribute__ ((mode(V2HI)));
  188. typedef float v2si __attribute__ ((mode(V2SI)));
  189. typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
  190. long mm_l = (long) mm;
  191. long mn_l = (long) mn;
  192. return ((unsigned long long)
  193. __builtin_sh_media_MMACFX_WL ((v2hi) mm_l, (v2hi) mn_l,
  194. (uv2si) mw));
  195. }
  196. static __inline unsigned long long
  197. sh_media_MMACNFX_WL (unsigned long long mm, unsigned long long mn,
  198. unsigned long long mw)
  199. {
  200. typedef float v2hi __attribute__ ((mode(V2HI)));
  201. typedef float v2si __attribute__ ((mode(V2SI)));
  202. typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
  203. long mm_l = (long) mm;
  204. long mn_l = (long) mn;
  205. return ((unsigned long long)
  206. __builtin_sh_media_MMACNFX_WL ((v2hi) mm_l, (v2hi) mn_l,
  207. (uv2si) mw));
  208. }
  209. static __inline unsigned long long
  210. sh_media_MMUL_L (unsigned long long mm, unsigned long long mn)
  211. {
  212. typedef float v2si __attribute__ ((mode(V2SI)));
  213. return (unsigned long long) __builtin_mulv2si3 ((v2si) mm, (v2si) mn);
  214. }
  215. static __inline unsigned long long
  216. sh_media_MMUL_W (unsigned long long mm, unsigned long long mn)
  217. {
  218. typedef float v4hi __attribute__ ((mode(V4HI)));
  219. return (unsigned long long) __builtin_mulv4hi3 ((v4hi) mm, (v4hi) mn);
  220. }
  221. static __inline unsigned long long
  222. sh_media_MMULFX_L (unsigned long long mm, unsigned long long mn)
  223. {
  224. typedef float v2si __attribute__ ((mode(V2SI)));
  225. return (unsigned long long) __builtin_sh_media_MMULFX_L ((v2si) mm,
  226. (v2si) mn);
  227. }
  228. static __inline unsigned long long
  229. sh_media_MMULFX_W (unsigned long long mm, unsigned long long mn)
  230. {
  231. typedef float v4hi __attribute__ ((mode(V4HI)));
  232. return (unsigned long long) __builtin_sh_media_MMULFX_W ((v4hi) mm,
  233. (v4hi) mn);
  234. }
  235. static __inline unsigned long long
  236. sh_media_MMULFXRP_W (unsigned long long mm, unsigned long long mn)
  237. {
  238. typedef float v4hi __attribute__ ((mode(V4HI)));
  239. return (unsigned long long) __builtin_sh_media_MMULFXRP_W ((v4hi) mm,
  240. (v4hi) mn);
  241. }
  242. static __inline unsigned long long
  243. sh_media_MMULHI_WL (unsigned long long mm, unsigned long long mn)
  244. {
  245. typedef float v4hi __attribute__ ((mode(V4HI)));
  246. return (unsigned long long) __builtin_sh_media_MMULHI_WL ((v4hi) mm,
  247. (v4hi) mn);
  248. }
  249. static __inline unsigned long long
  250. sh_media_MMULLO_WL (unsigned long long mm, unsigned long long mn)
  251. {
  252. typedef float v4hi __attribute__ ((mode(V4HI)));
  253. return (unsigned long long) __builtin_sh_media_MMULLO_WL ((v4hi) mm,
  254. (v4hi) mn);
  255. }
  256. static __inline unsigned long long
  257. sh_media_MMULSUM_WQ (unsigned long long mm, unsigned long long mn,
  258. unsigned long long mw)
  259. {
  260. typedef unsigned int uv4hi __attribute__ ((mode(V4HI)));
  261. return __builtin_sh_media_MMULSUM_WQ ((uv4hi) mm, (uv4hi) mn, mw);
  262. }
  263. static __inline unsigned long long
  264. sh_media_MPERM_W (unsigned long long mm, unsigned int mn)
  265. {
  266. typedef float v4hi __attribute__ ((mode(V4HI)));
  267. return (unsigned long long) __builtin_sh_media_MPERM_W ((v4hi) mm, mn);
  268. }
  269. static __inline unsigned long long
  270. sh_media_MSAD_UBQ (unsigned long long mm, unsigned long long mn,
  271. unsigned long long mw)
  272. {
  273. typedef unsigned int uv8qi __attribute__ ((mode(V8QI)));
  274. return __builtin_sh_media_MSAD_UBQ ((uv8qi) mm, (uv8qi) mn, mw);
  275. }
  276. static __inline unsigned long long
  277. sh_media_MSHALDS_L (unsigned long long mm, unsigned int mn)
  278. {
  279. typedef float v2si __attribute__ ((mode(V2SI)));
  280. return (unsigned long long) __builtin_sh_media_MSHALDS_L ((v2si) mm, mn);
  281. }
  282. static __inline unsigned long long
  283. sh_media_MSHALDS_W (unsigned long long mm, unsigned int mn)
  284. {
  285. typedef float v4hi __attribute__ ((mode(V4HI)));
  286. return (unsigned long long) __builtin_sh_media_MSHALDS_W ((v4hi) mm, mn);
  287. }
  288. static __inline unsigned long long
  289. sh_media_MSHARD_L (unsigned long long mm, unsigned int mn)
  290. {
  291. typedef float v2si __attribute__ ((mode(V2SI)));
  292. return (unsigned long long) __builtin_ashrv2si3 ((v2si) mm, mn);
  293. }
  294. static __inline unsigned long long
  295. sh_media_MSHARD_W (unsigned long long mm, unsigned int mn)
  296. {
  297. typedef float v4hi __attribute__ ((mode(V4HI)));
  298. return (unsigned long long) __builtin_ashrv4hi3 ((v4hi) mm, mn);
  299. }
  300. #define sh_media_MSHARDS_Q __builtin_sh_media_MSHARDS_Q
  301. static __inline unsigned long long
  302. sh_media_MSHFHI_B (unsigned long long mm, unsigned long long mn)
  303. {
  304. typedef float v8qi __attribute__ ((mode(V8QI)));
  305. return (unsigned long long) __builtin_sh_media_MSHFHI_B ((v8qi) mm,
  306. (v8qi) mn);
  307. }
  308. static __inline unsigned long long
  309. sh_media_MSHFHI_L (unsigned long long mm, unsigned long long mn)
  310. {
  311. typedef float v2si __attribute__ ((mode(V2SI)));
  312. return (unsigned long long) __builtin_sh_media_MSHFHI_L ((v2si) mm,
  313. (v2si) mn);
  314. }
  315. static __inline unsigned long long
  316. sh_media_MSHFHI_W (unsigned long long mm, unsigned long long mn)
  317. {
  318. typedef float v4hi __attribute__ ((mode(V4HI)));
  319. return (unsigned long long) __builtin_sh_media_MSHFHI_W ((v4hi) mm,
  320. (v4hi) mn);
  321. }
  322. static __inline unsigned long long
  323. sh_media_MSHFLO_B (unsigned long long mm, unsigned long long mn)
  324. {
  325. typedef float v8qi __attribute__ ((mode(V8QI)));
  326. return (unsigned long long) __builtin_sh_media_MSHFLO_B ((v8qi) mm,
  327. (v8qi) mn);
  328. }
  329. static __inline unsigned long long
  330. sh_media_MSHFLO_L (unsigned long long mm, unsigned long long mn)
  331. {
  332. typedef float v2si __attribute__ ((mode(V2SI)));
  333. return (unsigned long long) __builtin_sh_media_MSHFLO_L ((v2si) mm,
  334. (v2si) mn);
  335. }
  336. static __inline unsigned long long
  337. sh_media_MSHFLO_W (unsigned long long mm, unsigned long long mn)
  338. {
  339. typedef float v4hi __attribute__ ((mode(V4HI)));
  340. return (unsigned long long) __builtin_sh_media_MSHFLO_W ((v4hi) mm,
  341. (v4hi) mn);
  342. }
  343. static __inline unsigned long long
  344. sh_media_MSHLLD_L (unsigned long long mm, unsigned int mn)
  345. {
  346. typedef float v2si __attribute__ ((mode(V2SI)));
  347. return (unsigned long long) __builtin_ashlv2si3 ((v2si) mm, mn);
  348. }
  349. static __inline unsigned long long
  350. sh_media_MSHLLD_W (unsigned long long mm, unsigned int mn)
  351. {
  352. typedef float v4hi __attribute__ ((mode(V4HI)));
  353. return (unsigned long long) __builtin_ashlv4hi3 ((v4hi) mm, mn);
  354. }
  355. static __inline unsigned long long
  356. sh_media_MSHLRD_L (unsigned long long mm, unsigned int mn)
  357. {
  358. typedef float v2si __attribute__ ((mode(V2SI)));
  359. return (unsigned long long) __builtin_lshrv2si3 ((v2si) mm, mn);
  360. }
  361. static __inline unsigned long long
  362. sh_media_MSHLRD_W (unsigned long long mm, unsigned int mn)
  363. {
  364. typedef float v4hi __attribute__ ((mode(V4HI)));
  365. return (unsigned long long) __builtin_lshrv4hi3 ((v4hi) mm, mn);
  366. }
  367. static __inline unsigned long long
  368. sh_media_MSUB_L (unsigned long long mm, unsigned long long mn)
  369. {
  370. typedef float v2si __attribute__ ((mode(V2SI)));
  371. return (unsigned long long) __builtin_subv2si3 ((v2si) mm, (v2si) mn);
  372. }
  373. static __inline unsigned long long
  374. sh_media_MSUB_W (unsigned long long mm, unsigned long long mn)
  375. {
  376. typedef float v4hi __attribute__ ((mode(V4HI)));
  377. return (unsigned long long) __builtin_subv4hi3 ((v4hi) mm, (v4hi) mn);
  378. }
  379. static __inline unsigned long long
  380. sh_media_MSUBS_L (unsigned long long mm, unsigned long long mn)
  381. {
  382. typedef float v2si __attribute__ ((mode(V2SI)));
  383. return (unsigned long long) __builtin_sssubv2si3 ((v2si) mm, (v2si) mn);
  384. }
  385. static __inline unsigned long long
  386. sh_media_MSUBS_UB (unsigned long long mm, unsigned long long mn)
  387. {
  388. typedef float v8qi __attribute__ ((mode(V8QI)));
  389. return (unsigned long long) __builtin_ussubv8qi3 ((v8qi) mm, (v8qi) mn);
  390. }
  391. static __inline unsigned long long
  392. sh_media_MSUBS_W (unsigned long long mm, unsigned long long mn)
  393. {
  394. typedef float v4hi __attribute__ ((mode(V4HI)));
  395. return (unsigned long long) __builtin_sssubv4hi3 ((v4hi) mm, (v4hi) mn);
  396. }
  397. #if ! __SH4_NOFPU__
  398. /* Floating-point Intrinsics */
  399. #define sh_media_FABS_D __builtin_fabs
  400. #define sh_media_FABS_S __builtin_fabsf
  401. #define sh_media_FCMPUN_D __builtin_isunordered
  402. #define sh_media_FCMPUN_S __builtin_isunordered
  403. static __inline float sh_media_FCOSA_S (float fg)
  404. {
  405. union { int i; float f; } u;
  406. u.f = fg;
  407. return __builtin_sh_media_FCOSA_S (u.i);
  408. }
  409. static __inline float
  410. sh_media_FGETSCR (void)
  411. {
  412. float f;
  413. __asm volatile ("fgetscr %0" : "=f" (f));
  414. return f;
  415. }
  416. static __inline float
  417. sh_media_FIPR_S (const void *fvg, const void *fvh)
  418. {
  419. typedef float v4sf __attribute__ ((mode(V4SF)));
  420. v4sf vg = *(v4sf*) fvg;
  421. v4sf vh = *(v4sf*) fvh;
  422. return __builtin_sh_media_FIPR_S (vg, vh);
  423. }
  424. #if 0
  425. /* This gives different results for -O0 */
  426. static __inline float
  427. sh_media_FMAC_S (float fg, float fh, float fq)
  428. {
  429. return fg * fh + fq;
  430. }
  431. #else
  432. #define sh_media_FMAC_S __builtin_sh_media_FMAC_S
  433. #endif
  434. static __inline long long
  435. sh_media_FMOV_DQ (double dg)
  436. {
  437. union { long long l; double d; } u;
  438. u.d = dg;
  439. return u.l;
  440. }
  441. static __inline float
  442. sh_media_FMOV_LS (int mm)
  443. {
  444. union { int i; float f; } u;
  445. u.i = mm;
  446. return u.f;
  447. }
  448. static __inline double
  449. sh_media_FMOV_QD (long long mm)
  450. {
  451. union { long long l; double d; } u;
  452. u.l = mm;
  453. return u.d;
  454. }
  455. static __inline int
  456. sh_media_FMOV_SL (float fg)
  457. {
  458. union { int i; float f; } u;
  459. u.f = fg;
  460. return u.i;
  461. }
  462. static __inline void
  463. sh_media_FPUTSCR (float fg)
  464. {
  465. __asm volatile ("fputscr %0" : : "f" (fg));
  466. }
  467. static __inline float sh_media_FSINA_S (float fg)
  468. {
  469. union { int i; float f; } u;
  470. u.f = fg;
  471. return __builtin_sh_media_FSINA_S (u.i);
  472. }
  473. /* Can't use __builtin_sqrt / __builtin_sqrtf because they still implement
  474. error handling unless -ffast-math is used. */
  475. #define sh_media_FSQRT_D __builtin_sh_media_FSQRT_D
  476. #define sh_media_FSQRT_S __builtin_sh_media_FSQRT_S
  477. #define sh_media_FSRRA_S __builtin_sh_media_FSRRA_S
  478. static __inline void
  479. sh_media_FTRV_S (const void *mtrxg, const void *fvh, void *fvf)
  480. {
  481. typedef float v16sf __attribute__ ((mode(V16SF)));
  482. typedef float v4sf __attribute__ ((mode(V4SF)));
  483. v16sf mtrx = *(v16sf*) mtrxg;
  484. v4sf vh = *(v4sf*) fvh;
  485. *(v4sf*) fvf = __builtin_sh_media_FTRV_S (mtrx, vh);
  486. }
  487. #endif /* ! __SH4_NOFPU__ */
  488. /* Not implemented here: Control and Configuration intrinsics. */
  489. /* Misaligned Access Support intrinsics */
  490. static __inline unsigned long long
  491. sh_media_LDHI_L (void *p, int s)
  492. {
  493. return __builtin_sh_media_LDHI_L ((char *)p + s);
  494. }
  495. static __inline unsigned long long
  496. sh_media_LDHI_Q (void *p, int s)
  497. {
  498. return __builtin_sh_media_LDHI_Q ((char *)p + s);
  499. }
  500. static __inline unsigned long long
  501. sh_media_LDLO_L (void *p, int s)
  502. {
  503. return __builtin_sh_media_LDLO_L ((char *)p + s);
  504. }
  505. static __inline unsigned long long
  506. sh_media_LDLO_Q (void *p, int s)
  507. {
  508. return __builtin_sh_media_LDLO_Q ((char *)p + s);
  509. }
  510. static __inline void
  511. sh_media_STHI_L (void *p, int s, unsigned int mw)
  512. {
  513. __builtin_sh_media_STHI_L ((char*)p + s, mw);
  514. }
  515. static __inline void
  516. sh_media_STHI_Q (void *p, int s, unsigned long long mw)
  517. {
  518. __builtin_sh_media_STHI_Q ((char*)p + s, mw);
  519. }
  520. static __inline void
  521. sh_media_STLO_L (void *p, int s, unsigned int mw)
  522. {
  523. __builtin_sh_media_STLO_L ((char*)p + s, mw);
  524. }
  525. static __inline void
  526. sh_media_STLO_Q (void *p, int s, unsigned long long mw)
  527. {
  528. __builtin_sh_media_STLO_Q ((char*)p + s, mw);
  529. }
  530. /* Miscellaneous intrinsics */
  531. #define sh_media_NSB __builtin_sh_media_NSB
  532. static __inline unsigned long long
  533. sh_media_BYTEREV (unsigned long long mm)
  534. {
  535. typedef float v8qi __attribute__ ((mode(V8QI)));
  536. return (unsigned long long) __builtin_sh_media_BYTEREV ((v8qi) mm);
  537. }
  538. __inline__ static unsigned long long
  539. sh_media_CMVEQ (unsigned long long mm, unsigned long long mn, unsigned long long mw) __attribute__ ((always_inline));
  540. __inline__ static unsigned long long
  541. sh_media_CMVEQ (unsigned long long mm, unsigned long long mn, unsigned long long mw)
  542. {
  543. return mm == 0 ? mn : mw;
  544. }
  545. __inline__ static unsigned long long
  546. sh_media_CMVNE (unsigned long long mm, unsigned long long mn, unsigned long long mw) __attribute__ ((always_inline));
  547. __inline__ static unsigned long long
  548. sh_media_CMVNE (unsigned long long mm, unsigned long long mn, unsigned long long mw)
  549. {
  550. return mm != 0 ? mn : mw;
  551. }
  552. static __inline long long
  553. sh_media_ADDZ_L (unsigned int mm, unsigned int mn)
  554. {
  555. return mm + mn;
  556. }
  557. /* NOP and Synchronization intrinsics not implemented here. */
  558. static __inline__ void sh_media_PREFO(void *mm, int s)
  559. {
  560. __builtin_sh_media_PREFO (mm + s, 0, 0);
  561. }
  562. /* Event Handling intrinsics not implemented here. */
  563. /* Old asm stuff */
  564. static __inline__
  565. void
  566. sh_media_NOP (void)
  567. {
  568. __asm__ ("nop" : :);
  569. }
  570. __inline__ static
  571. unsigned long long
  572. sh_media_SWAP_Q (void *mm, long long mn, unsigned long long mw)
  573. {
  574. unsigned long long res;
  575. unsigned long long *addr = (unsigned long long *)((char *)mm + mn);
  576. __asm__ ("swap.q %m1, %0" : "=r" (res), "+o" (*addr) : "0" (mw));
  577. return res;
  578. }
  579. __inline__ static
  580. void
  581. sh_media_SYNCI (void)
  582. {
  583. __asm__ __volatile__ ("synci");
  584. }
  585. __inline__ static
  586. void
  587. sh_media_SYNCO (void)
  588. {
  589. __asm__ __volatile__ ("synco");
  590. }
  591. __inline__ static
  592. void
  593. sh_media_ALLOCO (void *mm, int s)
  594. {
  595. __builtin_sh_media_ALLOCO (mm + s);
  596. }
  597. __inline__ static
  598. void
  599. sh_media_ICBI (void *mm, int s)
  600. {
  601. __asm__ __volatile__ ("icbi %m0" : : "o" (((char*)mm)[s]));
  602. }
  603. __inline__ static
  604. void
  605. sh_media_OCBI (void *mm, int s)
  606. {
  607. __asm__ __volatile__ ("ocbi %m0" : : "o" (((char*)mm)[s]));
  608. }
  609. __inline__ static
  610. void
  611. sh_media_OCBP (void *mm, int s)
  612. {
  613. __asm__ __volatile__ ("ocbp %m0" : : "o" (((char*)mm)[s]));
  614. }
  615. __inline__ static
  616. void
  617. sh_media_OCBWB (void *mm, int s)
  618. {
  619. __asm__ __volatile__ ("ocbwb %m0" : : "o" (((char*)mm)[s]));
  620. }
  621. __inline__ static
  622. void
  623. sh_media_PREFI (void *mm, int s)
  624. {
  625. __asm__ __volatile__ ("prefi %m0" : : "o" (((char*)mm)[s]));
  626. }
  627. __inline__ static
  628. void
  629. sh_media_BRK (void)
  630. {
  631. __asm__ __volatile__ ("brk");
  632. }
  633. __inline__ static
  634. void
  635. sh_media_TRAPA (unsigned long long mm)
  636. {
  637. __asm__ __volatile__ ("trapa %%0" : : "r" (mm));
  638. }
  639. __inline__ static
  640. short
  641. sh_media_unaligned_LD_W (void *p)
  642. {
  643. #if __LITTLE_ENDIAN__
  644. return (((unsigned char *)p)[0]
  645. | (((short)((__signed__ char *)p)[1]) << 8));
  646. #else
  647. return ((((short)((__signed__ char *)p)[0]) << 8)
  648. | ((unsigned char *)p)[1]);
  649. #endif
  650. }
  651. __inline__ static
  652. unsigned short
  653. sh_media_unaligned_LD_UW (void *p)
  654. {
  655. unsigned char *addr = p;
  656. #if __LITTLE_ENDIAN__
  657. return sh_media_MSHFLO_B (addr[0], addr[1]);
  658. #else
  659. return sh_media_MSHFLO_B (addr[1], addr[0]);
  660. #endif
  661. }
  662. /* We don't use the sh_media_LD* functions here because that turned out
  663. to impede constant propagation of the offsets into the ldhi / ldlo
  664. instructions. */
  665. __inline__ static
  666. int
  667. sh_media_unaligned_LD_L (void *p)
  668. {
  669. #if __LITTLE_ENDIAN__
  670. return (__builtin_sh_media_LDHI_L ((char *)p + 3)
  671. | __builtin_sh_media_LDLO_L (p));
  672. #else
  673. return (__builtin_sh_media_LDLO_L ((char *)p + 3)
  674. | __builtin_sh_media_LDHI_L (p));
  675. #endif
  676. }
  677. __inline__ static
  678. long long
  679. sh_media_unaligned_LD_Q (void *p)
  680. {
  681. #if __LITTLE_ENDIAN__
  682. return (__builtin_sh_media_LDHI_Q ((char *)p + 7)
  683. | __builtin_sh_media_LDLO_Q (p));
  684. #else
  685. return (__builtin_sh_media_LDLO_Q ((char *)p + 7)
  686. | __builtin_sh_media_LDHI_Q (p));
  687. #endif
  688. }
  689. __inline__ static
  690. void
  691. sh_media_unaligned_ST_W (void *p, unsigned int k)
  692. {
  693. char *addr = p;
  694. #if __LITTLE_ENDIAN__
  695. addr[0] = k;
  696. addr[1] = k >> 8;
  697. #else
  698. addr[1] = k;
  699. addr[0] = k >> 8;
  700. #endif
  701. }
  702. /* We don't use the sh_media_ST* functions here because that turned out
  703. to impede constant propagation of the offsets into the ldhi / ldlo
  704. instructions. */
  705. __inline__ static
  706. void
  707. sh_media_unaligned_ST_L (void *p, unsigned int k)
  708. {
  709. #if __LITTLE_ENDIAN__
  710. __builtin_sh_media_STHI_L (p + 3, k);
  711. __builtin_sh_media_STLO_L (p, k);
  712. #else
  713. __builtin_sh_media_STLO_L (p + 3, k);
  714. __builtin_sh_media_STHI_L (p, k);
  715. #endif
  716. }
  717. __inline__ static
  718. void
  719. sh_media_unaligned_ST_Q (void *p, unsigned long long k)
  720. {
  721. #if __LITTLE_ENDIAN__
  722. __builtin_sh_media_STHI_Q (p + 7, k);
  723. __builtin_sh_media_STLO_Q (p, k);
  724. #else
  725. __builtin_sh_media_STLO_Q (p + 7, k);
  726. __builtin_sh_media_STHI_Q (p, k);
  727. #endif
  728. }
  729. #if ! __SH4_NOFPU__
  730. __inline__ static
  731. void
  732. sh_media_FVCOPY_S (const void *fvg, void *fvf)
  733. {
  734. const __GCC_FV *g = fvg;
  735. __GCC_FV *f = fvf;
  736. *f = *g;
  737. }
  738. __inline__ static
  739. void
  740. sh_media_FVADD_S (const void *fvg, const void *fvh, void *fvf)
  741. {
  742. const float *g = fvg, *h = fvh;
  743. float *f = fvf;
  744. #if 1
  745. int i;
  746. for (i = 0; i < 4; i++)
  747. f[i] = g[i] + h[i];
  748. #else
  749. f[0] = g[0] + h[0];
  750. f[1] = g[1] + h[1];
  751. f[2] = g[2] + h[2];
  752. f[3] = g[3] + h[3];
  753. #endif
  754. }
  755. __inline__ static
  756. void
  757. sh_media_FVSUB_S (const void *fvg, const void *fvh, void *fvf)
  758. {
  759. const float *g = fvg, *h = fvh;
  760. float *f = fvf;
  761. #if 1
  762. int i;
  763. for (i = 0; i < 4; i++)
  764. f[i] = g[i] - h[i];
  765. #else
  766. f[0] = g[0] - h[0];
  767. f[1] = g[1] - h[1];
  768. f[2] = g[2] - h[2];
  769. f[3] = g[3] - h[3];
  770. #endif
  771. }
  772. __inline__ static
  773. void
  774. sh_media_FMTRXCOPY_S (const void *mtrxg, void *mtrxf)
  775. {
  776. const __GCC_MTRX *g = mtrxg;
  777. __GCC_MTRX *f = mtrxf;
  778. *f = *g;
  779. }
  780. __inline__ static
  781. void
  782. sh_media_FMTRXADD_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
  783. {
  784. const __GCC_FV *g = mtrxg, *h = mtrxh;
  785. __GCC_FV *f = mtrxf;
  786. #if 1
  787. int i;
  788. for (i = 0; i < 4; i++)
  789. sh_media_FVADD_S (&g[i], &h[i], &f[i]);
  790. #else
  791. sh_media_FVADD_S (&g[0], &h[0], &f[0]);
  792. sh_media_FVADD_S (&g[1], &h[1], &f[1]);
  793. sh_media_FVADD_S (&g[2], &h[2], &f[2]);
  794. sh_media_FVADD_S (&g[3], &h[3], &f[3]);
  795. #endif
  796. }
  797. __inline__ static
  798. void
  799. sh_media_FMTRXSUB_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
  800. {
  801. const __GCC_FV *g = mtrxg, *h = mtrxh;
  802. __GCC_FV *f = mtrxf;
  803. #if 1
  804. int i;
  805. for (i = 0; i < 4; i++)
  806. sh_media_FVSUB_S (&g[i], &h[i], &f[i]);
  807. #else
  808. sh_media_FVSUB_S (&g[0], &h[0], &f[0]);
  809. sh_media_FVSUB_S (&g[1], &h[1], &f[1]);
  810. sh_media_FVSUB_S (&g[2], &h[2], &f[2]);
  811. sh_media_FVSUB_S (&g[3], &h[3], &f[3]);
  812. #endif
  813. }
  814. __inline__ static
  815. void
  816. sh_media_FTRVADD_S (const void *mtrxg, const void *fvh, const void *fvi,
  817. void *fvf)
  818. {
  819. sh_media_FTRV_S (mtrxg, fvh, fvf);
  820. sh_media_FVADD_S (fvf, fvi, fvf);
  821. }
  822. __inline__ static
  823. void
  824. sh_media_FTRVSUB_S (const void *mtrxg, const void *fvh, const void *fvi,
  825. void *fvf)
  826. {
  827. sh_media_FTRV_S (mtrxg, fvh, fvf);
  828. sh_media_FVSUB_S (fvf, fvi, fvf);
  829. }
  830. __inline__ static
  831. void
  832. sh_media_FMTRXMUL_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
  833. {
  834. const __GCC_FV *g = mtrxg;
  835. __GCC_FV *f = mtrxf;
  836. #if 1
  837. int j;
  838. for (j = 0; j < 4; j++)
  839. sh_media_FTRV_S (mtrxh, &g[j], &f[j]);
  840. #else
  841. sh_media_FTRV_S (mtrxh, &g[0], &f[0]);
  842. sh_media_FTRV_S (mtrxh, &g[1], &f[1]);
  843. sh_media_FTRV_S (mtrxh, &g[2], &f[2]);
  844. sh_media_FTRV_S (mtrxh, &g[3], &f[3]);
  845. #endif
  846. }
  847. __inline__ static
  848. void
  849. sh_media_FMTRXMULADD_S (const void *mtrxg, const void *mtrxh,
  850. const void *mtrxi, void *mtrxf)
  851. {
  852. const __GCC_FV *g = mtrxg, *i = mtrxi;
  853. __GCC_FV *f = mtrxf;
  854. #if 1
  855. int j;
  856. for (j = 0; j < 4; j++)
  857. sh_media_FTRVADD_S (mtrxh, &g[j], &i[j], &f[j]);
  858. #else
  859. sh_media_FTRVADD_S (mtrxh, &g[0], &i[0], &f[0]);
  860. sh_media_FTRVADD_S (mtrxh, &g[1], &i[1], &f[1]);
  861. sh_media_FTRVADD_S (mtrxh, &g[2], &i[2], &f[2]);
  862. sh_media_FTRVADD_S (mtrxh, &g[3], &i[3], &f[3]);
  863. #endif
  864. }
  865. __inline__ static
  866. void
  867. sh_media_FMTRXMULSUB_S (const void *mtrxg, const void *mtrxh,
  868. const void *mtrxi, void *mtrxf)
  869. {
  870. const __GCC_FV *g = mtrxg, *i = mtrxi;
  871. __GCC_FV *f = mtrxf;
  872. #if 1
  873. int j;
  874. for (j = 0; j < 4; j++)
  875. sh_media_FTRVSUB_S (mtrxh, &g[j], &i[j], &f[j]);
  876. #else
  877. sh_media_FTRVSUB_S (mtrxh, &g[0], &i[0], &f[0]);
  878. sh_media_FTRVSUB_S (mtrxh, &g[1], &i[1], &f[1]);
  879. sh_media_FTRVSUB_S (mtrxh, &g[2], &i[2], &f[2]);
  880. sh_media_FTRVSUB_S (mtrxh, &g[3], &i[3], &f[3]);
  881. #endif
  882. }
  883. #endif /* ! __SH4_NOFPU__ */
  884. #endif /* __SHMEDIA__ */
  885. #endif /* _USHMEDIA_H */