diff --git a/internal/cgen/base/fundamental-public.h b/internal/cgen/base/fundamental-public.h index 4935e8eb..71df64dc 100644 --- a/internal/cgen/base/fundamental-public.h +++ b/internal/cgen/base/fundamental-public.h @@ -85,15 +85,8 @@ #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__) +#if defined(__AVX__) || defined(__clang__) + // We need for the __cpuid function. #include // That's not enough for X64 SIMD, with clang-cl, if we want to use @@ -106,6 +99,18 @@ #include // SSE4.2 #include // AES, PCLMUL #define WUFFS_BASE__CPU_ARCH__X86_64 + +#else // defined(__AVX__) || defined(__clang__) + +// clang-cl (which defines both __clang__ and _MSC_VER) supports +// "__attribute__((target(arg)))". +// +// 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). +#pragma message("Wuffs with MSVC+X64 needs /arch:AVX for best performance") + +#endif // defined(__AVX__) || defined(__clang__) #endif // defined(_M_X64) #endif // (#if-chain ref AVOID_CPU_ARCH_1) diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index fbb663fc..002d99f4 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -55,8 +55,8 @@ const BaseFundamentalPublicH = "" + "fine WUFFS_VERSION_PRE_RELEASE_LABEL \"work.in.progress\"\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0\n#define WUFFS_VERSION_STRING \"0.0.0+0.00000000\"\n\n" + "" + "// ---------------- Configuration\n\n// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU\n// architecture, such as SSE SIMD for the x86 CPU family.\n#if defined(WUFFS_CONFIG__AVOID_CPU_ARCH) // (#if-chain ref AVOID_CPU_ARCH_0)\n// No-op.\n#else // (#if-chain ref AVOID_CPU_ARCH_0)\n\n// The \"defined(__clang__)\" isn't redundant. While vanilla clang defines\n// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.\n#if defined(__GNUC__) || defined(__clang__)\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg) __attribute__((target(arg)))\n#else\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg)\n#endif // defined(__GNUC__) || defined(__clang__)\n\n#if defined(__GNUC__) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n// To simplify Wuffs code, \"cpu_arch >= arm_xxx\" requires xxx but also\n// unaligned little-endian load/stores.\n#if defined(__ARM_FEATURE_UNALIGNED) && defined(__BYTE_ORDER__) && \\\n (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\n// Not all gcc versions define __ARM_ACLE, even if they support crc32" + - "\n// intrinsics. Look for __ARM_FEATURE_CRC32 instead.\n#if defined(__ARM_FEATURE_CRC32)\n#include \n#define WUFFS_BASE__CPU_ARCH__ARM_CRC32\n#endif // defined(__ARM_FEATURE_CRC32)\n#if defined(__ARM_NEON)\n#include \n#define WUFFS_BASE__CPU_ARCH__ARM_NEON\n#endif // defined(__ARM_NEON)\n#endif // defined(__ARM_FEATURE_UNALIGNED) etc\n\n// Similarly, \"cpu_arch >= x86_sse42\" requires SSE4.2 but also PCLMUL and\n// POPCNT. This is checked at runtime via cpuid, not at compile time.\n#if defined(__x86_64__)\n#include \n#include \n#define WUFFS_BASE__CPU_ARCH__X86_64\n#endif // defined(__x86_64__)\n\n#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n#if defined(_M_X64)\n#if defined(__clang__)\n// No-op. clang-cl (which defines both __clang__ and _MSC_VER) supports\n// \"__attribute__((target(arg)))\".\n#elif !defined(__AVX__)\n// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time\n// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not" + - "\n// of individual functions (that can be conditionally selected at runtime).\n#error \"Wuffs with MSVC+X64 needs /arch:AVX or /DWUFFS_CONFIG__AVOID_CPU_ARCH\"\n#endif // defined(__clang__); !defined(__AVX__)\n// We need for the __cpuid function.\n#include \n// That's not enough for X64 SIMD, with clang-cl, if we want to use\n// \"__attribute__((target(arg)))\" without e.g. \"/arch:AVX\".\n//\n// Some web pages suggest that is all you need, as it pulls in\n// the earlier SIMD families like SSE4.2, but that doesn't seem to work in\n// practice, possibly for the same reason that just doesn't work.\n#include // AVX, AVX2, FMA, POPCNT\n#include // SSE4.2\n#include // AES, PCLMUL\n#define WUFFS_BASE__CPU_ARCH__X86_64\n#endif // defined(_M_X64)\n\n#endif // (#if-chain ref AVOID_CPU_ARCH_1)\n#endif // (#if-chain ref AVOID_CPU_ARCH_0)\n\n" + + "\n// intrinsics. Look for __ARM_FEATURE_CRC32 instead.\n#if defined(__ARM_FEATURE_CRC32)\n#include \n#define WUFFS_BASE__CPU_ARCH__ARM_CRC32\n#endif // defined(__ARM_FEATURE_CRC32)\n#if defined(__ARM_NEON)\n#include \n#define WUFFS_BASE__CPU_ARCH__ARM_NEON\n#endif // defined(__ARM_NEON)\n#endif // defined(__ARM_FEATURE_UNALIGNED) etc\n\n// Similarly, \"cpu_arch >= x86_sse42\" requires SSE4.2 but also PCLMUL and\n// POPCNT. This is checked at runtime via cpuid, not at compile time.\n#if defined(__x86_64__)\n#include \n#include \n#define WUFFS_BASE__CPU_ARCH__X86_64\n#endif // defined(__x86_64__)\n\n#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n#if defined(_M_X64)\n#if defined(__AVX__) || defined(__clang__)\n\n// We need for the __cpuid function.\n#include \n// That's not enough for X64 SIMD, with clang-cl, if we want to use\n// \"__attribute__((target(arg)))\" without e.g. \"/arch:AVX\".\n//\n// Some web pages suggest that is all you need, as i" + + "t pulls in\n// the earlier SIMD families like SSE4.2, but that doesn't seem to work in\n// practice, possibly for the same reason that just doesn't work.\n#include // AVX, AVX2, FMA, POPCNT\n#include // SSE4.2\n#include // AES, PCLMUL\n#define WUFFS_BASE__CPU_ARCH__X86_64\n\n#else // defined(__AVX__) || defined(__clang__)\n\n// clang-cl (which defines both __clang__ and _MSC_VER) supports\n// \"__attribute__((target(arg)))\".\n//\n// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time\n// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not\n// of individual functions (that can be conditionally selected at runtime).\n#pragma message(\"Wuffs with MSVC+X64 needs /arch:AVX for best performance\")\n\n#endif // defined(__AVX__) || defined(__clang__)\n#endif // defined(_M_X64)\n\n#endif // (#if-chain ref AVOID_CPU_ARCH_1)\n#endif // (#if-chain ref AVOID_CPU_ARCH_0)\n\n" + "" + "// --------\n\n// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have\n// static storage. The motivation is discussed in the \"ALLOW STATIC\n// IMPLEMENTATION\" section of\n// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt\n#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS)\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif // defined(WUFFS_CONFIG__STATIC_FUNCTIONS)\n\n" + "" + diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index b6988cb9..27cd84fd 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -119,15 +119,8 @@ extern "C" { #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__) +#if defined(__AVX__) || defined(__clang__) + // We need for the __cpuid function. #include // That's not enough for X64 SIMD, with clang-cl, if we want to use @@ -140,6 +133,18 @@ extern "C" { #include // SSE4.2 #include // AES, PCLMUL #define WUFFS_BASE__CPU_ARCH__X86_64 + +#else // defined(__AVX__) || defined(__clang__) + +// clang-cl (which defines both __clang__ and _MSC_VER) supports +// "__attribute__((target(arg)))". +// +// 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). +#pragma message("Wuffs with MSVC+X64 needs /arch:AVX for best performance") + +#endif // defined(__AVX__) || defined(__clang__) #endif // defined(_M_X64) #endif // (#if-chain ref AVOID_CPU_ARCH_1)