src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 16 May 2013 00:43:22 -0700
changeset 7180 3733e68edbc3
parent 7003 eeaf77005c30
child 7351 668a3dc28361
permissions -rw-r--r--
Fixed bug 1846 - _allmul implementation in SDL_stdlib.c doesn't clean up the stack

Colin Barrett

I see this manifest itself (VS2012 x86) as:

"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

in the first call to SDL_GetTicks in my application. The disassembly at the problem line is:

hires_now.QuadPart *= 1000;
00AD0792 push 0
00AD0794 push 3E8h
00AD0799 mov eax,dword ptr [ebp-10h]
00AD079C push eax
00AD079D mov ecx,dword ptr [hires_now]
00AD07A0 push ecx
00AD07A1 call _allmul (0AE7D40h)
00AD07A6 mov dword ptr [hires_now],eax
00AD07A9 mov dword ptr [ebp-10h],edx

Apparently _allmul should be popping the stack but isn't (other similar functions in SDL_stdlib.c - _alldiv and whatnot - DO pop the stack).

A 'ret 10h' at the end of _allmul appears to do the trick
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@1330
    26
icculus@7003
    27
/* these are always #defined, make them real symbol in the library, too... */
icculus@7003
    28
#undef SDL_ceil
icculus@7003
    29
#undef SDL_abs
icculus@7003
    30
#undef SDL_sinf
icculus@7003
    31
#undef SDL_cosf
icculus@7003
    32
#undef SDL_isdigit
icculus@7003
    33
#undef SDL_isspace
icculus@7003
    34
#undef SDL_toupper
icculus@7003
    35
#undef SDL_tolower
icculus@7003
    36
double SDL_ceil(double x) { return SDL_ceil_inline(x); }
icculus@7003
    37
float SDL_cosf(float x) { return SDL_cosf_inline(x); }
icculus@7003
    38
float SDL_sinf(float x) { return SDL_sinf_inline(x); }
icculus@7003
    39
int SDL_abs(int x) { return SDL_abs_inline(x); }
icculus@7003
    40
int SDL_isdigit(int x) { return SDL_isdigit_inline(x); }
icculus@7003
    41
int SDL_isspace(int x) { return SDL_isspace_inline(x); }
icculus@7003
    42
int SDL_toupper(int x) { return SDL_toupper_inline(x); }
icculus@7003
    43
int SDL_tolower(int x) { return SDL_tolower_inline(x); }
icculus@7003
    44
icculus@7003
    45
slouken@1330
    46
#ifndef HAVE_LIBC
slouken@1330
    47
/* These are some C runtime intrinsics that need to be defined */
slouken@1330
    48
slouken@3255
    49
#if defined(_MSC_VER)
slouken@1330
    50
slouken@1433
    51
#ifndef __FLTUSED__
slouken@1433
    52
#define __FLTUSED__
slouken@3255
    53
__declspec(selectany) int _fltused = 1;
slouken@1433
    54
#endif
slouken@3255
    55
slouken@6355
    56
/* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */
slouken@6355
    57
#if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG)
slouken@5455
    58
#include <intrin.h>
slouken@5455
    59
slouken@5455
    60
#pragma function(memcpy)
slouken@5455
    61
void * memcpy ( void * destination, const void * source, size_t num )
slouken@5455
    62
{
slouken@5455
    63
    const Uint8 *src = (const Uint8 *)source;
slouken@5455
    64
    Uint8 *dst = (Uint8 *)destination;
slouken@5455
    65
    size_t i;
slouken@5455
    66
    
slouken@5455
    67
    /* All WIN64 architectures have SSE, right? */
slouken@5455
    68
    if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
slouken@5455
    69
        __m128 values[4];
slouken@5455
    70
        for (i = num / 64; i--;) {
slouken@5455
    71
            _mm_prefetch(src, _MM_HINT_NTA);
slouken@5455
    72
            values[0] = *(__m128 *) (src + 0);
slouken@5455
    73
            values[1] = *(__m128 *) (src + 16);
slouken@5455
    74
            values[2] = *(__m128 *) (src + 32);
slouken@5455
    75
            values[3] = *(__m128 *) (src + 48);
slouken@5455
    76
            _mm_stream_ps((float *) (dst + 0), values[0]);
slouken@5455
    77
            _mm_stream_ps((float *) (dst + 16), values[1]);
slouken@5455
    78
            _mm_stream_ps((float *) (dst + 32), values[2]);
slouken@5455
    79
            _mm_stream_ps((float *) (dst + 48), values[3]);
slouken@5455
    80
            src += 64;
slouken@5455
    81
            dst += 64;
slouken@5455
    82
        }
slouken@5455
    83
        num &= 63;
slouken@5455
    84
    }
