src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 27 Aug 2008 15:10:03 +0000
changeset 2735 204be4fc2726
parent 1895 c121d94672cb
child 2760 02aa80d7905f
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga
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@2735
   138
slouken@1895
   139
void
slouken@1895
   140
__declspec(naked)
slouken@1895
   141
_alldiv()
slouken@1330
   142
{
slouken@1895
   143
    /* *INDENT-OFF* */
slouken@1895
   144
    __asm {
slouken@1895
   145
        push        edi
slouken@1895
   146
        push        esi
slouken@1895
   147
        push        ebx
slouken@1895
   148
        xor         edi,edi
slouken@1895
   149
        mov         eax,dword ptr [esp+14h]
slouken@1895
   150
        or          eax,eax
slouken@1895
   151
        jge         L1
slouken@1895
   152
        inc         edi
slouken@1895
   153
        mov         edx,dword ptr [esp+10h]
slouken@1895
   154
        neg         eax
slouken@1895
   155
        neg         edx
slouken@1895
   156
        sbb         eax,0
slouken@1895
   157
        mov         dword ptr [esp+14h],eax
slouken@1895
   158
        mov         dword ptr [esp+10h],edx
slouken@1346
   159
L1:
slouken@1895
   160
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   161
        or          eax,eax
slouken@1895
   162
        jge         L2
slouken@1895
   163
        inc         edi
slouken@1895
   164
        mov         edx,dword ptr [esp+18h]
slouken@1895
   165
        neg         eax
slouken@1895
   166
        neg         edx
slouken@1895
   167
        sbb         eax,0
slouken@1895
   168
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   169
        mov         dword ptr [esp+18h],edx
slouken@1346
   170
L2:
slouken@1895
   171
        or          eax,eax
slouken@1895
   172
        jne         L3
slouken@1895
   173
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   174
        mov         eax,dword ptr [esp+14h]
slouken@1895
   175
        xor         edx,edx
slouken@1895
   176
        div         ecx
slouken@1895
   177
        mov         ebx,eax
slouken@1895
   178
        mov         eax,dword ptr [esp+10h]
slouken@1895
   179
        div         ecx
slouken@1895
   180
        mov         edx,ebx
slouken@1895
   181
        jmp         L4
slouken@1346
   182
L3:
slouken@1895
   183
        mov         ebx,eax
slouken@1895
   184
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   185
        mov         edx,dword ptr [esp+14h]
slouken@1895
   186
        mov         eax,dword ptr [esp+10h]
slouken@1346
   187
L5:
slouken@1895
   188
        shr         ebx,1
slouken@1895
   189
        rcr         ecx,1
slouken@1895
   190
        shr         edx,1
slouken@1895
   191
        rcr         eax,1
slouken@1895
   192
        or          ebx,ebx
slouken@1895
   193
        jne         L5
slouken@1895
   194
        div         ecx
slouken@1895
   195
        mov         esi,eax
slouken@1895
   196
        mul         dword ptr [esp+1Ch]
slouken@1895
   197
        mov         ecx,eax
slouken@1895
   198
        mov         eax,dword ptr [esp+18h]
slouken@1895
   199
        mul         esi
slouken@1895
   200
        add         edx,ecx
slouken@1895
   201
        jb          L6
slouken@1895
   202
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   203
        ja          L6
slouken@1895
   204
        jb          L7
slouken@1895
   205
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   206
        jbe         L7
slouken@1346
   207
L6:
slouken@1895
   208
        dec         esi
slouken@1346
   209
L7:
slouken@1895
   210
        xor         edx,edx
slouken@1895
   211
        mov         eax,esi
slouken@1346
   212
L4:
slouken@1895
   213
        dec         edi
slouken@1895
   214
        jne         L8
slouken@1895
   215
        neg         edx
slouken@1895
   216
        neg         eax
slouken@1895
   217
        sbb         edx,0
slouken@1346
   218
L8:
slouken@1895
   219
        pop         ebx
slouken@1895
   220
        pop         esi
slouken@1895
   221
        pop         edi
slouken@1895
   222
        ret         10h
slouken@1895
   223
    }
slouken@1895
   224
    /* *INDENT-ON* */
slouken@1330
   225
}
slouken@2735
   226
