This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch perf/map-span-simd
in repository efl.
View the commit online.
commit fd400853d7923c10bbfc6a1a427df0baf3824b9e
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 19:28:57 2026 -0600
evas/map: draw map spans with SSE3 and AVX2
Mapped images were sampled one pixel at a time: plain C for nearest
sampling, MMX for smooth. Rotated, zoomed and 3D mapped objects spend
their rendering time there.
The vector code draws whole groups of four or eight pixels and the
existing loop finishes each span, so it stays the reference and the
only code on CPUs without SSE3, chosen at run time. The pixels are the
same whichever draws them, which a new test checks per CPU tier. The
existing NEON loop is unchanged.
expedite, buffer engine, release build, Ryzen 7 6800U, frames per
second, before -> after, median of 5 runs (spread at most 6%). The SSE
columns have AVX2 disabled with EINA_CPU_DISABLE.
AVX2 SSE
38 Image Map Rotate 172 -> 345 163 -> 201
40 Map Nearest Rotate 634 -> 803 547 -> 590
42 Map Color Rotate 146 -> 307 141 -> 183
44 Map Color Nearest Rotate 201 -> 662 192 -> 455
46 Map Color Alpha Rotate 146 -> 307 141 -> 184
48 Map Color Alpha Nearest 201 -> 671 191 -> 455
50 Image Map 3D 1 1162 -> 3378 1114 -> 2488
51 Image Map 3D 2 859 -> 1582 842 -> 1019
52 Image Map 3D 3 558 -> 1452 482 -> 893
53 Image Map 3D 4 422 -> 721 376 -> 434
54 Image Map 3D 5 990 -> 4003 956 -> 2732
55 Image Map 3D 6 3716 -> 5087 3302 -> 3566
56 Image Map 3D Flow 564 -> 1120 450 -> 676
Tests 39, 41, 43, 45, 47 and 49 move like their neighbours above; none
of 38 to 56 got slower. Frames 1, 17, 40 and 103 of tests 38 to 56, 62
and 63 are identical before and after on every tier.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/evas/common/evas_map_image.c | 16 ++
src/lib/evas/common/evas_map_image_internal.c | 14 ++
src/lib/evas/common/evas_map_image_loop.c | 62 ++++++
src/lib/evas/common/evas_map_image_span.h | 36 ++++
src/lib/evas/common/evas_map_image_span_avx2.c | 184 ++++++++++++++++++
src/lib/evas/common/evas_map_image_span_sse3.c | 31 +++
src/lib/evas/common/evas_map_image_span_x86.h | 161 ++++++++++++++++
src/lib/evas/common/meson.build | 8 +-
src/tests/evas/evas_test_map_simd.c | 251 +++++++++++++++++++++++++
src/tests/evas/meson.build | 13 ++
10 files changed, 774 insertions(+), 2 deletions(-)
diff --git a/src/lib/evas/common/evas_map_image.c b/src/lib/evas/common/evas_map_image.c
index 3ff5273edc..8b2d803d59 100644
--- a/src/lib/evas/common/evas_map_image.c
+++ b/src/lib/evas/common/evas_map_image.c
@@ -1,6 +1,7 @@
#include "evas_common_private.h"
#include "evas_private.h"
#include "evas_blend_private.h"
+#include "evas_map_image_span.h"
#ifdef BUILD_NEON
#include <arm_neon.h>
#endif
@@ -34,6 +35,21 @@ struct _Line
int aa_len[2];
};
+/* NULL where the scalar loops have to draw everything themselves. */
+static const Evas_Map_Span_Func *
+_map_span_funcs_get(int smooth EINA_UNUSED)
+{
+#ifdef BUILD_AVX2
+ if (evas_common_cpu_has_feature(CPU_FEATURE_AVX2))
+ return evas_common_map_span_avx2[!!smooth];
+#endif
+#ifdef BUILD_SSE3
+ if (evas_common_cpu_has_feature(CPU_FEATURE_SSE3))
+ return evas_common_map_span_sse3[!!smooth];
+#endif
+ return NULL;
+}
+
static inline FPc
_interp(int x1, int x2, int p, FPc u1, FPc u2)
{
diff --git a/src/lib/evas/common/evas_map_image_internal.c b/src/lib/evas/common/evas_map_image_internal.c
index 04eff08770..1a40d23ddf 100644
--- a/src/lib/evas/common/evas_map_image_internal.c
+++ b/src/lib/evas/common/evas_map_image_internal.c
@@ -17,6 +17,8 @@ FUNC_NAME(RGBA_Image *src, RGBA_Image *dst,
Eina_Bool havea = EINA_FALSE;
Eina_Bool sa, ssa, da;
Eina_Bool saa; //Source alpha overriding with anti-alias flag.
+ const Evas_Map_Span_Func *span_funcs;
+ Evas_Map_Span_Run run;
int havecol = 4;
cx = clip_x;
@@ -60,6 +62,11 @@ FUNC_NAME(RGBA_Image *src, RGBA_Image *dst,
sw = src->cache_entry.w;
swp = sw << (FP + FPI);
shp = src->cache_entry.h << (FP + FPI);
+ span_funcs = _map_span_funcs_get(smooth);
+ run.texels = sp;
+ run.stride = sw;
+ run.u_end = swp;
+ run.v_end = shp;
sa = src->cache_entry.flags.alpha;
ssa = src->cache_entry.flags.alpha_sparse;
@@ -148,6 +155,8 @@ FUNC_NAME_DO(RGBA_Image *src, RGBA_Image *dst,
int i;
Eina_Bool sa, ssa, da;
Eina_Bool saa; //Source alpha overriding with anti-alias flag.
+ const Evas_Map_Span_Func *span_funcs;
+ Evas_Map_Span_Run run;
RGBA_Image *mask_ie = dc->clip.mask;
int mask_x = dc->clip.mask_x;
@@ -170,6 +179,11 @@ FUNC_NAME_DO(RGBA_Image *src, RGBA_Image *dst,
sw = src->cache_entry.w;
swp = sw << (FP + FPI);
shp = src->cache_entry.h << (FP + FPI);
+ span_funcs = _map_span_funcs_get(smooth);
+ run.texels = sp;
+ run.stride = sw;
+ run.u_end = swp;
+ run.v_end = shp;
havecol = ms->havecol;
direct = ms->direct;
diff --git a/src/lib/evas/common/evas_map_image_loop.c b/src/lib/evas/common/evas_map_image_loop.c
index c1b5e99b55..a994c86904 100644
--- a/src/lib/evas/common/evas_map_image_loop.c
+++ b/src/lib/evas/common/evas_map_image_loop.c
@@ -68,6 +68,37 @@
# endif //COLBLACK
# endif //SCALE_USING_NEON
+# ifndef COLBLACK
+ if (span_funcs)
+ {
+ int done;
+
+ run.u = u;
+ run.v = v;
+ run.ud = ud;
+ run.vd = vd;
+# ifdef COLMUL
+ run.c1 = c1;
+ run.c2 = c2;
+ run.cv = cv;
+ run.cd = cd;
+# ifdef COLSAME
+ done = span_funcs[(c1 == 0xffffffff) ?
+ EVAS_MAP_SPAN_PLAIN : EVAS_MAP_SPAN_COLOR](d, ww, &run);
+# else
+ done = span_funcs[EVAS_MAP_SPAN_GRADIENT](d, ww, &run);
+ cv += done * cd;
+# endif
+# else
+ done = span_funcs[EVAS_MAP_SPAN_PLAIN](d, ww, &run);
+# endif
+ d += done;
+ ww -= done;
+ u += done * ud;
+ v += done * vd;
+ }
+# endif
+
while (ww > 0)
{
# ifdef COLBLACK
@@ -301,6 +332,37 @@
# endif //COLBLACK
# endif //SCALE_USING_NEON
+# ifndef COLBLACK
+ if (span_funcs)
+ {
+ int done;
+
+ run.u = u;
+ run.v = v;
+ run.ud = ud;
+ run.vd = vd;
+# ifdef COLMUL
+ run.c1 = c1;
+ run.c2 = c2;
+ run.cv = cv;
+ run.cd = cd;
+# ifdef COLSAME
+ done = span_funcs[(c1 == 0xffffffff) ?
+ EVAS_MAP_SPAN_PLAIN : EVAS_MAP_SPAN_COLOR](d, ww, &run);
+# else
+ done = span_funcs[EVAS_MAP_SPAN_GRADIENT](d, ww, &run);
+ cv += done * cd;
+# endif
+# else
+ done = span_funcs[EVAS_MAP_SPAN_PLAIN](d, ww, &run);
+# endif
+ d += done;
+ ww -= done;
+ u += done * ud;
+ v += done * vd;
+ }
+# endif
+
while (ww > 0)
{
# ifndef SCALE_USING_NEON
diff --git a/src/lib/evas/common/evas_map_image_span.h b/src/lib/evas/common/evas_map_image_span.h
new file mode 100644
index 0000000000..be6db3e4a1
--- /dev/null
+++ b/src/lib/evas/common/evas_map_image_span.h
@@ -0,0 +1,36 @@
+#ifndef EVAS_MAP_IMAGE_SPAN_H
+#define EVAS_MAP_IMAGE_SPAN_H
+
+/* Vector versions of the span loops in evas_map_image_loop.c. They must
+ * produce the same pixels as those loops: a frame is drawn with whichever
+ * the CPU offers. */
+
+typedef enum
+{
+ EVAS_MAP_SPAN_PLAIN,
+ EVAS_MAP_SPAN_COLOR,
+ EVAS_MAP_SPAN_GRADIENT,
+ EVAS_MAP_SPAN_SHADE_LAST
+} Evas_Map_Span_Shade;
+
+/* One horizontal span. u, v and their bounds are 16.16 source coordinates,
+ * cv is the 16.16 position between the colors c1 and c2. */
+typedef struct _Evas_Map_Span_Run
+{
+ const DATA32 *texels;
+ int stride;
+ int u_end, v_end;
+ int u, v, ud, vd;
+ int cv, cd;
+ DATA32 c1, c2;
+} Evas_Map_Span_Run;
+
+/* Draws as many whole groups of pixels as fit in w and returns that count,
+ * leaving the rest to the caller. */
+typedef int (*Evas_Map_Span_Func)(DATA32 *d, int w, const Evas_Map_Span_Run *run);
+
+/* Indexed by [smooth][shade]. */
+extern const Evas_Map_Span_Func evas_common_map_span_sse3[2][EVAS_MAP_SPAN_SHADE_LAST];
+extern const Evas_Map_Span_Func evas_common_map_span_avx2[2][EVAS_MAP_SPAN_SHADE_LAST];
+
+#endif
diff --git a/src/lib/evas/common/evas_map_image_span_avx2.c b/src/lib/evas/common/evas_map_image_span_avx2.c
new file mode 100644
index 0000000000..010769d7bf
--- /dev/null
+++ b/src/lib/evas/common/evas_map_image_span_avx2.c
@@ -0,0 +1,184 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <immintrin.h>
+
+#include "evas_common_private.h"
+
+#ifndef EFL_ALWAYS_INLINE
+# define EFL_ALWAYS_INLINE inline __attribute__((always_inline))
+#endif
+
+#include "evas_map_image_span_x86.h"
+
+static EFL_ALWAYS_INLINE __m256i
+_map_fetch8(const DATA32 *texels, __m256i at)
+{
+ return _mm256_i32gather_epi32((const int *)texels, at, 4);
+}
+
+static EFL_ALWAYS_INLINE __m256i
+_map_clamp8(__m256i x, __m256i max)
+{
+ return _mm256_min_epi32(_mm256_max_epi32(x, _mm256_setzero_si256()), max);
+}
+
+static EFL_ALWAYS_INLINE __m256i
+_map_interp8(__m256i weight, __m256i to, __m256i from)
+{
+ __m256i step = _mm256_mullo_epi16(_mm256_sub_epi16(to, from), weight);
+
+ step = _mm256_add_epi16(_mm256_srli_epi16(step, 8), from);
+ return _mm256_and_si256(step, _mm256_set1_epi16(0xff));
+}
+
+static EFL_ALWAYS_INLINE __m256i
+_map_mul8(__m256i x, __m256i y)
+{
+ __m256i product = _mm256_mullo_epi16(x, y);
+
+ return _mm256_srli_epi16(_mm256_add_epi16(product, _mm256_set1_epi16(0xff)), 8);
+}
+
+/* Unpacking works within each 128 bit half, so lo holds the channels of
+ * pixels 0, 1, 4, 5 and hi those of 2, 3, 6, 7; packing puts them back. */
+static EFL_ALWAYS_INLINE void
+_map_weights8(__m256i weight, __m256i *lo, __m256i *hi)
+{
+ weight = _mm256_or_si256(weight, _mm256_slli_epi32(weight, 16));
+ *lo = _mm256_unpacklo_epi32(weight, weight);
+ *hi = _mm256_unpackhi_epi32(weight, weight);
+}
+
+static EFL_ALWAYS_INLINE int
+_map_span8(DATA32 *d, int w, const Evas_Map_Span_Run *run,
+ const Eina_Bool smooth, const Evas_Map_Span_Shade shade)
+{
+ const __m256i zero = _mm256_setzero_si256();
+ const __m256i lane = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7);
+ const __m256i stride = _mm256_set1_epi32(run->stride);
+ const __m256i du = _mm256_set1_epi32(8 * (unsigned int)run->ud);
+ const __m256i dv = _mm256_set1_epi32(8 * (unsigned int)run->vd);
+ const __m256i dc = _mm256_set1_epi32(8 * (unsigned int)run->cd);
+ const __m256i u_max = _mm256_set1_epi32(run->u_end - 1);
+ const __m256i v_max = _mm256_set1_epi32(run->v_end - 1);
+ const __m256i texel = _mm256_set1_epi32(1 << 16);
+ const __m256i byte = _mm256_set1_epi32(0xff);
+ __m256i u, v, cv = zero, c1 = zero, c2 = zero;
+ int done;
+
+ u = _mm256_add_epi32(_mm256_set1_epi32(run->u),
+ _mm256_mullo_epi32(_mm256_set1_epi32(run->ud), lane));
+ v = _mm256_add_epi32(_mm256_set1_epi32(run->v),
+ _mm256_mullo_epi32(_mm256_set1_epi32(run->vd), lane));
+ if (shade != EVAS_MAP_SPAN_PLAIN)
+ c1 = _mm256_unpacklo_epi8(_mm256_set1_epi32(run->c1), zero);
+ if (shade == EVAS_MAP_SPAN_GRADIENT)
+ {
+ c2 = _mm256_unpacklo_epi8(_mm256_set1_epi32(run->c2), zero);
+ cv = _mm256_add_epi32(_mm256_set1_epi32(run->cv),
+ _mm256_mullo_epi32(_mm256_set1_epi32(run->cd), lane));
+ }
+
+ for (done = 0; (done + 8) <= w; done += 8)
+ {
+ __m256i lo, hi, pixels;
+
+ if (smooth)
+ {
+ __m256i u1, v1, u2, v2, x1, x2, row1, row2, tl, tr, bl, br;
+ __m256i ru_lo, ru_hi, rv_lo, rv_hi;
+
+ u1 = _map_clamp8(u, u_max);
+ v1 = _map_clamp8(v, v_max);
+ u2 = _map_clamp8(_mm256_add_epi32(u1, texel), u_max);
+ v2 = _map_clamp8(_mm256_add_epi32(v1, texel), v_max);
+ x1 = _mm256_srai_epi32(u1, 16);
+ x2 = _mm256_srai_epi32(u2, 16);
+ row1 = _mm256_mullo_epi32(_mm256_srai_epi32(v1, 16), stride);
+ row2 = _mm256_mullo_epi32(_mm256_srai_epi32(v2, 16), stride);
+ tl = _map_fetch8(run->texels, _mm256_add_epi32(row1, x1));
+ tr = _map_fetch8(run->texels, _mm256_add_epi32(row1, x2));
+ bl = _map_fetch8(run->texels, _mm256_add_epi32(row2, x1));
+ br = _map_fetch8(run->texels, _mm256_add_epi32(row2, x2));
+
+ _map_weights8(_mm256_and_si256(_mm256_srli_epi32(u, 8), byte), &ru_lo, &ru_hi);
+ _map_weights8(_mm256_and_si256(_mm256_srli_epi32(v, 8), byte), &rv_lo, &rv_hi);
+ lo = _map_interp8(rv_lo,
+ _map_interp8(ru_lo, _mm256_unpacklo_epi8(br, zero),
+ _mm256_unpacklo_epi8(bl, zero)),
+ _map_interp8(ru_lo, _mm256_unpacklo_epi8(tr, zero),
+ _mm256_unpacklo_epi8(tl, zero)));
+ hi = _map_interp8(rv_hi,
+ _map_interp8(ru_hi, _mm256_unpackhi_epi8(br, zero),
+ _mm256_unpackhi_epi8(bl, zero)),
+ _map_interp8(ru_hi, _mm256_unpackhi_epi8(tr, zero),
+ _mm256_unpackhi_epi8(tl, zero)));
+ }
+ else
+ {
+ __m256i at = _mm256_add_epi32(_mm256_mullo_epi32(_mm256_srai_epi32(v, 16), stride),
+ _mm256_srai_epi32(u, 16));
+
+ pixels = _map_fetch8(run->texels, at);
+ lo = _mm256_unpacklo_epi8(pixels, zero);
+ hi = _mm256_unpackhi_epi8(pixels, zero);
+ }
+
+ if (shade == EVAS_MAP_SPAN_COLOR)
+ {
+ lo = _map_mul8(c1, lo);
+ hi = _map_mul8(c1, hi);
+ }
+ else if (shade == EVAS_MAP_SPAN_GRADIENT)
+ {
+ __m256i rc_lo, rc_hi;
+
+ _map_weights8(_mm256_srai_epi32(cv, 16), &rc_lo, &rc_hi);
+ lo = _map_mul8(_map_interp8(rc_lo, c2, c1), lo);
+ hi = _map_mul8(_map_interp8(rc_hi, c2, c1), hi);
+ cv = _mm256_add_epi32(cv, dc);
+ }
+
+ _mm256_storeu_si256((__m256i *)(d + done), _mm256_packus_epi16(lo, hi));
+ u = _mm256_add_epi32(u, du);
+ v = _mm256_add_epi32(v, dv);
+ }
+ return done;
+}
+
+static EFL_ALWAYS_INLINE int
+_map_span8_and_4(DATA32 *d, int w, const Evas_Map_Span_Run *run,
+ const Eina_Bool smooth, const Evas_Map_Span_Shade shade)
+{
+ Evas_Map_Span_Run rest;
+ int done = _map_span8(d, w, run, smooth, shade);
+
+ if ((w - done) < 4) return done;
+ rest = *run;
+ rest.u += done * rest.ud;
+ rest.v += done * rest.vd;
+ if (shade == EVAS_MAP_SPAN_GRADIENT) rest.cv += done * rest.cd;
+ return done + _map_span4(d + done, w - done, &rest, smooth, shade);
+}
+
+#define SPAN_FUNC(name, smooth, shade) \
+static int \
+name(DATA32 *d, int w, const Evas_Map_Span_Run *run) \
+{ \
+ return _map_span8_and_4(d, w, run, smooth, shade); \
+}
+
+SPAN_FUNC(_span_nearest, EINA_FALSE, EVAS_MAP_SPAN_PLAIN)
+SPAN_FUNC(_span_nearest_color, EINA_FALSE, EVAS_MAP_SPAN_COLOR)
+SPAN_FUNC(_span_nearest_gradient, EINA_FALSE, EVAS_MAP_SPAN_GRADIENT)
+SPAN_FUNC(_span_smooth, EINA_TRUE, EVAS_MAP_SPAN_PLAIN)
+SPAN_FUNC(_span_smooth_color, EINA_TRUE, EVAS_MAP_SPAN_COLOR)
+SPAN_FUNC(_span_smooth_gradient, EINA_TRUE, EVAS_MAP_SPAN_GRADIENT)
+
+const Evas_Map_Span_Func evas_common_map_span_avx2[2][EVAS_MAP_SPAN_SHADE_LAST] =
+{
+ { _span_nearest, _span_nearest_color, _span_nearest_gradient },
+ { _span_smooth, _span_smooth_color, _span_smooth_gradient }
+};
diff --git a/src/lib/evas/common/evas_map_image_span_sse3.c b/src/lib/evas/common/evas_map_image_span_sse3.c
new file mode 100644
index 0000000000..9ebc8d7fb1
--- /dev/null
+++ b/src/lib/evas/common/evas_map_image_span_sse3.c
@@ -0,0 +1,31 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "evas_common_private.h"
+
+#ifndef EFL_ALWAYS_INLINE
+# define EFL_ALWAYS_INLINE inline __attribute__((always_inline))
+#endif
+
+#include "evas_map_image_span_x86.h"
+
+#define SPAN_FUNC(name, smooth, shade) \
+static int \
+name(DATA32 *d, int w, const Evas_Map_Span_Run *run) \
+{ \
+ return _map_span4(d, w, run, smooth, shade); \
+}
+
+SPAN_FUNC(_span_nearest, EINA_FALSE, EVAS_MAP_SPAN_PLAIN)
+SPAN_FUNC(_span_nearest_color, EINA_FALSE, EVAS_MAP_SPAN_COLOR)
+SPAN_FUNC(_span_nearest_gradient, EINA_FALSE, EVAS_MAP_SPAN_GRADIENT)
+SPAN_FUNC(_span_smooth, EINA_TRUE, EVAS_MAP_SPAN_PLAIN)
+SPAN_FUNC(_span_smooth_color, EINA_TRUE, EVAS_MAP_SPAN_COLOR)
+SPAN_FUNC(_span_smooth_gradient, EINA_TRUE, EVAS_MAP_SPAN_GRADIENT)
+
+const Evas_Map_Span_Func evas_common_map_span_sse3[2][EVAS_MAP_SPAN_SHADE_LAST] =
+{
+ { _span_nearest, _span_nearest_color, _span_nearest_gradient },
+ { _span_smooth, _span_smooth_color, _span_smooth_gradient }
+};
diff --git a/src/lib/evas/common/evas_map_image_span_x86.h b/src/lib/evas/common/evas_map_image_span_x86.h
new file mode 100644
index 0000000000..c40f8b8618
--- /dev/null
+++ b/src/lib/evas/common/evas_map_image_span_x86.h
@@ -0,0 +1,161 @@
+/* The four pixel span loop, compiled once with -msse3 and once more inside
+ * the AVX2 unit, which uses it for what does not fill eight pixels. */
+
+#include <emmintrin.h>
+
+#include "evas_map_image_span.h"
+
+static EFL_ALWAYS_INLINE __m128i
+_map_mullo4(__m128i a, __m128i b)
+{
+ __m128i even = _mm_mul_epu32(a, b);
+ __m128i odd = _mm_mul_epu32(_mm_srli_si128(a, 4), _mm_srli_si128(b, 4));
+
+ return _mm_unpacklo_epi32(_mm_shuffle_epi32(even, _MM_SHUFFLE(0, 0, 2, 0)),
+ _mm_shuffle_epi32(odd, _MM_SHUFFLE(0, 0, 2, 0)));
+}
+
+/* x limited to [0, max] */
+static EFL_ALWAYS_INLINE __m128i
+_map_clamp4(__m128i x, __m128i max)
+{
+ __m128i over;
+
+ x = _mm_andnot_si128(_mm_srai_epi32(x, 31), x);
+ over = _mm_cmpgt_epi32(x, max);
+ return _mm_or_si128(_mm_and_si128(over, max), _mm_andnot_si128(over, x));
+}
+
+static EFL_ALWAYS_INLINE __m128i
+_map_fetch4(const DATA32 *texels, __m128i at)
+{
+ return _mm_setr_epi32(texels[_mm_cvtsi128_si32(at)],
+ texels[_mm_cvtsi128_si32(_mm_shuffle_epi32(at, 0x55))],
+ texels[_mm_cvtsi128_si32(_mm_shuffle_epi32(at, 0xaa))],
+ texels[_mm_cvtsi128_si32(_mm_shuffle_epi32(at, 0xff))]);
+}
+
+/* INTERP_256 on eight 16 bit channels */
+static EFL_ALWAYS_INLINE __m128i
+_map_interp4(__m128i weight, __m128i to, __m128i from)
+{
+ __m128i step = _mm_mullo_epi16(_mm_sub_epi16(to, from), weight);
+
+ step = _mm_add_epi16(_mm_srli_epi16(step, 8), from);
+ return _mm_and_si128(step, _mm_set1_epi16(0xff));
+}
+
+/* MUL4_SYM on eight 16 bit channels */
+static EFL_ALWAYS_INLINE __m128i
+_map_mul4(__m128i x, __m128i y)
+{
+ __m128i product = _mm_mullo_epi16(x, y);
+
+ return _mm_srli_epi16(_mm_add_epi16(product, _mm_set1_epi16(0xff)), 8);
+}
+
+/* Spread four per pixel weights, one per 32 bit lane, over the channels of
+ * the low and high pixel pairs. */
+static EFL_ALWAYS_INLINE void
+_map_weights4(__m128i weight, __m128i *lo, __m128i *hi)
+{
+ weight = _mm_or_si128(weight, _mm_slli_epi32(weight, 16));
+ *lo = _mm_unpacklo_epi32(weight, weight);
+ *hi = _mm_unpackhi_epi32(weight, weight);
+}
+
+static EFL_ALWAYS_INLINE int
+_map_span4(DATA32 *d, int w, const Evas_Map_Span_Run *run,
+ const Eina_Bool smooth, const Evas_Map_Span_Shade shade)
+{
+ const __m128i zero = _mm_setzero_si128();
+ const __m128i stride = _mm_set1_epi32(run->stride);
+ const __m128i du = _mm_set1_epi32(4 * (unsigned int)run->ud);
+ const __m128i dv = _mm_set1_epi32(4 * (unsigned int)run->vd);
+ const __m128i dc = _mm_set1_epi32(4 * (unsigned int)run->cd);
+ const __m128i u_max = _mm_set1_epi32(run->u_end - 1);
+ const __m128i v_max = _mm_set1_epi32(run->v_end - 1);
+ const __m128i texel = _mm_set1_epi32(1 << 16);
+ const __m128i byte = _mm_set1_epi32(0xff);
+ __m128i u, v, cv = zero, c1 = zero, c2 = zero;
+ int done;
+
+ u = _mm_add_epi32(_mm_set1_epi32(run->u),
+ _map_mullo4(_mm_set1_epi32(run->ud), _mm_setr_epi32(0, 1, 2, 3)));
+ v = _mm_add_epi32(_mm_set1_epi32(run->v),
+ _map_mullo4(_mm_set1_epi32(run->vd), _mm_setr_epi32(0, 1, 2, 3)));
+ if (shade != EVAS_MAP_SPAN_PLAIN)
+ c1 = _mm_unpacklo_epi8(_mm_set1_epi32(run->c1), zero);
+ if (shade == EVAS_MAP_SPAN_GRADIENT)
+ {
+ c2 = _mm_unpacklo_epi8(_mm_set1_epi32(run->c2), zero);
+ cv = _mm_add_epi32(_mm_set1_epi32(run->cv),
+ _map_mullo4(_mm_set1_epi32(run->cd), _mm_setr_epi32(0, 1, 2, 3)));
+ }
+
+ for (done = 0; (done + 4) <= w; done += 4)
+ {
+ __m128i lo, hi, pixels;
+
+ if (smooth)
+ {
+ __m128i u1, v1, u2, v2, x1, x2, row1, row2, tl, tr, bl, br;
+ __m128i ru_lo, ru_hi, rv_lo, rv_hi;
+
+ u1 = _map_clamp4(u, u_max);
+ v1 = _map_clamp4(v, v_max);
+ u2 = _map_clamp4(_mm_add_epi32(u1, texel), u_max);
+ v2 = _map_clamp4(_mm_add_epi32(v1, texel), v_max);
+ x1 = _mm_srai_epi32(u1, 16);
+ x2 = _mm_srai_epi32(u2, 16);
+ row1 = _map_mullo4(_mm_srai_epi32(v1, 16), stride);
+ row2 = _map_mullo4(_mm_srai_epi32(v2, 16), stride);
+ tl = _map_fetch4(run->texels, _mm_add_epi32(row1, x1));
+ tr = _map_fetch4(run->texels, _mm_add_epi32(row1, x2));
+ bl = _map_fetch4(run->texels, _mm_add_epi32(row2, x1));
+ br = _map_fetch4(run->texels, _mm_add_epi32(row2, x2));
+
+ _map_weights4(_mm_and_si128(_mm_srli_epi32(u, 8), byte), &ru_lo, &ru_hi);
+ _map_weights4(_mm_and_si128(_mm_srli_epi32(v, 8), byte), &rv_lo, &rv_hi);
+ lo = _map_interp4(rv_lo,
+ _map_interp4(ru_lo, _mm_unpacklo_epi8(br, zero),
+ _mm_unpacklo_epi8(bl, zero)),
+ _map_interp4(ru_lo, _mm_unpacklo_epi8(tr, zero),
+ _mm_unpacklo_epi8(tl, zero)));
+ hi = _map_interp4(rv_hi,
+ _map_interp4(ru_hi, _mm_unpackhi_epi8(br, zero),
+ _mm_unpackhi_epi8(bl, zero)),
+ _map_interp4(ru_hi, _mm_unpackhi_epi8(tr, zero),
+ _mm_unpackhi_epi8(tl, zero)));
+ }
+ else
+ {
+ __m128i at = _mm_add_epi32(_map_mullo4(_mm_srai_epi32(v, 16), stride),
+ _mm_srai_epi32(u, 16));
+
+ pixels = _map_fetch4(run->texels, at);
+ lo = _mm_unpacklo_epi8(pixels, zero);
+ hi = _mm_unpackhi_epi8(pixels, zero);
+ }
+
+ if (shade == EVAS_MAP_SPAN_COLOR)
+ {
+ lo = _map_mul4(c1, lo);
+ hi = _map_mul4(c1, hi);
+ }
+ else if (shade == EVAS_MAP_SPAN_GRADIENT)
+ {
+ __m128i rc_lo, rc_hi;
+
+ _map_weights4(_mm_srai_epi32(cv, 16), &rc_lo, &rc_hi);
+ lo = _map_mul4(_map_interp4(rc_lo, c2, c1), lo);
+ hi = _map_mul4(_map_interp4(rc_hi, c2, c1), hi);
+ cv = _mm_add_epi32(cv, dc);
+ }
+
+ _mm_storeu_si128((__m128i *)(d + done), _mm_packus_epi16(lo, hi));
+ u = _mm_add_epi32(u, du);
+ v = _mm_add_epi32(v, dv);
+ }
+ return done;
+}
diff --git a/src/lib/evas/common/meson.build b/src/lib/evas/common/meson.build
index 90bd28f809..912c523ae1 100644
--- a/src/lib/evas/common/meson.build
+++ b/src/lib/evas/common/meson.build
@@ -45,6 +45,8 @@ evas_src += files([
'evas_font_ot.c',
'evas_map_image.c',
'evas_map_image.h',
+ 'evas_map_image_span.h',
+ 'evas_map_image_span_x86.h',
'evas_blend.h',
'evas_blend_private.h',
'evas_convert_color.h',
@@ -84,14 +86,16 @@ evas_src += files([
if cpu_sse3 == true
evas_src_opt += files([
- 'evas_op_blend/op_blend_master_sse3.c'
+ 'evas_op_blend/op_blend_master_sse3.c',
+ 'evas_map_image_span_sse3.c'
])
endif
if cpu_avx2 == true
evas_src_opt_avx2 += files([
'evas_op_blend/op_blend_master_avx2.c',
- 'evas_op_copy/op_copy_master_avx2.c'
+ 'evas_op_copy/op_copy_master_avx2.c',
+ 'evas_map_image_span_avx2.c'
])
endif
diff --git a/src/tests/evas/evas_test_map_simd.c b/src/tests/evas/evas_test_map_simd.c
new file mode 100644
index 0000000000..7ea519bfd1
--- /dev/null
+++ b/src/tests/evas/evas_test_map_simd.c
@@ -0,0 +1,251 @@
+/* The software map rasterizer picks its span loops from the CPU features,
+ * and every choice has to produce the same pixels. Evas reads the features
+ * once per process, so each tier renders in its own child with
+ * EINA_CPU_DISABLE set before evas_init().
+ *
+ * Objects are drawn with the copy render op: the blend span functions are
+ * not required to agree to the last bit between tiers, the copy ones are.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include <Ecore_Evas.h>
+
+#define CANVAS_W 160
+#define CANVAS_H 120
+#define SRC_W 37
+#define SRC_H 23
+
+typedef struct
+{
+ const char *name;
+ int x[4], y[4];
+} Shape;
+
+typedef struct
+{
+ const char *name;
+ unsigned char col[4][4];
+} Shade;
+
+static const Shape shapes[] =
+{
+ { "upright", { 10, 140, 140, 10 }, { 10, 10, 100, 100 } },
+ { "rotated", { 70, 150, 90, 10 }, { 2, 70, 118, 50 } },
+ { "shrunk", { 20, 41, 38, 17 }, { 20, 23, 37, 34 } },
+ { "mirrored", { 150, 12, 20, 141 }, { 15, 9, 103, 111 } },
+ { "clipped", { -60, 220, 190, -30 }, { -20, -40, 150, 160 } },
+ { "sliver1", { 30, 31, 33, 32 }, { 5, 5, 115, 115 } },
+ { "sliver3", { 50, 53, 56, 53 }, { 5, 5, 115, 115 } },
+ { "sliver5", { 60, 65, 66, 61 }, { 5, 5, 115, 115 } },
+ { "sliver9", { 70, 79, 80, 71 }, { 5, 5, 115, 115 } },
+ { "wedge", { 5, 155, 82, 78 }, { 5, 6, 115, 114 } },
+};
+
+static const Shade shades[] =
+{
+ { "white", { { 255, 255, 255, 255 }, { 255, 255, 255, 255 },
+ { 255, 255, 255, 255 }, { 255, 255, 255, 255 } } },
+ { "tinted", { { 200, 120, 40, 255 }, { 200, 120, 40, 255 },
+ { 200, 120, 40, 255 }, { 200, 120, 40, 255 } } },
+ { "faded", { { 90, 90, 90, 128 }, { 90, 90, 90, 128 },
+ { 90, 90, 90, 128 }, { 90, 90, 90, 128 } } },
+ { "gradient", { { 255, 255, 255, 255 }, { 20, 200, 60, 255 },
+ { 10, 10, 10, 64 }, { 90, 30, 250, 255 } } },
+ { "black", { { 0, 0, 0, 255 }, { 0, 0, 0, 255 },
+ { 0, 0, 0, 255 }, { 0, 0, 0, 255 } } },
+};
+
+#define COUNT(a) (sizeof(a) / sizeof((a)[0]))
+#define SCENES (COUNT(shapes) * COUNT(shades) * 2 * 2)
+#define SCENE_PIXELS (CANVAS_W * CANVAS_H)
+#define BYTES (SCENES * SCENE_PIXELS * sizeof(unsigned int))
+
+static void
+_source_fill(unsigned int *pixels, Eina_Bool alpha)
+{
+ unsigned int seed = 12345;
+ int i;
+
+ for (i = 0; i < SRC_W * SRC_H; i++)
+ {
+ unsigned int a, r, g, b;
+
+ seed = (seed * 1103515245) + 12345;
+ a = alpha ? ((seed >> 3) & 0xff) : 0xff;
+ r = (((seed >> 24) & 0xff) * a) / 255;
+ g = (((seed >> 16) & 0xff) * a) / 255;
+ b = (((seed >> 8) & 0xff) * a) / 255;
+ /* Runs of fully transparent texels: the scalar loops special case
+ * them. */
+ if (alpha && (((i / 5) % 7) == 0)) a = r = g = b = 0;
+ pixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
+ }
+}
+
+static void
+_render(unsigned int *out)
+{
+ Ecore_Evas *ee;
+ Evas *e;
+ Evas_Object *bg, *img[2];
+ Evas_Map *map;
+ unsigned int src[SRC_W * SRC_H];
+ size_t shape, shade;
+ int alpha, smooth, i;
+
+ if (!ecore_evas_init()) _exit(2);
+ ee = ecore_evas_buffer_new(CANVAS_W, CANVAS_H);
+ if (!ee) _exit(2);
+ e = ecore_evas_get(ee);
+
+ bg = evas_object_rectangle_add(e);
+ evas_object_color_set(bg, 30, 60, 90, 255);
+ evas_object_resize(bg, CANVAS_W, CANVAS_H);
+ evas_object_show(bg);
+
+ for (alpha = 0; alpha < 2; alpha++)
+ {
+ img[alpha] = evas_object_image_filled_add(e);
+ evas_object_image_size_set(img[alpha], SRC_W, SRC_H);
+ evas_object_image_alpha_set(img[alpha], alpha);
+ _source_fill(src, alpha);
+ evas_object_image_data_copy_set(img[alpha], src);
+ evas_object_image_data_update_add(img[alpha], 0, 0, SRC_W, SRC_H);
+ evas_object_resize(img[alpha], SRC_W, SRC_H);
+ evas_object_render_op_set(img[alpha], EVAS_RENDER_COPY);
+ }
+
+ map = evas_map_new(4);
+ for (alpha = 0; alpha < 2; alpha++)
+ for (smooth = 0; smooth < 2; smooth++)
+ for (shade = 0; shade < COUNT(shades); shade++)
+ for (shape = 0; shape < COUNT(shapes); shape++)
+ {
+ const int u[4] = { 0, SRC_W, SRC_W, 0 };
+ const int v[4] = { 0, 0, SRC_H, SRC_H };
+
+ for (i = 0; i < 4; i++)
+ {
+ const unsigned char *c = shades[shade].col[i];
+
+ evas_map_point_coord_set(map, i, shapes[shape].x[i],
+ shapes[shape].y[i], 0);
+ evas_map_point_image_uv_set(map, i, u[i], v[i]);
+ evas_map_point_color_set(map, i, c[0], c[1], c[2], c[3]);
+ }
+ evas_map_smooth_set(map, smooth);
+ evas_object_map_set(img[alpha], map);
+ evas_object_map_enable_set(img[alpha], EINA_TRUE);
+ evas_object_show(img[alpha]);
+ evas_damage_rectangle_add(e, 0, 0, CANVAS_W, CANVAS_H);
+ ecore_evas_manual_render(ee);
+ memcpy(out, ecore_evas_buffer_pixels_get(ee),
+ SCENE_PIXELS * sizeof(unsigned int));
+ out += SCENE_PIXELS;
+ evas_object_hide(img[alpha]);
+ }
+ evas_map_free(map);
+ ecore_evas_free(ee);
+ ecore_evas_shutdown();
+}
+
+static unsigned int *
+_tier_render(const char *disable)
+{
+ unsigned int *out;
+ pid_t pid;
+ int status;
+
+ out = mmap(NULL, BYTES, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ if (out == MAP_FAILED) exit(2);
+ pid = fork();
+ if (pid < 0) exit(2);
+ if (!pid)
+ {
+ if (disable) setenv("EINA_CPU_DISABLE", disable, 1);
+ else unsetenv("EINA_CPU_DISABLE");
+ _render(out);
+ _exit(0);
+ }
+ if ((waitpid(pid, &status, 0) != pid) || (!WIFEXITED(status)) || WEXITSTATUS(status))
+ {
+ fprintf(stderr, "rendering with '%s' disabled did not finish\n",
+ disable ? disable : "nothing");
+ exit(1);
+ }
+ return out;
+}
+
+static int
+_tier_compare(const char *tier, const unsigned int *got, const unsigned int *ref)
+{
+ size_t i, bad = 0;
+
+ for (i = 0; i < SCENES; i++)
+ {
+ const unsigned int *g = got + (i * SCENE_PIXELS);
+ const unsigned int *r = ref + (i * SCENE_PIXELS);
+ size_t shape = i % COUNT(shapes);
+ size_t shade = (i / COUNT(shapes)) % COUNT(shades);
+ size_t smooth = (i / (COUNT(shapes) * COUNT(shades))) % 2;
+ size_t alpha = i / (COUNT(shapes) * COUNT(shades) * 2);
+ int p, count = 0, first = -1;
+
+ for (p = 0; p < SCENE_PIXELS; p++)
+ if (g[p] != r[p])
+ {
+ if (first < 0) first = p;
+ count++;
+ }
+ if (!count) continue;
+ if (bad++ < 8)
+ fprintf(stderr, "%s: %s %s %s %s: %d pixels differ, first at %d,%d "
+ "got %08x want %08x\n", tier, shapes[shape].name,
+ shades[shade].name, smooth ? "smooth" : "nearest",
+ alpha ? "alpha" : "opaque", count, first % CANVAS_W,
+ first / CANVAS_W, g[first], r[first]);
+ }
+ if (bad) fprintf(stderr, "%s: %zu of %zu scenes differ\n", tier, bad, (size_t)SCENES);
+ return !!bad;
+}
+
+int
+main(void)
+{
+ const unsigned int *ref, *mid, *full;
+ unsigned long long hash = 1469598103934665603ULL;
+ size_t i, drawn = 0;
+ int failed;
+
+ ref = _tier_render("avx2,sse3");
+ mid = _tier_render("avx2");
+ full = _tier_render(NULL);
+
+ for (i = 0; i < (BYTES / sizeof(unsigned int)); i++)
+ {
+ hash = (hash ^ ref[i]) * 1099511628211ULL;
+ if (ref[i] != 0xff1e3c5a) drawn++;
+ }
+ /* A scene list that draws nothing would compare equal and test nothing. */
+ if (drawn < (size_t)SCENES * 100)
+ {
+ fprintf(stderr, "only %zu pixels drawn over %zu scenes\n", drawn, (size_t)SCENES);
+ return 1;
+ }
+
+ failed = _tier_compare("without avx2", mid, ref);
+ failed |= _tier_compare("native", full, ref);
+ printf("%zu scenes, %zu drawn pixels, reference hash %016llx\n",
+ (size_t)SCENES, drawn, hash);
+ return failed;
+}
diff --git a/src/tests/evas/meson.build b/src/tests/evas/meson.build
index 600e89864e..88dbb502dc 100644
--- a/src/tests/evas/meson.build
+++ b/src/tests/evas/meson.build
@@ -81,6 +81,19 @@ test('evas-scale-sample-mask', evas_scale_sample_mask,
timeout : master_timeout
)
+# Renders maps once per CPU tier and requires identical pixels from each.
+if host_machine.system() != 'windows'
+ evas_map_simd = executable('evas_map_simd',
+ ['evas_test_map_simd.c'],
+ dependencies: [evas, ecore_evas]
+ )
+
+ test('evas-map-simd', evas_map_simd,
+ env : test_env,
+ timeout : master_timeout
+ )
+endif
+
# Compares every C/NEON pair in the evas span and point op tables. It includes
# the op translation units directly rather than linking them, because the copy
# tables are static; that keeps the library itself untouched. Skips (exit 77)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.