slouken@5455
    85
slouken@5455
    86
    while (num--) {
slouken@5455
    87
        *dst++ = *src++;
slouken@5455
    88
    }
slouken@5455
    89
    return destination;
slouken@5455
    90
}
slouken@5455
    91
#endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
slouken@5455
    92
slouken@5086
    93
#ifdef _M_IX86
slouken@1433
    94
slouken@4868
    95
void
slouken@4868
    96
__declspec(naked)
slouken@4868
    97
_chkstk()
slouken@4868
    98
{
slouken@4868
    99
}
slouken@4868
   100
slouken@1346
   101
/* Float to long */
slouken@3253
   102
void
slouken@3253
   103
__declspec(naked)
slouken@3253
   104
_ftol()
slouken@1345
   105
{
slouken@1895
   106
    /* *INDENT-OFF* */
slouken@1895
   107
    __asm {
slouken@1895
   108
        push        ebp
slouken@1895
   109
        mov         ebp,esp
slouken@1895
   110
        sub         esp,20h
slouken@1895
   111
        and         esp,0FFFFFFF0h
slouken@1895
   112
        fld         st(0)
slouken@1895
   113
        fst         dword ptr [esp+18h]
slouken@1895
   114
        fistp       qword ptr [esp+10h]
slouken@1895
   115
        fild        qword ptr [esp+10h]
slouken@1895
   116
        mov         edx,dword ptr [esp+18h]
slouken@1895
   117
        mov         eax,dword ptr [esp+10h]
slouken@1895
   118
        test        eax,eax
slouken@1895
   119
        je          integer_QnaN_or_zero
slouken@1346
   120
arg_is_not_integer_QnaN:
slouken@1895
   121
        fsubp       st(1),st
slouken@1895
   122
        test        edx,edx
slouken@1895
   123
        jns         positive
slouken@1895
   124
        fstp        dword ptr [esp]
slouken@1895
   125
        mov         ecx,dword ptr [esp]
slouken@1895
   126
        xor         ecx,80000000h
slouken@1895
   127
        add         ecx,7FFFFFFFh
slouken@1895
   128
        adc         eax,0
slouken@1895
   129
        mov         edx,dword ptr [esp+14h]
slouken@1895
   130
        adc         edx,0
slouken@1895
   131
        jmp         localexit
slouken@1346
   132
positive:
slouken@1895
   133
        fstp        dword ptr [esp]
slouken@1895
   134
        mov         ecx,dword ptr [esp]
slouken@1895
   135
        add         ecx,7FFFFFFFh
slouken@1895
   136
        sbb         eax,0
slouken@1895
   137
        mov         edx,dword ptr [esp+14h]
slouken@1895
   138
        sbb         edx,0
slouken@1895
   139
        jmp         localexit
slouken@1346
   140
integer_QnaN_or_zero:
slouken@1895
   141
        mov         edx,dword ptr [esp+14h]
slouken@1895
   142
        test        edx,7FFFFFFFh
slouken@1895
   143
        jne         arg_is_not_integer_QnaN
slouken@1895
   144
        fstp        dword ptr [esp+18h]
slouken@1895
   145
        fstp        dword ptr [esp+18h]
slouken@1346
   146
localexit:
slouken@1895
   147
        leave
slouken@1895
   148
        ret
slouken@1895
   149
    }
slouken@1895
   150
    /* *INDENT-ON* */
slouken@1345
   151
}
slouken@1895
   152
slouken@1895
   153
void
slouken@1895
   154
_ftol2_sse()
slouken@1330
   155
{
slouken@1895
   156
    _ftol();
slouken@1330
   157
}
slouken@1330
   158
slouken@1346
   159
/* 64-bit math operators for 32-bit systems */
slouken@1895
   160
void
slouken@1895
   161
__declspec(naked)
slouken@1895
   162
