src/stdlib/SDL_stdlib.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 24 Nov 2013 23:56:17 -0500
changeset 8093 b43765095a6f
parent 8056 abd9434c5d3e
child 8149 681eb46b8ac4
permissions -rw-r--r--
Make internal SDL sources include SDL_internal.h instead of SDL_config.h

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