wuffs_pixel_swizzler_bgra_premul_y_src/clang9  1.94GB/s ± 1%  12.08GB/s ± 0%  +521.63%  (p=0.008 n=5+5)
wuffs_pixel_swizzler_bgra_premul_y_src/gcc10   2.92GB/s ± 0%  16.00GB/s ± 0%  +448.86%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2021-01-13 15:22:15 +11:00
1 parent f171c06c4a
commit 79b39e14bf
5 files changed
+270 -31

No files matched your search

+121 -6
View File
@@ -48,7 +48,7 @@
extern "C" {
#endif
// ---------------- Fundamentals
// ---------------- Version
// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/,
// as a uint64_t. The major number is the high 32 bits. The minor number is the
@@ -74,17 +74,77 @@ extern "C" {
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0
#define WUFFS_VERSION_STRING "0.0.0+0.00000000"
// ---------------- Configuration
// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU
// architecture, such as SSE SIMD for the x86 CPU family.
#if defined(WUFFS_CONFIG__AVOID_CPU_ARCH)
// No-op.
#else
#if defined(__GNUC__) && defined(__x86_64__)
#include <cpuid.h>
#include <x86intrin.h>
#define WUFFS_BASE__CPU_ARCH__X86_64
#endif // defined(__GNUC__) && defined(__x86_64__)
#endif // defined(WUFFS_CONFIG__AVOID_CPU_ARCH)
// --------
// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have
// static storage. The motivation is discussed in the "ALLOW STATIC
// IMPLEMENTATION" section of
// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt
#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS
#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS)
#define WUFFS_BASE__MAYBE_STATIC static
#else
#define WUFFS_BASE__MAYBE_STATIC
#endif
#endif // defined(WUFFS_CONFIG__STATIC_FUNCTIONS)
// --------
// ---------------- CPU Architecture
// WUFFS_BASE__CPU_ARCH__X86_64__ETC are bits returned by
// wuffs_base__cpu_arch__x86_64__capabilities.
// - "SSE128" means all of SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 and POPCNT.
// - "AVX256" means all of AVX and AVX2.
// - "AVX512ETC" is reserved, pending need. Note that AVX-512 consists of
// multiple extensions that may be implemented independently.
#define WUFFS_BASE__CPU_ARCH__X86_64__SSE128 0x01
#define WUFFS_BASE__CPU_ARCH__X86_64__AVX256 0x02
static inline uint32_t //
wuffs_base__cpu_arch__x86_64__capabilities() {
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
uint32_t ret = 0;
unsigned int eax1 = 0;
unsigned int ebx1 = 0;
unsigned int ecx1 = 0;
unsigned int edx1 = 0;
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {
const unsigned int sse128_ecx1 = bit_SSE4_2 | bit_POPCNT;
if ((ecx1 & sse128_ecx1) == sse128_ecx1) {
ret |= WUFFS_BASE__CPU_ARCH__X86_64__SSE128;
}
}
unsigned int eax7 = 0;
unsigned int ebx7 = 0;
unsigned int ecx7 = 0;
unsigned int edx7 = 0;
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7)) {
const unsigned int avx256_ebx7 = bit_AVX2;
if ((ebx7 & avx256_ebx7) == avx256_ebx7) {
ret |= WUFFS_BASE__CPU_ARCH__X86_64__AVX256;
}
}
return ret;
#else
return 0;
#endif // defined( WUFFS_BASE__CPU_ARCH__X86_64)
}
// ---------------- Fundamentals
// Wuffs assumes that:
// - converting a uint32_t to a size_t will never overflow.
@@ -15952,6 +16012,57 @@ wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over(
return len;
}
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
#if defined(__GNUC__)
__attribute__((target("sse4.2")))
#endif
static uint64_t //
wuffs_base__pixel_swizzler__xxxx__y__sse128(uint8_t* dst_ptr,
size_t dst_len,
uint8_t* dst_palette_ptr,
size_t dst_palette_len,
const uint8_t* src_ptr,
size_t src_len) {
size_t dst_len4 = dst_len / 4;
size_t len = (dst_len4 < src_len) ? dst_len4 : src_len;
uint8_t* d = dst_ptr;
const uint8_t* s = src_ptr;
size_t n = len;
__m128i shuffle = _mm_set_epi8(0x03, 0x03, 0x03, 0x03, //
0x02, 0x02, 0x02, 0x02, //
0x01, 0x01, 0x01, 0x01, //
0x00, 0x00, 0x00, 0x00);
__m128i or = _mm_set_epi8(0xFF, 0x00, 0x00, 0x00, //
0xFF, 0x00, 0x00, 0x00, //
0xFF, 0x00, 0x00, 0x00, //
0xFF, 0x00, 0x00, 0x00);
while (n >= 4) {
__m128i x;
x = _mm_cvtsi32_si128(wuffs_base__load_u32le__no_bounds_check(s));
x = _mm_shuffle_epi8(x, shuffle);
x = _mm_or_si128(x, or);
_mm_storeu_si128((void*)d, x);
s += 4 * 1;
d += 4 * 4;
n -= 4;
}
while (n >= 1) {
wuffs_base__store_u32le__no_bounds_check(
d + (0 * 4), 0xFF000000 | (0x010101 * (uint32_t)s[0]));
s += 1 * 1;
d += 1 * 4;
n -= 1;
}
return len;
}
#endif
static uint64_t //
wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr,
size_t dst_len,
@@ -15965,8 +16076,6 @@ wuffs_base__pixel_swizzler__xxxx__y(uint8_t* dst_ptr,
const uint8_t* s = src_ptr;
size_t n = len;
// TODO: unroll.
while (n >= 1) {
wuffs_base__store_u32le__no_bounds_check(
d + (0 * 4), 0xFF000000 | (0x010101 * (uint32_t)s[0]));
@@ -16039,6 +16148,12 @@ wuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,
case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:
case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:
case WUFFS_BASE__PIXEL_FORMAT__RGBX:
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
if (wuffs_base__cpu_arch__x86_64__capabilities() &
WUFFS_BASE__CPU_ARCH__X86_64__SSE128) {
return wuffs_base__pixel_swizzler__xxxx__y__sse128;
}
#endif
return wuffs_base__pixel_swizzler__xxxx__y;
}
return NULL;