src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Jan 2016 10:25:53 -0800
changeset 9999 4de94185790e
parent 9998 f67cf37e9cd4
child 10001 e12c38730512
permissions -rw-r--r--
Fixed bug 3092 - Statically link sdl2 with /MT for msvc

Martin Gerhardy

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