Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
cairo-wideint.c File Reference
#include "cairoint.h"

Go to the source code of this file.

Defines

#define uint32_lo(i)   ((i) & 0xffff)
#define uint32_hi(i)   ((i) >> 16)
#define uint32_carry16   ((1) << 16)
#define _cairo_uint32_rsa(a, n)   ((uint32_t) (((int32_t) (a)) >> (n)))
#define uint64_lo32(i)   ((i).lo)
#define uint64_hi32(i)   ((i).hi)
#define _cairo_msbset64(q)   (q.hi & ((uint32_t) 1 << 31))

Functions

cairo_uint64_t _cairo_uint32_to_uint64 (uint32_t i)
cairo_int64_t _cairo_int32_to_int64 (int32_t i)
static const cairo_uint64_t _cairo_uint32s_to_uint64 (uint32_t h, uint32_t l)
cairo_uint64_t _cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b)
cairo_uint64_t _cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b)
cairo_uint64_t _cairo_uint32x32_64_mul (uint32_t a, uint32_t b)
cairo_int64_t _cairo_int32x32_64_mul (int32_t a, int32_t b)
cairo_uint64_t _cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b)
cairo_uint64_t _cairo_uint64_lsl (cairo_uint64_t a, int shift)
cairo_uint64_t _cairo_uint64_rsl (cairo_uint64_t a, int shift)
cairo_int64_t _cairo_uint64_rsa (cairo_int64_t a, int shift)
int _cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b)
int _cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b)
int _cairo_int64_lt (cairo_int64_t a, cairo_int64_t b)
cairo_uint64_t _cairo_uint64_not (cairo_uint64_t a)
cairo_uint64_t _cairo_uint64_negate (cairo_uint64_t a)
cairo_uquorem64_t _cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den)
cairo_quorem64_t _cairo_int64_divrem (cairo_int64_t num, cairo_int64_t den)
cairo_uint128_t _cairo_uint32_to_uint128 (uint32_t i)
cairo_int128_t _cairo_int32_to_int128 (int32_t i)
cairo_uint128_t _cairo_uint64_to_uint128 (cairo_uint64_t i)
cairo_int128_t _cairo_int64_to_int128 (cairo_int64_t i)
cairo_uint128_t _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b)
cairo_uint128_t _cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b)
static const cairo_uint64_t uint64_lo (cairo_uint64_t i)
static const cairo_uint64_t uint64_hi (cairo_uint64_t i)
static const cairo_uint64_t uint64_shift32 (cairo_uint64_t i)
cairo_uint128_t _cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b)
cairo_int128_t _cairo_int64x64_128_mul (cairo_int64_t a, cairo_int64_t b)
cairo_uint128_t _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b)
cairo_uint128_t _cairo_uint128_lsl (cairo_uint128_t a, int shift)
cairo_uint128_t _cairo_uint128_rsl (cairo_uint128_t a, int shift)
cairo_uint128_t _cairo_uint128_rsa (cairo_int128_t a, int shift)
int _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b)
int _cairo_int128_lt (cairo_int128_t a, cairo_int128_t b)
int _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b)
cairo_uquorem128_t _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den)
cairo_int128_t _cairo_int128_negate (cairo_int128_t a)
cairo_int128_t _cairo_int128_not (cairo_int128_t a)
cairo_quorem128_t _cairo_int128_divrem (cairo_int128_t num, cairo_int128_t den)

Variables

static const cairo_uint64_t uint64_carry32 = { 0, 1 }

Define Documentation

#define _cairo_msbset64 (   q)    (q.hi & ((uint32_t) 1 << 31))

Definition at line 583 of file cairo-wideint.c.

#define _cairo_uint32_rsa (   a,
  n 
)    ((uint32_t) (((int32_t) (a)) >> (n)))

Definition at line 197 of file cairo-wideint.c.

#define uint32_carry16   ((1) << 16)

Definition at line 111 of file cairo-wideint.c.

#define uint32_hi (   i)    ((i) >> 16)

Definition at line 110 of file cairo-wideint.c.

#define uint32_lo (   i)    ((i) & 0xffff)

Definition at line 109 of file cairo-wideint.c.

#define uint64_hi32 (   i)    ((i).hi)

Definition at line 409 of file cairo-wideint.c.

#define uint64_lo32 (   i)    ((i).lo)

Definition at line 408 of file cairo-wideint.c.


Function Documentation

Definition at line 638 of file cairo-wideint.c.

