OSDN Git Service

2011-11-04 Quentin Neill <quentin.neill@amd.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / f16cintrin.h
1 /* Copyright (C) 2011
2    Free Software Foundation, Inc.
3
4    This file is part of GCC.
5
6    GCC is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10
11    GCC is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    Under Section 7 of GPL version 3, you are granted additional
17    permissions described in the GCC Runtime Library Exception, version
18    3.1, as published by the Free Software Foundation.
19
20    You should have received a copy of the GNU General Public License and
21    a copy of the GCC Runtime Library Exception along with this program;
22    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23    <http://www.gnu.org/licenses/>.  */
24
25 #ifndef _X86INTRIN_H_INCLUDED
26 #if (!defined(_X86INTRIN_H_INCLUDED) && !defined(_IMMINTRIN_H_INCLUDED))
27 # error "Never use <f16intrin.h> directly; include <x86intrin.h> or <immintrin.h> instead."
28 #endif
29
30 #ifndef __F16C__
31 # error "F16C instruction set not enabled"
32 #else
33
34 #ifndef _F16CINTRIN_H_INCLUDED
35 #define _F16CINTRIN_H_INCLUDED
36
37 extern __inline float __attribute__((__gnu_inline__, __always_inline__, __artificial__))
38 _cvtsh_ss (unsigned short __S)
39 {
40   __v8hi __H = __extension__ (__v8hi){ __S, 0, 0, 0, 0, 0, 0, 0 };
41   __v4sf __A = __builtin_ia32_vcvtph2ps (__H);
42   return __builtin_ia32_vec_ext_v4sf (__A, 0);
43 }
44
45 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
46 _mm_cvtph_ps (__m128i __A)
47 {
48   return (__m128) __builtin_ia32_vcvtph2ps ((__v8hi) __A);
49 }
50
51 extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
52 _mm256_cvtph_ps (__m128i __A)
53 {
54   return (__m256) __builtin_ia32_vcvtph2ps256 ((__v8hi) __A);
55 }
56
57 #ifdef __OPTIMIZE__
58 extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
59 _cvtss_sh (float __F, const int __I)
60 {
61   __v4sf __A =  __extension__ (__v4sf){ __F, 0, 0, 0 };
62   __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);
63   return (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);
64 }
65
66 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
67 _mm_cvtps_ph (__m128 __A, const int __I)
68 {
69   return (__m128i) __builtin_ia32_vcvtps2ph ((__v4sf) __A, __I);
70 }
71
72 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
73 _mm256_cvtps_ph (__m256 __A, const int __I)
74 {
75   return (__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf) __A, __I);
76 }
77 #else
78 #define _cvtss_sh(__F, __I)                                             \
79   (__extension__                                                        \
80    ({                                                                   \
81       __v4sf __A =  __extension__ (__v4sf){ __F, 0, 0, 0 };             \
82       __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);                 \
83       (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);            \
84     }))
85
86 #define _mm_cvtps_ph(A, I) \
87   ((__m128i) __builtin_ia32_vcvtps2ph ((__v4sf)(__m128) A, (int) (I)))
88
89 #define _mm256_cvtps_ph(A, I) \
90   ((__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf)(__m256) A, (int) (I)))
91 #endif
92
93 #endif /* __F16C__ */
94 #endif