src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 04 Nov 2017 17:35:03 -0700
changeset 11684 eccdf37f8996
parent 11682 b26412a89fbb
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Added SDL_fmod() and SDL_fmodf()
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@11682
    41
#endif
slouken@11682
    42
}
slouken@11682
    43
slouken@11682
    44
float
slouken@11682
    45
SDL_atanf(float x)
slouken@11682
    46
{
slouken@11682
    47
#if defined(HAVE_ATANF)
slouken@11682
    48
    return atanf(x);
slouken@11682
    49
#else
slouken@11682
    50
    return (float)SDL_atan((double)x);
slouken@11682
    51
#endif
slouken@7351
    52
}
slouken@7351
    53
slouken@7351
    54
double
slouken@7351
    55
SDL_atan2(double x, double y)
slouken@7351
    56
{
slouken@7351
    57
#if defined(HAVE_ATAN2)
slouken@7351
    58
    return atan2(x, y);
slouken@7351
    59
#else
slouken@7351
    60
    return SDL_uclibc_atan2(x, y);
slouken@11682
    61
#endif
slouken@11682
    62
}
slouken@11682
    63
slouken@11682
    64
float
slouken@11682
    65
SDL_atan2f(float x, float y)
slouken@11682
    66
{
slouken@11682
    67
#if defined(HAVE_ATAN2F)
slouken@11682
    68
    return atan2f(x, y);
slouken@11682
    69
#else
slouken@11682
    70
    return (float)SDL_atan2((double)x, (double)y);
slouken@11682
    71
#endif
slouken@7351
    72
}
slouken@7351
    73
slouken@7351
    74
double
icculus@8056
    75
SDL_acos(double val)
icculus@8056
    76
{
icculus@8056
    77
#if defined(HAVE_ACOS)
icculus@8056
    78
    return acos(val);
icculus@8056
    79
#else
icculus@8056
    80
    double result;
icculus@8056
    81
    if (val == -1.0) {
icculus@8056
    82
        result = M_PI;
icculus@8056
    83
    } else {
icculus@8056
    84
        result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
icculus@8056
    85
        if (result < 0.0)
icculus@8056
    86
        {
icculus@8056
    87
            result += M_PI;
icculus@8056
    88
        }
icculus@8056
    89
    }
icculus@8056
    90
    return result;
icculus@8056
    91
#endif
icculus@8056
    92
}
icculus@8056
    93
slouken@11682
    94
float
slouken@11682
    95
SDL_acosf(float val)
slouken@11682
    96
{
slouken@11682
    97
#if defined(HAVE_ACOSF)
slouken@11682
    98
    return acosf(val);
slouken@11682
    99
#else
slouken@11682
   100
    return (float)SDL_acos((double)val);
slouken@11682
   101
#endif
slouken@11682
   102
}
slouken@11682
   103
icculus@8056
   104
double
icculus@8056
   105
SDL_asin(double val)
icculus@8056
   106
{
icculus@8056
   107
#if defined(HAVE_ASIN)
icculus@8056
   108
    return asin(val);
icculus@8056
   109
#else
icculus@8056
   110
    double result;
icculus@8056
   111
    if (val == -1.0) {
icculus@8056
   112
        result = -(M_PI / 2.0);
icculus@8056
   113
    } else {
icculus@8056
   114
        result = (M_PI / 2.0) - SDL_acos(val);
icculus@8056
   115
    }
icculus@8056
   116
    return result;
icculus@8056
   117
#endif
icculus@8056
   118
}
icculus@8056
   119
slouken@11682
   120
float
slouken@11682
   121
SDL_asinf(float val)
slouken@11682
   122
{
slouken@11682
   123
#if defined(HAVE_ASINF)
slouken@11682
   124
    return asinf(val);
slouken@11682
   125
#else
slouken@11682
   126
    return (float)SDL_asin((double)val);
slouken@11682
   127
#endif
slouken@11682
   128
}
slouken@11682
   129
icculus@8056
   130
double
slouken@7351
   131
SDL_ceil(double x)
slouken@7351
   132
{
slouken@10505
   133
#if defined(HAVE_CEIL)
slouken@7351
   134
    return ceil(x);
slouken@7351
   135
#else
slouken@8033
   136
    double integer = SDL_floor(x);
slouken@8033
   137
    double fraction = x - integer;
slouken@8033
   138
    if (fraction > 0.0) {
slouken@8033
   139
        integer += 1.0;
slouken@8033
   140
    }
slouken@8033
   141
    return integer;
slouken@7351
   142
#endif /* HAVE_CEIL */
slouken@7351
   143
}
slouken@7351
   144
slouken@11682
   145
float
slouken@11682
   146
SDL_ceilf(float x)
slouken@11682
   147
{
slouken@11682
   148
#if defined(HAVE_CEILF)
slouken@11682
   149
    return ceilf(x);
slouken@11682
   150
#else
slouken@11684
   151
    return (float)SDL_ceil((float)x);
slouken@11682
   152
#endif
slouken@11682
   153
}
slouken@11682
   154
slouken@7351
   155
double
slouken@7351
   156
SDL_copysign(double x, double y)
slouken@7351
   157
{
slouken@7351
   158
#if defined(HAVE_COPYSIGN)
slouken@7351
   159
    return copysign(x, y);
dludwig@8478
   160
#elif defined(HAVE__COPYSIGN)
dludwig@8478
   161
    return _copysign(x, y);
slouken@11341
   162
#elif defined(__WATCOMC__) && defined(__386__)
slouken@11341
   163
    /* this is nasty as hell, but it works.. */
slouken@11341
   164
    unsigned int *xi = (unsigned int *) &x,
slouken@11341
   165
                 *yi = (unsigned int *) &y;
slouken@11341
   166
    xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
slouken@11341
   167
    return x;
slouken@7351
   168
#else
slouken@7351
   169
    return SDL_uclibc_copysign(x, y);
slouken@7351
   170
#endif /* HAVE_COPYSIGN */
slouken@7351
   171
}
slouken@7351
   172
slouken@11682
   173
float
slouken@11682
   174
