src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 24 Nov 2008 23:25:36 +0000
changeset 2781 5651642f4a78
parent 2760 02aa80d7905f
child 2859 99210400e8b9
permissions -rw-r--r--
Added software fallback for YUV overlay code when YUV textures aren't available.
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
_ftol2_sse()
slouken@1330
    94
{
slouken@1895
    95
    _ftol();
slouken@1330
    96
}
slouken@1330
    97
slouken@1346
    98
/* 64-bit math operators for 32-bit systems */
slouken@1895
    99
void
slouken@1895
   100
__declspec(naked)
slouken@1895
   101
_allmul()
slouken@1330
   102
{
slouken@1895
   103
    /* *INDENT-OFF* */
slouken@1895
   104
    __asm {
slouken@1895
   105
        push        ebp
slouken@1895
   106
        mov         ebp,esp
slouken@1895
   107
        push        edi
slouken@1895
   108
        push        esi
slouken@1895
   109
        push        ebx
slouken@1895
   110
        sub         esp,0Ch
slouken@1895
   111
        mov         eax,dword ptr [ebp+10h]
slouken@1895
   112
        mov         edi,dword ptr [ebp+8]
slouken@1895
   113
        mov         ebx,eax
slouken@1895
   114
        mov         esi,eax
slouken@1895
   115
        sar         esi,1Fh
slouken@1895
   116
        mov         eax,dword ptr [ebp+8]
slouken@1895
   117
        mul         ebx
slouken@1895
   118
        imul        edi,esi
slouken@1895
   119
        mov         ecx,edx
slouken@1895
   120
        mov         dword ptr [ebp-18h],eax
slouken@1895
   121
        mov         edx,dword ptr [ebp+0Ch]
slouken@1895
   122
        add         ecx,edi
slouken@1895
   123
        imul        ebx,edx
slouken@1895
   124
        mov         eax,dword ptr [ebp-18h]
slouken@1895
   125
        lea         ebx,[ebx+ecx]
slouken@1895
   126
        mov         dword ptr [ebp-14h],ebx
slouken@1895
   127
        mov         edx,dword ptr [ebp-14h]
slouken@1895
   128
        add         esp,0Ch
slouken@1895
   129
        pop         ebx
slouken@1895
   130
        pop         esi
slouken@1895
   131
        pop         edi
slouken@1895
   132
        pop         ebp
slouken@1895
   133
        ret
slouken@1895
   134
    }
slouken@1895
   135
    /* *INDENT-ON* */
slouken@1330
   136
}
slouken@2735
   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@2735
   225
slouken@1895
   226
void
slouken@1895
   227
__declspec(naked)
slouken@1895
   228
_aulldiv()
slouken@1330
   229
{
slouken@1895
   230
    /* *INDENT-OFF* */
slouken@1895
   231
    __asm {
slouken@1895
   232
        push        ebx
slouken@1895
   233
        push        esi
slouken@1895
   234
        mov         eax,dword ptr [esp+18h]
slouken@1895
   235
        or          eax,eax
slouken@1895
   236
        jne         L1
slouken@1895
   237
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   238
        mov         eax,dword ptr [esp+10h]
slouken@1895
   239
        xor         edx,edx
slouken@1895
   240
        div         ecx
slouken@1895
   241
        mov         ebx,eax
slouken@1895
   242
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   243
        div         ecx
slouken@1895
   244
        mov         edx,ebx
slouken@1895
   245
        jmp         L2
slouken@1346
   246
L1:
slouken@1895
   247
        mov         ecx,eax
slouken@1895
   248
        mov         ebx,dword ptr [esp+14h]
slouken@1895
   249
        mov         edx,dword ptr [esp+10h]
slouken@1895
   250
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   251
L3:
slouken@1895
   252
        shr         ecx,1
slouken@1895
   253
        rcr         ebx,1
slouken@1895
   254
        shr         edx,1
slouken@1895
   255
        rcr         eax,1
slouken@1895
   256
        or          ecx,ecx
slouken@1895
   257
        jne         L3
slouken@1895
   258
        div         ebx
slouken@1895
   259
        mov         esi,eax
slouken@1895
   260
        mul         dword ptr [esp+18h]
slouken@1895
   261
        mov         ecx,eax
slouken@1895
   262
        mov         eax,dword ptr [esp+14h]
slouken@1895
   263
        mul         esi
slouken@1895
   264
        add         edx,ecx
slouken@1895
   265
        jb          L4
slouken@1895
   266
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   267
        ja          L4
slouken@1895
   268
        jb          L5
slouken@1895
   269
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   270
        jbe         L5
slouken@1346
   271
L4:
slouken@1895
   272
        dec         esi
slouken@1346
   273
L5:
slouken@1895
   274
        xor         edx,edx
slouken@1895
   275
        mov         eax,esi
slouken@1346
   276
L2:
slouken@1895
   277
        pop         esi
slouken@1895
   278
        pop         ebx
slouken@1895
   279
        ret         10h
slouken@1895
   280
    }
slouken@1895
   281
    /* *INDENT-ON* */
slouken@1330
   282
}
slouken@2735
   283
