Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
jslong.h File Reference
#include "jstypes.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define JSLL_MAXINT   JSLL_MaxInt()
#define JSLL_MININT   JSLL_MinInt()
#define JSLL_ZERO   JSLL_Zero()
#define JSLL_INIT(hi, lo)   {JS_INT32(hi), JS_INT32(lo)}
#define JSLL_IS_ZERO(a)   (((a).hi == 0) && ((a).lo == 0))
#define JSLL_EQ(a, b)   (((a).hi == (b).hi) && ((a).lo == (b).lo))
#define JSLL_NE(a, b)   (((a).hi != (b).hi) || ((a).lo != (b).lo))
#define JSLL_GE_ZERO(a)   (((a).hi >> 31) == 0)
#define JSLL_CMP(a, op, b)   JSLL_REAL_CMP(a, op, b)
#define JSLL_UCMP(a, op, b)   JSLL_REAL_UCMP(a, op, b)
#define JSLL_REAL_CMP(a, op, b)
#define JSLL_REAL_UCMP(a, op, b)
#define JSLL_AND(r, a, b)
#define JSLL_OR(r, a, b)
#define JSLL_XOR(r, a, b)
#define JSLL_OR2(r, a)
#define JSLL_NOT(r, a)
#define JSLL_NEG(r, a)
#define JSLL_ADD(r, a, b)
#define JSLL_SUB(r, a, b)
#define JSLL_MUL(r, a, b)
#define jslo16(a)   ((a) & JS_BITMASK(16))
#define jshi16(a)   ((a) >> 16)
#define JSLL_MUL32(r, a, b)
#define JSLL_UDIVMOD(qp, rp, a, b)   jsll_udivmod(qp, rp, a, b)
#define JSLL_DIV(r, a, b)
#define JSLL_MOD(r, a, b)
#define JSLL_SHL(r, a, b)
#define JSLL_ISHL(r, a, b)
#define JSLL_SHR(r, a, b)
#define JSLL_USHR(r, a, b)
#define JSLL_L2I(i, l)   ((i) = (l).lo)
#define JSLL_L2UI(ui, l)   ((ui) = (l).lo)
#define JSLL_L2F(f, l)   { double _d; JSLL_L2D(_d, l); (f) = (JSFloat64)_d; }
#define JSLL_L2D(d, l)
#define JSLL_I2L(l, i)   { JSInt32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }
#define JSLL_UI2L(l, ui)   ((l).lo = (ui), (l).hi = 0)
#define JSLL_F2L(l, f)   { double _d = (double)f; JSLL_D2L(l, _d); }
#define JSLL_D2L(l, d)

Functions

JS_BEGIN_EXTERN_C JS_PUBLIC_API (JSInt64) JSLL_MaxInt(void)
 JS_PUBLIC_API (void) jsll_udivmod(JSUint64 *qp

Variables

JSUint64rp
JSUint64 JSUint64 a
JSUint64 JSUint64 JSUint64 b

Define Documentation

#define jshi16 (   a)    ((a) >> 16)

Definition at line 259 of file jslong.h.

#define JSLL_ADD (   r,
  a,
  b 
)
Value:
{ \
    JSInt64 _a, _b; \
    _a = a; _b = b; \
    (r).lo = _a.lo + _b.lo; \
    (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
}

Definition at line 237 of file jslong.h.

#define JSLL_AND (   r,
  a,
  b 
)
Value:
((r).lo = (a).lo & (b).lo, \
                                 (r).hi = (a).hi & (b).hi)

Definition at line 224 of file jslong.h.

#define JSLL_CMP (   a,
  op,
  b 
)    JSLL_REAL_CMP(a, op, b)

Definition at line 215 of file jslong.h.

#define JSLL_D2L (   l,
  d 
)
Value:
{ \
    int _negative; \
    double _absval, _d_hi; \
    JSInt64 _lo_d; \
 \
    _negative = ((d) < 0); \
    _absval = _negative ? -(d) : (d); \
 \
    (l).hi = _absval / 4.294967296e9; \
    (l).lo = 0; \
    JSLL_L2D(_d_hi, l); \
    _absval -= _d_hi; \
    _lo_d.hi = 0; \
    if (_absval < 0) { \
    _lo_d.lo = -_absval; \
    JSLL_SUB(l, l, _lo_d); \
    } else { \
    _lo_d.lo = _absval; \
    JSLL_ADD(l, l, _lo_d); \
    } \
 \
    if (_negative) \
    JSLL_NEG(l, l); \
}

Definition at line 408 of file jslong.h.

