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