src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Jan 2016 10:25:53 -0800
changeset 9999 4de94185790e
parent 9998 f67cf37e9cd4
child 10001 e12c38730512
permissions -rw-r--r--
Fixed bug 3092 - Statically link sdl2 with /MT for msvc

Martin Gerhardy

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