#define JSLL_DIV (   r,
  a,
  b 
)
Value:
{ \
    JSInt64 _a, _b; \
    JSUint32 _negative = (JSInt32)(a).hi < 0; \
    if (_negative) { \
    JSLL_NEG(_a, a); \
    } else { \
    _a = a; \
    } \
    if ((JSInt32)(b).hi < 0) { \
    _negative ^= 1; \
    JSLL_NEG(_b, b); \
    } else { \
    _b = b; \
    } \
    JSLL_UDIVMOD(&(r), 0, _a, _b); \
    if (_negative) \
    JSLL_NEG(r, r); \
}

Definition at line 281 of file jslong.h.

#define JSLL_EQ (   a,
  b 
)    (((a).hi == (b).hi) && ((a).lo == (b).lo))

Definition at line 207 of file jslong.h.

#define JSLL_F2L (   l,
  f 
)    { double _d = (double)f; JSLL_D2L(l, _d); }

Definition at line 406 of file jslong.h.

#define JSLL_GE_ZERO (   a)    (((a).hi >> 31) == 0)

Definition at line 209 of file jslong.h.

#define JSLL_I2L (   l,
  i 
)    { JSInt32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }

Definition at line 404 of file jslong.h.

#define JSLL_INIT (   hi,
  lo 
)    {JS_INT32(hi), JS_INT32(lo)}

Definition at line 203 of file jslong.h.

#define JSLL_IS_ZERO (   a)    (((a).hi == 0) && ((a).lo == 0))

Definition at line 206 of file jslong.h.

#define JSLL_ISHL (   r,
  a,
  b 
)
Value:
{ \
    if (b) { \
    JSInt64 _a; \
    _a.lo = (a); \
    _a.hi = 0; \
        if ((b) < 32) { \
        (r).lo = (a) << ((b) & 31); \
        (r).hi = ((a) >> (32 - (b))); \
    } else { \
        (r).lo = 0; \
        (r).hi = (a) << ((b) & 31); \
    } \
    } else { \
    (r).lo = (a); \
    (r).hi = 0; \
    } \
}

Definition at line 335 of file jslong.h.

#define JSLL_L2D (   d,
  l 
)
Value:
{ \
    int _negative; \
    JSInt64 _absval; \
 \
    _negative = (l).hi >> 31; \
    if (_negative) { \
    JSLL_NEG(_absval, l); \
    } else { \
    _absval = l; \
    } \
    (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
    if (_negative) \
    (d) = -(d); \
}

Definition at line 389 of file jslong.h.

#define JSLL_L2F (   f,
  l 
)    { double _d; JSLL_L2D(_d, l); (f) = (JSFloat64)_d; }

Definition at line 387 of file jslong.h.

#define JSLL_L2I (   i,
  l 
)    ((i) = (l).lo)

Definition at line 385 of file jslong.h.

#define JSLL_L2UI (   ui,
  l 
)    ((ui) = (l).lo)

Definition at line 386 of file jslong.h.

#define JSLL_MAXINT   JSLL_MaxInt()

Definition at line 75 of file jslong.h.

#define JSLL_MININT   JSLL_MinInt()

Definition at line 76 of file jslong.h.

#define JSLL_MOD (   r,
  a,
  b 
)
Value:
{ \
    JSInt64 _a, _b; \
    JSUint32 _negative = (JSInt32)(a).hi < 0; \
    if (_negative) { \
    JSLL_NEG(_a, a); \
    } else { \
    _a = a; \
    } \
    if ((JSInt32)(b).hi < 0) { \
    JSLL_NEG(_b, b); \
    } else { \
    _b = b; \
    } \
    JSLL_UDIVMOD(0, &(r), _a, _b); \
    if (_negative) \
    JSLL_NEG(r, r); \
}

Definition at line 300 of file jslong.h.

#define JSLL_MUL (   r,
  a,
  b 
)
Value:
{ \
    JSInt64 _a, _b; \
    _a = a; _b = b; \
    JSLL_MUL32(r, _a.lo, _b.lo); \
    (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
}

Definition at line 251 of file jslong.h.

#define JSLL_MUL32 (   r,
  a,
  b 
)
Value:
{ \
     JSUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
     _a1 = jshi16(a), _a0 = jslo16(a); \
     _b1 = jshi16(b), _b0 = jslo16(b); \
     _y0 = _a0 * _b0; \
     _y1 = _a0 * _b1; \
     _y2 = _a1 * _b0; \
     _y3 = _a1 * _b1; \
     _y1 += jshi16(_y0);                         /* can't carry */ \
     _y1 += _y2;                                /* might carry */ \
     if (_y1 < _y2)    \
        _y3 += (JSUint32)(JS_BIT(16));  /* propagate */ \
     (r).lo = (jslo16(_y1) << 16) + jslo16(_y0); \
     (r).hi = _y3 + jshi16(_y1); \
}

