src/stdlib/SDL_stdlib.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 07 Jun 2015 19:58:42 -0400
changeset 9715 8945c203a54b
parent 9619 b94b6d0bff0f
child 9716 f2804ed2a5a3
permissions -rw-r--r--
VS2005 tweaks (thanks, Ozkan!).

Fixes Bugzilla #2895.

His notes:

The following trivial changes make SDL2 tree (mostly) compatible with Visual
Studio 2005:

* SDL_stdlib.c: Similar to VS2010 and newer, VS2005 also generates memcpy(),
(it also generates memset(), see below), so propagate the #if condition to
cover VS2005.

* SDL_pixels.c (SDL_CalculateGammaRamp): VS2005 generates a memset() call for
gamma==0 case, so replace the if loop with SDL_memset().

* SDL_windowsvideo.h: Include msctf.h only with VS2008 and newer, otherwise
include SDL_msctf.h

* SDL_windowskeyboard.c: Adjust the #ifdefs so that SDL_msctf.h inclusion is
always recognized correctly.
slouken@1330
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@1330
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1330
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1330
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1330
    20
*/
icculus@9306
    21
icculus@9306
    22
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
icculus@9306
    23
#define SDL_DISABLE_ANALYZE_MACROS 1
icculus@9306
    24
#endif
icculus@9306
    25
icculus@8093
    26
#include "../SDL_internal.h"
slouken@1330
    27
slouken@1330
    28
/* This file contains portable stdlib functions for SDL */
slouken@1330
    29
slouken@1354
    30
#include "SDL_stdinc.h"
slouken@7351
    31
#include "../libm/math_libm.h"
slouken@1330
    32
slouken@7351
    33
slouken@7351
    34
double
slouken@7351
    35
SDL_atan(double x)
slouken@7351
    36
{
slouken@7351
    37
#ifdef HAVE_ATAN
slouken@7351
    38
    return atan(x);
slouken@7351
    39
#else
slouken@7351
    40
    return SDL_uclibc_atan(x);
slouken@7351
    41
#endif /* HAVE_ATAN */
slouken@7351
    42
}
slouken@7351
    43
slouken@7351
    44
double
slouken@7351
    45
SDL_atan2(double x, double y)
slouken@7351
    46
{
slouken@7351
    47
#if defined(HAVE_ATAN2)
slouken@7351
    48
    return atan2(x, y);
slouken@7351
    49
#else
slouken@7351
    50
    return SDL_uclibc_atan2(x, y);
slouken@7351
    51
#endif /* HAVE_ATAN2 */
slouken@7351
    52
}
slouken@7351
    53
slouken@7351
    54
double
icculus@8056
    55
SDL_acos(double val)
icculus@8056
    56
{
icculus@8056
    57
#if defined(HAVE_ACOS)
icculus@8056
    58
    return acos(val);
icculus@8056
    59
#else
icculus@8056
    60
    double result;
icculus@8056
    61
    if (val == -1.0) {
icculus@8056
    62
        result = M_PI;
icculus@8056
    63
    } else {
icculus@8056
    64
        result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
icculus@8056
    65
        if (result < 0.0)
icculus@8056
    66
        {
icculus@8056
    67
            result += M_PI;
icculus@8056
    68
        }
icculus@8056
    69
    }
icculus@8056
    70
    return result;
icculus@8056
    71
#endif
icculus@8056
    72
}
icculus@8056
    73
icculus@8056
    74
double
icculus@8056
    75
SDL_asin(double val)
icculus@8056
    76
{
icculus@8056
    77
#if defined(HAVE_ASIN)
icculus@8056
    78
    return asin(val);
icculus@8056
    79
#else
icculus@8056
    80
    double result;
icculus@8056
    81
    if (val == -1.0) {
icculus@8056
    82
        result = -(M_PI / 2.0);
icculus@8056
    83
    } else {
icculus@8056
    84
        result = (M_PI / 2.0) - SDL_acos(val);
icculus@8056
    85
    }
icculus@8056
    86
    return result;
icculus@8056
    87
#endif
icculus@8056
    88
}
icculus@8056
    89
icculus@8056
    90
double
slouken@7351
    91
SDL_ceil(double x)
slouken@7351
    92
{
slouken@7351
    93
#ifdef HAVE_CEIL
slouken@7351
    94
    return ceil(x);
slouken@7351
    95
#else
slouken@8033
    96
    double integer = SDL_floor(x);
slouken@8033
    97
    double fraction = x - integer;
slouken@8033
    98
    if (fraction > 0.0) {
slouken@8033
    99
        integer += 1.0;
slouken@8033
   100
    }
slouken@8033
   101
    return integer;
slouken@7351
   102
#endif /* HAVE_CEIL */
slouken@7351
   103
}
slouken@7351
   104
slouken@7351
   105
double
slouken@7351
   106
SDL_copysign(double x, double y)
slouken@7351
   107
{
slouken@7351
   108
#if defined(HAVE_COPYSIGN)
slouken@7351
   109
    return copysign(x, y);
dludwig@8478
   110
#elif defined(HAVE__COPYSIGN)
dludwig@8478
   111
    return _copysign(x, y);
slouken@7351
   112
#else
slouken@7351
   113
    return SDL_uclibc_copysign(x, y);
slouken@7351
   114
#endif /* HAVE_COPYSIGN */
slouken@7351
   115
}
slouken@7351
   116
slouken@7351
   117
double
slouken@7351
   118
SDL_cos(double x)
slouken@7351
   119
{
slouken@7351
   120
#if defined(HAVE_COS)
slouken@7351
   121
    return cos(x);
slouken@7351
   122
#else
slouken@7351
   123
    return SDL_uclibc_cos(x);
slouken@7351
   124
#endif /* HAVE_COS */
slouken@7351
   125
}
slouken@7351
   126