SDL_copysignf(float x, float y)
slouken@11682
   175
{
slouken@11682
   176
#if defined(HAVE_COPYSIGNF)
slouken@11682
   177
    return copysignf(x, y);
slouken@11682
   178
#else
slouken@11682
   179
    return (float)SDL_copysign((double)x, (double)y);
slouken@11682
   180
#endif
slouken@11682
   181
}
slouken@11682
   182
slouken@7351
   183
double
slouken@7351
   184
SDL_cos(double x)
slouken@7351
   185
{
slouken@7351
   186
#if defined(HAVE_COS)
slouken@7351
   187
    return cos(x);
slouken@7351
   188
#else
slouken@7351
   189
    return SDL_uclibc_cos(x);
slouken@11682
   190
#endif
slouken@7351
   191
}
slouken@7351
   192
slouken@7351
   193
float
slouken@7351
   194
SDL_cosf(float x)
slouken@7351
   195
{
slouken@10505
   196
#if defined(HAVE_COSF)
slouken@7351
   197
    return cosf(x);
slouken@7351
   198
#else
slouken@7351
   199
    return (float)SDL_cos((double)x);
slouken@7351
   200
#endif
slouken@7351
   201
}
slouken@7351
   202
slouken@7351
   203
double
slouken@7351
   204
SDL_fabs(double x)
slouken@7351
   205
{
slouken@7351
   206
#if defined(HAVE_FABS)
slouken@7351
   207
    return fabs(x); 
slouken@7351
   208
#else
slouken@7351
   209
    return SDL_uclibc_fabs(x);
slouken@11682
   210
#endif
slouken@11682
   211
}
slouken@11682
   212
slouken@11682
   213
float
slouken@11682
   214
SDL_fabsf(float x)
slouken@11682
   215
{
slouken@11682
   216
#if defined(HAVE_FABSF)
slouken@11682
   217
    return fabsf(x); 
slouken@11682
   218
#else
slouken@11682
   219
    return (float)SDL_fabs((double)x);
slouken@11682
   220
#endif
slouken@7351
   221
}
slouken@7351
   222
slouken@7351
   223
double
slouken@7351
   224
SDL_floor(double x)
slouken@7351
   225
{
slouken@7351
   226
#if defined(HAVE_FLOOR)
slouken@7351
   227
    return floor(x);
slouken@7351
   228
#else
slouken@7351
   229
    return SDL_uclibc_floor(x);
slouken@11682
   230
#endif
slouken@11682
   231
}
slouken@11682
   232
slouken@11682
   233
float
slouken@11682
   234
SDL_floorf(float x)
slouken@11682
   235
{
slouken@11682
   236
#if defined(HAVE_FLOORF)
slouken@11682
   237
    return floorf(x);
slouken@11682
   238
#else
slouken@11682
   239
    return (float)SDL_floor((double)x);
slouken@11682
   240
#endif
slouken@7351
   241
}
slouken@7351
   242
slouken@7351
   243
double
slouken@11684
   244
SDL_fmod(double x, double y)
slouken@11684
   245
{
slouken@11684
   246
#if defined(HAVE_FMOD)
slouken@11684
   247
    return fmod(x, y);
slouken@11684
   248
#else
slouken@11684
   249
    return SDL_uclibc_fmod(x, y);
slouken@11684
   250
#endif
slouken@11684
   251
}
slouken@11684
   252
slouken@11684
   253
float
slouken@11684
   254
SDL_fmodf(float x, float y)
slouken@11684
   255
{
slouken@11684
   256
#if defined(HAVE_FMODF)
slouken@11684
   257
    return fmodf(x, y);
slouken@11684
   258
#else
slouken@11684
   259
    return (float)SDL_fmod((double)x, (double)y);
slouken@11684
   260
#endif
slouken@11684
   261
}
slouken@11684
   262
slouken@11684
   263
double
slouken@7351
   264
SDL_log(double x)
slouken@7351
   265
{
slouken@7351
   266
#if defined(HAVE_LOG)
slouken@7351
   267
    return log(x);
slouken@7351
   268
#else
slouken@7351
   269
    return SDL_uclibc_log(x);
slouken@11682
   270
#endif
slouken@11682
   271
}
slouken@11682
   272
slouken@11682
   273
float
slouken@11682
   274
SDL_logf(float x)
slouken@11682
   275
{
slouken@11682
   276
#if defined(HAVE_LOGF)
slouken@11682
   277
    return logf(x);
slouken@11682
   278
#else
slouken@11682
   279
    return (float)SDL_log((double)x);
slouken@11682
   280
#endif
slouken@7351
   281
}
slouken@7351
   282
slouken@7351
   283
double
slouken@7351
   284
SDL_pow(double x, double y)
slouken@7351
   285
{
slouken@7351
   286
#if defined(HAVE_POW)
slouken@7351
   287
    return pow(x, y);
slouken@7351
   288
#else
slouken@7351
   289
    return SDL_uclibc_pow(x, y);
slouken@11682
   290
#endif
slouken@11682
   291
}
slouken@11682
   292
slouken@11682
   293
float
slouken@11682
   294
SDL_powf(float x, float y)
slouken@11682
   295
{
slouken@11682
   296
#if defined(HAVE_POWF)
slouken@11682
   297
    return powf(x, y);
slouken@11682
   298
#else
slouken@11682
   299
    return (float)SDL_pow((double)x, (double)y);
slouken@11682
   300
#endif
slouken@7351
   301
}
slouken@7351
   302
slouken@7351
   303
double
slouken@7351
   304
SDL_scalbn(double x, int n)
slouken@7351
   305
{
slouken@7351
   306
#if defined(HAVE_SCALBN)
slouken@7351
   307
    return scalbn(x, n);
dludwig@8478
   308
#elif defined(HAVE__SCALB)
dludwig@8478
   309
    return _scalb(x, n);
icculus@11404
   310
#elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
icculus@11404
   311
/* from scalbn(3): If FLT_RADIX equals 2 (which is
icculus@11404
   312
 * usual), then scalbn() is equivalent to ldexp(3). */
icculus@11404
   313
    return ldexp(x, n);
slouken@7351
   314
#else
slouken@7351
   315
    return SDL_uclibc_scalbn(x, n);
slouken@11682
   316
#endif
slouken@11682
   317
}
slouken@11682
   318
