SDL_stdlib.c 22 KB

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