slouken@7351
   127
float
slouken@7351
   128
SDL_cosf(float x)
slouken@7351
   129
{
slouken@7351
   130
#ifdef HAVE_COSF
slouken@7351
   131
    return cosf(x);
slouken@7351
   132
#else
slouken@7351
   133
    return (float)SDL_cos((double)x);
slouken@7351
   134
#endif
slouken@7351
   135
}
slouken@7351
   136
slouken@7351
   137
double
slouken@7351
   138
SDL_fabs(double x)
slouken@7351
   139
{
slouken@7351
   140
#if defined(HAVE_FABS)
slouken@7351
   141
    return fabs(x); 
slouken@7351
   142
#else
slouken@7351
   143
    return SDL_uclibc_fabs(x);
slouken@7351
   144
#endif /* HAVE_FABS */
slouken@7351
   145
}
slouken@7351
   146
slouken@7351
   147
double
slouken@7351
   148
SDL_floor(double x)
slouken@7351
   149
{
slouken@7351
   150
#if defined(HAVE_FLOOR)
slouken@7351
   151
    return floor(x);
slouken@7351
   152
#else
slouken@7351
   153
    return SDL_uclibc_floor(x);
slouken@7351
   154
#endif /* HAVE_FLOOR */
slouken@7351
   155
}
slouken@7351
   156
slouken@7351
   157
double
slouken@7351
   158
SDL_log(double x)
slouken@7351
   159
{
slouken@7351
   160
#if defined(HAVE_LOG)
slouken@7351
   161
    return log(x);
slouken@7351
   162
#else
slouken@7351
   163
    return SDL_uclibc_log(x);
slouken@7351
   164
#endif /* HAVE_LOG */
slouken@7351
   165
}
slouken@7351
   166
slouken@7351
   167
double
slouken@7351
   168
SDL_pow(double x, double y)
slouken@7351
   169
{
slouken@7351
   170
#if defined(HAVE_POW)
slouken@7351
   171
    return pow(x, y);
slouken@7351
   172
#else
slouken@7351
   173
    return SDL_uclibc_pow(x, y);
slouken@7351
   174
#endif /* HAVE_POW */
slouken@7351
   175
}
slouken@7351
   176
slouken@7351
   177
double
slouken@7351
   178
SDL_scalbn(double x, int n)
slouken@7351
   179
{
slouken@7351
   180
#if defined(HAVE_SCALBN)
slouken@7351
   181
    return scalbn(x, n);
dludwig@8478
   182
#elif defined(HAVE__SCALB)
dludwig@8478
   183
    return _scalb(x, n);
slouken@7351
   184
#else
slouken@7351
   185
    return SDL_uclibc_scalbn(x, n);
slouken@7351
   186
#endif /* HAVE_SCALBN */
slouken@7351
   187
}
slouken@7351
   188
slouken@7351
   189
double
slouken@7351
   190
SDL_sin(double x)
slouken@7351
   191
{
slouken@7351
   192
#if defined(HAVE_SIN)
slouken@7351
   193
    return sin(x);
slouken@7351
   194
#else
slouken@7351
   195
    return SDL_uclibc_sin(x);
slouken@7351
   196
#endif /* HAVE_SIN */
slouken@7351
   197
}
slouken@7351
   198
slouken@7351
   199
float 
slouken@7351
   200
SDL_sinf(float x)
slouken@7351
   201
{
slouken@7351
   202
#ifdef HAVE_SINF
slouken@7351
   203
    return sinf(x);
slouken@7351
   204
#else
slouken@7351
   205
    return (float)SDL_sin((double)x);
slouken@7351
   206
#endif /* HAVE_SINF */
slouken@7351
   207
}
slouken@7351
   208
slouken@7351
   209
double
slouken@7351
   210
SDL_sqrt(double x)
slouken@7351
   211
{
slouken@7351
   212
#if defined(HAVE_SQRT)
slouken@7351
   213
    return sqrt(x);
slouken@7351
   214
#else
slouken@7351
   215
    return SDL_uclibc_sqrt(x);
slouken@7351
   216
#endif
slouken@7351
   217
}
slouken@7351
   218
slouken@8840
   219
float
slouken@8840
   220
SDL_sqrtf(float x)
slouken@8840
   221
{
slouken@8840
   222
#if defined(HAVE_SQRTF)
slouken@8840
   223
    return sqrtf(x);
slouken@8840
   224
#else
slouken@8840
   225
    return (float)SDL_sqrt((double)x);
slouken@8840
   226
#endif
slouken@8840
   227
}
slouken@8840
   228
slouken@8840
   229
double
slouken@8840
   230
SDL_tan(double x)
slouken@8840
   231
{
slouken@8840
   232
#if defined(HAVE_TAN)
slouken@8840
   233
    return tan(x);
slouken@8840
   234
#else
slouken@8840
   235
    return SDL_uclibc_tan(x);
slouken@8840
   236
#endif
slouken@8840
   237
}
slouken@8840
   238
slouken@8840
   239
float
slouken@8840
   240
SDL_tanf(float x)
slouken@8840
   241
{
slouken@8840
   242
#if defined(HAVE_TANF)
slouken@8840
   243
    return tanf(x);
slouken@8840
   244
#else
slouken@8840
   245
    return (float)SDL_tan((double)x);
slouken@8840
   246
#endif
slouken@8840
   247
}
slouken@8840
   248
slouken@7351
   249
