mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-28 16:49:43 +00:00
update sdl to 2.26.5
This commit is contained in:
parent
0d981b62cf
commit
0e44e165bd
1260 changed files with 290370 additions and 124892 deletions
57
Engine/lib/sdl/src/stdlib/SDL_crc16.c
Normal file
57
Engine/lib/sdl/src/stdlib/SDL_crc16.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
|
||||
/* Public domain CRC implementation adapted from:
|
||||
http://home.thep.lu.se/~bjorn/crc/crc32_simple.c
|
||||
|
||||
This algorithm is compatible with the 16-bit CRC described here:
|
||||
https://www.lammertbies.nl/comm/info/crc-calculation
|
||||
*/
|
||||
/* NOTE: DO NOT CHANGE THIS ALGORITHM
|
||||
There is code that relies on this in the joystick code
|
||||
*/
|
||||
|
||||
static Uint16 crc16_for_byte(Uint8 r)
|
||||
{
|
||||
Uint16 crc = 0;
|
||||
int i;
|
||||
for (i = 0; i < 8; ++i) {
|
||||
crc = ((crc ^ r) & 1? 0xA001 : 0) ^ crc >> 1;
|
||||
r >>= 1;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
Uint16 SDL_crc16(Uint16 crc, const void *data, size_t len)
|
||||
{
|
||||
/* As an optimization we can precalculate a 256 entry table for each byte */
|
||||
size_t i;
|
||||
for(i = 0; i < len; ++i) {
|
||||
crc = crc16_for_byte((Uint8)crc ^ ((const Uint8*)data)[i]) ^ crc >> 8;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,6 +25,9 @@
|
|||
|
||||
/* Public domain CRC implementation adapted from:
|
||||
http://home.thep.lu.se/~bjorn/crc/crc32_simple.c
|
||||
|
||||
This algorithm is compatible with the 32-bit CRC described here:
|
||||
https://www.lammertbies.nl/comm/info/crc-calculation
|
||||
*/
|
||||
/* NOTE: DO NOT CHANGE THIS ALGORITHM
|
||||
There is code that relies on this in the joystick code
|
||||
|
|
@ -33,7 +36,7 @@
|
|||
static Uint32 crc32_for_byte(Uint32 r)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < 8; ++i) {
|
||||
for (i = 0; i < 8; ++i) {
|
||||
r = (r & 1? 0: (Uint32)0xEDB88320L) ^ r >> 1;
|
||||
}
|
||||
return r ^ (Uint32)0xFF000000L;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#if defined(__WIN32__) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV))
|
||||
#if (defined(__WIN32__) || defined(__WINGDK__)) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV))
|
||||
/* Note this isn't thread-safe! */
|
||||
static char *SDL_envmem = NULL; /* Ugh, memory leak */
|
||||
static size_t SDL_envmemlen = 0;
|
||||
|
|
@ -54,7 +54,7 @@ SDL_setenv(const char *name, const char *value, int overwrite)
|
|||
|
||||
return setenv(name, value, overwrite);
|
||||
}
|
||||
#elif defined(__WIN32__)
|
||||
#elif defined(__WIN32__) || defined(__WINGDK__)
|
||||
int
|
||||
SDL_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
|
|
@ -187,7 +187,7 @@ SDL_getenv(const char *name)
|
|||
|
||||
return getenv(name);
|
||||
}
|
||||
#elif defined(__WIN32__)
|
||||
#elif defined(__WIN32__) || defined(__WINGDK__)
|
||||
char *
|
||||
SDL_getenv(const char *name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -131,7 +131,7 @@ static struct
|
|||
{ "US-ASCII", ENCODING_ASCII },
|
||||
{ "8859-1", ENCODING_LATIN1 },
|
||||
{ "ISO-8859-1", ENCODING_LATIN1 },
|
||||
#if defined(__WIN32__) || defined(__OS2__)
|
||||
#if defined(__WIN32__) || defined(__OS2__) || defined(__GDK__)
|
||||
{ "WCHAR_T", ENCODING_UTF16LE },
|
||||
#else
|
||||
{ "WCHAR_T", ENCODING_UCS4NATIVE },
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -487,7 +487,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K
|
|||
#endif /* WIN32 */
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#define HAVE_MMAP 1
|
||||
#define HAVE_MORECORE 0
|
||||
|
|
@ -1247,7 +1249,7 @@ extern "C"
|
|||
#ifndef LACKS_UNISTD_H
|
||||
#include <unistd.h> /* for sbrk */
|
||||
#else /* LACKS_UNISTD_H */
|
||||
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
|
||||
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
|
||||
extern void *sbrk(ptrdiff_t);
|
||||
#endif /* FreeBSD etc */
|
||||
#endif /* LACKS_UNISTD_H */
|
||||
|
|
@ -2578,7 +2580,7 @@ init_mparams(void)
|
|||
#else /* (FOOTERS && !INSECURE) */
|
||||
s = (size_t) 0x58585858U;
|
||||
#endif /* (FOOTERS && !INSECURE) */
|
||||
ACQUIRE_MAGIC_INIT_LOCK();
|
||||
(void)ACQUIRE_MAGIC_INIT_LOCK();
|
||||
if (mparams.magic == 0) {
|
||||
mparams.magic = s;
|
||||
/* Set up lock for main malloc area */
|
||||
|
|
@ -3015,6 +3017,8 @@ internal_malloc_stats(mstate m)
|
|||
(unsigned long) (maxfp));
|
||||
fprintf(stderr, "system bytes = %10lu\n", (unsigned long) (fp));
|
||||
fprintf(stderr, "in use bytes = %10lu\n", (unsigned long) (used));
|
||||
#else
|
||||
(void)used;
|
||||
#endif
|
||||
|
||||
POSTACTION(m);
|
||||
|
|
@ -3459,7 +3463,9 @@ add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
|
|||
msegmentptr ss = (msegmentptr) (chunk2mem(sp));
|
||||
mchunkptr tnext = chunk_plus_offset(sp, ssize);
|
||||
mchunkptr p = tnext;
|
||||
#ifdef DEBUG
|
||||
int nfences = 0;
|
||||
#endif
|
||||
|
||||
/* reset top to new space */
|
||||
init_top(m, (mchunkptr) tbase, tsize - TOP_FOOT_SIZE);
|
||||
|
|
@ -3477,13 +3483,17 @@ add_segment(mstate m, char *tbase, size_t tsize, flag_t mmapped)
|
|||
for (;;) {
|
||||
mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE);
|
||||
p->head = FENCEPOST_HEAD;
|
||||
#ifdef DEBUG
|
||||
++nfences;
|
||||
#endif
|
||||
if ((char *) (&(nextp->head)) < old_end)
|
||||
p = nextp;
|
||||
else
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
assert(nfences >= 2);
|
||||
#endif
|
||||
|
||||
/* Insert the rest of old top into a bin as an ordinary free chunk */
|
||||
if (csp != old_top) {
|
||||
|
|
@ -5328,6 +5338,25 @@ static struct
|
|||
real_malloc, real_calloc, real_realloc, real_free, { 0 }
|
||||
};
|
||||
|
||||
void SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
|
||||
SDL_calloc_func *calloc_func,
|
||||
SDL_realloc_func *realloc_func,
|
||||
SDL_free_func *free_func)
|
||||
{
|
||||
if (malloc_func) {
|
||||
*malloc_func = real_malloc;
|
||||
}
|
||||
if (calloc_func) {
|
||||
*calloc_func = real_calloc;
|
||||
}
|
||||
if (realloc_func) {
|
||||
*realloc_func = real_realloc;
|
||||
}
|
||||
if (free_func) {
|
||||
*free_func = real_free;
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
|
||||
SDL_calloc_func *calloc_func,
|
||||
SDL_realloc_func *realloc_func,
|
||||
|
|
|
|||
728
Engine/lib/sdl/src/stdlib/SDL_mslibc.c
Normal file
728
Engine/lib/sdl/src/stdlib/SDL_mslibc.c
Normal file
|
|
@ -0,0 +1,728 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains SDL replacements for functions in the C library */
|
||||
|
||||
#if !defined(HAVE_LIBC) && !defined(SDL_STATIC_LIB)
|
||||
|
||||
/* These are some C runtime intrinsics that need to be defined */
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#ifndef __FLTUSED__
|
||||
#define __FLTUSED__
|
||||
__declspec(selectany) int _fltused = 1;
|
||||
#endif
|
||||
|
||||
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
|
||||
Always provide it for the SDL2 DLL, but skip it when building static lib w/ static runtime. */
|
||||
#if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
|
||||
extern void *memcpy(void* dst, const void* src, size_t len);
|
||||
#pragma intrinsic(memcpy)
|
||||
|
||||
#if !defined(__clang__)
|
||||
#pragma function(memcpy)
|
||||
#endif
|
||||
void *
|
||||
memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
return SDL_memcpy(dst, src, len);
|
||||
}
|
||||
|
||||
extern void *memset(void* dst, int c, size_t len);
|
||||
#pragma intrinsic(memset)
|
||||
|
||||
#if !defined(__clang__)
|
||||
#pragma function(memset)
|
||||
#endif
|
||||
void *
|
||||
memset(void *dst, int c, size_t len)
|
||||
{
|
||||
return SDL_memset(dst, c, len);
|
||||
}
|
||||
#endif /* (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT)) */
|
||||
|
||||
#ifdef _M_IX86
|
||||
|
||||
/* Float to long */
|
||||
void
|
||||
__declspec(naked)
|
||||
_ftol()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
sub esp,20h
|
||||
and esp,0FFFFFFF0h
|
||||
fld st(0)
|
||||
fst dword ptr [esp+18h]
|
||||
fistp qword ptr [esp+10h]
|
||||
fild qword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
test eax,eax
|
||||
je integer_QnaN_or_zero
|
||||
arg_is_not_integer_QnaN:
|
||||
fsubp st(1),st
|
||||
test edx,edx
|
||||
jns positive
|
||||
fstp dword ptr [esp]
|
||||
mov ecx,dword ptr [esp]
|
||||
xor ecx,80000000h
|
||||
add ecx,7FFFFFFFh
|
||||
adc eax,0
|
||||
mov edx,dword ptr [esp+14h]
|
||||
adc edx,0
|
||||
jmp localexit
|
||||
positive:
|
||||
fstp dword ptr [esp]
|
||||
mov ecx,dword ptr [esp]
|
||||
add ecx,7FFFFFFFh
|
||||
sbb eax,0
|
||||
mov edx,dword ptr [esp+14h]
|
||||
sbb edx,0
|
||||
jmp localexit
|
||||
integer_QnaN_or_zero:
|
||||
mov edx,dword ptr [esp+14h]
|
||||
test edx,7FFFFFFFh
|
||||
jne arg_is_not_integer_QnaN
|
||||
fstp dword ptr [esp+18h]
|
||||
fstp dword ptr [esp+18h]
|
||||
localexit:
|
||||
leave
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
_ftol2_sse()
|
||||
{
|
||||
_ftol();
|
||||
}
|
||||
|
||||
void
|
||||
_ftol2()
|
||||
{
|
||||
_ftol();
|
||||
}
|
||||
|
||||
/* 64-bit math operators for 32-bit systems */
|
||||
void
|
||||
__declspec(naked)
|
||||
_allmul()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
mov eax, dword ptr[esp+8]
|
||||
mov ecx, dword ptr[esp+10h]
|
||||
or ecx, eax
|
||||
mov ecx, dword ptr[esp+0Ch]
|
||||
jne hard
|
||||
mov eax, dword ptr[esp+4]
|
||||
mul ecx
|
||||
ret 10h
|
||||
hard:
|
||||
push ebx
|
||||
mul ecx
|
||||
mov ebx, eax
|
||||
mov eax, dword ptr[esp+8]
|
||||
mul dword ptr[esp+14h]
|
||||
add ebx, eax
|
||||
mov eax, dword ptr[esp+8]
|
||||
mul ecx
|
||||
add edx, ebx
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_alldiv()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
xor edi,edi
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+10h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+14h],eax
|
||||
mov dword ptr [esp+10h],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+1Ch]
|
||||
or eax,eax
|
||||
jge L2
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+18h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+1Ch],eax
|
||||
mov dword ptr [esp+18h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+14h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
div ecx
|
||||
mov edx,ebx
|
||||
jmp L4
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov edx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+1Ch]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+18h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+14h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+10h]
|
||||
jbe L7
|
||||
L6:
|
||||
dec esi
|
||||
L7:
|
||||
xor edx,edx
|
||||
mov eax,esi
|
||||
L4:
|
||||
dec edi
|
||||
jne L8
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aulldiv()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
push esi
|
||||
mov eax,dword ptr [esp+18h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
div ecx
|
||||
mov edx,ebx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+14h]
|
||||
mov edx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+18h]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+14h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+10h]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+0Ch]
|
||||
jbe L5
|
||||
L4:
|
||||
dec esi
|
||||
L5:
|
||||
xor edx,edx
|
||||
mov eax,esi
|
||||
L2:
|
||||
pop esi
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allrem()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
push edi
|
||||
xor edi,edi
|
||||
mov eax,dword ptr [esp+10h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+10h],eax
|
||||
mov dword ptr [esp+0Ch],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+18h]
|
||||
or eax,eax
|
||||
jge L2
|
||||
mov edx,dword ptr [esp+14h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+18h],eax
|
||||
mov dword ptr [esp+14h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
div ecx
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
dec edi
|
||||
jns L4
|
||||
jmp L8
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov edx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov ecx,eax
|
||||
mul dword ptr [esp+18h]
|
||||
xchg eax,ecx
|
||||
mul dword ptr [esp+14h]
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+10h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+0Ch]
|
||||
jbe L7
|
||||
L6:
|
||||
sub eax,dword ptr [esp+14h]
|
||||
sbb edx,dword ptr [esp+18h]
|
||||
L7:
|
||||
sub eax,dword ptr [esp+0Ch]
|
||||
sbb edx,dword ptr [esp+10h]
|
||||
dec edi
|
||||
jns L8
|
||||
L4:
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop edi
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aullrem()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov eax,dword ptr [esp+8]
|
||||
div ecx
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
mov eax,dword ptr [esp+8]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov ecx,eax
|
||||
mul dword ptr [esp+14h]
|
||||
xchg eax,ecx
|
||||
mul dword ptr [esp+10h]
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+0Ch]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+8]
|
||||
jbe L5
|
||||
L4:
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
L5:
|
||||
sub eax,dword ptr [esp+8]
|
||||
sbb edx,dword ptr [esp+0Ch]
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L2:
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_alldvrm()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push edi
|
||||
push esi
|
||||
push ebp
|
||||
xor edi,edi
|
||||
xor ebp,ebp
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
inc ebp
|
||||
mov edx,dword ptr [esp+10h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+14h],eax
|
||||
mov dword ptr [esp+10h],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+1Ch]
|
||||
or eax,eax
|
||||
jge L2
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+18h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+1Ch],eax
|
||||
mov dword ptr [esp+18h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+14h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mov eax,ebx
|
||||
mul dword ptr [esp+18h]
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
mul dword ptr [esp+18h]
|
||||
add edx,ecx
|
||||
jmp L4
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov edx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+1Ch]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+18h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+14h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+10h]
|
||||
jbe L7
|
||||
L6:
|
||||
dec esi
|
||||
sub eax,dword ptr [esp+18h]
|
||||
sbb edx,dword ptr [esp+1Ch]
|
||||
L7:
|
||||
xor ebx,ebx
|
||||
L4:
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
dec ebp
|
||||
jns L9
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L9:
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
dec edi
|
||||
jne L8
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop ebp
|
||||
pop esi
|
||||
pop edi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aulldvrm()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push esi
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+8]
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mov eax,ebx
|
||||
mul dword ptr [esp+10h]
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
mul dword ptr [esp+10h]
|
||||
add edx,ecx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
mov eax,dword ptr [esp+8]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+14h]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+0Ch]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+8]
|
||||
jbe L5
|
||||
L4:
|
||||
dec esi
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
L5:
|
||||
xor ebx,ebx
|
||||
L2:
|
||||
sub eax,dword ptr [esp+8]
|
||||
sbb edx,dword ptr [esp+0Ch]
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
pop esi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allshl()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,40h
|
||||
jae RETZERO
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shld edx,eax,cl
|
||||
shl eax,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov edx,eax
|
||||
xor eax,eax
|
||||
and cl,1Fh
|
||||
shl edx,cl
|
||||
ret
|
||||
RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allshr()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,3Fh
|
||||
jae RETSIGN
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shrd eax,edx,cl
|
||||
sar edx,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov eax,edx
|
||||
sar edx,1Fh
|
||||
and cl,1Fh
|
||||
sar eax,cl
|
||||
ret
|
||||
RETSIGN:
|
||||
sar edx,1Fh
|
||||
mov eax,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aullshr()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,40h
|
||||
jae RETZERO
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shrd eax,edx,cl
|
||||
shr edx,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
and cl,1Fh
|
||||
shr eax,cl
|
||||
ret
|
||||
RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
#endif /* _M_IX86 */
|
||||
|
||||
#endif /* MSC_VER */
|
||||
|
||||
#endif /* !HAVE_LIBC && !SDL_STATIC_LIB */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -414,7 +414,7 @@ static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
|
|||
char *first,*last;
|
||||
char *pivot=malloc(size);
|
||||
size_t trunc=TRUNC_nonaligned*size;
|
||||
assert(pivot!=0);
|
||||
assert(pivot != NULL);
|
||||
|
||||
first=(char*)base; last=first+(nmemb-1)*size;
|
||||
|
||||
|
|
@ -445,7 +445,7 @@ static void qsort_aligned(void *base, size_t nmemb, size_t size,
|
|||
char *first,*last;
|
||||
char *pivot=malloc(size);
|
||||
size_t trunc=TRUNC_aligned*size;
|
||||
assert(pivot!=0);
|
||||
assert(pivot != NULL);
|
||||
|
||||
first=(char*)base; last=first+(nmemb-1)*size;
|
||||
|
||||
|
|
@ -475,7 +475,7 @@ static void qsort_words(void *base, size_t nmemb,
|
|||
int stacktop=0;
|
||||
char *first,*last;
|
||||
char *pivot=malloc(WORD_BYTES);
|
||||
assert(pivot!=0);
|
||||
assert(pivot != NULL);
|
||||
|
||||
first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -533,697 +533,114 @@ int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) :
|
|||
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
|
||||
#endif
|
||||
|
||||
/* This file contains a portable memcpy manipulation function for SDL */
|
||||
|
||||
void *
|
||||
SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
/* Presumably this is well tuned for speed.
|
||||
On my machine this is twice as fast as the C code below.
|
||||
*/
|
||||
return __builtin_memcpy(dst, src, len);
|
||||
#elif defined(HAVE_MEMCPY)
|
||||
return memcpy(dst, src, len);
|
||||
#elif defined(HAVE_BCOPY)
|
||||
bcopy(src, dst, len);
|
||||
return dst;
|
||||
#else
|
||||
/* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
|
||||
using Uint32* pointers, so we need to make sure the pointers are
|
||||
aligned before we loop using them.
|
||||
*/
|
||||
if (((uintptr_t)src & 0x3) || ((uintptr_t)dst & 0x3)) {
|
||||
/* Do an unaligned byte copy */
|
||||
Uint8 *srcp1 = (Uint8 *)src;
|
||||
Uint8 *dstp1 = (Uint8 *)dst;
|
||||
|
||||
while (len--) {
|
||||
*dstp1++ = *srcp1++;
|
||||
}
|
||||
} else {
|
||||
size_t left = (len % 4);
|
||||
Uint32 *srcp4, *dstp4;
|
||||
Uint8 *srcp1, *dstp1;
|
||||
|
||||
srcp4 = (Uint32 *) src;
|
||||
dstp4 = (Uint32 *) dst;
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
*dstp4++ = *srcp4++;
|
||||
}
|
||||
|
||||
srcp1 = (Uint8 *) srcp4;
|
||||
dstp1 = (Uint8 *) dstp4;
|
||||
switch (left) {
|
||||
case 3:
|
||||
*dstp1++ = *srcp1++;
|
||||
case 2:
|
||||
*dstp1++ = *srcp1++;
|
||||
case 1:
|
||||
*dstp1++ = *srcp1++;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
#endif /* __GNUC__ */
|
||||
}
|
||||
|
||||
void *
|
||||
SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
|
||||
{
|
||||
#if defined(HAVE_MEMSET)
|
||||
return memset(dst, c, len);
|
||||
#else
|
||||
size_t left;
|
||||
Uint32 *dstp4;
|
||||
Uint8 *dstp1 = (Uint8 *) dst;
|
||||
Uint8 value1;
|
||||
Uint32 value4;
|
||||
|
||||
/* The value used in memset() is a byte, passed as an int */
|
||||
c &= 0xff;
|
||||
|
||||
/* The destination pointer needs to be aligned on a 4-byte boundary to
|
||||
* execute a 32-bit set. Set first bytes manually if needed until it is
|
||||
* aligned. */
|
||||
value1 = (Uint8)c;
|
||||
while ((uintptr_t)dstp1 & 0x3) {
|
||||
if (len--) {
|
||||
*dstp1++ = value1;
|
||||
} else {
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
value4 = ((Uint32)c | ((Uint32)c << 8) | ((Uint32)c << 16) | ((Uint32)c << 24));
|
||||
dstp4 = (Uint32 *) dstp1;
|
||||
left = (len % 4);
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
*dstp4++ = value4;
|
||||
}
|
||||
|
||||
dstp1 = (Uint8 *) dstp4;
|
||||
switch (left) {
|
||||
case 3:
|
||||
*dstp1++ = value1;
|
||||
case 2:
|
||||
*dstp1++ = value1;
|
||||
case 1:
|
||||
*dstp1++ = value1;
|
||||
}
|
||||
|
||||
return dst;
|
||||
#endif /* HAVE_MEMSET */
|
||||
}
|
||||
|
||||
#if defined(HAVE_CTYPE_H) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
int SDL_isblank(int x) { return isblank(x); }
|
||||
#else
|
||||
int SDL_isblank(int x) { return ((x) == ' ') || ((x) == '\t'); }
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBC
|
||||
/* These are some C runtime intrinsics that need to be defined */
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#ifndef __FLTUSED__
|
||||
#define __FLTUSED__
|
||||
__declspec(selectany) int _fltused = 1;
|
||||
#endif
|
||||
|
||||
/* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls.
|
||||
Always provide it for the SDL2 DLL, but skip it when building static lib w/ static runtime. */
|
||||
#if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
|
||||
extern void *memcpy(void* dst, const void* src, size_t len);
|
||||
#pragma intrinsic(memcpy)
|
||||
|
||||
#pragma function(memcpy)
|
||||
void *
|
||||
memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
return SDL_memcpy(dst, src, len);
|
||||
}
|
||||
|
||||
extern void *memset(void* dst, int c, size_t len);
|
||||
#pragma intrinsic(memset)
|
||||
|
||||
#pragma function(memset)
|
||||
void *
|
||||
memset(void *dst, int c, size_t len)
|
||||
{
|
||||
return SDL_memset(dst, c, len);
|
||||
}
|
||||
#endif /* (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT)) */
|
||||
|
||||
#ifdef _M_IX86
|
||||
|
||||
/* Float to long */
|
||||
void
|
||||
__declspec(naked)
|
||||
_ftol()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
sub esp,20h
|
||||
and esp,0FFFFFFF0h
|
||||
fld st(0)
|
||||
fst dword ptr [esp+18h]
|
||||
fistp qword ptr [esp+10h]
|
||||
fild qword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
test eax,eax
|
||||
je integer_QnaN_or_zero
|
||||
arg_is_not_integer_QnaN:
|
||||
fsubp st(1),st
|
||||
test edx,edx
|
||||
jns positive
|
||||
fstp dword ptr [esp]
|
||||
mov ecx,dword ptr [esp]
|
||||
xor ecx,80000000h
|
||||
add ecx,7FFFFFFFh
|
||||
adc eax,0
|
||||
mov edx,dword ptr [esp+14h]
|
||||
adc edx,0
|
||||
jmp localexit
|
||||
positive:
|
||||
fstp dword ptr [esp]
|
||||
mov ecx,dword ptr [esp]
|
||||
add ecx,7FFFFFFFh
|
||||
sbb eax,0
|
||||
mov edx,dword ptr [esp+14h]
|
||||
sbb edx,0
|
||||
jmp localexit
|
||||
integer_QnaN_or_zero:
|
||||
mov edx,dword ptr [esp+14h]
|
||||
test edx,7FFFFFFFh
|
||||
jne arg_is_not_integer_QnaN
|
||||
fstp dword ptr [esp+18h]
|
||||
fstp dword ptr [esp+18h]
|
||||
localexit:
|
||||
leave
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
_ftol2_sse()
|
||||
{
|
||||
_ftol();
|
||||
}
|
||||
|
||||
/* 64-bit math operators for 32-bit systems */
|
||||
void
|
||||
__declspec(naked)
|
||||
_allmul()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
mov eax, dword ptr[esp+8]
|
||||
mov ecx, dword ptr[esp+10h]
|
||||
or ecx, eax
|
||||
mov ecx, dword ptr[esp+0Ch]
|
||||
jne hard
|
||||
mov eax, dword ptr[esp+4]
|
||||
mul ecx
|
||||
ret 10h
|
||||
hard:
|
||||
push ebx
|
||||
mul ecx
|
||||
mov ebx, eax
|
||||
mov eax, dword ptr[esp+8]
|
||||
mul dword ptr[esp+14h]
|
||||
add ebx, eax
|
||||
mov eax, dword ptr[esp+8]
|
||||
mul ecx
|
||||
add edx, ebx
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_alldiv()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push edi
|
||||
push esi
|
||||
push ebx
|
||||
xor edi,edi
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+10h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+14h],eax
|
||||
mov dword ptr [esp+10h],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+1Ch]
|
||||
or eax,eax
|
||||
jge L2
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+18h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+1Ch],eax
|
||||
mov dword ptr [esp+18h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+14h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
div ecx
|
||||
mov edx,ebx
|
||||
jmp L4
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov edx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+1Ch]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+18h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+14h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+10h]
|
||||
jbe L7
|
||||
L6:
|
||||
dec esi
|
||||
L7:
|
||||
xor edx,edx
|
||||
mov eax,esi
|
||||
L4:
|
||||
dec edi
|
||||
jne L8
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop ebx
|
||||
pop esi
|
||||
pop edi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aulldiv()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
push esi
|
||||
mov eax,dword ptr [esp+18h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
div ecx
|
||||
mov edx,ebx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+14h]
|
||||
mov edx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+18h]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+14h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+10h]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+0Ch]
|
||||
jbe L5
|
||||
L4:
|
||||
dec esi
|
||||
L5:
|
||||
xor edx,edx
|
||||
mov eax,esi
|
||||
L2:
|
||||
pop esi
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allrem()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
push edi
|
||||
xor edi,edi
|
||||
mov eax,dword ptr [esp+10h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+10h],eax
|
||||
mov dword ptr [esp+0Ch],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+18h]
|
||||
or eax,eax
|
||||
jge L2
|
||||
mov edx,dword ptr [esp+14h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+18h],eax
|
||||
mov dword ptr [esp+14h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
div ecx
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
dec edi
|
||||
jns L4
|
||||
jmp L8
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+14h]
|
||||
mov edx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov ecx,eax
|
||||
mul dword ptr [esp+18h]
|
||||
xchg eax,ecx
|
||||
mul dword ptr [esp+14h]
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+10h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+0Ch]
|
||||
jbe L7
|
||||
L6:
|
||||
sub eax,dword ptr [esp+14h]
|
||||
sbb edx,dword ptr [esp+18h]
|
||||
L7:
|
||||
sub eax,dword ptr [esp+0Ch]
|
||||
sbb edx,dword ptr [esp+10h]
|
||||
dec edi
|
||||
jns L8
|
||||
L4:
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop edi
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aullrem()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push ebx
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov eax,dword ptr [esp+8]
|
||||
div ecx
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
mov eax,dword ptr [esp+8]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov ecx,eax
|
||||
mul dword ptr [esp+14h]
|
||||
xchg eax,ecx
|
||||
mul dword ptr [esp+10h]
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+0Ch]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+8]
|
||||
jbe L5
|
||||
L4:
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
L5:
|
||||
sub eax,dword ptr [esp+8]
|
||||
sbb edx,dword ptr [esp+0Ch]
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L2:
|
||||
pop ebx
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_alldvrm()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push edi
|
||||
push esi
|
||||
push ebp
|
||||
xor edi,edi
|
||||
xor ebp,ebp
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jge L1
|
||||
inc edi
|
||||
inc ebp
|
||||
mov edx,dword ptr [esp+10h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+14h],eax
|
||||
mov dword ptr [esp+10h],edx
|
||||
L1:
|
||||
mov eax,dword ptr [esp+1Ch]
|
||||
or eax,eax
|
||||
jge L2
|
||||
inc edi
|
||||
mov edx,dword ptr [esp+18h]
|
||||
neg eax
|
||||
neg edx
|
||||
sbb eax,0
|
||||
mov dword ptr [esp+1Ch],eax
|
||||
mov dword ptr [esp+18h],edx
|
||||
L2:
|
||||
or eax,eax
|
||||
jne L3
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov eax,dword ptr [esp+14h]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mov eax,ebx
|
||||
mul dword ptr [esp+18h]
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
mul dword ptr [esp+18h]
|
||||
add edx,ecx
|
||||
jmp L4
|
||||
L3:
|
||||
mov ebx,eax
|
||||
mov ecx,dword ptr [esp+18h]
|
||||
mov edx,dword ptr [esp+14h]
|
||||
mov eax,dword ptr [esp+10h]
|
||||
L5:
|
||||
shr ebx,1
|
||||
rcr ecx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ebx,ebx
|
||||
jne L5
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+1Ch]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+18h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L6
|
||||
cmp edx,dword ptr [esp+14h]
|
||||
ja L6
|
||||
jb L7
|
||||
cmp eax,dword ptr [esp+10h]
|
||||
jbe L7
|
||||
L6:
|
||||
dec esi
|
||||
sub eax,dword ptr [esp+18h]
|
||||
sbb edx,dword ptr [esp+1Ch]
|
||||
L7:
|
||||
xor ebx,ebx
|
||||
L4:
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
dec ebp
|
||||
jns L9
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L9:
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
dec edi
|
||||
jne L8
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
L8:
|
||||
pop ebp
|
||||
pop esi
|
||||
pop edi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aulldvrm()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
push esi
|
||||
mov eax,dword ptr [esp+14h]
|
||||
or eax,eax
|
||||
jne L1
|
||||
mov ecx,dword ptr [esp+10h]
|
||||
mov eax,dword ptr [esp+0Ch]
|
||||
xor edx,edx
|
||||
div ecx
|
||||
mov ebx,eax
|
||||
mov eax,dword ptr [esp+8]
|
||||
div ecx
|
||||
mov esi,eax
|
||||
mov eax,ebx
|
||||
mul dword ptr [esp+10h]
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
mul dword ptr [esp+10h]
|
||||
add edx,ecx
|
||||
jmp L2
|
||||
L1:
|
||||
mov ecx,eax
|
||||
mov ebx,dword ptr [esp+10h]
|
||||
mov edx,dword ptr [esp+0Ch]
|
||||
mov eax,dword ptr [esp+8]
|
||||
L3:
|
||||
shr ecx,1
|
||||
rcr ebx,1
|
||||
shr edx,1
|
||||
rcr eax,1
|
||||
or ecx,ecx
|
||||
jne L3
|
||||
div ebx
|
||||
mov esi,eax
|
||||
mul dword ptr [esp+14h]
|
||||
mov ecx,eax
|
||||
mov eax,dword ptr [esp+10h]
|
||||
mul esi
|
||||
add edx,ecx
|
||||
jb L4
|
||||
cmp edx,dword ptr [esp+0Ch]
|
||||
ja L4
|
||||
jb L5
|
||||
cmp eax,dword ptr [esp+8]
|
||||
jbe L5
|
||||
L4:
|
||||
dec esi
|
||||
sub eax,dword ptr [esp+10h]
|
||||
sbb edx,dword ptr [esp+14h]
|
||||
L5:
|
||||
xor ebx,ebx
|
||||
L2:
|
||||
sub eax,dword ptr [esp+8]
|
||||
sbb edx,dword ptr [esp+0Ch]
|
||||
neg edx
|
||||
neg eax
|
||||
sbb edx,0
|
||||
mov ecx,edx
|
||||
mov edx,ebx
|
||||
mov ebx,ecx
|
||||
mov ecx,eax
|
||||
mov eax,esi
|
||||
pop esi
|
||||
ret 10h
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allshl()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,40h
|
||||
jae RETZERO
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shld edx,eax,cl
|
||||
shl eax,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov edx,eax
|
||||
xor eax,eax
|
||||
and cl,1Fh
|
||||
shl edx,cl
|
||||
ret
|
||||
RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_allshr()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,3Fh
|
||||
jae RETSIGN
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shrd eax,edx,cl
|
||||
sar edx,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov eax,edx
|
||||
sar edx,1Fh
|
||||
and cl,1Fh
|
||||
sar eax,cl
|
||||
ret
|
||||
RETSIGN:
|
||||
sar edx,1Fh
|
||||
mov eax,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
void
|
||||
__declspec(naked)
|
||||
_aullshr()
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
__asm {
|
||||
cmp cl,40h
|
||||
jae RETZERO
|
||||
cmp cl,20h
|
||||
jae MORE32
|
||||
shrd eax,edx,cl
|
||||
shr edx,cl
|
||||
ret
|
||||
MORE32:
|
||||
mov eax,edx
|
||||
xor edx,edx
|
||||
and cl,1Fh
|
||||
shr eax,cl
|
||||
ret
|
||||
RETZERO:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
ret
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
}
|
||||
|
||||
#endif /* _M_IX86 */
|
||||
|
||||
#endif /* MSC_VER */
|
||||
|
||||
#endif /* !HAVE_LIBC */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -29,6 +29,10 @@
|
|||
#include "SDL_stdinc.h"
|
||||
#include "SDL_vacopy.h"
|
||||
|
||||
#if defined(__vita__)
|
||||
#include <psp2/kernel/clib.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
|
||||
#define SDL_isupperhex(X) (((X) >= 'A') && ((X) <= 'F'))
|
||||
#define SDL_islowerhex(X) (((X) >= 'a') && ((X) <= 'f'))
|
||||
|
|
@ -49,9 +53,9 @@ static unsigned UTF8_TrailingBytes(unsigned char c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL)
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOL) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
|
||||
static size_t
|
||||
SDL_ScanLong(const char *text, int radix, long *valuep)
|
||||
SDL_ScanLong(const char *text, int count, int radix, long *valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
long value = 0;
|
||||
|
|
@ -78,6 +82,10 @@ SDL_ScanLong(const char *text, int radix, long *valuep)
|
|||
value *= radix;
|
||||
value += v;
|
||||
++text;
|
||||
|
||||
if (count > 0 && (text - textstart) == count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valuep && text > textstart) {
|
||||
if (negative && value) {
|
||||
|
|
@ -92,11 +100,15 @@ SDL_ScanLong(const char *text, int radix, long *valuep)
|
|||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOUL) || !defined(HAVE_STRTOD)
|
||||
static size_t
|
||||
SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
||||
SDL_ScanUnsignedLong(const char *text, int count, int radix, unsigned long *valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
unsigned long value = 0;
|
||||
|
||||
if (*text == '-') {
|
||||
return SDL_ScanLong(text, count, radix, (long *)valuep);
|
||||
}
|
||||
|
||||
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
|
||||
text += 2;
|
||||
}
|
||||
|
|
@ -114,6 +126,10 @@ SDL_ScanUnsignedLong(const char *text, int radix, unsigned long *valuep)
|
|||
value *= radix;
|
||||
value += v;
|
||||
++text;
|
||||
|
||||
if (count > 0 && (text - textstart) == count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valuep && text > textstart) {
|
||||
*valuep = value;
|
||||
|
|
@ -154,9 +170,9 @@ SDL_ScanUintPtrT(const char *text, int radix, uintptr_t * valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL)
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOLL) || !defined(HAVE_STRTOULL)
|
||||
static size_t
|
||||
SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
||||
SDL_ScanLongLong(const char *text, int count, int radix, Sint64 * valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
Sint64 value = 0;
|
||||
|
|
@ -183,6 +199,10 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
|||
value *= radix;
|
||||
value += v;
|
||||
++text;
|
||||
|
||||
if (count > 0 && (text - textstart) == count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valuep && text > textstart) {
|
||||
if (negative && value) {
|
||||
|
|
@ -197,11 +217,15 @@ SDL_ScanLongLong(const char *text, int radix, Sint64 * valuep)
|
|||
|
||||
#if !defined(HAVE_VSSCANF) || !defined(HAVE_STRTOULL)
|
||||
static size_t
|
||||
SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
|
||||
SDL_ScanUnsignedLongLong(const char *text, int count, int radix, Uint64 * valuep)
|
||||
{
|
||||
const char *textstart = text;
|
||||
Uint64 value = 0;
|
||||
|
||||
if (*text == '-') {
|
||||
return SDL_ScanLongLong(text, count, radix, (Sint64 *)valuep);
|
||||
}
|
||||
|
||||
if (radix == 16 && SDL_strncmp(text, "0x", 2) == 0) {
|
||||
text += 2;
|
||||
}
|
||||
|
|
@ -219,6 +243,10 @@ SDL_ScanUnsignedLongLong(const char *text, int radix, Uint64 * valuep)
|
|||
value *= radix;
|
||||
value += v;
|
||||
++text;
|
||||
|
||||
if (count > 0 && (text - textstart) == count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valuep && text > textstart) {
|
||||
*valuep = value;
|
||||
|
|
@ -240,7 +268,7 @@ SDL_ScanFloat(const char *text, double *valuep)
|
|||
negative = SDL_TRUE;
|
||||
++text;
|
||||
}
|
||||
text += SDL_ScanUnsignedLong(text, 10, &lvalue);
|
||||
text += SDL_ScanUnsignedLong(text, 0, 10, &lvalue);
|
||||
value += lvalue;
|
||||
if (*text == '.') {
|
||||
int mult = 10;
|
||||
|
|
@ -263,108 +291,6 @@ SDL_ScanFloat(const char *text, double *valuep)
|
|||
}
|
||||
#endif
|
||||
|
||||
void *
|
||||
SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
|
||||
{
|
||||
#if defined(HAVE_MEMSET)
|
||||
return memset(dst, c, len);
|
||||
#else
|
||||
size_t left;
|
||||
Uint32 *dstp4;
|
||||
Uint8 *dstp1 = (Uint8 *) dst;
|
||||
Uint8 value1;
|
||||
Uint32 value4;
|
||||
|
||||
/* The value used in memset() is a byte, passed as an int */
|
||||
c &= 0xff;
|
||||
|
||||
/* The destination pointer needs to be aligned on a 4-byte boundary to
|
||||
* execute a 32-bit set. Set first bytes manually if needed until it is
|
||||
* aligned. */
|
||||
value1 = (Uint8)c;
|
||||
while ((uintptr_t)dstp1 & 0x3) {
|
||||
if (len--) {
|
||||
*dstp1++ = value1;
|
||||
} else {
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
value4 = ((Uint32)c | ((Uint32)c << 8) | ((Uint32)c << 16) | ((Uint32)c << 24));
|
||||
dstp4 = (Uint32 *) dstp1;
|
||||
left = (len % 4);
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
*dstp4++ = value4;
|
||||
}
|
||||
|
||||
dstp1 = (Uint8 *) dstp4;
|
||||
switch (left) {
|
||||
case 3:
|
||||
*dstp1++ = value1;
|
||||
case 2:
|
||||
*dstp1++ = value1;
|
||||
case 1:
|
||||
*dstp1++ = value1;
|
||||
}
|
||||
|
||||
return dst;
|
||||
#endif /* HAVE_MEMSET */
|
||||
}
|
||||
|
||||
void *
|
||||
SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
/* Presumably this is well tuned for speed.
|
||||
On my machine this is twice as fast as the C code below.
|
||||
*/
|
||||
return __builtin_memcpy(dst, src, len);
|
||||
#elif defined(HAVE_MEMCPY)
|
||||
return memcpy(dst, src, len);
|
||||
#elif defined(HAVE_BCOPY)
|
||||
bcopy(src, dst, len);
|
||||
return dst;
|
||||
#else
|
||||
/* GCC 4.9.0 with -O3 will generate movaps instructions with the loop
|
||||
using Uint32* pointers, so we need to make sure the pointers are
|
||||
aligned before we loop using them.
|
||||
*/
|
||||
if (((uintptr_t)src & 0x3) || ((uintptr_t)dst & 0x3)) {
|
||||
/* Do an unaligned byte copy */
|
||||
Uint8 *srcp1 = (Uint8 *)src;
|
||||
Uint8 *dstp1 = (Uint8 *)dst;
|
||||
|
||||
while (len--) {
|
||||
*dstp1++ = *srcp1++;
|
||||
}
|
||||
} else {
|
||||
size_t left = (len % 4);
|
||||
Uint32 *srcp4, *dstp4;
|
||||
Uint8 *srcp1, *dstp1;
|
||||
|
||||
srcp4 = (Uint32 *) src;
|
||||
dstp4 = (Uint32 *) dst;
|
||||
len /= 4;
|
||||
while (len--) {
|
||||
*dstp4++ = *srcp4++;
|
||||
}
|
||||
|
||||
srcp1 = (Uint8 *) srcp4;
|
||||
dstp1 = (Uint8 *) dstp4;
|
||||
switch (left) {
|
||||
case 3:
|
||||
*dstp1++ = *srcp1++;
|
||||
case 2:
|
||||
*dstp1++ = *srcp1++;
|
||||
case 1:
|
||||
*dstp1++ = *srcp1++;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
#endif /* __GNUC__ */
|
||||
}
|
||||
|
||||
void *
|
||||
SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
|
||||
{
|
||||
|
|
@ -392,7 +318,18 @@ SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src,
|
|||
int
|
||||
SDL_memcmp(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
#if defined(HAVE_MEMCMP)
|
||||
#if defined(__vita__)
|
||||
/*
|
||||
Using memcmp on NULL is UB per POSIX / C99 7.21.1/2.
|
||||
But, both linux and bsd allow that, with an exception:
|
||||
zero length strings are always identical, so NULLs are never dereferenced.
|
||||
sceClibMemcmp on PSVita doesn't allow that, so we check ourselves.
|
||||
*/
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
return sceClibMemcmp(s1, s2, len);
|
||||
#elif defined(HAVE_MEMCMP)
|
||||
return memcmp(s1, s2, len);
|
||||
#else
|
||||
char *s1p = (char *) s1;
|
||||
|
|
@ -675,6 +612,23 @@ SDL_utf8strlen(const char *str)
|
|||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_utf8strnlen(const char *str, size_t bytes)
|
||||
{
|
||||
size_t retval = 0;
|
||||
const char *p = str;
|
||||
unsigned char ch;
|
||||
|
||||
while ((ch = *(p++)) != 0 && bytes-- > 0) {
|
||||
/* if top two bits are 1 and 0, it's a continuation byte. */
|
||||
if ((ch & 0xc0) != 0x80) {
|
||||
retval++;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
|
@ -764,6 +718,9 @@ SDL_strchr(const char *string, int c)
|
|||
}
|
||||
++string;
|
||||
}
|
||||
if (c == '\0') {
|
||||
return (char *) string;
|
||||
}
|
||||
return NULL;
|
||||
#endif /* HAVE_STRCHR */
|
||||
}
|
||||
|
|
@ -776,7 +733,7 @@ SDL_strrchr(const char *string, int c)
|
|||
#elif defined(HAVE_RINDEX)
|
||||
return SDL_const_cast(char*,rindex(string, c));
|
||||
#else
|
||||
const char *bufp = string + SDL_strlen(string) - 1;
|
||||
const char *bufp = string + SDL_strlen(string);
|
||||
while (bufp >= string) {
|
||||
if (*bufp == c) {
|
||||
return (char *) bufp;
|
||||
|
|
@ -804,6 +761,23 @@ SDL_strstr(const char *haystack, const char *needle)
|
|||
#endif /* HAVE_STRSTR */
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_strcasestr(const char *haystack, const char *needle)
|
||||
{
|
||||
#if defined(HAVE_STRCASESTR)
|
||||
return SDL_const_cast(char*,strcasestr(haystack, needle));
|
||||
#else
|
||||
size_t length = SDL_strlen(needle);
|
||||
while (*haystack) {
|
||||
if (SDL_strncasecmp(haystack, needle, length) == 0) {
|
||||
return (char *) haystack;
|
||||
}
|
||||
++haystack;
|
||||
}
|
||||
return NULL;
|
||||
#endif /* HAVE_STRCASESTR */
|
||||
}
|
||||
|
||||
#if !defined(HAVE__LTOA) || !defined(HAVE__I64TOA) || \
|
||||
!defined(HAVE__ULTOA) || !defined(HAVE__UI64TOA)
|
||||
static const char ntoa_table[] = {
|
||||
|
|
@ -957,7 +931,7 @@ SDL_strtol(const char *string, char **endp, int base)
|
|||
}
|
||||
}
|
||||
|
||||
len = SDL_ScanLong(string, base, &value);
|
||||
len = SDL_ScanLong(string, 0, base, &value);
|
||||
if (endp) {
|
||||
*endp = (char *) string + len;
|
||||
}
|
||||
|
|
@ -982,7 +956,7 @@ SDL_strtoul(const char *string, char **endp, int base)
|
|||
}
|
||||
}
|
||||
|
||||
len = SDL_ScanUnsignedLong(string, base, &value);
|
||||
len = SDL_ScanUnsignedLong(string, 0, base, &value);
|
||||
if (endp) {
|
||||
*endp = (char *) string + len;
|
||||
}
|
||||
|
|
@ -1007,7 +981,7 @@ SDL_strtoll(const char *string, char **endp, int base)
|
|||
}
|
||||
}
|
||||
|
||||
len = SDL_ScanLongLong(string, base, &value);
|
||||
len = SDL_ScanLongLong(string, 0, base, &value);
|
||||
if (endp) {
|
||||
*endp = (char *) string + len;
|
||||
}
|
||||
|
|
@ -1032,7 +1006,7 @@ SDL_strtoull(const char *string, char **endp, int base)
|
|||
}
|
||||
}
|
||||
|
||||
len = SDL_ScanUnsignedLongLong(string, base, &value);
|
||||
len = SDL_ScanUnsignedLongLong(string, 0, base, &value);
|
||||
if (endp) {
|
||||
*endp = (char *) string + len;
|
||||
}
|
||||
|
|
@ -1192,7 +1166,8 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
DO_SHORT,
|
||||
DO_INT,
|
||||
DO_LONG,
|
||||
DO_LONGLONG
|
||||
DO_LONGLONG,
|
||||
DO_SIZE_T
|
||||
} inttype = DO_INT;
|
||||
size_t advance;
|
||||
SDL_bool suppress = SDL_FALSE;
|
||||
|
|
@ -1210,7 +1185,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
suppress = SDL_TRUE;
|
||||
++fmt;
|
||||
}
|
||||
fmt += SDL_ScanLong(fmt, 10, &count);
|
||||
fmt += SDL_ScanLong(fmt, 0, 10, &count);
|
||||
|
||||
if (*fmt == 'c') {
|
||||
if (!count) {
|
||||
|
|
@ -1256,6 +1231,9 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
inttype = DO_LONGLONG;
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
inttype = DO_SIZE_T;
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
int index = 0;
|
||||
|
|
@ -1273,17 +1251,26 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
SDL_FALLTHROUGH;
|
||||
case 'd':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Sint64 value;
|
||||
advance = SDL_ScanLongLong(text, radix, &value);
|
||||
Sint64 value = 0;
|
||||
advance = SDL_ScanLongLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
Sint64 *valuep = va_arg(ap, Sint64 *);
|
||||
*valuep = value;
|
||||
++retval;
|
||||
}
|
||||
} else if (inttype == DO_SIZE_T) {
|
||||
Sint64 value = 0;
|
||||
advance = SDL_ScanLongLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
size_t *valuep = va_arg(ap, size_t *);
|
||||
*valuep = (size_t)value;
|
||||
++retval;
|
||||
}
|
||||
} else {
|
||||
long value;
|
||||
advance = SDL_ScanLong(text, radix, &value);
|
||||
long value = 0;
|
||||
advance = SDL_ScanLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
switch (inttype) {
|
||||
|
|
@ -1306,6 +1293,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
}
|
||||
break;
|
||||
case DO_LONGLONG:
|
||||
case DO_SIZE_T:
|
||||
/* Handled above */
|
||||
break;
|
||||
}
|
||||
|
|
@ -1328,16 +1316,25 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
case 'u':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Uint64 value = 0;
|
||||
advance = SDL_ScanUnsignedLongLong(text, radix, &value);
|
||||
advance = SDL_ScanUnsignedLongLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
Uint64 *valuep = va_arg(ap, Uint64 *);
|
||||
*valuep = value;
|
||||
++retval;
|
||||
}
|
||||
} else if (inttype == DO_SIZE_T) {
|
||||
Uint64 value = 0;
|
||||
advance = SDL_ScanUnsignedLongLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
size_t *valuep = va_arg(ap, size_t *);
|
||||
*valuep = (size_t)value;
|
||||
++retval;
|
||||
}
|
||||
} else {
|
||||
unsigned long value = 0;
|
||||
advance = SDL_ScanUnsignedLong(text, radix, &value);
|
||||
advance = SDL_ScanUnsignedLong(text, count, radix, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
switch (inttype) {
|
||||
|
|
@ -1360,6 +1357,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
}
|
||||
break;
|
||||
case DO_LONGLONG:
|
||||
case DO_SIZE_T:
|
||||
/* Handled above */
|
||||
break;
|
||||
}
|
||||
|
|
@ -1383,7 +1381,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
|||
break;
|
||||
case 'f':
|
||||
{
|
||||
double value;
|
||||
double value = 0.0;
|
||||
advance = SDL_ScanFloat(text, &value);
|
||||
text += advance;
|
||||
if (advance && !suppress) {
|
||||
|
|
@ -1703,7 +1701,8 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
{
|
||||
DO_INT,
|
||||
DO_LONG,
|
||||
DO_LONGLONG
|
||||
DO_LONGLONG,
|
||||
DO_SIZE_T
|
||||
} inttype = DO_INT;
|
||||
|
||||
SDL_zero(info);
|
||||
|
|
@ -1786,6 +1785,9 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
inttype = DO_LONGLONG;
|
||||
}
|
||||
break;
|
||||
case 'z':
|
||||
inttype = DO_SIZE_T;
|
||||
break;
|
||||
case 'i':
|
||||
case 'd':
|
||||
if (info.precision >= 0) {
|
||||
|
|
@ -1804,6 +1806,10 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
|
||||
va_arg(ap, Sint64));
|
||||
break;
|
||||
case DO_SIZE_T:
|
||||
length += SDL_PrintLongLong(TEXT_AND_LEN_ARGS, &info,
|
||||
va_arg(ap, size_t));
|
||||
break;
|
||||
}
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
|
|
@ -1846,6 +1852,10 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
|||
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
|
||||
va_arg(ap, Uint64));
|
||||
break;
|
||||
case DO_SIZE_T:
|
||||
length += SDL_PrintUnsignedLongLong(TEXT_AND_LEN_ARGS, &info,
|
||||
va_arg(ap, size_t));
|
||||
break;
|
||||
}
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue