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