slouken@1895
   227
void
slouken@1895
   228
__declspec(naked)
slouken@1895
   229
_aulldiv()
slouken@1330
   230
{
slouken@1895
   231
    /* *INDENT-OFF* */
slouken@1895
   232
    __asm {
slouken@1895
   233
        push        ebx
slouken@1895
   234
        push        esi
slouken@1895
   235
        mov         eax,dword ptr [esp+18h]
slouken@1895
   236
        or          eax,eax
slouken@1895
   237
        jne         L1
slouken@1895
   238
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   239
        mov         eax,dword ptr [esp+10h]
slouken@1895
   240
        xor         edx,edx
slouken@1895
   241
        div         ecx
slouken@1895
   242
        mov         ebx,eax
slouken@1895
   243
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   244
        div         ecx
slouken@1895
   245
        mov         edx,ebx
slouken@1895
   246
        jmp         L2
slouken@1346
   247
L1:
slouken@1895
   248
        mov         ecx,eax
slouken@1895
   249
        mov         ebx,dword ptr [esp+14h]
slouken@1895
   250
        mov         edx,dword ptr [esp+10h]
slouken@1895
   251
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   252
L3:
slouken@1895
   253
        shr         ecx,1
slouken@1895
   254
        rcr         ebx,1
slouken@1895
   255
        shr         edx,1
slouken@1895
   256
        rcr         eax,1
slouken@1895
   257
        or          ecx,ecx
slouken@1895
   258
        jne         L3
slouken@1895
   259
        div         ebx
slouken@1895
   260
        mov         esi,eax
slouken@1895
   261
        mul         dword ptr [esp+18h]
slouken@1895
   262
        mov         ecx,eax
slouken@1895
   263
        mov         eax,dword ptr [esp+14h]
slouken@1895
   264
        mul         esi
slouken@1895
   265
        add         edx,ecx
slouken@1895
   266
        jb          L4
slouken@1895
   267
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   268
        ja          L4
slouken@1895
   269
        jb          L5
slouken@1895
   270
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   271
        jbe         L5
slouken@1346
   272
L4:
slouken@1895
   273
        dec         esi
slouken@1346
   274
L5:
slouken@1895
   275
        xor         edx,edx
slouken@1895
   276
        mov         eax,esi
slouken@1346
   277
L2:
slouken@1895
   278
        pop         esi
slouken@1895
   279
        pop         ebx
slouken@1895
   280
        ret         10h
slouken@1895
   281
    }
slouken@1895
   282
    /* *INDENT-ON* */
slouken@1330
   283
}
slouken@2735
   284
slouken@1895
   285
void
slouken@1895
   286
__declspec(naked)
slouken@1895
   287
