src/stdlib/SDL_stdlib.c
author David Ludwig <dludwig@pobox.com>
Thu, 28 Nov 2013 22:09:21 -0500
changeset 8543 b9dd3cf38585
parent 8478 337b5dc0797b
parent 8033 8181c3a4a055
child 8583 fb2933ca805f
permissions -rw-r--r--
WinRT: merged with latest SDL 2.x/HG code

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