src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Aug 2017 16:30:24 -0700
changeset 11341 8b3231952c22
parent 10737 3406a0f8b041
child 11404 bd5b569b2a1b
permissions -rw-r--r--
Fixed bug 3768 - provide a quick copysign() solution for watcom

Ozkan Sezer

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