SDL_stdlib.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_config.h"
  19. /* This file contains portable stdlib functions for SDL */
  20. #include "SDL_stdinc.h"
  21. #include "../libm/math_libm.h"
  22. double
  23. SDL_atan(double x)
  24. {
  25. #ifdef HAVE_ATAN
  26. return atan(x);
  27. #else
  28. return SDL_uclibc_atan(x);
  29. #endif /* HAVE_ATAN */
  30. }
  31. double
  32. SDL_atan2(double x, double y)
  33. {
  34. #if defined(HAVE_ATAN2)
  35. return atan2(x, y);
  36. #else
  37. return SDL_uclibc_atan2(x, y);
  38. #endif /* HAVE_ATAN2 */
  39. }
  40. double
  41. SDL_ceil(double x)
  42. {
  43. #ifdef HAVE_CEIL
  44. return ceil(x);
  45. #else
  46. return (double)(int)((x)+0.5);
  47. #endif /* HAVE_CEIL */
  48. }
  49. double
  50. SDL_copysign(double x, double y)
  51. {
  52. #if defined(HAVE_COPYSIGN)
  53. return copysign(x, y);
  54. #elif defined(HAVE__COPYSIGN)
  55. return _copysign(x, y);
  56. #else
  57. return SDL_uclibc_copysign(x, y);
  58. #endif /* HAVE_COPYSIGN */
  59. }
  60. double
  61. SDL_cos(double x)
  62. {
  63. #if defined(HAVE_COS)
  64. return cos(x);
  65. #else
  66. return SDL_uclibc_cos(x);
  67. #endif /* HAVE_COS */
  68. }
  69. float
  70. SDL_cosf(float x)
  71. {
  72. #ifdef HAVE_COSF
  73. return cosf(x);
  74. #else
  75. return (float)SDL_cos((double)x);
  76. #endif
  77. }
  78. double
  79. SDL_fabs(double x)
  80. {
  81. #if defined(HAVE_FABS)
  82. return fabs(x);
  83. #else
  84. return SDL_uclibc_fabs(x);
  85. #endif /* HAVE_FABS */
  86. }
  87. double
  88. SDL_floor(double x)
  89. {
  90. #if defined(HAVE_FLOOR)
  91. return floor(x);
  92. #else
  93. return SDL_uclibc_floor(x);
  94. #endif /* HAVE_FLOOR */
  95. }
  96. double
  97. SDL_log(double x)
  98. {
  99. #if defined(HAVE_LOG)
  100. return log(x);
  101. #else
  102. return SDL_uclibc_log(x);
  103. #endif /* HAVE_LOG */
  104. }
  105. double
  106. SDL_pow(double x, double y)
  107. {
  108. #if defined(HAVE_POW)
  109. return pow(x, y);
  110. #else
  111. return SDL_uclibc_pow(x, y);
  112. #endif /* HAVE_POW */
  113. }
  114. double
  115. SDL_scalbn(double x, int n)
  116. {
  117. #if defined(HAVE_SCALBN)
  118. return scalbn(x, n);
  119. #elif defined(HAVE__SCALB)
  120. return _scalb(x, n);
  121. #else
  122. return SDL_uclibc_scalbn(x, n);
  123. #endif /* HAVE_SCALBN */
  124. }
  125. double
  126. SDL_sin(double x)
  127. {
  128. #if defined(HAVE_SIN)
  129. return sin(x);
  130. #else
  131. return SDL_uclibc_sin(x);
  132. #endif /* HAVE_SIN */
  133. }
  134. float
  135. SDL_sinf(float x)
  136. {
  137. #ifdef HAVE_SINF
  138. return sinf(x);
  139. #else
  140. return (float)SDL_sin((double)x);
  141. #endif /* HAVE_SINF */
  142. }
  143. double
  144. SDL_sqrt(double x)
  145. {
  146. #if defined(HAVE_SQRT)
  147. return sqrt(x);
  148. #else
  149. return SDL_uclibc_sqrt(x);
  150. #endif
  151. }
  152. int SDL_abs(int x)
  153. {
  154. #ifdef HAVE_ABS
  155. return abs(x);
  156. #else
  157. return ((x) < 0 ? -(x) : (x));
  158. #endif
  159. }
  160. #ifdef HAVE_CTYPE_H
  161. int SDL_isdigit(int x) { return isdigit(x); }
  162. int SDL_isspace(int x) { return isspace(x); }
  163. int SDL_toupper(int x) { return toupper(x); }
  164. int SDL_tolower(int x) { return tolower(x); }
  165. #else
  166. int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
  167. int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
  168. int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
  169. int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
  170. #endif
  171. #ifndef HAVE_LIBC
  172. /* These are some C runtime intrinsics that need to be defined */
  173. #if defined(_MSC_VER)
  174. #ifndef __FLTUSED__
  175. #define __FLTUSED__
  176. __declspec(selectany) int _fltused = 1;
  177. #endif
  178. /* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */
  179. #if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG)
  180. #include <intrin.h>
  181. #pragma function(memcpy)
  182. void * memcpy ( void * destination, const void * source, size_t num )
  183. {
  184. const Uint8 *src = (const Uint8 *)source;
  185. Uint8 *dst = (Uint8 *)destination;
  186. size_t i;
  187. /* All WIN64 architectures have SSE, right? */
  188. if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
  189. __m128 values[4];
  190. for (i = num / 64; i--;) {
  191. _mm_prefetch(src, _MM_HINT_NTA);
  192. values[0] = *(__m128 *) (src + 0);
  193. values[1] = *(__m128 *) (src + 16);
  194. values[2] = *(__m128 *) (src + 32);
  195. values[3] = *(__m128 *) (src + 48);
  196. _mm_stream_ps((float *) (dst + 0), values[0]);
  197. _mm_stream_ps((float *) (dst + 16), values[1]);
  198. _mm_stream_ps((float *) (dst + 32), values[2]);
  199. _mm_stream_ps((float *) (dst + 48), values[3]);
  200. src += 64;
  201. dst += 64;
  202. }
  203. num &= 63;
  204. }
  205. while (num--) {
  206. *dst++ = *src++;
  207. }
  208. return destination;
  209. }
  210. #endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
  211. #ifdef _M_IX86
  212. void
  213. __declspec(naked)
  214. _chkstk()
  215. {
  216. }
  217. /* Float to long */
  218. void
  219. __declspec(naked)
  220. _ftol()
  221. {
  222. /* *INDENT-OFF* */
  223. __asm {
  224. push ebp
  225. mov ebp,esp
  226. sub esp,20h
  227. and esp,0FFFFFFF0h
  228. fld st(0)
  229. fst dword ptr [esp+18h]
  230. fistp qword ptr [esp+10h]
  231. fild qword ptr [esp+10h]
  232. mov edx,dword ptr [esp+18h]
  233. mov eax,dword ptr [esp+10h]
  234. test eax,eax
  235. je integer_QnaN_or_zero
  236. arg_is_not_integer_QnaN:
  237. fsubp st(1),st
  238. test edx,edx
  239. jns positive
  240. fstp dword ptr [esp]
  241. mov ecx,dword ptr [esp]
  242. xor ecx,80000000h
  243. add ecx,7FFFFFFFh
  244. adc eax,0
  245. mov edx,dword ptr [esp+14h]
  246. adc edx,0
  247. jmp localexit
  248. positive:
  249. fstp dword ptr [esp]
  250. mov ecx,dword ptr [esp]
  251. add ecx,7FFFFFFFh
  252. sbb eax,0
  253. mov edx,dword ptr [esp+14h]
  254. sbb edx,0
  255. jmp localexit
  256. integer_QnaN_or_zero:
  257. mov edx,dword ptr [esp+14h]
  258. test edx,7FFFFFFFh
  259. jne arg_is_not_integer_QnaN
  260. fstp dword ptr [esp+18h]
  261. fstp dword ptr [esp+18h]
  262. localexit:
  263. leave
  264. ret
  265. }
  266. /* *INDENT-ON* */
  267. }
  268. void
  269. _ftol2_sse()
  270. {
  271. _ftol();
  272. }
  273. /* 64-bit math operators for 32-bit systems */
  274. void
  275. __declspec(naked)
  276. _allmul()
  277. {
  278. /* *INDENT-OFF* */
  279. __asm {
  280. push ebp
  281. mov ebp,esp
  282. push edi
  283. push esi
  284. push ebx
  285. sub esp,0Ch
  286. mov eax,dword ptr [ebp+10h]
  287. mov edi,dword ptr [ebp+8]
  288. mov ebx,eax
  289. mov esi,eax
  290. sar esi,1Fh
  291. mov eax,dword ptr [ebp+8]
  292. mul ebx
  293. imul edi,esi
  294. mov ecx,edx
  295. mov dword ptr [ebp-18h],eax
  296. mov edx,dword ptr [ebp+0Ch]
  297. add ecx,edi
  298. imul ebx,edx
  299. mov eax,dword ptr [ebp-18h]
  300. lea ebx,[ebx+ecx]
  301. mov dword ptr [ebp-14h],ebx
  302. mov edx,dword ptr [ebp-14h]
  303. add esp,0Ch
  304. pop ebx
  305. pop esi
  306. pop edi
  307. pop ebp
  308. ret 10h
  309. }
  310. /* *INDENT-ON* */
  311. }
  312. void
  313. __declspec(naked)
  314. _alldiv()
  315. {
  316. /* *INDENT-OFF* */
  317. __asm {
  318. push edi
  319. push esi
  320. push ebx
  321. xor edi,edi
  322. mov eax,dword ptr [esp+14h]
  323. or eax,eax
  324. jge L1
  325. inc edi
  326. mov edx,dword ptr [esp+10h]
  327. neg eax
  328. neg edx
  329. sbb eax,0
  330. mov dword ptr [esp+14h],eax
  331. mov dword ptr [esp+10h],edx
  332. L1:
  333. mov eax,dword ptr [esp+1Ch]
  334. or eax,eax
  335. jge L2
  336. inc edi
  337. mov edx,dword ptr [esp+18h]
  338. neg eax
  339. neg edx
  340. sbb eax,0
  341. mov dword ptr [esp+1Ch],eax
  342. mov dword ptr [esp+18h],edx
  343. L2:
  344. or eax,eax
  345. jne L3
  346. mov ecx,dword ptr [esp+18h]
  347. mov eax,dword ptr [esp+14h]
  348. xor edx,edx
  349. div ecx
  350. mov ebx,eax
  351. mov eax,dword ptr [esp+10h]
  352. div ecx
  353. mov edx,ebx
  354. jmp L4
  355. L3:
  356. mov ebx,eax
  357. mov ecx,dword ptr [esp+18h]
  358. mov edx,dword ptr [esp+14h]
  359. mov eax,dword ptr [esp+10h]
  360. L5:
  361. shr ebx,1
  362. rcr ecx,1
  363. shr edx,1
  364. rcr eax,1
  365. or ebx,ebx
  366. jne L5
  367. div ecx
  368. mov esi,eax
  369. mul dword ptr [esp+1Ch]
  370. mov ecx,eax
  371. mov eax,dword ptr [esp+18h]
  372. mul esi
  373. add edx,ecx
  374. jb L6
  375. cmp edx,dword ptr [esp+14h]
  376. ja L6
  377. jb L7
  378. cmp eax,dword ptr [esp+10h]
  379. jbe L7
  380. L6:
  381. dec esi
  382. L7:
  383. xor edx,edx
  384. mov eax,esi
  385. L4:
  386. dec edi
  387. jne L8
  388. neg edx
  389. neg eax
  390. sbb edx,0
  391. L8:
  392. pop ebx
  393. pop esi
  394. pop edi
  395. ret 10h
  396. }
  397. /* *INDENT-ON* */
  398. }
  399. void
  400. __declspec(naked)
  401. _aulldiv()
  402. {
  403. /* *INDENT-OFF* */
  404. __asm {
  405. push ebx
  406. push esi
  407. mov eax,dword ptr [esp+18h]
  408. or eax,eax
  409. jne L1
  410. mov ecx,dword ptr [esp+14h]
  411. mov eax,dword ptr [esp+10h]
  412. xor edx,edx
  413. div ecx
  414. mov ebx,eax
  415. mov eax,dword ptr [esp+0Ch]
  416. div ecx
  417. mov edx,ebx
  418. jmp L2
  419. L1:
  420. mov ecx,eax
  421. mov ebx,dword ptr [esp+14h]
  422. mov edx,dword ptr [esp+10h]
  423. mov eax,dword ptr [esp+0Ch]
  424. L3:
  425. shr ecx,1
  426. rcr ebx,1
  427. shr edx,1
  428. rcr eax,1
  429. or ecx,ecx
  430. jne L3
  431. div ebx
  432. mov esi,eax
  433. mul dword ptr [esp+18h]
  434. mov ecx,eax
  435. mov eax,dword ptr [esp+14h]
  436. mul esi
  437. add edx,ecx
  438. jb L4
  439. cmp edx,dword ptr [esp+10h]
  440. ja L4
  441. jb L5
  442. cmp eax,dword ptr [esp+0Ch]
  443. jbe L5
  444. L4:
  445. dec esi
  446. L5:
  447. xor edx,edx
  448. mov eax,esi
  449. L2:
  450. pop esi
  451. pop ebx
  452. ret 10h
  453. }
  454. /* *INDENT-ON* */
  455. }
  456. void
  457. __declspec(naked)
  458. _allrem()
  459. {
  460. /* *INDENT-OFF* */
  461. __asm {
  462. push ebx
  463. push edi
  464. xor edi,edi
  465. mov eax,dword ptr [esp+10h]
  466. or eax,eax
  467. jge L1
  468. inc edi
  469. mov edx,dword ptr [esp+0Ch]
  470. neg eax
  471. neg edx
  472. sbb eax,0
  473. mov dword ptr [esp+10h],eax
  474. mov dword ptr [esp+0Ch],edx
  475. L1:
  476. mov eax,dword ptr [esp+18h]
  477. or eax,eax
  478. jge L2
  479. mov edx,dword ptr [esp+14h]
  480. neg eax
  481. neg edx
  482. sbb eax,0
  483. mov dword ptr [esp+18h],eax
  484. mov dword ptr [esp+14h],edx
  485. L2:
  486. or eax,eax
  487. jne L3
  488. mov ecx,dword ptr [esp+14h]
  489. mov eax,dword ptr [esp+10h]
  490. xor edx,edx
  491. div ecx
  492. mov eax,dword ptr [esp+0Ch]
  493. div ecx
  494. mov eax,edx
  495. xor edx,edx
  496. dec edi
  497. jns L4
  498. jmp L8
  499. L3:
  500. mov ebx,eax
  501. mov ecx,dword ptr [esp+14h]
  502. mov edx,dword ptr [esp+10h]
  503. mov eax,dword ptr [esp+0Ch]
  504. L5:
  505. shr ebx,1
  506. rcr ecx,1
  507. shr edx,1
  508. rcr eax,1
  509. or ebx,ebx
  510. jne L5
  511. div ecx
  512. mov ecx,eax
  513. mul dword ptr [esp+18h]
  514. xchg eax,ecx
  515. mul dword ptr [esp+14h]
  516. add edx,ecx
  517. jb L6
  518. cmp edx,dword ptr [esp+10h]
  519. ja L6
  520. jb L7
  521. cmp eax,dword ptr [esp+0Ch]
  522. jbe L7
  523. L6:
  524. sub eax,dword ptr [esp+14h]
  525. sbb edx,dword ptr [esp+18h]
  526. L7:
  527. sub eax,dword ptr [esp+0Ch]
  528. sbb edx,dword ptr [esp+10h]
  529. dec edi
  530. jns L8
  531. L4:
  532. neg edx
  533. neg eax
  534. sbb edx,0
  535. L8:
  536. pop edi
  537. pop ebx
  538. ret 10h
  539. }
  540. /* *INDENT-ON* */
  541. }
  542. void
  543. __declspec(naked)
  544. _aullrem()
  545. {
  546. /* *INDENT-OFF* */
  547. __asm {
  548. push ebx
  549. mov eax,dword ptr [esp+14h]
  550. or eax,eax
  551. jne L1
  552. mov ecx,dword ptr [esp+10h]
  553. mov eax,dword ptr [esp+0Ch]
  554. xor edx,edx
  555. div ecx
  556. mov eax,dword ptr [esp+8]
  557. div ecx
  558. mov eax,edx
  559. xor edx,edx
  560. jmp L2
  561. L1:
  562. mov ecx,eax
  563. mov ebx,dword ptr [esp+10h]
  564. mov edx,dword ptr [esp+0Ch]
  565. mov eax,dword ptr [esp+8]
  566. L3:
  567. shr ecx,1
  568. rcr ebx,1
  569. shr edx,1
  570. rcr eax,1
  571. or ecx,ecx
  572. jne L3
  573. div ebx
  574. mov ecx,eax
  575. mul dword ptr [esp+14h]
  576. xchg eax,ecx
  577. mul dword ptr [esp+10h]
  578. add edx,ecx
  579. jb L4
  580. cmp edx,dword ptr [esp+0Ch]
  581. ja L4
  582. jb L5
  583. cmp eax,dword ptr [esp+8]
  584. jbe L5
  585. L4:
  586. sub eax,dword ptr [esp+10h]
  587. sbb edx,dword ptr [esp+14h]
  588. L5:
  589. sub eax,dword ptr [esp+8]
  590. sbb edx,dword ptr [esp+0Ch]
  591. neg edx
  592. neg eax
  593. sbb edx,0
  594. L2:
  595. pop ebx
  596. ret 10h
  597. }
  598. /* *INDENT-ON* */
  599. }
  600. void
  601. __declspec(naked)
  602. _alldvrm()
  603. {
  604. /* *INDENT-OFF* */
  605. __asm {
  606. push edi
  607. push esi
  608. push ebp
  609. xor edi,edi
  610. xor ebp,ebp
  611. mov eax,dword ptr [esp+14h]
  612. or eax,eax
  613. jge L1
  614. inc edi
  615. inc ebp
  616. mov edx,dword ptr [esp+10h]
  617. neg eax
  618. neg edx
  619. sbb eax,0
  620. mov dword ptr [esp+14h],eax
  621. mov dword ptr [esp+10h],edx
  622. L1:
  623. mov eax,dword ptr [esp+1Ch]
  624. or eax,eax
  625. jge L2
  626. inc edi
  627. mov edx,dword ptr [esp+18h]
  628. neg eax
  629. neg edx
  630. sbb eax,0
  631. mov dword ptr [esp+1Ch],eax
  632. mov dword ptr [esp+18h],edx
  633. L2:
  634. or eax,eax
  635. jne L3
  636. mov ecx,dword ptr [esp+18h]
  637. mov eax,dword ptr [esp+14h]
  638. xor edx,edx
  639. div ecx
  640. mov ebx,eax
  641. mov eax,dword ptr [esp+10h]
  642. div ecx
  643. mov esi,eax
  644. mov eax,ebx
  645. mul dword ptr [esp+18h]
  646. mov ecx,eax
  647. mov eax,esi
  648. mul dword ptr [esp+18h]
  649. add edx,ecx
  650. jmp L4
  651. L3:
  652. mov ebx,eax
  653. mov ecx,dword ptr [esp+18h]
  654. mov edx,dword ptr [esp+14h]
  655. mov eax,dword ptr [esp+10h]
  656. L5:
  657. shr ebx,1
  658. rcr ecx,1
  659. shr edx,1
  660. rcr eax,1
  661. or ebx,ebx
  662. jne L5
  663. div ecx
  664. mov esi,eax
  665. mul dword ptr [esp+1Ch]
  666. mov ecx,eax
  667. mov eax,dword ptr [esp+18h]
  668. mul esi
  669. add edx,ecx
  670. jb L6
  671. cmp edx,dword ptr [esp+14h]
  672. ja L6
  673. jb L7
  674. cmp eax,dword ptr [esp+10h]
  675. jbe L7
  676. L6:
  677. dec esi
  678. sub eax,dword ptr [esp+18h]
  679. sbb edx,dword ptr [esp+1Ch]
  680. L7:
  681. xor ebx,ebx
  682. L4:
  683. sub eax,dword ptr [esp+10h]
  684. sbb edx,dword ptr [esp+14h]
  685. dec ebp
  686. jns L9
  687. neg edx
  688. neg eax
  689. sbb edx,0
  690. L9:
  691. mov ecx,edx
  692. mov edx,ebx
  693. mov ebx,ecx
  694. mov ecx,eax
  695. mov eax,esi
  696. dec edi
  697. jne L8
  698. neg edx
  699. neg eax
  700. sbb edx,0
  701. L8:
  702. pop ebp
  703. pop esi
  704. pop edi
  705. ret 10h
  706. }
  707. /* *INDENT-ON* */
  708. }
  709. void
  710. __declspec(naked)
  711. _aulldvrm()
  712. {
  713. /* *INDENT-OFF* */
  714. __asm {
  715. push esi
  716. mov eax,dword ptr [esp+14h]
  717. or eax,eax
  718. jne L1
  719. mov ecx,dword ptr [esp+10h]
  720. mov eax,dword ptr [esp+0Ch]
  721. xor edx,edx
  722. div ecx
  723. mov ebx,eax
  724. mov eax,dword ptr [esp+8]
  725. div ecx
  726. mov esi,eax
  727. mov eax,ebx
  728. mul dword ptr [esp+10h]
  729. mov ecx,eax
  730. mov eax,esi
  731. mul dword ptr [esp+10h]
  732. add edx,ecx
  733. jmp L2
  734. L1:
  735. mov ecx,eax
  736. mov ebx,dword ptr [esp+10h]
  737. mov edx,dword ptr [esp+0Ch]
  738. mov eax,dword ptr [esp+8]
  739. L3:
  740. shr ecx,1
  741. rcr ebx,1
  742. shr edx,1
  743. rcr eax,1
  744. or ecx,ecx
  745. jne L3
  746. div ebx
  747. mov esi,eax
  748. mul dword ptr [esp+14h]
  749. mov ecx,eax
  750. mov eax,dword ptr [esp+10h]
  751. mul esi
  752. add edx,ecx
  753. jb L4
  754. cmp edx,dword ptr [esp+0Ch]
  755. ja L4
  756. jb L5
  757. cmp eax,dword ptr [esp+8]
  758. jbe L5
  759. L4:
  760. dec esi
  761. sub eax,dword ptr [esp+10h]
  762. sbb edx,dword ptr [esp+14h]
  763. L5:
  764. xor ebx,ebx
  765. L2:
  766. sub eax,dword ptr [esp+8]
  767. sbb edx,dword ptr [esp+0Ch]
  768. neg edx
  769. neg eax
  770. sbb edx,0
  771. mov ecx,edx
  772. mov edx,ebx
  773. mov ebx,ecx
  774. mov ecx,eax
  775. mov eax,esi
  776. pop esi
  777. ret 10h
  778. }
  779. /* *INDENT-ON* */
  780. }
  781. void
  782. __declspec(naked)
  783. _allshl()
  784. {
  785. /* *INDENT-OFF* */
  786. __asm {
  787. cmp cl,40h
  788. jae RETZERO
  789. cmp cl,20h
  790. jae MORE32
  791. shld edx,eax,cl
  792. shl eax,cl
  793. ret
  794. MORE32:
  795. mov edx,eax
  796. xor eax,eax
  797. and cl,1Fh
  798. shl edx,cl
  799. ret
  800. RETZERO:
  801. xor eax,eax
  802. xor edx,edx
  803. ret
  804. }
  805. /* *INDENT-ON* */
  806. }
  807. void
  808. __declspec(naked)
  809. _allshr()
  810. {
  811. /* *INDENT-OFF* */
  812. __asm {
  813. cmp cl,40h
  814. jae RETZERO
  815. cmp cl,20h
  816. jae MORE32
  817. shrd eax,edx,cl
  818. sar edx,cl
  819. ret
  820. MORE32:
  821. mov eax,edx
  822. xor edx,edx
  823. and cl,1Fh
  824. sar eax,cl
  825. ret
  826. RETZERO:
  827. xor eax,eax
  828. xor edx,edx
  829. ret
  830. }
  831. /* *INDENT-ON* */
  832. }
  833. void
  834. __declspec(naked)
  835. _aullshr()
  836. {
  837. /* *INDENT-OFF* */
  838. __asm {
  839. cmp cl,40h
  840. jae RETZERO
  841. cmp cl,20h
  842. jae MORE32
  843. shrd eax,edx,cl
  844. shr edx,cl
  845. ret
  846. MORE32:
  847. mov eax,edx
  848. xor edx,edx
  849. and cl,1Fh
  850. shr eax,cl
  851. ret
  852. RETZERO:
  853. xor eax,eax
  854. xor edx,edx
  855. ret
  856. }
  857. /* *INDENT-ON* */
  858. }
  859. #endif /* _M_IX86 */
  860. #endif /* MSC_VER */
  861. #endif /* !HAVE_LIBC */
  862. /* vi: set ts=4 sw=4 expandtab: */