int SDL_abs(int x)
slouken@7351
   250
{
slouken@7351
   251
#ifdef HAVE_ABS
slouken@7351
   252
    return abs(x);
slouken@7351
   253
#else
slouken@7351
   254
    return ((x) < 0 ? -(x) : (x));
slouken@7351
   255
#endif
slouken@7351
   256
}
slouken@7351
   257
slouken@7351
   258
#ifdef HAVE_CTYPE_H
slouken@7351
   259
int SDL_isdigit(int x) { return isdigit(x); }
slouken@7351
   260
int SDL_isspace(int x) { return isspace(x); }
slouken@7351
   261
int SDL_toupper(int x) { return toupper(x); }
slouken@7351
   262
int SDL_tolower(int x) { return tolower(x); }
slouken@7351
   263
#else
slouken@7351
   264
int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
philipp@7357
   265
int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
slouken@7351
   266
int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
slouken@7351
   267
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
slouken@7351
   268
#endif
icculus@7003
   269
icculus@7003
   270
slouken@1330
   271
#ifndef HAVE_LIBC
slouken@1330
   272
/* These are some C runtime intrinsics that need to be defined */
slouken@1330
   273
slouken@3255
   274
#if defined(_MSC_VER)
slouken@1330
   275
slouken@1433
   276
#ifndef __FLTUSED__
slouken@1433
   277
#define __FLTUSED__
slouken@3255
   278
__declspec(selectany) int _fltused = 1;
slouken@1433
   279
#endif
slouken@3255
   280
slouken@6355
   281
/* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */
icculus@9715
   282
/* Visual Studio 2005 does it too, and it also generates memset() calls */
icculus@9715
   283
#if (_MSC_VER == 1400 || _MSC_VER >= 1600) && defined(_WIN64) && !defined(_DEBUG)
slouken@5455
   284
#include <intrin.h>
slouken@5455
   285
slouken@5455
   286
#pragma function(memcpy)
slouken@5455
   287
void * memcpy ( void * destination, const void * source, size_t num )
slouken@5455
   288
{
slouken@5455
   289
    const Uint8 *src = (const Uint8 *)source;
slouken@5455
   290
    Uint8 *dst = (Uint8 *)destination;
slouken@5455
   291
    size_t i;
slouken@5455
   292
    
slouken@5455
   293
    /* All WIN64 architectures have SSE, right? */
slouken@5455
   294
    if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
slouken@5455
   295
        __m128 values[4];
slouken@5455
   296
        for (i = num / 64; i--;) {
slouken@5455
   297
            _mm_prefetch(src, _MM_HINT_NTA);
slouken@5455
   298
            values[0] = *(__m128 *) (src + 0);
slouken@5455
   299
            values[1] = *(__m128 *) (src + 16);
slouken@5455
   300
            values[2] = *(__m128 *) (src + 32);
slouken@5455
   301
            values[3] = *(__m128 *) (src + 48);
slouken@5455
   302
            _mm_stream_ps((float *) (dst + 0), values[0]);
slouken@5455
   303
            _mm_stream_ps((float *) (dst + 16), values[1]);
slouken@5455
   304
            _mm_stream_ps((float *) (dst + 32), values[2]);
slouken@5455
   305
            _mm_stream_ps((float *) (dst + 48), values[3]);
slouken@5455
   306
            src += 64;
slouken@5455
   307
            dst += 64;
slouken@5455
   308
        }
slouken@5455
   309
        num &= 63;
slouken@5455
   310
    }
slouken@5455
   311
slouken@5455
   312
    while (num--) {
slouken@5455
   313
        *dst++ = *src++;
slouken@5455
   314
    }
slouken@5455
   315
    return destination;
slouken@5455
   316
}
slouken@5455
   317
#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
slouken@5455
   318
slouken@5086
   319
#ifdef _M_IX86
slouken@1433
   320
slouken@1346
   321
/* Float to long */
slouken@3253
   322
void
slouken@3253
   323
__declspec(naked)
slouken@3253
   324
_ftol()
slouken@1345
   325
{
slouken@1895
   326
    /* *INDENT-OFF* */
slouken@1895
   327
    __asm {
slouken@1895
   328
        push        ebp
slouken@1895
   329
        mov         ebp,esp
slouken@1895
   330
        sub         esp,20h
slouken@1895
   331
        and         esp,0FFFFFFF0h
slouken@1895
   332
        fld         st(0)
slouken@1895
   333
        fst         dword ptr [esp+18h]
slouken@1895
   334
        fistp       qword ptr [esp+10h]
slouken@1895
   335
        fild        qword ptr [esp+10h]
slouken@1895
   336
        mov         edx,dword ptr [esp+18h]
slouken@1895
   337
        mov         eax,dword ptr [esp+10h]
slouken@1895
   338
        test        eax,eax
slouken@1895
   339
        je          integer_QnaN_or_zero
slouken@1346
   340
arg_is_not_integer_QnaN:
slouken@1895
   341
        fsubp       st(1),st
slouken@1895
   342
        test        edx,edx
slouken@1895
   343
        jns         positive
slouken@1895
   344
        fstp        dword ptr [esp]
slouken@1895
   345
        mov         ecx,dword ptr [esp]
slouken@1895
   346
        xor         ecx,80000000h
slouken@1895
   347
        add         ecx,7FFFFFFFh
slouken@1895
   348
        adc         eax,0
slouken@1895
   349
        mov         edx,dword ptr [esp+14h]
slouken@1895
   350
        adc         edx,0
slouken@1895
   351
        jmp         localexit
slouken@1346
   352
positive:
slouken@1895
   353
        fstp        dword ptr [esp]
slouken@1895
   354
        mov         ecx,dword ptr [esp]
slouken@1895
   355
        add         ecx,7FFFFFFFh
slouken@1895
   356
        sbb         eax,0
slouken@1895
   357
        mov         edx,dword ptr [esp+14h]
slouken@1895
   358
        sbb         edx,0
slouken@1895
   359
        jmp         localexit
slouken@1346
   360
integer_QnaN_or_zero:
slouken@1895
   361
        mov         edx,dword ptr [esp+14h]
slouken@1895
   362
        test        edx,7FFFFFFFh
slouken@1895
   363
        jne         arg_is_not_integer_QnaN
slouken@1895
   364
        fstp        dword ptr [esp+18h]
slouken@1895
   365
        fstp        dword ptr [esp+18h]
slouken@1346
   366
localexit:
slouken@1895
   367
        leave
slouken@1895
   368
        ret
slouken@1895
   369
    }
slouken@1895
   370
    /* *INDENT-ON* */
slouken@1345
   371
}
slouken@1895
   372
slouken@1895
   373
void
slouken@1895
   374
_ftol2_sse()
slouken@1330
   375
{
slouken@1895
   376
    _ftol();
slouken@1330
   377
}
slouken@1330
   378
slouken@9015
   379
/* 64-bit math operators for 32-bit systems */
slouken@9015
   380
void
slouken@9015
   381
__declspec(naked)
slouken@9015
   382
_allmul()
slouken@9015
   383
{
slouken@9015
   384
    /* *INDENT-OFF* */
slouken@9015
   385
    __asm {
slouken@9015
   386
        mov         eax, dword ptr[esp+8]
slouken@9015
   387
        mov         ecx, dword ptr[esp+10h]
slouken@9015
   388
        or          ecx, eax
slouken@9015
   389
        mov         ecx, dword ptr[esp+0Ch]
slouken@9015
   390
        jne         hard
slouken@9015
   391
        mov         eax, dword ptr[esp+4]
slouken@9015
   392
        mul         ecx
slouken@9015
   393
        ret         10h
slouken@9015
   394
hard:
slouken@9015
   395
        push        ebx
slouken@9015
   396
        mul         ecx
slouken@9015
   397
        mov         ebx, eax
slouken@9015
   398
        mov         eax, dword ptr[esp+8]
slouken@9015
   399
        mul         dword ptr[esp+14h]
slouken@9015
   400
        add         ebx, eax
slouken@9015
   401
        mov         eax, dword ptr[esp+8]
slouken@9015
   402
        mul         ecx
slouken@9015
   403
        add         edx, ebx
slouken@9015
   404
        pop         ebx
slouken@9015
   405
        ret         10h
slouken@9015
   406
    }
slouken@9015
   407
    /* *INDENT-ON* */
slouken@1330
   408
}
slouken@2735
   409
slouken@1895
   410
void
slouken@1895
   411
__declspec(naked)
slouken@1895
   412
_alldiv()
slouken@1330
   413
{
slouken@1895
   414
    /* *INDENT-OFF* */
slouken@1895
   415
    __asm {
slouken@1895
   416
        push        edi
slouken@1895
   417
        push        esi
slouken@1895
   418
        push        ebx
slouken@1895
   419
        xor         edi,edi
slouken@1895
   420
        mov         eax,dword ptr [esp+14h]
slouken@1895
   421
        or          eax,eax
slouken@1895
   422
        jge         L1
slouken@1895
   423
        inc         edi
slouken@1895
   424
        mov         edx,dword ptr [esp+10h]
slouken@1895
   425
        neg         eax
slouken@1895
   426
        neg         edx
slouken@1895
   427
        sbb         eax,0
slouken@1895
   428
        mov         dword ptr [esp+14h],eax
slouken@1895
   429
        mov         dword ptr [esp+10h],edx
slouken@1346
   430
L1:
slouken@1895
   431
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   432
        or          eax,eax
slouken@1895
   433
        jge         L2
slouken@1895
   434
        inc         edi
slouken@1895
   435
        mov         edx,dword ptr [esp+18h]
slouken@1895
   436
        neg         eax
slouken@1895
   437
        neg         edx
slouken@1895
   438
        sbb         eax,0
slouken@1895
   439
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   440
        mov         dword ptr [esp+18h],edx
slouken@1346
   441
L2:
slouken@1895
   442
        or          eax,eax
slouken@1895
   443
        jne         L3
slouken@1895
   444
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   445
        mov         eax,dword ptr [esp+14h]
slouken@1895
   446
        xor         edx,edx
slouken@1895
   447
        div         ecx
slouken@1895
   448
        mov         ebx,eax
slouken@1895
   449
        mov         eax,dword ptr [esp+10h]
slouken@1895
   450
        div         ecx
slouken@1895
   451
        mov         edx,ebx
slouken@1895
   452
        jmp         L4
slouken@1346
   453
L3:
slouken@1895
   454
        mov         ebx,eax
slouken@1895
   455
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   456
        mov         edx,dword ptr [esp+14h]
slouken@1895
   457
        mov         eax,dword ptr [esp+10h]
slouken@1346
   458
L5:
slouken@1895
   459
        shr         ebx,1
slouken@1895
   460
        rcr         ecx,1
slouken@1895
   461
        shr         edx,1
slouken@1895
   462
        rcr         eax,1
slouken@1895
   463
        or          ebx,ebx
slouken@1895
   464
        jne         L5
slouken@1895
   465
        div         ecx
slouken@1895
   466
        mov         esi,eax
slouken@1895
   467
        mul         dword ptr [esp+1Ch]
slouken@1895
   468
        mov         ecx,eax
slouken@1895
   469
        mov         eax,dword ptr [esp+18h]
slouken@1895
   470
        mul         esi
slouken@1895
   471
        add         edx,ecx
slouken@1895
   472
        jb          L6
slouken@1895
   473
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   474
        ja          L6
slouken@1895
   475
        jb          L7
slouken@1895
   476
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   477
        jbe         L7
slouken@1346
   478
L6:
slouken@1895
   479
        dec         esi
slouken@1346
   480
L7:
slouken@1895
   481
        xor         edx,edx
slouken@1895
   482
        mov         eax,esi
slouken@1346
   483
L4:
slouken@1895
   484
        dec         edi
slouken@1895
   485
        jne         L8
slouken@1895
   486
        neg         edx
slouken@1895
   487
        neg         eax
slouken@1895
   488
        sbb         edx,0
slouken@1346
   489
L8:
slouken@1895
   490
        pop         ebx
slouken@1895
   491
        pop         esi
slouken@1895
   492
        pop         edi
slouken@1895
   493
        ret         10h
slouken@1895
   494
    }
slouken@1895
   495
    /* *INDENT-ON* */
slouken@1330
   496
}
slouken@2735
   497
