src/stdlib/SDL_stdlib.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 08 Sep 2014 01:36:22 -0400
changeset 9126 08f3b56969b1
parent 9080 2e4e71ec140f
child 9306 817656bd36ec
permissions -rw-r--r--
Deal with various .bmp file format variants in SDL_LoadBMP_RW().

This helps when modern versions of The Gimp (and lots of other things)
produces a 32-bit bitmap with an alpha channel, or anything with "BI_BITFIELDS"
format, since that data is now embedded in the bitmap info header instead of
directly following it and we would accidentally skip over embedded versions of
it.

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