SDL_stdlib.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 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. #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
  33. }
  34. float
  35. SDL_atanf(float x)
  36. {
  37. #if defined(HAVE_ATANF)
  38. return atanf(x);
  39. #else
  40. return (float)SDL_atan((double)x);
  41. #endif
  42. }
  43. double
  44. SDL_atan2(double x, double y)
  45. {
  46. #if defined(HAVE_ATAN2)
  47. return atan2(x, y);
  48. #else
  49. return SDL_uclibc_atan2(x, y);
  50. #endif
  51. }
  52. float
  53. SDL_atan2f(float x, float y)
  54. {
  55. #if defined(HAVE_ATAN2F)
  56. return atan2f(x, y);
  57. #else
  58. return (float)SDL_atan2((double)x, (double)y);
  59. #endif
  60. }
  61. double
  62. SDL_acos(double val)
  63. {
  64. #if defined(HAVE_ACOS)
  65. return acos(val);
  66. #else
  67. double result;
  68. if (val == -1.0) {
  69. result = M_PI;
  70. } else {
  71. result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
  72. if (result < 0.0)
  73. {
  74. result += M_PI;
  75. }
  76. }
  77. return result;
  78. #endif
  79. }
  80. float
  81. SDL_acosf(float val)
  82. {
  83. #if defined(HAVE_ACOSF)
  84. return acosf(val);
  85. #else
  86. return (float)SDL_acos((double)val);
  87. #endif
  88. }
  89. double
  90. SDL_asin(double val)
  91. {
  92. #if defined(HAVE_ASIN)
  93. return asin(val);
  94. #else
  95. double result;
  96. if (val == -1.0) {
  97. result = -(M_PI / 2.0);
  98. } else {
  99. result = (M_PI / 2.0) - SDL_acos(val);
  100. }
  101. return result;
  102. #endif
  103. }
  104. float
  105. SDL_asinf(float val)
  106. {
  107. #if defined(HAVE_ASINF)
  108. return asinf(val);
  109. #else
  110. return (float)SDL_asin((double)val);
  111. #endif
  112. }
  113. double
  114. SDL_ceil(double x)
  115. {
  116. #if defined(HAVE_CEIL)
  117. return ceil(x);
  118. #else
  119. double integer = SDL_floor(x);
  120. double fraction = x - integer;
  121. if (fraction > 0.0) {
  122. integer += 1.0;
  123. }
  124. return integer;
  125. #endif /* HAVE_CEIL */
  126. }
  127. float
  128. SDL_ceilf(float x)
  129. {
  130. #if defined(HAVE_CEILF)
  131. return ceilf(x);
  132. #else
  133. return (float)SDL_ceil((float)x);
  134. #endif
  135. }
  136. double
  137. SDL_copysign(double x, double y)
  138. {
  139. #if defined(HAVE_COPYSIGN)
  140. return copysign(x, y);
  141. #elif defined(HAVE__COPYSIGN)
  142. return _copysign(x, y);
  143. #elif defined(__WATCOMC__) && defined(__386__)
  144. /* this is nasty as hell, but it works.. */
  145. unsigned int *xi = (unsigned int *) &x,
  146. *yi = (unsigned int *) &y;
  147. xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
  148. return x;
  149. #else
  150. return SDL_uclibc_copysign(x, y);
  151. #endif /* HAVE_COPYSIGN */
  152. }
  153. float
  154. SDL_copysignf(float x, float y)
  155. {
  156. #if defined(HAVE_COPYSIGNF)
  157. return copysignf(x, y);
  158. #else
  159. return (float)SDL_copysign((double)x, (double)y);
  160. #endif
  161. }
  162. double
  163. SDL_cos(double x)
  164. {
  165. #if defined(HAVE_COS)
  166. return cos(x);
  167. #else
  168. return SDL_uclibc_cos(x);
  169. #endif
  170. }
  171. float
  172. SDL_cosf(float x)
  173. {
  174. #if defined(HAVE_COSF)
  175. return cosf(x);
  176. #else
  177. return (float)SDL_cos((double)x);
  178. #endif
  179. }
  180. double
  181. SDL_exp(double x)
  182. {
  183. #if defined(HAVE_EXP)
  184. return exp(x);
  185. #else
  186. return SDL_uclibc_exp(x);
  187. #endif
  188. }
  189. float
  190. SDL_expf(float x)
  191. {
  192. #if defined(HAVE_EXPF)
  193. return expf(x);
  194. #else
  195. return (float)SDL_exp((double)x);
  196. #endif
  197. }
  198. double
  199. SDL_fabs(double x)
  200. {
  201. #if defined(HAVE_FABS)
  202. return fabs(x);
  203. #else
  204. return SDL_uclibc_fabs(x);
  205. #endif
  206. }
  207. float
  208. SDL_fabsf(float x)
  209. {
  210. #if defined(HAVE_FABSF)
  211. return fabsf(x);
  212. #else
  213. return (float)SDL_fabs((double)x);
  214. #endif
  215. }
  216. double
  217. SDL_floor(double x)
  218. {
  219. #if defined(HAVE_FLOOR)
  220. return floor(x);
  221. #else
  222. return SDL_uclibc_floor(x);
  223. #endif
  224. }
  225. float
  226. SDL_floorf(float x)
  227. {
  228. #if defined(HAVE_FLOORF)
  229. return floorf(x);
  230. #else
  231. return (float)SDL_floor((double)x);
  232. #endif
  233. }
  234. double
  235. SDL_trunc(double x)
  236. {
  237. #if defined(HAVE_TRUNC)
  238. return trunc(x);
  239. #else
  240. if (x >= 0.0f) {
  241. return SDL_floor(x);
  242. } else {
  243. return SDL_ceil(x);
  244. }
  245. #endif
  246. }
  247. float
  248. SDL_truncf(float x)
  249. {
  250. #if defined(HAVE_TRUNCF)
  251. return truncf(x);
  252. #else
  253. return (float)SDL_trunc((double)x);
  254. #endif
  255. }
  256. double
  257. SDL_fmod(double x, double y)
  258. {
  259. #if defined(HAVE_FMOD)
  260. return fmod(x, y);
  261. #else
  262. return SDL_uclibc_fmod(x, y);
  263. #endif
  264. }
  265. float
  266. SDL_fmodf(float x, float y)
  267. {
  268. #if defined(HAVE_FMODF)
  269. return fmodf(x, y);
  270. #else
  271. return (float)SDL_fmod((double)x, (double)y);
  272. #endif
  273. }
  274. double
  275. SDL_log(double x)
  276. {
  277. #if defined(HAVE_LOG)
  278. return log(x);
  279. #else
  280. return SDL_uclibc_log(x);
  281. #endif
  282. }
  283. float
  284. SDL_logf(float x)
  285. {
  286. #if defined(HAVE_LOGF)
  287. return logf(x);
  288. #else
  289. return (float)SDL_log((double)x);
  290. #endif
  291. }
  292. double
  293. SDL_log10(double x)
  294. {
  295. #if defined(HAVE_LOG10)
  296. return log10(x);
  297. #else
  298. return SDL_uclibc_log10(x);
  299. #endif
  300. }
  301. float
  302. SDL_log10f(float x)
  303. {
  304. #if defined(HAVE_LOG10F)
  305. return log10f(x);
  306. #else
  307. return (float)SDL_log10((double)x);
  308. #endif
  309. }
  310. double
  311. SDL_pow(double x, double y)
  312. {
  313. #if defined(HAVE_POW)
  314. return pow(x, y);
  315. #else
  316. return SDL_uclibc_pow(x, y);
  317. #endif
  318. }
  319. float
  320. SDL_powf(float x, float y)
  321. {
  322. #if defined(HAVE_POWF)
  323. return powf(x, y);
  324. #else
  325. return (float)SDL_pow((double)x, (double)y);
  326. #endif
  327. }
  328. double
  329. SDL_round(double arg)
  330. {
  331. #if defined HAVE_ROUND
  332. return round(arg);
  333. #else
  334. if (arg >= 0.0) {
  335. return SDL_floor(arg + 0.5);
  336. } else {
  337. return SDL_ceil(arg - 0.5);
  338. }
  339. #endif
  340. }
  341. float
  342. SDL_roundf(float arg)
  343. {
  344. #if defined HAVE_ROUNDF
  345. return roundf(arg);
  346. #else
  347. return (float)SDL_round((double)arg);
  348. #endif
  349. }
  350. long
  351. SDL_lround(double arg)
  352. {
  353. #if defined HAVE_LROUND
  354. return lround(arg);
  355. #else
  356. return (long)SDL_round(arg);
  357. #endif
  358. }
  359. long
  360. SDL_lroundf(float arg)
  361. {
  362. #if defined HAVE_LROUNDF
  363. return lroundf(arg);
  364. #else
  365. return (long)SDL_round((double)arg);
  366. #endif
  367. }
  368. double
  369. SDL_scalbn(double x, int n)
  370. {
  371. #if defined(HAVE_SCALBN)
  372. return scalbn(x, n);
  373. #elif defined(HAVE__SCALB)
  374. return _scalb(x, n);
  375. #elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
  376. /* from scalbn(3): If FLT_RADIX equals 2 (which is
  377. * usual), then scalbn() is equivalent to ldexp(3). */
  378. return ldexp(x, n);
  379. #else
  380. return SDL_uclibc_scalbn(x, n);
  381. #endif
  382. }
  383. float
  384. SDL_scalbnf(float x, int n)
  385. {
  386. #if defined(HAVE_SCALBNF)
  387. return scalbnf(x, n);
  388. #else
  389. return (float)SDL_scalbn((double)x, n);
  390. #endif
  391. }
  392. double
  393. SDL_sin(double x)
  394. {
  395. #if defined(HAVE_SIN)
  396. return sin(x);
  397. #else
  398. return SDL_uclibc_sin(x);
  399. #endif
  400. }
  401. float
  402. SDL_sinf(float x)
  403. {
  404. #if defined(HAVE_SINF)
  405. return sinf(x);
  406. #else
  407. return (float)SDL_sin((double)x);
  408. #endif
  409. }
  410. double
  411. SDL_sqrt(double x)
  412. {
  413. #if defined(HAVE_SQRT)
  414. return sqrt(x);
  415. #else
  416. return SDL_uclibc_sqrt(x);
  417. #endif
  418. }
  419. float
  420. SDL_sqrtf(float x)
  421. {
  422. #if defined(HAVE_SQRTF)
  423. return sqrtf(x);
  424. #else
  425. return (float)SDL_sqrt((double)x);
  426. #endif
  427. }
  428. double
  429. SDL_tan(double x)
  430. {
  431. #if defined(HAVE_TAN)
  432. return tan(x);
  433. #else
  434. return SDL_uclibc_tan(x);
  435. #endif
  436. }
  437. float
  438. SDL_tanf(float x)
  439. {
  440. #if defined(HAVE_TANF)
  441. return tanf(x);
  442. #else
  443. return (float)SDL_tan((double)x);
  444. #endif
  445. }
  446. int SDL_abs(int x)
  447. {
  448. #if defined(HAVE_ABS)
  449. return abs(x);
  450. #else
  451. return ((x) < 0 ? -(x) : (x));
  452. #endif
  453. }
  454. #if defined(HAVE_CTYPE_H)
  455. int SDL_isalpha(int x) { return isalpha(x); }
  456. int SDL_isalnum(int x) { return isalnum(x); }
  457. int SDL_isdigit(int x) { return isdigit(x); }
  458. int SDL_isxdigit(int x) { return isxdigit(x); }
  459. int SDL_ispunct(int x) { return ispunct(x); }
  460. int SDL_isspace(int x) { return isspace(x); }
  461. int SDL_isupper(int x) { return isupper(x); }
  462. int SDL_islower(int x) { return islower(x); }
  463. int SDL_isprint(int x) { return isprint(x); }
  464. int SDL_isgraph(int x) { return isgraph(x); }
  465. int SDL_iscntrl(int x) { return iscntrl(x); }
  466. int SDL_toupper(int x) { return toupper(x); }
  467. int SDL_tolower(int x) { return tolower(x); }
  468. #else
  469. int SDL_isalpha(int x) { return (SDL_isupper(x)) || (SDL_islower(x)); }
  470. int SDL_isalnum(int x) { return (SDL_isalpha(x)) || (SDL_isdigit(x)); }
  471. int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
  472. int SDL_isxdigit(int x) { return (SDL_isalpha(x)) || (SDL_isdigit(x)); }
  473. int SDL_ispunct(int x) { return (SDL_isprint(x)) && (!SDL_isalnum(x)); }
  474. int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
  475. int SDL_isupper(int x) { return ((x) >= 'A') && ((x) <= 'Z'); }
  476. int SDL_islower(int x) { return ((x) >= 'a') && ((x) <= 'z'); }
  477. int SDL_isprint(int x) { return ((x) >= ' ') && ((x) < '\x7f'); }
  478. int SDL_isgraph(int x) { return (SDL_isprint(x)) && ((x) != ' '); }
  479. int SDL_iscntrl(int x) { return (((x) >= '\0') && ((x) <= '\x1f')) || ((x) == '\x7f'); }
  480. int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
  481. int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
  482. #endif
  483. #if defined(HAVE_CTYPE_H) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  484. int SDL_isblank(int x) { return isblank(x); }
  485. #else
  486. int SDL_isblank(int x) { return ((x) == ' ') || ((x) == '\t'); }
  487. #endif
  488. #ifndef HAVE_LIBC
  489. /* These are some C runtime intrinsics that need to be defined */
  490. #if defined(_MSC_VER)
  491. #ifndef __FLTUSED__
  492. #define __FLTUSED__
  493. __declspec(selectany) int _fltused = 1;
  494. #endif
  495. /* The optimizer on Visual Studio 2005 and later generates memcpy() and memset() calls */
  496. #if _MSC_VER >= 1400
  497. extern void *memcpy(void* dst, const void* src, size_t len);
  498. #pragma intrinsic(memcpy)
  499. #pragma function(memcpy)
  500. void *
  501. memcpy(void *dst, const void *src, size_t len)
  502. {
  503. return SDL_memcpy(dst, src, len);
  504. }
  505. extern void *memset(void* dst, int c, size_t len);
  506. #pragma intrinsic(memset)
  507. #pragma function(memset)
  508. void *
  509. memset(void *dst, int c, size_t len)
  510. {
  511. return SDL_memset(dst, c, len);
  512. }
  513. #endif /* _MSC_VER >= 1400 */
  514. #ifdef _M_IX86
  515. /* Float to long */
  516. void
  517. __declspec(naked)
  518. _ftol()
  519. {
  520. /* *INDENT-OFF* */
  521. __asm {
  522. push ebp
  523. mov ebp,esp
  524. sub esp,20h
  525. and esp,0FFFFFFF0h
  526. fld st(0)
  527. fst dword ptr [esp+18h]
  528. fistp qword ptr [esp+10h]
  529. fild qword ptr [esp+10h]
  530. mov edx,dword ptr [esp+18h]
  531. mov eax,dword ptr [esp+10h]
  532. test eax,eax
  533. je integer_QnaN_or_zero
  534. arg_is_not_integer_QnaN:
  535. fsubp st(1),st
  536. test edx,edx
  537. jns positive
  538. fstp dword ptr [esp]
  539. mov ecx,dword ptr [esp]
  540. xor ecx,80000000h
  541. add ecx,7FFFFFFFh
  542. adc eax,0
  543. mov edx,dword ptr [esp+14h]
  544. adc edx,0
  545. jmp localexit
  546. positive:
  547. fstp dword ptr [esp]
  548. mov ecx,dword ptr [esp]
  549. add ecx,7FFFFFFFh
  550. sbb eax,0
  551. mov edx,dword ptr [esp+14h]
  552. sbb edx,0
  553. jmp localexit
  554. integer_QnaN_or_zero:
  555. mov edx,dword ptr [esp+14h]
  556. test edx,7FFFFFFFh
  557. jne arg_is_not_integer_QnaN
  558. fstp dword ptr [esp+18h]
  559. fstp dword ptr [esp+18h]
  560. localexit:
  561. leave
  562. ret
  563. }
  564. /* *INDENT-ON* */
  565. }
  566. void
  567. _ftol2_sse()
  568. {
  569. _ftol();
  570. }
  571. /* 64-bit math operators for 32-bit systems */
  572. void
  573. __declspec(naked)
  574. _allmul()
  575. {
  576. /* *INDENT-OFF* */
  577. __asm {
  578. mov eax, dword ptr[esp+8]
  579. mov ecx, dword ptr[esp+10h]
  580. or ecx, eax
  581. mov ecx, dword ptr[esp+0Ch]
  582. jne hard
  583. mov eax, dword ptr[esp+4]
  584. mul ecx
  585. ret 10h
  586. hard:
  587. push ebx
  588. mul ecx
  589. mov ebx, eax
  590. mov eax, dword ptr[esp+8]
  591. mul dword ptr[esp+14h]
  592. add ebx, eax
  593. mov eax, dword ptr[esp+8]
  594. mul ecx
  595. add edx, ebx
  596. pop ebx
  597. ret 10h
  598. }
  599. /* *INDENT-ON* */
  600. }
  601. void
  602. __declspec(naked)
  603. _alldiv()
  604. {
  605. /* *INDENT-OFF* */
  606. __asm {
  607. push edi
  608. push esi
  609. push ebx
  610. xor edi,edi
  611. mov eax,dword ptr [esp+14h]
  612. or eax,eax
  613. jge L1
  614. inc edi
  615. mov edx,dword ptr [esp+10h]
  616. neg eax
  617. neg edx
  618. sbb eax,0
  619. mov dword ptr [esp+14h],eax
  620. mov dword ptr [esp+10h],edx
  621. L1:
  622. mov eax,dword ptr [esp+1Ch]
  623. or eax,eax
  624. jge L2
  625. inc edi
  626. mov edx,dword ptr [esp+18h]
  627. neg eax
  628. neg edx
  629. sbb eax,0
  630. mov dword ptr [esp+1Ch],eax
  631. mov dword ptr [esp+18h],edx
  632. L2:
  633. or eax,eax
  634. jne L3
  635. mov ecx,dword ptr [esp+18h]
  636. mov eax,dword ptr [esp+14h]
  637. xor edx,edx
  638. div ecx
  639. mov ebx,eax
  640. mov eax,dword ptr [esp+10h]
  641. div ecx
  642. mov edx,ebx
  643. jmp L4
  644. L3:
  645. mov ebx,eax
  646. mov ecx,dword ptr [esp+18h]
  647. mov edx,dword ptr [esp+14h]
  648. mov eax,dword ptr [esp+10h]
  649. L5:
  650. shr ebx,1
  651. rcr ecx,1
  652. shr edx,1
  653. rcr eax,1
  654. or ebx,ebx
  655. jne L5
  656. div ecx
  657. mov esi,eax
  658. mul dword ptr [esp+1Ch]
  659. mov ecx,eax
  660. mov eax,dword ptr [esp+18h]
  661. mul esi
  662. add edx,ecx
  663. jb L6
  664. cmp edx,dword ptr [esp+14h]
  665. ja L6
  666. jb L7
  667. cmp eax,dword ptr [esp+10h]
  668. jbe L7
  669. L6:
  670. dec esi
  671. L7:
  672. xor edx,edx
  673. mov eax,esi
  674. L4:
  675. dec edi
  676. jne L8
  677. neg edx
  678. neg eax
  679. sbb edx,0
  680. L8:
  681. pop ebx
  682. pop esi
  683. pop edi
  684. ret 10h
  685. }
  686. /* *INDENT-ON* */
  687. }
  688. void
  689. __declspec(naked)
  690. _aulldiv()
  691. {
  692. /* *INDENT-OFF* */
  693. __asm {
  694. push ebx
  695. push esi
  696. mov eax,dword ptr [esp+18h]
  697. or eax,eax
  698. jne L1
  699. mov ecx,dword ptr [esp+14h]
  700. mov eax,dword ptr [esp+10h]
  701. xor edx,edx
  702. div ecx
  703. mov ebx,eax
  704. mov eax,dword ptr [esp+0Ch]
  705. div ecx
  706. mov edx,ebx
  707. jmp L2
  708. L1:
  709. mov ecx,eax
  710. mov ebx,dword ptr [esp+14h]
  711. mov edx,dword ptr [esp+10h]
  712. mov eax,dword ptr [esp+0Ch]
  713. L3:
  714. shr ecx,1
  715. rcr ebx,1
  716. shr edx,1
  717. rcr eax,1
  718. or ecx,ecx
  719. jne L3
  720. div ebx
  721. mov esi,eax
  722. mul dword ptr [esp+18h]
  723. mov ecx,eax
  724. mov eax,dword ptr [esp+14h]
  725. mul esi
  726. add edx,ecx
  727. jb L4
  728. cmp edx,dword ptr [esp+10h]
  729. ja L4
  730. jb L5
  731. cmp eax,dword ptr [esp+0Ch]
  732. jbe L5
  733. L4:
  734. dec esi
  735. L5:
  736. xor edx,edx
  737. mov eax,esi
  738. L2:
  739. pop esi
  740. pop ebx
  741. ret 10h
  742. }
  743. /* *INDENT-ON* */
  744. }
  745. void
  746. __declspec(naked)
  747. _allrem()
  748. {
  749. /* *INDENT-OFF* */
  750. __asm {
  751. push ebx
  752. push edi
  753. xor edi,edi
  754. mov eax,dword ptr [esp+10h]
  755. or eax,eax
  756. jge L1
  757. inc edi
  758. mov edx,dword ptr [esp+0Ch]
  759. neg eax
  760. neg edx
  761. sbb eax,0
  762. mov dword ptr [esp+10h],eax
  763. mov dword ptr [esp+0Ch],edx
  764. L1:
  765. mov eax,dword ptr [esp+18h]
  766. or eax,eax
  767. jge L2
  768. mov edx,dword ptr [esp+14h]
  769. neg eax
  770. neg edx
  771. sbb eax,0
  772. mov dword ptr [esp+18h],eax
  773. mov dword ptr [esp+14h],edx
  774. L2:
  775. or eax,eax
  776. jne L3
  777. mov ecx,dword ptr [esp+14h]
  778. mov eax,dword ptr [esp+10h]
  779. xor edx,edx
  780. div ecx
  781. mov eax,dword ptr [esp+0Ch]
  782. div ecx
  783. mov eax,edx
  784. xor edx,edx
  785. dec edi
  786. jns L4
  787. jmp L8
  788. L3:
  789. mov ebx,eax
  790. mov ecx,dword ptr [esp+14h]
  791. mov edx,dword ptr [esp+10h]
  792. mov eax,dword ptr [esp+0Ch]
  793. L5:
  794. shr ebx,1
  795. rcr ecx,1
  796. shr edx,1
  797. rcr eax,1
  798. or ebx,ebx
  799. jne L5
  800. div ecx
  801. mov ecx,eax
  802. mul dword ptr [esp+18h]
  803. xchg eax,ecx
  804. mul dword ptr [esp+14h]
  805. add edx,ecx
  806. jb L6
  807. cmp edx,dword ptr [esp+10h]
  808. ja L6
  809. jb L7
  810. cmp eax,dword ptr [esp+0Ch]
  811. jbe L7
  812. L6:
  813. sub eax,dword ptr [esp+14h]
  814. sbb edx,dword ptr [esp+18h]
  815. L7:
  816. sub eax,dword ptr [esp+0Ch]
  817. sbb edx,dword ptr [esp+10h]
  818. dec edi
  819. jns L8
  820. L4:
  821. neg edx
  822. neg eax
  823. sbb edx,0
  824. L8:
  825. pop edi
  826. pop ebx
  827. ret 10h
  828. }
  829. /* *INDENT-ON* */
  830. }
  831. void
  832. __declspec(naked)
  833. _aullrem()
  834. {
  835. /* *INDENT-OFF* */
  836. __asm {
  837. push ebx
  838. mov eax,dword ptr [esp+14h]
  839. or eax,eax
  840. jne L1
  841. mov ecx,dword ptr [esp+10h]
  842. mov eax,dword ptr [esp+0Ch]
  843. xor edx,edx
  844. div ecx
  845. mov eax,dword ptr [esp+8]
  846. div ecx
  847. mov eax,edx
  848. xor edx,edx
  849. jmp L2
  850. L1:
  851. mov ecx,eax
  852. mov ebx,dword ptr [esp+10h]
  853. mov edx,dword ptr [esp+0Ch]
  854. mov eax,dword ptr [esp+8]
  855. L3:
  856. shr ecx,1
  857. rcr ebx,1
  858. shr edx,1
  859. rcr eax,1
  860. or ecx,ecx
  861. jne L3
  862. div ebx
  863. mov ecx,eax
  864. mul dword ptr [esp+14h]
  865. xchg eax,ecx
  866. mul dword ptr [esp+10h]
  867. add edx,ecx
  868. jb L4
  869. cmp edx,dword ptr [esp+0Ch]
  870. ja L4
  871. jb L5
  872. cmp eax,dword ptr [esp+8]
  873. jbe L5
  874. L4:
  875. sub eax,dword ptr [esp+10h]
  876. sbb edx,dword ptr [esp+14h]
  877. L5:
  878. sub eax,dword ptr [esp+8]
  879. sbb edx,dword ptr [esp+0Ch]
  880. neg edx
  881. neg eax
  882. sbb edx,0
  883. L2:
  884. pop ebx
  885. ret 10h
  886. }
  887. /* *INDENT-ON* */
  888. }
  889. void
  890. __declspec(naked)
  891. _alldvrm()
  892. {
  893. /* *INDENT-OFF* */
  894. __asm {
  895. push edi
  896. push esi
  897. push ebp
  898. xor edi,edi
  899. xor ebp,ebp
  900. mov eax,dword ptr [esp+14h]
  901. or eax,eax
  902. jge L1
  903. inc edi
  904. inc ebp
  905. mov edx,dword ptr [esp+10h]
  906. neg eax
  907. neg edx
  908. sbb eax,0
  909. mov dword ptr [esp+14h],eax
  910. mov dword ptr [esp+10h],edx
  911. L1:
  912. mov eax,dword ptr [esp+1Ch]
  913. or eax,eax
  914. jge L2
  915. inc edi
  916. mov edx,dword ptr [esp+18h]
  917. neg eax
  918. neg edx
  919. sbb eax,0
  920. mov dword ptr [esp+1Ch],eax
  921. mov dword ptr [esp+18h],edx
  922. L2:
  923. or eax,eax
  924. jne L3
  925. mov ecx,dword ptr [esp+18h]
  926. mov eax,dword ptr [esp+14h]
  927. xor edx,edx
  928. div ecx
  929. mov ebx,eax
  930. mov eax,dword ptr [esp+10h]
  931. div ecx
  932. mov esi,eax
  933. mov eax,ebx
  934. mul dword ptr [esp+18h]
  935. mov ecx,eax
  936. mov eax,esi
  937. mul dword ptr [esp+18h]
  938. add edx,ecx
  939. jmp L4
  940. L3:
  941. mov ebx,eax
  942. mov ecx,dword ptr [esp+18h]
  943. mov edx,dword ptr [esp+14h]
  944. mov eax,dword ptr [esp+10h]
  945. L5:
  946. shr ebx,1
  947. rcr ecx,1
  948. shr edx,1
  949. rcr eax,1
  950. or ebx,ebx
  951. jne L5
  952. div ecx
  953. mov esi,eax
  954. mul dword ptr [esp+1Ch]
  955. mov ecx,eax
  956. mov eax,dword ptr [esp+18h]
  957. mul esi
  958. add edx,ecx
  959. jb L6
  960. cmp edx,dword ptr [esp+14h]
  961. ja L6
  962. jb L7
  963. cmp eax,dword ptr [esp+10h]
  964. jbe L7
  965. L6:
  966. dec esi
  967. sub eax,dword ptr [esp+18h]
  968. sbb edx,dword ptr [esp+1Ch]
  969. L7:
  970. xor ebx,ebx
  971. L4:
  972. sub eax,dword ptr [esp+10h]
  973. sbb edx,dword ptr [esp+14h]
  974. dec ebp
  975. jns L9
  976. neg edx
  977. neg eax
  978. sbb edx,0
  979. L9:
  980. mov ecx,edx
  981. mov edx,ebx
  982. mov ebx,ecx
  983. mov ecx,eax
  984. mov eax,esi
  985. dec edi
  986. jne L8
  987. neg edx
  988. neg eax
  989. sbb edx,0
  990. L8:
  991. pop ebp
  992. pop esi
  993. pop edi
  994. ret 10h
  995. }
  996. /* *INDENT-ON* */
  997. }
  998. void
  999. __declspec(naked)
  1000. _aulldvrm()
  1001. {
  1002. /* *INDENT-OFF* */
  1003. __asm {
  1004. push esi
  1005. mov eax,dword ptr [esp+14h]
  1006. or eax,eax
  1007. jne L1
  1008. mov ecx,dword ptr [esp+10h]
  1009. mov eax,dword ptr [esp+0Ch]
  1010. xor edx,edx
  1011. div ecx
  1012. mov ebx,eax
  1013. mov eax,dword ptr [esp+8]
  1014. div ecx
  1015. mov esi,eax
  1016. mov eax,ebx
  1017. mul dword ptr [esp+10h]
  1018. mov ecx,eax
  1019. mov eax,esi
  1020. mul dword ptr [esp+10h]
  1021. add edx,ecx
  1022. jmp L2
  1023. L1:
  1024. mov ecx,eax
  1025. mov ebx,dword ptr [esp+10h]
  1026. mov edx,dword ptr [esp+0Ch]
  1027. mov eax,dword ptr [esp+8]
  1028. L3:
  1029. shr ecx,1
  1030. rcr ebx,1
  1031. shr edx,1
  1032. rcr eax,1
  1033. or ecx,ecx
  1034. jne L3
  1035. div ebx
  1036. mov esi,eax
  1037. mul dword ptr [esp+14h]
  1038. mov ecx,eax
  1039. mov eax,dword ptr [esp+10h]
  1040. mul esi
  1041. add edx,ecx
  1042. jb L4
  1043. cmp edx,dword ptr [esp+0Ch]
  1044. ja L4
  1045. jb L5
  1046. cmp eax,dword ptr [esp+8]
  1047. jbe L5
  1048. L4:
  1049. dec esi
  1050. sub eax,dword ptr [esp+10h]
  1051. sbb edx,dword ptr [esp+14h]
  1052. L5:
  1053. xor ebx,ebx
  1054. L2:
  1055. sub eax,dword ptr [esp+8]
  1056. sbb edx,dword ptr [esp+0Ch]
  1057. neg edx
  1058. neg eax
  1059. sbb edx,0
  1060. mov ecx,edx
  1061. mov edx,ebx
  1062. mov ebx,ecx
  1063. mov ecx,eax
  1064. mov eax,esi
  1065. pop esi
  1066. ret 10h
  1067. }
  1068. /* *INDENT-ON* */
  1069. }
  1070. void
  1071. __declspec(naked)
  1072. _allshl()
  1073. {
  1074. /* *INDENT-OFF* */
  1075. __asm {
  1076. cmp cl,40h
  1077. jae RETZERO
  1078. cmp cl,20h
  1079. jae MORE32
  1080. shld edx,eax,cl
  1081. shl eax,cl
  1082. ret
  1083. MORE32:
  1084. mov edx,eax
  1085. xor eax,eax
  1086. and cl,1Fh
  1087. shl edx,cl
  1088. ret
  1089. RETZERO:
  1090. xor eax,eax
  1091. xor edx,edx
  1092. ret
  1093. }
  1094. /* *INDENT-ON* */
  1095. }
  1096. void
  1097. __declspec(naked)
  1098. _allshr()
  1099. {
  1100. /* *INDENT-OFF* */
  1101. __asm {
  1102. cmp cl,3Fh
  1103. jae RETSIGN
  1104. cmp cl,20h
  1105. jae MORE32
  1106. shrd eax,edx,cl
  1107. sar edx,cl
  1108. ret
  1109. MORE32:
  1110. mov eax,edx
  1111. sar edx,1Fh
  1112. and cl,1Fh
  1113. sar eax,cl
  1114. ret
  1115. RETSIGN:
  1116. sar edx,1Fh
  1117. mov eax,edx
  1118. ret
  1119. }
  1120. /* *INDENT-ON* */
  1121. }
  1122. void
  1123. __declspec(naked)
  1124. _aullshr()
  1125. {
  1126. /* *INDENT-OFF* */
  1127. __asm {
  1128. cmp cl,40h
  1129. jae RETZERO
  1130. cmp cl,20h
  1131. jae MORE32
  1132. shrd eax,edx,cl
  1133. shr edx,cl
  1134. ret
  1135. MORE32:
  1136. mov eax,edx
  1137. xor edx,edx
  1138. and cl,1Fh
  1139. shr eax,cl
  1140. ret
  1141. RETZERO:
  1142. xor eax,eax
  1143. xor edx,edx
  1144. ret
  1145. }
  1146. /* *INDENT-ON* */
  1147. }
  1148. #endif /* _M_IX86 */
  1149. #endif /* MSC_VER */
  1150. #endif /* !HAVE_LIBC */
  1151. /* vi: set ts=4 sw=4 expandtab: */