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