slouken@1895
   498
void
slouken@1895
   499
__declspec(naked)
slouken@1895
   500
_aulldiv()
slouken@1330
   501
{
slouken@1895
   502
    /* *INDENT-OFF* */
slouken@1895
   503
    __asm {
slouken@1895
   504
        push        ebx
slouken@1895
   505
        push        esi
slouken@1895
   506
        mov         eax,dword ptr [esp+18h]
slouken@1895
   507
        or          eax,eax
slouken@1895
   508
        jne         L1
slouken@1895
   509
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   510
        mov         eax,dword ptr [esp+10h]
slouken@1895
   511
        xor         edx,edx
slouken@1895
   512
        div         ecx
slouken@1895
   513
        mov         ebx,eax
slouken@1895
   514
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   515
        div         ecx
slouken@1895
   516
        mov         edx,ebx
slouken@1895
   517
        jmp         L2
slouken@1346
   518
L1:
slouken@1895
   519
        mov         ecx,eax
slouken@1895
   520
        mov         ebx,dword ptr [esp+14h]
slouken@1895
   521
        mov         edx,dword ptr [esp+10h]
slouken@1895
   522
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   523
L3:
slouken@1895
   524
        shr         ecx,1
slouken@1895
   525
        rcr         ebx,1
slouken@1895
   526
        shr         edx,1
slouken@1895
   527
        rcr         eax,1
slouken@1895
   528
        or          ecx,ecx
slouken@1895
   529
        jne         L3
slouken@1895
   530
        div         ebx
slouken@1895
   531
        mov         esi,eax
slouken@1895
   532
        mul         dword ptr [esp+18h]
slouken@1895
   533
        mov         ecx,eax
slouken@1895
   534
        mov         eax,dword ptr [esp+14h]
slouken@1895
   535
        mul         esi
slouken@1895
   536
        add         edx,ecx
slouken@1895
   537
        jb          L4
slouken@1895
   538
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   539
        ja          L4
slouken@1895
   540
        jb          L5
slouken@1895
   541
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   542
        jbe         L5
slouken@1346
   543
L4:
slouken@1895
   544
        dec         esi
slouken@1346
   545
L5:
slouken@1895
   546
        xor         edx,edx
slouken@1895
   547
        mov         eax,esi
slouken@1346
   548
L2:
slouken@1895
   549
        pop         esi
slouken@1895
   550
        pop         ebx
slouken@1895
   551
        ret         10h
slouken@1895
   552
    }
slouken@1895
   553
    /* *INDENT-ON* */
slouken@1330
   554
}
slouken@2735
   555
slouken@1895
   556
void
slouken@1895
   557
__declspec(naked)
slouken@1895
   558
_allrem()
slouken@1330
   559
{
slouken@1895
   560
    /* *INDENT-OFF* */
slouken@1895
   561
    __asm {
slouken@1895
   562
        push        ebx
slouken@1895
   563
        push        edi
slouken@1895
   564
        xor         edi,edi
slouken@1895
   565
        mov         eax,dword ptr [esp+10h]
slouken@1895
   566
        or          eax,eax
slouken@1895
   567
        jge         L1
slouken@1895
   568
        inc         edi
slouken@1895
   569
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   570
        neg         eax
slouken@1895
   571
        neg         edx
slouken@1895
   572
        sbb         eax,0
slouken@1895
   573
        mov         dword ptr [esp+10h],eax
slouken@1895
   574
        mov         dword ptr [esp+0Ch],edx
slouken@1346
   575
L1:
slouken@1895
   576
        mov         eax,dword ptr [esp+18h]
slouken@1895
   577
        or          eax,eax
slouken@1895
   578
        jge         L2
slouken@1895
   579
        mov         edx,dword ptr [esp+14h]
slouken@1895
   580
        neg         eax
slouken@1895
   581
        neg         edx
slouken@1895
   582
        sbb         eax,0
slouken@1895
   583
        mov         dword ptr [esp+18h],eax
slouken@1895
   584
        mov         dword ptr [esp+14h],edx
slouken@1346
   585
L2:
slouken@1895
   586
        or          eax,eax
slouken@1895
   587
        jne         L3
slouken@1895
   588
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   589
        mov         eax,dword ptr [esp+10h]
slouken@1895
   590
        xor         edx,edx
slouken@1895
   591
        div         ecx
slouken@1895
   592
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   593
        div         ecx
slouken@1895
   594
        mov         eax,edx
slouken@1895
   595
        xor         edx,edx
slouken@1895
   596
        dec         edi
slouken@1895
   597
        jns         L4
slouken@1895
   598
        jmp         L8
slouken@1346
   599
L3:
slouken@1895
   600
        mov         ebx,eax
slouken@1895
   601
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   602
        mov         edx,dword ptr [esp+10h]
slouken@1895
   603
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   604
L5:
slouken@1895
   605
        shr         ebx,1
slouken@1895
   606
        rcr         ecx,1
slouken@1895
   607
        shr         edx,1
slouken@1895
   608
        rcr         eax,1
slouken@1895
   609
        or          ebx,ebx
slouken@1895
   610
        jne         L5
slouken@1895
   611
        div         ecx
slouken@1895
   612
        mov         ecx,eax
slouken@1895
   613
        mul         dword ptr [esp+18h]
slouken@1895
   614
        xchg        eax,ecx
slouken@1895
   615
        mul         dword ptr [esp+14h]
slouken@1895
   616
        add         edx,ecx
slouken@1895
   617
        jb          L6
slouken@1895
   618
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   619
        ja          L6
slouken@1895
   620
        jb          L7
slouken@1895
   621
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   622
        jbe         L7
slouken@1346
   623
L6:
slouken@1895
   624
        sub         eax,dword ptr [esp+14h]
slouken@1895
   625
        sbb         edx,dword ptr [esp+18h]
slouken@1346
   626
L7:
slouken@1895
   627
        sub         eax,dword ptr [esp+0Ch]
slouken@1895
   628
        sbb         edx,dword ptr [esp+10h]
slouken@1895
   629
        dec         edi
slouken@1895
   630
        jns         L8
slouken@1346
   631
L4:
slouken@1895
   632
        neg         edx
slouken@1895
   633
        neg         eax
slouken@1895
   634
        sbb         edx,0
slouken@1346
   635
L8:
slouken@1895
   636
        pop         edi
slouken@1895
   637
        pop         ebx
slouken@1895
   638
        ret         10h
slouken@1895
   639
    }
slouken@1895
   640
    /* *INDENT-ON* */
slouken@1330
   641
}
slouken@2735
   642
