summaryrefslogtreecommitdiff
path: root/src/lib/ector/software/ector_software_gradient_sse3.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-11-15 12:25:15 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2018-11-16 00:08:47 +0000
commitb9225fd710baeddd2ab6256e3b7b20e2e47e3633 (patch)
tree22d3a36c950cca4e50064b46c4d9b788fff4a2f2 /src/lib/ector/software/ector_software_gradient_sse3.c
parent788507961a55670c959ed5aa57e84c818bc0f4a1 (diff)
ector - fix meson build with sse3 on ix86 (32bit)
Diffstat (limited to 'src/lib/ector/software/ector_software_gradient_sse3.c')
-rw-r--r--src/lib/ector/software/ector_software_gradient_sse3.c214
1 files changed, 214 insertions, 0 deletions
diff --git a/src/lib/ector/software/ector_software_gradient_sse3.c b/src/lib/ector/software/ector_software_gradient_sse3.c
new file mode 100644
index 0000000000..883bdbf37e
--- /dev/null
+++ b/src/lib/ector/software/ector_software_gradient_sse3.c
@@ -0,0 +1,214 @@
1#include "ector_software_gradient.h"
2
3#ifdef BUILD_SSE3
4#include <immintrin.h>
5
6#define GRADIENT_STOPTABLE_SIZE_SHIFT 10
7typedef union { __m128i v; int i[4];} vec4_i;
8typedef union { __m128 v; float f[4];} vec4_f;
9
10#define FETCH_CLAMP_INIT_F \
11 __m128 v_min = _mm_set1_ps(0.0f); \
12 __m128 v_max = _mm_set1_ps((float)(GRADIENT_STOPTABLE_SIZE-1)); \
13 __m128 v_halff = _mm_set1_ps(0.5f); \
14 __m128i v_repeat_mask = _mm_set1_epi32(~((uint32_t)(0xffffff) << GRADIENT_STOPTABLE_SIZE_SHIFT)); \
15 __m128i v_reflect_mask = _mm_set1_epi32(~((uint32_t)(0xffffff) << (GRADIENT_STOPTABLE_SIZE_SHIFT+1))); \
16 __m128i v_reflect_limit = _mm_set1_epi32(2 * GRADIENT_STOPTABLE_SIZE - 1);
17
18#define FETCH_CLAMP_REPEAT_F \
19 vec4_i index_vec; \
20 index_vec.v = _mm_and_si128(v_repeat_mask, _mm_cvttps_epi32(v_index));
21
22#define FETCH_CLAMP_REFLECT_F \
23 vec4_i index_vec; \
24 __m128i v_index_i = _mm_and_si128(v_reflect_mask, _mm_cvttps_epi32(v_index)); \
25 __m128i v_index_i_inv = _mm_sub_epi32(v_reflect_limit, v_index_i); \
26 index_vec.v = _mm_min_epi16(v_index_i, v_index_i_inv);
27
28#define FETCH_CLAMP_PAD_F \
29 vec4_i index_vec; \
30 index_vec.v = _mm_cvttps_epi32(_mm_min_ps(v_max, _mm_max_ps(v_min, v_index)));
31
32#define FETCH_EPILOGUE_CPY \
33 *buffer++ = g_data->color_table[index_vec.i[0]]; \
34 *buffer++ = g_data->color_table[index_vec.i[1]]; \
35 *buffer++ = g_data->color_table[index_vec.i[2]]; \
36 *buffer++ = g_data->color_table[index_vec.i[3]]; \
37}
38
39static void
40loop_break(unsigned int *buffer, int length, int *lprealign, int *lby4 , int *lremaining)
41{
42 int l1=0, l2=0, l3=0;
43
44 while ((uintptr_t)buffer & 0xF)
45 buffer++ , l1++;
46
47 if(length <= l1)
48 {
49 l1 = length;
50 }
51 else
52 {
53 l3 = (length - l1) % 4;
54 l2 = length - l1 - l3 ;
55 }
56
57 *lprealign = l1;
58 *lby4 = l2;
59 *lremaining = l3;
60}
61
62void
63_radial_helper_sse3(uint32_t *buffer, int length, Ector_Renderer_Software_Gradient_Data *g_data,
64 float det, float delta_det, float delta_delta_det, float b, float delta_b)
65{
66 int lprealign, lby4, lremaining, i;
67 vec4_f det_vec;
68 vec4_f delta_det4_vec;
69 vec4_f b_vec;
70 __m128 v_delta_delta_det16;
71 __m128 v_delta_delta_det6;
72 __m128 v_delta_b4;
73
74 loop_break(buffer, length, &lprealign, &lby4, &lremaining);
75
76 // prealign loop
77 for (i = 0 ; i < lprealign ; i++)
78 {
79 *buffer++ = _gradient_pixel(g_data, sqrt(det) - b);
80 det += delta_det;
81 delta_det += delta_delta_det;
82 b += delta_b;
83 }
84
85 // lby4 16byte align loop
86 for (i = 0; i < 4; ++i)
87 {
88 det_vec.f[i] = det;
89 delta_det4_vec.f[i] = 4 * delta_det;
90 b_vec.f[i] = b;
91
92 det += delta_det;
93 delta_det += delta_delta_det;
94 b += delta_b;
95 }
96
97 v_delta_delta_det16 = _mm_set1_ps(16 * delta_delta_det);
98 v_delta_delta_det6 = _mm_set1_ps(6 * delta_delta_det);
99 v_delta_b4 = _mm_set1_ps(4 * delta_b);
100
101#define FETCH_RADIAL_PROLOGUE \
102 for (i = 0 ; i < lby4 ; i+=4) { \
103 __m128 v_index_local = _mm_sub_ps(_mm_sqrt_ps(det_vec.v), b_vec.v); \
104 __m128 v_index = _mm_add_ps(_mm_mul_ps(v_index_local, v_max), v_halff); \
105 det_vec.v = _mm_add_ps(_mm_add_ps(det_vec.v, delta_det4_vec.v), v_delta_delta_det6); \
106 delta_det4_vec.v = _mm_add_ps(delta_det4_vec.v, v_delta_delta_det16); \
107 b_vec.v = _mm_add_ps(b_vec.v, v_delta_b4);
108
109#define FETCH_RADIAL_LOOP(FETCH_CLAMP) \
110 FETCH_RADIAL_PROLOGUE; \
111 FETCH_CLAMP; \
112 FETCH_EPILOGUE_CPY;
113
114 FETCH_CLAMP_INIT_F;
115 switch (g_data->gd->s)
116 {
117 case EFL_GFX_GRADIENT_SPREAD_REPEAT:
118 FETCH_RADIAL_LOOP(FETCH_CLAMP_REPEAT_F);
119 break;
120 case EFL_GFX_GRADIENT_SPREAD_REFLECT:
121 FETCH_RADIAL_LOOP( FETCH_CLAMP_REFLECT_F);
122 break;
123 default:
124 FETCH_RADIAL_LOOP(FETCH_CLAMP_PAD_F);
125 break;
126 }
127
128 // remaining loop
129 for (i = 0 ; i < lremaining ; i++)
130 *buffer++ = _gradient_pixel(g_data, sqrt(det_vec.f[i]) - b_vec.f[i]);
131}
132
133void
134_linear_helper_sse3(uint32_t *buffer, int length, Ector_Renderer_Software_Gradient_Data *g_data, int t, int inc)
135{
136 int lprealign, lby4, lremaining, i;
137 vec4_i t_vec;
138 __m128i v_inc;
139 __m128i v_fxtpt_size;
140 __m128i v_min;
141 __m128i v_max;
142 __m128i v_repeat_mask;
143 __m128i v_reflect_mask;
144 __m128i v_reflect_limit;
145
146 loop_break(buffer, length, &lprealign, &lby4, &lremaining);
147
148 // prealign loop
149 for (i = 0 ; i < lprealign ; i++)
150 {
151 *buffer++ = _gradient_pixel_fixed(g_data, t);
152 t += inc;
153 }
154
155 // lby4 16byte align loop
156 for (i = 0; i < 4; ++i)
157 {
158 t_vec.i[i] = t;
159 t += inc;
160 }
161
162 v_inc = _mm_set1_epi32(4 * inc);
163 v_fxtpt_size = _mm_set1_epi32(FIXPT_SIZE * 0.5);
164
165 v_min = _mm_set1_epi32(0);
166 v_max = _mm_set1_epi32((GRADIENT_STOPTABLE_SIZE - 1));
167
168 v_repeat_mask = _mm_set1_epi32(~((uint32_t)(0xffffff) << GRADIENT_STOPTABLE_SIZE_SHIFT));
169 v_reflect_mask = _mm_set1_epi32(~((uint32_t)(0xffffff) << (GRADIENT_STOPTABLE_SIZE_SHIFT + 1)));
170
171 v_reflect_limit = _mm_set1_epi32(2 * GRADIENT_STOPTABLE_SIZE - 1);
172
173#define FETCH_LINEAR_LOOP_PROLOGUE \
174 for (i = 0 ; i < lby4 ; i+=4) { \
175 vec4_i index_vec; \
176 __m128i v_index; \
177 v_index = _mm_srai_epi32(_mm_add_epi32(t_vec.v, v_fxtpt_size), FIXPT_BITS); \
178 t_vec.v = _mm_add_epi32(t_vec.v, v_inc);
179
180#define FETCH_LINEAR_LOOP_CLAMP_REPEAT \
181 index_vec.v = _mm_and_si128(v_repeat_mask, v_index);
182
183#define FETCH_LINEAR_LOOP_CLAMP_REFLECT \
184 __m128i v_index_i = _mm_and_si128(v_reflect_mask, v_index); \
185 __m128i v_index_i_inv = _mm_sub_epi32(v_reflect_limit, v_index_i); \
186 index_vec.v = _mm_min_epi16(v_index_i, v_index_i_inv);
187
188#define FETCH_LINEAR_LOOP_CLAMP_PAD \
189 index_vec.v = _mm_min_epi16(v_max, _mm_max_epi16(v_min, v_index));
190
191#define FETCH_LINEAR_LOOP(FETCH_LINEAR_LOOP_CLAMP) \
192 FETCH_LINEAR_LOOP_PROLOGUE; \
193 FETCH_LINEAR_LOOP_CLAMP; \
194 FETCH_EPILOGUE_CPY;
195
196 switch (g_data->gd->s)
197 {
198 case EFL_GFX_GRADIENT_SPREAD_REPEAT:
199 FETCH_LINEAR_LOOP(FETCH_LINEAR_LOOP_CLAMP_REPEAT);
200 break;
201 case EFL_GFX_GRADIENT_SPREAD_REFLECT:
202 FETCH_LINEAR_LOOP(FETCH_LINEAR_LOOP_CLAMP_REFLECT);
203 break;
204 default:
205 FETCH_LINEAR_LOOP(FETCH_LINEAR_LOOP_CLAMP_PAD);
206 break;
207 }
208
209 // remaining loop
210 for (i = 0 ; i < lremaining ; i++)
211 *buffer++ = _gradient_pixel_fixed(g_data, t_vec.i[i]);
212}
213
214#endif