Import gcc-4.4.1
[dragonfly.git] / contrib / gcc-4.4 / gcc / config / i386 / mmintrin-common.h
1 /* Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
2
3    This file is part of GCC.
4
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 3, or (at your option)
8    any later version.
9
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.
14
15    Under Section 7 of GPL version 3, you are granted additional
16    permissions described in the GCC Runtime Library Exception, version
17    3.1, as published by the Free Software Foundation.
18
19    You should have received a copy of the GNU General Public License and
20    a copy of the GCC Runtime Library Exception along with this program;
21    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22    <http://www.gnu.org/licenses/>.  */
23
24 /* Common definition of the ROUND and PTEST intrinsics that are shared
25    between SSE4.1 and SSE5.  */
26
27 #ifndef _MMINTRIN_COMMON_H_INCLUDED
28 #define _MMINTRIN_COMMON_H_INCLUDED
29
30 #if !defined(__SSE5__) && !defined(__SSE4_1__)
31 # error "SSE5 or SSE4.1 instruction set not enabled"
32 #else
33
34 /* Rounding mode macros. */
35 #define _MM_FROUND_TO_NEAREST_INT       0x00
36 #define _MM_FROUND_TO_NEG_INF           0x01
37 #define _MM_FROUND_TO_POS_INF           0x02
38 #define _MM_FROUND_TO_ZERO              0x03
39 #define _MM_FROUND_CUR_DIRECTION        0x04
40
41 #define _MM_FROUND_RAISE_EXC            0x00
42 #define _MM_FROUND_NO_EXC               0x08
43
44 #define _MM_FROUND_NINT         \
45   (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC)
46 #define _MM_FROUND_FLOOR        \
47   (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC)
48 #define _MM_FROUND_CEIL         \
49   (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC)
50 #define _MM_FROUND_TRUNC        \
51   (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC)
52 #define _MM_FROUND_RINT         \
53   (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC)
54 #define _MM_FROUND_NEARBYINT    \
55   (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC)
56
57 /* Test Instruction */
58 /* Packed integer 128-bit bitwise comparison. Return 1 if
59    (__V & __M) == 0.  */
60 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
61 _mm_testz_si128 (__m128i __M, __m128i __V)
62 {
63   return __builtin_ia32_ptestz128 ((__v2di)__M, (__v2di)__V);
64 }
65
66 /* Packed integer 128-bit bitwise comparison. Return 1 if
67    (__V & ~__M) == 0.  */
68 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
69 _mm_testc_si128 (__m128i __M, __m128i __V)
70 {
71   return __builtin_ia32_ptestc128 ((__v2di)__M, (__v2di)__V);
72 }
73
74 /* Packed integer 128-bit bitwise comparison. Return 1 if
75    (__V & __M) != 0 && (__V & ~__M) != 0.  */
76 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
77 _mm_testnzc_si128 (__m128i __M, __m128i __V)
78 {
79   return __builtin_ia32_ptestnzc128 ((__v2di)__M, (__v2di)__V);
80 }
81
82 /* Macros for packed integer 128-bit comparison intrinsics.  */
83 #define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V))
84
85 #define _mm_test_all_ones(V) \
86   _mm_testc_si128 ((V), _mm_cmpeq_epi32 ((V), (V)))
87
88 #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128 ((M), (V))
89
90 /* Packed/scalar double precision floating point rounding.  */
91
92 #ifdef __OPTIMIZE__
93 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
94 _mm_round_pd (__m128d __V, const int __M)
95 {
96   return (__m128d) __builtin_ia32_roundpd ((__v2df)__V, __M);
97 }
98
99 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
100 _mm_round_sd(__m128d __D, __m128d __V, const int __M)
101 {
102   return (__m128d) __builtin_ia32_roundsd ((__v2df)__D,
103                                            (__v2df)__V,
104                                            __M);
105 }
106 #else
107 #define _mm_round_pd(V, M) \
108   ((__m128d) __builtin_ia32_roundpd ((__v2df)(__m128d)(V), (int)(M)))
109
110 #define _mm_round_sd(D, V, M)                                           \
111   ((__m128d) __builtin_ia32_roundsd ((__v2df)(__m128d)(D),              \
112                                      (__v2df)(__m128d)(V), (int)(M)))
113 #endif
114
115 /* Packed/scalar single precision floating point rounding.  */
116
117 #ifdef __OPTIMIZE__
118 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
119 _mm_round_ps (__m128 __V, const int __M)
120 {
121   return (__m128) __builtin_ia32_roundps ((__v4sf)__V, __M);
122 }
123
124 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
125 _mm_round_ss (__m128 __D, __m128 __V, const int __M)
126 {
127   return (__m128) __builtin_ia32_roundss ((__v4sf)__D,
128                                           (__v4sf)__V,
129                                           __M);
130 }
131 #else
132 #define _mm_round_ps(V, M) \
133   ((__m128) __builtin_ia32_roundps ((__v4sf)(__m128)(V), (int)(M)))
134
135 #define _mm_round_ss(D, V, M)                                           \
136   ((__m128) __builtin_ia32_roundss ((__v4sf)(__m128)(D),                \
137                                     (__v4sf)(__m128)(V), (int)(M)))
138 #endif
139
140 /* Macros for ceil/floor intrinsics.  */
141 #define _mm_ceil_pd(V)     _mm_round_pd ((V), _MM_FROUND_CEIL)
142 #define _mm_ceil_sd(D, V)  _mm_round_sd ((D), (V), _MM_FROUND_CEIL)
143
144 #define _mm_floor_pd(V)    _mm_round_pd((V), _MM_FROUND_FLOOR)
145 #define _mm_floor_sd(D, V) _mm_round_sd ((D), (V), _MM_FROUND_FLOOR)
146
147 #define _mm_ceil_ps(V)     _mm_round_ps ((V), _MM_FROUND_CEIL)
148 #define _mm_ceil_ss(D, V)  _mm_round_ss ((D), (V), _MM_FROUND_CEIL)
149
150 #define _mm_floor_ps(V)    _mm_round_ps ((V), _MM_FROUND_FLOOR)
151 #define _mm_floor_ss(D, V) _mm_round_ss ((D), (V), _MM_FROUND_FLOOR)
152
153 #endif /* __SSE5__/__SSE4_1__ */
154
155 #endif /* _MMINTRIN_COMMON_H_INCLUDED */