00001
00002
00003
00004 #if defined (ACE_LACKS_LONGLONG_T)
00005
00006 ACE_INLINE
00007 ACE_U_LongLong::ACE_U_LongLong (const ACE_UINT32 lo, const ACE_UINT32 hi)
00008 {
00009 h_ () = hi;
00010 l_ () = lo;
00011 }
00012
00013 ACE_INLINE ACE_UINT32
00014 ACE_U_LongLong::hi (void) const
00015 {
00016 return h_ ();
00017 }
00018
00019 ACE_INLINE ACE_UINT32
00020 ACE_U_LongLong::lo (void) const
00021 {
00022 return l_ ();
00023 }
00024
00025 ACE_INLINE void
00026 ACE_U_LongLong::hi (const ACE_UINT32 hi)
00027 {
00028 h_ () = hi;
00029 }
00030
00031 ACE_INLINE void
00032 ACE_U_LongLong::lo (const ACE_UINT32 lo)
00033 {
00034 l_ () = lo;
00035 }
00036
00037 ACE_INLINE
00038 ACE_U_LongLong::~ACE_U_LongLong (void)
00039 {
00040 }
00041
00042 ACE_INLINE int
00043 ACE_U_LongLong::operator== (const ACE_U_LongLong &n) const
00044 {
00045 return h_ () == n.h_ () && l_ () == n.l_ ();
00046 }
00047
00048 ACE_INLINE int
00049 ACE_U_LongLong::operator== (const ACE_UINT32 n) const
00050 {
00051 return h_ () == 0 && l_ () == n;
00052 }
00053
00054 ACE_INLINE int
00055 ACE_U_LongLong::operator!= (const ACE_U_LongLong &n) const
00056 {
00057 return ! (*this == n);
00058 }
00059
00060 ACE_INLINE int
00061 ACE_U_LongLong::operator!= (const ACE_UINT32 n) const
00062 {
00063 return ! (*this == n);
00064 }
00065
00066 ACE_INLINE int
00067 ACE_U_LongLong::operator< (const ACE_U_LongLong &n) const
00068 {
00069 return h_ () < n.h_ () ? 1
00070 : h_ () > n.h_ () ? 0
00071 : l_ () < n.l_ ();
00072 }
00073
00074 ACE_INLINE int
00075 ACE_U_LongLong::operator< (const ACE_UINT32 n) const
00076 {
00077 return operator< (ACE_static_cast (const ACE_U_LongLong, n));
00078 }
00079
00080 ACE_INLINE int
00081 ACE_U_LongLong::operator<= (const ACE_U_LongLong &n) const
00082 {
00083 return h_ () < n.h_ () ? 1
00084 : h_ () > n.h_ () ? 0
00085 : l_ () <= n.l_ ();
00086 }
00087
00088 ACE_INLINE int
00089 ACE_U_LongLong::operator<= (const ACE_UINT32 n) const
00090 {
00091 return operator<= (ACE_static_cast (const ACE_U_LongLong, n));
00092 }
00093
00094 ACE_INLINE int
00095 ACE_U_LongLong::operator> (const ACE_U_LongLong &n) const
00096 {
00097 return h_ () > n.h_ () ? 1
00098 : h_ () < n.h_ () ? 0
00099 : l_ () > n.l_ ();
00100 }
00101
00102 ACE_INLINE int
00103 ACE_U_LongLong::operator> (const ACE_UINT32 n) const
00104 {
00105 return operator> (ACE_static_cast (const ACE_U_LongLong, n));
00106 }
00107
00108 ACE_INLINE int
00109 ACE_U_LongLong::operator>= (const ACE_U_LongLong &n) const
00110 {
00111 return h_ () > n.h_ () ? 1
00112 : h_ () < n.h_ () ? 0
00113 : l_ () >= n.l_ ();
00114 }
00115
00116 ACE_INLINE int
00117 ACE_U_LongLong::operator>= (const ACE_UINT32 n) const
00118 {
00119 return operator>= (ACE_static_cast (const ACE_U_LongLong, n));
00120 }
00121
00122 ACE_INLINE
00123 ACE_U_LongLong::ACE_U_LongLong (const ACE_U_LongLong &n)
00124 {
00125 h_ () = n.h_ ();
00126 l_ () = n.l_ ();
00127 }
00128
00129 ACE_INLINE ACE_U_LongLong &
00130 ACE_U_LongLong::operator= (const ACE_U_LongLong &n)
00131 {
00132 h_ () = n.h_ ();
00133 l_ () = n.l_ ();
00134
00135 return *this;
00136 }
00137
00138 ACE_INLINE ACE_U_LongLong
00139 ACE_U_LongLong::operator+ (const ACE_U_LongLong &n) const
00140 {
00141 ACE_U_LongLong ret (l_ () + n.l_ (), h_ () + n.h_ ());
00142 if (ret.l_ () < n.l_ ()) ++ret.h_ ();
00143
00144 return ret;
00145 }
00146
00147 ACE_INLINE ACE_U_LongLong
00148 ACE_U_LongLong::operator+ (const ACE_UINT32 n) const
00149 {
00150 return operator+ (ACE_static_cast (const ACE_U_LongLong, n));
00151 }
00152
00153 ACE_INLINE ACE_U_LongLong
00154 ACE_U_LongLong::operator- (const ACE_U_LongLong &n) const
00155 {
00156 ACE_U_LongLong ret (l_ () - n.l_ (), h_ () - n.h_ ());
00157 if (l_ () < n.l_ ()) --ret.h_ ();
00158
00159 return ret;
00160 }
00161
00162 ACE_INLINE ACE_U_LongLong
00163 ACE_U_LongLong::operator- (const ACE_UINT32 n) const
00164 {
00165 return operator- (ACE_static_cast (const ACE_U_LongLong, n));
00166 }
00167
00168 ACE_INLINE ACE_U_LongLong
00169 ACE_U_LongLong::operator<< (const u_int n) const
00170 {
00171 const ACE_UINT32 carry_mask = l_ () >> (32 - n);
00172 ACE_U_LongLong ret (n < 32 ? l_ () << n : 0,
00173 n < 32 ? (h_ () << n) | carry_mask : carry_mask);
00174
00175 return ret;
00176 }
00177
00178 ACE_INLINE ACE_U_LongLong &
00179 ACE_U_LongLong::operator<<= (const u_int n)
00180 {
00181 const ACE_UINT32 carry_mask = l_ () >> (32 - n);
00182 h_ () = n < 32 ? (h_ () << n) | carry_mask : carry_mask;
00183
00184
00185 l_ () = n < 32 ? l_ () << n : 0;
00186
00187 return *this;
00188 }
00189
00190 ACE_INLINE ACE_U_LongLong
00191 ACE_U_LongLong::operator>> (const u_int n) const
00192 {
00193 const ACE_UINT32 carry_mask = h_ () << (32 - n);
00194 ACE_U_LongLong ret (n < 32 ? (l_ () >> n) | carry_mask : 0,
00195 n < 32 ? h_ () >> n : 0);
00196
00197 return ret;
00198 }
00199
00200 ACE_INLINE ACE_U_LongLong &
00201 ACE_U_LongLong::operator>>= (const u_int n)
00202 {
00203 const ACE_UINT32 carry_mask = h_ () << (32 - n);
00204 l_ () = n < 32 ? (l_ () >> n) | carry_mask : carry_mask;
00205 h_ () = n < 32 ? h_ () >> n : 0;
00206
00207 return *this;
00208 }
00209
00210 ACE_INLINE double
00211 ACE_U_LongLong::operator/ (const double n) const
00212 {
00213
00214
00215 return ((double) 0xffffffffu - n + 1.0) / n * h_ () +
00216 (double) h_ () + (double) l_ () / n;
00217 }
00218
00219 ACE_INLINE ACE_U_LongLong &
00220 ACE_U_LongLong::operator+= (const ACE_U_LongLong &n)
00221 {
00222 h_ () += n.h_ ();
00223 l_ () += n.l_ ();
00224 if (l_ () < n.l_ ()) ++h_ ();
00225
00226 return *this;
00227 }
00228
00229 ACE_INLINE ACE_U_LongLong &
00230 ACE_U_LongLong::operator+= (const ACE_UINT32 n)
00231 {
00232 return operator+= (ACE_static_cast (const ACE_U_LongLong, n));
00233 }
00234
00235 #define ACE_HIGHBIT (~(~0UL >> 1))
00236
00237 ACE_INLINE ACE_UINT32
00238 ACE_U_LongLong::ul_shift (ACE_UINT32 a, ACE_UINT32 c_in, ACE_UINT32 *c_out) const
00239 {
00240 const ACE_UINT32 b = (a << 1) | c_in;
00241 *c_out = (*c_out << 1) + ((a & ACE_HIGHBIT) > 0);
00242
00243 return b;
00244 }
00245
00246 ACE_INLINE ACE_U_LongLong
00247 ACE_U_LongLong::ull_shift (ACE_U_LongLong a,
00248 ACE_UINT32 c_in,
00249 ACE_UINT32 *c_out) const
00250 {
00251 ACE_U_LongLong b;
00252
00253 b.l_ () = (a.l_ () << 1) | c_in;
00254 c_in = ((a.l_ () & ACE_HIGHBIT) > 0);
00255 b.h_ () = (a.h_ () << 1) | c_in;
00256 *c_out = (*c_out << 1) + ((a.h_ () & ACE_HIGHBIT) > 0);
00257
00258 return b;
00259 }
00260
00261 ACE_INLINE ACE_U_LongLong
00262 ACE_U_LongLong::ull_add (ACE_U_LongLong a, ACE_U_LongLong b, ACE_UINT32 *carry) const
00263 {
00264 ACE_U_LongLong r (0, 0);
00265 ACE_UINT32 c1, c2, c3, c4;
00266
00267 c1 = a.l_ () % 2;
00268 c2 = b.l_ () % 2;
00269 c3 = 0;
00270
00271 r.l_ () = a.l_ ()/2 + b.l_ ()/2 + (c1+c2)/2;
00272 r.l_ () = ul_shift (r.l_ (), (c1+c2)%2, &c3);
00273
00274 c1 = a.h_ () % 2;
00275 c2 = b.h_ () % 2;
00276 c4 = 0;
00277
00278 r.h_ () = a.h_ ()/2 + b.h_ ()/2 + (c1+c2+c3)/2;
00279 r.h_ () = ul_shift (r.h_ (), (c1+c2+c3)%2, &c4);
00280
00281 *carry = c4;
00282
00283 return r;
00284 }
00285
00286 ACE_INLINE ACE_U_LongLong
00287 ACE_U_LongLong::ull_mult (ACE_U_LongLong a, ACE_UINT32 b, ACE_UINT32 *carry) const
00288 {
00289 register ACE_UINT32 mask = ACE_HIGHBIT;
00290 const ACE_U_LongLong zero (0, 0);
00291 ACE_U_LongLong accum (0, 0);
00292 ACE_UINT32 c;
00293
00294 *carry = 0;
00295 if (b > 0)
00296 do
00297 {
00298 accum = ull_shift (accum, 0U, carry);
00299 if (b & mask)
00300 accum = ull_add (accum, a, &c);
00301 else
00302 accum = ull_add (accum, zero, &c);
00303 *carry += c;
00304 mask >>= 1;
00305 }
00306 while (mask > 0);
00307
00308 return accum;
00309 }
00310
00311 ACE_INLINE ACE_U_LongLong
00312 ACE_U_LongLong::operator* (const ACE_UINT32 n) const
00313 {
00314 ACE_UINT32 carry;
00315
00316 return ull_mult (*this, n, &carry);
00317 }
00318
00319 ACE_INLINE ACE_U_LongLong &
00320 ACE_U_LongLong::operator*= (const ACE_UINT32 n)
00321 {
00322 ACE_UINT32 carry;
00323
00324 return *this = ull_mult (*this, n, &carry);
00325 }
00326
00327 ACE_INLINE ACE_U_LongLong &
00328 ACE_U_LongLong::operator-= (const ACE_U_LongLong &n)
00329 {
00330 h_ () -= n.h_ ();
00331 if (l_ () < n.l_ ()) --h_ ();
00332 l_ () -= n.l_ ();
00333
00334 return *this;
00335 }
00336
00337 ACE_INLINE ACE_U_LongLong &
00338 ACE_U_LongLong::operator-= (const ACE_UINT32 n)
00339 {
00340 return operator-= (ACE_static_cast (const ACE_U_LongLong, n));
00341 }
00342
00343 ACE_INLINE ACE_U_LongLong &
00344 ACE_U_LongLong::operator++ ()
00345 {
00346 ++l_ ();
00347 if (l_ () == 0) ++h_ ();
00348
00349 return *this;
00350 }
00351
00352 ACE_INLINE ACE_U_LongLong &
00353 ACE_U_LongLong::operator-- ()
00354 {
00355 if (l_ () == 0) --h_ ();
00356 --l_ ();
00357
00358 return *this;
00359 }
00360
00361 ACE_INLINE ACE_U_LongLong &
00362 ACE_U_LongLong::operator|= (const ACE_U_LongLong n)
00363 {
00364 l_ () |= n.l_ ();
00365 h_ () |= n.h_ ();
00366
00367 return *this;
00368 }
00369
00370 ACE_INLINE ACE_U_LongLong &
00371 ACE_U_LongLong::operator|= (const ACE_UINT32 n)
00372 {
00373 return operator|= (ACE_static_cast (const ACE_U_LongLong, n));
00374 }
00375
00376 ACE_INLINE ACE_U_LongLong &
00377 ACE_U_LongLong::operator&= (const ACE_U_LongLong n)
00378 {
00379 l_ () &= n.l_ ();
00380 h_ () &= n.h_ ();
00381
00382 return *this;
00383 }
00384
00385 ACE_INLINE ACE_U_LongLong &
00386 ACE_U_LongLong::operator&= (const ACE_UINT32 n)
00387 {
00388 return operator&= (ACE_static_cast (const ACE_U_LongLong, n));
00389 }
00390
00391 ACE_INLINE ACE_UINT32
00392 ACE_U_LongLong::operator/ (const ACE_UINT32 n) const
00393 {
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 return (0xffffffffu - n + 1) / n * h_ () + h_ () + l_ () / n;
00404 }
00405
00406 ACE_INLINE ACE_UINT32
00407 ACE_U_LongLong::operator% (const ACE_UINT32 n) const
00408 {
00409
00410
00411
00412
00413
00414
00415
00416
00417 return ((0xffffffff - n + 1) % n * h_ () + l_ () % n) % n;
00418 }
00419
00420 ACE_INLINE ACE_UINT32
00421 ACE_U_LongLong::operator| (const ACE_INT32 n) const
00422 {
00423 return l_ () | n;
00424 }
00425
00426 ACE_INLINE ACE_UINT32
00427 ACE_U_LongLong::operator& (const ACE_INT32 n) const
00428 {
00429 return l_ () & n;
00430 }
00431
00432 ACE_INLINE ACE_U_LongLong
00433 ACE_U_LongLong::operator* (const ACE_INT32 n) const
00434 {
00435 return operator* ((ACE_UINT32) n);
00436 }
00437
00438 ACE_INLINE ACE_U_LongLong &
00439 ACE_U_LongLong::operator*= (const ACE_INT32 n)
00440 {
00441 return operator*= ((ACE_UINT32) n);
00442 }
00443
00444 ACE_INLINE ACE_UINT32
00445 ACE_U_LongLong::operator/ (const ACE_INT32 n) const
00446 {
00447 return operator/ ((ACE_UINT32) n);
00448 }
00449
00450 #if ACE_SIZEOF_INT == 4
00451 ACE_INLINE ACE_UINT32
00452 ACE_U_LongLong::operator/ (const u_long n) const
00453 {
00454 return operator/ ((ACE_UINT32) n);
00455 }
00456
00457 ACE_INLINE ACE_UINT32
00458 ACE_U_LongLong::operator/ (const long n) const
00459 {
00460 return operator/ ((ACE_UINT32) n);
00461 }
00462
00463 #else
00464 ACE_INLINE ACE_UINT32
00465 ACE_U_LongLong::operator/ (const u_int n) const
00466 {
00467 return operator/ ((ACE_UINT32) n);
00468 }
00469
00470 ACE_INLINE ACE_UINT32
00471 ACE_U_LongLong::operator/ (const int n) const
00472 {
00473 return operator/ ((ACE_UINT32) n);
00474 }
00475 #endif
00476
00477 #endif