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