summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-10-02 18:31:10 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-10-02 20:54:50 +0900
commitff3d2a68d5762ec6bed88f97f2a3751bb51caf86 (patch)
treeec78ec4f24e04fe5e782ede482ee78159edef80f /src/lib
parent04b28686afbffce1305d00eec27752889b8cc9b2 (diff)
eina: add infrastructure to handle more CPU and compiler builtin information.
Diffstat (limited to '')
-rw-r--r--src/lib/eina/eina_config.h.in15
-rw-r--r--src/lib/eina/eina_cpu.c37
-rw-r--r--src/lib/eina/eina_cpu.h11
-rw-r--r--src/lib/eina/eina_inline_cpu.x70
-rw-r--r--src/lib/eina/eina_main.c4
5 files changed, 131 insertions, 6 deletions
diff --git a/src/lib/eina/eina_config.h.in b/src/lib/eina/eina_config.h.in
index abcf2f98fc..eb0869cf40 100644
--- a/src/lib/eina/eina_config.h.in
+++ b/src/lib/eina/eina_config.h.in
@@ -72,4 +72,19 @@
72#endif 72#endif
73@EINA_CONFIGURE_HAVE_ALLOCA_H@ 73@EINA_CONFIGURE_HAVE_ALLOCA_H@
74 74
75#ifdef EINA_HAVE_BSWAP16
76# undef EINA_HAVE_BSWAP16
77#endif
78@EINA_CONFIGURE_HAVE_BSWAP16@
79
80#ifdef EINA_HAVE_BSWAP32
81# undef EINA_HAVE_BSWAP32
82#endif
83@EINA_CONFIGURE_HAVE_BSWAP32@
84
85#ifdef EINA_HAVE_BSWAP64
86# undef EINA_HAVE_BSWAP64
87#endif
88@EINA_CONFIGURE_HAVE_BSWAP64@
89
75#endif /* EINA_CONFIG_H_ */ 90#endif /* EINA_CONFIG_H_ */
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index eb710027df..670b21c5d0 100644
--- a/src/lib/eina/eina_cpu.c
+++ b/src/lib/eina/eina_cpu.c
@@ -92,6 +92,9 @@ void _x86_simd(Eina_Cpu_Features *features)
92 * 28 = HTT (Hyper Threading) 92 * 28 = HTT (Hyper Threading)
93 * ecx 93 * ecx
94 * 0 = SSE3 94 * 0 = SSE3
95 * 9 = SSSE3
96 * 19 = SSE4.1
97 * 20 = SSE4.2
95 */ 98 */
96 if ((d >> 23) & 1) 99 if ((d >> 23) & 1)
97 *features |= EINA_CPU_MMX; 100 *features |= EINA_CPU_MMX;
@@ -104,6 +107,15 @@ void _x86_simd(Eina_Cpu_Features *features)
104 107
105 if (c & 1) 108 if (c & 1)
106 *features |= EINA_CPU_SSE3; 109 *features |= EINA_CPU_SSE3;
110
111 if ((c >> 9) & 1)
112 *features |= EINA_CPU_SSSE3;
113
114 if ((c >> 19) & 1)
115 *features |= EINA_CPU_SSE41;
116
117 if ((c >> 20) & 1)
118 *features |= EINA_CPU_SSE42;
107} 119}
108#endif 120#endif
109 121
@@ -118,17 +130,32 @@ void _x86_simd(Eina_Cpu_Features *features)
118/* FIXME the features checks should be called when this function is called? 130/* FIXME the features checks should be called when this function is called?
119 * or make it static by doing eina_cpu_init() and return a local var 131 * or make it static by doing eina_cpu_init() and return a local var
120 */ 132 */
133EAPI Eina_Cpu_Features eina_cpu_features = 0;
134
135Eina_Bool
136eina_cpu_init(void)
137{
138#if defined(__i386__) || defined(__x86_64__)
139 _x86_simd(&eina_cpu_features);
140#endif
141 // FIXME: Handle NEON and friends
142
143 return EINA_TRUE;
144}
145
146Eina_Bool
147eina_cpu_shutdown(void)
148{
149 return EINA_TRUE;
150}
151
121/** 152/**
122 * 153 *
123 * @return 154 * @return
124 */ 155 */
125EAPI Eina_Cpu_Features eina_cpu_features_get(void) 156EAPI Eina_Cpu_Features eina_cpu_features_get(void)
126{ 157{
127 Eina_Cpu_Features ecf = 0; 158 return eina_cpu_features;
128#if defined(__i386__) || defined(__x86_64__)
129 _x86_simd(&ecf);
130#endif
131 return ecf;
132} 159}
133 160
134static int _cpu_count = -1; 161static int _cpu_count = -1;
diff --git a/src/lib/eina/eina_cpu.h b/src/lib/eina/eina_cpu.h
index ac32e1db9b..651d925653 100644
--- a/src/lib/eina/eina_cpu.h
+++ b/src/lib/eina/eina_cpu.h
@@ -31,9 +31,20 @@ typedef enum _Eina_Cpu_Features
31 EINA_CPU_ALTIVEC = 0x00000010, 31 EINA_CPU_ALTIVEC = 0x00000010,
32 EINA_CPU_VIS = 0x00000020, 32 EINA_CPU_VIS = 0x00000020,
33 EINA_CPU_NEON = 0x00000040, 33 EINA_CPU_NEON = 0x00000040,
34 EINA_CPU_SSSE3 = 0x00000080,
35 EINA_CPU_SSE41 = 0x00000100,
36 EINA_CPU_SSE42 = 0x00000200
34} Eina_Cpu_Features; 37} Eina_Cpu_Features;
35 38
39EAPI extern Eina_Cpu_Features eina_cpu_features;
40
36EAPI Eina_Cpu_Features eina_cpu_features_get(void); 41EAPI Eina_Cpu_Features eina_cpu_features_get(void);
37EAPI int eina_cpu_count(void); 42EAPI int eina_cpu_count(void);
38 43
44static inline unsigned short eina_swap16(unsigned short x);
45static inline unsigned int eina_swap32(unsigned int x);
46static inline unsigned long long eina_swap64(unsigned long long x);
47
48#include "eina_inline_cpu.x"
49
39#endif /* EINA_CPU_H_ */ 50#endif /* EINA_CPU_H_ */
diff --git a/src/lib/eina/eina_inline_cpu.x b/src/lib/eina/eina_inline_cpu.x
new file mode 100644
index 0000000000..bdfb4a4b13
--- /dev/null
+++ b/src/lib/eina/eina_inline_cpu.x
@@ -0,0 +1,70 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2013 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18/*
19 * This code has been partially inspired by :
20 * - http://create.stephan-brumme.com/crc32/
21 */
22
23#ifndef EINA_INLINE_CPU_X_
24#define EINA_INLINE_CPU_X_
25
26static inline unsigned short
27eina_swap16(unsigned short x)
28{
29#ifdef EINA_HAVE_BSWAP16
30 return __builtin_bswap16(x);
31#else
32 return (((x & 0xff00) >> 8) |
33 ((x & 0x00ff) << 8));
34#endif
35}
36
37static inline unsigned int
38eina_swap32(unsigned int x)
39{
40#ifdef EINA_HAVE_BSWAP32
41 return __builtin_bswap32(x);
42#else
43 return (x >> 24) |
44 ((x >> 8) & 0x0000FF00) |
45 ((x << 8) & 0x00FF0000) |
46 (x << 24);
47#endif
48}
49
50static inline unsigned long long
51eina_swap64(unsigned long long x)
52{
53#ifdef EINA_HAVE_BSWAP64
54 return __builtin_bswap64(x);
55#else
56 return (((x & 0xff00000000000000ull) >> 56) |
57 ((x & 0x00ff000000000000ull) >> 40) |
58 ((x & 0x0000ff0000000000ull) >> 24) |
59 ((x & 0x000000ff00000000ull) >> 8) |
60 ((x & 0x00000000ff000000ull) << 8) |
61 ((x & 0x0000000000ff0000ull) << 24) |
62 ((x & 0x000000000000ff00ull) << 40) |
63 ((x & 0x00000000000000ffull) << 56)));
64#endif
65}
66
67
68
69#endif
70
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c
index fa6ece893c..321946000e 100644
--- a/src/lib/eina/eina_main.c
+++ b/src/lib/eina/eina_main.c
@@ -159,6 +159,7 @@ EAPI Eina_Inlist *_eina_tracking = NULL;
159 S(tmpstr); 159 S(tmpstr);
160 S(thread); 160 S(thread);
161 S(cow); 161 S(cow);
162 S(cpu);
162/* no model for now 163/* no model for now
163 S(model); 164 S(model);
164 */ 165 */
@@ -201,7 +202,8 @@ static const struct eina_desc_setup _eina_desc_setup[] = {
201 S(value), 202 S(value),
202 S(tmpstr), 203 S(tmpstr),
203 S(thread), 204 S(thread),
204 S(cow) 205 S(cow),
206 S(cpu)
205/* no model for now 207/* no model for now
206 S(model) 208 S(model)
207 */ 209 */