SDL_stdlib.c 22 KB

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