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