gdk: add i386 3DNow pixel compositing
This commit is contained in:
parent
cc25d6664d
commit
c7f4dc8a82
4 changed files with 143 additions and 4 deletions
43
configure.ac
43
configure.ac
|
|
@ -255,6 +255,49 @@ AC_SUBST(GDK_PIXELOPS_X86_MMX_CFLAGS)
|
|||
AM_CONDITIONAL(GDK_PIXELOPS_X86_MMX,
|
||||
test "$gdk_pixelops_x86_mmx" = yes)
|
||||
|
||||
GDK_PIXELOPS_X86_3DNOW_CFLAGS=
|
||||
gdk_pixelops_x86_3dnow=no
|
||||
|
||||
if test "$gdk_pixelops_x86_mmx" = yes; then
|
||||
AC_MSG_CHECKING([whether the C compiler supports GDK 3DNow pixel operations])
|
||||
|
||||
gdk_save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -mmmx -m3dnow -mno-sse -mno-sse2"
|
||||
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[
|
||||
#include <cpuid.h>
|
||||
#include <mmintrin.h>
|
||||
#include <mm3dnow.h>
|
||||
]],
|
||||
[[
|
||||
__m64 value = _mm_set1_pi16 (1);
|
||||
volatile int sink;
|
||||
|
||||
value = _m_pmulhrw (value, value);
|
||||
sink = _mm_cvtsi64_si32 (value);
|
||||
sink ^= (int) bit_3DNOW;
|
||||
_m_femms ();
|
||||
(void) sink;
|
||||
]])],
|
||||
[gdk_pixelops_x86_3dnow=yes],
|
||||
[gdk_pixelops_x86_3dnow=no])
|
||||
|
||||
CFLAGS="$gdk_save_CFLAGS"
|
||||
AC_MSG_RESULT([$gdk_pixelops_x86_3dnow])
|
||||
fi
|
||||
|
||||
if test "$gdk_pixelops_x86_3dnow" = yes; then
|
||||
GDK_PIXELOPS_X86_3DNOW_CFLAGS="-mmmx -m3dnow -mno-sse -mno-sse2"
|
||||
AC_DEFINE([HAVE_GDK_PIXELOPS_X86_3DNOW], [1],
|
||||
[Define if the GDK 32-bit x86 3DNow pixel operations backend can be built])
|
||||
fi
|
||||
|
||||
AC_SUBST(GDK_PIXELOPS_X86_3DNOW_CFLAGS)
|
||||
AM_CONDITIONAL(GDK_PIXELOPS_X86_3DNOW,
|
||||
test "$gdk_pixelops_x86_3dnow" = yes)
|
||||
|
||||
|
||||
dnl
|
||||
dnl Check for a working C++ compiler, but do not bail out, if none is found.
|
||||
|
|
|
|||
|
|
@ -138,6 +138,17 @@ libgdk_pixelops_x86_mmx_la_CFLAGS = \
|
|||
$(GDK_PIXELOPS_X86_MMX_CFLAGS)
|
||||
endif
|
||||
|
||||
if GDK_PIXELOPS_X86_3DNOW
|
||||
noinst_LTLIBRARIES += libgdk-pixelops-x86-3dnow.la
|
||||
gdk_pixelops_arch_libs += libgdk-pixelops-x86-3dnow.la
|
||||
|
||||
libgdk_pixelops_x86_3dnow_la_SOURCES = gdkpixelops-x86-mmx.c
|
||||
libgdk_pixelops_x86_3dnow_la_CFLAGS = \
|
||||
$(AM_CFLAGS) \
|
||||
$(GDK_PIXELOPS_X86_3DNOW_CFLAGS) \
|
||||
-DGDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
endif
|
||||
|
||||
gdk_pixelops_private_sources = \
|
||||
gdkpixelops-generic.c \
|
||||
$(gdk_pixelops_arch_sources)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,17 @@
|
|||
#include <string.h>
|
||||
#include <mmintrin.h>
|
||||
|
||||
#ifdef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
#include <mm3dnow.h>
|
||||
#define GDK_PIXELOPS_COMPOSITE_0888 _gdk_pixel_ops_composite_0888_3dnow
|
||||
#define GDK_PIXELOPS_COMPOSITE_565 _gdk_pixel_ops_composite_565_3dnow
|
||||
#define GDK_PIXELOPS_MMX_EMPTY() _m_femms ()
|
||||
#else
|
||||
#define GDK_PIXELOPS_COMPOSITE_0888 _gdk_pixel_ops_composite_0888_mmx
|
||||
#define GDK_PIXELOPS_COMPOSITE_565 _gdk_pixel_ops_composite_565_mmx
|
||||
#define GDK_PIXELOPS_MMX_EMPTY() _mm_empty ()
|
||||
#endif
|
||||
|
||||
#include "gdkpixelops.h"
|
||||
|
||||
#ifndef __i386__
|
||||
|
|
@ -23,8 +34,37 @@ _gdk_pixel_ops_composite_0888_generic (guchar *src_buf,
|
|||
gint width,
|
||||
gint height);
|
||||
|
||||
#ifdef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
static __inline__ __m64
|
||||
blend_3dnow (__m64 s,
|
||||
__m64 d,
|
||||
__m64 a)
|
||||
{
|
||||
__m64 scaled;
|
||||
__m64 mask;
|
||||
__m64 coeff;
|
||||
__m64 delta;
|
||||
__m64 correction;
|
||||
__m64 t;
|
||||
|
||||
scaled = _mm_slli_pi16 (a, 8);
|
||||
mask = _mm_srai_pi16 (scaled, 15);
|
||||
|
||||
coeff = _mm_add_pi16 (a, scaled);
|
||||
coeff = _mm_sub_pi16 (coeff, mask);
|
||||
|
||||
delta = _mm_sub_pi16 (s, d);
|
||||
correction = _mm_and_si64 (delta, mask);
|
||||
|
||||
t = _m_pmulhrw (delta, coeff);
|
||||
t = _mm_add_pi16 (t, correction);
|
||||
|
||||
return _mm_add_pi16 (t, d);
|
||||
}
|
||||
#endif
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
||||
GDK_PIXELOPS_COMPOSITE_0888 (guchar *src_buf,
|
||||
gint src_rowstride,
|
||||
guchar *dest_buf,
|
||||
gint dest_rowstride,
|
||||
|
|
@ -47,8 +87,10 @@ _gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
|||
{
|
||||
const __m64 zero = _mm_setzero_si64 ();
|
||||
const __m64 ones = _mm_cmpeq_pi16 (zero, zero);
|
||||
#ifndef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
const __m64 ff = _mm_srli_pi16 (ones, 8);
|
||||
const __m64 bias = _mm_set1_pi16 (0x80);
|
||||
#endif
|
||||
const __m64 rgb_mask = _mm_srli_si64 (ones, 16);
|
||||
guchar *src = src_buf;
|
||||
guchar *dest = dest_buf;
|
||||
|
|
@ -67,7 +109,9 @@ _gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
|||
__m64 s;
|
||||
__m64 d;
|
||||
__m64 a;
|
||||
#ifndef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
__m64 ia;
|
||||
#endif
|
||||
__m64 t;
|
||||
__m64 packed;
|
||||
|
||||
|
|
@ -89,6 +133,9 @@ _gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
|||
a = _mm_unpacklo_pi32 (a, a);
|
||||
a = _mm_and_si64 (a, rgb_mask);
|
||||
|
||||
#ifdef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
t = blend_3dnow (s, d, a);
|
||||
#else
|
||||
ia = _mm_sub_pi16 (ff, a);
|
||||
|
||||
t = _mm_add_pi16 (_mm_mullo_pi16 (s, a),
|
||||
|
|
@ -97,6 +144,7 @@ _gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
|||
t = _mm_add_pi16 (t, bias);
|
||||
t = _mm_add_pi16 (t, _mm_srli_pi16 (t, 8));
|
||||
t = _mm_srli_pi16 (t, 8);
|
||||
#endif
|
||||
|
||||
packed = _mm_packs_pu16 (t, t);
|
||||
result = (guint32) _mm_cvtsi64_si32 (packed);
|
||||
|
|
@ -111,7 +159,7 @@ _gdk_pixel_ops_composite_0888_mmx (guchar *src_buf,
|
|||
dest += dest_rowstride;
|
||||
}
|
||||
|
||||
_mm_empty ();
|
||||
GDK_PIXELOPS_MMX_EMPTY ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +196,9 @@ blend_565_mmx (__m64 zero,
|
|||
__m64 s;
|
||||
__m64 d;
|
||||
__m64 a;
|
||||
#ifndef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
__m64 ia;
|
||||
#endif
|
||||
__m64 t;
|
||||
guint32 result;
|
||||
|
||||
|
|
@ -162,6 +212,9 @@ blend_565_mmx (__m64 zero,
|
|||
a = _mm_unpacklo_pi16 (a, a);
|
||||
a = _mm_unpacklo_pi32 (a, a);
|
||||
|
||||
#ifdef GDK_PIXELOPS_X86_3DNOW_IMPL
|
||||
t = blend_3dnow (s, d, a);
|
||||
#else
|
||||
ia = _mm_sub_pi16 (ff, a);
|
||||
|
||||
t = _mm_add_pi16 (_mm_mullo_pi16 (s, a),
|
||||
|
|
@ -170,6 +223,7 @@ blend_565_mmx (__m64 zero,
|
|||
t = _mm_add_pi16 (t, bias);
|
||||
t = _mm_add_pi16 (t, _mm_srli_pi16 (t, 8));
|
||||
t = _mm_srli_pi16 (t, 8);
|
||||
#endif
|
||||
t = _mm_packs_pu16 (t, t);
|
||||
|
||||
__asm__ ("movd %1,%0"
|
||||
|
|
@ -180,7 +234,7 @@ blend_565_mmx (__m64 zero,
|
|||
}
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_gdk_pixel_ops_composite_565_mmx (guchar *src_buf,
|
||||
GDK_PIXELOPS_COMPOSITE_565 (guchar *src_buf,
|
||||
gint src_rowstride,
|
||||
guchar *dest_buf,
|
||||
gint dest_rowstride,
|
||||
|
|
@ -255,5 +309,5 @@ _gdk_pixel_ops_composite_565_mmx (guchar *src_buf,
|
|||
dest += dest_rowstride;
|
||||
}
|
||||
|
||||
_mm_empty ();
|
||||
GDK_PIXELOPS_MMX_EMPTY ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,26 @@ _gdk_pixel_ops_composite_565_mmx (guchar *src_buf,
|
|||
gint width,
|
||||
gint height);
|
||||
|
||||
#ifdef HAVE_GDK_PIXELOPS_X86_3DNOW
|
||||
G_GNUC_INTERNAL void
|
||||
_gdk_pixel_ops_composite_0888_3dnow (guchar *src_buf,
|
||||
gint src_rowstride,
|
||||
guchar *dest_buf,
|
||||
gint dest_rowstride,
|
||||
GdkByteOrder dest_byte_order,
|
||||
gint width,
|
||||
gint height);
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_gdk_pixel_ops_composite_565_3dnow (guchar *src_buf,
|
||||
gint src_rowstride,
|
||||
guchar *dest_buf,
|
||||
gint dest_rowstride,
|
||||
GdkByteOrder dest_byte_order,
|
||||
gint width,
|
||||
gint height);
|
||||
#endif
|
||||
|
||||
G_GNUC_INTERNAL void
|
||||
_gdk_pixel_ops_init (void)
|
||||
{
|
||||
|
|
@ -51,6 +71,17 @@ _gdk_pixel_ops_init (void)
|
|||
_gdk_pixel_ops_composite_0888_mmx;
|
||||
_gdk_pixel_ops.composite_565 =
|
||||
_gdk_pixel_ops_composite_565_mmx;
|
||||
|
||||
#ifdef HAVE_GDK_PIXELOPS_X86_3DNOW
|
||||
if (__get_cpuid (0x80000001U, &eax, &ebx, &ecx, &edx) &&
|
||||
(edx & bit_3DNOW) != 0)
|
||||
{
|
||||
_gdk_pixel_ops.composite_0888 =
|
||||
_gdk_pixel_ops_composite_0888_3dnow;
|
||||
_gdk_pixel_ops.composite_565 =
|
||||
_gdk_pixel_ops_composite_565_3dnow;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue