src/stdlib/SDL_stdlib.c
changeset 1346 1b5fbaf1d2c6
parent 1345 7f32b9bede06
child 1354 22f39393668a
     1.1 --- a/src/stdlib/SDL_stdlib.c	Tue Feb 07 18:36:54 2006 +0000
     1.2 +++ b/src/stdlib/SDL_stdlib.c	Wed Feb 08 08:55:33 2006 +0000
     1.3 @@ -30,43 +30,581 @@
     1.4  
     1.5  #if defined(_MSC_VER)
     1.6  
     1.7 -/* Float to long (FIXME!) */
     1.8 -long _ftol()
     1.9 +/* Float to long */
    1.10 +void __declspec(naked) _ftol()
    1.11  {
    1.12 -	return 0;
    1.13 +	__asm {
    1.14 +		push        ebp
    1.15 +		mov         ebp,esp
    1.16 +		sub         esp,20h
    1.17 +		and         esp,0FFFFFFF0h
    1.18 +		fld         st(0)
    1.19 +		fst         dword ptr [esp+18h]
    1.20 +		fistp       qword ptr [esp+10h]
    1.21 +		fild        qword ptr [esp+10h]
    1.22 +		mov         edx,dword ptr [esp+18h]
    1.23 +		mov         eax,dword ptr [esp+10h]
    1.24 +		test        eax,eax
    1.25 +		je          integer_QnaN_or_zero
    1.26 +arg_is_not_integer_QnaN:
    1.27 +		fsubp       st(1),st
    1.28 +		test        edx,edx
    1.29 +		jns         positive
    1.30 +		fstp        dword ptr [esp]
    1.31 +		mov         ecx,dword ptr [esp]
    1.32 +		xor         ecx,80000000h
    1.33 +		add         ecx,7FFFFFFFh
    1.34 +		adc         eax,0
    1.35 +		mov         edx,dword ptr [esp+14h]
    1.36 +		adc         edx,0
    1.37 +		jmp         localexit
    1.38 +positive:
    1.39 +		fstp        dword ptr [esp]
    1.40 +		mov         ecx,dword ptr [esp]
    1.41 +		add         ecx,7FFFFFFFh
    1.42 +		sbb         eax,0
    1.43 +		mov         edx,dword ptr [esp+14h]
    1.44 +		sbb         edx,0
    1.45 +		jmp         localexit
    1.46 +integer_QnaN_or_zero:
    1.47 +		mov         edx,dword ptr [esp+14h]
    1.48 +		test        edx,7FFFFFFFh
    1.49 +		jne         arg_is_not_integer_QnaN
    1.50 +		fstp        dword ptr [esp+18h]
    1.51 +		fstp        dword ptr [esp+18h]
    1.52 +localexit:
    1.53 +		leave
    1.54 +		ret
    1.55 +	}
    1.56  }
    1.57 -long _ftol2_sse()
    1.58 +void __declspec(naked) _ftol2_sse()
    1.59  {
    1.60 -	return 0;
    1.61 +	_ftol();
    1.62  }
    1.63  
    1.64 -/* 64-bit math operators (FIXME!) */
    1.65 -void _allmul()
    1.66 +/* 64-bit math operators for 32-bit systems */
    1.67 +void __declspec(naked) _allmul()
    1.68  {
    1.69 +	__asm {
    1.70 +		push        ebp
    1.71 +		mov         ebp,esp
    1.72 +		push        edi
    1.73 +		push        esi
    1.74 +		push        ebx
    1.75 +		sub         esp,0Ch
    1.76 +		mov         eax,dword ptr [ebp+10h]
    1.77 +		mov         edi,dword ptr [ebp+8]
    1.78 +		mov         ebx,eax
    1.79 +		mov         esi,eax
    1.80 +		sar         esi,1Fh
    1.81 +		mov         eax,dword ptr [ebp+8]
    1.82 +		mul         ebx
    1.83 +		imul        edi,esi
    1.84 +		mov         ecx,edx
    1.85 +		mov         dword ptr [ebp-18h],eax
    1.86 +		mov         edx,dword ptr [ebp+0Ch]
    1.87 +		add         ecx,edi
    1.88 +		imul        ebx,edx
    1.89 +		mov         eax,dword ptr [ebp-18h]
    1.90 +		lea         ebx,[ebx+ecx]
    1.91 +		mov         dword ptr [ebp-14h],ebx
    1.92 +		mov         edx,dword ptr [ebp-14h]
    1.93 +		add         esp,0Ch
    1.94 +		pop         ebx
    1.95 +		pop         esi
    1.96 +		pop         edi
    1.97 +		pop         ebp
    1.98 +		ret
    1.99 +	}
   1.100  }
   1.101 -void _alldiv()
   1.102 +void __declspec(naked) _alldiv()
   1.103  {
   1.104 +	__asm {
   1.105 +		push        edi
   1.106 +		push        esi
   1.107 +		push        ebx
   1.108 +		xor         edi,edi
   1.109 +		mov         eax,dword ptr [esp+14h]
   1.110 +		or          eax,eax
   1.111 +		jge         L1
   1.112 +		inc         edi
   1.113 +		mov         edx,dword ptr [esp+10h]
   1.114 +		neg         eax
   1.115 +		neg         edx
   1.116 +		sbb         eax,0
   1.117 +		mov         dword ptr [esp+14h],eax
   1.118 +		mov         dword ptr [esp+10h],edx
   1.119 +L1:
   1.120 +		mov         eax,dword ptr [esp+1Ch]
   1.121 +		or          eax,eax
   1.122 +		jge         L2
   1.123 +		inc         edi
   1.124 +		mov         edx,dword ptr [esp+18h]
   1.125 +		neg         eax
   1.126 +		neg         edx
   1.127 +		sbb         eax,0
   1.128 +		mov         dword ptr [esp+1Ch],eax
   1.129 +		mov         dword ptr [esp+18h],edx
   1.130 +L2:
   1.131 +		or          eax,eax
   1.132 +		jne         L3
   1.133 +		mov         ecx,dword ptr [esp+18h]
   1.134 +		mov         eax,dword ptr [esp+14h]
   1.135 +		xor         edx,edx
   1.136 +		div         ecx
   1.137 +		mov         ebx,eax
   1.138 +		mov         eax,dword ptr [esp+10h]
   1.139 +		div         ecx
   1.140 +		mov         edx,ebx
   1.141 +		jmp         L4
   1.142 +L3:
   1.143 +		mov         ebx,eax
   1.144 +		mov         ecx,dword ptr [esp+18h]
   1.145 +		mov         edx,dword ptr [esp+14h]
   1.146 +		mov         eax,dword ptr [esp+10h]
   1.147 +L5:
   1.148 +		shr         ebx,1
   1.149 +		rcr         ecx,1
   1.150 +		shr         edx,1
   1.151 +		rcr         eax,1
   1.152 +		or          ebx,ebx
   1.153 +		jne         L5
   1.154 +		div         ecx
   1.155 +		mov         esi,eax
   1.156 +		mul         dword ptr [esp+1Ch]
   1.157 +		mov         ecx,eax
   1.158 +		mov         eax,dword ptr [esp+18h]
   1.159 +		mul         esi
   1.160 +		add         edx,ecx
   1.161 +		jb          L6
   1.162 +		cmp         edx,dword ptr [esp+14h]
   1.163 +		ja          L6
   1.164 +		jb          L7
   1.165 +		cmp         eax,dword ptr [esp+10h]
   1.166 +		jbe         L7
   1.167 +L6:
   1.168 +		dec         esi
   1.169 +L7:
   1.170 +		xor         edx,edx
   1.171 +		mov         eax,esi
   1.172 +L4:
   1.173 +		dec         edi
   1.174 +		jne         L8
   1.175 +		neg         edx
   1.176 +		neg         eax
   1.177 +		sbb         edx,0
   1.178 +L8:
   1.179 +		pop         ebx
   1.180 +		pop         esi
   1.181 +		pop         edi
   1.182 +		ret         10h
   1.183 +	}
   1.184  }
   1.185 -void _aulldiv()
   1.186 +void __declspec(naked) _aulldiv()
   1.187  {
   1.188 +	__asm {
   1.189 +		push        ebx
   1.190 +		push        esi
   1.191 +		mov         eax,dword ptr [esp+18h]
   1.192 +		or          eax,eax
   1.193 +		jne         L1
   1.194 +		mov         ecx,dword ptr [esp+14h]
   1.195 +		mov         eax,dword ptr [esp+10h]
   1.196 +		xor         edx,edx
   1.197 +		div         ecx
   1.198 +		mov         ebx,eax
   1.199 +		mov         eax,dword ptr [esp+0Ch]
   1.200 +		div         ecx
   1.201 +		mov         edx,ebx
   1.202 +		jmp         L2
   1.203 +L1:
   1.204 +		mov         ecx,eax
   1.205 +		mov         ebx,dword ptr [esp+14h]
   1.206 +		mov         edx,dword ptr [esp+10h]
   1.207 +		mov         eax,dword ptr [esp+0Ch]
   1.208 +L3:
   1.209 +		shr         ecx,1
   1.210 +		rcr         ebx,1
   1.211 +		shr         edx,1
   1.212 +		rcr         eax,1
   1.213 +		or          ecx,ecx
   1.214 +		jne         L3
   1.215 +		div         ebx
   1.216 +		mov         esi,eax
   1.217 +		mul         dword ptr [esp+18h]
   1.218 +		mov         ecx,eax
   1.219 +		mov         eax,dword ptr [esp+14h]
   1.220 +		mul         esi
   1.221 +		add         edx,ecx
   1.222 +		jb          L4
   1.223 +		cmp         edx,dword ptr [esp+10h]
   1.224 +		ja          L4
   1.225 +		jb          L5
   1.226 +		cmp         eax,dword ptr [esp+0Ch]
   1.227 +		jbe         L5
   1.228 +L4:
   1.229 +		dec         esi
   1.230 +L5:
   1.231 +		xor         edx,edx
   1.232 +		mov         eax,esi
   1.233 +L2:
   1.234 +		pop         esi
   1.235 +		pop         ebx
   1.236 +		ret         10h
   1.237 +	}
   1.238  }
   1.239 -void _allrem()
   1.240 +void __declspec(naked) _allrem()
   1.241  {
   1.242 +	__asm {
   1.243 +		push        ebx
   1.244 +		push        edi
   1.245 +		xor         edi,edi
   1.246 +		mov         eax,dword ptr [esp+10h]
   1.247 +		or          eax,eax
   1.248 +		jge         L1
   1.249 +		inc         edi
   1.250 +		mov         edx,dword ptr [esp+0Ch]
   1.251 +		neg         eax
   1.252 +		neg         edx
   1.253 +		sbb         eax,0
   1.254 +		mov         dword ptr [esp+10h],eax
   1.255 +		mov         dword ptr [esp+0Ch],edx
   1.256 +L1:
   1.257 +		mov         eax,dword ptr [esp+18h]
   1.258 +		or          eax,eax
   1.259 +		jge         L2
   1.260 +		mov         edx,dword ptr [esp+14h]
   1.261 +		neg         eax
   1.262 +		neg         edx
   1.263 +		sbb         eax,0
   1.264 +		mov         dword ptr [esp+18h],eax
   1.265 +		mov         dword ptr [esp+14h],edx
   1.266 +L2:
   1.267 +		or          eax,eax
   1.268 +		jne         L3
   1.269 +		mov         ecx,dword ptr [esp+14h]
   1.270 +		mov         eax,dword ptr [esp+10h]
   1.271 +		xor         edx,edx
   1.272 +		div         ecx
   1.273 +		mov         eax,dword ptr [esp+0Ch]
   1.274 +		div         ecx
   1.275 +		mov         eax,edx
   1.276 +		xor         edx,edx
   1.277 +		dec         edi
   1.278 +		jns         L4
   1.279 +		jmp         L8
   1.280 +L3:
   1.281 +		mov         ebx,eax
   1.282 +		mov         ecx,dword ptr [esp+14h]
   1.283 +		mov         edx,dword ptr [esp+10h]
   1.284 +		mov         eax,dword ptr [esp+0Ch]
   1.285 +L5:
   1.286 +		shr         ebx,1
   1.287 +		rcr         ecx,1
   1.288 +		shr         edx,1
   1.289 +		rcr         eax,1
   1.290 +		or          ebx,ebx
   1.291 +		jne         L5
   1.292 +		div         ecx
   1.293 +		mov         ecx,eax
   1.294 +		mul         dword ptr [esp+18h]
   1.295 +		xchg        eax,ecx
   1.296 +		mul         dword ptr [esp+14h]
   1.297 +		add         edx,ecx
   1.298 +		jb          L6
   1.299 +		cmp         edx,dword ptr [esp+10h]
   1.300 +		ja          L6
   1.301 +		jb          L7
   1.302 +		cmp         eax,dword ptr [esp+0Ch]
   1.303 +		jbe         L7
   1.304 +L6:
   1.305 +		sub         eax,dword ptr [esp+14h]
   1.306 +		sbb         edx,dword ptr [esp+18h]
   1.307 +L7:
   1.308 +		sub         eax,dword ptr [esp+0Ch]
   1.309 +		sbb         edx,dword ptr [esp+10h]
   1.310 +		dec         edi
   1.311 +		jns         L8
   1.312 +L4:
   1.313 +		neg         edx
   1.314 +		neg         eax
   1.315 +		sbb         edx,0
   1.316 +L8:
   1.317 +		pop         edi
   1.318 +		pop         ebx
   1.319 +		ret         10h
   1.320 +	}
   1.321  }
   1.322 -void _aullrem()
   1.323 +void __declspec(naked) _aullrem()
   1.324  {
   1.325 +	__asm {
   1.326 +		push        ebx
   1.327 +		mov         eax,dword ptr [esp+14h]
   1.328 +		or          eax,eax
   1.329 +		jne         L1
   1.330 +		mov         ecx,dword ptr [esp+10h]
   1.331 +		mov         eax,dword ptr [esp+0Ch]
   1.332 +		xor         edx,edx
   1.333 +		div         ecx
   1.334 +		mov         eax,dword ptr [esp+8]
   1.335 +		div         ecx
   1.336 +		mov         eax,edx
   1.337 +		xor         edx,edx
   1.338 +		jmp         L2
   1.339 +L1:
   1.340 +		mov         ecx,eax
   1.341 +		mov         ebx,dword ptr [esp+10h]
   1.342 +		mov         edx,dword ptr [esp+0Ch]
   1.343 +		mov         eax,dword ptr [esp+8]
   1.344 +L3:
   1.345 +		shr         ecx,1
   1.346 +		rcr         ebx,1
   1.347 +		shr         edx,1
   1.348 +		rcr         eax,1
   1.349 +		or          ecx,ecx
   1.350 +		jne         L3
   1.351 +		div         ebx
   1.352 +		mov         ecx,eax
   1.353 +		mul         dword ptr [esp+14h]
   1.354 +		xchg        eax,ecx
   1.355 +		mul         dword ptr [esp+10h]
   1.356 +		add         edx,ecx
   1.357 +		jb          L4
   1.358 +		cmp         edx,dword ptr [esp+0Ch]
   1.359 +		ja          L4
   1.360 +		jb          L5
   1.361 +		cmp         eax,dword ptr [esp+8]
   1.362 +		jbe         L5
   1.363 +L4:
   1.364 +		sub         eax,dword ptr [esp+10h]
   1.365 +		sbb         edx,dword ptr [esp+14h]
   1.366 +L5:
   1.367 +		sub         eax,dword ptr [esp+8]
   1.368 +		sbb         edx,dword ptr [esp+0Ch]
   1.369 +		neg         edx
   1.370 +		neg         eax
   1.371 +		sbb         edx,0
   1.372 +L2:
   1.373 +		pop         ebx
   1.374 +		ret         10h
   1.375 +	}
   1.376  }
   1.377 -void _alldvrm()
   1.378 +void __declspec(naked) _alldvrm()
   1.379  {
   1.380 +	__asm {
   1.381 +		push        edi
   1.382 +		push        esi
   1.383 +		push        ebp
   1.384 +		xor         edi,edi
   1.385 +		xor         ebp,ebp
   1.386 +		mov         eax,dword ptr [esp+14h]
   1.387 +		or          eax,eax
   1.388 +		jge         L1
   1.389 +		inc         edi
   1.390 +		inc         ebp
   1.391 +		mov         edx,dword ptr [esp+10h]
   1.392 +		neg         eax
   1.393 +		neg         edx
   1.394 +		sbb         eax,0
   1.395 +		mov         dword ptr [esp+14h],eax
   1.396 +		mov         dword ptr [esp+10h],edx
   1.397 +L1:
   1.398 +		mov         eax,dword ptr [esp+1Ch]
   1.399 +		or          eax,eax
   1.400 +		jge         L2
   1.401 +		inc         edi
   1.402 +		mov         edx,dword ptr [esp+18h]
   1.403 +		neg         eax
   1.404 +		neg         edx
   1.405 +		sbb         eax,0
   1.406 +		mov         dword ptr [esp+1Ch],eax
   1.407 +		mov         dword ptr [esp+18h],edx
   1.408 +L2:
   1.409 +		or          eax,eax
   1.410 +		jne         L3
   1.411 +		mov         ecx,dword ptr [esp+18h]
   1.412 +		mov         eax,dword ptr [esp+14h]
   1.413 +		xor         edx,edx
   1.414 +		div         ecx
   1.415 +		mov         ebx,eax
   1.416 +		mov         eax,dword ptr [esp+10h]
   1.417 +		div         ecx
   1.418 +		mov         esi,eax
   1.419 +		mov         eax,ebx
   1.420 +		mul         dword ptr [esp+18h]
   1.421 +		mov         ecx,eax
   1.422 +		mov         eax,esi
   1.423 +		mul         dword ptr [esp+18h]
   1.424 +		add         edx,ecx
   1.425 +		jmp         L4
   1.426 +L3:
   1.427 +		mov         ebx,eax
   1.428 +		mov         ecx,dword ptr [esp+18h]
   1.429 +		mov         edx,dword ptr [esp+14h]
   1.430 +		mov         eax,dword ptr [esp+10h]
   1.431 +L5:
   1.432 +		shr         ebx,1
   1.433 +		rcr         ecx,1
   1.434 +		shr         edx,1
   1.435 +		rcr         eax,1
   1.436 +		or          ebx,ebx
   1.437 +		jne         L5
   1.438 +		div         ecx
   1.439 +		mov         esi,eax
   1.440 +		mul         dword ptr [esp+1Ch]
   1.441 +		mov         ecx,eax
   1.442 +		mov         eax,dword ptr [esp+18h]
   1.443 +		mul         esi
   1.444 +		add         edx,ecx
   1.445 +		jb          L6
   1.446 +		cmp         edx,dword ptr [esp+14h]
   1.447 +		ja          L6
   1.448 +		jb          L7
   1.449 +		cmp         eax,dword ptr [esp+10h]
   1.450 +		jbe         L7
   1.451 +L6:
   1.452 +		dec         esi
   1.453 +		sub         eax,dword ptr [esp+18h]
   1.454 +		sbb         edx,dword ptr [esp+1Ch]
   1.455 +L7:
   1.456 +		xor         ebx,ebx
   1.457 +L4:
   1.458 +		sub         eax,dword ptr [esp+10h]
   1.459 +		sbb         edx,dword ptr [esp+14h]
   1.460 +		dec         ebp
   1.461 +		jns         L9
   1.462 +		neg         edx
   1.463 +		neg         eax
   1.464 +		sbb         edx,0
   1.465 +L9:
   1.466 +		mov         ecx,edx
   1.467 +		mov         edx,ebx
   1.468 +		mov         ebx,ecx
   1.469 +		mov         ecx,eax
   1.470 +		mov         eax,esi
   1.471 +		dec         edi
   1.472 +		jne         L8
   1.473 +		neg         edx
   1.474 +		neg         eax
   1.475 +		sbb         edx,0
   1.476 +L8:
   1.477 +		pop         ebp
   1.478 +		pop         esi
   1.479 +		pop         edi
   1.480 +		ret         10h
   1.481 +	}
   1.482  }
   1.483 -void _aulldvrm()
   1.484 +void __declspec(naked) _aulldvrm()
   1.485  {
   1.486 +	__asm {
   1.487 +		push        esi
   1.488 +		mov         eax,dword ptr [esp+14h]
   1.489 +		or          eax,eax
   1.490 +		jne         L1
   1.491 +		mov         ecx,dword ptr [esp+10h]
   1.492 +		mov         eax,dword ptr [esp+0Ch]
   1.493 +		xor         edx,edx
   1.494 +		div         ecx
   1.495 +		mov         ebx,eax
   1.496 +		mov         eax,dword ptr [esp+8]
   1.497 +		div         ecx
   1.498 +		mov         esi,eax
   1.499 +		mov         eax,ebx
   1.500 +		mul         dword ptr [esp+10h]
   1.501 +		mov         ecx,eax
   1.502 +		mov         eax,esi
   1.503 +		mul         dword ptr [esp+10h]
   1.504 +		add         edx,ecx
   1.505 +		jmp         L2
   1.506 +L1:
   1.507 +		mov         ecx,eax
   1.508 +		mov         ebx,dword ptr [esp+10h]
   1.509 +		mov         edx,dword ptr [esp+0Ch]
   1.510 +		mov         eax,dword ptr [esp+8]
   1.511 +L3:
   1.512 +		shr         ecx,1
   1.513 +		rcr         ebx,1
   1.514 +		shr         edx,1
   1.515 +		rcr         eax,1
   1.516 +		or          ecx,ecx
   1.517 +		jne         L3
   1.518 +		div         ebx
   1.519 +		mov         esi,eax
   1.520 +		mul         dword ptr [esp+14h]
   1.521 +		mov         ecx,eax
   1.522 +		mov         eax,dword ptr [esp+10h]
   1.523 +		mul         esi
   1.524 +		add         edx,ecx
   1.525 +		jb          L4
   1.526 +		cmp         edx,dword ptr [esp+0Ch]
   1.527 +		ja          L4
   1.528 +		jb          L5
   1.529 +		cmp         eax,dword ptr [esp+8]
   1.530 +		jbe         L5
   1.531 +L4:
   1.532 +		dec         esi
   1.533 +		sub         eax,dword ptr [esp+10h]
   1.534 +		sbb         edx,dword ptr [esp+14h]
   1.535 +L5:
   1.536 +		xor         ebx,ebx
   1.537 +L2:
   1.538 +		sub         eax,dword ptr [esp+8]
   1.539 +		sbb         edx,dword ptr [esp+0Ch]
   1.540 +		neg         edx
   1.541 +		neg         eax
   1.542 +		sbb         edx,0
   1.543 +		mov         ecx,edx
   1.544 +		mov         edx,ebx
   1.545 +		mov         ebx,ecx
   1.546 +		mov         ecx,eax
   1.547 +		mov         eax,esi
   1.548 +		pop         esi
   1.549 +		ret         10h
   1.550 +	}
   1.551  }
   1.552 -void _allshl()
   1.553 +void __declspec(naked) _allshl()
   1.554  {
   1.555 +	__asm {
   1.556 +		cmp         cl,40h
   1.557 +		jae         RETZERO
   1.558 +		cmp         cl,20h
   1.559 +		jae         MORE32
   1.560 +		shld        edx,eax,cl
   1.561 +		shl         eax,cl
   1.562 +		ret
   1.563 +MORE32:
   1.564 +		mov         edx,eax
   1.565 +		xor         eax,eax
   1.566 +		and         cl,1Fh
   1.567 +		shl         edx,cl
   1.568 +		ret
   1.569 +RETZERO:
   1.570 +		xor         eax,eax
   1.571 +		xor         edx,edx
   1.572 +		ret
   1.573 +	}
   1.574  }
   1.575 -void _aullshr()
   1.576 +void __declspec(naked) _aullshr()
   1.577  {
   1.578 +	__asm {
   1.579 +		cmp         cl,40h
   1.580 +		jae         RETZERO
   1.581 +		cmp         cl,20h
   1.582 +		jae         MORE32
   1.583 +		shrd        eax,edx,cl
   1.584 +		shr         edx,cl
   1.585 +		ret
   1.586 +MORE32:
   1.587 +		mov         eax,edx
   1.588 +		xor         edx,edx
   1.589 +		and         cl,1Fh
   1.590 +		shr         eax,cl
   1.591 +		ret
   1.592 +RETZERO:
   1.593 +		xor         eax,eax
   1.594 +		xor         edx,edx
   1.595 +		ret
   1.596 +	}
   1.597  }
   1.598  
   1.599  #endif /* MSC_VER */