src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 16 Aug 2014 23:23:15 -0700
changeset 9075 257a6793aaf5
parent 9015 45f11ff360a8
child 9080 2e4e71ec140f
permissions -rw-r--r--
Added SDL_round(), contributed by Benoit Pierre - thanks!
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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 #include "../SDL_internal.h"
    22 
    23 /* This file contains portable stdlib functions for SDL */
    24 
    25 #include "SDL_stdinc.h"
    26 #include "../libm/math_libm.h"
    27 
    28 
    29 double
    30 SDL_atan(double x)
    31 {
    32 #ifdef HAVE_ATAN
    33     return atan(x);
    34 #else
    35     return SDL_uclibc_atan(x);
    36 #endif /* HAVE_ATAN */
    37 }
    38 
    39 double
    40 SDL_atan2(double x, double y)
    41 {
    42 #if defined(HAVE_ATAN2)
    43     return atan2(x, y);
    44 #else
    45     return SDL_uclibc_atan2(x, y);
    46 #endif /* HAVE_ATAN2 */
    47 }
    48 
    49 double
    50 SDL_acos(double val)
    51 {
    52 #if defined(HAVE_ACOS)
    53     return acos(val);
    54 #else
    55     double result;
    56     if (val == -1.0) {
    57         result = M_PI;
    58     } else {
    59         result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
    60         if (result < 0.0)
    61         {
    62             result += M_PI;
    63         }
    64     }
    65     return result;
    66 #endif
    67 }
    68 
    69 double
    70 SDL_asin(double val)
    71 {
    72 #if defined(HAVE_ASIN)
    73     return asin(val);
    74 #else
    75     double result;
    76     if (val == -1.0) {
    77         result = -(M_PI / 2.0);
    78     } else {
    79         result = (M_PI / 2.0) - SDL_acos(val);
    80     }
    81     return result;
    82 #endif
    83 }
    84 
    85 double
    86 SDL_ceil(double x)
    87 {
    88 #ifdef HAVE_CEIL
    89     return ceil(x);
    90 #else
    91     double integer = SDL_floor(x);
    92     double fraction = x - integer;
    93     if (fraction > 0.0) {
    94         integer += 1.0;
    95     }
    96     return integer;
    97 #endif /* HAVE_CEIL */
    98 }
    99 
   100 double
   101 SDL_copysign(double x, double y)
   102 {
   103 #if defined(HAVE_COPYSIGN)
   104     return copysign(x, y);
   105 #elif defined(HAVE__COPYSIGN)
   106     return _copysign(x, y);
   107 #else
   108     return SDL_uclibc_copysign(x, y);
   109 #endif /* HAVE_COPYSIGN */
   110 }
   111 
   112 double
   113 SDL_cos(double x)
   114 {
   115 #if defined(HAVE_COS)
   116     return cos(x);
   117 #else
   118     return SDL_uclibc_cos(x);
   119 #endif /* HAVE_COS */
   120 }
   121 
   122 float
   123 SDL_cosf(float x)
   124 {
   125 #ifdef HAVE_COSF
   126     return cosf(x);
   127 #else
   128     return (float)SDL_cos((double)x);
   129 #endif
   130 }
   131 
   132 double
   133 SDL_fabs(double x)
   134 {
   135 #if defined(HAVE_FABS)
   136     return fabs(x); 
   137 #else
   138     return SDL_uclibc_fabs(x);
   139 #endif /* HAVE_FABS */
   140 }
   141 
   142 double
   143 SDL_floor(double x)
   144 {
   145 #if defined(HAVE_FLOOR)
   146     return floor(x);
   147 #else
   148     return SDL_uclibc_floor(x);
   149 #endif /* HAVE_FLOOR */
   150 }
   151 
   152 double
   153 SDL_log(double x)
   154 {
   155 #if defined(HAVE_LOG)
   156     return log(x);
   157 #else
   158     return SDL_uclibc_log(x);
   159 #endif /* HAVE_LOG */
   160 }
   161 
   162 double
   163 SDL_pow(double x, double y)
   164 {
   165 #if defined(HAVE_POW)
   166     return pow(x, y);
   167 #else
   168     return SDL_uclibc_pow(x, y);
   169 #endif /* HAVE_POW */
   170 }
   171 
   172 double
   173 SDL_round(double x)
   174 {
   175 #if defined(HAVE_ROUND)
   176     return round(x);
   177 #else
   178     return SDL_uclibc_round(x);
   179 #endif /* HAVE_ROUND */
   180 }
   181 
   182 double
   183 SDL_scalbn(double x, int n)
   184 {
   185 #if defined(HAVE_SCALBN)
   186     return scalbn(x, n);
   187 #elif defined(HAVE__SCALB)
   188     return _scalb(x, n);
   189 #else
   190     return SDL_uclibc_scalbn(x, n);
   191 #endif /* HAVE_SCALBN */
   192 }
   193 
   194 double
   195 SDL_sin(double x)
   196 {
   197 #if defined(HAVE_SIN)
   198     return sin(x);
   199 #else
   200     return SDL_uclibc_sin(x);
   201 #endif /* HAVE_SIN */
   202 }
   203 
   204 float 
   205 SDL_sinf(float x)
   206 {
   207 #ifdef HAVE_SINF
   208     return sinf(x);
   209 #else
   210     return (float)SDL_sin((double)x);
   211 #endif /* HAVE_SINF */
   212 }
   213 
   214 double
   215 SDL_sqrt(double x)
   216 {
   217 #if defined(HAVE_SQRT)
   218     return sqrt(x);
   219 #else
   220     return SDL_uclibc_sqrt(x);
   221 #endif
   222 }
   223 
   224 float
   225 SDL_sqrtf(float x)
   226 {
   227 #if defined(HAVE_SQRTF)
   228     return sqrtf(x);
   229 #else
   230     return (float)SDL_sqrt((double)x);
   231 #endif
   232 }
   233 
   234 double
   235 SDL_tan(double x)
   236 {
   237 #if defined(HAVE_TAN)
   238     return tan(x);
   239 #else
   240     return SDL_uclibc_tan(x);
   241 #endif
   242 }
   243 
   244 float
   245 SDL_tanf(float x)
   246 {
   247 #if defined(HAVE_TANF)
   248     return tanf(x);
   249 #else
   250     return (float)SDL_tan((double)x);
   251 #endif
   252 }
   253 
   254 int SDL_abs(int x)
   255 {
   256 #ifdef HAVE_ABS
   257     return abs(x);
   258 #else
   259     return ((x) < 0 ? -(x) : (x));
   260 #endif
   261 }
   262 
   263 #ifdef HAVE_CTYPE_H
   264 int SDL_isdigit(int x) { return isdigit(x); }
   265 int SDL_isspace(int x) { return isspace(x); }
   266 int SDL_toupper(int x) { return toupper(x); }
   267 int SDL_tolower(int x) { return tolower(x); }
   268 #else
   269 int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
   270 int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }
   271 int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   272 int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   273 #endif
   274 
   275 
   276 #ifndef HAVE_LIBC
   277 /* These are some C runtime intrinsics that need to be defined */
   278 
   279 #if defined(_MSC_VER)
   280 
   281 #ifndef __FLTUSED__
   282 #define __FLTUSED__
   283 __declspec(selectany) int _fltused = 1;
   284 #endif
   285 
   286 /* The optimizer on Visual Studio 2010/2012 generates memcpy() calls */
   287 #if _MSC_VER >= 1600 && defined(_WIN64) && !defined(_DEBUG)
   288 #include <intrin.h>
   289 
   290 #pragma function(memcpy)
   291 void * memcpy ( void * destination, const void * source, size_t num )
   292 {
   293     const Uint8 *src = (const Uint8 *)source;
   294     Uint8 *dst = (Uint8 *)destination;
   295     size_t i;
   296     
   297     /* All WIN64 architectures have SSE, right? */
   298     if (!((uintptr_t) src & 15) && !((uintptr_t) dst & 15)) {
   299         __m128 values[4];
   300         for (i = num / 64; i--;) {
   301             _mm_prefetch(src, _MM_HINT_NTA);
   302             values[0] = *(__m128 *) (src + 0);
   303             values[1] = *(__m128 *) (src + 16);
   304             values[2] = *(__m128 *) (src + 32);
   305             values[3] = *(__m128 *) (src + 48);
   306             _mm_stream_ps((float *) (dst + 0), values[0]);
   307             _mm_stream_ps((float *) (dst + 16), values[1]);
   308             _mm_stream_ps((float *) (dst + 32), values[2]);
   309             _mm_stream_ps((float *) (dst + 48), values[3]);
   310             src += 64;
   311             dst += 64;
   312         }
   313         num &= 63;
   314     }
   315 
   316     while (num--) {
   317         *dst++ = *src++;
   318     }
   319     return destination;
   320 }
   321 #endif /* _MSC_VER == 1600 && defined(_WIN64) && !defined(_DEBUG) */
   322 
   323 #ifdef _M_IX86
   324 
   325 /* Float to long */
   326 void
   327 __declspec(naked)
   328 _ftol()
   329 {
   330     /* *INDENT-OFF* */
   331     __asm {
   332         push        ebp
   333         mov         ebp,esp
   334         sub         esp,20h
   335         and         esp,0FFFFFFF0h
   336         fld         st(0)
   337         fst         dword ptr [esp+18h]
   338         fistp       qword ptr [esp+10h]
   339         fild        qword ptr [esp+10h]
   340         mov         edx,dword ptr [esp+18h]
   341         mov         eax,dword ptr [esp+10h]
   342         test        eax,eax
   343         je          integer_QnaN_or_zero
   344 arg_is_not_integer_QnaN:
   345         fsubp       st(1),st
   346         test        edx,edx
   347         jns         positive
   348         fstp        dword ptr [esp]
   349         mov         ecx,dword ptr [esp]
   350         xor         ecx,80000000h
   351         add         ecx,7FFFFFFFh
   352         adc         eax,0
   353         mov         edx,dword ptr [esp+14h]
   354         adc         edx,0
   355         jmp         localexit
   356 positive:
   357         fstp        dword ptr [esp]
   358         mov         ecx,dword ptr [esp]
   359         add         ecx,7FFFFFFFh
   360         sbb         eax,0
   361         mov         edx,dword ptr [esp+14h]
   362         sbb         edx,0
   363         jmp         localexit
   364 integer_QnaN_or_zero:
   365         mov         edx,dword ptr [esp+14h]
   366         test        edx,7FFFFFFFh
   367         jne         arg_is_not_integer_QnaN
   368         fstp        dword ptr [esp+18h]
   369         fstp        dword ptr [esp+18h]
   370 localexit:
   371         leave
   372         ret
   373     }
   374     /* *INDENT-ON* */
   375 }
   376 
   377 void
   378 _ftol2_sse()
   379 {
   380     _ftol();
   381 }
   382 
   383 /* 64-bit math operators for 32-bit systems */
   384 void
   385 __declspec(naked)
   386 _allmul()
   387 {
   388     /* *INDENT-OFF* */
   389     __asm {
   390         mov         eax, dword ptr[esp+8]
   391         mov         ecx, dword ptr[esp+10h]
   392         or          ecx, eax
   393         mov         ecx, dword ptr[esp+0Ch]
   394         jne         hard
   395         mov         eax, dword ptr[esp+4]
   396         mul         ecx
   397         ret         10h
   398 hard:
   399         push        ebx
   400         mul         ecx
   401         mov         ebx, eax
   402         mov         eax, dword ptr[esp+8]
   403         mul         dword ptr[esp+14h]
   404         add         ebx, eax
   405         mov         eax, dword ptr[esp+8]
   406         mul         ecx
   407         add         edx, ebx
   408         pop         ebx
   409         ret         10h
   410     }
   411     /* *INDENT-ON* */
   412 }
   413 
   414 void
   415 __declspec(naked)
   416 _alldiv()
   417 {
   418     /* *INDENT-OFF* */
   419     __asm {
   420         push        edi
   421         push        esi
   422         push        ebx
   423         xor         edi,edi
   424         mov         eax,dword ptr [esp+14h]
   425         or          eax,eax
   426         jge         L1
   427         inc         edi
   428         mov         edx,dword ptr [esp+10h]
   429         neg         eax
   430         neg         edx
   431         sbb         eax,0
   432         mov         dword ptr [esp+14h],eax
   433         mov         dword ptr [esp+10h],edx
   434 L1:
   435         mov         eax,dword ptr [esp+1Ch]
   436         or          eax,eax
   437         jge         L2
   438         inc         edi
   439         mov         edx,dword ptr [esp+18h]
   440         neg         eax
   441         neg         edx
   442         sbb         eax,0
   443         mov         dword ptr [esp+1Ch],eax
   444         mov         dword ptr [esp+18h],edx
   445 L2:
   446         or          eax,eax
   447         jne         L3
   448         mov         ecx,dword ptr [esp+18h]
   449         mov         eax,dword ptr [esp+14h]
   450         xor         edx,edx
   451         div         ecx
   452         mov         ebx,eax
   453         mov         eax,dword ptr [esp+10h]
   454         div         ecx
   455         mov         edx,ebx
   456         jmp         L4
   457 L3:
   458         mov         ebx,eax
   459         mov         ecx,dword ptr [esp+18h]
   460         mov         edx,dword ptr [esp+14h]
   461         mov         eax,dword ptr [esp+10h]
   462 L5:
   463         shr         ebx,1
   464         rcr         ecx,1
   465         shr         edx,1
   466         rcr         eax,1
   467         or          ebx,ebx
   468         jne         L5
   469         div         ecx
   470         mov         esi,eax
   471         mul         dword ptr [esp+1Ch]
   472         mov         ecx,eax
   473         mov         eax,dword ptr [esp+18h]
   474         mul         esi
   475         add         edx,ecx
   476         jb          L6
   477         cmp         edx,dword ptr [esp+14h]
   478         ja          L6
   479         jb          L7
   480         cmp         eax,dword ptr [esp+10h]
   481         jbe         L7
   482 L6:
   483         dec         esi
   484 L7:
   485         xor         edx,edx
   486         mov         eax,esi
   487 L4:
   488         dec         edi
   489         jne         L8
   490         neg         edx
   491         neg         eax
   492         sbb         edx,0
   493 L8:
   494         pop         ebx
   495         pop         esi
   496         pop         edi
   497         ret         10h
   498     }
   499     /* *INDENT-ON* */
   500 }
   501 
   502 void
   503 __declspec(naked)
   504 _aulldiv()
   505 {
   506     /* *INDENT-OFF* */
   507     __asm {
   508         push        ebx
   509         push        esi
   510         mov         eax,dword ptr [esp+18h]
   511         or          eax,eax
   512         jne         L1
   513         mov         ecx,dword ptr [esp+14h]
   514         mov         eax,dword ptr [esp+10h]
   515         xor         edx,edx
   516         div         ecx
   517         mov         ebx,eax
   518         mov         eax,dword ptr [esp+0Ch]
   519         div         ecx
   520         mov         edx,ebx
   521         jmp         L2
   522 L1:
   523         mov         ecx,eax
   524         mov         ebx,dword ptr [esp+14h]
   525         mov         edx,dword ptr [esp+10h]
   526         mov         eax,dword ptr [esp+0Ch]
   527 L3:
   528         shr         ecx,1
   529         rcr         ebx,1
   530         shr         edx,1
   531         rcr         eax,1
   532         or          ecx,ecx
   533         jne         L3
   534         div         ebx
   535         mov         esi,eax
   536         mul         dword ptr [esp+18h]
   537         mov         ecx,eax
   538         mov         eax,dword ptr [esp+14h]
   539         mul         esi
   540         add         edx,ecx
   541         jb          L4
   542         cmp         edx,dword ptr [esp+10h]
   543         ja          L4
   544         jb          L5
   545         cmp         eax,dword ptr [esp+0Ch]
   546         jbe         L5
   547 L4:
   548         dec         esi
   549 L5:
   550         xor         edx,edx
   551         mov         eax,esi
   552 L2:
   553         pop         esi
   554         pop         ebx
   555         ret         10h
   556     }
   557     /* *INDENT-ON* */
   558 }
   559 
   560 void
   561 __declspec(naked)
   562 _allrem()
   563 {
   564     /* *INDENT-OFF* */
   565     __asm {
   566         push        ebx
   567         push        edi
   568         xor         edi,edi
   569         mov         eax,dword ptr [esp+10h]
   570         or          eax,eax
   571         jge         L1
   572         inc         edi
   573         mov         edx,dword ptr [esp+0Ch]
   574         neg         eax
   575         neg         edx
   576         sbb         eax,0
   577         mov         dword ptr [esp+10h],eax
   578         mov         dword ptr [esp+0Ch],edx
   579 L1:
   580         mov         eax,dword ptr [esp+18h]
   581         or          eax,eax
   582         jge         L2
   583         mov         edx,dword ptr [esp+14h]
   584         neg         eax
   585         neg         edx
   586         sbb         eax,0
   587         mov         dword ptr [esp+18h],eax
   588         mov         dword ptr [esp+14h],edx
   589 L2:
   590         or          eax,eax
   591         jne         L3
   592         mov         ecx,dword ptr [esp+14h]
   593         mov         eax,dword ptr [esp+10h]
   594         xor         edx,edx
   595         div         ecx
   596         mov         eax,dword ptr [esp+0Ch]
   597         div         ecx
   598         mov         eax,edx
   599         xor         edx,edx
   600         dec         edi
   601         jns         L4
   602         jmp         L8
   603 L3:
   604         mov         ebx,eax
   605         mov         ecx,dword ptr [esp+14h]
   606         mov         edx,dword ptr [esp+10h]
   607         mov         eax,dword ptr [esp+0Ch]
   608 L5:
   609         shr         ebx,1
   610         rcr         ecx,1
   611         shr         edx,1
   612         rcr         eax,1
   613         or          ebx,ebx
   614         jne         L5
   615         div         ecx
   616         mov         ecx,eax
   617         mul         dword ptr [esp+18h]
   618         xchg        eax,ecx
   619         mul         dword ptr [esp+14h]
   620         add         edx,ecx
   621         jb          L6
   622         cmp         edx,dword ptr [esp+10h]
   623         ja          L6
   624         jb          L7
   625         cmp         eax,dword ptr [esp+0Ch]
   626         jbe         L7
   627 L6:
   628         sub         eax,dword ptr [esp+14h]
   629         sbb         edx,dword ptr [esp+18h]
   630 L7:
   631         sub         eax,dword ptr [esp+0Ch]
   632         sbb         edx,dword ptr [esp+10h]
   633         dec         edi
   634         jns         L8
   635 L4:
   636         neg         edx
   637         neg         eax
   638         sbb         edx,0
   639 L8:
   640         pop         edi
   641         pop         ebx
   642         ret         10h
   643     }
   644     /* *INDENT-ON* */
   645 }
   646 
   647 void
   648 __declspec(naked)
   649 _aullrem()
   650 {
   651     /* *INDENT-OFF* */
   652     __asm {
   653         push        ebx
   654         mov         eax,dword ptr [esp+14h]
   655         or          eax,eax
   656         jne         L1
   657         mov         ecx,dword ptr [esp+10h]
   658         mov         eax,dword ptr [esp+0Ch]
   659         xor         edx,edx
   660         div         ecx
   661         mov         eax,dword ptr [esp+8]
   662         div         ecx
   663         mov         eax,edx
   664         xor         edx,edx
   665         jmp         L2
   666 L1:
   667         mov         ecx,eax
   668         mov         ebx,dword ptr [esp+10h]
   669         mov         edx,dword ptr [esp+0Ch]
   670         mov         eax,dword ptr [esp+8]
   671 L3:
   672         shr         ecx,1
   673         rcr         ebx,1
   674         shr         edx,1
   675         rcr         eax,1
   676         or          ecx,ecx
   677         jne         L3
   678         div         ebx
   679         mov         ecx,eax
   680         mul         dword ptr [esp+14h]
   681         xchg        eax,ecx
   682         mul         dword ptr [esp+10h]
   683         add         edx,ecx
   684         jb          L4
   685         cmp         edx,dword ptr [esp+0Ch]
   686         ja          L4
   687         jb          L5
   688         cmp         eax,dword ptr [esp+8]
   689         jbe         L5
   690 L4:
   691         sub         eax,dword ptr [esp+10h]
   692         sbb         edx,dword ptr [esp+14h]
   693 L5:
   694         sub         eax,dword ptr [esp+8]
   695         sbb         edx,dword ptr [esp+0Ch]
   696         neg         edx
   697         neg         eax
   698         sbb         edx,0
   699 L2:
   700         pop         ebx
   701         ret         10h
   702     }
   703     /* *INDENT-ON* */
   704 }
   705 
   706 void
   707 __declspec(naked)
   708 _alldvrm()
   709 {
   710     /* *INDENT-OFF* */
   711     __asm {
   712         push        edi
   713         push        esi
   714         push        ebp
   715         xor         edi,edi
   716         xor         ebp,ebp
   717         mov         eax,dword ptr [esp+14h]
   718         or          eax,eax
   719         jge         L1
   720         inc         edi
   721         inc         ebp
   722         mov         edx,dword ptr [esp+10h]
   723         neg         eax
   724         neg         edx
   725         sbb         eax,0
   726         mov         dword ptr [esp+14h],eax
   727         mov         dword ptr [esp+10h],edx
   728 L1:
   729         mov         eax,dword ptr [esp+1Ch]
   730         or          eax,eax
   731         jge         L2
   732         inc         edi
   733         mov         edx,dword ptr [esp+18h]
   734         neg         eax
   735         neg         edx
   736         sbb         eax,0
   737         mov         dword ptr [esp+1Ch],eax
   738         mov         dword ptr [esp+18h],edx
   739 L2:
   740         or          eax,eax
   741         jne         L3
   742         mov         ecx,dword ptr [esp+18h]
   743         mov         eax,dword ptr [esp+14h]
   744         xor         edx,edx
   745         div         ecx
   746         mov         ebx,eax
   747         mov         eax,dword ptr [esp+10h]
   748         div         ecx
   749         mov         esi,eax
   750         mov         eax,ebx
   751         mul         dword ptr [esp+18h]
   752         mov         ecx,eax
   753         mov         eax,esi
   754         mul         dword ptr [esp+18h]
   755         add         edx,ecx
   756         jmp         L4
   757 L3:
   758         mov         ebx,eax
   759         mov         ecx,dword ptr [esp+18h]
   760         mov         edx,dword ptr [esp+14h]
   761         mov         eax,dword ptr [esp+10h]
   762 L5:
   763         shr         ebx,1
   764         rcr         ecx,1
   765         shr         edx,1
   766         rcr         eax,1
   767         or          ebx,ebx
   768         jne         L5
   769         div         ecx
   770         mov         esi,eax
   771         mul         dword ptr [esp+1Ch]
   772         mov         ecx,eax
   773         mov         eax,dword ptr [esp+18h]
   774         mul         esi
   775         add         edx,ecx
   776         jb          L6
   777         cmp         edx,dword ptr [esp+14h]
   778         ja          L6
   779         jb          L7
   780         cmp         eax,dword ptr [esp+10h]
   781         jbe         L7
   782 L6:
   783         dec         esi
   784         sub         eax,dword ptr [esp+18h]
   785         sbb         edx,dword ptr [esp+1Ch]
   786 L7:
   787         xor         ebx,ebx
   788 L4:
   789         sub         eax,dword ptr [esp+10h]
   790         sbb         edx,dword ptr [esp+14h]
   791         dec         ebp
   792         jns         L9
   793         neg         edx
   794         neg         eax
   795         sbb         edx,0
   796 L9:
   797         mov         ecx,edx
   798         mov         edx,ebx
   799         mov         ebx,ecx
   800         mov         ecx,eax
   801         mov         eax,esi
   802         dec         edi
   803         jne         L8
   804         neg         edx
   805         neg         eax
   806         sbb         edx,0
   807 L8:
   808         pop         ebp
   809         pop         esi
   810         pop         edi
   811         ret         10h
   812     }
   813     /* *INDENT-ON* */
   814 }
   815 
   816 void
   817 __declspec(naked)
   818 _aulldvrm()
   819 {
   820     /* *INDENT-OFF* */
   821     __asm {
   822         push        esi
   823         mov         eax,dword ptr [esp+14h]
   824         or          eax,eax
   825         jne         L1
   826         mov         ecx,dword ptr [esp+10h]
   827         mov         eax,dword ptr [esp+0Ch]
   828         xor         edx,edx
   829         div         ecx
   830         mov         ebx,eax
   831         mov         eax,dword ptr [esp+8]
   832         div         ecx
   833         mov         esi,eax
   834         mov         eax,ebx
   835         mul         dword ptr [esp+10h]
   836         mov         ecx,eax
   837         mov         eax,esi
   838         mul         dword ptr [esp+10h]
   839         add         edx,ecx
   840         jmp         L2
   841 L1:
   842         mov         ecx,eax
   843         mov         ebx,dword ptr [esp+10h]
   844         mov         edx,dword ptr [esp+0Ch]
   845         mov         eax,dword ptr [esp+8]
   846 L3:
   847         shr         ecx,1
   848         rcr         ebx,1
   849         shr         edx,1
   850         rcr         eax,1
   851         or          ecx,ecx
   852         jne         L3
   853         div         ebx
   854         mov         esi,eax
   855         mul         dword ptr [esp+14h]
   856         mov         ecx,eax
   857         mov         eax,dword ptr [esp+10h]
   858         mul         esi
   859         add         edx,ecx
   860         jb          L4
   861         cmp         edx,dword ptr [esp+0Ch]
   862         ja          L4
   863         jb          L5
   864         cmp         eax,dword ptr [esp+8]
   865         jbe         L5
   866 L4:
   867         dec         esi
   868         sub         eax,dword ptr [esp+10h]
   869         sbb         edx,dword ptr [esp+14h]
   870 L5:
   871         xor         ebx,ebx
   872 L2:
   873         sub         eax,dword ptr [esp+8]
   874         sbb         edx,dword ptr [esp+0Ch]
   875         neg         edx
   876         neg         eax
   877         sbb         edx,0
   878         mov         ecx,edx
   879         mov         edx,ebx
   880         mov         ebx,ecx
   881         mov         ecx,eax
   882         mov         eax,esi
   883         pop         esi
   884         ret         10h
   885     }
   886     /* *INDENT-ON* */
   887 }
   888 
   889 void
   890 __declspec(naked)
   891 _allshl()
   892 {
   893     /* *INDENT-OFF* */
   894     __asm {
   895         cmp         cl,40h
   896         jae         RETZERO
   897         cmp         cl,20h
   898         jae         MORE32
   899         shld        edx,eax,cl
   900         shl         eax,cl
   901         ret
   902 MORE32:
   903         mov         edx,eax
   904         xor         eax,eax
   905         and         cl,1Fh
   906         shl         edx,cl
   907         ret
   908 RETZERO:
   909         xor         eax,eax
   910         xor         edx,edx
   911         ret
   912     }
   913     /* *INDENT-ON* */
   914 }
   915 
   916 void
   917 __declspec(naked)
   918 _allshr()
   919 {
   920     /* *INDENT-OFF* */
   921     __asm {
   922         cmp         cl,40h
   923         jae         RETZERO
   924         cmp         cl,20h
   925         jae         MORE32
   926         shrd        eax,edx,cl
   927         sar         edx,cl
   928         ret
   929 MORE32:
   930         mov         eax,edx
   931         xor         edx,edx
   932         and         cl,1Fh
   933         sar         eax,cl
   934         ret
   935 RETZERO:
   936         xor         eax,eax
   937         xor         edx,edx
   938         ret
   939     }
   940     /* *INDENT-ON* */
   941 }
   942 
   943 void
   944 __declspec(naked)
   945 _aullshr()
   946 {
   947     /* *INDENT-OFF* */
   948     __asm {
   949         cmp         cl,40h
   950         jae         RETZERO
   951         cmp         cl,20h
   952         jae         MORE32
   953         shrd        eax,edx,cl
   954         shr         edx,cl
   955         ret
   956 MORE32:
   957         mov         eax,edx
   958         xor         edx,edx
   959         and         cl,1Fh
   960         shr         eax,cl
   961         ret
   962 RETZERO:
   963         xor         eax,eax
   964         xor         edx,edx
   965         ret
   966     }
   967     /* *INDENT-ON* */
   968 }
   969 
   970 #endif /* _M_IX86 */
   971 
   972 #endif /* MSC_VER */
   973 
   974 #endif /* !HAVE_LIBC */
   975 
   976 /* vi: set ts=4 sw=4 expandtab: */