slouken@1895
   284
void
slouken@1895
   285
__declspec(naked)
slouken@1895
   286
_allrem()
slouken@1330
   287
{
slouken@1895
   288
    /* *INDENT-OFF* */
slouken@1895
   289
    __asm {
slouken@1895
   290
        push        ebx
slouken@1895
   291
        push        edi
slouken@1895
   292
        xor         edi,edi
slouken@1895
   293
        mov         eax,dword ptr [esp+10h]
slouken@1895
   294
        or          eax,eax
slouken@1895
   295
        jge         L1
slouken@1895
   296
        inc         edi
slouken@1895
   297
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   298
        neg         eax
slouken@1895
   299
        neg         edx
slouken@1895
   300
        sbb         eax,0
slouken@1895
   301
        mov         dword ptr [esp+10h],eax
slouken@1895
   302
        mov         dword ptr [esp+0Ch],edx
slouken@1346
   303
L1:
slouken@1895
   304
        mov         eax,dword ptr [esp+18h]
slouken@1895
   305
        or          eax,eax
slouken@1895
   306
        jge         L2
slouken@1895
   307
        mov         edx,dword ptr [esp+14h]
slouken@1895
   308
        neg         eax
slouken@1895
   309
        neg         edx
slouken@1895
   310
        sbb         eax,0
slouken@1895
   311
        mov         dword ptr [esp+18h],eax
slouken@1895
   312
        mov         dword ptr [esp+14h],edx
slouken@1346
   313
L2:
slouken@1895
   314
        or          eax,eax
slouken@1895
   315
        jne         L3
slouken@1895
   316
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   317
        mov         eax,dword ptr [esp+10h]
slouken@1895
   318
        xor         edx,edx
slouken@1895
   319
        div         ecx
slouken@1895
   320
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   321
        div         ecx
slouken@1895
   322
        mov         eax,edx
slouken@1895
   323
        xor         edx,edx
slouken@1895
   324
        dec         edi
slouken@1895
   325
        jns         L4
slouken@1895
   326
        jmp         L8
slouken@1346
   327
L3:
slouken@1895
   328
        mov         ebx,eax
slouken@1895
   329
        mov         ecx,dword ptr [esp+14h]
slouken@1895
   330
        mov         edx,dword ptr [esp+10h]
slouken@1895
   331
        mov         eax,dword ptr [esp+0Ch]
slouken@1346
   332
L5:
slouken@1895
   333
        shr         ebx,1
slouken@1895
   334
        rcr         ecx,1
slouken@1895
   335
        shr         edx,1
slouken@1895
   336
        rcr         eax,1
slouken@1895
   337
        or          ebx,ebx
slouken@1895
   338
        jne         L5
slouken@1895
   339
        div         ecx
slouken@1895
   340
        mov         ecx,eax
slouken@1895
   341
        mul         dword ptr [esp+18h]
slouken@1895
   342
        xchg        eax,ecx
slouken@1895
   343
        mul         dword ptr [esp+14h]
slouken@1895
   344
        add         edx,ecx
slouken@1895
   345
        jb          L6
slouken@1895
   346
        cmp         edx,dword ptr [esp+10h]
slouken@1895
   347
        ja          L6
slouken@1895
   348
        jb          L7
slouken@1895
   349
        cmp         eax,dword ptr [esp+0Ch]
slouken@1895
   350
        jbe         L7
slouken@1346
   351
L6:
slouken@1895
   352
        sub         eax,dword ptr [esp+14h]
slouken@1895
   353
        sbb         edx,dword ptr [esp+18h]
slouken@1346
   354
L7:
slouken@1895
   355
        sub         eax,dword ptr [esp+0Ch]
slouken@1895
   356
        sbb         edx,dword ptr [esp+10h]
slouken@1895
   357
        dec         edi
slouken@1895
   358
        jns         L8
slouken@1346
   359
L4:
slouken@1895
   360
        neg         edx
slouken@1895
   361
        neg         eax
slouken@1895
   362
        sbb         edx,0
slouken@1346
   363
L8:
slouken@1895
   364
        pop         edi
slouken@1895
   365
        pop         ebx
slouken@1895
   366
        ret         10h
slouken@1895
   367
    }
slouken@1895
   368
    /* *INDENT-ON* */
slouken@1330
   369
}
slouken@2735
   370
