SDL_stdlib.c 24 KB

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