slouken@11682
   319
float
slouken@11682
   320
SDL_scalbnf(float x, int n)
slouken@11682
   321
{
slouken@11682
   322
#if defined(HAVE_SCALBNF)
slouken@11682
   323
    return scalbnf(x, n);
slouken@11682
   324
#else
slouken@11682
   325
    return (float)SDL_scalbn((double)x, n);
slouken@11682
   326
#endif
slouken@7351
   327
}
slouken@7351
   328
slouken@7351
   329
double
slouken@7351
   330
SDL_sin(double x)
slouken@7351
   331
{
slouken@7351
   332
#if defined(HAVE_SIN)
slouken@7351
   333
    return sin(x);
slouken@7351
   334
#else
slouken@7351
   335
    return SDL_uclibc_sin(x);
slouken@11682
   336
#endif
slouken@7351
   337
}
slouken@7351
   338
slouken@7351
   339
float 
slouken@7351
   340
SDL_sinf(float x)
slouken@7351
   341
{
slouken@10505
   342
#if defined(HAVE_SINF)
slouken@7351
   343
    return sinf(x);
slouken@7351
   344
#else
slouken@7351
   345
    return (float)SDL_sin((double)x);
slouken@11682
   346
#endif
slouken@7351
   347
}
slouken@7351
   348
slouken@7351
   349
double
slouken@7351
   350
SDL_sqrt(double x)
slouken@7351
   351
{
slouken@7351
   352
#if defined(HAVE_SQRT)
slouken@7351
   353
    return sqrt(x);
slouken@7351
   354
#else
slouken@7351
   355
    return SDL_uclibc_sqrt(x);
slouken@7351
   356
#endif
slouken@7351
   357
}
slouken@7351
   358
slouken@8840
   359
float
slouken@8840
   360
SDL_sqrtf(float x)
slouken@8840
   361
{
slouken@8840
   362
#if defined(HAVE_SQRTF)
slouken@8840
   363
    return sqrtf(x);
slouken@8840
   364
#else
slouken@8840
   365
    return (float)SDL_sqrt((double)x);
slouken@8840
   366
#endif
slouken@8840
   367
}
slouken@8840
   368
slouken@8840
   369
double
slouken@8840
   370
SDL_tan(double x)
slouken@8840
   371
{
slouken@8840
   372
#if defined(HAVE_TAN)
slouken@8840
   373
    return tan(x);
slouken@8840
   374
#else
slouken@8840
   375
    return SDL_uclibc_tan(x);
slouken@8840
   376
#endif
slouken@8840
   377
}
slouken@8840
   378
slouken@8840
   379
float
slouken@8840
   380
SDL_tanf(float x)
slouken@8840
   381
{
slouken@8840
   382
#if defined(HAVE_TANF)
slouken@8840
   383
    return tanf(x);
slouken@8840
   384
#else
slouken@8840
   385
    return (float)SDL_tan((double)x);
slouken@8840
   386
#endif
slouken@8840
   387
}
slouken@8840
   388
slouken@7351
   389
int SDL_abs(int x)
slouken@7351
   390
{
slouken@10505
   391
#if defined(HAVE_ABS)
slouken@7351
   392
    return abs(x);
slouken@7351
   393
#else
slouken@7351
   394
    return ((x) < 0 ? -(x) : (x));
slouken@7351
   395
#endif
slouken@7351
   396
}
slouken@7351
   397
slouken@10505
   398
#if defined(HAVE_CTYPE_H)
slouken@7351
   399
int SDL_isdigit(int x) { return isdigit(x); }
slouken@7351
   400
int SDL_isspace(int x) { return isspace(x); }
slouken@7351
   401
int SDL_toupper(int x) { return toupper(x); }
slouken@7351
   402
int SDL_tolower(int x) { return tolower(x); }
slouken@7351
   403
#else
slouken@7351
   404
int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
philipp@7357
   405
int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
slouken@7351
   406
int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
slouken@7351
   407
int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
slouken@7351
   408
#endif
icculus@7003
   409
icculus@7003
   410
slouken@1330
   411
#ifndef HAVE_LIBC
slouken@1330
   412
/* These are some C runtime intrinsics that need to be defined */
slouken@1330
   413
slouken@3255
   414
#if defined(_MSC_VER)
slouken@1330
   415
slouken@1433
   416
#ifndef __FLTUSED__
slouken@1433
   417
#define __FLTUSED__
slouken@3255
   418
__declspec(selectany) int _fltused = 1;
slouken@1433
   419
#endif
slouken@3255
   420
icculus@9716
   421
/* The optimizer on Visual Studio 2005 and later generates memcpy() calls */
slouken@10550
   422
#if (_MSC_VER >= 1400) && defined(_WIN64) && !defined(_DEBUG) && !(_MSC_VER >= 1900 && defined(_MT))
slouken@5455
   423
#include <intrin.h>
slouken@5455
   424
slouken@5455
   425
#pragma function(memcpy)
slouken@5455
   426
void * memcpy ( void * destination, const void * source, size_t num )
slouken@5455
   427
{
slouken@5455
   428
    const Uint8 *src = (const Uint8 *)source;
slouken@5455
   429
    Uint8 *dst = (Uint8 *)destination;
slouken@5455
   430
    size_t i;
slouken@5455
   431
    
slouken@5455
   432
    /* All WIN64 architectures have SSE, right? */
slouken@5455
   433
    if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
slouken@5455
   434
        __m128 values[4];
slouken@5455
   435
        for (i = num / 64; i--;) {
slouken@5455
   436
            _mm_prefetch(src, _MM_HINT_NTA);
slouken@5455
   437
            values[0] = *(__m128 *) (src + 0);
slouken@5455
   438
            values[1] = *(__m128 *) (src + 16);
slouken@5455
   439
            values[2] = *(__m128 *) (src + 32);
slouken@5455
   440
            values[3] = *(__m128 *) (src + 48);
slouken@5455
   441
            _mm_stream_ps((float *) (dst + 0), values[0]);
slouken@5455
   442
            _mm_stream_ps((float *) (dst + 16), values[1]);
slouken@5455
   443
            _mm_stream_ps((float *) (dst + 32), values[2]);
slouken@5455
   444
            _mm_stream_ps((float *) (dst + 48), values[3]);
slouken@5455
   445
            src += 64;
slouken@5455
   446
            dst += 64;
slouken@5455
   447
        }
slouken@5455
   448
        num &= 63;
slouken@5455
   449
    }