_allmul()
slouken@1330
   163
{
slouken@1895
   164
    /* *INDENT-OFF* */
slouken@1895
   165
    __asm {
slouken@1895
   166
        push        ebp
slouken@1895
   167
        mov         ebp,esp
slouken@1895
   168
        push        edi
slouken@1895
   169
        push        esi
slouken@1895
   170
        push        ebx
slouken@1895
   171
        sub         esp,0Ch
slouken@1895
   172
        mov         eax,dword ptr [ebp+10h]
slouken@1895
   173
        mov         edi,dword ptr [ebp+8]
slouken@1895
   174
        mov         ebx,eax
slouken@1895
   175
        mov         esi,eax
slouken@1895
   176
        sar         esi,1Fh
slouken@1895
   177
        mov         eax,dword ptr [ebp+8]
slouken@1895
   178
        mul         ebx
slouken@1895
   179
        imul        edi,esi
slouken@1895
   180
        mov         ecx,edx
slouken@1895
   181
        mov         dword ptr [ebp-18h],eax
slouken@1895
   182
        mov         edx,dword ptr [ebp+0Ch]
slouken@1895
   183
        add         ecx,edi
slouken@1895
   184
        imul        ebx,edx
slouken@1895
   185
        mov         eax,dword ptr [ebp-18h]
slouken@1895
   186
        lea         ebx,[ebx+ecx]
slouken@1895
   187
        mov         dword ptr [ebp-14h],ebx
slouken@1895
   188
        mov         edx,dword ptr [ebp-14h]
slouken@1895
   189
        add         esp,0Ch
slouken@1895
   190
        pop         ebx
slouken@1895
   191
        pop         esi
slouken@1895
   192
        pop         edi
slouken@1895
   193
        pop         ebp
slouken@7180
   194
        ret         10h
slouken@1895
   195
    }
slouken@1895
   196
    /* *INDENT-ON* */
slouken@1330
   197
}
slouken@2735
   198
slouken@1895
   199
void
slouken@1895
   200
__declspec(naked)
slouken@1895
   201
_alldiv()
slouken@1330
   202
{
slouken@1895
   203
    /* *INDENT-OFF* */
slouken@1895
   204
    __asm {
slouken@1895
   205
        push        edi
slouken@1895
   206
        push        esi
slouken@1895
   207
        push        ebx
slouken@1895
   208
        xor         edi,edi
slouken@1895
   209
        mov         eax,dword ptr [esp+14h]
slouken@1895
   210
        or          eax,eax
slouken@1895
   211
        jge         L1
slouken@1895
   212
        inc         edi
slouken@1895
   213
        mov         edx,dword ptr [esp+10h]
slouken@1895
   214
        neg         eax
slouken@1895
   215
        neg         edx
slouken@1895
   216
        sbb         eax,0
slouken@1895
   217
        mov         dword ptr [esp+14h],eax
slouken@1895
   218
        mov         dword ptr [esp+10h],edx
slouken@1346
   219
L1:
slouken@1895
   220
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   221
        or          eax,eax
slouken@1895
   222
        jge         L2
slouken@1895
   223
        inc         edi
slouken@1895
   224
        mov         edx,dword ptr [esp+18h]
slouken@1895
   225
        neg         eax
slouken@1895
   226
        neg         edx
slouken@1895
   227
        sbb         eax,0
slouken@1895
   228
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   229
        mov         dword ptr [esp+18h],edx
slouken@1346
   230
L2:
slouken@1895
   231
        or          eax,eax
slouken@1895
   232
        jne         L3
slouken@1895
   233
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   234
        mov         eax,dword ptr [esp+14h]
slouken@1895
   235
        xor         edx,edx
slouken@1895
   236
        div         ecx
slouken@1895
   237
        mov         ebx,eax
slouken@1895
   238
        mov         eax,dword ptr [esp+10h]
slouken@1895
   239
        div         ecx
slouken@1895
   240
        mov         edx,ebx
slouken@1895
   241
        jmp         L4
slouken@1346
   242
L3:
slouken@1895
   243
        mov         ebx,eax
slouken@1895
   244
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   245
        mov         edx,dword ptr [esp+14h]
slouken@1895
   246
        mov         eax,dword ptr [esp+10h]
slouken@1346
   247
L5:
slouken@1895
   248
        shr         ebx,1
slouken@1895
   249
        rcr         ecx,1
slouken@1895
   250
        shr         edx,1
slouken@1895
   251
        rcr         eax,1
slouken@1895
   252
        or          ebx,ebx
slouken@1895
   253
        jne         L5
slouken@1895
   254
        div         ecx
slouken@1895
   255
        mov         esi,eax
slouken@1895
   256
        mul         dword ptr [esp+1Ch]
slouken@1895
   257
        mov         ecx,eax
slouken@1895
   258
        mov         eax,dword ptr [esp+18h]
slouken@1895
   259
        mul         esi
slouken@1895
   260
        add         edx,ecx
slouken@1895
   261
        jb          L6
slouken@1895
   262
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   263
        ja          L6
slouken@1895
   264
        jb          L7
slouken@1895
   265
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   266
        jbe         L7
slouken@1346
   267
L6:
slouken@1895
   268
        dec         esi
slouken@1346
   269
L7:
slouken@1895
   270
        xor         edx,edx
slouken@1895
   271
        mov         eax,esi
slouken@1346
   272
L4:
slouken@1895
   273
        dec         edi
slouken@1895
   274
        jne         L8
slouken@1895
   275
        neg         edx
slouken@1895
   276
        neg         eax
slouken@1895
   277
        sbb         edx,0
slouken@1346
   278
L8:
slouken@1895
   279
        pop         ebx
slouken@1895
   280
        pop         esi
slouken@1895
   281
        pop         edi
slouken@1895
   282
        ret         10h
slouken@1895
   283
    }
slouken@1895
   284
    /* *INDENT-ON* */
slouken@1330
   285
}
slouken@2735
   286
