Changeset 60468 in webkit for trunk/JavaScriptCore/wtf/dtoa.cpp


Ignore:
Timestamp:
Jun 1, 2010, 1:57:38 AM (15 years ago)
Author:
[email protected]
Message:

2010-06-01 Kent Tamura <[email protected]>

Reviewed by Shinichiro Hamaji.

Fix style errors of dtoa
https://bugs.webkit.org/show_bug.cgi?id=39972

Fix all errors reported by check-webkit-style.

  • wtf/dtoa.cpp:
  • wtf/dtoa.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/dtoa.cpp

    r52729 r60468  
    143143#include <math.h>
    144144#include <stdint.h>
     145#include <stdio.h>
    145146#include <stdlib.h>
    146147#include <string.h>
     
    149150#include <wtf/FastMalloc.h>
    150151#include <wtf/MathExtras.h>
     152#include <wtf/Threading.h>
    151153#include <wtf/Vector.h>
    152 #include <wtf/Threading.h>
    153 
    154 #include <stdio.h>
    155154
    156155#if COMPILER(MSVC)
     
    180179#endif
    181180
    182 typedef union { double d; uint32_t L[2]; } U;
     181typedef union {
     182    double d;
     183    uint32_t L[2];
     184} U;
    183185
    184186#ifdef YES_ALIAS
     
    204206/* The following definition of Storeinc is appropriate for MIPS processors.
    205207 * An alternative that might be better on some machines is
    206  * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
     208 *  *p++ = high << 16 | low & 0xffff;
    207209 */
     210static ALWAYS_INLINE uint32_t* storeInc(uint32_t* p, uint16_t high, uint16_t low)
     211{
     212    uint16_t* p16 = reinterpret_cast<uint16_t*>(p);
    208213#if defined(IEEE_8087) || defined(IEEE_ARM)
    209 #define Storeinc(a,b,c) (((unsigned short*)a)[1] = (unsigned short)b, ((unsigned short*)a)[0] = (unsigned short)c, a++)
    210 #else
    211 #define Storeinc(a,b,c) (((unsigned short*)a)[0] = (unsigned short)b, ((unsigned short*)a)[1] = (unsigned short)c, a++)
    212 #endif
     214    p16[1] = high;
     215    p16[0] = low;
     216#else
     217    p16[0] = high;
     218    p16[1] = low;
     219#endif
     220    return p + 1;
     221}
    213222
    214223#define Exp_shift  20
     
    248257#define Flt_Rounds 1
    249258#endif
    250 #endif /*Flt_Rounds*/
    251 
    252 
    253 #define rounded_product(a,b) a *= b
    254 #define rounded_quotient(a,b) a /= b
     259#endif /* Flt_Rounds */
     260
     261
     262#define rounded_product(a, b) a *= b
     263#define rounded_quotient(a, b) a /= b
    255264
    256265#define Big0 (Frac_mask1 | Exp_msk1 * (DBL_MAX_EXP + Bias - 1))
     
    414423}
    415424
    416 static int lo0bits (uint32_t* y)
     425static int lo0bits(uint32_t* y)
    417426{
    418427    int k;
     
    469478    BigInt c;
    470479    int wa, wb, wc;
    471     const uint32_t *x = 0, *xa, *xb, *xae, *xbe;
    472     uint32_t *xc, *xc0;
     480    const uint32_t* x = 0;
     481    const uint32_t* xa;
     482    const uint32_t* xb;
     483    const uint32_t* xae;
     484    const uint32_t* xbe;
     485    uint32_t* xc;
     486    uint32_t* xc0;
    473487    uint32_t y;
    474488#ifdef USE_LONG_LONG
     
    522536                uint32_t z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
    523537                carry = z2 >> 16;
    524                 Storeinc(xc, z2, z);
     538                xc = storeInc(xc, z2, z);
    525539            } while (x < xae);
    526540            *xc = carry;
     
    534548                z = (*x & 0xffff) * y + (*xc >> 16) + carry;
    535549                carry = z >> 16;
    536                 Storeinc(xc, z, z2);
     550                xc = storeInc(xc, z, z2);
    537551                z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
    538552                carry = z2 >> 16;
     
    542556    }
    543557#else
    544     for(; xb < xbe; xc0++) {
     558    for (; xb < xbe; xc0++) {
    545559        if ((y = *xb++)) {
    546560            x = xa;
     
    568582   
    569583static P5Node* p5s;
    570 static int p5s_count;
     584static int p5sCount;
    571585
    572586static ALWAYS_INLINE void pow5mult(BigInt& b, int k)
     
    591605        p5->next = 0;
    592606        p5s = p5;
    593         p5s_count = 1;
    594     }
    595 
    596     int p5s_count_local = p5s_count;
     607        p5sCount = 1;
     608    }
     609
     610    int p5sCountLocal = p5sCount;
    597611#if ENABLE(JSC_MULTIPLE_THREADS)
    598612    s_dtoaP5Mutex->unlock();
    599613#endif
    600     int p5s_used = 0;
     614    int p5sUsed = 0;
    601615
    602616    for (;;) {
     
    607621            break;
    608622
    609         if (++p5s_used == p5s_count_local) {
     623        if (++p5sUsed == p5sCountLocal) {
    610624#if ENABLE(JSC_MULTIPLE_THREADS)
    611625            s_dtoaP5Mutex->lock();
    612626#endif
    613             if (p5s_used == p5s_count) {
     627            if (p5sUsed == p5sCount) {
    614628                ASSERT(!p5->next);
    615629                p5->next = new P5Node;
     
    617631                p5->next->val = p5->val;
    618632                mult(p5->next->val, p5->next->val);
    619                 ++p5s_count;
     633                ++p5sCount;
    620634            }
    621635           
    622             p5s_count_local = p5s_count;
     636            p5sCountLocal = p5sCount;
    623637#if ENABLE(JSC_MULTIPLE_THREADS)
    624638            s_dtoaP5Mutex->unlock();
     
    660674        ASSERT(dst == dstStart + n);
    661675
    662         b.resize(origSize + n + (b.words()[n1 - 1] != 0));
     676        b.resize(origSize + n + !!b.words()[n1 - 1]);
    663677    }
    664678#else
     
    672686        *dst = hiSubword;
    673687        ASSERT(dst == dstStart + n);
    674         result->wds = b->wds + n + (result->x[n1 - 1] != 0);
     688        result->wds = b->wds + n + !!result->x[n1 - 1];
    675689     }
    676  #endif
     690#endif
    677691    else {
    678692        do {
     
    715729    const BigInt* b = &bRef;
    716730    int i, wa, wb;
    717     uint32_t *xc;
     731    uint32_t* xc;
    718732
    719733    i = cmp(*a, *b);
     
    762776        uint32_t z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
    763777        borrow = (z & 0x10000) >> 16;
    764         Storeinc(xc, z, y);
     778        xc = storeInc(xc, z, y);
    765779    } while (xb < xbe);
    766780    while (xa < xae) {
     
    769783        uint32_t z = (*xa++ >> 16) - borrow;
    770784        borrow = (z & 0x10000) >> 16;
    771         Storeinc(xc, z, y);
     785        xc = storeInc(xc, z, y);
    772786    }
    773787#else
     
    844858        w = xa > xa0 ? *--xa : 0;
    845859        d1 = (y << (32 - Ebits + k)) | (w >> (Ebits - k));
    846         goto ret_d;
     860        goto returnD;
    847861    }
    848862    z = xa > xa0 ? *--xa : 0;
     
    862876        y = xa > xa0 ? *--xa : 0;
    863877        d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
    864         goto ret_d;
     878        goto returnD;
    865879    }
    866880    z = xa > xa0 ? *--xa : 0;
     
    871885    d1 = w << k + 16 | y << k;
    872886#endif
    873 ret_d:
     887returnD:
    874888#undef d0
    875889#undef d1
     
    880894{
    881895    int de, k;
    882     uint32_t *x, y, z;
     896    uint32_t* x;
     897    uint32_t y, z;
    883898#ifndef Sudden_Underflow
    884899    int i;
     
    11161131    sign = nz0 = nz = 0;
    11171132    dval(&rv) = 0;
    1118     for (s = s00; ; s++)
     1133    for (s = s00; ; s++) {
    11191134        switch (*s) {
    1120             case '-':
    1121                 sign = 1;
    1122                 /* no break */
    1123             case '+':
    1124                 if (*++s)
    1125                     goto break2;
    1126                 /* no break */
    1127             case 0:
    1128                 goto ret0;
    1129             case '\t':
    1130             case '\n':
    1131             case '\v':
    1132             case '\f':
    1133             case '\r':
    1134             case ' ':
    1135                 continue;
    1136             default:
     1135        case '-':
     1136            sign = 1;
     1137            /* no break */
     1138        case '+':
     1139            if (*++s)
    11371140                goto break2;
    1138         }
     1141            /* no break */
     1142        case 0:
     1143            goto ret0;
     1144        case '\t':
     1145        case '\n':
     1146        case '\v':
     1147        case '\f':
     1148        case '\r':
     1149        case ' ':
     1150            continue;
     1151        default:
     1152            goto break2;
     1153        }
     1154    }
    11391155break2:
    11401156    if (*s == '0') {
     
    11611177                nf += nz;
    11621178                nz = 0;
    1163                 goto have_dig;
    1164             }
    1165             goto dig_done;
     1179                goto haveDig;
     1180            }
     1181            goto digDone;
    11661182        }
    11671183        for (; c >= '0' && c <= '9'; c = *++s) {
    1168 have_dig:
     1184haveDig:
    11691185            nz++;
    11701186            if (c -= '0') {
     
    11831199        }
    11841200    }
    1185 dig_done:
     1201digDone:
    11861202    e = 0;
    11871203    if (c == 'e' || c == 'E') {
    1188         if (!nd && !nz && !nz0) {
     1204        if (!nd && !nz && !nz0)
    11891205            goto ret0;
    1190         }
    11911206        s00 = s;
    11921207        esign = 0;
    11931208        switch (c = *++s) {
    1194             case '-':
    1195                 esign = 1;
    1196             case '+':
    1197                 c = *++s;
     1209        case '-':
     1210            esign = 1;
     1211        case '+':
     1212            c = *++s;
    11981213        }
    11991214        if (c >= '0' && c <= '9') {
     
    12231238#ifdef INFNAN_CHECK
    12241239            /* Check for Nan and Infinity */
    1225             switch(c) {
    1226                 case 'i':
    1227                 case 'I':
    1228                     if (match(&s,"nf")) {
    1229                         --s;
    1230                         if (!match(&s,"inity"))
    1231                             ++s;
    1232                         word0(&rv) = 0x7ff00000;
    1233                         word1(&rv) = 0;
    1234                         goto ret;
    1235                     }
    1236                     break;
    1237                 case 'n':
    1238                 case 'N':
    1239                     if (match(&s, "an")) {
    1240                         word0(&rv) = NAN_WORD0;
    1241                         word1(&rv) = NAN_WORD1;
     1240            switch (c) {
     1241            case 'i':
     1242            case 'I':
     1243                if (match(&s, "nf")) {
     1244                    --s;
     1245                    if (!match(&s, "inity"))
     1246                        ++s;
     1247                    word0(&rv) = 0x7ff00000;
     1248                    word1(&rv) = 0;
     1249                    goto ret;
     1250                }
     1251                break;
     1252            case 'n':
     1253            case 'N':
     1254                if (match(&s, "an")) {
     1255                    word0(&rv) = NAN_WORD0;
     1256                    word1(&rv) = NAN_WORD1;
    12421257#ifndef No_Hex_NaN
    1243                         if (*s == '(') /*)*/
    1244                             hexnan(&rv, &s);
    1245 #endif
    1246                         goto ret;
    1247                     }
     1258                    if (*s == '(') /*)*/
     1259                        hexnan(&rv, &s);
     1260#endif
     1261                    goto ret;
     1262                }
    12481263            }
    12491264#endif /* INFNAN_CHECK */
     
    14991514            lshift(delta, Log2P);
    15001515            if (cmp(delta, bs) > 0)
    1501                 goto drop_down;
     1516                goto dropDown;
    15021517            break;
    15031518        }
    1504         if (i == 0) {
     1519        if (!i) {
    15051520            /* exactly half-way between */
    15061521            if (dsign) {
     
    15211536                }
    15221537            } else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {
    1523 drop_down:
     1538dropDown:
    15241539                /* boundary case -- decrement exponent */
    15251540#ifdef Sudden_Underflow /*{{*/
     
    15931608#ifdef Check_FLT_ROUNDS
    15941609            switch (Rounding) {
    1595                 case 2: /* towards +infinity */
    1596                     aadj1 -= 0.5;
    1597                     break;
    1598                 case 0: /* towards 0 */
    1599                 case 3: /* towards -infinity */
    1600                     aadj1 += 0.5;
    1601             }
    1602 #else
    1603             if (Flt_Rounds == 0)
     1610            case 2: /* towards +infinity */
     1611                aadj1 -= 0.5;
     1612                break;
     1613            case 0: /* towards 0 */
     1614            case 3: /* towards -infinity */
     1615                aadj1 += 0.5;
     1616            }
     1617#else
     1618            if (!Flt_Rounds)
    16041619                aadj1 += 0.5;
    16051620#endif /*Check_FLT_ROUNDS*/
     
    16201635                word1(&rv) = Big1;
    16211636                goto cont;
    1622             } else
    1623                 word0(&rv) += P * Exp_msk1;
     1637            }
     1638            word0(&rv) += P * Exp_msk1;
    16241639        } else {
    16251640#ifdef Avoid_Underflow
     
    16441659                adj.d = aadj1 * ulp(&rv);
    16451660                dval(&rv) += adj.d;
    1646                 if ((word0(&rv) & Exp_mask) <= P * Exp_msk1)
    1647                 {
     1661                if ((word0(&rv) & Exp_mask) <= P * Exp_msk1) {
    16481662                    if (word0(&rv0) == Tiny0 && word1(&rv0) == Tiny1)
    16491663                        goto undfl;
     
    16521666                    goto cont;
    16531667                }
    1654                 else
    1655                     word0(&rv) -= P * Exp_msk1;
     1668                word0(&rv) -= P * Exp_msk1;
    16561669            } else {
    16571670                adj.d = aadj1 * ulp(&rv);
     
    16941707#endif
    16951708cont:
    1696         ;
     1709        {}
    16971710    }
    16981711#ifdef SET_INEXACT
     
    17131726#ifndef NO_ERRNO
    17141727        /* try to avoid the bug of testing an 8087 register value */
    1715         if (word0(&rv) == 0 && word1(&rv) == 0)
     1728        if (!word0(&rv) && !word1(&rv))
    17161729            errno = ERANGE;
    17171730#endif
     
    17341747{
    17351748    size_t n;
    1736     uint32_t *bx, *bxe, q, *sx, *sxe;
     1749    uint32_t* bx;
     1750    uint32_t* bxe;
     1751    uint32_t q;
     1752    uint32_t* sx;
     1753    uint32_t* sxe;
    17371754#ifdef USE_LONG_LONG
    17381755    unsigned long long borrow, carry, y, ys;
     
    17761793            z = (*bx >> 16) - (zs & 0xffff) - borrow;
    17771794            borrow = (z & 0x10000) >> 16;
    1778             Storeinc(bx, z, y);
     1795            bx = storeInc(bx, z, y);
    17791796#else
    17801797            ys = *sx++ * q + carry;
     
    18161833            z = (*bx >> 16) - (zs & 0xffff) - borrow;
    18171834            borrow = (z & 0x10000) >> 16;
    1818             Storeinc(bx, z, y);
     1835            bx = storeInc(bx, z, y);
    18191836#else
    18201837            ys = *sx++ + carry;
     
    18931910    U d2, eps, u;
    18941911    double ds;
    1895     char *s, *s0;
     1912    char* s;
     1913    char* s0;
    18961914#ifdef SET_INEXACT
    18971915    int inexact, oldinexact;
     
    19061924        *sign = 0;
    19071925
    1908     if ((word0(&u) & Exp_mask) == Exp_mask)
    1909     {
     1926    if ((word0(&u) & Exp_mask) == Exp_mask) {
    19101927        /* Infinity or NaN */
    19111928        *decpt = 9999;
     
    20602077        if (k_check && dval(&u) < 1. && ilim > 0) {
    20612078            if (ilim1 <= 0)
    2062                 goto fast_failed;
     2079                goto fastFailed;
    20632080            ilim = ilim1;
    20642081            k--;
     
    20682085        dval(&eps) = (ieps * dval(&u)) + 7.;
    20692086        word0(&eps) -= (P - 1) * Exp_msk1;
    2070         if (ilim == 0) {
     2087        if (!ilim) {
    20712088            S.clear();
    20722089            mhi.clear();
    20732090            dval(&u) -= 5.;
    20742091            if (dval(&u) > dval(&eps))
    2075                 goto one_digit;
     2092                goto oneDigit;
    20762093            if (dval(&u) < -dval(&eps))
    2077                 goto no_digits;
    2078             goto fast_failed;
     2094                goto noDigits;
     2095            goto fastFailed;
    20792096        }
    20802097#ifndef No_leftright
     
    20912108                    goto ret;
    20922109                if (1. - dval(&u) < dval(&eps))
    2093                     goto bump_up;
     2110                    goto bumpUp;
    20942111                if (++i >= ilim)
    20952112                    break;
     
    21082125                if (i == ilim) {
    21092126                    if (dval(&u) > 0.5 + dval(&eps))
    2110                         goto bump_up;
    2111                     else if (dval(&u) < 0.5 - dval(&eps)) {
     2127                        goto bumpUp;
     2128                    if (dval(&u) < 0.5 - dval(&eps)) {
    21122129                        while (*--s == '0') { }
    21132130                        s++;
     
    21202137        }
    21212138#endif
    2122 fast_failed:
     2139fastFailed:
    21232140        s = s0;
    21242141        dval(&u) = dval(&d2);
     
    21362153            mhi.clear();
    21372154            if (ilim < 0 || dval(&u) <= 5 * ds)
    2138                 goto no_digits;
    2139             goto one_digit;
     2155                goto noDigits;
     2156            goto oneDigit;
    21402157        }
    21412158        for (i = 1;; i++, dval(&u) *= 10.) {
     
    21592176                dval(&u) += dval(&u);
    21602177                if (dval(&u) > ds || (dval(&u) == ds && (L & 1))) {
    2161 bump_up:
     2178bumpUp:
    21622179                    while (*--s == '9')
    21632180                        if (s == s0) {
     
    22532270        lshift(S, s2);
    22542271    if (k_check) {
    2255         if (cmp(b,S) < 0) {
     2272        if (cmp(b, S) < 0) {
    22562273            k--;
    22572274            multadd(b, 10, 0);    /* we botched the k estimate */
     
    22772294
    22782295        for (i = 1;;i++) {
    2279             dig = quorem(b,S) + '0';
     2296            dig = quorem(b, S) + '0';
    22802297            /* Do we yet have the shortest decimal string
    22812298             * that will round to d?
     
    22842301            diff(delta, S, mhi);
    22852302            j1 = delta.sign ? 1 : cmp(b, delta);
    2286             if (j1 == 0 && !(word1(&u) & 1)) {
     2303            if (!j1 && !(word1(&u) & 1)) {
    22872304                if (dig == '9')
    2288                     goto round_9_up;
     2305                    goto round9up;
    22892306                if (j > 0)
    22902307                    dig++;
     
    22962313                goto ret;
    22972314            }
    2298             if (j < 0 || (j == 0 && !(word1(&u) & 1))) {
     2315            if (j < 0 || (!j && !(word1(&u) & 1))) {
    22992316                if (!b.words()[0] && b.size() <= 1) {
    23002317#ifdef SET_INEXACT
    23012318                    inexact = 0;
    23022319#endif
    2303                     goto accept_dig;
     2320                    goto acceptDig;
    23042321                }
    23052322                if (j1 > 0) {
    23062323                    lshift(b, 1);
    23072324                    j1 = cmp(b, S);
    2308                     if ((j1 > 0 || (j1 == 0 && (dig & 1))) && dig++ == '9')
    2309                         goto round_9_up;
     2325                    if ((j1 > 0 || (!j1 && (dig & 1))) && dig++ == '9')
     2326                        goto round9up;
    23102327                }
    2311 accept_dig:
     2328acceptDig:
    23122329                *s++ = dig;
    23132330                goto ret;
     
    23152332            if (j1 > 0) {
    23162333                if (dig == '9') { /* possible if i == 1 */
    2317 round_9_up:
     2334round9up:
    23182335                    *s++ = '9';
    23192336                    goto roundoff;
     
    23312348    } else
    23322349        for (i = 1;; i++) {
    2333             *s++ = dig = quorem(b,S) + '0';
     2350            *s++ = dig = quorem(b, S) + '0';
    23342351            if (!b.words()[0] && b.size() <= 1) {
    23352352#ifdef SET_INEXACT
     
    23472364    lshift(b, 1);
    23482365    j = cmp(b, S);
    2349     if (j > 0 || (j == 0 && (dig & 1))) {
     2366    if (j > 0 || (!j && (dig & 1))) {
    23502367roundoff:
    23512368        while (*--s == '9')
     
    23612378    }
    23622379    goto ret;
    2363 no_digits:
     2380noDigits:
    23642381    k = -1 - ndigits;
    23652382    goto ret;
    2366 one_digit:
     2383oneDigit:
    23672384    *s++ = '1';
    23682385    k++;
Note: See TracChangeset for help on using the changeset viewer.