SDL_stdlib.c 22 KB

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