slouken@1895
   287
void
slouken@1895
   288
__declspec(naked)
slouken@1895
   289
_aulldiv()
slouken@1330
   290
{
slouken@1895
   291
    /* *INDENT-OFF* */
slouken@1895
   292
    __asm {
slouken@1895
   293
        push        ebx
slouken@1895
   294
        push        esi
slouken@1895
   295
        mov         eax,dword ptr [esp+18h]
slouken@1895
   296
        or          eax,eax
slouken@1895
   297
        jne         L1
slouken@1895
   298
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   299
        mov         eax,dword ptr [esp+10h]
slouken@1895
   300
        xor         edx,edx
slouken@1895
   301
        div         ecx
slouken@1895
   302
        mov         ebx,eax
slouken@1895
   303
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   304
        div         ecx
slouken@1895
   305
        mov         edx,ebx
slouken@1895
   306
        jmp         L2
slouken@1346
   307
L1:
slouken@1895
   308
        mov         ecx,eax
slouken@1895
   309
        mov         ebx,dword ptr [esp+14h]
slouken@1895
   310
        mov         edx,dword ptr [esp+10h]
slouken@1895
   311
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   312
L3:
slouken@1895
   313
        shr         ecx,1
slouken@1895
   314
        rcr         ebx,1
slouken@1895
   315
        shr         edx,1
slouken@1895
   316
        rcr         eax,1
slouken@1895
   317
        or          ecx,ecx
slouken@1895
   318
        jne         L3
slouken@1895
   319
        div         ebx
slouken@1895
   320
        mov         esi,eax
slouken@1895
   321
        mul         dword ptr [esp+18h]
slouken@1895
   322
        mov         ecx,eax
slouken@1895
   323
        mov         eax,dword ptr [esp+14h]
slouken@1895
   324
        mul         esi
slouken@1895
   325
        add         edx,ecx
slouken@1895
   326
        jb          L4
slouken@1895
   327
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   328
        ja          L4
slouken@1895
   329
        jb          L5
slouken@1895
   330
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   331
        jbe         L5
slouken@1346
   332
L4:
slouken@1895
   333
        dec         esi
slouken@1346
   334
L5:
slouken@1895
   335
        xor         edx,edx
slouken@1895
   336
        mov         eax,esi
slouken@1346
   337
L2:
slouken@1895
   338
        pop         esi
slouken@1895
   339
        pop         ebx
slouken@1895
   340
        ret         10h
slouken@1895
   341
    }
slouken@1895
   342
    /* *INDENT-ON* */
slouken@1330
   343
}
slouken@2735
   344
slouken@1895
   345
void
slouken@1895
   346
__declspec(naked)
slouken@1895
   347
