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