Files
SDL/test/testautomation_intrinsics.c
Anonymous Maarten 3472dc11d6 Fix uses of undefined macro identifiers (-Wundef)
* Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINDOWS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_ANDROID

* Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DUMMY

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_COCOA

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_UIKIT

* Fix -Wundef warnings due to use of unguarded SDL_TIMERS_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_EVENTS_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_TIMER_DUMMY

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_SENSOR_DISABLED

* Fix -Wundef warnings due to use of unguarded __ANDROID__

* Fix -Wundef warnings due to use of unguarded __IOS__

* Fix -Wundef warnings due to use of unguarded EMULATE_CAS

* Fix -Wundef warnings due to use of unguarded SDL_ATOMIC_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_THREADS_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_SNDIO

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_NETBSD

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_WASAPI

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DSOUND

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_HAIKU

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_COREAUDIO

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_AAUDIO

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OPENSLES

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ANDROID

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PS2

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PSP

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_VITA

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_N3DS

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_EMSCRIPTEN

* Fix -Wundef warnings due to use of unguarded SDL_NEON_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_ALTIVEC_BLITTERS

* Fix -Wundef warnings due to use of unguarded __VITA__

* Fix -Wundef warnings due to use of unguarded __3DS__

* Fix -Wundef warnings due to use of unguarded SDL_DYNAPI_PROC_NO_VARARGS

* Fix -Wundef warnings due to use of unguarded __APPLE__

* Fix -Wundef warnings due to use of unguarded __WINRT__

* Fix -Wundef warnings due to use of unguarded SDL_HIDAPI_DISABLED

* Fix -Wundef warnings due to use of unguarded __TVOS__

* Fix -Wundef warnings due to use of unguarded HAVE_DRIVER_BACKEND

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_XINPUT

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_WGI

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DINPUT

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_MFI

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_EMSCRIPTEN

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PS2

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PSP

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VITA

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_N3DS

* Fix -Wundef warnings due to use of unguarded __MACOS__

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINRT

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RPI

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR_OGL

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D11

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D12

* Fix -Wundef warnings due to use of unguarded SDL_RENDER_DISABLED

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_METAL

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PS2

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PSP

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_VITA_GXM

* Fix -Wundef warnings due to use of unguarded SDL_ARM_SIMD_BLITTERS

* Fix -Wundef warnings due to use of unguarded SDL_ARM_NEON_BLITTERS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_HAIKU

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PS2

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PSP

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VITA

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_N3DS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_KMSDRM

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_EMSCRIPTEN

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_NGAGE

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_METAL

* Fix -Wundef warnings due to use of unguarded SDL_LSX_INTRINSICS

* Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_NP_H

* Fix -Wundef warnings due to use of unguarded __RISCOS__

* Fix -Wundef warnings due to use of unguarded FAKE_RECURSIVE_MUTEX

* Fix -Wundef warnings due to use of unguarded USE_POSIX_SPAWN

* textureData is only needed when SDL is built with YUV support

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ALSA

* Fix -Wundef warnings due to use of unguarded SDL_SSE3_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_SSE4_2_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_SSE4_1_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_AVX512F_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_SSE2_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_AVX_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_AVX2_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_SSE_INTRINSICS

* Fix -Wundef warnings due to use of unguarded SDL_MMX_INTRINSICS

* Fix -Wundef warnings due to use of unguarded HAVE_CLOCK_GETTIME

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DUMMY

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_DUMMY

* Fix -Wundef warnings due to use of unguarded HAVE_GCC_ATOMICS

* Fix -Wundef warnings due to use of unguarded HAVE_GCC_SYNC_LOCK_TEST_AND_SET

* Fix -Wundef warnings due to use of unguarded SDL_USE_LIBDBUS

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_JACK

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VIRTUAL

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_LINUX

* Fix -Wundef warnings due to use of unguarded HAVE_LIBC

* Fix -Wundef warnings due to disabling SDL_LIBC