_allrem()
slouken@1330
   348
{
slouken@1895
   349
    /* *INDENT-OFF* */
slouken@1895
   350
    __asm {
slouken@1895
   351
        push        ebx
slouken@1895
   352
        push        edi
slouken@1895
   353
        xor         edi,edi
slouken@1895
   354
        mov         eax,dword ptr [esp+10h]
slouken@1895
   355
        or          eax,eax
slouken@1895
   356
        jge         L1
slouken@1895
   357
        inc         edi
slouken@1895
   358
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   359
        neg         eax
slouken@1895
   360
        neg         edx
slouken@1895
   361
        sbb         eax,0
slouken@1895
   362
        mov         dword ptr [esp+10h],eax
slouken@1895
   363
        mov         dword ptr [esp+0Ch],edx
slouken@1346
   364
L1:
slouken@1895
   365
        mov         eax,dword ptr [esp+18h]
slouken@1895
   366
        or          eax,eax
slouken@1895
   367
        jge         L2
slouken@1895
   368
        mov         edx,dword ptr [esp+14h]
slouken@1895
   369
        neg         eax
slouken@1895
   370
        neg         edx
slouken@1895
   371
        sbb         eax,0
slouken@1895
   372
        mov         dword ptr [esp+18h],eax
slouken@1895
   373
        mov         dword ptr [esp+14h],edx
slouken@1346
   374
L2:
slouken@1895
   375
        or          eax,eax
slouken@1895
   376
        jne         L3
slouken@1895
   377
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   378
        mov         eax,dword ptr [esp+10h]
slouken@1895
   379
        xor         edx,edx
slouken@1895
   380
        div         ecx
slouken@1895
   381
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   382
        div         ecx
slouken@1895
   383
        mov         eax,edx
slouken@1895
   384
        xor         edx,edx
slouken@1895
   385
        dec         edi
slouken@1895
   386
        jns         L4
slouken@1895
   387
        jmp         L8
slouken@1346
   388
L3:
slouken@1895
   389
        mov         ebx,eax
slouken@1895
   390
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   391
        mov         edx,dword ptr [esp+10h]
slouken@1895
   392
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   393
L5:
slouken@1895
   394
        shr         ebx,1
slouken@1895
   395
        rcr         ecx,1
slouken@1895
   396
        shr         edx,1
slouken@1895
   397
        rcr         eax,1
slouken@1895
   398
        or          ebx,ebx
slouken@1895
   399
        jne         L5
slouken@1895
   400
        div         ecx
slouken@1895
   401
        mov         ecx,eax
slouken@1895
   402
        mul         dword ptr [esp+18h]
slouken@1895
   403
        xchg        eax,ecx
slouken@1895
   404
        mul         dword ptr [esp+14h]
slouken@1895
   405
        add         edx,ecx
slouken@1895
   406
        jb          L6
slouken@1895
   407
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   408
        ja          L6
slouken@1895
   409
        jb          L7
slouken@1895
   410
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   411
        jbe         L7
slouken@1346
   412
L6:
slouken@1895
   413
        sub         eax,dword ptr [esp+14h]
slouken@1895
   414
        sbb         edx,dword ptr [esp+18h]
slouken@1346
   415
L7:
slouken@1895
   416
        sub         eax,dword ptr [esp+0Ch]
slouken@1895
   417
        sbb         edx,dword ptr [esp+10h]
slouken@1895
   418
        dec         edi
slouken@1895
   419
        jns         L8
slouken@1346
   420
L4:
slouken@1895
   421
        neg         edx
slouken@1895
   422
        neg         eax
slouken@1895
   423
        sbb         edx,0
slouken@1346
   424
L8:
slouken@1895
   425
        pop         edi
slouken@1895
   426
        pop         ebx
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
_aullrem()
slouken@1330
   435
{
slouken@1895
   436
    /* *INDENT-OFF* */
slouken@1895
   437
    __asm {
slouken@1895
   438
        push        ebx
slouken@1895
   439
        mov         eax,dword ptr [esp+14h]
slouken@1895
   440
        or          eax,eax
slouken@1895
   441
        jne         L1
slouken@1895
   442
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   443
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   444
        xor         edx,edx
slouken@1895
   445
        div         ecx
slouken@1895
   446
        mov         eax,dword ptr [esp+8]
slouken@1895
   447
        div         ecx
slouken@1895
   448
        mov         eax,edx
slouken@1895
   449
        xor         edx,edx
slouken@1895
   450
        jmp         L2
slouken@1346
   451
L1:
slouken@1895
   452
        mov         ecx,eax
slouken@1895
   453
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   454
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   455
        mov         eax,dword ptr [esp+8]
slouken@1346
   456
L3:
slouken@1895
   457
        shr         ecx,1
slouken@1895
   458
        rcr         ebx,1
slouken@1895
   459
        shr         edx,1
slouken@1895
   460
        rcr         eax,1
slouken@1895
   461
        or          ecx,ecx
slouken@1895
   462
        jne         L3
slouken@1895
   463
        div         ebx
slouken@1895
   464
        mov         ecx,eax
slouken@1895
   465
        mul         dword ptr [esp+14h]
slouken@1895
   466
        xchg        eax,ecx
slouken@1895
   467
        mul         dword ptr [esp+10h]
slouken@1895
   468
        add         edx,ecx
slouken@1895
   469
        jb          L4
slouken@1895
   470
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   471
        ja          L4
slouken@1895
   472
        jb          L5
slouken@1895
   473
        cmp         eax,dword ptr [esp+8]
slouken@1895
   474
        jbe         L5
slouken@1346
   475
L4:
slouken@1895
   476
        sub         eax,dword ptr [esp+10h]
slouken@1895
   477
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   478
L5:
slouken@1895
   479
        sub         eax,dword ptr [esp+8]
slouken@1895
   480
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   481
        neg         edx
slouken@1895
   482
        neg         eax
slouken@1895
   483
        sbb         edx,0
slouken@1346
   484
L2:
slouken@1895
   485
        pop         ebx
slouken@1895
   486
        ret         10h
slouken@1895
   487
    }
slouken@1895
   488
    /* *INDENT-ON* */
slouken@1330
   489
}
slouken@2735
   490
slouken@1895
   491
void
slouken@1895
   492
__declspec(naked)
slouken@1895
   493
_alldvrm()
slouken@1330
   494
{
slouken@1895
   495
    /* *INDENT-OFF* */
slouken@1895
   496
    __asm {
slouken@1895
   497
        push        edi
slouken@1895
   498
        push        esi
slouken@1895
   499
        push        ebp
slouken@1895
   500
        xor         edi,edi
slouken@1895
   501
        xor         ebp,ebp
slouken@1895
   502
        mov         eax,dword ptr [esp+14h]
slouken@1895
   503
        or          eax,eax
slouken@1895
   504
        jge         L1
slouken@1895
   505
        inc         edi
slouken@1895
   506
        inc         ebp
slouken@1895
   507
        mov         edx,dword ptr [esp+10h]
slouken@1895
   508
        neg         eax
slouken@1895
   509
        neg         edx
slouken@1895
   510
        sbb         eax,0
slouken@1895
   511
        mov         dword ptr [esp+14h],eax
slouken@1895
   512
        mov         dword ptr [esp+10h],edx
slouken@1346
   513
L1:
slouken@1895
   514
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   515
        or          eax,eax
slouken@1895
   516
        jge         L2
slouken@1895
   517
        inc         edi
slouken@1895
   518
        mov         edx,dword ptr [esp+18h]
slouken@1895
   519
        neg         eax
slouken@1895
   520
        neg         edx
slouken@1895
   521
        sbb         eax,0
slouken@1895
   522
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   523
        mov         dword ptr [esp+18h],edx
slouken@1346
   524
L2:
slouken@1895
   525
        or          eax,eax
slouken@1895
   526
        jne         L3
slouken@1895
   527
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   528
        mov         eax,dword ptr [esp+14h]
slouken@1895
   529
        xor         edx,edx
slouken@1895
   530
        div         ecx
slouken@1895
   531
        mov         ebx,eax
slouken@1895
   532
        mov         eax,dword ptr [esp+10h]
slouken@1895
   533
        div         ecx
slouken@1895
   534
        mov         esi,eax
slouken@1895
   535
        mov         eax,ebx
slouken@1895
   536
        mul         dword ptr [esp+18h]
slouken@1895
   537
        mov         ecx,eax
slouken@1895
   538
        mov         eax,esi
slouken@1895
   539
        mul         dword ptr [esp+18h]
slouken@1895
   540
        add         edx,ecx
slouken@1895
   541
        jmp         L4
slouken@1346
   542
L3:
slouken@1895
   543
        mov         ebx,eax
slouken@1895
   544
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   545
        mov         edx,dword ptr [esp+14h]
slouken@1895
   546
        mov         eax,dword ptr [esp+10h]
slouken@1346
   547
L5:
slouken@1895
   548
        shr         ebx,1
slouken@1895
   549
        rcr         ecx,1
slouken@1895
   550
        shr         edx,1
slouken@1895
   551
        rcr         eax,1
slouken@1895
   552
        or          ebx,ebx
slouken@1895
   553
        jne         L5
slouken@1895
   554
        div         ecx
slouken@1895
   555
        mov         esi,eax
slouken@1895
   556
        mul         dword ptr [esp+1Ch]
slouken@1895
   557
        mov         ecx,eax
slouken@1895
   558
        mov         eax,dword ptr [esp+18h]
slouken@1895
   559
        mul         esi
slouken@1895
   560
        add         edx,ecx
slouken@1895
   561
        jb          L6
slouken@1895
   562
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   563
        ja          L6
slouken@1895
   564
        jb          L7
slouken@1895
   565
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   566
        jbe         L7
slouken@1346
   567
L6:
slouken@1895
   568
        dec         esi
slouken@1895
   569
        sub         eax,dword ptr [esp+18h]
slouken@1895
   570
        sbb         edx,dword ptr [esp+1Ch]
slouken@1346
   571
L7:
slouken@1895
   572
        xor         ebx,ebx
slouken@1346
   573
L4:
slouken@1895
   574
        sub         eax,dword ptr [esp+10h]
slouken@1895
   575
        sbb         edx,dword ptr [esp+14h]
slouken@1895
   576
        dec         ebp
slouken@1895
   577
        jns         L9
slouken@1895
   578
        neg         edx
slouken@1895
   579
        neg         eax
slouken@1895
   580
        sbb         edx,0
slouken@1346
   581
L9:
slouken@1895
   582
        mov         ecx,edx
slouken@1895
   583
        mov         edx,ebx
slouken@1895
   584
        mov         ebx,ecx
slouken@1895
   585
        mov         ecx,eax
slouken@1895
   586
        mov         eax,esi
slouken@1895
   587
        dec         edi
slouken@1895
   588
        jne         L8
slouken@1895
   589
        neg         edx
slouken@1895
   590
        neg         eax
slouken@1895
   591
        sbb         edx,0
slouken@1346
   592
L8:
slouken@1895
   593
        pop         ebp
slouken@1895
   594
        pop         esi
slouken@1895
   595
        pop         edi
slouken@1895
   596
        ret         10h
slouken@1895
   597
    }
slouken@1895
   598
    /* *INDENT-ON* */
slouken@1330
   599
}
slouken@2735
   600
slouken@1895
   601
void
slouken@1895
   602
__declspec(naked)
slouken@1895
   603
_aulldvrm()
slouken@1330
   604
{
slouken@1895
   605
    /* *INDENT-OFF* */
slouken@1895
   606
    __asm {
slouken@1895
   607
        push        esi
slouken@1895
   608
        mov         eax,dword ptr [esp+14h]
slouken@1895
   609
        or          eax,eax
slouken@1895
   610
        jne         L1
slouken@1895
   611
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   612
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   613
        xor         edx,edx
slouken@1895
   614
        div         ecx
slouken@1895
   615
        mov         ebx,eax
slouken@1895
   616
        mov         eax,dword ptr [esp+8]
slouken@1895
   617
        div         ecx
slouken@1895
   618
        mov         esi,eax
slouken@1895
   619
        mov         eax,ebx
slouken@1895
   620
        mul         dword ptr [esp+10h]
slouken@1895
   621
        mov         ecx,eax
slouken@1895
   622
        mov         eax,esi
slouken@1895
   623
        mul         dword ptr [esp+10h]
slouken@1895
   624
        add         edx,ecx
slouken@1895
   625
        jmp         L2
slouken@1346
   626
L1:
slouken@1895
   627
        mov         ecx,eax
slouken@1895
   628
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   629
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   630
        mov         eax,dword ptr [esp+8]
slouken@1346
   631
L3:
slouken@1895
   632
        shr         ecx,1
slouken@1895
   633
        rcr         ebx,1
slouken@1895
   634
        shr         edx,1
slouken@1895
   635
        rcr         eax,1
slouken@1895
   636
        or          ecx,ecx
slouken@1895
   637
        jne         L3
slouken@1895
   638
        div         ebx
slouken@1895
   639
        mov         esi,eax
slouken@1895
   640
        mul         dword ptr [esp+14h]
slouken@1895
   641
        mov         ecx,eax
slouken@1895
   642
        mov         eax,dword ptr [esp+10h]
slouken@1895
   643
        mul         esi
slouken@1895
   644
        add         edx,ecx
slouken@1895
   645
        jb          L4
slouken@1895
   646
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   647
        ja          L4
slouken@1895
   648
        jb          L5
slouken@1895
   649
        cmp         eax,dword ptr [esp+8]
slouken@1895
   650
        jbe         L5
slouken@1346
   651
L4:
slouken@1895
   652
        dec         esi
slouken@1895
   653
        sub         eax,dword ptr [esp+10h]
slouken@1895
   654
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   655
L5:
slouken@1895
   656
        xor         ebx,ebx
slouken@1346
   657
L2:
slouken@1895
   658
        sub         eax,dword ptr [esp+8]
slouken@1895
   659
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   660
        neg         edx
slouken@1895
   661
        neg         eax
slouken@1895
   662
        sbb         edx,0
slouken@1895
   663
        mov         ecx,edx
slouken@1895
   664
        mov         edx,ebx
slouken@1895
   665
        mov         ebx,ecx
slouken@1895
   666
        mov         ecx,eax
slouken@1895
   667
        mov         eax,esi
slouken@1895
   668
        pop         esi
slouken@1895
   669
        ret         10h
slouken@1895
   670
    }
slouken@1895
   671
    /* *INDENT-ON* */
slouken@1330
   672
}
slouken@2735
   673
slouken@1895
   674
void
slouken@1895
   675
__declspec(naked)
slouken@1895
   676
_allshl()
slouken@1330
   677
{
slouken@1895
   678
    /* *INDENT-OFF* */
slouken@1895
   679
    __asm {
slouken@1895
   680
        cmp         cl,40h
slouken@1895
   681
        jae         RETZERO
slouken@1895
   682
        cmp         cl,20h
slouken@1895
   683
        jae         MORE32
slouken@1895
   684
        shld        edx,eax,cl
slouken@1895
   685
        shl         eax,cl
slouken@1895
   686
        ret
slouken@1346
   687
MORE32:
slouken@1895
   688
        mov         edx,eax
slouken@1895
   689
        xor         eax,eax
slouken@1895
   690
        and         cl,1Fh
slouken@1895
   691
        shl         edx,cl
slouken@1895
   692
        ret
slouken@1346
   693
RETZERO:
slouken@1895
   694
        xor         eax,eax
slouken@1895
   695
        xor         edx,edx
slouken@1895
   696
        ret
slouken@1895
   697
    }
slouken@1895
   698
    /* *INDENT-ON* */
slouken@1330
   699
}
slouken@2735
   700
slouken@1895
   701
void
slouken@1895
   702
__declspec(naked)
slouken@2760
   703
_allshr()
slouken@2760
   704
{
slouken@2760
   705
    /* *INDENT-OFF* */
slouken@2760
   706
    __asm {
slouken@2760
   707
        cmp         cl,40h
slouken@2760
   708
        jae         RETZERO
slouken@2760
   709
        cmp         cl,20h
slouken@2760
   710
        jae         MORE32
slouken@2760
   711
        shrd        eax,edx,cl
slouken@2760
   712
        sar         edx,cl
slouken@2760
   713
        ret
slouken@2760
   714
MORE32:
slouken@2760
   715
        mov         eax,edx
slouken@2760
   716
        xor         edx,edx
slouken@2760
   717
        and         cl,1Fh
slouken@2760
   718
        sar         eax,cl
slouken@2760
   719
        ret
slouken@2760
   720
RETZERO:
slouken@2760
   721
        xor         eax,eax
slouken@2760
   722
        xor         edx,edx
slouken@2760
   723
        ret
slouken@2760
   724
    }
slouken@2760
   725
    /* *INDENT-ON* */
slouken@2760
   726
}
slouken@2760
   727
slouken@2760
   728
void
slouken@2760
   729
__declspec(naked)
slouken@1895
   730
_aullshr()
slouken@1330
   731
{
slouken@1895
   732
    /* *INDENT-OFF* */
slouken@1895
   733
    __asm {
slouken@1895
   734
        cmp         cl,40h
slouken@1895
   735
        jae         RETZERO
slouken@1895
   736
        cmp         cl,20h
slouken@1895
   737
        jae         MORE32
slouken@1895
   738
        shrd        eax,edx,cl
slouken@1895
   739
        shr         edx,cl
slouken@1895
   740
        ret
slouken@1346
   741
MORE32:
slouken@1895
   742
        mov         eax,edx
slouken@1895
   743
        xor         edx,edx
slouken@1895
   744
        and         cl,1Fh
slouken@1895
   745
        shr         eax,cl
slouken@1895
   746
        ret
slouken@1346
   747
RETZERO:
slouken@1895
   748
        xor         eax,eax
slouken@1895
   749
        xor         edx,edx
slouken@1895
   750
        ret
slouken@1895
   751
    }
slouken@1895
   752
    /* *INDENT-ON* */
slouken@1330
   753
}
slouken@1330
   754
slouken@5455
   755
#endif /* _M_IX86 */
slouken@3255
   756
slouken@1330
   757
#endif /* MSC_VER */
slouken@1330
   758
slouken@1331
   759
#endif /* !HAVE_LIBC */
slouken@1895
   760
slouken@1895
   761
/* vi: set ts=4 sw=4 expandtab: */