slouken@1895
   371
void
slouken@1895
   372
__declspec(naked)
slouken@1895
   373
_aullrem()
slouken@1330
   374
{
slouken@1895
   375
    /* *INDENT-OFF* */
slouken@1895
   376
    __asm {
slouken@1895
   377
        push        ebx
slouken@1895
   378
        mov         eax,dword ptr [esp+14h]
slouken@1895
   379
        or          eax,eax
slouken@1895
   380
        jne         L1
slouken@1895
   381
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   382
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   383
        xor         edx,edx
slouken@1895
   384
        div         ecx
slouken@1895
   385
        mov         eax,dword ptr [esp+8]
slouken@1895
   386
        div         ecx
slouken@1895
   387
        mov         eax,edx
slouken@1895
   388
        xor         edx,edx
slouken@1895
   389
        jmp         L2
slouken@1346
   390
L1:
slouken@1895
   391
        mov         ecx,eax
slouken@1895
   392
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   393
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   394
        mov         eax,dword ptr [esp+8]
slouken@1346
   395
L3:
slouken@1895
   396
        shr         ecx,1
slouken@1895
   397
        rcr         ebx,1
slouken@1895
   398
        shr         edx,1
slouken@1895
   399
        rcr         eax,1
slouken@1895
   400
        or          ecx,ecx
slouken@1895
   401
        jne         L3
slouken@1895
   402
        div         ebx
slouken@1895
   403
        mov         ecx,eax
slouken@1895
   404
        mul         dword ptr [esp+14h]
slouken@1895
   405
        xchg        eax,ecx
slouken@1895
   406
        mul         dword ptr [esp+10h]
slouken@1895
   407
        add         edx,ecx
slouken@1895
   408
        jb          L4
slouken@1895
   409
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   410
        ja          L4
slouken@1895
   411
        jb          L5
slouken@1895
   412
        cmp         eax,dword ptr [esp+8]
slouken@1895
   413
        jbe         L5
slouken@1346
   414
L4:
slouken@1895
   415
        sub         eax,dword ptr [esp+10h]
slouken@1895
   416
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   417
L5:
slouken@1895
   418
        sub         eax,dword ptr [esp+8]
slouken@1895
   419
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   420
        neg         edx
slouken@1895
   421
        neg         eax
slouken@1895
   422
        sbb         edx,0
slouken@1346
   423
L2:
slouken@1895
   424
        pop         ebx
slouken@1895
   425
        ret         10h
slouken@1895
   426
    }
slouken@1895
   427
    /* *INDENT-ON* */
slouken@1330
   428
}
slouken@2735
   429
slouken@1895
   430
void
slouken@1895
   431
__declspec(naked)
slouken@1895
   432
