src/stdlib/SDL_stdlib.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Aug 2017 16:30:24 -0700
changeset 11341 8b3231952c22
parent 10737 3406a0f8b041
child 11404 bd5b569b2a1b
permissions -rw-r--r--
Fixed bug 3768 - provide a quick copysign() solution for watcom

Ozkan Sezer

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