cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

SDL_stdlib.c (22341B)


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