_alldvrm()
slouken@1330
   433
{
slouken@1895
   434
    /* *INDENT-OFF* */
slouken@1895
   435
    __asm {
slouken@1895
   436
        push        edi
slouken@1895
   437
        push        esi
slouken@1895
   438
        push        ebp
slouken@1895
   439
        xor         edi,edi
slouken@1895
   440
        xor         ebp,ebp
slouken@1895
   441
        mov         eax,dword ptr [esp+14h]
slouken@1895
   442
        or          eax,eax
slouken@1895
   443
        jge         L1
slouken@1895
   444
        inc         edi
slouken@1895
   445
        inc         ebp
slouken@1895
   446
        mov         edx,dword ptr [esp+10h]
slouken@1895
   447
        neg         eax
slouken@1895
   448
        neg         edx
slouken@1895
   449
        sbb         eax,0
slouken@1895
   450
        mov         dword ptr [esp+14h],eax
slouken@1895
   451
        mov         dword ptr [esp+10h],edx
slouken@1346
   452
L1:
slouken@1895
   453
        mov         eax,dword ptr [esp+1Ch]
slouken@1895
   454
        or          eax,eax
slouken@1895
   455
        jge         L2
slouken@1895
   456
        inc         edi
slouken@1895
   457
        mov         edx,dword ptr [esp+18h]
slouken@1895
   458
        neg         eax
slouken@1895
   459
        neg         edx
slouken@1895
   460
        sbb         eax,0
slouken@1895
   461
        mov         dword ptr [esp+1Ch],eax
slouken@1895
   462
        mov         dword ptr [esp+18h],edx
slouken@1346
   463
L2:
slouken@1895
   464
        or          eax,eax
slouken@1895
   465
        jne         L3
slouken@1895
   466
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   467
        mov         eax,dword ptr [esp+14h]
slouken@1895
   468
        xor         edx,edx
slouken@1895
   469
        div         ecx
slouken@1895
   470
        mov         ebx,eax
slouken@1895
   471
        mov         eax,dword ptr [esp+10h]
slouken@1895
   472
        div         ecx
slouken@1895
   473
        mov         esi,eax
slouken@1895
   474
        mov         eax,ebx
slouken@1895
   475
        mul         dword ptr [esp+18h]
slouken@1895
   476
        mov         ecx,eax
slouken@1895
   477
        mov         eax,esi
slouken@1895
   478
        mul         dword ptr [esp+18h]
slouken@1895
   479
        add         edx,ecx
slouken@1895
   480
        jmp         L4
slouken@1346
   481
L3:
slouken@1895
   482
        mov         ebx,eax
slouken@1895
   483
        mov         ecx,dword ptr [esp+18h]
slouken@1895
   484
        mov         edx,dword ptr [esp+14h]
slouken@1895
   485
        mov         eax,dword ptr [esp+10h]
slouken@1346
   486
L5:
slouken@1895
   487
        shr         ebx,1
slouken@1895
   488
        rcr         ecx,1
slouken@1895
   489
        shr         edx,1
slouken@1895
   490
        rcr         eax,1
slouken@1895
   491
        or          ebx,ebx
slouken@1895
   492
        jne         L5
slouken@1895
   493
        div         ecx
slouken@1895
   494
        mov         esi,eax
slouken@1895
   495
        mul         dword ptr [esp+1Ch]
slouken@1895
   496
        mov         ecx,eax
slouken@1895
   497
        mov         eax,dword ptr [esp+18h]
slouken@1895
   498
        mul         esi
slouken@1895
   499
        add         edx,ecx
slouken@1895
   500
        jb          L6
slouken@1895
   501
        cmp         edx,dword ptr [esp+14h]
slouken@1895
   502
        ja          L6
slouken@1895
   503
        jb          L7
slouken@1895
   504
        cmp         eax,dword ptr [esp+10h]
slouken@1895
   505
        jbe         L7
slouken@1346
   506
L6:
slouken@1895
   507
        dec         esi
slouken@1895
   508
        sub         eax,dword ptr [esp+18h]
slouken@1895
   509
        sbb         edx,dword ptr [esp+1Ch]
slouken@1346
   510
L7:
slouken@1895
   511
        xor         ebx,ebx
slouken@1346
   512
L4:
slouken@1895
   513
        sub         eax,dword ptr [esp+10h]
slouken@1895
   514
        sbb         edx,dword ptr [esp+14h]
slouken@1895
   515
        dec         ebp
slouken@1895
   516
        jns         L9
slouken@1895
   517
        neg         edx
slouken@1895
   518
        neg         eax
slouken@1895
   519
        sbb         edx,0
slouken@1346
   520
L9:
slouken@1895
   521
        mov         ecx,edx
slouken@1895
   522
        mov         edx,ebx
slouken@1895
   523
        mov         ebx,ecx
slouken@1895
   524
        mov         ecx,eax
slouken@1895
   525
        mov         eax,esi
slouken@1895
   526
        dec         edi
slouken@1895
   527
        jne         L8
slouken@1895
   528
        neg         edx
slouken@1895
   529
        neg         eax
slouken@1895
   530
        sbb         edx,0
slouken@1346
   531
L8:
slouken@1895
   532
        pop         ebp
slouken@1895
   533
        pop         esi
slouken@1895
   534
        pop         edi
slouken@1895
   535
        ret         10h
slouken@1895
   536
    }
slouken@1895
   537
    /* *INDENT-ON* */
slouken@1330
   538
}
slouken@2735
   539
