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