slouken@5455
   450
slouken@5455
   451
    while (num--) {
slouken@5455
   452
        *dst++ = *src++;
slouken@5455
   453
    }
slouken@5455
   454
    return destination;
slouken@5455
   455
}
slouken@5455
   456
#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
slouken@5455
   457
slouken@5086
   458
#ifdef _M_IX86
slouken@1433
   459
slouken@1346
   460
/* Float to long */
slouken@3253
   461
void
slouken@3253
   462
__declspec(naked)
slouken@3253
   463
_ftol()
slouken@1345
   464
{
slouken@1895
   465
    /* *INDENT-OFF* */
slouken@1895
   466
    __asm {
slouken@1895
   467
        push        ebp
slouken@1895
   468
        mov         ebp,esp
slouken@1895
   469
        sub         esp,20h
slouken@1895
   470
        and         esp,0FFFFFFF0h
slouken@1895
   471
        fld         st(0)
slouken@1895
   472
        fst         dword ptr [esp+18h]
slouken@1895
   473
        fistp       qword ptr [esp+10h]
slouken@1895
   474
        fild        qword ptr [esp+10h]
slouken@1895
   475
        mov         edx,dword ptr [esp+18h]
slouken@1895
   476
        mov         eax,dword ptr [esp+10h]
slouken@1895
   477
        test        eax,eax
slouken@1895
   478
        je          integer_QnaN_or_zero
slouken@1346
   479
arg_is_not_integer_QnaN:
slouken@1895
   480
        fsubp       st(1),st
slouken@1895
   481
        test        edx,edx
slouken@1895
   482
        jns         positive
slouken@1895
   483
        fstp        dword ptr [esp]
slouken@1895
   484
        mov         ecx,dword ptr [esp]
slouken@1895
   485
        xor         ecx,80000000h
slouken@1895
   486
        add         ecx,7FFFFFFFh
slouken@1895
   487
        adc         eax,0
slouken@1895
   488
        mov         edx,dword ptr [esp+14h]
slouken@1895
   489
        adc         edx,0
slouken@1895
   490
        jmp         localexit
slouken@1346
   491
positive:
slouken@1895
   492
        fstp        dword ptr [esp]
slouken@1895
   493
        mov         ecx,dword ptr [esp]
slouken@1895
   494
        add         ecx,7FFFFFFFh
slouken@1895
   495
        sbb         eax,0
slouken@1895
   496
        mov         edx,dword ptr [esp+14h]
slouken@1895
   497
        sbb         edx,0
slouken@1895
   498
        jmp         localexit
slouken@1346
   499
integer_QnaN_or_zero:
slouken@1895
   500
        mov         edx,dword ptr [esp+14h]
slouken@1895
   501
        test        edx,7FFFFFFFh
slouken@1895
   502
        jne         arg_is_not_integer_QnaN
slouken@1895
   503
        fstp        dword ptr [esp+18h]
slouken@1895
   504
        fstp        dword ptr [esp+18h]
slouken@1346
   505
localexit:
slouken@1895
   506
        leave
slouken@1895
   507
        ret
slouken@1895
   508
    }
slouken@1895
   509
    /* *INDENT-ON* */
slouken@1345
   510
}
slouken@1895
   511
slouken@1895
   512
void
slouken@1895
   513
_ftol2_sse()
slouken@1330
   514
{
slouken@1895
   515
    _ftol();
slouken@1330
   516
}
slouken@1330
   517
slouken@10587
   518
/* 64-bit math operators for 32-bit systems */
slouken@10587
   519
void
slouken@10587
   520
__declspec(naked)
slouken@10587
   521
_allmul()
slouken@10587
   522
{
slouken@10587
   523
    /* *INDENT-OFF* */
slouken@10587
   524
    __asm {
slouken@10587
   525
        mov         eax, dword ptr[esp+8]
slouken@10587
   526
        mov         ecx, dword ptr[esp+10h]
slouken@10587
   527
        or          ecx, eax
slouken@10587
   528
        mov         ecx, dword ptr[esp+0Ch]
slouken@10587
   529
        jne         hard
slouken@10587
   530
        mov         eax, dword ptr[esp+4]
slouken@10587
   531
        mul         ecx
slouken@10587
   532
        ret         10h
slouken@10587
   533
hard:
slouken@10587
   534
        push        ebx
slouken@10587
   535
        mul         ecx
slouken@10587
   536
        mov         ebx, eax
slouken@10587
   537
        mov         eax, dword ptr[esp+8]
slouken@10587
   538
        mul         dword ptr[esp+14h]
slouken@10587
   539
        add         ebx, eax
slouken@10587
   540
        mov         eax, dword ptr[esp+8]
slouken@10587
   541
        mul         ecx
slouken@10587
   542
        add         edx, ebx
slouken@10587
   543
        pop         ebx
slouken@10587
   544
        ret         10h
slouken@10587
   545
    }
slouken@10587
   546
    /* *INDENT-ON* */
slouken@1330
   547
}
slouken@2735
   548
slouken@1895
   549
void
slouken@1895
   550
__declspec(naked)
slouken@1895
   551
