SDL_stdlib.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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
  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 y, double x)
  45. {
  46. #if defined(HAVE_ATAN2)
  47. return atan2(y, x);
  48. #else
  49. return SDL_uclibc_atan2(y, x);
  50. #endif
  51. }
  52. float
  53. SDL_atan2f(float y, float x)
  54. {
  55. #if defined(HAVE_ATAN2F)
  56. return atan2f(y, x);
  57. #else
  58. return (float)SDL_atan2((double)y, (double)x);
  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((double)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 (((x) >= 'A') && ((x) <= 'F')) || (((x) >= 'a') && ((x) <= 'f')) || (SDL_isdigit(x)); }
  473. int SDL_ispunct(int x) { return (SDL_isgraph(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. Always provide it for the SDL2 DLL, but skip it when building static lib w/ static runtime. */
  497. #if (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT))
  498. extern void *memcpy(void* dst, const void* src, size_t len);
  499. #pragma intrinsic(memcpy)
  500. #pragma function(memcpy)
  501. void *
  502. memcpy(void *dst, const void *src, size_t len)
  503. {
  504. return SDL_memcpy(dst, src, len);
  505. }
  506. extern void *memset(void* dst, int c, size_t len);
  507. #pragma intrinsic(memset)
  508. #pragma function(memset)
  509. void *
  510. memset(void *dst, int c, size_t len)
  511. {
  512. return SDL_memset(dst, c, len);
  513. }
  514. #endif /* (_MSC_VER >= 1400) && (!defined(_MT) || defined(DLL_EXPORT)) */
  515. #ifdef _M_IX86
  516. /* Float to long */
  517. void
  518. __declspec(naked)
  519. _ftol()
  520. {
  521. /* *INDENT-OFF* */
  522. __asm {
  523. push ebp
  524. mov ebp,esp
  525. sub esp,20h
  526. and esp,0FFFFFFF0h
  527. fld st(0)
  528. fst dword ptr [esp+18h]
  529. fistp qword ptr [esp+10h]
  530. fild qword ptr [esp+10h]
  531. mov edx,dword ptr [esp+18h]
  532. mov eax,dword ptr [esp+10h]
  533. test eax,eax
  534. je integer_QnaN_or_zero
  535. arg_is_not_integer_QnaN:
  536. fsubp st(1),st
  537. test edx,edx
  538. jns positive
  539. fstp dword ptr [esp]
  540. mov ecx,dword ptr [esp]
  541. xor ecx,80000000h
  542. add ecx,7FFFFFFFh
  543. adc eax,0
  544. mov edx,dword ptr [esp+14h]
  545. adc edx,0
  546. jmp localexit
  547. positive:
  548. fstp dword ptr [esp]
  549. mov ecx,dword ptr [esp]
  550. add ecx,7FFFFFFFh
  551. sbb eax,0
  552. mov edx,dword ptr [esp+14h]
  553. sbb edx,0
  554. jmp localexit
  555. integer_QnaN_or_zero:
  556. mov edx,dword ptr [esp+14h]
  557. test edx,7FFFFFFFh
  558. jne arg_is_not_integer_QnaN
  559. fstp dword ptr [esp+18h]
  560. fstp dword ptr [esp+18h]
  561. localexit:
  562. leave
  563. ret
  564. }
  565. /* *INDENT-ON* */
  566. }
  567. void
  568. _ftol2_sse()
  569. {
  570. _ftol();
  571. }
  572. /* 64-bit math operators for 32-bit systems */
  573. void
  574. __declspec(naked)
  575. _allmul()
  576. {
  577. /* *INDENT-OFF* */
  578. __asm {
  579. mov eax, dword ptr[esp+8]
  580. mov ecx, dword ptr[esp+10h]
  581. or ecx, eax
  582. mov ecx, dword ptr[esp+0Ch]
  583. jne hard
  584. mov eax, dword ptr[esp+4]
  585. mul ecx
  586. ret 10h
  587. hard:
  588. push ebx
  589. mul ecx
  590. mov ebx, eax
  591. mov eax, dword ptr[esp+8]
  592. mul dword ptr[esp+14h]
  593. add ebx, eax
  594. mov eax, dword ptr[esp+8]
  595. mul ecx
  596. add edx, ebx
  597. pop ebx
  598. ret 10h
  599. }
  600. /* *INDENT-ON* */
  601. }
  602. void
  603. __declspec(naked)
  604. _alldiv()
  605. {
  606. /* *INDENT-OFF* */
  607. __asm {
  608. push edi
  609. push esi
  610. push ebx
  611. xor edi,edi
  612. mov eax,dword ptr [esp+14h]
  613. or eax,eax
  614. jge L1
  615. inc edi
  616. mov edx,dword ptr [esp+10h]
  617. neg eax
  618. neg edx
  619. sbb eax,0
  620. mov dword ptr [esp+14h],eax
  621. mov dword ptr [esp+10h],edx
  622. L1:
  623. mov eax,dword ptr [esp+1Ch]
  624. or eax,eax
  625. jge L2
  626. inc edi
  627. mov edx,dword ptr [esp+18h]
  628. neg eax
  629. neg edx
  630. sbb eax,0
  631. mov dword ptr [esp+1Ch],eax
  632. mov dword ptr [esp+18h],edx
  633. L2:
  634. or eax,eax
  635. jne L3
  636. mov ecx,dword ptr [esp+18h]
  637. mov eax,dword ptr [esp+14h]
  638. xor edx,edx
  639. div ecx
  640. mov ebx,eax
  641. mov eax,dword ptr [esp+10h]
  642. div ecx
  643. mov edx,ebx
  644. jmp L4
  645. L3:
  646. mov ebx,eax
  647. mov ecx,dword ptr [esp+18h]
  648. mov edx,dword ptr [esp+14h]
  649. mov eax,dword ptr [esp+10h]
  650. L5:
  651. shr ebx,1
  652. rcr ecx,1
  653. shr edx,1
  654. rcr eax,1
  655. or ebx,ebx
  656. jne L5
  657. div ecx
  658. mov esi,eax
  659. mul dword ptr [esp+1Ch]
  660. mov ecx,eax
  661. mov eax,dword ptr [esp+18h]
  662. mul esi
  663. add edx,ecx
  664. jb L6
  665. cmp edx,dword ptr [esp+14h]
  666. ja L6
  667. jb L7
  668. cmp eax,dword ptr [esp+10h]
  669. jbe L7
  670. L6:
  671. dec esi
  672. L7:
  673. xor edx,edx
  674. mov eax,esi
  675. L4:
  676. dec edi
  677. jne L8
  678. neg edx
  679. neg eax
  680. sbb edx,0
  681. L8:
  682. pop ebx
  683. pop esi
  684. pop edi
  685. ret 10h
  686. }
  687. /* *INDENT-ON* */
  688. }
  689. void
  690. __declspec(naked)
  691. _aulldiv()
  692. {
  693. /* *INDENT-OFF* */
  694. __asm {
  695. push ebx
  696. push esi
  697. mov eax,dword ptr [esp+18h]
  698. or eax,eax
  699. jne L1
  700. mov ecx,dword ptr [esp+14h]
  701. mov eax,dword ptr [esp+10h]
  702. xor edx,edx
  703. div ecx
  704. mov ebx,eax
  705. mov eax,dword ptr [esp+0Ch]
  706. div ecx
  707. mov edx,ebx
  708. jmp L2
  709. L1:
  710. mov ecx,eax
  711. mov ebx,dword ptr [esp+14h]
  712. mov edx,dword ptr [esp+10h]
  713. mov eax,dword ptr [esp+0Ch]
  714. L3:
  715. shr ecx,1
  716. rcr ebx,1
  717. shr edx,1
  718. rcr eax,1
  719. or ecx,ecx
  720. jne L3
  721. div ebx
  722. mov esi,eax
  723. mul dword ptr [esp+18h]
  724. mov ecx,eax
  725. mov eax,dword ptr [esp+14h]
  726. mul esi
  727. add edx,ecx
  728. jb L4
  729. cmp edx,dword ptr [esp+10h]
  730. ja L4
  731. jb L5
  732. cmp eax,dword ptr [esp+0Ch]
  733. jbe L5
  734. L4:
  735. dec esi
  736. L5:
  737. xor edx,edx
  738. mov eax,esi
  739. L2:
  740. pop esi
  741. pop ebx
  742. ret 10h
  743. }
  744. /* *INDENT-ON* */
  745. }
  746. void
  747. __declspec(naked)
  748. _allrem()
  749. {
  750. /* *INDENT-OFF* */
  751. __asm {
  752. push ebx
  753. push edi
  754. xor edi,edi
  755. mov eax,dword ptr [esp+10h]
  756. or eax,eax
  757. jge L1
  758. inc edi
  759. mov edx,dword ptr [esp+0Ch]
  760. neg eax
  761. neg edx
  762. sbb eax,0
  763. mov dword ptr [esp+10h],eax
  764. mov dword ptr [esp+0Ch],edx
  765. L1:
  766. mov eax,dword ptr [esp+18h]
  767. or eax,eax
  768. jge L2
  769. mov edx,dword ptr [esp+14h]
  770. neg eax
  771. neg edx
  772. sbb eax,0
  773. mov dword ptr [esp+18h],eax
  774. mov dword ptr [esp+14h],edx
  775. L2:
  776. or eax,eax
  777. jne L3
  778. mov ecx,dword ptr [esp+14h]
  779. mov eax,dword ptr [esp+10h]
  780. xor edx,edx
  781. div ecx
  782. mov eax,dword ptr [esp+0Ch]
  783. div ecx
  784. mov eax,edx
  785. xor edx,edx
  786. dec edi
  787. jns L4
  788. jmp L8
  789. L3:
  790. mov ebx,eax
  791. mov ecx,dword ptr [esp+14h]
  792. mov edx,dword ptr [esp+10h]
  793. mov eax,dword ptr [esp+0Ch]
  794. L5:
  795. shr ebx,1
  796. rcr ecx,1
  797. shr edx,1
  798. rcr eax,1
  799. or ebx,ebx
  800. jne L5
  801. div ecx
  802. mov ecx,eax
  803. mul dword ptr [esp+18h]
  804. xchg eax,ecx
  805. mul dword ptr [esp+14h]
  806. add edx,ecx
  807. jb L6
  808. cmp edx,dword ptr [esp+10h]
  809. ja L6
  810. jb L7
  811. cmp eax,dword ptr [esp+0Ch]
  812. jbe L7
  813. L6:
  814. sub eax,dword ptr [esp+14h]
  815. sbb edx,dword ptr [esp+18h]
  816. L7:
  817. sub eax,dword ptr [esp+0Ch]
  818. sbb edx,dword ptr [esp+10h]
  819. dec edi
  820. jns L8
  821. L4:
  822. neg edx
  823. neg eax
  824. sbb edx,0
  825. L8:
  826. pop edi
  827. pop ebx
  828. ret 10h
  829. }
  830. /* *INDENT-ON* */
  831. }
  832. void
  833. __declspec(naked)
  834. _aullrem()
  835. {
  836. /* *INDENT-OFF* */
  837. __asm {
  838. push ebx
  839. mov eax,dword ptr [esp+14h]
  840. or eax,eax
  841. jne L1
  842. mov ecx,dword ptr [esp+10h]
  843. mov eax,dword ptr [esp+0Ch]
  844. xor edx,edx
  845. div ecx
  846. mov eax,dword ptr [esp+8]
  847. div ecx
  848. mov eax,edx
  849. xor edx,edx
  850. jmp L2
  851. L1:
  852. mov ecx,eax
  853. mov ebx,dword ptr [esp+10h]
  854. mov edx,dword ptr [esp+0Ch]
  855. mov eax,dword ptr [esp+8]
  856. L3:
  857. shr ecx,1
  858. rcr ebx,1
  859. shr edx,1
  860. rcr eax,1
  861. or ecx,ecx
  862. jne L3
  863. div ebx
  864. mov ecx,eax
  865. mul dword ptr [esp+14h]
  866. xchg eax,ecx
  867. mul dword ptr [esp+10h]
  868. add edx,ecx
  869. jb L4
  870. cmp edx,dword ptr [esp+0Ch]
  871. ja L4
  872. jb L5
  873. cmp eax,dword ptr [esp+8]
  874. jbe L5
  875. L4:
  876. sub eax,dword ptr [esp+10h]
  877. sbb edx,dword ptr [esp+14h]
  878. L5:
  879. sub eax,dword ptr [esp+8]
  880. sbb edx,dword ptr [esp+0Ch]
  881. neg edx
  882. neg eax
  883. sbb edx,0
  884. L2:
  885. pop ebx
  886. ret 10h
  887. }
  888. /* *INDENT-ON* */
  889. }
  890. void
  891. __declspec(naked)
  892. _alldvrm()
  893. {
  894. /* *INDENT-OFF* */
  895. __asm {
  896. push edi
  897. push esi
  898. push ebp
  899. xor edi,edi
  900. xor ebp,ebp
  901. mov eax,dword ptr [esp+14h]
  902. or eax,eax
  903. jge L1
  904. inc edi
  905. inc ebp
  906. mov edx,dword ptr [esp+10h]
  907. neg eax
  908. neg edx
  909. sbb eax,0
  910. mov dword ptr [esp+14h],eax
  911. mov dword ptr [esp+10h],edx
  912. L1:
  913. mov eax,dword ptr [esp+1Ch]
  914. or eax,eax
  915. jge L2
  916. inc edi
  917. mov edx,dword ptr [esp+18h]
  918. neg eax
  919. neg edx
  920. sbb eax,0
  921. mov dword ptr [esp+1Ch],eax
  922. mov dword ptr [esp+18h],edx
  923. L2:
  924. or eax,eax
  925. jne L3
  926. mov ecx,dword ptr [esp+18h]
  927. mov eax,dword ptr [esp+14h]
  928. xor edx,edx
  929. div ecx
  930. mov ebx,eax
  931. mov eax,dword ptr [esp+10h]
  932. div ecx
  933. mov esi,eax
  934. mov eax,ebx
  935. mul dword ptr [esp+18h]
  936. mov ecx,eax
  937. mov eax,esi
  938. mul dword ptr [esp+18h]
  939. add edx,ecx
  940. jmp L4
  941. L3:
  942. mov ebx,eax
  943. mov ecx,dword ptr [esp+18h]
  944. mov edx,dword ptr [esp+14h]
  945. mov eax,dword ptr [esp+10h]
  946. L5:
  947. shr ebx,1
  948. rcr ecx,1
  949. shr edx,1
  950. rcr eax,1
  951. or ebx,ebx
  952. jne L5
  953. div ecx
  954. mov esi,eax
  955. mul dword ptr [esp+1Ch]
  956. mov ecx,eax
  957. mov eax,dword ptr [esp+18h]
  958. mul esi
  959. add edx,ecx
  960. jb L6
  961. cmp edx,dword ptr [esp+14h]
  962. ja L6
  963. jb L7
  964. cmp eax,dword ptr [esp+10h]
  965. jbe L7
  966. L6:
  967. dec esi
  968. sub eax,dword ptr [esp+18h]
  969. sbb edx,dword ptr [esp+1Ch]
  970. L7:
  971. xor ebx,ebx
  972. L4:
  973. sub eax,dword ptr [esp+10h]
  974. sbb edx,dword ptr [esp+14h]
  975. dec ebp
  976. jns L9
  977. neg edx
  978. neg eax
  979. sbb edx,0
  980. L9:
  981. mov ecx,edx
  982. mov edx,ebx
  983. mov ebx,ecx
  984. mov ecx,eax
  985. mov eax,esi
  986. dec edi
  987. jne L8
  988. neg edx
  989. neg eax
  990. sbb edx,0
  991. L8:
  992. pop ebp
  993. pop esi
  994. pop edi
  995. ret 10h
  996. }
  997. /* *INDENT-ON* */
  998. }
  999. void
  1000. __declspec(naked)
  1001. _aulldvrm()
  1002. {
  1003. /* *INDENT-OFF* */
  1004. __asm {
  1005. push esi
  1006. mov eax,dword ptr [esp+14h]
  1007. or eax,eax
  1008. jne L1
  1009. mov ecx,dword ptr [esp+10h]
  1010. mov eax,dword ptr [esp+0Ch]
  1011. xor edx,edx
  1012. div ecx
  1013. mov ebx,eax
  1014. mov eax,dword ptr [esp+8]
  1015. div ecx
  1016. mov esi,eax
  1017. mov eax,ebx
  1018. mul dword ptr [esp+10h]
  1019. mov ecx,eax
  1020. mov eax,esi
  1021. mul dword ptr [esp+10h]
  1022. add edx,ecx
  1023. jmp L2
  1024. L1:
  1025. mov ecx,eax
  1026. mov ebx,dword ptr [esp+10h]
  1027. mov edx,dword ptr [esp+0Ch]
  1028. mov eax,dword ptr [esp+8]
  1029. L3:
  1030. shr ecx,1
  1031. rcr ebx,1
  1032. shr edx,1
  1033. rcr eax,1
  1034. or ecx,ecx
  1035. jne L3
  1036. div ebx
  1037. mov esi,eax
  1038. mul dword ptr [esp+14h]
  1039. mov ecx,eax
  1040. mov eax,dword ptr [esp+10h]
  1041. mul esi
  1042. add edx,ecx
  1043. jb L4
  1044. cmp edx,dword ptr [esp+0Ch]
  1045. ja L4
  1046. jb L5
  1047. cmp eax,dword ptr [esp+8]
  1048. jbe L5
  1049. L4:
  1050. dec esi
  1051. sub eax,dword ptr [esp+10h]
  1052. sbb edx,dword ptr [esp+14h]
  1053. L5:
  1054. xor ebx,ebx
  1055. L2:
  1056. sub eax,dword ptr [esp+8]
  1057. sbb edx,dword ptr [esp+0Ch]
  1058. neg edx
  1059. neg eax
  1060. sbb edx,0
  1061. mov ecx,edx
  1062. mov edx,ebx
  1063. mov ebx,ecx
  1064. mov ecx,eax
  1065. mov eax,esi
  1066. pop esi
  1067. ret 10h
  1068. }
  1069. /* *INDENT-ON* */
  1070. }
  1071. void
  1072. __declspec(naked)
  1073. _allshl()
  1074. {
  1075. /* *INDENT-OFF* */
  1076. __asm {
  1077. cmp cl,40h
  1078. jae RETZERO
  1079. cmp cl,20h
  1080. jae MORE32
  1081. shld edx,eax,cl
  1082. shl eax,cl
  1083. ret
  1084. MORE32:
  1085. mov edx,eax
  1086. xor eax,eax
  1087. and cl,1Fh
  1088. shl edx,cl
  1089. ret
  1090. RETZERO:
  1091. xor eax,eax
  1092. xor edx,edx
  1093. ret
  1094. }
  1095. /* *INDENT-ON* */
  1096. }
  1097. void
  1098. __declspec(naked)
  1099. _allshr()
  1100. {
  1101. /* *INDENT-OFF* */
  1102. __asm {
  1103. cmp cl,3Fh
  1104. jae RETSIGN
  1105. cmp cl,20h
  1106. jae MORE32
  1107. shrd eax,edx,cl
  1108. sar edx,cl
  1109. ret
  1110. MORE32:
  1111. mov eax,edx
  1112. sar edx,1Fh
  1113. and cl,1Fh
  1114. sar eax,cl
  1115. ret
  1116. RETSIGN:
  1117. sar edx,1Fh
  1118. mov eax,edx
  1119. ret
  1120. }
  1121. /* *INDENT-ON* */
  1122. }
  1123. void
  1124. __declspec(naked)
  1125. _aullshr()
  1126. {
  1127. /* *INDENT-OFF* */
  1128. __asm {
  1129. cmp cl,40h
  1130. jae RETZERO
  1131. cmp cl,20h
  1132. jae MORE32
  1133. shrd eax,edx,cl
  1134. shr edx,cl
  1135. ret
  1136. MORE32:
  1137. mov eax,edx
  1138. xor edx,edx
  1139. and cl,1Fh
  1140. shr eax,cl
  1141. ret
  1142. RETZERO:
  1143. xor eax,eax
  1144. xor edx,edx
  1145. ret
  1146. }
  1147. /* *INDENT-ON* */
  1148. }
  1149. #endif /* _M_IX86 */
  1150. #endif /* MSC_VER */
  1151. #endif /* !HAVE_LIBC */
  1152. /* vi: set ts=4 sw=4 expandtab: */