Definition at line 261 of file jslong.h.

#define JSLL_NE (   a,
  b 
)    (((a).hi != (b).hi) || ((a).lo != (b).lo))

Definition at line 208 of file jslong.h.

#define JSLL_NEG (   r,
  a 
)
Value:
((r).lo = -(JSInt32)(a).lo, \
                                 (r).hi = -(JSInt32)(a).hi - ((r).lo != 0))

Definition at line 235 of file jslong.h.

#define JSLL_NOT (   r,
  a 
)
Value:
((r).lo = ~(a).lo, \
                                 (r).hi = ~(a).hi)

Definition at line 232 of file jslong.h.

#define JSLL_OR (   r,
  a,
  b 
)
Value:
((r).lo = (a).lo | (b).lo, \
                                 (r).hi = (a).hi | (b).hi)

Definition at line 226 of file jslong.h.

#define JSLL_OR2 (   r,
  a 
)
Value:
((r).lo = (r).lo | (a).lo, \
                                 (r).hi = (r).hi | (a).hi)

Definition at line 230 of file jslong.h.

#define JSLL_REAL_CMP (   a,
  op,
  b 
)
Value:
(((JSInt32)(a).hi op (JSInt32)(b).hi) || \
                                 (((a).hi == (b).hi) && ((a).lo op (b).lo)))

Definition at line 219 of file jslong.h.

#define JSLL_REAL_UCMP (   a,
  op,
  b 
)
Value:
(((a).hi op (b).hi) || \
                                 (((a).hi == (b).hi) && ((a).lo op (b).lo)))

Definition at line 221 of file jslong.h.

#define JSLL_SHL (   r,
  a,
  b 
)
Value:
{ \
    if (b) { \
    JSInt64 _a; \
        _a = a; \
        if ((b) < 32) { \
        (r).lo = _a.lo << ((b) & 31); \
        (r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
    } else { \
        (r).lo = 0; \
        (r).hi = _a.lo << ((b) & 31); \
    } \
    } else { \
    (r) = (a); \
    } \
}

Definition at line 318 of file jslong.h.

#define JSLL_SHR (   r,
  a,
  b 
)
Value:
{ \
    if (b) { \
    JSInt64 _a; \
        _a = a; \
    if ((b) < 32) { \
        (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
        (r).hi = (JSInt32)_a.hi >> ((b) & 31); \
    } else { \
        (r).lo = (JSInt32)_a.hi >> ((b) & 31); \
        (r).hi = (JSInt32)_a.hi >> 31; \
    } \
    } else { \
    (r) = (a); \
    } \
}

Definition at line 353 of file jslong.h.

#define JSLL_SUB (   r,
  a,
  b 
)
Value:
{ \
    JSInt64 _a, _b; \
    _a = a; _b = b; \
    (r).lo = _a.lo - _b.lo; \
    (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
}

Definition at line 244 of file jslong.h.

#define JSLL_UCMP (   a,
  op,
  b 
)    JSLL_REAL_UCMP(a, op, b)

Definition at line 216 of file jslong.h.

#define JSLL_UDIVMOD (   qp,
  rp,
  a,
  b 
)    jsll_udivmod(qp, rp, a, b)

Definition at line 277 of file jslong.h.

#define JSLL_UI2L (   l,
  ui 
)    ((l).lo = (ui), (l).hi = 0)

Definition at line 405 of file jslong.h.

#define JSLL_USHR (   r,
  a,
  b 
)
Value:
{ \
    if (b) { \
    JSInt64 _a; \
        _a = a; \
    if ((b) < 32) { \
        (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
        (r).hi = _a.hi >> ((b) & 31); \
    } else { \
        (r).lo = _a.hi >> ((b) & 31); \
        (r).hi = 0; \
    } \
    } else { \
    (r) = (a); \
    } \
}

Definition at line 369 of file jslong.h.

#define JSLL_XOR (   r,
  a,
  b 
)
Value:
((r).lo = (a).lo ^ (b).lo, \
                                 (r).hi = (a).hi ^ (b).hi)

Definition at line 228 of file jslong.h.

#define JSLL_ZERO   JSLL_Zero()

Definition at line 77 of file jslong.h.

#define jslo16 (   a)    ((a) & JS_BITMASK(16))

Definition at line 258 of file jslong.h.


Function Documentation

Definition at line 55 of file jslong.c.

