src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 27 Nov 2013 00:29:46 -0800
changeset 8033 8181c3a4a055
parent 7357 9bd0b241c941
child 8056 abd9434c5d3e
child 8543 b9dd3cf38585
permissions -rw-r--r--
Fixed bug 2274 - SDL_ceil is incorrectly implemented when HAVE_LIBC is not defined

Ghassan Al-Mashareqa

The SDL_ceil function is implemented incorrectly when HAVE_CEIL is not defined (HAVE_LIBC not defined).

The following code:

double val = SDL_ceil(2.3);
printf("%g", val);

prints "2.0", as STD_ceil is defined as:

double
SDL_ceil(double x)
{
#ifdef HAVE_CEIL
return ceil(x);
#else
return (double)(int)((x)+0.5);
#endif /* HAVE_CEIL */
}

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