* Fix -Wundef warnings due to use of unguarded HAVE_PLATFORM_BACKEND

* Fix -Wundef warnings due to use of unguarded DEBUG

* Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H

* Fix -Werror=unused-variable when building with SDL_LIBC=OFF

* Fix -Wundef warnings due to use of unguqrded SDL_USE_LIBUDEV

* Use SDL alloc functions in libusb/hid.c

* Fix -Wundef warnings due to use of unguarded HAVE_LIBUDEV_H

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_OFFSCREEN

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_GLX

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL_ES2

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OSS

* Remove SDL_AUDIO_DRIVER_SUNAUDIO reference since it is never set

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PIPEWIRE

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PULSEAUDIO

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XCURSOR

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XDBE

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XFIXES

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XINPUT2

* Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH

* Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XRANDR

* Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XSHAPE

* Don't call XShape functions when XShape is diabled

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND

* Fix -Wundef warnings due to use of unuarded SDL_VIDEO_DRIVER_X11

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL

* Disable array when compiled with SDL_EVENTS=OFF

* Fix -Wundef warnings due to use of unguarded SDL_INPUT_LINUXEV

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_WINDOWS

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_PS2

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_PSP

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_VITA

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_N3DS

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_STDCPP

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_NGAGE

* Fix -Wundef warnings due to use of unguarded __WINDOWS__

* Fix -Wundef warnings due to use of unguarded __WINGDK__

* Fix -Wundef warnings due to use of unguarded __ANDROID__

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_GENERIC_COND_SUFFIX

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PIB

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR

* Fix -Wundef warnings due to use of unguarded SDL_FILE_DISABLED

* Fix -Wundef warnings due to use of unguarded __XBOXONE__

* Fix -Wundef warnings due to use of unguarded __XBOXSERIES__

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_WGL

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_QNX

* Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_QNX

* Fix -Wundef warnings due to use of unguarded DEBUG_RAZOR

* Fix -Wundef warnings due to use of unguarded WINAPI_FAMILY_PHONE_APP

* Fix -Wundef warnings due to use of unguarded SDL_MAC_NO_SANDBOX

* Fix -Wundef warnings due to use of unguarded __(IPHONE|APPLETV|MAC)_OS_VERSION_MAX_ALLOWED

* Fix C4090 warning ('function': different 'const' qualifiers)

* ci: use -isystem for include dirs of pspdev toolchain

* cmake: add -Wundef option

* Fix remaining -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN and SDL_VIDEO_METAL

* Fix -Wundef warnings due to use of unguarded __MACOS__

* DEBUG_CONVERT is guaranteed to be defined in src/audio/SDL_audiocvt.c

* Fix -Wundef warnings due to use of unguarded HAVE_NANOSLEEP

* Fix -Wundef warnings due to use of unguarded HAVE_DXGI_H

* Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H

* fix SDL_VIDEO_DRIVER_WAYLAND

* fix SDL_VIDEO_DRIVER_X11

* Fix -Wundef warnings due to use of unguarded HAVE_MMDEVICEAPI_H

* Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SETNAME_NP

* Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SET_NAME_NP

* Fix -Wundef warnings due to use of unguarded HAVE_SETJMP

* Fix -Wundef warnings due to use of unguarded HAVE_SIGNAL_H

* Fix -Wundef warnings due to use of unguarded HAVE_TPCSHRD_H

* Fix -Wundef warnings due to use of unguarded MACOSX_COREAUDIO

* Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DINPUT

* Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_IOKIT

* Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_XINPUT

* Fix -Wundef warnings due to use of unguarded SDL_IPHONE_KEYBOARD

* Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_RAWINPUT

* Fix -Wundef warnings due to use of unguarded SDL_POWER_ANDROID

* Fix -Wundef warnings due to use of unguarded SDL_POWER_EMSCRIPTEN

* Fix -Wundef warnings due to use of unguarded SDL_POWER_HAIKU

* Fix -Wundef warnings due to use of unguarded SDL_POWER_LINUX

