1 /* Copyright (C) 2007, 2008, 2009 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 3, or (at your option)
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 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.
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/>. */
24 /* Common definition of the ROUND and PTEST intrinsics that are shared
25 between SSE4.1 and SSE5. */
27 #ifndef _MMINTRIN_COMMON_H_INCLUDED
28 #define _MMINTRIN_COMMON_H_INCLUDED
30 #if !defined(__SSE5__) && !defined(__SSE4_1__)
31 # error "SSE5 or SSE4.1 instruction set not enabled"
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
41 #define _MM_FROUND_RAISE_EXC 0x00
42 #define _MM_FROUND_NO_EXC 0x08
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)
57 /* Test Instruction */
58 /* Packed integer 128-bit bitwise comparison. Return 1 if
60 extern __inline
int __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
61 _mm_testz_si128 (__m128i __M
, __m128i __V
)
63 return __builtin_ia32_ptestz128 ((__v2di
)__M
, (__v2di
)__V
);
66 /* Packed integer 128-bit bitwise comparison. Return 1 if
68 extern __inline
int __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
69 _mm_testc_si128 (__m128i __M
, __m128i __V
)
71 return __builtin_ia32_ptestc128 ((__v2di
)__M
, (__v2di
)__V
);
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
)
79 return __builtin_ia32_ptestnzc128 ((__v2di
)__M
, (__v2di
)__V
);
82 /* Macros for packed integer 128-bit comparison intrinsics. */
83 #define _mm_test_all_zeros(M, V) _mm_testz_si128 ((M), (V))
85 #define _mm_test_all_ones(V) \
86 _mm_testc_si128 ((V), _mm_cmpeq_epi32 ((V), (V)))
88 #define _mm_test_mix_ones_zeros(M, V) _mm_testnzc_si128 ((M), (V))
90 /* Packed/scalar double precision floating point rounding. */
93 extern __inline __m128d
__attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
94 _mm_round_pd (__m128d __V
, const int __M
)
96 return (__m128d
) __builtin_ia32_roundpd ((__v2df
)__V
, __M
);
99 extern __inline __m128d
__attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
100 _mm_round_sd(__m128d __D
, __m128d __V
, const int __M
)
102 return (__m128d
) __builtin_ia32_roundsd ((__v2df
)__D
,
107 #define _mm_round_pd(V, M) \
108 ((__m128d) __builtin_ia32_roundpd ((__v2df)(__m128d)(V), (int)(M)))
110 #define _mm_round_sd(D, V, M) \
111 ((__m128d) __builtin_ia32_roundsd ((__v2df)(__m128d)(D), \
112 (__v2df)(__m128d)(V), (int)(M)))
115 /* Packed/scalar single precision floating point rounding. */
118 extern __inline __m128
__attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
119 _mm_round_ps (__m128 __V
, const int __M
)
121 return (__m128
) __builtin_ia32_roundps ((__v4sf
)__V
, __M
);
124 extern __inline __m128
__attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
125 _mm_round_ss (__m128 __D
, __m128 __V
, const int __M
)
127 return (__m128
) __builtin_ia32_roundss ((__v4sf
)__D
,
132 #define _mm_round_ps(V, M) \
133 ((__m128) __builtin_ia32_roundps ((__v4sf)(__m128)(V), (int)(M)))
135 #define _mm_round_ss(D, V, M) \
136 ((__m128) __builtin_ia32_roundss ((__v4sf)(__m128)(D), \
137 (__v4sf)(__m128)(V), (int)(M)))
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)
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)
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)
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)
153 #endif /* __SSE5__/__SSE4_1__ */
155 #endif /* _MMINTRIN_COMMON_H_INCLUDED */