slouken@1895
   643
void
slouken@1895
   644
__declspec(naked)
slouken@1895
   645
_aullrem()
slouken@1330
   646
{
slouken@1895
   647
    /* *INDENT-OFF* */
slouken@1895
   648
    __asm {
slouken@1895
   649
        push        ebx
slouken@1895
   650
        mov         eax,dword ptr [esp+14h]
slouken@1895
   651
        or          eax,eax
slouken@1895
   652
        jne         L1
slouken@1895
   653
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   654
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   655
        xor         edx,edx
slouken@1895
   656
        div         ecx
slouken@1895
   657
        mov         eax,dword ptr [esp+8]
slouken@1895
   658
        div         ecx
slouken@1895
   659
        mov         eax,edx
slouken@1895
   660
        xor         edx,edx
slouken@1895
   661
        jmp         L2
slouken@1346
   662
L1:
slouken@1895
   663
        mov         ecx,eax
slouken@1895
   664
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   665
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   666
        mov         eax,dword ptr [esp+8]
slouken@1346
   667
L3:
slouken@1895
   668
        shr         ecx,1
slouken@1895
   669
        rcr         ebx,1
slouken@1895
   670
        shr         edx,1
slouken@1895
   671
        rcr         eax,1
slouken@1895
   672
        or          ecx,ecx
slouken@1895
   673
        jne         L3
slouken@1895
   674
        div         ebx
slouken@1895
   675
        mov         ecx,eax
slouken@1895
   676
        mul         dword ptr [esp+14h]
slouken@1895
   677
        xchg        eax,ecx
slouken@1895
   678
        mul         dword ptr [esp+10h]
slouken@1895
   679
        add         edx,ecx
slouken@1895
   680
        jb          L4
slouken@1895
   681
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   682
        ja          L4
slouken@1895
   683
        jb          L5
slouken@1895
   684
        cmp         eax,dword ptr [esp+8]
slouken@1895
   685
        jbe         L5
slouken@1346
   686
L4:
slouken@1895
   687
        sub         eax,dword ptr [esp+10h]
slouken@1895
   688
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   689
L5:
slouken@1895
   690
        sub         eax,dword ptr [esp+8]
slouken@1895
   691
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   692
        neg         edx
slouken@1895
   693
        neg         eax
slouken@1895
   694
        sbb         edx,0
slouken@1346
   695
L2:
slouken@1895
   696
        pop         ebx
slouken@1895
   697
        ret         10h
slouken@1895
   698
    }
slouken@1895
   699
    /* *INDENT-ON* */
slouken@1330
   700
}
slouken@2735
   701
slouken@1895
   702
void
slouken@1895
   703
__declspec(naked)
slouken@1895
   704