* Fix -Wundef warnings due to use of unguarded SDL_POWER_MACOSX

* Fix -Wundef warnings due to use of unguarded SDL_POWER_PSP

* Fix -Wundef warnings due to use of unguarded SDL_POWER_UIKIT

* Fix -Wundef warnings due to use of unguarded SDL_POWER_VITA

* Fix -Wundef warnings due to use of unguarded SDL_POWER_WINDOWS

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX

* Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE_VDK

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_CGL

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL

* Fix -Wundef warnings due to use of unguarded __MACOS__

* Fix -Wundef warnings due to use of unguarded __OpenBSD__

* Fix -Wundef warnings due to use of unguarded __FreeBSD__

* Fix -Wundef warnings due to use of unguarded __MWERKS__

* Fix -Wundef warnings due to use of unguarded __WIN32__

* Fix -Wundef warnings due to use of unguarded SDL_IPHONE_LAUNCHSCREEN

* Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2

* Remove unused HAVE_CONST, HAVE_INLINE and HAVE_VOLATILE

* Revert "Use SDL alloc functions in libusb/hid.c"

This reverts commit 847c64b00d.

* Handle FAKE_RECURSIVE_MUTEX in similar way as SDL2

* Don't use defined in macro
2023-03-29 21:49:01 +00:00

689 lines
22 KiB
C