slouken@1895
   540
void
slouken@1895
   541
__declspec(naked)
slouken@1895
   542
_aulldvrm()
slouken@1330
   543
{
slouken@1895
   544
    /* *INDENT-OFF* */
slouken@1895
   545
    __asm {
slouken@1895
   546
        push        esi
slouken@1895
   547
        mov         eax,dword ptr [esp+14h]
slouken@1895
   548
        or          eax,eax
slouken@1895
   549
        jne         L1
slouken@1895
   550
        mov         ecx,dword ptr [esp+10h]
slouken@1895
   551
        mov         eax,dword ptr [esp+0Ch]
slouken@1895
   552
        xor         edx,edx
slouken@1895
   553
        div         ecx
slouken@1895
   554
        mov         ebx,eax
slouken@1895
   555
        mov         eax,dword ptr [esp+8]
slouken@1895
   556
        div         ecx
slouken@1895
   557
        mov         esi,eax
slouken@1895
   558
        mov         eax,ebx
slouken@1895
   559
        mul         dword ptr [esp+10h]
slouken@1895
   560
        mov         ecx,eax
slouken@1895
   561
        mov         eax,esi
slouken@1895
   562
        mul         dword ptr [esp+10h]
slouken@1895
   563
        add         edx,ecx
slouken@1895
   564
        jmp         L2
slouken@1346
   565
L1:
slouken@1895
   566
        mov         ecx,eax
slouken@1895
   567
        mov         ebx,dword ptr [esp+10h]
slouken@1895
   568
        mov         edx,dword ptr [esp+0Ch]
slouken@1895
   569
        mov         eax,dword ptr [esp+8]
slouken@1346
   570
L3:
slouken@1895
   571
        shr         ecx,1
slouken@1895
   572
        rcr         ebx,1
slouken@1895
   573
        shr         edx,1
slouken@1895
   574
        rcr         eax,1
slouken@1895
   575
        or          ecx,ecx
slouken@1895
   576
        jne         L3
slouken@1895
   577
        div         ebx
slouken@1895
   578
        mov         esi,eax
slouken@1895
   579
        mul         dword ptr [esp+14h]
slouken@1895
   580
        mov         ecx,eax
slouken@1895
   581
        mov         eax,dword ptr [esp+10h]
slouken@1895
   582
        mul         esi
slouken@1895
   583
        add         edx,ecx
slouken@1895
   584
        jb          L4
slouken@1895
   585
        cmp         edx,dword ptr [esp+0Ch]
slouken@1895
   586
        ja          L4
slouken@1895
   587
        jb          L5
slouken@1895
   588
        cmp         eax,dword ptr [esp+8]
slouken@1895
   589
        jbe         L5
slouken@1346
   590
L4:
slouken@1895
   591
        dec         esi
slouken@1895
   592
        sub         eax,dword ptr [esp+10h]
slouken@1895
   593
        sbb         edx,dword ptr [esp+14h]
slouken@1346
   594
L5:
slouken@1895
   595
        xor         ebx,ebx
slouken@1346
   596
L2:
slouken@1895
   597
        sub         eax,dword ptr [esp+8]
slouken@1895
   598
        sbb         edx,dword ptr [esp+0Ch]
slouken@1895
   599
        neg         edx
slouken@1895
   600
        neg         eax
slouken@1895
   601
        sbb         edx,0
slouken@1895
   602
        mov         ecx,edx
slouken@1895
   603
        mov         edx,ebx
slouken@1895
   604
        mov         ebx,ecx
slouken@1895
   605
        mov         ecx,eax
slouken@1895
   606
        mov         eax,esi
slouken@1895
   607
        pop         esi
slouken@1895
   608
        ret         10h
slouken@1895
   609
    }
slouken@1895
   610
    /* *INDENT-ON* */
slouken@1330
   611
}
slouken@2735
   612
