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