_allrem()
slouken@1330
   288
{
slouken@1895
   289
    /* *INDENT-OFF* */
slouken@1895
   290
    __asm {
slouken@1895
   291
        push        ebx
slouken@1895
   292
        push        edi
slouken@1895
   293
        xor         edi,edi
slouken@1895
   294
        mov         eax,dword ptr [esp+10h]
slouken@1895
   295
        or          eax,eax
slouken@1895
   296
        jge         L1
slouken@1895
   297
        inc         edi
slouken@1895
   298
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   299
        neg         eax
slouken@1895
   300
        neg         edx
slouken@1895
   301
        sbb         eax,0
slouken@1895
   302
        mov         dword ptr [esp+10h],eax
slouken@1895
   303
        mov         dword ptr [esp+0Ch],edx
slouken@1346
   304
L1:
slouken@1895
   305
        mov         eax,dword ptr [esp+18h]
slouken@1895
   306
        or          eax,eax
slouken@1895
   307
        jge         L2
slouken@1895
   308
        mov         edx,dword ptr [esp+14h]
slouken@1895
   309
        neg         eax
slouken@1895
   310
        neg         edx
slouken@1895
   311
        sbb         eax,0
slouken@1895
   312
        mov         dword ptr [esp+18h],eax
slouken@1895
   313
        mov         dword ptr [esp+14h],edx
slouken@1346
   314
L2:
slouken@1895
   315
        or          eax,eax
slouken@1895
   316
        jne         L3
slouken@1895
   317
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   318
        mov         eax,dword ptr [esp+10h]
slouken@1895
   319
        xor         edx,edx
slouken@1895
   320
        div         ecx
slouken@1895
   321
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   322
        div         ecx
slouken@1895
   323
        mov         eax,edx
slouken@1895
   324
        xor         edx,edx
slouken@1895
   325
        dec         edi
slouken@1895
   326
        jns         L4
slouken@1895
   327
        jmp         L8
slouken@1346
   328
L3:
slouken@1895
   329
        mov         ebx,eax
slouken@1895
   330
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   331
        mov         edx,dword ptr [esp+10h]
slouken@1895
   332
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   333
L5:
slouken@1895
   334
        shr         ebx,1
slouken@1895
   335
        rcr         ecx,1
slouken@1895
   336
        shr         edx,1
slouken@1895
   337
        rcr         eax,1
slouken@1895
   338
        or          ebx,ebx
slouken@1895
   339
        jne         L5
slouken@1895
   340
        div         ecx
slouken@1895
   341
        mov         ecx,eax
slouken@1895
   342
        mul         dword ptr [esp+18h]
slouken@1895
   343
        xchg        eax,ecx
slouken@1895
   344
        mul         dword ptr [esp+14h]
slouken@1895
   345
        add         edx,ecx
slouken@1895
   346
        jb          L6
slouken@1895
   347
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   348
        ja          L6
slouken@1895
   349
        jb          L7
slouken@1895
   350
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   351
        jbe         L7
slouken@1346
   352
L6:
slouken@1895
   353
        sub         eax,dword ptr [esp+14h]
slouken@1895
   354
        sbb         edx,dword ptr [esp+18h]
slouken@1346
   355
L7:
slouken@1895
   356
        sub         eax,dword ptr [esp+0Ch]
slouken@1895
   357
        sbb         edx,dword ptr [esp+10h]
slouken@1895
   358
        dec         edi
slouken@1895
   359
        jns         L8
slouken@1346
   360
L4:
slouken@1895
   361
        neg         edx
slouken@1895
   362
        neg         eax
slouken@1895
   363
        sbb         edx,0
slouken@1346
   364
L8:
slouken@1895
   365
        pop         edi
slouken@1895
   366
        pop         ebx
slouken@1895
   367
        ret         10h
slouken@1895
   368
    }
slouken@1895
   369
    /* *INDENT-ON* */
slouken@1330
   370
}
slouken@2735
   371
slouken@1895
   372
void
slouken@1895
   373
__declspec(naked)
slouken@1895
   374
_aullrem()
slouken@1330
   375
{
slouken@1895
   376
    /* *INDENT-OFF* */
slouken@1895
   377
    __asm {
slouken@1895
   378
        push        ebx
slouken@1895
   379
        mov         eax,dword ptr [esp+14h]
slouken@1895
   380
        or          eax,eax
slouken@1895
   381
        jne         L1
slouken@1895
   382
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   383
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   384
        xor         edx,edx
slouken@1895
   385
        div         ecx
slouken@1895
   386
        mov         eax,dword ptr [esp+8]
slouken@1895
   387
        div         ecx
slouken@1895
   388
        mov         eax,edx
slouken@1895
   389
        xor         edx,edx
slouken@1895
   390
        jmp         L2
slouken@1346
   391
L1:
slouken@1895
   392
        mov         ecx,eax
slouken@1895
   393
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   394
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   395
        mov         eax,dword ptr [esp+8]
slouken@1346
   396
L3:
slouken@1895
   397
        shr         ecx,1
slouken@1895
   398
        rcr         ebx,1
slouken@1895
   399
        shr         edx,1
slouken@1895
   400
        rcr         eax,1
slouken@1895
   401
        or          ecx,ecx
slouken@1895
   402
        jne         L3
slouken@1895
   403
        div         ebx
slouken@1895
   404
        mov         ecx,eax
slouken@1895
   405
        mul         dword ptr [esp+14h]
slouken@1895
   406
        xchg        eax,ecx
slouken@1895
   407
        mul         dword ptr [esp+10h]
slouken@1895
   408
        add         edx,ecx
slouken@1895
   409
        jb          L4
slouken@1895
   410
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   411
        ja          L4
slouken@1895
   412
        jb          L5
slouken@1895
   413
        cmp         eax,dword ptr [esp+8]
slouken@1895
   414
        jbe         L5
slouken@1346
   415
L4:
slouken@1895
   416
        sub         eax,dword ptr [esp+10h]
slouken@1895
   417
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   418
L5:
slouken@1895
   419
        sub         eax,dword ptr [esp+8]
slouken@1895
   420
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   421
        neg         edx
slouken@1895
   422
        neg         eax
slouken@1895
   423
        sbb         edx,0
slouken@1346
   424
L2:
slouken@1895
   425
        pop         ebx
slouken@1895
   426
        ret         10h
slouken@1895
   427
    }
slouken@1895
   428
    /* *INDENT-ON* */
slouken@1330
   429
}
slouken@2735
   430
