VirtualBox

Changeset 102246 in vbox for trunk


Ignore:
Timestamp:
Nov 22, 2023 10:46:18 AM (15 months ago)
Author:
vboxsync
Message:

libs/xpcom: Remove unused code in nsprpub, bugref:10545

Location:
trunk/src/libs/xpcom18a4/nsprpub/pr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/prlong.h

    r11551 r102246  
    6767**      initializer
    6868***********************************************************************/
    69 #if defined(HAVE_WATCOM_BUG_2)
    70 PRInt64 __pascal __loadds __export
    71     LL_MaxInt(void);
    72 PRInt64 __pascal __loadds __export
    73     LL_MinInt(void);
    74 PRInt64 __pascal __loadds __export
    75     LL_Zero(void);
    76 PRUint64 __pascal __loadds __export
    77     LL_MaxUint(void);
    78 #else
    7969NSPR_API(PRInt64) LL_MaxInt(void);
    8070NSPR_API(PRInt64) LL_MinInt(void);
    8171NSPR_API(PRInt64) LL_Zero(void);
    8272NSPR_API(PRUint64) LL_MaxUint(void);
    83 #endif
    8473
    8574#define LL_MAXINT   LL_MaxInt()
     
    8776#define LL_ZERO     LL_Zero()
    8877#define LL_MAXUINT  LL_MaxUint()
    89 
    90 #if defined(HAVE_LONG_LONG)
    9178
    9279#if PR_BYTES_PER_LONG == 8
     
    207194     *(rp) = ((PRUint64)(a) % (b)))
    208195
    209 #else  /* !HAVE_LONG_LONG */
    210 
    211 #ifdef IS_LITTLE_ENDIAN
    212 #define LL_INIT(hi, lo) {PR_UINT32(lo), PR_UINT32(hi)}
    213 #else
    214 #define LL_INIT(hi, lo) {PR_UINT32(hi), PR_UINT32(lo)}
    215 #endif
    216 
    217 #define LL_IS_ZERO(a)        (((a).hi == 0) && ((a).lo == 0))
    218 #define LL_EQ(a, b)        (((a).hi == (b).hi) && ((a).lo == (b).lo))
    219 #define LL_NE(a, b)        (((a).hi != (b).hi) || ((a).lo != (b).lo))
    220 #define LL_GE_ZERO(a)        (((a).hi >> 31) == 0)
    221 
    222 #define LL_CMP(a, op, b)    (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
    223                  ((PRInt32)(a).hi op (PRInt32)(b).hi))
    224 #define LL_UCMP(a, op, b)    (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
    225                  ((a).hi op (b).hi))
    226 
    227 #define LL_AND(r, a, b)        ((r).lo = (a).lo & (b).lo, \
    228                  (r).hi = (a).hi & (b).hi)
    229 #define LL_OR(r, a, b)        ((r).lo = (a).lo | (b).lo, \
    230                  (r).hi = (a).hi | (b).hi)
    231 #define LL_XOR(r, a, b)        ((r).lo = (a).lo ^ (b).lo, \
    232                  (r).hi = (a).hi ^ (b).hi)
    233 #define LL_OR2(r, a)        ((r).lo = (r).lo | (a).lo, \
    234                  (r).hi = (r).hi | (a).hi)
    235 #define LL_NOT(r, a)        ((r).lo = ~(a).lo, \
    236                  (r).hi = ~(a).hi)
    237 
    238 #define LL_NEG(r, a)        ((r).lo = -(PRInt32)(a).lo, \
    239                  (r).hi = -(PRInt32)(a).hi - ((r).lo != 0))
    240 #define LL_ADD(r, a, b) { \
    241     PRInt64 _a, _b; \
    242     _a = a; _b = b; \
    243     (r).lo = _a.lo + _b.lo; \
    244     (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
    245 }
    246 
    247 #define LL_SUB(r, a, b) { \
    248     PRInt64 _a, _b; \
    249     _a = a; _b = b; \
    250     (r).lo = _a.lo - _b.lo; \
    251     (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
    252 }
    253 
    254 #define LL_MUL(r, a, b) { \
    255     PRInt64 _a, _b; \
    256     _a = a; _b = b; \
    257     LL_MUL32(r, _a.lo, _b.lo); \
    258     (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
    259 }
    260 
    261 #define _lo16(a)        ((a) & PR_BITMASK(16))
    262 #define _hi16(a)        ((a) >> 16)
    263 
    264 #define LL_MUL32(r, a, b) { \
    265      PRUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
    266      _a1 = _hi16(a), _a0 = _lo16(a); \
    267      _b1 = _hi16(b), _b0 = _lo16(b); \
    268      _y0 = _a0 * _b0; \
    269      _y1 = _a0 * _b1; \
    270      _y2 = _a1 * _b0; \
    271      _y3 = _a1 * _b1; \
    272      _y1 += _hi16(_y0);                         /* can't carry */ \
    273      _y1 += _y2;                                /* might carry */ \
    274      if (_y1 < _y2)    \
    275         _y3 += (PRUint32)(PR_BIT(16));  /* propagate */ \
    276      (r).lo = (_lo16(_y1) << 16) + _lo16(_y0); \
    277      (r).hi = _y3 + _hi16(_y1); \
    278 }
    279 
    280 #define LL_UDIVMOD(qp, rp, a, b)    ll_udivmod(qp, rp, a, b)
    281 
    282 NSPR_API(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b);
    283 
    284 #define LL_DIV(r, a, b) { \
    285     PRInt64 _a, _b; \
    286     PRUint32 _negative = (PRInt32)(a).hi < 0; \
    287     if (_negative) { \
    288     LL_NEG(_a, a); \
    289     } else { \
    290     _a = a; \
    291     } \
    292     if ((PRInt32)(b).hi < 0) { \
    293     _negative ^= 1; \
    294     LL_NEG(_b, b); \
    295     } else { \
    296     _b = b; \
    297     } \
    298     LL_UDIVMOD(&(r), 0, _a, _b); \
    299     if (_negative) \
    300     LL_NEG(r, r); \
    301 }
    302 
    303 #define LL_MOD(r, a, b) { \
    304     PRInt64 _a, _b; \
    305     PRUint32 _negative = (PRInt32)(a).hi < 0; \
    306     if (_negative) { \
    307     LL_NEG(_a, a); \
    308     } else { \
    309     _a = a; \
    310     } \
    311     if ((PRInt32)(b).hi < 0) { \
    312     LL_NEG(_b, b); \
    313     } else { \
    314     _b = b; \
    315     } \
    316     LL_UDIVMOD(0, &(r), _a, _b); \
    317     if (_negative) \
    318     LL_NEG(r, r); \
    319 }
    320 
    321 #define LL_SHL(r, a, b) { \
    322     if (b) { \
    323     PRInt64 _a; \
    324         _a = a; \
    325         if ((b) < 32) { \
    326         (r).lo = _a.lo << ((b) & 31); \
    327         (r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
    328     } else { \
    329         (r).lo = 0; \
    330         (r).hi = _a.lo << ((b) & 31); \
    331     } \
    332     } else { \
    333     (r) = (a); \
    334     } \
    335 }
    336 
    337 /* a is an PRInt32, b is PRInt32, r is PRInt64 */
    338 #define LL_ISHL(r, a, b) { \
    339     if (b) { \
    340     PRInt64 _a; \
    341     _a.lo = (a); \
    342     _a.hi = 0; \
    343         if ((b) < 32) { \
    344         (r).lo = (a) << ((b) & 31); \
    345         (r).hi = ((a) >> (32 - (b))); \
    346     } else { \
    347         (r).lo = 0; \
    348         (r).hi = (a) << ((b) & 31); \
    349     } \
    350     } else { \
    351     (r).lo = (a); \
    352     (r).hi = 0; \
    353     } \
    354 }
    355 
    356 #define LL_SHR(r, a, b) { \
    357     if (b) { \
    358     PRInt64 _a; \
    359         _a = a; \
    360     if ((b) < 32) { \
    361         (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
    362         (r).hi = (PRInt32)_a.hi >> ((b) & 31); \
    363     } else { \
    364         (r).lo = (PRInt32)_a.hi >> ((b) & 31); \
    365         (r).hi = (PRInt32)_a.hi >> 31; \
    366     } \
    367     } else { \
    368     (r) = (a); \
    369     } \
    370 }
    371 
    372 #define LL_USHR(r, a, b) { \
    373     if (b) { \
    374     PRInt64 _a; \
    375         _a = a; \
    376     if ((b) < 32) { \
    377         (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
    378         (r).hi = _a.hi >> ((b) & 31); \
    379     } else { \
    380         (r).lo = _a.hi >> ((b) & 31); \
    381         (r).hi = 0; \
    382     } \
    383     } else { \
    384     (r) = (a); \
    385     } \
    386 }
    387 
    388 #define LL_L2I(i, l)        ((i) = (l).lo)
    389 #define LL_L2UI(ui, l)        ((ui) = (l).lo)
    390 #define LL_L2F(f, l)        { double _d; LL_L2D(_d, l); (f) = (PRFloat64)_d; }
    391 
    392 #define LL_L2D(d, l) { \
    393     int _negative; \
    394     PRInt64 _absval; \
    395  \
    396     _negative = (l).hi >> 31; \
    397     if (_negative) { \
    398     LL_NEG(_absval, l); \
    399     } else { \
    400     _absval = l; \
    401     } \
    402     (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
    403     if (_negative) \
    404     (d) = -(d); \
    405 }
    406 
    407 #define LL_I2L(l, i)        { PRInt32 _i = ((PRInt32)(i)) >> 31; (l).lo = (i); (l).hi = _i; }
    408 #define LL_UI2L(l, ui)      ((l).lo = (ui), (l).hi = 0)
    409 #define LL_F2L(l, f)        { double _d = (double)f; LL_D2L(l, _d); }
    410 
    411 #define LL_D2L(l, d) { \
    412     int _negative; \
    413     double _absval, _d_hi; \
    414     PRInt64 _lo_d; \
    415  \
    416     _negative = ((d) < 0); \
    417     _absval = _negative ? -(d) : (d); \
    418  \
    419     (l).hi = _absval / 4.294967296e9; \
    420     (l).lo = 0; \
    421     LL_L2D(_d_hi, l); \
    422     _absval -= _d_hi; \
    423     _lo_d.hi = 0; \
    424     if (_absval < 0) { \
    425     _lo_d.lo = -_absval; \
    426     LL_SUB(l, l, _lo_d); \
    427     } else { \
    428     _lo_d.lo = _absval; \
    429     LL_ADD(l, l, _lo_d); \
    430     } \
    431  \
    432     if (_negative) \
    433     LL_NEG(l, l); \
    434 }
    435 
    436 #endif /* !HAVE_LONG_LONG */
    437 
    438196PR_END_EXTERN_C
    439197
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prlong.c

    r102243 r102246  
    4343static PRUint64 ll_maxuint = LL_INIT( 0xffffffff, 0xffffffff );
    4444
    45 #if defined(HAVE_WATCOM_BUG_2)
    46 PRInt64 __pascal __loadds __export
    47     LL_Zero(void) { return ll_zero; }
    48 PRInt64 __pascal __loadds __export
    49     LL_MaxInt(void) { return ll_maxint; }
    50 PRInt64 __pascal __loadds __export
    51     LL_MinInt(void) { return ll_minint; }
    52 PRUint64 __pascal __loadds __export
    53     LL_MaxUint(void) { return ll_maxuint; }
    54 #else
    5545PR_IMPLEMENT(PRInt64) LL_Zero(void) { return ll_zero; }
    5646PR_IMPLEMENT(PRInt64) LL_MaxInt(void) { return ll_maxint; }
    5747PR_IMPLEMENT(PRInt64) LL_MinInt(void) { return ll_minint; }
    5848PR_IMPLEMENT(PRUint64) LL_MaxUint(void) { return ll_maxuint; }
    59 #endif
    60 
    61 #ifndef HAVE_LONG_LONG
    62 /*
    63 ** Divide 64-bit a by 32-bit b, which must be normalized so its high bit is 1.
    64 */
    65 static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
    66 {
    67     PRUint32 d1, d0, q1, q0;
    68     PRUint32 r1, r0, m;
    69 
    70     d1 = _hi16(b);
    71     d0 = _lo16(b);
    72     r1 = a.hi % d1;
    73     q1 = a.hi / d1;
    74     m = q1 * d0;
    75     r1 = (r1 << 16) | _hi16(a.lo);
    76     if (r1 < m) {
    77         q1--, r1 += b;
    78         if (r1 >= b     /* i.e., we didn't get a carry when adding to r1 */
    79             && r1 < m) {
    80             q1--, r1 += b;
    81         }
    82     }
    83     r1 -= m;
    84     r0 = r1 % d1;
    85     q0 = r1 / d1;
    86     m = q0 * d0;
    87     r0 = (r0 << 16) | _lo16(a.lo);
    88     if (r0 < m) {
    89         q0--, r0 += b;
    90         if (r0 >= b
    91             && r0 < m) {
    92             q0--, r0 += b;
    93         }
    94     }
    95     *qp = (q1 << 16) | q0;
    96     *rp = r0 - m;
    97 }
    98 
    99 static PRUint32 CountLeadingZeros(PRUint32 a)
    100 {
    101     PRUint32 t;
    102     PRUint32 r = 32;
    103 
    104     if ((t = a >> 16) != 0)
    105         r -= 16, a = t;
    106     if ((t = a >> 8) != 0)
    107         r -= 8, a = t;
    108     if ((t = a >> 4) != 0)
    109         r -= 4, a = t;
    110     if ((t = a >> 2) != 0)
    111         r -= 2, a = t;
    112     if ((t = a >> 1) != 0)
    113         r -= 1, a = t;
    114     if (a & 1)
    115         r--;
    116     return r;
    117 }
    118 
    119 PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b)
    120 {
    121     PRUint32 n0, n1, n2;
    122     PRUint32 q0, q1;
    123     PRUint32 rsh, lsh;
    124 
    125     n0 = a.lo;
    126     n1 = a.hi;
    127 
    128     if (b.hi == 0) {
    129         if (b.lo > n1) {
    130             /* (0 q0) = (n1 n0) / (0 D0) */
    131 
    132             lsh = CountLeadingZeros(b.lo);
    133 
    134             if (lsh) {
    135                 /*
    136                  * Normalize, i.e. make the most significant bit of the
    137                  * denominator be set.
    138                  */
    139                 b.lo = b.lo << lsh;
    140                 n1 = (n1 << lsh) | (n0 >> (32 - lsh));
    141                 n0 = n0 << lsh;
    142             }
    143 
    144             a.lo = n0, a.hi = n1;
    145             norm_udivmod32(&q0, &n0, a, b.lo);
    146             q1 = 0;
    147 
    148             /* remainder is in n0 >> lsh */
    149         } else {
    150             /* (q1 q0) = (n1 n0) / (0 d0) */
    151 
    152             if (b.lo == 0)              /* user wants to divide by zero! */
    153                 b.lo = 1 / b.lo;        /* so go ahead and crash */
    154 
    155             lsh = CountLeadingZeros(b.lo);
    156 
    157             if (lsh == 0) {
    158                 /*
    159                  * From (n1 >= b.lo)
    160                  *   && (the most significant bit of b.lo is set),
    161                  * conclude that
    162                  *      (the most significant bit of n1 is set)
    163                  *   && (the leading quotient digit q1 = 1).
    164                  *
    165                  * This special case is necessary, not an optimization
    166                  * (Shifts counts of 32 are undefined).
    167                  */
    168                 n1 -= b.lo;
    169                 q1 = 1;
    170             } else {
    171                 /*
    172                  * Normalize.
    173                  */
    174                 rsh = 32 - lsh;
    175 
    176                 b.lo = b.lo << lsh;
    177                 n2 = n1 >> rsh;
    178                 n1 = (n1 << lsh) | (n0 >> rsh);
    179                 n0 = n0 << lsh;
    180 
    181                 a.lo = n1, a.hi = n2;
    182                 norm_udivmod32(&q1, &n1, a, b.lo);
    183             }
    184 
    185             /* n1 != b.lo... */
    186 
    187             a.lo = n0, a.hi = n1;
    188             norm_udivmod32(&q0, &n0, a, b.lo);
    189 
    190             /* remainder in n0 >> lsh */
    191         }
    192 
    193         if (rp) {
    194             rp->lo = n0 >> lsh;
    195             rp->hi = 0;
    196         }
    197     } else {
    198         if (b.hi > n1) {
    199             /* (0 0) = (n1 n0) / (D1 d0) */
    200 
    201             q0 = 0;
    202             q1 = 0;
    203 
    204             /* remainder in (n1 n0) */
    205             if (rp) {
    206                 rp->lo = n0;
    207                 rp->hi = n1;
    208             }
    209         } else {
    210             /* (0 q0) = (n1 n0) / (d1 d0) */
    211 
    212             lsh = CountLeadingZeros(b.hi);
    213             if (lsh == 0) {
    214                 /*
    215                  * From (n1 >= b.hi)
    216                  *   && (the most significant bit of b.hi is set),
    217                  * conclude that
    218                  *      (the most significant bit of n1 is set)
    219                  *   && (the quotient digit q0 = 0 or 1).
    220                  *
    221                  * This special case is necessary, not an optimization.
    222                  */
    223 
    224                 /*
    225                  * The condition on the next line takes advantage of that
    226                  * n1 >= b.hi (true due to control flow).
    227                  */
    228                 if (n1 > b.hi || n0 >= b.lo) {
    229                     q0 = 1;
    230                     a.lo = n0, a.hi = n1;
    231                     LL_SUB(a, a, b);
    232                 } else {
    233                     q0 = 0;
    234                 }
    235                 q1 = 0;
    236 
    237                 if (rp) {
    238                     rp->lo = n0;
    239                     rp->hi = n1;
    240                 }
    241             } else {
    242                 PRInt64 m;
    243 
    244                 /*
    245                  * Normalize.
    246                  */
    247                 rsh = 32 - lsh;
    248 
    249                 b.hi = (b.hi << lsh) | (b.lo >> rsh);
    250                 b.lo = b.lo << lsh;
    251                 n2 = n1 >> rsh;
    252                 n1 = (n1 << lsh) | (n0 >> rsh);
    253                 n0 = n0 << lsh;
    254 
    255                 a.lo = n1, a.hi = n2;
    256                 norm_udivmod32(&q0, &n1, a, b.hi);
    257                 LL_MUL32(m, q0, b.lo);
    258 
    259                 if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
    260                     q0--;
    261                     LL_SUB(m, m, b);
    262                 }
    263 
    264                 q1 = 0;
    265 
    266                 /* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
    267                 if (rp) {
    268                     a.lo = n0, a.hi = n1;
    269                     LL_SUB(a, a, m);
    270                     rp->lo = (a.hi << rsh) | (a.lo >> lsh);
    271                     rp->hi = a.hi >> lsh;
    272                 }
    273             }
    274         }
    275     }
    276 
    277     if (qp) {
    278         qp->lo = q0;
    279         qp->hi = q1;
    280     }
    281 }
    282 #endif /* !HAVE_LONG_LONG */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette