src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 02 Feb 2014 00:53:27 -0800
changeset 8149 681eb46b8ac4
parent 8093 b43765095a6f
child 8231 ad3edb1923f2
permissions -rw-r--r--
Fixed bug 2374 - Update copyright for 2014...

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