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