{ return ll_zero; }

Definition at line 118 of file jslong.c.

{
    JSUint32 n0, n1, n2;
    JSUint32 q0, q1;
    JSUint32 rsh, lsh;

    n0 = a.lo;
    n1 = a.hi;

    if (b.hi == 0) {
        if (b.lo > n1) {
            /* (0 q0) = (n1 n0) / (0 D0) */

            lsh = CountLeadingZeros(b.lo);

            if (lsh) {
                /*
                 * Normalize, i.e. make the most significant bit of the
                 * denominator be set.
                 */
                b.lo = b.lo << lsh;
                n1 = (n1 << lsh) | (n0 >> (32 - lsh));
                n0 = n0 << lsh;
            }

            a.lo = n0, a.hi = n1;
            norm_udivmod32(&q0, &n0, a, b.lo);
            q1 = 0;

            /* remainder is in n0 >> lsh */
        } else {
            /* (q1 q0) = (n1 n0) / (0 d0) */

            if (b.lo == 0)              /* user wants to divide by zero! */
                b.lo = 1 / b.lo;        /* so go ahead and crash */

            lsh = CountLeadingZeros(b.lo);

            if (lsh == 0) {
                /*
                 * From (n1 >= b.lo)
                 *   && (the most significant bit of b.lo is set),
                 * conclude that
                 *      (the most significant bit of n1 is set)
                 *   && (the leading quotient digit q1 = 1).
                 *
                 * This special case is necessary, not an optimization
                 * (Shifts counts of 32 are undefined).
                 */
                n1 -= b.lo;
                q1 = 1;
            } else {
                /*
                 * Normalize.
                 */
                rsh = 32 - lsh;

                b.lo = b.lo << lsh;
                n2 = n1 >> rsh;
                n1 = (n1 << lsh) | (n0 >> rsh);
                n0 = n0 << lsh;

                a.lo = n1, a.hi = n2;
                norm_udivmod32(&q1, &n1, a, b.lo);
            }

            /* n1 != b.lo... */

            a.lo = n0, a.hi = n1;
            norm_udivmod32(&q0, &n0, a, b.lo);

            /* remainder in n0 >> lsh */
        }

        if (rp) {
            rp->lo = n0 >> lsh;
            rp->hi = 0;
        }
    } else {
        if (b.hi > n1) {
            /* (0 0) = (n1 n0) / (D1 d0) */

            q0 = 0;
            q1 = 0;

            /* remainder in (n1 n0) */
            if (rp) {
                rp->lo = n0;
                rp->hi = n1;
            }
        } else {
            /* (0 q0) = (n1 n0) / (d1 d0) */

            lsh = CountLeadingZeros(b.hi);
            if (lsh == 0) {
                /*
                 * From (n1 >= b.hi)
                 *   && (the most significant bit of b.hi is set),
                 * conclude that
                 *      (the most significant bit of n1 is set)
                 *   && (the quotient digit q0 = 0 or 1).
                 *
                 * This special case is necessary, not an optimization.
                 */

                /*
                 * The condition on the next line takes advantage of that
                 * n1 >= b.hi (true due to control flow).
                 */
                if (n1 > b.hi || n0 >= b.lo) {
                    q0 = 1;
                    a.lo = n0, a.hi = n1;
                    JSLL_SUB(a, a, b);
                } else {
                    q0 = 0;
                }
                q1 = 0;

                if (rp) {
                    rp->lo = n0;
                    rp->hi = n1;
                }
            } else {
                JSInt64 m;

                /*
                 * Normalize.
                 */
                rsh = 32 - lsh;

                b.hi = (b.hi << lsh) | (b.lo >> rsh);
                b.lo = b.lo << lsh;
                n2 = n1 >> rsh;
                n1 = (n1 << lsh) | (n0 >> rsh);
                n0 = n0 << lsh;

                a.lo = n1, a.hi = n2;
                norm_udivmod32(&q0, &n1, a, b.hi);
                JSLL_MUL32(m, q0, b.lo);

                if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
                    q0--;
                    JSLL_SUB(m, m, b);
                }

                q1 = 0;

                /* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
                if (rp) {
                    a.lo = n0, a.hi = n1;
                    JSLL_SUB(a, a, m);
                    rp->lo = (a.hi << rsh) | (a.lo >> lsh);
                    rp->hi = a.hi >> lsh;
                }
            }
        }
    }

    if (qp) {
        qp->lo = q0;
        qp->hi = q1;
    }
}

Variable Documentation

Definition at line 279 of file jslong.h.

Definition at line 279 of file jslong.h.

Definition at line 279 of file jslong.h.