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