slouken@1895
   431
void
slouken@1895
   432
__declspec(naked)
slouken@1895
   433
_alldvrm()
slouken@1330
   434
{
slouken@1895
   435
    /* *INDENT-OFF* */
slouken@1895
   436
    __asm {
slouken@1895
   437
        push        edi
slouken@1895
   438
        push        esi
slouken@1895
   439
        push        ebp
slouken@1895
   440
        xor         edi,edi
slouken@1895
   441
        xor         ebp,ebp
slouken@1895
   442
        mov         eax,dword ptr [esp+14h]
slouken@1895
   443
        or          eax,eax
slouken@1895
   444
        jge         L1
slouken@1895
   445
        inc         edi
slouken@1895
   446
        inc         ebp
slouken@1895
   447
        mov         edx,dword ptr [esp+10h]
slouken@1895
   448
        neg         eax
slouken@1895
   449
        neg         edx
slouken@1895
   450
        sbb         eax,0
slouken@1895
   451
        mov         dword ptr [esp+14h],eax
slouken@1895
   452
        mov         dword ptr [esp+10h],edx
slouken@1346
   453
L1:
slouken@1895
   454
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   455
        or          eax,eax
slouken@1895
   456
        jge         L2
slouken@1895
   457
        inc         edi
slouken@1895
   458
        mov         edx,dword ptr [esp+18h]
slouken@1895
   459
        neg         eax
slouken@1895
   460
        neg         edx
slouken@1895
   461
        sbb         eax,0
slouken@1895
   462
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   463
        mov         dword ptr [esp+18h],edx
slouken@1346
   464
L2:
slouken@1895
   465
        or          eax,eax
slouken@1895
   466
        jne         L3
slouken@1895
   467
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   468
        mov         eax,dword ptr [esp+14h]
slouken@1895
   469
        xor         edx,edx
slouken@1895
   470
        div         ecx
slouken@1895
   471
        mov         ebx,eax
slouken@1895
   472
        mov         eax,dword ptr [esp+10h]
slouken@1895
   473
        div         ecx
slouken@1895
   474
        mov         esi,eax
slouken@1895
   475
        mov         eax,ebx
slouken@1895
   476
        mul         dword ptr [esp+18h]
slouken@1895
   477
        mov         ecx,eax
slouken@1895
   478
        mov         eax,esi
slouken@1895
   479
        mul         dword ptr [esp+18h]
slouken@1895
   480
        add         edx,ecx
slouken@1895
   481
        jmp         L4
slouken@1346
   482
L3:
slouken@1895
   483
        mov         ebx,eax
slouken@1895
   484
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   485
        mov         edx,dword ptr [esp+14h]
slouken@1895
   486
        mov         eax,dword ptr [esp+10h]
slouken@1346
   487
L5:
slouken@1895
   488
        shr         ebx,1
slouken@1895
   489
        rcr         ecx,1
slouken@1895
   490
        shr         edx,1
slouken@1895
   491
        rcr         eax,1
slouken@1895
   492
        or          ebx,ebx
slouken@1895
   493
        jne         L5
slouken@1895
   494
        div         ecx
slouken@1895
   495
        mov         esi,eax
slouken@1895
   496
        mul         dword ptr [esp+1Ch]
slouken@1895
   497
        mov         ecx,eax
slouken@1895
   498
        mov         eax,dword ptr [esp+18h]
slouken@1895
   499
        mul         esi
slouken@1895
   500
        add         edx,ecx
slouken@1895
   501
        jb          L6
slouken@1895
   502
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   503
        ja          L6
slouken@1895
   504
        jb          L7
slouken@1895
   505
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   506
        jbe         L7
slouken@1346
   507
L6:
slouken@1895
   508
        dec         esi
slouken@1895
   509
        sub         eax,dword ptr [esp+18h]
slouken@1895
   510
        sbb         edx,dword ptr [esp+1Ch]
slouken@1346
   511
L7:
slouken@1895
   512
        xor         ebx,ebx
slouken@1346
   513
L4:
slouken@1895
   514
        sub         eax,dword ptr [esp+10h]
slouken@1895
   515
        sbb         edx,dword ptr [esp+14h]
slouken@1895
   516
        dec         ebp
slouken@1895
   517
        jns         L9
slouken@1895
   518
        neg         edx
slouken@1895
   519
        neg         eax
slouken@1895
   520
        sbb         edx,0
slouken@1346
   521
L9:
slouken@1895
   522
        mov         ecx,edx
slouken@1895
   523
        mov         edx,ebx
slouken@1895
   524
        mov         ebx,ecx
slouken@1895
   525
        mov         ecx,eax
slouken@1895
   526
        mov         eax,esi
slouken@1895
   527
        dec         edi
slouken@1895
   528
        jne         L8
slouken@1895
   529
        neg         edx
slouken@1895
   530
        neg         eax
slouken@1895
   531
        sbb         edx,0
slouken@1346
   532
L8:
slouken@1895
   533
        pop         ebp
slouken@1895
   534
        pop         esi
slouken@1895
   535
        pop         edi
slouken@1895
   536
        ret         10h
slouken@1895
   537
    }
slouken@1895
   538
    /* *INDENT-ON* */
slouken@1330
   539
}
slouken@2735
   540