{
    int                     num_neg = _cairo_int128_negative (num);
    int                     den_neg = _cairo_int128_negative (den);
    cairo_uquorem128_t      uqr;
    cairo_quorem128_t       qr;

    if (num_neg)
       num = _cairo_int128_negate (num);
    if (den_neg)
       den = _cairo_int128_negate (den);
    uqr = _cairo_uint128_divrem (num, den);
    if (num_neg)
       qr.rem = _cairo_int128_negate (uqr.rem);
    else
       qr.rem = uqr.rem;
    if (num_neg != den_neg)
       qr.quo = _cairo_int128_negate (uqr.quo);
    else
       qr.quo = uqr.quo;
    return qr;
}

Here is the call graph for this function:

Definition at line 564 of file cairo-wideint.c.

{
    if (_cairo_int128_negative (a) && !_cairo_int128_negative (b))
       return 1;
    if (!_cairo_int128_negative (a) && _cairo_int128_negative (b))
       return 0;
    return _cairo_uint128_lt (a, b);
}

Here is the call graph for this function:

Definition at line 620 of file cairo-wideint.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 628 of file cairo-wideint.c.

{
    a.lo = _cairo_uint64_not (a.lo);
    a.hi = _cairo_uint64_not (a.hi);
    return a;
}

Here is the call graph for this function:

Definition at line 344 of file cairo-wideint.c.

{
    cairo_int128_t   q;

    q.lo = _cairo_int32_to_int64 (i);
    q.hi = _cairo_int32_to_int64 (i < 0 ? -1 : 0);
    return q;
}

Here is the call graph for this function:

Definition at line 66 of file cairo-wideint.c.

{
    cairo_uint64_t   q;

    q.lo = i;
    q.hi = i < 0 ? -1 : 0;
    return q;
}

Here is the caller graph for this function:

Definition at line 142 of file cairo-wideint.c.

{
    cairo_int64_t s;
    s = _cairo_uint32x32_64_mul ((uint32_t) a, (uint32_t) b);
    if (a < 0)
       s.hi -= b;
    if (b < 0)
       s.hi -= a;
    return s;
}

Here is the call graph for this function:

Definition at line 296 of file cairo-wideint.c.

{
    int                     num_neg = _cairo_int64_negative (num);
    int                     den_neg = _cairo_int64_negative (den);
    cairo_uquorem64_t       uqr;
    cairo_quorem64_t qr;

    if (num_neg)
       num = _cairo_int64_negate (num);
    if (den_neg)
       den = _cairo_int64_negate (den);
    uqr = _cairo_uint64_divrem (num, den);
    if (num_neg)
       qr.rem = _cairo_int64_negate (uqr.rem);
    else
       qr.rem = uqr.rem;
    if (num_neg != den_neg)
       qr.quo = (cairo_int64_t) _cairo_int64_negate (uqr.quo);
    else
       qr.quo = (cairo_int64_t) uqr.quo;
    return qr;
}

Here is the call graph for this function:

Definition at line 230 of file cairo-wideint.c.

{
    if (_cairo_int64_negative (a) && !_cairo_int64_negative (b))
       return 1;
    if (!_cairo_int64_negative (a) && _cairo_int64_negative (b))
       return 0;
    return _cairo_uint64_lt (a, b);
}

Here is the call graph for this function:

Definition at line 364 of file cairo-wideint.c.

{
    cairo_int128_t   q;

    q.lo = i;
    q.hi = _cairo_int32_to_int64 (_cairo_int64_negative(i) ? -1 : 0);
    return q;
}

Here is the call graph for this function:

Definition at line 474 of file cairo-wideint.c.

Here is the call graph for this function:

Definition at line 374 of file cairo-wideint.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 587 of file cairo-wideint.c.

