Replaced SDL_SIMDAlloc(), SDL_SIMDRealloc(), and SDL_SIMDFree() with SDL_aligned_alloc() and SDL_aligned_free()

Fixes https://github.com/libsdl-org/SDL/issues/5641
This commit is contained in:
Sam Lantinga 2023-01-09 17:42:16 -08:00
parent 9597c482fa
commit 2aa9569b3e
13 changed files with 132 additions and 194 deletions

View file

@ -444,6 +444,32 @@ int stdlib_sscanf(void *arg)
#define SIZE_FORMAT "zu"
#endif
/**
* @brief Call to SDL_aligned_alloc
*/
int stdlib_aligned_alloc(void *arg)
{
size_t i, alignment;
void *ptr;
for (i = 0; i < 2*sizeof(void *); ++i) {
SDLTest_AssertPass("Call to SDL_aligned_alloc(%"SIZE_FORMAT")", i);
ptr = SDL_aligned_alloc(i, 1);
if (i < sizeof(void *)) {
alignment = sizeof(void *);
} else {
alignment = i;
}
SDLTest_AssertCheck(ptr != NULL, "Check output, expected non-NULL, got: %p", ptr);
SDLTest_AssertCheck((((size_t)ptr) % alignment) == 0, "Check output, expected aligned pointer, actual offset: %"SIZE_FORMAT, (((size_t)ptr) % alignment));
SDLTest_AssertPass("Filling memory to alignment value");
SDL_memset(ptr, 0xAA, alignment);
SDL_aligned_free(ptr);
}
return TEST_COMPLETED;
}
typedef struct
{
size_t a;
@ -600,19 +626,23 @@ stdlib_overflow(void *arg)
/* Standard C routine test cases */
static const SDLTest_TestCaseReference stdlibTest1 = {
(SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED
stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest2 = {
(SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest3 = {
(SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest4 = {
(SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest5 = {
stdlib_aligned_alloc, "stdlib_aligned_alloc", "Call to SDL_aligned_alloc", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTestOverflow = {
@ -625,6 +655,7 @@ static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest2,
&stdlibTest3,
&stdlibTest4,
&stdlibTest5,
&stdlibTestOverflow,
NULL
};