2005-05-13 Josh Conner <jconner@apple.com>
[official-gcc.git] / gcc / config / sh / ushmedia.h
blob514ddff35b576bb3805939a4f673338eef370b91
1 /* Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GCC; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 /* As a special exception, if you include this header file into source
21 files compiled by GCC, this header file does not by itself cause
22 the resulting executable to be covered by the GNU General Public
23 License. This exception does not however invalidate any other
24 reasons why the executable file might be covered by the GNU General
25 Public License. */
27 /* ushmedia.h: Intrinsics corresponding to SHmedia instructions that
28 may be executed in both user and privileged mode. */
30 #ifndef _USHMEDIA_H
31 #define _USHMEDIA_H
33 #if __SHMEDIA__
34 #if ! __SH4_NO_FPU
35 typedef float __GCC_FV __attribute__ ((vector_size (4 * sizeof (float))));
36 typedef float __GCC_MTRX __attribute__ ((vector_size (16 * sizeof (float))));
37 #endif
39 static __inline unsigned long long
40 sh_media_MABS_L (unsigned long long mm)
42 typedef float v2si __attribute__ ((mode(V2SI)));
44 return (unsigned long long) __builtin_absv2si2 ((v2si) mm);
47 static __inline unsigned long long
48 sh_media_MABS_W (unsigned long long mm)
50 typedef float v4hi __attribute__ ((mode(V4HI)));
52 return (unsigned long long) __builtin_absv4hi2 ((v4hi) mm);
55 static __inline unsigned long long
56 sh_media_MADD_L (unsigned long long mm, unsigned long long mn)
58 typedef float v2si __attribute__ ((mode(V2SI)));
60 return (unsigned long long) __builtin_addv2si3 ((v2si) mm, (v2si) mn);
63 static __inline unsigned long long
64 sh_media_MADD_W (unsigned long long mm, unsigned long long mn)
66 typedef float v4hi __attribute__ ((mode(V4HI)));
68 return (unsigned long long) __builtin_addv4hi3 ((v4hi) mm, (v4hi) mn);
71 static __inline unsigned long long
72 sh_media_MADDS_L (unsigned long long mm, unsigned long long mn)
74 typedef float v2si __attribute__ ((mode(V2SI)));
76 return (unsigned long long) __builtin_ssaddv2si3 ((v2si) mm, (v2si) mn);
79 static __inline unsigned long long
80 sh_media_MADDS_UB (unsigned long long mm, unsigned long long mn)
82 typedef float v8qi __attribute__ ((mode(V8QI)));
84 return (unsigned long long) __builtin_usaddv8qi3 ((v8qi) mm, (v8qi) mn);
87 static __inline unsigned long long
88 sh_media_MADDS_W (unsigned long long mm, unsigned long long mn)
90 typedef float v4hi __attribute__ ((mode(V4HI)));
92 return (unsigned long long) __builtin_ssaddv4hi3 ((v4hi) mm, (v4hi) mn);
95 static __inline unsigned long long
96 sh_media_MCMPEQ_B (unsigned long long mm, unsigned long long mn)
98 typedef float v8qi __attribute__ ((mode(V8QI)));
100 return (unsigned long long) __builtin_sh_media_MCMPEQ_B ((v8qi) mm,
101 (v8qi) mn);
104 static __inline unsigned long long
105 sh_media_MCMPEQ_L (unsigned long long mm, unsigned long long mn)
107 typedef float v2si __attribute__ ((mode(V2SI)));
109 return (unsigned long long) __builtin_sh_media_MCMPEQ_L ((v2si) mm,
110 (v2si) mn);
113 static __inline unsigned long long
114 sh_media_MCMPEQ_W (unsigned long long mm, unsigned long long mn)
116 typedef float v4hi __attribute__ ((mode(V4HI)));
118 return (unsigned long long) __builtin_sh_media_MCMPEQ_W ((v4hi) mm,
119 (v4hi) mn);
122 static __inline unsigned long long
123 sh_media_MCMPGT_UB (unsigned long long mm, unsigned long long mn)
125 typedef float v8qi __attribute__ ((mode(V8QI)));
127 return (unsigned long long) __builtin_sh_media_MCMPGT_UB ((v8qi) mm,
128 (v8qi) mn);
131 static __inline unsigned long long
132 sh_media_MCMPGT_L (unsigned long long mm, unsigned long long mn)
134 typedef float v2si __attribute__ ((mode(V2SI)));
136 return (unsigned long long) __builtin_sh_media_MCMPGT_L ((v2si) mm,
137 (v2si) mn);
140 static __inline unsigned long long
141 sh_media_MCMPGT_W (unsigned long long mm, unsigned long long mn)
143 typedef float v4hi __attribute__ ((mode(V4HI)));
145 return (unsigned long long) __builtin_sh_media_MCMPGT_W ((v4hi) mm,
146 (v4hi) mn);
149 #define sh_media_MCMV __builtin_sh_media_MCMV
151 static __inline unsigned long long
152 sh_media_MCNVS_LW (unsigned long long mm, unsigned long long mn)
154 typedef float v2si __attribute__ ((mode(V2SI)));
155 typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
157 return (unsigned long long) __builtin_sh_media_MCNVS_LW ((v2si) mm,
158 (uv2si) mn);
161 static __inline unsigned long long
162 sh_media_MCNVS_WB (unsigned long long mm, unsigned long long mn)
164 typedef float v4hi __attribute__ ((mode(V4HI)));
166 return (unsigned long long) __builtin_sh_media_MCNVS_WB ((v4hi) mm,
167 (v4hi) mn);
170 static __inline unsigned long long
171 sh_media_MCNVS_WUB (unsigned long long mm, unsigned long long mn)
173 typedef float v4hi __attribute__ ((mode(V4HI)));
175 return (unsigned long long) __builtin_sh_media_MCNVS_WUB ((v4hi) mm,
176 (v4hi) mn);
179 static __inline unsigned long long
180 sh_media_MEXTR1 (unsigned long long mm, unsigned long long mn)
182 typedef float v8qi __attribute__ ((mode(V8QI)));
184 return (unsigned long long) __builtin_sh_media_MEXTR1 ((v8qi) mm,
185 (v8qi) mn);
188 static __inline unsigned long long
189 sh_media_MEXTR2 (unsigned long long mm, unsigned long long mn)
191 typedef float v8qi __attribute__ ((mode(V8QI)));
193 return (unsigned long long) __builtin_sh_media_MEXTR2 ((v8qi) mm,
194 (v8qi) mn);
197 static __inline unsigned long long
198 sh_media_MEXTR3 (unsigned long long mm, unsigned long long mn)
200 typedef float v8qi __attribute__ ((mode(V8QI)));
202 return (unsigned long long) __builtin_sh_media_MEXTR3 ((v8qi) mm,
203 (v8qi) mn);
206 static __inline unsigned long long
207 sh_media_MEXTR4 (unsigned long long mm, unsigned long long mn)
209 typedef float v8qi __attribute__ ((mode(V8QI)));
211 return (unsigned long long) __builtin_sh_media_MEXTR4 ((v8qi) mm,
212 (v8qi) mn);
215 static __inline unsigned long long
216 sh_media_MEXTR5 (unsigned long long mm, unsigned long long mn)
218 typedef float v8qi __attribute__ ((mode(V8QI)));
220 return (unsigned long long) __builtin_sh_media_MEXTR5 ((v8qi) mm,
221 (v8qi) mn);
224 static __inline unsigned long long
225 sh_media_MEXTR6 (unsigned long long mm, unsigned long long mn)
227 typedef float v8qi __attribute__ ((mode(V8QI)));
229 return (unsigned long long) __builtin_sh_media_MEXTR6 ((v8qi) mm,
230 (v8qi) mn);
233 static __inline unsigned long long
234 sh_media_MEXTR7 (unsigned long long mm, unsigned long long mn)
236 typedef float v8qi __attribute__ ((mode(V8QI)));
238 return (unsigned long long) __builtin_sh_media_MEXTR7 ((v8qi) mm,
239 (v8qi) mn);
242 static __inline unsigned long long
243 sh_media_MMACFX_WL (unsigned long long mm, unsigned long long mn,
244 unsigned long long mw)
246 typedef float v2hi __attribute__ ((mode(V2HI)));
247 typedef float v2si __attribute__ ((mode(V2SI)));
248 typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
250 long mm_l = (long) mm;
251 long mn_l = (long) mn;
253 return ((unsigned long long)
254 __builtin_sh_media_MMACFX_WL ((v2hi) mm_l, (v2hi) mn_l,
255 (uv2si) mw));
258 static __inline unsigned long long
259 sh_media_MMACNFX_WL (unsigned long long mm, unsigned long long mn,
260 unsigned long long mw)
262 typedef float v2hi __attribute__ ((mode(V2HI)));
263 typedef float v2si __attribute__ ((mode(V2SI)));
264 typedef unsigned int uv2si __attribute__ ((mode(V2SI)));
266 long mm_l = (long) mm;
267 long mn_l = (long) mn;
269 return ((unsigned long long)
270 __builtin_sh_media_MMACNFX_WL ((v2hi) mm_l, (v2hi) mn_l,
271 (uv2si) mw));
274 static __inline unsigned long long
275 sh_media_MMUL_L (unsigned long long mm, unsigned long long mn)
277 typedef float v2si __attribute__ ((mode(V2SI)));
279 return (unsigned long long) __builtin_mulv2si3 ((v2si) mm, (v2si) mn);
282 static __inline unsigned long long
283 sh_media_MMUL_W (unsigned long long mm, unsigned long long mn)
285 typedef float v4hi __attribute__ ((mode(V4HI)));
287 return (unsigned long long) __builtin_mulv4hi3 ((v4hi) mm, (v4hi) mn);
290 static __inline unsigned long long
291 sh_media_MMULFX_L (unsigned long long mm, unsigned long long mn)
293 typedef float v2si __attribute__ ((mode(V2SI)));
295 return (unsigned long long) __builtin_sh_media_MMULFX_L ((v2si) mm,
296 (v2si) mn);
299 static __inline unsigned long long
300 sh_media_MMULFX_W (unsigned long long mm, unsigned long long mn)
302 typedef float v4hi __attribute__ ((mode(V4HI)));
304 return (unsigned long long) __builtin_sh_media_MMULFX_W ((v4hi) mm,
305 (v4hi) mn);
308 static __inline unsigned long long
309 sh_media_MMULFXRP_W (unsigned long long mm, unsigned long long mn)
311 typedef float v4hi __attribute__ ((mode(V4HI)));
313 return (unsigned long long) __builtin_sh_media_MMULFXRP_W ((v4hi) mm,
314 (v4hi) mn);
317 static __inline unsigned long long
318 sh_media_MMULHI_WL (unsigned long long mm, unsigned long long mn)
320 typedef float v4hi __attribute__ ((mode(V4HI)));
322 return (unsigned long long) __builtin_sh_media_MMULHI_WL ((v4hi) mm,
323 (v4hi) mn);
326 static __inline unsigned long long
327 sh_media_MMULLO_WL (unsigned long long mm, unsigned long long mn)
329 typedef float v4hi __attribute__ ((mode(V4HI)));
331 return (unsigned long long) __builtin_sh_media_MMULLO_WL ((v4hi) mm,
332 (v4hi) mn);
335 static __inline unsigned long long
336 sh_media_MMULSUM_WQ (unsigned long long mm, unsigned long long mn,
337 unsigned long long mw)
339 typedef unsigned int uv4hi __attribute__ ((mode(V4HI)));
341 return __builtin_sh_media_MMULSUM_WQ ((uv4hi) mm, (uv4hi) mn, mw);
344 static __inline unsigned long long
345 sh_media_MPERM_W (unsigned long long mm, unsigned int mn)
347 typedef float v4hi __attribute__ ((mode(V4HI)));
349 return (unsigned long long) __builtin_sh_media_MPERM_W ((v4hi) mm, mn);
352 static __inline unsigned long long
353 sh_media_MSAD_UBQ (unsigned long long mm, unsigned long long mn,
354 unsigned long long mw)
356 typedef unsigned int uv8qi __attribute__ ((mode(V8QI)));
358 return __builtin_sh_media_MSAD_UBQ ((uv8qi) mm, (uv8qi) mn, mw);
361 static __inline unsigned long long
362 sh_media_MSHALDS_L (unsigned long long mm, unsigned int mn)
364 typedef float v2si __attribute__ ((mode(V2SI)));
366 return (unsigned long long) __builtin_sh_media_MSHALDS_L ((v2si) mm, mn);
369 static __inline unsigned long long
370 sh_media_MSHALDS_W (unsigned long long mm, unsigned int mn)
372 typedef float v4hi __attribute__ ((mode(V4HI)));
374 return (unsigned long long) __builtin_sh_media_MSHALDS_W ((v4hi) mm, mn);
377 static __inline unsigned long long
378 sh_media_MSHARD_L (unsigned long long mm, unsigned int mn)
380 typedef float v2si __attribute__ ((mode(V2SI)));
382 return (unsigned long long) __builtin_ashrv2si3 ((v2si) mm, mn);
385 static __inline unsigned long long
386 sh_media_MSHARD_W (unsigned long long mm, unsigned int mn)
388 typedef float v4hi __attribute__ ((mode(V4HI)));
390 return (unsigned long long) __builtin_ashrv4hi3 ((v4hi) mm, mn);
393 #define sh_media_MSHARDS_Q __builtin_sh_media_MSHARDS_Q
395 static __inline unsigned long long
396 sh_media_MSHFHI_B (unsigned long long mm, unsigned long long mn)
398 typedef float v8qi __attribute__ ((mode(V8QI)));
400 return (unsigned long long) __builtin_sh_media_MSHFHI_B ((v8qi) mm,
401 (v8qi) mn);
404 static __inline unsigned long long
405 sh_media_MSHFHI_L (unsigned long long mm, unsigned long long mn)
407 typedef float v2si __attribute__ ((mode(V2SI)));
409 return (unsigned long long) __builtin_sh_media_MSHFHI_L ((v2si) mm,
410 (v2si) mn);
413 static __inline unsigned long long
414 sh_media_MSHFHI_W (unsigned long long mm, unsigned long long mn)
416 typedef float v4hi __attribute__ ((mode(V4HI)));
418 return (unsigned long long) __builtin_sh_media_MSHFHI_W ((v4hi) mm,
419 (v4hi) mn);
422 static __inline unsigned long long
423 sh_media_MSHFLO_B (unsigned long long mm, unsigned long long mn)
425 typedef float v8qi __attribute__ ((mode(V8QI)));
427 return (unsigned long long) __builtin_sh_media_MSHFLO_B ((v8qi) mm,
428 (v8qi) mn);
431 static __inline unsigned long long
432 sh_media_MSHFLO_L (unsigned long long mm, unsigned long long mn)
434 typedef float v2si __attribute__ ((mode(V2SI)));
436 return (unsigned long long) __builtin_sh_media_MSHFLO_L ((v2si) mm,
437 (v2si) mn);
440 static __inline unsigned long long
441 sh_media_MSHFLO_W (unsigned long long mm, unsigned long long mn)
443 typedef float v4hi __attribute__ ((mode(V4HI)));
445 return (unsigned long long) __builtin_sh_media_MSHFLO_W ((v4hi) mm,
446 (v4hi) mn);
449 static __inline unsigned long long
450 sh_media_MSHLLD_L (unsigned long long mm, unsigned int mn)
452 typedef float v2si __attribute__ ((mode(V2SI)));
454 return (unsigned long long) __builtin_ashlv2si3 ((v2si) mm, mn);
457 static __inline unsigned long long
458 sh_media_MSHLLD_W (unsigned long long mm, unsigned int mn)
460 typedef float v4hi __attribute__ ((mode(V4HI)));
462 return (unsigned long long) __builtin_ashlv4hi3 ((v4hi) mm, mn);
465 static __inline unsigned long long
466 sh_media_MSHLRD_L (unsigned long long mm, unsigned int mn)
468 typedef float v2si __attribute__ ((mode(V2SI)));
470 return (unsigned long long) __builtin_lshrv2si3 ((v2si) mm, mn);
473 static __inline unsigned long long
474 sh_media_MSHLRD_W (unsigned long long mm, unsigned int mn)
476 typedef float v4hi __attribute__ ((mode(V4HI)));
478 return (unsigned long long) __builtin_lshrv4hi3 ((v4hi) mm, mn);
481 static __inline unsigned long long
482 sh_media_MSUB_L (unsigned long long mm, unsigned long long mn)
484 typedef float v2si __attribute__ ((mode(V2SI)));
486 return (unsigned long long) __builtin_subv2si3 ((v2si) mm, (v2si) mn);
489 static __inline unsigned long long
490 sh_media_MSUB_W (unsigned long long mm, unsigned long long mn)
492 typedef float v4hi __attribute__ ((mode(V4HI)));
494 return (unsigned long long) __builtin_subv4hi3 ((v4hi) mm, (v4hi) mn);
497 static __inline unsigned long long
498 sh_media_MSUBS_L (unsigned long long mm, unsigned long long mn)
500 typedef float v2si __attribute__ ((mode(V2SI)));
502 return (unsigned long long) __builtin_sssubv2si3 ((v2si) mm, (v2si) mn);
505 static __inline unsigned long long
506 sh_media_MSUBS_UB (unsigned long long mm, unsigned long long mn)
508 typedef float v8qi __attribute__ ((mode(V8QI)));
510 return (unsigned long long) __builtin_ussubv8qi3 ((v8qi) mm, (v8qi) mn);
513 static __inline unsigned long long
514 sh_media_MSUBS_W (unsigned long long mm, unsigned long long mn)
516 typedef float v4hi __attribute__ ((mode(V4HI)));
518 return (unsigned long long) __builtin_sssubv4hi3 ((v4hi) mm, (v4hi) mn);
521 #if ! __SH4_NOFPU__
522 /* Floating-point Intrinsics */
524 #define sh_media_FABS_D __builtin_fabs
525 #define sh_media_FABS_S __builtin_fabsf
526 #define sh_media_FCMPUN_D __builtin_isunordered
527 #define sh_media_FCMPUN_S __builtin_isunordered
529 static __inline float sh_media_FCOSA_S (float fg)
531 union { int i; float f; } u;
533 u.f = fg;
534 return __builtin_sh_media_FCOSA_S (u.i);
537 static __inline float
538 sh_media_FGETSCR (void)
540 float f;
542 __asm volatile ("fgetscr %0" : "=f" (f));
543 return f;
546 static __inline float
547 sh_media_FIPR_S (const void *fvg, const void *fvh)
549 typedef float v4sf __attribute__ ((mode(V4SF)));
550 v4sf vg = *(v4sf*) fvg;
551 v4sf vh = *(v4sf*) fvh;
553 return __builtin_sh_media_FIPR_S (vg, vh);
556 #if 0
557 /* This gives different results for -O0 */
558 static __inline float
559 sh_media_FMAC_S (float fg, float fh, float fq)
561 return fg * fh + fq;
563 #else
565 #define sh_media_FMAC_S __builtin_sh_media_FMAC_S
566 #endif
568 static __inline long long
569 sh_media_FMOV_DQ (double dg)
571 union { long long l; double d; } u;
573 u.d = dg;
574 return u.l;
577 static __inline float
578 sh_media_FMOV_LS (int mm)
580 union { int i; float f; } u;
582 u.i = mm;
583 return u.f;
586 static __inline double
587 sh_media_FMOV_QD (long long mm)
589 union { long long l; double d; } u;
591 u.l = mm;
592 return u.d;
595 static __inline int
596 sh_media_FMOV_SL (float fg)
598 union { int i; float f; } u;
600 u.f = fg;
601 return u.i;
604 static __inline void
605 sh_media_FPUTSCR (float fg)
607 __asm volatile ("fputscr %0" : : "f" (fg));
610 static __inline float sh_media_FSINA_S (float fg)
612 union { int i; float f; } u;
614 u.f = fg;
615 return __builtin_sh_media_FSINA_S (u.i);
618 /* Can't use __builtin_sqrt / __builtin_sqrtf because they still implement
619 error handling unless -ffast-math is used. */
620 #define sh_media_FSQRT_D __builtin_sh_media_FSQRT_D
621 #define sh_media_FSQRT_S __builtin_sh_media_FSQRT_S
622 #define sh_media_FSRRA_S __builtin_sh_media_FSRRA_S
624 static __inline void
625 sh_media_FTRV_S (const void *mtrxg, const void *fvh, void *fvf)
627 typedef float v16sf __attribute__ ((mode(V16SF)));
628 typedef float v4sf __attribute__ ((mode(V4SF)));
629 v16sf mtrx = *(v16sf*) mtrxg;
630 v4sf vh = *(v4sf*) fvh;
632 *(v4sf*) fvf = __builtin_sh_media_FTRV_S (mtrx, vh);
634 #endif /* ! __SH4_NOFPU__ */
636 /* Not implemented here: Control and Configuration intrinsics. */
637 /* Misaligned Access Support intrinsics */
639 static __inline unsigned long long
640 sh_media_LDHI_L (void *p, int s)
642 return __builtin_sh_media_LDHI_L ((char *)p + s);
645 static __inline unsigned long long
646 sh_media_LDHI_Q (void *p, int s)
648 return __builtin_sh_media_LDHI_Q ((char *)p + s);
651 static __inline unsigned long long
652 sh_media_LDLO_L (void *p, int s)
654 return __builtin_sh_media_LDLO_L ((char *)p + s);
657 static __inline unsigned long long
658 sh_media_LDLO_Q (void *p, int s)
660 return __builtin_sh_media_LDLO_Q ((char *)p + s);
663 static __inline void
664 sh_media_STHI_L (void *p, int s, unsigned int mw)
666 __builtin_sh_media_STHI_L ((char*)p + s, mw);
669 static __inline void
670 sh_media_STHI_Q (void *p, int s, unsigned long long mw)
672 __builtin_sh_media_STHI_Q ((char*)p + s, mw);
675 static __inline void
676 sh_media_STLO_L (void *p, int s, unsigned int mw)
678 __builtin_sh_media_STLO_L ((char*)p + s, mw);
681 static __inline void
682 sh_media_STLO_Q (void *p, int s, unsigned long long mw)
684 __builtin_sh_media_STLO_Q ((char*)p + s, mw);
687 /* Miscellaneous intrinsics */
689 #define sh_media_NSB __builtin_sh_media_NSB
691 static __inline unsigned long long
692 sh_media_BYTEREV (unsigned long long mm)
694 typedef float v8qi __attribute__ ((mode(V8QI)));
696 return (unsigned long long) __builtin_sh_media_BYTEREV ((v8qi) mm);
699 __inline__ static unsigned long long
700 sh_media_CMVEQ (unsigned long long mm, unsigned long long mn, unsigned long long mw) __attribute__ ((always_inline));
702 __inline__ static unsigned long long
703 sh_media_CMVEQ (unsigned long long mm, unsigned long long mn, unsigned long long mw)
705 return mm == 0 ? mn : mw;
708 __inline__ static unsigned long long
709 sh_media_CMVNE (unsigned long long mm, unsigned long long mn, unsigned long long mw) __attribute__ ((always_inline));
711 __inline__ static unsigned long long
712 sh_media_CMVNE (unsigned long long mm, unsigned long long mn, unsigned long long mw)
714 return mm != 0 ? mn : mw;
717 static __inline long long
718 sh_media_ADDZ_L (unsigned int mm, unsigned int mn)
720 return mm + mn;
723 /* NOP and Synchronization instrinsics not implemented here. */
725 static __inline__ void sh_media_PREFO(void *mm, int s)
727 __builtin_sh_media_PREFO (mm + s, 0, 0);
730 /* Event Handling instrinsics not implemented here. */
732 /* Old asm stuff */
734 static __inline__
735 void
736 sh_media_NOP (void)
738 __asm__ ("nop" : :);
741 __inline__ static
742 unsigned long long
743 sh_media_SWAP_Q (void *mm, long long mn, unsigned long long mw)
745 unsigned long long res;
746 unsigned long long *addr = (unsigned long long *)((char *)mm + mn);
747 __asm__ ("swap.q %m1, %0" : "=r" (res), "+o" (*addr) : "0" (mw));
748 return res;
751 __inline__ static
752 void
753 sh_media_SYNCI (void)
755 __asm__ __volatile__ ("synci");
758 __inline__ static
759 void
760 sh_media_SYNCO (void)
762 __asm__ __volatile__ ("synco");
765 __inline__ static
766 void
767 sh_media_ALLOCO (void *mm, int s)
769 __builtin_sh_media_ALLOCO (mm + s);
772 __inline__ static
773 void
774 sh_media_ICBI (void *mm, int s)
776 __asm__ __volatile__ ("icbi %m0" : : "o" (((char*)mm)[s]));
779 __inline__ static
780 void
781 sh_media_OCBI (void *mm, int s)
783 __asm__ __volatile__ ("ocbi %m0" : : "o" (((char*)mm)[s]));
786 __inline__ static
787 void
788 sh_media_OCBP (void *mm, int s)
790 __asm__ __volatile__ ("ocbp %m0" : : "o" (((char*)mm)[s]));
793 __inline__ static
794 void
795 sh_media_OCBWB (void *mm, int s)
797 __asm__ __volatile__ ("ocbwb %m0" : : "o" (((char*)mm)[s]));
800 __inline__ static
801 void
802 sh_media_PREFI (void *mm, int s)
804 __asm__ __volatile__ ("prefi %m0" : : "o" (((char*)mm)[s]));
807 __inline__ static
808 void
809 sh_media_BRK (void)
811 __asm__ __volatile__ ("brk");
814 __inline__ static
815 void
816 sh_media_TRAPA (unsigned long long mm)
818 __asm__ __volatile__ ("trapa %%0" : : "r" (mm));
821 __inline__ static
822 short
823 sh_media_unaligned_LD_W (void *p)
825 #if __LITTLE_ENDIAN__
826 return (((unsigned char *)p)[0]
827 | (((short)((__signed__ char *)p)[1]) << 8));
828 #else
829 return ((((short)((__signed__ char *)p)[0]) << 8)
830 | ((unsigned char *)p)[1]);
831 #endif
834 __inline__ static
835 unsigned short
836 sh_media_unaligned_LD_UW (void *p)
838 unsigned char *addr = p;
839 #if __LITTLE_ENDIAN__
840 return sh_media_MSHFLO_B (addr[0], addr[1]);
841 #else
842 return sh_media_MSHFLO_B (addr[1], addr[0]);
843 #endif
846 /* We don't use the sh_media_LD* functions here because that turned out
847 to impede constant propagation of the offsets into the ldhi / ldlo
848 instructions. */
849 __inline__ static
850 int
851 sh_media_unaligned_LD_L (void *p)
853 #if __LITTLE_ENDIAN__
854 return (__builtin_sh_media_LDHI_L ((char *)p + 3)
855 | __builtin_sh_media_LDLO_L (p));
856 #else
857 return (__builtin_sh_media_LDLO_L ((char *)p + 3)
858 | __builtin_sh_media_LDHI_L (p));
859 #endif
862 __inline__ static
863 long long
864 sh_media_unaligned_LD_Q (void *p)
866 #if __LITTLE_ENDIAN__
867 return (__builtin_sh_media_LDHI_Q ((char *)p + 7)
868 | __builtin_sh_media_LDLO_Q (p));
869 #else
870 return (__builtin_sh_media_LDLO_Q ((char *)p + 7)
871 | __builtin_sh_media_LDHI_Q (p));
872 #endif
875 __inline__ static
876 void
877 sh_media_unaligned_ST_W (void *p, unsigned int k)
879 char *addr = p;
880 #if __LITTLE_ENDIAN__
881 addr[0] = k;
882 addr[1] = k >> 8;
883 #else
884 addr[1] = k;
885 addr[0] = k >> 8;
886 #endif
889 /* We don't use the sh_media_ST* functions here because that turned out
890 to impede constant propagation of the offsets into the ldhi / ldlo
891 instructions. */
892 __inline__ static
893 void
894 sh_media_unaligned_ST_L (void *p, unsigned int k)
896 #if __LITTLE_ENDIAN__
897 __builtin_sh_media_STHI_L (p + 3, k);
898 __builtin_sh_media_STLO_L (p, k);
899 #else
900 __builtin_sh_media_STLO_L (p + 3, k);
901 __builtin_sh_media_STHI_L (p, k);
902 #endif
905 __inline__ static
906 void
907 sh_media_unaligned_ST_Q (void *p, unsigned long long k)
909 #if __LITTLE_ENDIAN__
910 __builtin_sh_media_STHI_Q (p + 7, k);
911 __builtin_sh_media_STLO_Q (p, k);
912 #else
913 __builtin_sh_media_STLO_Q (p + 7, k);
914 __builtin_sh_media_STHI_Q (p, k);
915 #endif
918 #if ! __SH4_NOFPU__
919 __inline__ static
920 void
921 sh_media_FVCOPY_S (const void *fvg, void *fvf)
923 const __GCC_FV *g = fvg;
924 __GCC_FV *f = fvf;
925 *f = *g;
928 __inline__ static
929 void
930 sh_media_FVADD_S (const void *fvg, const void *fvh, void *fvf)
932 const float *g = fvg, *h = fvh;
933 float *f = fvf;
934 #if 1
935 int i;
937 for (i = 0; i < 4; i++)
938 f[i] = g[i] + h[i];
939 #else
940 f[0] = g[0] + h[0];
941 f[1] = g[1] + h[1];
942 f[2] = g[2] + h[2];
943 f[3] = g[3] + h[3];
944 #endif
947 __inline__ static
948 void
949 sh_media_FVSUB_S (const void *fvg, const void *fvh, void *fvf)
951 const float *g = fvg, *h = fvh;
952 float *f = fvf;
953 #if 1
954 int i;
956 for (i = 0; i < 4; i++)
957 f[i] = g[i] - h[i];
958 #else
959 f[0] = g[0] - h[0];
960 f[1] = g[1] - h[1];
961 f[2] = g[2] - h[2];
962 f[3] = g[3] - h[3];
963 #endif
966 __inline__ static
967 void
968 sh_media_FMTRXCOPY_S (const void *mtrxg, void *mtrxf)
970 const __GCC_MTRX *g = mtrxg;
971 __GCC_MTRX *f = mtrxf;
972 *f = *g;
975 __inline__ static
976 void
977 sh_media_FMTRXADD_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
979 const __GCC_FV *g = mtrxg, *h = mtrxh;
980 __GCC_FV *f = mtrxf;
981 #if 1
982 int i;
984 for (i = 0; i < 4; i++)
985 sh_media_FVADD_S (&g[i], &h[i], &f[i]);
986 #else
987 sh_media_FVADD_S (&g[0], &h[0], &f[0]);
988 sh_media_FVADD_S (&g[1], &h[1], &f[1]);
989 sh_media_FVADD_S (&g[2], &h[2], &f[2]);
990 sh_media_FVADD_S (&g[3], &h[3], &f[3]);
991 #endif
994 __inline__ static
995 void
996 sh_media_FMTRXSUB_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
998 const __GCC_FV *g = mtrxg, *h = mtrxh;
999 __GCC_FV *f = mtrxf;
1000 #if 1
1001 int i;
1003 for (i = 0; i < 4; i++)
1004 sh_media_FVSUB_S (&g[i], &h[i], &f[i]);
1005 #else
1006 sh_media_FVSUB_S (&g[0], &h[0], &f[0]);
1007 sh_media_FVSUB_S (&g[1], &h[1], &f[1]);
1008 sh_media_FVSUB_S (&g[2], &h[2], &f[2]);
1009 sh_media_FVSUB_S (&g[3], &h[3], &f[3]);
1010 #endif
1013 __inline__ static
1014 void
1015 sh_media_FTRVADD_S (const void *mtrxg, const void *fvh, const void *fvi, void *fvf)
1017 sh_media_FTRV_S (mtrxg, fvh, fvf);
1018 sh_media_FVADD_S (fvf, fvi, fvf);
1021 __inline__ static
1022 void
1023 sh_media_FTRVSUB_S (const void *mtrxg, const void *fvh, const void *fvi, void *fvf)
1025 sh_media_FTRV_S (mtrxg, fvh, fvf);
1026 sh_media_FVSUB_S (fvf, fvi, fvf);
1029 __inline__ static
1030 void
1031 sh_media_FMTRXMUL_S (const void *mtrxg, const void *mtrxh, void *mtrxf)
1033 const __GCC_FV *g = mtrxg;
1034 __GCC_FV *f = mtrxf;
1035 #if 1
1036 int j;
1038 for (j = 0; j < 4; j++)
1039 sh_media_FTRV_S (mtrxh, &g[j], &f[j]);
1040 #else
1041 sh_media_FTRV_S (mtrxh, &g[0], &f[0]);
1042 sh_media_FTRV_S (mtrxh, &g[1], &f[1]);
1043 sh_media_FTRV_S (mtrxh, &g[2], &f[2]);
1044 sh_media_FTRV_S (mtrxh, &g[3], &f[3]);
1045 #endif
1048 __inline__ static
1049 void
1050 sh_media_FMTRXMULADD_S (const void *mtrxg, const void *mtrxh, const void *mtrxi, void *mtrxf)
1052 const __GCC_FV *g = mtrxg, *i = mtrxi;
1053 __GCC_FV *f = mtrxf;
1054 #if 1
1055 int j;
1057 for (j = 0; j < 4; j++)
1058 sh_media_FTRVADD_S (mtrxh, &g[j], &i[j], &f[j]);
1059 #else
1060 sh_media_FTRVADD_S (mtrxh, &g[0], &i[0], &f[0]);
1061 sh_media_FTRVADD_S (mtrxh, &g[1], &i[1], &f[1]);
1062 sh_media_FTRVADD_S (mtrxh, &g[2], &i[2], &f[2]);
1063 sh_media_FTRVADD_S (mtrxh, &g[3], &i[3], &f[3]);
1064 #endif
1067 __inline__ static
1068 void
1069 sh_media_FMTRXMULSUB_S (const void *mtrxg, const void *mtrxh, const void *mtrxi, void *mtrxf)
1071 const __GCC_FV *g = mtrxg, *i = mtrxi;
1072 __GCC_FV *f = mtrxf;
1073 #if 1
1074 int j;
1076 for (j = 0; j < 4; j++)
1077 sh_media_FTRVSUB_S (mtrxh, &g[j], &i[j], &f[j]);
1078 #else
1079 sh_media_FTRVSUB_S (mtrxh, &g[0], &i[0], &f[0]);
1080 sh_media_FTRVSUB_S (mtrxh, &g[1], &i[1], &f[1]);
1081 sh_media_FTRVSUB_S (mtrxh, &g[2], &i[2], &f[2]);
1082 sh_media_FTRVSUB_S (mtrxh, &g[3], &i[3], &f[3]);
1083 #endif
1085 #endif /* ! __SH4_NOFPU__ */
1087 #endif /* __SHMEDIA__ */
1089 #endif /* _USHMEDIA_H */