_alldvrm()
slouken@1330
   705
{
slouken@1895
   706
    /* *INDENT-OFF* */
slouken@1895
   707
    __asm {
slouken@1895
   708
        push        edi
slouken@1895
   709
        push        esi
slouken@1895
   710
        push        ebp
slouken@1895
   711
        xor         edi,edi
slouken@1895
   712
        xor         ebp,ebp
slouken@1895
   713
        mov         eax,dword ptr [esp+14h]
slouken@1895
   714
        or          eax,eax
slouken@1895
   715
        jge         L1
slouken@1895
   716
        inc         edi
slouken@1895
   717
        inc         ebp
slouken@1895
   718
        mov         edx,dword ptr [esp+10h]
slouken@1895
   719
        neg         eax
slouken@1895
   720
        neg         edx
slouken@1895
   721
        sbb         eax,0
slouken@1895
   722
        mov         dword ptr [esp+14h],eax
slouken@1895
   723
        mov         dword ptr [esp+10h],edx
slouken@1346
   724
L1:
slouken@1895
   725
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   726
        or          eax,eax
slouken@1895
   727
        jge         L2
slouken@1895
   728
        inc         edi
slouken@1895
   729
        mov         edx,dword ptr [esp+18h]
slouken@1895
   730
        neg         eax
slouken@1895
   731
        neg         edx
slouken@1895
   732
        sbb         eax,0
slouken@1895
   733
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   734
        mov         dword ptr [esp+18h],edx
slouken@1346
   735
L2:
slouken@1895
   736
        or          eax,eax
slouken@1895
   737
        jne         L3
slouken@1895
   738
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   739
        mov         eax,dword ptr [esp+14h]
slouken@1895
   740
        xor         edx,edx
slouken@1895
   741
        div         ecx
slouken@1895
   742
        mov         ebx,eax
slouken@1895
   743
        mov         eax,dword ptr [esp+10h]
slouken@1895
   744
        div         ecx
slouken@1895
   745
        mov         esi,eax
slouken@1895
   746
        mov         eax,ebx
slouken@1895
   747
        mul         dword ptr [esp+18h]
slouken@1895
   748
        mov         ecx,eax
slouken@1895
   749
        mov         eax,esi
slouken@1895
   750
        mul         dword ptr [esp+18h]
slouken@1895
   751
        add         edx,ecx
slouken@1895
   752
        jmp         L4
slouken@1346
   753
L3:
slouken@1895
   754
        mov         ebx,eax
slouken@1895
   755
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   756
        mov         edx,dword ptr [esp+14h]
slouken@1895
   757
        mov         eax,dword ptr [esp+10h]
slouken@1346
   758
L5:
slouken@1895
   759
        shr         ebx,1
slouken@1895
   760
        rcr         ecx,1
slouken@1895
   761
        shr         edx,1
slouken@1895
   762
        rcr         eax,1
slouken@1895
   763
        or          ebx,ebx
slouken@1895
   764
        jne         L5
slouken@1895
   765
        div         ecx
slouken@1895
   766
        mov         esi,eax
slouken@1895
   767
        mul         dword ptr [esp+1Ch]
slouken@1895
   768
        mov         ecx,eax
slouken@1895
   769
        mov         eax,dword ptr [esp+18h]
slouken@1895
   770
        mul         esi
slouken@1895
   771
        add         edx,ecx
slouken@1895
   772
        jb          L6
slouken@1895
   773
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   774
        ja          L6
slouken@1895
   775
        jb          L7
slouken@1895
   776
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   777
        jbe         L7
slouken@1346
   778
L6:
slouken@1895
   779
        dec         esi
slouken@1895
   780
        sub         eax,dword ptr [esp+18h]
slouken@1895
   781
        sbb         edx,dword ptr [esp+1Ch]
slouken@1346
   782
L7:
slouken@1895
   783
        xor         ebx,ebx
slouken@1346
   784
L4:
slouken@1895
   785
        sub         eax,dword ptr [esp+10h]
slouken@1895
   786
        sbb         edx,dword ptr [esp+14h]
slouken@1895
   787
        dec         ebp
slouken@1895
   788
        jns         L9
slouken@1895
   789
        neg         edx
slouken@1895
   790
        neg         eax
slouken@1895
   791
        sbb         edx,0
slouken@1346
   792
L9:
slouken@1895
   793
        mov         ecx,edx
slouken@1895
   794
        mov         edx,ebx
slouken@1895
   795
        mov         ebx,ecx
slouken@1895
   796
        mov         ecx,eax
slouken@1895
   797
        mov         eax,esi
slouken@1895
   798
        dec         edi
slouken@1895
   799
        jne         L8
slouken@1895
   800
        neg         edx
slouken@1895
   801
        neg         eax
slouken@1895
   802
        sbb         edx,0
slouken@1346
   803
L8:
slouken@1895
   804
        pop         ebp
slouken@1895
   805
        pop         esi
slouken@1895
   806
        pop         edi
slouken@1895
   807
        ret         10h
slouken@1895
   808
    }
slouken@1895
   809
    /* *INDENT-ON* */
slouken@1330
   810
}
slouken@2735
   811
slouken@1895
   812
void
slouken@1895
   813
__declspec(naked)
slouken@1895
   814
