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