_alldiv()
slouken@1330
   552
{
slouken@1895
   553
    /* *INDENT-OFF* */
slouken@1895
   554
    __asm {
slouken@1895
   555
        push        edi
slouken@1895
   556
        push        esi
slouken@1895
   557
        push        ebx
slouken@1895
   558
        xor         edi,edi
slouken@1895
   559
        mov         eax,dword ptr [esp+14h]
slouken@1895
   560
        or          eax,eax
slouken@1895
   561
        jge         L1
slouken@1895
   562
        inc         edi
slouken@1895
   563
        mov         edx,dword ptr [esp+10h]
slouken@1895
   564
        neg         eax
slouken@1895
   565
        neg         edx
slouken@1895
   566
        sbb         eax,0
slouken@1895
   567
        mov         dword ptr [esp+14h],eax
slouken@1895
   568
        mov         dword ptr [esp+10h],edx
slouken@1346
   569
L1:
slouken@1895
   570
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   571
        or          eax,eax
slouken@1895
   572
        jge         L2
slouken@1895
   573
        inc         edi
slouken@1895
   574
        mov         edx,dword ptr [esp+18h]
slouken@1895
   575
        neg         eax
slouken@1895
   576
        neg         edx
slouken@1895
   577
        sbb         eax,0
slouken@1895
   578
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   579
        mov         dword ptr [esp+18h],edx
slouken@1346
   580
L2:
slouken@1895
   581
        or          eax,eax
slouken@1895
   582
        jne         L3
slouken@1895
   583
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   584
        mov         eax,dword ptr [esp+14h]
slouken@1895
   585
        xor         edx,edx
slouken@1895
   586
        div         ecx
slouken@1895
   587
        mov         ebx,eax
slouken@1895
   588
        mov         eax,dword ptr [esp+10h]
slouken@1895
   589
        div         ecx
slouken@1895
   590
        mov         edx,ebx
slouken@1895
   591
        jmp         L4
slouken@1346
   592
L3:
slouken@1895
   593
        mov         ebx,eax
slouken@1895
   594
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   595
        mov         edx,dword ptr [esp+14h]
slouken@1895
   596
        mov         eax,dword ptr [esp+10h]
slouken@1346
   597
L5:
slouken@1895
   598
        shr         ebx,1
slouken@1895
   599
        rcr         ecx,1
slouken@1895
   600
        shr         edx,1
slouken@1895
   601
        rcr         eax,1
slouken@1895
   602
        or          ebx,ebx
slouken@1895
   603
        jne         L5
slouken@1895
   604
        div         ecx
slouken@1895
   605
        mov         esi,eax
slouken@1895
   606
        mul         dword ptr [esp+1Ch]
slouken@1895
   607
        mov         ecx,eax
slouken@1895
   608
        mov         eax,dword ptr [esp+18h]
slouken@1895
   609
        mul         esi
slouken@1895
   610
        add         edx,ecx
slouken@1895
   611
        jb          L6
slouken@1895
   612
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   613
        ja          L6
slouken@1895
   614
        jb          L7
slouken@1895
   615
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   616
        jbe         L7
slouken@1346
   617
L6:
slouken@1895
   618
        dec         esi
slouken@1346
   619
L7:
slouken@1895
   620
        xor         edx,edx
slouken@1895
   621
        mov         eax,esi
slouken@1346
   622
L4:
slouken@1895
   623
        dec         edi
slouken@1895
   624
        jne         L8
slouken@1895
   625
        neg         edx
slouken@1895
   626
        neg         eax
slouken@1895
   627
        sbb         edx,0
slouken@1346
   628
L8:
slouken@1895
   629
        pop         ebx
slouken@1895
   630
        pop         esi
slouken@1895
   631
        pop         edi
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
_aulldiv()
slouken@1330
   640
{
slouken@1895
   641
    /* *INDENT-OFF* */
slouken@1895
   642
    __asm {
slouken@1895
   643
        push        ebx
slouken@1895
   644
        push        esi
slouken@1895
   645
        mov         eax,dword ptr [esp+18h]
slouken@1895
   646
        or          eax,eax
slouken@1895
   647
        jne         L1
slouken@1895
   648
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   649
        mov         eax,dword ptr [esp+10h]
slouken@1895
   650
        xor         edx,edx
slouken@1895
   651
        div         ecx
slouken@1895
   652
        mov         ebx,eax
slouken@1895
   653
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   654
        div         ecx
slouken@1895
   655
        mov         edx,ebx
slouken@1895
   656
        jmp         L2
slouken@1346
   657
L1:
slouken@1895
   658
        mov         ecx,eax
slouken@1895
   659
        mov         ebx,dword ptr [esp+14h]
slouken@1895
   660
        mov         edx,dword ptr [esp+10h]
slouken@1895
   661
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   662
L3:
slouken@1895
   663
        shr         ecx,1
slouken@1895
   664
        rcr         ebx,1
slouken@1895
   665
        shr         edx,1
slouken@1895
   666
        rcr         eax,1
slouken@1895
   667
        or          ecx,ecx
slouken@1895
   668
        jne         L3
slouken@1895
   669
        div         ebx
slouken@1895
   670
        mov         esi,eax
slouken@1895
   671
        mul         dword ptr [esp+18h]
slouken@1895
   672
        mov         ecx,eax
slouken@1895
   673
        mov         eax,dword ptr [esp+14h]
slouken@1895
   674
        mul         esi
slouken@1895
   675
        add         edx,ecx
slouken@1895
   676
        jb          L4
slouken@1895
   677
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   678
        ja          L4
slouken@1895
   679
        jb          L5
slouken@1895
   680
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   681
        jbe         L5
slouken@1346
   682
L4:
slouken@1895
   683
        dec         esi
slouken@1346
   684
L5:
slouken@1895
   685
        xor         edx,edx
slouken@1895
   686
        mov         eax,esi
slouken@1346
   687
L2:
slouken@1895
   688
        pop         esi
slouken@1895
   689
        pop         ebx
slouken@1895
   690
        ret         10h
slouken@1895
   691
    }
slouken@1895
   692
    /* *INDENT-ON* */
slouken@1330
   693
}
slouken@2735
   694
slouken@1895
   695
void
slouken@1895
   696
__declspec(naked)
slouken@1895
   697
_allrem()
slouken@1330
   698
{
slouken@1895
   699
    /* *INDENT-OFF* */
slouken@1895
   700
    __asm {
slouken@1895
   701
        push        ebx
slouken@1895
   702
        push        edi
slouken@1895
   703
        xor         edi,edi
slouken@1895
   704
        mov         eax,dword ptr [esp+10h]
slouken@1895
   705
        or          eax,eax
slouken@1895
   706
        jge         L1
slouken@1895
   707
        inc         edi
slouken@1895
   708
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   709
        neg         eax
slouken@1895
   710
        neg         edx
slouken@1895
   711
        sbb         eax,0
slouken@1895
   712
        mov         dword ptr [esp+10h],eax
slouken@1895
   713
        mov         dword ptr [esp+0Ch],edx
slouken@1346
   714
L1:
slouken@1895
   715
        mov         eax,dword ptr [esp+18h]
slouken@1895
   716
        or          eax,eax
slouken@1895
   717
        jge         L2
slouken@1895
   718
        mov         edx,dword ptr [esp+14h]
slouken@1895
   719
        neg         eax
slouken@1895
   720
        neg         edx
slouken@1895
   721
        sbb         eax,0
slouken@1895
   722
        mov         dword ptr [esp+18h],eax
slouken@1895
   723
        mov         dword ptr [esp+14h],edx
slouken@1346
   724
L2:
slouken@1895
   725
        or          eax,eax
slouken@1895
   726
        jne         L3
slouken@1895
   727
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   728
        mov         eax,dword ptr [esp+10h]
slouken@1895
   729
        xor         edx,edx
slouken@1895
   730
        div         ecx
slouken@1895
   731
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   732
        div         ecx
slouken@1895
   733
        mov         eax,edx
slouken@1895
   734
        xor         edx,edx
slouken@1895
   735
        dec         edi
slouken@1895
   736
        jns         L4
slouken@1895
   737
        jmp         L8
slouken@1346
   738
L3:
slouken@1895
   739
        mov         ebx,eax
slouken@1895
   740
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   741
        mov         edx,dword ptr [esp+10h]
slouken@1895
   742
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   743
L5:
slouken@1895
   744
        shr         ebx,1
slouken@1895
   745
        rcr         ecx,1
slouken@1895
   746
        shr         edx,1
slouken@1895
   747
        rcr         eax,1
slouken@1895
   748
        or          ebx,ebx
slouken@1895
   749
        jne         L5
slouken@1895
   750
        div         ecx
slouken@1895
   751
        mov         ecx,eax
slouken@1895
   752
        mul         dword ptr [esp+18h]
slouken@1895
   753
        xchg        eax,ecx
slouken@1895
   754
        mul         dword ptr [esp+14h]
slouken@1895
   755
        add         edx,ecx
slouken@1895
   756
        jb          L6
slouken@1895
   757
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   758
        ja          L6
slouken@1895
   759
        jb          L7
slouken@1895
   760
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   761
        jbe         L7
slouken@1346
   762
L6:
slouken@1895
   763
        sub         eax,dword ptr [esp+14h]
slouken@1895
   764
        sbb         edx,dword ptr [esp+18h]
slouken@1346
   765
L7:
slouken@1895
   766
        sub         eax,dword ptr [esp+0Ch]
slouken@1895
   767
        sbb         edx,dword ptr [esp+10h]
slouken@1895
   768
        dec         edi
slouken@1895
   769
        jns         L8
slouken@1346
   770
L4:
slouken@1895
   771
        neg         edx
slouken@1895
   772
        neg         eax
slouken@1895
   773
        sbb         edx,0
slouken@1346
   774
L8:
slouken@1895
   775
        pop         edi
slouken@1895
   776
        pop         ebx
slouken@1895
   777
        ret         10h
slouken@1895
   778
    }
slouken@1895
   779
    /* *INDENT-ON* */
slouken@1330
   780
}
slouken@2735
   781
slouken@1895
   782
void
slouken@1895
   783
__declspec(naked)
slouken@1895
   784
_aullrem()
slouken@1330
   785
{
slouken@1895
   786
    /* *INDENT-OFF* */
slouken@1895
   787
    __asm {
slouken@1895
   788
        push        ebx
slouken@1895
   789
        mov         eax,dword ptr [esp+14h]
slouken@1895
   790
        or          eax,eax
slouken@1895
   791
        jne         L1
slouken@1895
   792
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   793
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   794
        xor         edx,edx
slouken@1895
   795
        div         ecx
slouken@1895
   796
        mov         eax,dword ptr [esp+8]
slouken@1895
   797
        div         ecx
slouken@1895
   798
        mov         eax,edx
slouken@1895
   799
        xor         edx,edx
slouken@1895
   800
        jmp         L2
slouken@1346
   801
L1:
slouken@1895
   802
        mov         ecx,eax
slouken@1895
   803
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   804
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   805
        mov         eax,dword ptr [esp+8]
slouken@1346
   806
L3:
slouken@1895
   807
        shr         ecx,1
slouken@1895
   808
        rcr         ebx,1
slouken@1895
   809
        shr         edx,1
slouken@1895
   810
        rcr         eax,1
slouken@1895
   811
        or          ecx,ecx
slouken@1895
   812
        jne         L3
slouken@1895
   813
        div         ebx
slouken@1895
   814
        mov         ecx,eax
slouken@1895
   815
        mul         dword ptr [esp+14h]
slouken@1895
   816
        xchg        eax,ecx
slouken@1895
   817
        mul         dword ptr [esp+10h]
slouken@1895
   818
        add         edx,ecx
slouken@1895
   819
        jb          L4
slouken@1895
   820
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   821
        ja          L4
slouken@1895
   822
        jb          L5
slouken@1895
   823
        cmp         eax,dword ptr [esp+8]
slouken@1895
   824
        jbe         L5
slouken@1346
   825
L4:
slouken@1895
   826
        sub         eax,dword ptr [esp+10h]
slouken@1895
   827
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   828
L5:
slouken@1895
   829
        sub         eax,dword ptr [esp+8]
slouken@1895
   830
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   831
        neg         edx
slouken@1895
   832
        neg         eax
slouken@1895
   833
        sbb         edx,0
slouken@1346
   834
L2:
slouken@1895
   835
        pop         ebx
slouken@1895
   836
        ret         10h
slouken@1895
   837
    }
slouken@1895
   838
    /* *INDENT-ON* */
slouken@1330
   839
}
slouken@2735
   840
slouken@1895
   841
void
slouken@1895
   842
__declspec(naked)
slouken@1895
   843
_alldvrm()
slouken@1330
   844
{
slouken@1895
   845
    /* *INDENT-OFF* */
slouken@1895
   846
    __asm {
slouken@1895
   847
        push        edi
slouken@1895
   848
        push        esi
slouken@1895
   849
        push        ebp
slouken@1895
   850
        xor         edi,edi
slouken@1895
   851
        xor         ebp,ebp
slouken@1895
   852
        mov         eax,dword ptr [esp+14h]
slouken@1895
   853
        or          eax,eax
slouken@1895
   854
        jge         L1
slouken@1895
   855
        inc         edi
slouken@1895
   856
        inc         ebp
slouken@1895
   857
        mov         edx,dword ptr [esp+10h]
slouken@1895
   858
        neg         eax
slouken@1895
   859
        neg         edx
slouken@1895
   860
        sbb         eax,0
slouken@1895
   861
        mov         dword ptr [esp+14h],eax
slouken@1895
   862
        mov         dword ptr [esp+10h],edx
slouken@1346
   863
L1:
slouken@1895
   864
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   865
        or          eax,eax
slouken@1895
   866
        jge         L2
slouken@1895
   867
        inc         edi
slouken@1895
   868
        mov         edx,dword ptr [esp+18h]
slouken@1895
   869
        neg         eax
slouken@1895
   870
        neg         edx
slouken@1895
   871
        sbb         eax,0
slouken@1895
   872
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   873
        mov         dword ptr [esp+18h],edx
slouken@1346
   874
L2:
slouken@1895
   875
        or          eax,eax
slouken@1895
   876
        jne         L3
slouken@1895
   877
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   878
        mov         eax,dword ptr [esp+14h]
slouken@1895
   879
        xor         edx,edx
slouken@1895
   880
        div         ecx
slouken@1895
   881
        mov         ebx,eax
slouken@1895
   882
        mov         eax,dword ptr [esp+10h]
slouken@1895
   883
        div         ecx
slouken@1895
   884
        mov         esi,eax
slouken@1895
   885
        mov         eax,ebx
slouken@1895
   886
        mul         dword ptr [esp+18h]
slouken@1895
   887
        mov         ecx,eax
slouken@1895
   888
        mov         eax,esi
slouken@1895
   889
        mul         dword ptr [esp+18h]
slouken@1895
   890
        add         edx,ecx
slouken@1895
   891
        jmp         L4
slouken@1346
   892
L3:
slouken@1895
   893
        mov         ebx,eax
slouken@1895
   894
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   895
        mov         edx,dword ptr [esp+14h]
slouken@1895
   896
        mov         eax,dword ptr [esp+10h]
slouken@1346
   897
L5:
slouken@1895
   898
        shr         ebx,1
slouken@1895
   899
        rcr         ecx,1
slouken@1895
   900
        shr         edx,1
slouken@1895
   901
        rcr         eax,1
slouken@1895
   902
        or          ebx,ebx
slouken@1895
   903
        jne         L5
slouken@1895
   904
        div         ecx
slouken@1895
   905
        mov         esi,eax
slouken@1895
   906
        mul         dword ptr [esp+1Ch]
slouken@1895
   907
        mov         ecx,eax
slouken@1895
   908
        mov         eax,dword ptr [esp+18h]
slouken@1895
   909
        mul         esi
slouken@1895
   910
        add         edx,ecx
slouken@1895
   911
        jb          L6
slouken@1895
   912
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   913
        ja          L6
slouken@1895
   914
        jb          L7
slouken@1895
   915
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   916
        jbe         L7
slouken@1346
   917
L6:
slouken@1895
   918
        dec         esi
slouken@1895
   919
        sub         eax,dword ptr [esp+18h]
slouken@1895
   920
        sbb         edx,dword ptr [esp+1Ch]
slouken@1346
   921
L7:
slouken@1895
   922
        xor         ebx,ebx
slouken@1346
   923
L4:
slouken@1895
   924
        sub         eax,dword ptr [esp+10h]
slouken@1895
   925
        sbb         edx,dword ptr [esp+14h]
slouken@1895
   926
        dec         ebp
slouken@1895
   927
        jns         L9
slouken@1895
   928
        neg         edx
slouken@1895
   929
        neg         eax
slouken@1895
   930
        sbb         edx,0
slouken@1346
   931
L9:
slouken@1895
   932
        mov         ecx,edx
slouken@1895
   933
        mov         edx,ebx
slouken@1895
   934
        mov         ebx,ecx
slouken@1895
   935
        mov         ecx,eax
slouken@1895
   936
        mov         eax,esi
slouken@1895
   937
        dec         edi
slouken@1895
   938
        jne         L8
slouken@1895
   939
        neg         edx
slouken@1895
   940
        neg         eax
slouken@1895
   941
        sbb         edx,0
slouken@1346
   942
L8:
slouken@1895
   943
        pop         ebp
slouken@1895
   944
        pop         esi
slouken@1895
   945
        pop         edi
slouken@1895
   946
        ret         10h
slouken@1895
   947
    }
slouken@1895
   948
    /* *INDENT-ON* */
slouken@1330
   949
}
slouken@2735
   950
slouken@1895
   951
void
slouken@1895
   952
__declspec(naked)
slouken@1895
   953
_aulldvrm()
slouken@1330
   954
{
slouken@1895
   955
    /* *INDENT-OFF* */
slouken@1895
   956
    __asm {
slouken@1895
   957
        push        esi
slouken@1895
   958
        mov         eax,dword ptr [esp+14h]
slouken@1895
   959
        or          eax,eax
slouken@1895
   960
        jne         L1
slouken@1895
   961
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   962
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   963
        xor         edx,edx
slouken@1895
   964
        div         ecx
slouken@1895
   965
        mov         ebx,eax
slouken@1895
   966
        mov         eax,dword ptr [esp+8]
slouken@1895
   967
        div         ecx
slouken@1895
   968
        mov         esi,eax
slouken@1895
   969
        mov         eax,ebx
slouken@1895
   970
        mul         dword ptr [esp+10h]
slouken@1895
   971
        mov         ecx,eax
slouken@1895
   972
        mov         eax,esi
slouken@1895
   973
        mul         dword ptr [esp+10h]
slouken@1895
   974
        add         edx,ecx
slouken@1895
   975
        jmp         L2
slouken@1346
   976
L1:
slouken@1895
   977
        mov         ecx,eax
slouken@1895
   978
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   979
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   980
        mov         eax,dword ptr [esp+8]
slouken@1346
   981
L3:
slouken@1895
   982
        shr         ecx,1
slouken@1895
   983
        rcr         ebx,1
slouken@1895
   984
        shr         edx,1
slouken@1895
   985
        rcr         eax,1
slouken@1895
   986
        or          ecx,ecx
slouken@1895
   987
        jne         L3
slouken@1895
   988
        div         ebx
slouken@1895
   989
        mov         esi,eax
slouken@1895
   990
        mul         dword ptr [esp+14h]
slouken@1895
   991
        mov         ecx,eax
slouken@1895
   992
        mov         eax,dword ptr [esp+10h]
slouken@1895
   993
        mul         esi
slouken@1895
   994
        add         edx,ecx
slouken@1895
   995
        jb          L4
slouken@1895
   996
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   997
        ja          L4
slouken@1895
   998
        jb          L5
slouken@1895
   999
        cmp         eax,dword ptr [esp+8]
slouken@1895
  1000
        jbe         L5
slouken@1346
  1001
L4:
slouken@1895
  1002
        dec         esi
slouken@1895
  1003
        sub         eax,dword ptr [esp+10h]
slouken@1895
  1004
        sbb         edx,dword ptr [esp+14h]
slouken@1346
  1005
L5:
slouken@1895
  1006
        xor         ebx,ebx
slouken@1346
  1007
L2:
slouken@1895
  1008
        sub         eax,dword ptr [esp+8]
slouken@1895
  1009
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
  1010
        neg         edx
slouken@1895
  1011
        neg         eax
slouken@1895
  1012
        sbb         edx,0
slouken@1895
  1013
        mov         ecx,edx
slouken@1895
  1014
        mov         edx,ebx
slouken@1895
  1015
        mov         ebx,ecx
slouken@1895
  1016
        mov         ecx,eax
slouken@1895
  1017
        mov         eax,esi
slouken@1895
  1018
        pop         esi
slouken@1895
  1019
        ret         10h
slouken@1895
  1020
    }
slouken@1895
  1021
    /* *INDENT-ON* */
slouken@1330
  1022
}
slouken@2735
  1023
slouken@1895
  1024
void
slouken@1895
  1025
__declspec(naked)
slouken@1895
  1026
_allshl()
slouken@1330
  1027
{
slouken@1895
  1028
    /* *INDENT-OFF* */
slouken@1895
  1029
    __asm {
slouken@1895
  1030
        cmp         cl,40h
slouken@1895
  1031
        jae         RETZERO
slouken@1895
  1032
        cmp         cl,20h
slouken@1895
  1033
        jae         MORE32
slouken@1895
  1034
        shld        edx,eax,cl
slouken@1895
  1035
        shl         eax,cl
slouken@1895
  1036
        ret
slouken@1346
  1037
MORE32:
slouken@1895
  1038
        mov         edx,eax
slouken@1895
  1039
        xor         eax,eax
slouken@1895
  1040
        and         cl,1Fh
slouken@1895
  1041
        shl         edx,cl
slouken@1895
  1042
        ret
slouken@1346
  1043
RETZERO:
slouken@1895
  1044
        xor         eax,eax
slouken@1895
  1045
        xor         edx,edx
slouken@1895
  1046
        ret
slouken@1895
  1047
    }
slouken@1895
  1048
    /* *INDENT-ON* */
slouken@1330
  1049
}
slouken@2735
  1050
slouken@1895
  1051
void
slouken@1895
  1052
__declspec(naked)
slouken@2760
  1053
_allshr()
slouken@2760
  1054
{
slouken@2760
  1055
    /* *INDENT-OFF* */
slouken@2760
  1056
    __asm {
slouken@10587
  1057
        cmp         cl,3Fh
slouken@10587
  1058
        jae         RETSIGN
slouken@2760
  1059
        cmp         cl,20h
slouken@2760
  1060
        jae         MORE32
slouken@2760
  1061
        shrd        eax,edx,cl
slouken@2760
  1062
        sar         edx,cl
slouken@2760
  1063
        ret
slouken@2760
  1064
MORE32:
slouken@2760
  1065
        mov         eax,edx
slouken@10587
  1066
        sar         edx,1Fh
slouken@2760
  1067
        and         cl,1Fh
slouken@2760
  1068
        sar         eax,cl
slouken@2760
  1069
        ret
slouken@10587
  1070
RETSIGN:
slouken@10587
  1071
        sar         edx,1Fh
slouken@10587
  1072
        mov         eax,edx
slouken@2760
  1073
        ret
slouken@2760
  1074
    }
slouken@2760
  1075
    /* *INDENT-ON* */
slouken@2760
  1076
}
slouken@2760
  1077
slouken@2760
  1078
void
slouken@2760
  1079
__declspec(naked)
slouken@1895
  1080
_aullshr()
slouken@1330
  1081
{
slouken@1895
  1082
    /* *INDENT-OFF* */
slouken@1895
  1083
    __asm {
slouken@1895
  1084
        cmp         cl,40h
slouken@1895
  1085
        jae         RETZERO
slouken@1895
  1086
        cmp         cl,20h
slouken@1895
  1087
        jae         MORE32
slouken@1895
  1088
        shrd        eax,edx,cl
slouken@1895
  1089
        shr         edx,cl
slouken@1895
  1090
        ret
slouken@1346
  1091
MORE32:
slouken@1895
  1092
        mov         eax,edx
slouken@1895
  1093
        xor         edx,edx
slouken@1895
  1094
        and         cl,1Fh
slouken@1895
  1095
        shr         eax,cl
slouken@1895
  1096
        ret
slouken@1346
  1097
RETZERO:
slouken@1895
  1098
        xor         eax,eax
slouken@1895
  1099
        xor         edx,edx
slouken@1895
  1100
        ret
slouken@1895
  1101
    }
slouken@1895
  1102
    /* *INDENT-ON* */
slouken@1330
  1103
}
slouken@1330
  1104
slouken@5455
  1105
#endif /* _M_IX86 */
slouken@3255
  1106
slouken@1330
  1107
#endif /* MSC_VER */
slouken@1330
  1108
slouken@1331
  1109
#endif /* !HAVE_LIBC */
slouken@1895
  1110
slouken@1895
  1111
/* vi: set ts=4 sw=4 expandtab: */