/**
* Intrinsics test suite
*/
/* Disable intrinsics that are unsupported by the current compiler */
#include <build_config/SDL_build_config.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_intrin.h>
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
// FIXME: missing tests for loongarch lsx/lasx
// FIXME: missing tests for powerpc altivec
/* ================= Test Case Implementation ================== */
/* Helper functions */
static int allocate_random_int_arrays(Sint32 **dest, Sint32 **a, Sint32 **b, size_t *size) {
size_t i;
*size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
*dest = SDL_malloc(sizeof(Sint32) * *size);
*a = SDL_malloc(sizeof(Sint32) * *size);
*b = SDL_malloc(sizeof(Sint32) * *size);
if (!*dest || !*a || !*b) {
SDLTest_AssertCheck(SDL_FALSE, "SDL_malloc failed");
return -1;
}
for (i = 0; i < *size; ++i) {
(*a)[i] = SDLTest_RandomSint32();
(*b)[i] = SDLTest_RandomSint32();
}
return 0;
}
static int allocate_random_float_arrays(float **dest, float **a, float **b, size_t *size) {
size_t i;
*size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
*dest = SDL_malloc(sizeof(float) * *size);
*a = SDL_malloc(sizeof(float) * *size);
*b = SDL_malloc(sizeof(float) * *size);
if (!*dest || !*a || !*b) {
SDLTest_AssertCheck(SDL_FALSE, "SDL_malloc failed");
return -1;
}
for (i = 0; i < *size; ++i) {
(*a)[i] = SDLTest_RandomUnitFloat();
(*b)[i] = SDLTest_RandomUnitFloat();
}
return 0;
}
static int allocate_random_double_arrays(double **dest, double **a, double **b, size_t *size) {
size_t i;
*size = (size_t)SDLTest_RandomIntegerInRange(127, 999);
*dest = SDL_malloc(sizeof(double) * *size);
*a = SDL_malloc(sizeof(double) * *size);
*b = SDL_malloc(sizeof(double) * *size);
if (!*dest || !*a || !*b) {
SDLTest_AssertCheck(SDL_FALSE, "SDL_malloc failed");
return -1;
}
for (i = 0; i < *size; ++i) {
(*a)[i] = SDLTest_RandomUnitDouble();
(*b)[i] = SDLTest_RandomUnitDouble();
}
return 0;
}
static void free_arrays(void *dest, void *a, void *b) {
SDL_free(dest);
SDL_free(a);
SDL_free(b);
}
/**
* \brief Verify element-wise addition of 2 int arrays.
*/
static void verify_ints_addition(const Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size, const char *desc) {
size_t i;
int all_good = 1;
for (i = 0; i < size; ++i) {
Sint32 expected = a[i] + b[i];
if (dest[i] != expected) {
SDLTest_AssertCheck(SDL_FALSE, "%"SDL_PRIs32" + %"SDL_PRIs32" = %"SDL_PRIs32", expected %"SDL_PRIs32" ([%"SDL_PRIu32"/%"SDL_PRIu32"] %s)",
a[i], b[i], dest[i], expected, (Uint32)i, (Uint32)size, desc);
all_good = 0;
}
}
if (all_good) {
SDLTest_AssertCheck(SDL_TRUE, "All int additions were correct (%s)", desc);
}
}
/**
* \brief Verify element-wise multiplication of 2 int arrays.
*/
static void verify_ints_multiplication(const Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size, const char *desc) {
size_t i;
int all_good = 1;
for (i = 0; i < size; ++i) {
Sint32 expected = a[i] * b[i];
if (dest[i] != expected) {
SDLTest_AssertCheck(SDL_FALSE, "%"SDL_PRIs32" * %"SDL_PRIs32" = %"SDL_PRIs32", expected %"SDL_PRIs32" ([%"SDL_PRIu32"/%"SDL_PRIu32"] %s)",
a[i], b[i], dest[i], expected, (Uint32)i, (Uint32)size, desc);
all_good = 0;
}
}
if (all_good) {
SDLTest_AssertCheck(SDL_TRUE, "All int multiplication were correct (%s)", desc);
}
}
/**
* \brief Verify element-wise addition of 2 float arrays.
*/
static void verify_floats_addition(const float *dest, const float *a, const float *b, size_t size, const char *desc) {
size_t i;
int all_good = 1;
for (i = 0; i < size; ++i) {
float expected = a[i] + b[i];
float abs_error = SDL_fabsf(dest[i] - expected);
if (abs_error > 1.0e-5f) {
SDLTest_AssertCheck(SDL_FALSE, "%g + %g = %g, expected %g (error = %g) ([%"SDL_PRIu32"/%"SDL_PRIu32"] %s)",
a[i], b[i], dest[i], expected, abs_error, (Uint32) i, (Uint32) size, desc);
all_good = 0;
}
}
if (all_good) {
SDLTest_AssertCheck(SDL_TRUE, "All float additions were correct (%s)", desc);
}
}
/**
* \brief Verify element-wise addition of 2 double arrays.
*/
static void verify_doubles_addition(const double *dest, const double *a, const double *b, size_t size, const char *desc) {
size_t i;
int all_good = 1;
for (i = 0; i < size; ++i) {
double expected = a[i] + b[i];
double abs_error = SDL_fabs(dest[i] - expected);
if (abs_error > 1.0e-5) {
SDLTest_AssertCheck(abs_error < 1.0e-5f, "%g + %g = %g, expected %g (error = %g) ([%"SDL_PRIu32"/%"SDL_PRIu32"] %s)",
a[i], b[i], dest[i], expected, abs_error, (Uint32) i, (Uint32) size, desc);
all_good = SDL_FALSE;
}
}
if (all_good) {
SDLTest_AssertCheck(SDL_TRUE, "All double additions were correct (%s)", desc);
}
}
/* Intrinsic kernels */
static void kernel_ints_add_cpu(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size; --size, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
static void kernel_ints_mul_cpu(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size; --size, ++dest, ++a, ++b) {
*dest = *a * *b;
}
}
static void kernel_floats_add_cpu(float *dest, const float *a, const float *b, size_t size) {
for (; size; --size, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
static void kernel_doubles_add_cpu(double *dest, const double *a, const double *b, size_t size) {
for (; size; --size, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
#if defined(SDL_MMX_INTRINSICS)
SDL_TARGETING("mmx") static void kernel_ints_add_mmx(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size >= 2; size -= 2, dest += 2, a += 2, b += 2) {
*(__m64*)dest = _mm_add_pi32(*(__m64*)a, *(__m64*)b);
}
if (size) {
*dest = *a + *b;
}
_mm_empty();
}
#endif
#if defined(SDL_SSE_INTRINSICS)
SDL_TARGETING("sse") static void kernel_floats_add_sse(float *dest, const float *a, const float *b, size_t size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
_mm_storeu_ps(dest, _mm_add_ps(_mm_loadu_ps(a), _mm_loadu_ps (b)));
}
for (; size; size--, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
#endif
#if defined(SDL_SSE2_INTRINSICS)
SDL_TARGETING("sse2") static void kernel_doubles_add_sse2(double *dest, const double *a, const double *b, size_t size) {
for (; size >= 2; size -= 2, dest += 2, a += 2, b += 2) {
_mm_storeu_pd(dest, _mm_add_pd(_mm_loadu_pd(a), _mm_loadu_pd(b)));
}
if (size) {
*dest = *a + *b;
}
}
#endif
#if defined(SDL_SSE3_INTRINSICS)
SDL_TARGETING("sse3") static void kernel_ints_add_sse3(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
_mm_storeu_si128((__m128i*)dest, _mm_add_epi32(_mm_lddqu_si128((__m128i*)a), _mm_lddqu_si128((__m128i*)b)));
}
for (;size; --size, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
#endif
#if defined(SDL_SSE4_1_INTRINSICS)
SDL_TARGETING("sse4.1") static void kernel_ints_mul_sse4_1(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
_mm_storeu_si128((__m128i*)dest, _mm_mullo_epi32(_mm_lddqu_si128((__m128i*)a), _mm_lddqu_si128((__m128i*)b)));
}
for (;size; --size, ++dest, ++a, ++b) {
*dest = *a * *b;
}
}
#endif
#if defined(SDL_SSE4_2_INTRINSICS)
SDL_TARGETING("sse4.2") static Uint32 calculate_crc32c_sse4_2(const char *text) {
Uint32 crc32c = ~0;
size_t len = SDL_strlen(text);
#if defined(__x86_64__) || defined(_M_X64)
for (; len >= 8; len -= 8, text += 8) {
crc32c = (Uint32)_mm_crc32_u64(crc32c, *(Sint64*)text);
}
if (len >= 4) {
crc32c = (Uint32)_mm_crc32_u32(crc32c, *(Sint32*)text);
len -= 4;
text += 4;
}
#else
for (; len >= 4; len -= 4, text += 4) {
crc32c = (Uint32)_mm_crc32_u32(crc32c, *(Sint32*)text);
}
#endif
if (len >= 2) {
crc32c = (Uint32)_mm_crc32_u16(crc32c, *(Sint16*)text);
len -= 2;
text += 2;
}
if (len) {
crc32c = (Uint32)_mm_crc32_u8(crc32c, *text);
}
return ~crc32c;
}
#endif
#if defined(SDL_AVX_INTRINSICS)
SDL_TARGETING("avx") static void kernel_floats_add_avx(float *dest, const float *a, const float *b, size_t size) {
for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
_mm256_storeu_ps(dest, _mm256_add_ps(_mm256_loadu_ps(a), _mm256_loadu_ps(b)));
}
for (; size; size--, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
#endif
#if defined(SDL_AVX2_INTRINSICS)
SDL_TARGETING("avx2") static void kernel_ints_add_avx2(Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size) {
for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
_mm256_storeu_si256((__m256i*)dest, _mm256_add_epi32(_mm256_loadu_si256((__m256i*)a), _mm256_loadu_si256((__m256i*)b)));
}
for (; size; size--, ++dest, ++a, ++b) {
*dest = *a + *b;
}
}
#endif
#if defined(SDL_AVX512F_INTRINSICS)
SDL_TARGETING("avx512f") static void kernel_floats_add_avx512f(float *dest, const float *a, const float *b, size_t size) {
for (; size >= 16; size -= 16, dest += 16, a += 16, b += 16) {
_mm512_storeu_ps(dest, _mm512_add_ps(_mm512_loadu_ps(a), _mm512_loadu_ps(b)));
}
for (; size; --size) {
*dest++ = *a++ + *b++;
}
}
#endif
/* Test case functions */
static int intrinsics_selftest(void *arg)
{
{
size_t size;
Sint32 *dest, *a, *b;
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_mul_cpu(dest, a, b, size);
verify_ints_multiplication(dest, a, b, size, "CPU");
free_arrays(dest, a, b);
}
{
size_t size;
Sint32 *dest, *a, *b;
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_add_cpu(dest, a, b, size);
verify_ints_addition(dest, a, b, size, "CPU");
free_arrays(dest, a, b);
}
{
size_t size;
float *dest, *a, *b;
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_floats_add_cpu(dest, a, b, size);
verify_floats_addition(dest, a, b, size, "CPU");
free_arrays(dest, a, b);
}
{
size_t size;
double *dest, *a, *b;
if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_doubles_add_cpu(dest, a, b, size);
verify_doubles_addition(dest, a, b, size, "CPU");
free_arrays(dest, a, b);
}
return TEST_COMPLETED;
}
static int intrinsics_testMMX(void *arg)
{
if (SDL_HasMMX()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has MMX support.");
#if defined(SDL_MMX_INTRINSICS)
{
size_t size;
Sint32 *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses MMX intrinsics.");
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_add_mmx(dest, a, b, size);
verify_ints_addition(dest, a, b, size, "MMX");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use MMX intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO MMX support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testSSE(void *arg)
{
if (SDL_HasSSE()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has SSE support.");
#if defined(SDL_SSE_INTRINSICS)
{
size_t size;
float *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses SSE intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_floats_add_sse(dest, a, b, size);
verify_floats_addition(dest, a, b, size, "SSE");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use SSE intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO SSE support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testSSE2(void *arg)
{
if (SDL_HasSSE2()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has SSE2 support.");
#if defined(SDL_SSE2_INTRINSICS)
{
size_t size;
double *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses SSE2 intrinsics.");
if (allocate_random_double_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_doubles_add_sse2(dest, a, b, size);
verify_doubles_addition(dest, a, b, size, "SSE2");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use SSE2 intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO SSE2 support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testSSE3(void *arg)
{
if (SDL_HasSSE3()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has SSE3 support.");
#if defined(SDL_SSE3_INTRINSICS)
{
size_t size;
Sint32 *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses SSE3 intrinsics.");
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_add_sse3(dest, a, b, size);
verify_ints_addition(dest, a, b, size, "SSE3");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use SSE3 intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO SSE3 support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testSSE4_1(void *arg)
{
if (SDL_HasSSE41()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has SSE4.1 support.");
#if defined(SDL_SSE4_1_INTRINSICS)
{
size_t size;
Sint32 *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses SSE4.1 intrinsics.");
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_mul_sse4_1(dest, a, b, size);
verify_ints_multiplication(dest, a, b, size, "SSE4.1");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use SSE4.1 intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO SSE4.1 support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testSSE4_2(void *arg)
{
if (SDL_HasSSE42()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has SSE4.2 support.");
#if defined(SDL_SSE4_2_INTRINSICS)
{
struct {
const char *input;
Uint32 crc32c;
} references[] = {
{"", 0x00000000},
{"Hello world", 0x72b51f78},
{"Simple DirectMedia Layer", 0x56f85341, },
};
size_t i;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses SSE4.2 intrinsics.");
for (i = 0; i < SDL_arraysize(references); ++i) {
Uint32 actual = calculate_crc32c_sse4_2(references[i].input);
SDLTest_AssertCheck(actual == references[i].crc32c, "CRC32-C(\"%s\")=0x%08x, got 0x%08x",
references[i].input, references[i].crc32c, actual);
}
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use SSE4.2 intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO SSE4.2 support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testAVX(void *arg)
{
if (SDL_HasAVX()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has AVX support.");
#if defined(SDL_AVX_INTRINSICS)
{
size_t size;
float *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses AVX intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_floats_add_avx(dest, a, b, size);
verify_floats_addition(dest, a, b, size, "AVX");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use AVX intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO AVX support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testAVX2(void *arg)
{
if (SDL_HasAVX2()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has AVX2 support.");
#if defined(SDL_AVX2_INTRINSICS)
{
size_t size;
Sint32 *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses AVX2 intrinsics.");
if (allocate_random_int_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_ints_add_avx2(dest, a, b, size);
verify_ints_addition(dest, a, b, size, "AVX2");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use AVX2 intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO AVX2 support.");
}
return TEST_SKIPPED;
}
static int intrinsics_testAVX512F(void *arg)
{
if (SDL_HasAVX512F()) {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has AVX512F support.");
#if defined(SDL_AVX512F_INTRINSICS)
{
size_t size;
float *dest, *a, *b;
SDLTest_AssertCheck(SDL_TRUE, "Test executable uses AVX512F intrinsics.");
if (allocate_random_float_arrays(&dest, &a, &b, &size) < 0) {
return TEST_ABORTED;
}
kernel_floats_add_avx512f(dest, a, b, size);
verify_floats_addition(dest, a, b, size, "AVX512F");
free_arrays(dest, a, b);
return TEST_COMPLETED;
}
#else
SDLTest_AssertCheck(SDL_TRUE, "Test executable does NOT use AVX512F intrinsics.");
#endif
} else {
SDLTest_AssertCheck(SDL_TRUE, "CPU of test machine has NO AVX512F support.");
}
return TEST_SKIPPED;
}
/* ================= Test References ================== */
/* Intrinsics test cases */
static const SDLTest_TestCaseReference intrinsicsTest1 = {
(SDLTest_TestCaseFp)intrinsics_selftest, "intrinsics_selftest", "Intrinsics testautomation selftest", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest2 = {
(SDLTest_TestCaseFp)intrinsics_testMMX, "intrinsics_testMMX", "Tests MMX intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest3 = {
(SDLTest_TestCaseFp)intrinsics_testSSE, "intrinsics_testSSE", "Tests SSE intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest4 = {
(SDLTest_TestCaseFp)intrinsics_testSSE2, "intrinsics_testSSE2", "Tests SSE2 intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest5 = {
(SDLTest_TestCaseFp)intrinsics_testSSE3, "intrinsics_testSSE3", "Tests SSE3 intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest6 = {
(SDLTest_TestCaseFp)intrinsics_testSSE4_1, "intrinsics_testSSE4.1", "Tests SSE4.1 intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest7 = {
(SDLTest_TestCaseFp)intrinsics_testSSE4_2, "intrinsics_testSSE4.2", "Tests SSE4.2 intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest8 = {
(SDLTest_TestCaseFp)intrinsics_testAVX, "intrinsics_testAVX", "Tests AVX intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest9 = {
(SDLTest_TestCaseFp)intrinsics_testAVX2, "intrinsics_testAVX2", "Tests AVX2 intrinsics", TEST_ENABLED
};
static const SDLTest_TestCaseReference intrinsicsTest10 = {
(SDLTest_TestCaseFp)intrinsics_testAVX512F, "intrinsics_testAVX512F", "Tests AVX512F intrinsics", TEST_ENABLED
};
/* Sequence of Platform test cases */
static const SDLTest_TestCaseReference *platformTests[] = {
&intrinsicsTest1,
&intrinsicsTest2,
&intrinsicsTest3,
&intrinsicsTest4,
&intrinsicsTest5,
&intrinsicsTest6,
&intrinsicsTest7,
&intrinsicsTest8,
&intrinsicsTest9,
&intrinsicsTest10,
NULL
};
/* Platform test suite (global) */
SDLTest_TestSuiteReference intrinsicsTestSuite = {
"Intrinsics",
NULL,
platformTests,
NULL
};