SDL_stdlib.c 24 KB

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