_aulldvrm()
slouken@1330
   815
{
slouken@1895
   816
    /* *INDENT-OFF* */
slouken@1895
   817
    __asm {
slouken@1895
   818
        push        esi
slouken@1895
   819
        mov         eax,dword ptr [esp+14h]
slouken@1895
   820
        or          eax,eax
slouken@1895
   821
        jne         L1
slouken@1895
   822
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   823
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   824
        xor         edx,edx
slouken@1895
   825
        div         ecx
slouken@1895
   826
        mov         ebx,eax
slouken@1895
   827
        mov         eax,dword ptr [esp+8]
slouken@1895
   828
        div         ecx
slouken@1895
   829
        mov         esi,eax
slouken@1895
   830
        mov         eax,ebx
slouken@1895
   831
        mul         dword ptr [esp+10h]
slouken@1895
   832
        mov         ecx,eax
slouken@1895
   833
        mov         eax,esi
slouken@1895
   834
        mul         dword ptr [esp+10h]
slouken@1895
   835
        add         edx,ecx
slouken@1895
   836
        jmp         L2
slouken@1346
   837
L1:
slouken@1895
   838
        mov         ecx,eax
slouken@1895
   839
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   840
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   841
        mov         eax,dword ptr [esp+8]
slouken@1346
   842
L3:
slouken@1895
   843
        shr         ecx,1
slouken@1895
   844
        rcr         ebx,1
slouken@1895
   845
        shr         edx,1
slouken@1895
   846
        rcr         eax,1
slouken@1895
   847
        or          ecx,ecx
slouken@1895
   848
        jne         L3
slouken@1895
   849
        div         ebx
slouken@1895
   850
        mov         esi,eax
slouken@1895
   851
        mul         dword ptr [esp+14h]
slouken@1895
   852
        mov         ecx,eax
slouken@1895
   853
        mov         eax,dword ptr [esp+10h]
slouken@1895
   854
        mul         esi
slouken@1895
   855
        add         edx,ecx
slouken@1895
   856
        jb          L4
slouken@1895
   857
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   858
        ja          L4
slouken@1895
   859
        jb          L5
slouken@1895
   860
        cmp         eax,dword ptr [esp+8]
slouken@1895
   861
        jbe         L5
slouken@1346
   862
L4:
slouken@1895
   863
        dec         esi
slouken@1895
   864
        sub         eax,dword ptr [esp+10h]
slouken@1895
   865
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   866
L5:
slouken@1895
   867
        xor         ebx,ebx
slouken@1346
   868
L2:
slouken@1895
   869
        sub         eax,dword ptr [esp+8]
slouken@1895
   870
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   871
        neg         edx
slouken@1895
   872
        neg         eax
slouken@1895
   873
        sbb         edx,0
slouken@1895
   874
        mov         ecx,edx
slouken@1895
   875
        mov         edx,ebx
slouken@1895
   876
        mov         ebx,ecx
slouken@1895
   877
        mov         ecx,eax
slouken@1895
   878
        mov         eax,esi
slouken@1895
   879
        pop         esi
slouken@1895
   880
        ret         10h
slouken@1895
   881
    }
slouken@1895
   882
    /* *INDENT-ON* */
slouken@1330
   883
}
slouken@2735
   884
slouken@1895
   885
void
slouken@1895
   886
__declspec(naked)
slouken@1895
   887
_allshl()
slouken@1330
   888
{
slouken@1895
   889
    /* *INDENT-OFF* */
slouken@1895
   890
    __asm {
slouken@1895
   891
        cmp         cl,40h
slouken@1895
   892
        jae         RETZERO
slouken@1895
   893
        cmp         cl,20h
slouken@1895
   894
        jae         MORE32
slouken@1895
   895
        shld        edx,eax,cl
slouken@1895
   896
        shl         eax,cl
slouken@1895
   897
        ret
slouken@1346
   898
MORE32:
slouken@1895
   899
        mov         edx,eax
slouken@1895
   900
        xor         eax,eax
slouken@1895
   901
        and         cl,1Fh
slouken@1895
   902
        shl         edx,cl
slouken@1895
   903
        ret
slouken@1346
   904
RETZERO:
slouken@1895
   905
        xor         eax,eax
slouken@1895
   906
        xor         edx,edx
slouken@1895
   907
        ret
slouken@1895
   908
    }
slouken@1895
   909
    /* *INDENT-ON* */
slouken@1330
   910
}
slouken@2735
   911
slouken@1895
   912
void
slouken@1895
   913
__declspec(naked)
slouken@2760
   914
_allshr()
slouken@2760
   915
{
slouken@2760
   916
    /* *INDENT-OFF* */
slouken@2760
   917
    __asm {
slouken@2760
   918
        cmp         cl,40h
slouken@2760
   919
        jae         RETZERO
slouken@2760
   920
        cmp         cl,20h
slouken@2760
   921
        jae         MORE32
slouken@2760
   922
        shrd        eax,edx,cl
slouken@2760
   923
        sar         edx,cl
slouken@2760
   924
        ret
slouken@2760
   925
MORE32:
slouken@2760
   926
        mov         eax,edx
slouken@2760
   927
        xor         edx,edx
slouken@2760
   928
        and         cl,1Fh
slouken@2760
   929
        sar         eax,cl
slouken@2760
   930
        ret
slouken@2760
   931
RETZERO:
slouken@2760
   932
        xor         eax,eax
slouken@2760
   933
        xor         edx,edx
slouken@2760
   934
        ret
slouken@2760
   935
    }
slouken@2760
   936
    /* *INDENT-ON* */
slouken@2760
   937
}
slouken@2760
   938
slouken@2760
   939
void
slouken@2760
   940
__declspec(naked)
slouken@1895
   941
_aullshr()
slouken@1330
   942
{
slouken@1895
   943
    /* *INDENT-OFF* */
slouken@1895
   944
    __asm {
slouken@1895
   945
        cmp         cl,40h
slouken@1895
   946
        jae         RETZERO
slouken@1895
   947
        cmp         cl,20h
slouken@1895
   948
        jae         MORE32
slouken@1895
   949
        shrd        eax,edx,cl
slouken@1895
   950
        shr         edx,cl
slouken@1895
   951
        ret
slouken@1346
   952
MORE32:
slouken@1895
   953
        mov         eax,edx
slouken@1895
   954
        xor         edx,edx
slouken@1895
   955
        and         cl,1Fh
slouken@1895
   956
        shr         eax,cl
slouken@1895
   957
        ret
slouken@1346
   958
RETZERO:
slouken@1895
   959
        xor         eax,eax
slouken@1895
   960
        xor         edx,edx
slouken@1895
   961
        ret
slouken@1895
   962
    }
slouken@1895
   963
    /* *INDENT-ON* */
slouken@1330
   964
}
slouken@1330
   965
slouken@5455
   966
#endif /* _M_IX86 */
slouken@3255
   967
slouken@1330
   968
#endif /* MSC_VER */
slouken@1330
   969
slouken@1331
   970
#endif /* !HAVE_LIBC */
slouken@1895
   971
slouken@1895
   972
/* vi: set ts=4 sw=4 expandtab: */