mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Add WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET
This commit is contained in:
1 parent
073d3e0150
commit
9914f7314d
6 files changed
+83
-65
No files matched your search
@@ -44,10 +44,19 @@
|
||||
|
||||
// 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)
|
||||
#if defined(WUFFS_CONFIG__AVOID_CPU_ARCH) // (#if-chain ref AVOID_CPU_ARCH_0)
|
||||
// No-op.
|
||||
#else // (#if-chain ref AVOID_CPU_ARCH_0)
|
||||
|
||||
// The "defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg) __attribute__((target(arg)))
|
||||
#else
|
||||
#if defined(__GNUC__)
|
||||
#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg)
|
||||
#endif // defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
#if defined(__GNUC__) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
// To simplify Wuffs code, "cpu_arch >= arm_xxx" requires xxx but also
|
||||
// unaligned little-endian load/stores.
|
||||
@@ -73,15 +82,24 @@
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
#if defined(_M_X64)
|
||||
#if defined(__clang__)
|
||||
// No-op. clang-cl (which defines both __clang__ and _MSC_VER) supports
|
||||
// "__attribute__((target(arg)))".
|
||||
#elif !defined(__AVX__)
|
||||
// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time
|
||||
// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not
|
||||
// of individual functions (that can be conditionally selected at runtime).
|
||||
#error "Wuffs with MSVC+X64 needs /arch:AVX or /DWUFFS_CONFIG__AVOID_CPU_ARCH"
|
||||
#endif // defined(__clang__); !defined(__AVX__)
|
||||
#include <intrin.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
#endif // defined(_M_X64)
|
||||
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_CONFIG__AVOID_CPU_ARCH)
|
||||
#endif // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
#endif // (#if-chain ref AVOID_CPU_ARCH_0)
|
||||
|
||||
// --------
|
||||
|
||||
@@ -123,6 +141,8 @@ wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
// - bit_POPCNT = (1 << 23)
|
||||
// - bit_SSE4_2 = (1 << 20)
|
||||
const unsigned int sse42_ecx1 = 0x00900002;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax1 = 0;
|
||||
unsigned int ebx1 = 0;
|
||||
|
||||
@@ -757,9 +757,7 @@ wuffs_base__pixel_swizzler__swap_rgb_bgr(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((target("sse4.2")))
|
||||
#endif
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
@@ -2102,9 +2100,7 @@ wuffs_base__pixel_swizzler__bgrw__bgrx(uint8_t* dst_ptr,
|
||||
}
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((target("sse4.2")))
|
||||
#endif
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__bgrw__rgb__sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
@@ -2545,9 +2541,7 @@ wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over(
|
||||
}
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((target("sse4.2")))
|
||||
#endif
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("sse4.2")
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__xxxx__y__sse42(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
|
||||
Reference in new issue
Block a user