SDL_stdlib.c 22 KB

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