slouken@1895
   541
void
slouken@1895
   542
__declspec(naked)
slouken@1895
   543
_aulldvrm()
slouken@1330
   544
{
slouken@1895
   545
    /* *INDENT-OFF* */
slouken@1895
   546
    __asm {
slouken@1895
   547
        push        esi
slouken@1895
   548
        mov         eax,dword ptr [esp+14h]
slouken@1895
   549
        or          eax,eax
slouken@1895
   550
        jne         L1
slouken@1895
   551
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   552
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   553
        xor         edx,edx
slouken@1895
   554
        div         ecx
slouken@1895
   555
        mov         ebx,eax
slouken@1895
   556
        mov         eax,dword ptr [esp+8]
slouken@1895
   557
        div         ecx
slouken@1895
   558
        mov         esi,eax
slouken@1895
   559
        mov         eax,ebx
slouken@1895
   560
        mul         dword ptr [esp+10h]
slouken@1895
   561
        mov         ecx,eax
slouken@1895
   562
        mov         eax,esi
slouken@1895
   563
        mul         dword ptr [esp+10h]
slouken@1895
   564
        add         edx,ecx
slouken@1895
   565
        jmp         L2
slouken@1346
   566
L1:
slouken@1895
   567
        mov         ecx,eax
slouken@1895
   568
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   569
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   570
        mov         eax,dword ptr [esp+8]
slouken@1346
   571
L3:
slouken@1895
   572
        shr         ecx,1
slouken@1895
   573
        rcr         ebx,1
slouken@1895
   574
        shr         edx,1
slouken@1895
   575
        rcr         eax,1
slouken@1895
   576
        or          ecx,ecx
slouken@1895
   577
        jne         L3
slouken@1895
   578
        div         ebx
slouken@1895
   579
        mov         esi,eax
slouken@1895
   580
        mul         dword ptr [esp+14h]
slouken@1895
   581
        mov         ecx,eax
slouken@1895
   582
        mov         eax,dword ptr [esp+10h]
slouken@1895
   583
        mul         esi
slouken@1895
   584
        add         edx,ecx
slouken@1895
   585
        jb          L4
slouken@1895
   586
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   587
        ja          L4
slouken@1895
   588
        jb          L5
slouken@1895
   589
        cmp         eax,dword ptr [esp+8]
slouken@1895
   590
        jbe         L5
slouken@1346
   591
L4:
slouken@1895
   592
        dec         esi
slouken@1895
   593
        sub         eax,dword ptr [esp+10h]
slouken@1895
   594
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   595
L5:
slouken@1895
   596
        xor         ebx,ebx
slouken@1346
   597
L2:
slouken@1895
   598
        sub         eax,dword ptr [esp+8]
slouken@1895
   599
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   600
        neg         edx
slouken@1895
   601
        neg         eax
slouken@1895
   602
        sbb         edx,0
slouken@1895
   603
        mov         ecx,edx
slouken@1895
   604
        mov         edx,ebx
slouken@1895
   605
        mov         ebx,ecx
slouken@1895
   606
        mov         ecx,eax
slouken@1895
   607
        mov         eax,esi
slouken@1895
   608
        pop         esi
slouken@1895
   609
        ret         10h
slouken@1895
   610
    }
slouken@1895
   611
    /* *INDENT-ON* */
slouken@1330
   612
}
slouken@2735
   613
