OSDN Git Service

* tree.h (block_nonartificial_location): New prototype.
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / mmintrin-common.h
1 /* Copyright (C) 2007 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 2, 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    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, 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.  */
19
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.  */
26
27 /* Common definition of the ROUND and PTEST intrinsics that are shared
28    between SSE4.1 and SSE5.  */
29
30 #ifndef _MMINTRIN_COMMON_H_INCLUDED
31 #define _MMINTRIN_COMMON_H_INCLUDED
32
33 #if !defined(__SSE5__) && !defined(__SSE4_1__)
34 # error "SSE5 or SSE4.1 instruction set not enabled"
35 #else
36
37 /* Rounding mode macros. */
38 #define _MM_FROUND_TO_NEAREST_INT       0x00
39 #define _MM_FROUND_TO_NEG_INF           0x01
40 #define _MM_FROUND_TO_POS_INF           0x02
41 #define _MM_FROUND_TO_ZERO              0x03
42 #define _MM_FROUND_CUR_DIRECTION        0x04
43
44 #define _MM_FROUND_RAISE_EXC            0x00
45 #define _MM_FROUND_NO_EXC               0x08
46
47 #define _MM_FROUND_NINT         \
48   (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC)
49 #define _MM_FROUND_FLOOR        \
50   (_MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC)
51 #define _MM_FROUND_CEIL         \
52   (_MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC)
53 #define _MM_FROUND_TRUNC        \
54   (_MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC)
55 #define _MM_FROUND_RINT         \
56   (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC)
57 #define _MM_FROUND_NEARBYINT    \
58   (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC)
59
60 /* Test Instruction */
61 /* Packed integer 128-bit bitwise comparison. Return 1 if
62    (__V & __M) == 0.  */
63 static __inline int __attribute__((__always_inline__, __artificial__))
64 _mm_testz_si128 (__m128i __M, __m128i __V)
65 {
66   return __builtin_ia32_ptestz128 ((__v2di)__M, (__v2di)__V);
67 }
68
69 /* Packed integer 128-bit bitwise comparison. Return 1 if
70    (__V & ~__M) == 0.  */
71 static __inline int __attribute__((__always_inline__, __artificial__))
72 _mm_testc_si128 (__m128i __M, __m128i __V)
73 {
74   return __builtin_ia32_ptestc128 ((__v2di)__M, (__v2di)__V);
75 }
76
77 /* Packed integer 128-bit bitwise comparison. Return 1 if
78    (__V & __M) != 0 && (__V & ~__M) != 0.  */
79 static __inline int __attribute__((__always_inline__, __artificial__))
80 _mm_testnzc_si128 (__m128i __M, __m128i __V)
81 {
82   return __builtin_ia32_ptestnzc128 ((__v2di)__M, (__v2di)__V);
83 }
84
85 /* Macros for packed integer 128-bit comparison intrinsics.  */
86 #define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V))
87
88 #define _mm_test_all_ones(V) \
89   _mm_testc_si128 ((V), _mm_cmpeq_epi32 ((V), (V)))
90
91 #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128 ((M), (V))
92
93 /* Packed/scalar double precision floating point rounding.  */
94
95 #ifdef __OPTIMIZE__
96 static __inline __m128d __attribute__((__always_inline__, __artificial__))
97 _mm_round_pd (__m128d __V, const int __M)
98 {
99   return (__m128d) __builtin_ia32_roundpd ((__v2df)__V, __M);
100 }
101
102 static __inline __m128d __attribute__((__always_inline__, __artificial__))
103 _mm_round_sd(__m128d __D, __m128d __V, const int __M)
104 {
105   return (__m128d) __builtin_ia32_roundsd ((__v2df)__D,
106                                            (__v2df)__V,
107                                            __M);
108 }
109 #else
110 #define _mm_round_pd(V, M) \
111   ((__m128d) __builtin_ia32_roundpd ((__v2df)(V), (M)))
112
113 #define _mm_round_sd(D, V, M) \
114   ((__m128d) __builtin_ia32_roundsd ((__v2df)(D), (__v2df)(V), (M)))
115 #endif
116
117 /* Packed/scalar single precision floating point rounding.  */
118
119 #ifdef __OPTIMIZE__
120 static __inline __m128 __attribute__((__always_inline__, __artificial__))
121 _mm_round_ps (__m128 __V, const int __M)
122 {
123   return (__m128) __builtin_ia32_roundps ((__v4sf)__V, __M);
124 }
125
126 static __inline __m128 __attribute__((__always_inline__, __artificial__))
127 _mm_round_ss (__m128 __D, __m128 __V, const int __M)
128 {
129   return (__m128) __builtin_ia32_roundss ((__v4sf)__D,
130                                           (__v4sf)__V,
131                                           __M);
132 }
133 #else
134 #define _mm_round_ps(V, M) \
135   ((__m128) __builtin_ia32_roundps ((__v4sf)(V), (M)))
136
137 #define _mm_round_ss(D, V, M) \
138   ((__m128) __builtin_ia32_roundss ((__v4sf)(D), (__v4sf)(V), (M)))
139 #endif
140
141 /* Macros for ceil/floor intrinsics.  */
142 #define _mm_ceil_pd(V)     _mm_round_pd ((V), _MM_FROUND_CEIL)
143 #define _mm_ceil_sd(D, V)  _mm_round_sd ((D), (V), _MM_FROUND_CEIL)
144
145 #define _mm_floor_pd(V)    _mm_round_pd((V), _MM_FROUND_FLOOR)
146 #define _mm_floor_sd(D, V) _mm_round_sd ((D), (V), _MM_FROUND_FLOOR)
147
148 #define _mm_ceil_ps(V)     _mm_round_ps ((V), _MM_FROUND_CEIL)
149 #define _mm_ceil_ss(D, V)  _mm_round_ss ((D), (V), _MM_FROUND_CEIL)
150
151 #define _mm_floor_ps(V)    _mm_round_ps ((V), _MM_FROUND_FLOOR)
152 #define _mm_floor_ss(D, V) _mm_round_ss ((D), (V), _MM_FROUND_FLOOR)
153
154 #endif /* __SSE5__/__SSE4_1__ */
155
156 #endif /* _MMINTRIN_COMMON_H_INCLUDED */