slouken@1895
   613
void
slouken@1895
   614
__declspec(naked)
slouken@1895
   615
_allshl()
slouken@1330
   616
{
slouken@1895
   617
    /* *INDENT-OFF* */
slouken@1895
   618
    __asm {
slouken@1895
   619
        cmp         cl,40h
slouken@1895
   620
        jae         RETZERO
slouken@1895
   621
        cmp         cl,20h
slouken@1895
   622
        jae         MORE32
slouken@1895
   623
        shld        edx,eax,cl
slouken@1895
   624
        shl         eax,cl
slouken@1895
   625
        ret
slouken@1346
   626
MORE32:
slouken@1895
   627
        mov         edx,eax
slouken@1895
   628
        xor         eax,eax
slouken@1895
   629
        and         cl,1Fh
slouken@1895
   630
        shl         edx,cl
slouken@1895
   631
        ret
slouken@1346
   632
RETZERO:
slouken@1895
   633
        xor         eax,eax
slouken@1895
   634
        xor         edx,edx
slouken@1895
   635
        ret
slouken@1895
   636
    }
slouken@1895
   637
    /* *INDENT-ON* */
slouken@1330
   638
}
slouken@2735
   639
slouken@1895
   640
void
slouken@1895
   641
__declspec(naked)
slouken@2760
   642
_allshr()
slouken@2760
   643
{
slouken@2760
   644
    /* *INDENT-OFF* */
slouken@2760
   645
    __asm {
slouken@2760
   646
        cmp         cl,40h
slouken@2760
   647
        jae         RETZERO
slouken@2760
   648
        cmp         cl,20h
slouken@2760
   649
        jae         MORE32
slouken@2760
   650
        shrd        eax,edx,cl
slouken@2760
   651
        sar         edx,cl
slouken@2760
   652
        ret
slouken@2760
   653
MORE32:
slouken@2760
   654
        mov         eax,edx
slouken@2760
   655
        xor         edx,edx
slouken@2760
   656
        and         cl,1Fh
slouken@2760
   657
        sar         eax,cl
slouken@2760
   658
        ret
slouken@2760
   659
RETZERO:
slouken@2760
   660
        xor         eax,eax
slouken@2760
   661
        xor         edx,edx
slouken@2760
   662
        ret
slouken@2760
   663
    }
slouken@2760
   664
    /* *INDENT-ON* */
slouken@2760
   665
}
slouken@2760
   666
slouken@2760
   667
void
slouken@2760
   668
__declspec(naked)
slouken@1895
   669
_aullshr()
slouken@1330
   670
{
slouken@1895
   671
    /* *INDENT-OFF* */
slouken@1895
   672
    __asm {
slouken@1895
   673
        cmp         cl,40h
slouken@1895
   674
        jae         RETZERO
slouken@1895
   675
        cmp         cl,20h
slouken@1895
   676
        jae         MORE32
slouken@1895
   677
        shrd        eax,edx,cl
slouken@1895
   678
        shr         edx,cl
slouken@1895
   679
        ret
slouken@1346
   680
MORE32:
slouken@1895
   681
        mov         eax,edx
slouken@1895
   682
        xor         edx,edx
slouken@1895
   683
        and         cl,1Fh
slouken@1895
   684
        shr         eax,cl
slouken@1895
   685
        ret
slouken@1346
   686
RETZERO:
slouken@1895
   687
        xor         eax,eax
slouken@1895
   688
        xor         edx,edx
slouken@1895
   689
        ret
slouken@1895
   690
    }
slouken@1895
   691
    /* *INDENT-ON* */
slouken@1330
   692
}
slouken@1330
   693
slouken@1330
   694
#endif /* MSC_VER */
slouken@1330
   695
slouken@1331
   696
#endif /* !HAVE_LIBC */
slouken@1895
   697
slouken@1895
   698
/* vi: set ts=4 sw=4 expandtab: */