Basic_Types.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Basic_Types.inl,v 4.4 2006/04/03 18:01:46 ossama Exp
00004 
00005 # if !defined (ACE_LACKS_LONGLONG_T) && defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00006 
00007 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00008 
00009 // Implementation for ACE_U_LongLong when we have signed long long
00010 // but no unsigned long long.
00011 
00012 ACE_INLINE
00013 ACE_U_LongLong::ACE_U_LongLong (const long long value)
00014   : data_ (value)
00015 {
00016 }
00017 
00018 ACE_INLINE ACE_UINT32
00019 ACE_U_LongLong::hi (void) const
00020 {
00021   return (data_ >> 32) & 0xFFFFFFFF;
00022 }
00023 
00024 ACE_INLINE ACE_UINT32
00025 ACE_U_LongLong::lo (void) const
00026 {
00027   return data_ & 0xFFFFFFFF;
00028 }
00029 
00030 ACE_INLINE void
00031 ACE_U_LongLong::hi (const ACE_UINT32 hi)
00032 {
00033   data_ = hi;
00034   data_ <<= 32;
00035 }
00036 
00037 ACE_INLINE void
00038 ACE_U_LongLong::lo (const ACE_UINT32 lo)
00039 {
00040   data_ = lo;
00041 }
00042 
00043 ACE_INLINE long long
00044 ACE_U_LongLong::to_int64 (void) const
00045 {
00046   return data_;
00047 }
00048 
00049 ACE_INLINE
00050 ACE_U_LongLong::~ACE_U_LongLong (void)
00051 {
00052 }
00053 
00054 ACE_INLINE bool
00055 ACE_U_LongLong::operator== (const ACE_U_LongLong &n) const
00056 {
00057   return data_  == n.data_;
00058 }
00059 
00060 ACE_INLINE bool
00061 ACE_U_LongLong::operator== (const ACE_UINT32 n) const
00062 {
00063   return data_  == n;
00064 }
00065 
00066 ACE_INLINE bool
00067 ACE_U_LongLong::operator!= (const ACE_U_LongLong &n) const
00068 {
00069   return ! (*this == n);
00070 }
00071 
00072 ACE_INLINE bool
00073 ACE_U_LongLong::operator!= (const ACE_UINT32 n) const
00074 {
00075   return ! (*this == n);
00076 }
00077 
00078 ACE_INLINE bool
00079 ACE_U_LongLong::operator< (const ACE_U_LongLong &n) const
00080 {
00081   if (data_ > 0)
00082     if (n.data_ > 0)
00083       return data_ < n.data_;
00084     else
00085       return true;
00086   else
00087     if (n.data_ > 0)
00088       return false;
00089     else
00090       return data_ < n.data_;
00091 }
00092 
00093 ACE_INLINE bool
00094 ACE_U_LongLong::operator< (const ACE_UINT32 n) const
00095 {
00096   return operator< (static_cast<const ACE_U_LongLong> (n));
00097 }
00098 
00099 ACE_INLINE bool
00100 ACE_U_LongLong::operator<= (const ACE_U_LongLong &n) const
00101 {
00102   if (data_ == n.data_) return true;
00103 
00104   return data_ < n.data_;
00105 }
00106 
00107 ACE_INLINE bool
00108 ACE_U_LongLong::operator<= (const ACE_UINT32 n) const
00109 {
00110   return operator<= (static_cast<const ACE_U_LongLong> (n));
00111 }
00112 
00113 ACE_INLINE bool
00114 ACE_U_LongLong::operator> (const ACE_U_LongLong &n) const
00115 {
00116   if (data_ > 0)
00117     if (n.data_ > 0)
00118       return data_ > n.data_;
00119     else
00120       return false;
00121   else
00122     if (n.data_ > 0)
00123       return true;
00124     else
00125       return data_ > n.data_;
00126 }
00127 
00128 ACE_INLINE bool
00129 ACE_U_LongLong::operator> (const ACE_UINT32 n) const
00130 {
00131   return operator> (static_cast<const ACE_U_LongLong> (n));
00132 }
00133 
00134 ACE_INLINE bool
00135 ACE_U_LongLong::operator>= (const ACE_U_LongLong &n) const
00136 {
00137   if (data_ == n.data_) return true;
00138 
00139   return data_ > n.data_;
00140 }
00141 
00142 ACE_INLINE bool
00143 ACE_U_LongLong::operator>= (const ACE_UINT32 n) const
00144 {
00145   return operator>= (static_cast<const ACE_U_LongLong> (n));
00146 }
00147 
00148 ACE_INLINE
00149 ACE_U_LongLong::ACE_U_LongLong (const ACE_U_LongLong &n)
00150   : data_ (n.data_)
00151 {
00152 }
00153 
00154 ACE_INLINE ACE_U_LongLong &
00155 ACE_U_LongLong::operator= (const ACE_U_LongLong &n)
00156 {
00157   data_ = n.data_;
00158 
00159   return *this;
00160 }
00161 
00162 ACE_INLINE ACE_U_LongLong &
00163 ACE_U_LongLong::operator= (const ACE_INT32 &rhs)
00164 {
00165   if (rhs >= 0)
00166     {
00167       data_ = rhs;
00168       data_ &= 0xFFFFFFFF;
00169     }
00170   else
00171     {
00172       // We do not handle the case where a negative 32 bit integer is
00173       // assigned to this representation of a 64 bit unsigned integer.
00174       // The "undefined behavior" behavior performed by this
00175       // implementation is to simply set all bits to zero.
00176       data_ = 0;
00177     }
00178 
00179   return *this;
00180 }
00181 
00182 ACE_INLINE ACE_U_LongLong &
00183 ACE_U_LongLong::operator= (const ACE_UINT32 &rhs)
00184 {
00185   data_ = rhs;
00186 
00187   return *this;
00188 }
00189 
00190 
00191 ACE_INLINE ACE_U_LongLong
00192 ACE_U_LongLong::operator+ (const ACE_U_LongLong &n) const
00193 {
00194   return data_ + n.data_;
00195 }
00196 
00197 ACE_INLINE ACE_U_LongLong
00198 ACE_U_LongLong::operator+ (const ACE_UINT32 n) const
00199 {
00200   return operator+ (static_cast<const ACE_U_LongLong> (n));
00201 }
00202 
00203 ACE_INLINE ACE_U_LongLong
00204 ACE_U_LongLong::operator- (const ACE_U_LongLong &n) const
00205 {
00206   return data_ - n.data_;
00207 }
00208 
00209 ACE_INLINE ACE_U_LongLong
00210 ACE_U_LongLong::operator- (const ACE_UINT32 n) const
00211 {
00212   return operator- (static_cast<const ACE_U_LongLong> (n));
00213 }
00214 
00215 ACE_INLINE ACE_U_LongLong
00216 ACE_U_LongLong::operator<< (const u_int n) const
00217 {
00218   return data_ << n;
00219 }
00220 
00221 ACE_INLINE ACE_U_LongLong &
00222 ACE_U_LongLong::operator<<= (const u_int n)
00223 {
00224   data_ <<= n;
00225 
00226   return *this;
00227 }
00228 
00229 ACE_INLINE ACE_U_LongLong
00230 ACE_U_LongLong::operator>> (const u_int n) const
00231 {
00232   return data_ >> n;
00233 }
00234 
00235 ACE_INLINE ACE_U_LongLong &
00236 ACE_U_LongLong::operator>>= (const u_int n)
00237 {
00238   data_ >>= n;
00239 
00240   return *this;
00241 }
00242 
00243 ACE_INLINE double
00244 ACE_U_LongLong::operator/ (const double n) const
00245 {
00246   return data_ / n;
00247 }
00248 
00249 ACE_INLINE ACE_U_LongLong &
00250 ACE_U_LongLong::operator+= (const ACE_U_LongLong &n)
00251 {
00252   data_ += n.data_;
00253 
00254   return *this;
00255 }
00256 
00257 ACE_INLINE ACE_U_LongLong &
00258 ACE_U_LongLong::operator+= (const ACE_UINT32 n)
00259 {
00260   return operator+= (static_cast<const ACE_U_LongLong> (n));
00261 }
00262 
00263 ACE_INLINE ACE_U_LongLong
00264 ACE_U_LongLong::operator* (const ACE_UINT32 n) const
00265 {
00266   return data_ * n;
00267 }
00268 
00269 ACE_INLINE ACE_U_LongLong &
00270 ACE_U_LongLong::operator*= (const ACE_UINT32 n)
00271 {
00272   data_ *= n;
00273 
00274   return *this;
00275 }
00276 
00277 ACE_INLINE ACE_U_LongLong &
00278 ACE_U_LongLong::operator-= (const ACE_U_LongLong &n)
00279 {
00280   data_ -= n.data_;
00281 
00282   return *this;
00283 }
00284 
00285 ACE_INLINE ACE_U_LongLong &
00286 ACE_U_LongLong::operator-= (const ACE_UINT32 n)
00287 {
00288   return operator-= (static_cast<const ACE_U_LongLong> (n));
00289 }
00290 
00291 ACE_INLINE ACE_U_LongLong &
00292 ACE_U_LongLong::operator++ ()
00293 {
00294   ++data_;
00295 
00296   return *this;
00297 }
00298 
00299 ACE_INLINE ACE_U_LongLong &
00300 ACE_U_LongLong::operator-- ()
00301 {
00302   --data_;
00303 
00304   return *this;
00305 }
00306 
00307 ACE_INLINE const ACE_U_LongLong
00308 ACE_U_LongLong::operator++ (int)
00309 {
00310   // Post-increment operator should always be implemented in terms of
00311   // the pre-increment operator to enforce consistent semantics.
00312   ACE_U_LongLong temp (*this);
00313   ++*this;
00314   return temp;
00315 }
00316 
00317 ACE_INLINE const ACE_U_LongLong
00318 ACE_U_LongLong::operator-- (int)
00319 {
00320   // Post-decrement operator should always be implemented in terms of
00321   // the pre-decrement operator to enforce consistent semantics.
00322   ACE_U_LongLong temp (*this);
00323   --*this;
00324   return temp;
00325 }
00326 
00327 ACE_INLINE ACE_U_LongLong &
00328 ACE_U_LongLong::operator|= (const ACE_U_LongLong n)
00329 {
00330   data_ |= n.data_;
00331 
00332   return *this;
00333 }
00334 
00335 ACE_INLINE ACE_U_LongLong &
00336 ACE_U_LongLong::operator|= (const ACE_UINT32 n)
00337 {
00338   return operator|= (static_cast<const ACE_U_LongLong> (n));
00339 }
00340 
00341 ACE_INLINE ACE_U_LongLong &
00342 ACE_U_LongLong::operator&= (const ACE_U_LongLong n)
00343 {
00344   data_ &= n.data_;
00345 
00346   return *this;
00347 }
00348 
00349 ACE_INLINE ACE_U_LongLong &
00350 ACE_U_LongLong::operator&= (const ACE_UINT32 n)
00351 {
00352   return operator&= (static_cast<const ACE_U_LongLong> (n));
00353 }
00354 
00355 ACE_INLINE ACE_UINT32
00356 ACE_U_LongLong::operator/ (const ACE_UINT32 n) const
00357 {
00358   return data_ / n;
00359 }
00360 
00361 ACE_INLINE ACE_UINT32
00362 ACE_U_LongLong::operator% (const ACE_UINT32 n) const
00363 {
00364   return data_ % n;
00365 }
00366 
00367 ACE_INLINE ACE_UINT32
00368 ACE_U_LongLong::operator| (const ACE_INT32 n) const
00369 {
00370   return data_ | n;
00371 }
00372 
00373 ACE_INLINE ACE_UINT32
00374 ACE_U_LongLong::operator& (const ACE_INT32 n) const
00375 {
00376   return data_ & n;
00377 }
00378 
00379 ACE_INLINE ACE_U_LongLong
00380 ACE_U_LongLong::operator* (const ACE_INT32 n) const
00381 {
00382   return operator* ((ACE_UINT32) n);
00383 }
00384 
00385 ACE_INLINE ACE_U_LongLong &
00386 ACE_U_LongLong::operator*= (const ACE_INT32 n)
00387 {
00388   return operator*= ((ACE_UINT32) n);
00389 }
00390 
00391 ACE_INLINE ACE_UINT32
00392 ACE_U_LongLong::operator/ (const ACE_INT32 n) const
00393 {
00394   return operator/ ((ACE_UINT32) n);
00395 }
00396 
00397 #if ACE_SIZEOF_INT == 4
00398 ACE_INLINE ACE_UINT32
00399 ACE_U_LongLong::operator/ (const u_long n) const
00400 {
00401   return operator/ ((ACE_UINT32) n);
00402 }
00403 
00404 ACE_INLINE ACE_UINT32
00405 ACE_U_LongLong::operator/ (const long n) const
00406 {
00407   return operator/ ((ACE_UINT32) n);
00408 }
00409 
00410 #else  /* ACE_SIZEOF_INT != 4 */
00411 ACE_INLINE ACE_UINT32
00412 ACE_U_LongLong::operator/ (const u_int n) const
00413 {
00414   return operator/ ((ACE_UINT32) n);
00415 }
00416 
00417 ACE_INLINE ACE_UINT32
00418 ACE_U_LongLong::operator/ (const int n) const
00419 {
00420   return operator/ ((ACE_UINT32) n);
00421 }
00422 #endif
00423 
00424 ACE_END_VERSIONED_NAMESPACE_DECL
00425 
00426 #elif defined (ACE_LACKS_LONGLONG_T)
00427 
00428 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00429 
00430 ACE_INLINE
00431 ACE_U_LongLong::ACE_U_LongLong (const ACE_UINT32 lo, const ACE_UINT32 hi)
00432 {
00433   h_ () = hi;
00434   l_ () = lo;
00435 }
00436 
00437 ACE_INLINE ACE_UINT32
00438 ACE_U_LongLong::hi (void) const
00439 {
00440   return h_ ();
00441 }
00442 
00443 ACE_INLINE ACE_UINT32
00444 ACE_U_LongLong::lo (void) const
00445 {
00446   return l_ ();
00447 }
00448 
00449 ACE_INLINE void
00450 ACE_U_LongLong::hi (const ACE_UINT32 hi)
00451 {
00452   h_ () = hi;
00453 }
00454 
00455 ACE_INLINE void
00456 ACE_U_LongLong::lo (const ACE_UINT32 lo)
00457 {
00458   l_ () = lo;
00459 }
00460 
00461 ACE_INLINE
00462 ACE_U_LongLong::~ACE_U_LongLong (void)
00463 {
00464 }
00465 
00466 ACE_INLINE bool
00467 ACE_U_LongLong::operator== (const ACE_U_LongLong &n) const
00468 {
00469   return h_ () == n.h_ ()  &&  l_ () == n.l_ ();
00470 }
00471 
00472 ACE_INLINE bool
00473 ACE_U_LongLong::operator== (const ACE_UINT32 n) const
00474 {
00475   return h_ () == 0  &&  l_ () == n;
00476 }
00477 
00478 ACE_INLINE bool
00479 ACE_U_LongLong::operator!= (const ACE_U_LongLong &n) const
00480 {
00481   return ! (*this == n);
00482 }
00483 
00484 ACE_INLINE bool
00485 ACE_U_LongLong::operator!= (const ACE_UINT32 n) const
00486 {
00487   return ! (*this == n);
00488 }
00489 
00490 ACE_INLINE bool
00491 ACE_U_LongLong::operator< (const ACE_U_LongLong &n) const
00492 {
00493   return h_ () < n.h_ () ? 1
00494                          : h_ () > n.h_ () ? 0
00495                                            : l_ () < n.l_ ();
00496 }
00497 
00498 ACE_INLINE bool
00499 ACE_U_LongLong::operator< (const ACE_UINT32 n) const
00500 {
00501   return operator< (static_cast<const ACE_U_LongLong> (n));
00502 }
00503 
00504 ACE_INLINE bool
00505 ACE_U_LongLong::operator<= (const ACE_U_LongLong &n) const
00506 {
00507   return h_ () < n.h_ () ? 1
00508                          : h_ () > n.h_ () ? 0
00509                                            : l_ () <= n.l_ ();
00510 }
00511 
00512 ACE_INLINE bool
00513 ACE_U_LongLong::operator<= (const ACE_UINT32 n) const
00514 {
00515   return operator<= (static_cast<const ACE_U_LongLong> (n));
00516 }
00517 
00518 ACE_INLINE bool
00519 ACE_U_LongLong::operator> (const ACE_U_LongLong &n) const
00520 {
00521   return h_ () > n.h_ () ? 1
00522                          : h_ () < n.h_ () ? 0
00523                                            : l_ () > n.l_ ();
00524 }
00525 
00526 ACE_INLINE bool
00527 ACE_U_LongLong::operator> (const ACE_UINT32 n) const
00528 {
00529   return operator> (static_cast<const ACE_U_LongLong> (n));
00530 }
00531 
00532 ACE_INLINE bool
00533 ACE_U_LongLong::operator>= (const ACE_U_LongLong &n) const
00534 {
00535   return h_ () > n.h_ () ? 1
00536                          : h_ () < n.h_ () ? 0
00537                                            : l_ () >= n.l_ ();
00538 }
00539 
00540 ACE_INLINE bool
00541 ACE_U_LongLong::operator>= (const ACE_UINT32 n) const
00542 {
00543   return operator>= (static_cast<const ACE_U_LongLong> (n));
00544 }
00545 
00546 ACE_INLINE
00547 ACE_U_LongLong::ACE_U_LongLong (const ACE_U_LongLong &n)
00548 {
00549   h_ () = n.h_ ();
00550   l_ () = n.l_ ();
00551 }
00552 
00553 ACE_INLINE ACE_U_LongLong &
00554 ACE_U_LongLong::operator= (const ACE_U_LongLong &n)
00555 {
00556   h_ () = n.h_ ();
00557   l_ () = n.l_ ();
00558 
00559   return *this;
00560 }
00561 
00562 ACE_INLINE ACE_U_LongLong &
00563 ACE_U_LongLong::operator= (const ACE_INT32 &rhs)
00564 {
00565   if (rhs >= 0)
00566     {
00567       l_ () = static_cast<ACE_UINT32> (rhs);
00568       h_ () = 0;
00569     }
00570   else
00571     {
00572       // We do not handle the case where a negative 32 bit integer is
00573       // assigned to this representation of a 64 bit unsigned integer.
00574       // The "undefined behavior" behavior performed by this
00575       // implementation is to simply set all bits to zero.
00576       l_ () = 0;
00577       h_ () = 0;
00578     }
00579 
00580   return *this;
00581 }
00582 
00583 ACE_INLINE ACE_U_LongLong &
00584 ACE_U_LongLong::operator= (const ACE_UINT32 &rhs)
00585 {
00586   l_ () = rhs;
00587   h_ () = 0;
00588 
00589   return *this;
00590 }
00591 
00592 
00593 ACE_INLINE ACE_U_LongLong
00594 ACE_U_LongLong::operator+ (const ACE_U_LongLong &n) const
00595 {
00596   ACE_U_LongLong ret (l_ () + n.l_ (), h_ () + n.h_ ());
00597   if (ret.l_ () < n.l_ ()) /* carry */ ++ret.h_ ();
00598 
00599   return ret;
00600 }
00601 
00602 ACE_INLINE ACE_U_LongLong
00603 ACE_U_LongLong::operator+ (const ACE_UINT32 n) const
00604 {
00605   return operator+ (static_cast<const ACE_U_LongLong> (n));
00606 }
00607 
00608 ACE_INLINE ACE_U_LongLong
00609 ACE_U_LongLong::operator- (const ACE_U_LongLong &n) const
00610 {
00611   ACE_U_LongLong ret (l_ () - n.l_ (), h_ () - n.h_ ());
00612   if (l_ () < n.l_ ()) /* borrow */ --ret.h_ ();
00613 
00614   return ret;
00615 }
00616 
00617 ACE_INLINE ACE_U_LongLong
00618 ACE_U_LongLong::operator- (const ACE_UINT32 n) const
00619 {
00620   return operator- (static_cast<const ACE_U_LongLong> (n));
00621 }
00622 
00623 ACE_INLINE ACE_U_LongLong
00624 ACE_U_LongLong::operator<< (const u_int n) const
00625 {
00626   const ACE_UINT32 carry_mask = l_ () >> (32 - n);
00627   ACE_U_LongLong ret (n < 32  ?  l_ () << n  :  0,
00628                       n < 32  ?  (h_ () << n) | carry_mask  :  carry_mask);
00629 
00630   return ret;
00631 }
00632 
00633 ACE_INLINE ACE_U_LongLong &
00634 ACE_U_LongLong::operator<<= (const u_int n)
00635 {
00636   const ACE_UINT32 carry_mask = l_ () >> (32 - n);
00637   h_ () = n < 32  ?  (h_ () << n) | carry_mask  :  carry_mask;
00638 
00639   // g++ 2.7.2.3/Solaris 2.5.1 doesn't modify l_ () if shifted by 32.
00640   l_ () = n < 32  ?  l_ () << n  :  0;
00641 
00642   return *this;
00643 }
00644 
00645 ACE_INLINE ACE_U_LongLong
00646 ACE_U_LongLong::operator>> (const u_int n) const
00647 {
00648   const ACE_UINT32 carry_mask = h_ () << (32 - n);
00649   ACE_U_LongLong ret (n < 32  ?  (l_ () >> n) | carry_mask  :  0,
00650                       n < 32  ?  h_ () >> n  :  0);
00651 
00652   return ret;
00653 }
00654 
00655 ACE_INLINE ACE_U_LongLong &
00656 ACE_U_LongLong::operator>>= (const u_int n)
00657 {
00658   const ACE_UINT32 carry_mask = h_ () << (32 - n);
00659   l_ () = n < 32  ?  (l_ () >> n) | carry_mask  :  carry_mask;
00660   h_ () = n < 32  ?  h_ () >> n  :  0;
00661 
00662   return *this;
00663 }
00664 
00665 ACE_INLINE double
00666 ACE_U_LongLong::operator/ (const double n) const
00667 {
00668   // See the derivation above in operator/ (const ACE_UINT32).
00669 
00670   return ((double) 0xffffffffu - n + 1.0) / n * h_ ()  +
00671          (double) h_ ()  +  (double) l_ () / n;
00672 }
00673 
00674 ACE_INLINE ACE_U_LongLong &
00675 ACE_U_LongLong::operator+= (const ACE_U_LongLong &n)
00676 {
00677   h_ () += n.h_ ();
00678   l_ () += n.l_ ();
00679   if (l_ () < n.l_ ()) /* carry */ ++h_ ();
00680 
00681   return *this;
00682 }
00683 
00684 ACE_INLINE ACE_U_LongLong &
00685 ACE_U_LongLong::operator+= (const ACE_UINT32 n)
00686 {
00687   return operator+= (static_cast<const ACE_U_LongLong> (n));
00688 }
00689 
00690 #define ACE_HIGHBIT (~(~0UL >> 1))
00691 
00692 ACE_INLINE ACE_UINT32
00693 ACE_U_LongLong::ul_shift (ACE_UINT32 a, ACE_UINT32 c_in, ACE_UINT32 *c_out) const
00694 {
00695   const ACE_UINT32 b = (a << 1) | c_in;
00696   *c_out = (*c_out << 1) + ((a & ACE_HIGHBIT) > 0);
00697 
00698   return b;
00699 }
00700 
00701 ACE_INLINE ACE_U_LongLong
00702 ACE_U_LongLong::ull_shift (ACE_U_LongLong a,
00703                            ACE_UINT32 c_in,
00704                            ACE_UINT32 *c_out) const
00705 {
00706   ACE_U_LongLong b;
00707 
00708   b.l_ () = (a.l_ () << 1) | c_in;
00709   c_in = ((a.l_ () & ACE_HIGHBIT) > 0);
00710   b.h_ () = (a.h_ () << 1) | c_in;
00711   *c_out = (*c_out << 1) + ((a.h_ () & ACE_HIGHBIT) > 0);
00712 
00713   return b;
00714 }
00715 
00716 ACE_INLINE ACE_U_LongLong
00717 ACE_U_LongLong::ull_add (ACE_U_LongLong a, ACE_U_LongLong b, ACE_UINT32 *carry) const
00718 {
00719   ACE_U_LongLong r (0, 0);
00720   ACE_UINT32 c1, c2, c3, c4;
00721 
00722   c1 = a.l_ () % 2;
00723   c2 = b.l_ () % 2;
00724   c3 = 0;
00725 
00726   r.l_ () = a.l_ ()/2 +  b.l_ ()/2 + (c1+c2)/2;
00727   r.l_ () = ul_shift (r.l_ (), (c1+c2)%2, &c3);
00728 
00729   c1 = a.h_ () % 2;
00730   c2 = b.h_ () % 2;
00731   c4 = 0;
00732 
00733   r.h_ () = a.h_ ()/2 + b.h_ ()/2 + (c1+c2+c3)/2;
00734   r.h_ () = ul_shift (r.h_ (), (c1+c2+c3)%2, &c4);
00735 
00736   *carry = c4;
00737 
00738   return r;
00739 }
00740 
00741 ACE_INLINE ACE_U_LongLong
00742 ACE_U_LongLong::ull_mult (ACE_U_LongLong a, ACE_UINT32 b, ACE_UINT32 *carry) const
00743 {
00744   register ACE_UINT32 mask = ACE_HIGHBIT;
00745   const ACE_U_LongLong zero (0, 0);
00746   ACE_U_LongLong accum (0, 0);
00747   ACE_UINT32 c;
00748 
00749   *carry = 0;
00750   if (b > 0)
00751     do
00752       {
00753         accum = ull_shift (accum, 0U, carry);
00754         if (b & mask)
00755           accum = ull_add (accum, a, &c);
00756         else
00757           accum = ull_add (accum, zero, &c);
00758         *carry += c;
00759         mask >>= 1;
00760       }
00761     while (mask > 0);
00762 
00763   return accum;
00764 }
00765 
00766 ACE_INLINE ACE_U_LongLong
00767 ACE_U_LongLong::operator* (const ACE_UINT32 n) const
00768 {
00769   ACE_UINT32 carry;  // will throw the carry away
00770 
00771   return ull_mult (*this, n, &carry);
00772 }
00773 
00774 ACE_INLINE ACE_U_LongLong &
00775 ACE_U_LongLong::operator*= (const ACE_UINT32 n)
00776 {
00777   ACE_UINT32 carry;  // will throw the carry away
00778 
00779   return *this = ull_mult (*this, n, &carry);
00780 }
00781 
00782 ACE_INLINE ACE_U_LongLong &
00783 ACE_U_LongLong::operator-= (const ACE_U_LongLong &n)
00784 {
00785   h_ () -= n.h_ ();
00786   if (l_ () < n.l_ ()) /* borrow */ --h_ ();
00787   l_ () -= n.l_ ();
00788 
00789   return *this;
00790 }
00791 
00792 ACE_INLINE ACE_U_LongLong &
00793 ACE_U_LongLong::operator-= (const ACE_UINT32 n)
00794 {
00795   return operator-= (static_cast<const ACE_U_LongLong> (n));
00796 }
00797 
00798 ACE_INLINE ACE_U_LongLong &
00799 ACE_U_LongLong::operator++ ()
00800 {
00801   ++l_ ();
00802   if (l_ () == 0) /* carry */ ++h_ ();
00803 
00804   return *this;
00805 }
00806 
00807 ACE_INLINE ACE_U_LongLong &
00808 ACE_U_LongLong::operator-- ()
00809 {
00810   if (l_ () == 0) /* borrow */ --h_ ();
00811   --l_ ();
00812 
00813   return *this;
00814 }
00815 
00816 ACE_INLINE const ACE_U_LongLong
00817 ACE_U_LongLong::operator++ (int)
00818 {
00819   // Post-increment operator should always be implemented in terms of
00820   // the pre-increment operator to enforce consistent semantics.
00821   ACE_U_LongLong temp (*this);
00822   ++*this;
00823   return temp;
00824 }
00825 
00826 ACE_INLINE const ACE_U_LongLong
00827 ACE_U_LongLong::operator-- (int)
00828 {
00829   // Post-decrement operator should always be implemented in terms of
00830   // the pre-decrement operator to enforce consistent semantics.
00831   ACE_U_LongLong temp (*this);
00832   --*this;
00833   return temp;
00834 }
00835 
00836 ACE_INLINE ACE_U_LongLong &
00837 ACE_U_LongLong::operator|= (const ACE_U_LongLong n)
00838 {
00839   l_ () |= n.l_ ();
00840   h_ () |= n.h_ ();
00841 
00842   return *this;
00843 }
00844 
00845 ACE_INLINE ACE_U_LongLong &
00846 ACE_U_LongLong::operator|= (const ACE_UINT32 n)
00847 {
00848   return operator|= (static_cast<const ACE_U_LongLong> (n));
00849 }
00850 
00851 ACE_INLINE ACE_U_LongLong &
00852 ACE_U_LongLong::operator&= (const ACE_U_LongLong n)
00853 {
00854   l_ () &= n.l_ ();
00855   h_ () &= n.h_ ();
00856 
00857   return *this;
00858 }
00859 
00860 ACE_INLINE ACE_U_LongLong &
00861 ACE_U_LongLong::operator&= (const ACE_UINT32 n)
00862 {
00863   return operator&= (static_cast<const ACE_U_LongLong> (n));
00864 }
00865 
00866 ACE_INLINE ACE_UINT32
00867 ACE_U_LongLong::operator/ (const ACE_UINT32 n) const
00868 {
00869   // This takes advantage of the fact that the return type has only 32
00870   // bits.  Replace 0x100000000 with 0xffffffff + 1 because the former
00871   // has 33 bits.
00872   // Quotient = (0x100000000u * hi_ + lo_) / n
00873   //          = ((0x100000000u - n + n) * hi_ + lo_) / n
00874   //          = ((0x100000000u - n) / n * hi_  +  hi_ * n / n  +  lo_ / n
00875   //          = (0x100000000u - n) / n * hi_ +  hi_  +  lo_ / n
00876   //          = (0xffffffffu - n + 1) / n * hi_ +  hi_  +  lo_ / n
00877 
00878   return (0xffffffffu - n + 1) / n * h_ ()  +  h_ ()  +  l_ () / n;
00879 }
00880 
00881 ACE_INLINE ACE_UINT32
00882 ACE_U_LongLong::operator% (const ACE_UINT32 n) const
00883 {
00884   // Because the argument is an ACE_UINT32, the result can never be
00885   // bigger than 32 bits.  Replace 0x100000000 with 0xffffffff + 1
00886   // because the former has 33 bits.
00887   // Mod = (0x100000000u * hi_ + lo_) % n
00888   //     = (0x100000000u % n * hi_  +  lo_ % n) % n
00889   //     = ((0x100000000u - n) % n * hi_  +  lo_ % n) % n
00890   //     = ((0xffffffffu - n + 1) % n * hi_  +  lo_ % n) % n
00891 
00892   return ((0xffffffff - n + 1)  % n * h_ ()  +  l_ () % n) % n;
00893 }
00894 
00895 ACE_INLINE ACE_UINT32
00896 ACE_U_LongLong::operator| (const ACE_INT32 n) const
00897 {
00898   return l_ () | n;
00899 }
00900 
00901 ACE_INLINE ACE_UINT32
00902 ACE_U_LongLong::operator& (const ACE_INT32 n) const
00903 {
00904   return l_ () & n;
00905 }
00906 
00907 ACE_INLINE ACE_U_LongLong
00908 ACE_U_LongLong::operator* (const ACE_INT32 n) const
00909 {
00910   return operator* ((ACE_UINT32) n);
00911 }
00912 
00913 ACE_INLINE ACE_U_LongLong &
00914 ACE_U_LongLong::operator*= (const ACE_INT32 n)
00915 {
00916   return operator*= ((ACE_UINT32) n);
00917 }
00918 
00919 ACE_INLINE ACE_UINT32
00920 ACE_U_LongLong::operator/ (const ACE_INT32 n) const
00921 {
00922   return operator/ ((ACE_UINT32) n);
00923 }
00924 
00925 #if ACE_SIZEOF_INT == 4
00926 ACE_INLINE ACE_UINT32
00927 ACE_U_LongLong::operator/ (const u_long n) const
00928 {
00929   return operator/ ((ACE_UINT32) n);
00930 }
00931 
00932 ACE_INLINE ACE_UINT32
00933 ACE_U_LongLong::operator/ (const long n) const
00934 {
00935   return operator/ ((ACE_UINT32) n);
00936 }
00937 
00938 #else  /* ACE_SIZEOF_INT != 4 */
00939 ACE_INLINE ACE_UINT32
00940 ACE_U_LongLong::operator/ (const u_int n) const
00941 {
00942   return operator/ ((ACE_UINT32) n);
00943 }
00944 
00945 ACE_INLINE ACE_UINT32
00946 ACE_U_LongLong::operator/ (const int n) const
00947 {
00948   return operator/ ((ACE_UINT32) n);
00949 }
00950 #endif /* ACE_SIZEOF_INT != 4 */
00951 
00952 ACE_END_VERSIONED_NAMESPACE_DECL
00953 
00954 #endif /* ACE_LACKS_LONGLONG_T  || ACE_LACKS_UNSIGNEDLONGLONG_T */

Generated on Thu Nov 9 09:41:47 2006 for ACE by doxygen 1.3.6