{
    cairo_uquorem128_t      qr;
    cairo_uint128_t  bit;
    cairo_uint128_t  quo;
    
    bit = _cairo_uint32_to_uint128 (1);
    
    /* normalize to make den >= num, but not overflow */
    while (_cairo_uint128_lt (den, num) && !_cairo_msbset64(den.hi))
    {
       bit = _cairo_uint128_lsl (bit, 1);
       den = _cairo_uint128_lsl (den, 1);
    }
    quo = _cairo_uint32_to_uint128 (0);
    
    /* generate quotient, one bit at a time */
    while (_cairo_uint128_ne (bit, _cairo_uint32_to_uint128(0)))
    {
       if (_cairo_uint128_le (den, num))
       {
           num = _cairo_uint128_sub (num, den);
           quo = _cairo_uint128_add (quo, bit);
       }
       bit = _cairo_uint128_rsl (bit, 1);
       den = _cairo_uint128_rsl (den, 1);
    }
    qr.quo = quo;
    qr.rem = num;
    return qr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 574 of file cairo-wideint.c.

{
    return (_cairo_uint64_eq (a.hi, b.hi) &&
           _cairo_uint64_eq (a.lo, b.lo));
}

Here is the call graph for this function:

Definition at line 502 of file cairo-wideint.c.

{
    if (shift >= 64)
    {
       a.hi = a.lo;
       a.lo = _cairo_uint32_to_uint64 (0);
       shift -= 64;
    }
    if (shift)
    {
       a.hi = _cairo_uint64_add (_cairo_uint64_lsl (a.hi, shift),
                                _cairo_uint64_rsl (a.lo, (64 - shift)));
       a.lo = _cairo_uint64_lsl (a.lo, shift);
    }
    return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 556 of file cairo-wideint.c.

{
    return (_cairo_uint64_lt (a.hi, b.hi) ||
           (_cairo_uint64_eq (a.hi, b.hi) &&
            _cairo_uint64_lt (a.lo, b.lo)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 489 of file cairo-wideint.c.

Here is the call graph for this function:

Definition at line 538 of file cairo-wideint.c.

{
    if (shift >= 64)
    {
       a.lo = a.hi;
       a.hi = _cairo_uint64_rsa (a.hi, 64-1);
       shift -= 64;
    }
    if (shift)
    {
       a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift),
                                _cairo_uint64_lsl (a.hi, (64 - shift)));
       a.hi = _cairo_uint64_rsa (a.hi, shift);
    }
    return a;
}

Here is the call graph for this function:

Definition at line 520 of file cairo-wideint.c.

{
    if (shift >= 64)
    {
       a.lo = a.hi;
       a.hi = _cairo_uint32_to_uint64 (0);
       shift -= 64;
    }
    if (shift)
    {
       a.lo = _cairo_uint64_add (_cairo_uint64_rsl (a.lo, shift),
                                _cairo_uint64_lsl (a.hi, (64 - shift)));
       a.hi = _cairo_uint64_rsl (a.hi, shift);
    }
    return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 386 of file cairo-wideint.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 334 of file cairo-wideint.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 56 of file cairo-wideint.c.

{
    cairo_uint64_t   q;

    q.lo = i;
    q.hi = 0;
    return q;
}

Here is the caller graph for this function:

Definition at line 76 of file cairo-wideint.c.

{
    cairo_uint64_t   q;

    q.lo = l;
    q.hi = h;
    return q;
}

Definition at line 114 of file cairo-wideint.c.

{
    cairo_uint64_t  s;
    
    uint16_t  ah, al, bh, bl;
    uint32_t  r0, r1, r2, r3;

    al = uint32_lo (a);
    ah = uint32_hi (a);
    bl = uint32_lo (b);
    bh = uint32_hi (b);

    r0 = (uint32_t) al * bl;
    r1 = (uint32_t) al * bh;
    r2 = (uint32_t) ah * bl;
    r3 = (uint32_t) ah * bh;

    r1 += uint32_hi(r0);    /* no carry possible */
    r1 += r2;            /* but this can carry */
    if (r1 < r2)         /* check */
       r3 += uint32_carry16;

    s.hi = r3 + uint32_hi(r1);
    s.lo = (uint32_lo (r1) << 16) + uint32_lo (r0);
    return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 86 of file cairo-wideint.c.

{
    cairo_uint64_t   s;

    s.hi = a.hi + b.hi;
    s.lo = a.lo + b.lo;
    if (s.lo < a.lo)
       s.hi++;
    return s;
}

Here is the caller graph for this function:

Definition at line 261 of file cairo-wideint.c.

{
    cairo_uquorem64_t       qr;
    cairo_uint64_t   bit;
    cairo_uint64_t   quo;
    
    bit = _cairo_uint32_to_uint64 (1);
    
    /* normalize to make den >= num, but not overflow */
    while (_cairo_uint64_lt (den, num) && (den.hi & 0x80000000) == 0)
    {
       bit = _cairo_uint64_lsl (bit, 1);
       den = _cairo_uint64_lsl (den, 1);
    }
    quo = _cairo_uint32_to_uint64 (0);
    
    /* generate quotient, one bit at a time */
    while (bit.hi | bit.lo)
    {
       if (_cairo_uint64_le (den, num))
       {
           num = _cairo_uint64_sub (num, den);
           quo = _cairo_uint64_add (quo, bit);
       }
       bit = _cairo_uint64_rsl (bit, 1);
       den = _cairo_uint64_rsl (den, 1);
    }
    qr.quo = quo;
    qr.rem = num;
    return qr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 224 of file cairo-wideint.c.

{
    return a.hi == b.hi && a.lo == b.lo;
}

Here is the caller graph for this function:

Definition at line 164 of file cairo-wideint.c.

{
    if (shift >= 32)
    {
       a.hi = a.lo;
       a.lo = 0;
       shift -= 32;
    }
    if (shift)
    {
       a.hi = a.hi << shift | a.lo >> (32 - shift);
       a.lo = a.lo << shift;
    }
    return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 217 of file cairo-wideint.c.

{
    return (a.hi < b.hi ||
           (a.hi == b.hi && a.lo < b.lo));
}

Here is the caller graph for this function:

Definition at line 154 of file cairo-wideint.c.

{
    cairo_uint64_t   s;
    
    s = _cairo_uint32x32_64_mul (a.lo, b.lo);
    s.hi += a.lo * b.hi + a.hi * b.lo;
    return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 248 of file cairo-wideint.c.

{
    a.lo = ~a.lo;
    a.hi = ~a.hi;
    if (++a.lo == 0)
       ++a.hi;
    return a;
}

Definition at line 240 of file cairo-wideint.c.

{
    a.lo = ~a.lo;
    a.hi = ~a.hi;
    return a;
}

Here is the caller graph for this function:

Definition at line 200 of file cairo-wideint.c.

{
    if (shift >= 32)
    {
       a.lo = a.hi;
       a.hi = _cairo_uint32_rsa (a.hi, 31);
       shift -= 32;
    }
    if (shift)
    {
       a.lo = a.lo >> shift | a.hi << (32 - shift);
       a.hi = _cairo_uint32_rsa (a.hi, shift);
    }
    return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 181 of file cairo-wideint.c.

{
    if (shift >= 32)
    {
       a.lo = a.hi;
       a.hi = 0;
       shift -= 32;
    }
    if (shift)
    {
       a.lo = a.lo >> shift | a.hi << (32 - shift);
       a.hi = a.hi >> shift;
    }
    return a;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file cairo-wideint.c.

{
    cairo_uint64_t   s;

    s.hi = a.hi - b.hi;
    s.lo = a.lo - b.lo;
    if (s.lo > a.lo)
       s.hi--;
    return s;
}

Here is the caller graph for this function:

Definition at line 354 of file cairo-wideint.c.

{
    cairo_uint128_t  q;

    q.lo = i;
    q.hi = _cairo_uint32_to_uint64 (0);
    return q;
}

Here is the call graph for this function:

Definition at line 446 of file cairo-wideint.c.

{
    cairo_uint128_t  s;
    uint32_t         ah, al, bh, bl;
    cairo_uint64_t   r0, r1, r2, r3;

    al = uint64_lo32 (a);
    ah = uint64_hi32 (a);
    bl = uint64_lo32 (b);
    bh = uint64_hi32 (b);

    r0 = _cairo_uint32x32_64_mul (al, bl);
    r1 = _cairo_uint32x32_64_mul (al, bh);
    r2 = _cairo_uint32x32_64_mul (ah, bl);
    r3 = _cairo_uint32x32_64_mul (ah, bh);

    r1 = _cairo_uint64_add (r1, uint64_hi (r0));    /* no carry possible */
    r1 = _cairo_uint64_add (r1, r2);                 /* but this can carry */
    if (_cairo_uint64_lt (r1, r2))            /* check */
       r3 = _cairo_uint64_add (r3, uint64_carry32);

    s.hi = _cairo_uint64_add (r3, uint64_hi(r1));
    s.lo = _cairo_uint64_add (uint64_shift32 (r1),
                            uint64_lo (r0));
    return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const cairo_uint64_t uint64_hi ( cairo_uint64_t  i) [static]

Definition at line 422 of file cairo-wideint.c.

{
    cairo_uint64_t  s;

    s.lo = i.hi;
    s.hi = 0;
    return s;
}

Here is the caller graph for this function:

static const cairo_uint64_t uint64_lo ( cairo_uint64_t  i) [static]

Definition at line 412 of file cairo-wideint.c.

{
    cairo_uint64_t  s;

    s.lo = i.lo;
    s.hi = 0;
    return s;
}

Here is the caller graph for this function:

Definition at line 432 of file cairo-wideint.c.

{
    cairo_uint64_t  s;

    s.lo = 0;
    s.hi = i.lo;
    return s;
}

Here is the caller graph for this function:


Variable Documentation

const cairo_uint64_t uint64_carry32 = { 0, 1 } [static]

Definition at line 441 of file cairo-wideint.c.