slouken@1895
   614
void
slouken@1895
   615
__declspec(naked)
slouken@1895
   616
_allshl()
slouken@1330
   617
{
slouken@1895
   618
    /* *INDENT-OFF* */
slouken@1895
   619
    __asm {
slouken@1895
   620
        cmp         cl,40h
slouken@1895
   621
        jae         RETZERO
slouken@1895
   622
        cmp         cl,20h
slouken@1895
   623
        jae         MORE32
slouken@1895
   624
        shld        edx,eax,cl
slouken@1895
   625
        shl         eax,cl
slouken@1895
   626
        ret
slouken@1346
   627
MORE32:
slouken@1895
   628
        mov         edx,eax
slouken@1895
   629
        xor         eax,eax
slouken@1895
   630
        and         cl,1Fh
slouken@1895
   631
        shl         edx,cl
slouken@1895
   632
        ret
slouken@1346
   633
RETZERO:
slouken@1895
   634
        xor         eax,eax
slouken@1895
   635
        xor         edx,edx
slouken@1895
   636
        ret
slouken@1895
   637
    }
slouken@1895
   638
    /* *INDENT-ON* */
slouken@1330
   639
}
slouken@2735
   640
slouken@1895
   641
void
slouken@1895
   642
__declspec(naked)
slouken@1895
   643
_aullshr()
slouken@1330
   644
{
slouken@1895
   645
    /* *INDENT-OFF* */
slouken@1895
   646
    __asm {
slouken@1895
   647
        cmp         cl,40h
slouken@1895
   648
        jae         RETZERO
slouken@1895
   649
        cmp         cl,20h
slouken@1895
   650
        jae         MORE32
slouken@1895
   651
        shrd        eax,edx,cl
slouken@1895
   652
        shr         edx,cl
slouken@1895
   653
        ret
slouken@1346
   654
MORE32:
slouken@1895
   655
        mov         eax,edx
slouken@1895
   656
        xor         edx,edx
slouken@1895
   657
        and         cl,1Fh
slouken@1895
   658
        shr         eax,cl
slouken@1895
   659
        ret
slouken@1346
   660
RETZERO:
slouken@1895
   661
        xor         eax,eax
slouken@1895
   662
        xor         edx,edx
slouken@1895
   663
        ret
slouken@1895
   664
    }
slouken@1895
   665
    /* *INDENT-ON* */
slouken@1330
   666
}
slouken@1330
   667
slouken@1330
   668
#endif /* MSC_VER */
slouken@1330
   669
slouken@1331
   670
#endif /* !HAVE_LIBC */
slouken@1895
   671
slouken@1895
   672
/* vi: set ts=4 sw=4 expandtab: */