LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 INRIA | 3 * Copyright (c) 2010 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 13 matching lines...) Expand all Loading... |
24 #define INT64X64_128_H | 24 #define INT64X64_128_H |
25 | 25 |
26 #include <stdint.h> | 26 #include <stdint.h> |
27 #include <cmath> // pow | 27 #include <cmath> // pow |
28 | 28 |
29 #if defined(HAVE___UINT128_T) && !defined(HAVE_UINT128_T) | 29 #if defined(HAVE___UINT128_T) && !defined(HAVE_UINT128_T) |
30 typedef __uint128_t uint128_t; ///< uint128 typedef | 30 typedef __uint128_t uint128_t; ///< uint128 typedef |
31 typedef __int128_t int128_t; ///< int128 typedef | 31 typedef __int128_t int128_t; ///< int128 typedef |
32 #endif | 32 #endif |
33 | 33 |
34 /** | |
35 * \ingroup highprec | |
36 * Declaration of the ns3::int64x64_t type using a native int128_t type.. | |
37 */ | |
38 | 34 |
39 namespace ns3 { | 35 namespace ns3 { |
40 | 36 |
41 /** | 37 /** |
42 * \internal | 38 * \internal |
| 39 * \ingroup highprec |
43 * The implementation documented here is based on native 128-bit integers. | 40 * The implementation documented here is based on native 128-bit integers. |
44 */ | 41 */ |
45 class int64x64_t | 42 class int64x64_t |
46 { | 43 { |
47 /// uint128_t high bit (sign bit). | 44 /// uint128_t high bit (sign bit). |
48 static const uint128_t HP128_MASK_HI_BIT = (((int128_t)1)<<127); | 45 static const uint128_t HP128_MASK_HI_BIT = (((int128_t)1)<<127); |
49 /// Mask for fraction part. | 46 /// Mask for fraction part. |
50 static const uint64_t HP_MASK_LO = 0xffffffffffffffffULL; | 47 static const uint64_t HP_MASK_LO = 0xffffffffffffffffULL; |
51 /// Mask for sign + integer part. | 48 /// Mask for sign + integer part. |
52 static const uint64_t HP_MASK_HI = ~HP_MASK_LO; | 49 static const uint64_t HP_MASK_HI = ~HP_MASK_LO; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 * | 249 * |
253 * (Really this should be a separate type representing Q0.128.) | 250 * (Really this should be a separate type representing Q0.128.) |
254 * | 251 * |
255 * \param [in] v The value to compute the inverse of. | 252 * \param [in] v The value to compute the inverse of. |
256 * \return A Q0.128 representation of the inverse. | 253 * \return A Q0.128 representation of the inverse. |
257 */ | 254 */ |
258 static int64x64_t Invert (const uint64_t v); | 255 static int64x64_t Invert (const uint64_t v); |
259 | 256 |
260 private: | 257 private: |
261 | 258 |
| 259 /** |
| 260 * \ingroup highprec |
| 261 * Equality operator |
| 262 * \param lhs the left hand side value |
| 263 * \param rhs the right hand side value |
| 264 * \returns true if the two values are equal |
| 265 */ |
262 friend bool operator == (const int64x64_t & lhs, const int64x64_t & rh
s); | 266 friend bool operator == (const int64x64_t & lhs, const int64x64_t & rh
s); |
263 | 267 |
| 268 /** |
| 269 * \ingroup highprec |
| 270 * Less than operator. |
| 271 * \param lhs the left hand side value |
| 272 * \param rhs the right hand side value |
| 273 * \returns true if the left hand value is less than the right hand value |
| 274 */ |
264 friend bool operator < (const int64x64_t & lhs, const int64x64_t & rh
s); | 275 friend bool operator < (const int64x64_t & lhs, const int64x64_t & rh
s); |
| 276 /** |
| 277 * \ingroup highprec |
| 278 * Greater than operator. |
| 279 * \param lhs the left hand side value |
| 280 * \param rhs the right hand side value |
| 281 * \returns true if the left hand value is greater than the right hand value |
| 282 */ |
265 friend bool operator > (const int64x64_t & lhs, const int64x64_t & rh
s); | 283 friend bool operator > (const int64x64_t & lhs, const int64x64_t & rh
s); |
266 ·· | 284 ·· |
| 285 /** |
| 286 * \ingroup highprec |
| 287 * Addition operator. |
| 288 * \param lhs the left hand side value |
| 289 * \param rhs the right hand side value |
| 290 * \returns the sum of the two values |
| 291 */ |
267 friend int64x64_t & operator += ( int64x64_t & lhs, const int64x64_t & rh
s); | 292 friend int64x64_t & operator += ( int64x64_t & lhs, const int64x64_t & rh
s); |
| 293 /** |
| 294 * \ingroup highprec |
| 295 * Subrtracgtion operator. |
| 296 * \param lhs the left hand side value |
| 297 * \param rhs the right hand side value |
| 298 * \returns the difference of the two values |
| 299 */ |
268 friend int64x64_t & operator -= ( int64x64_t & lhs, const int64x64_t & rh
s); | 300 friend int64x64_t & operator -= ( int64x64_t & lhs, const int64x64_t & rh
s); |
| 301 /** |
| 302 * \ingroup highprec |
| 303 * Multiplication operator. |
| 304 * \param lhs the left hand side value |
| 305 * \param rhs the right hand side value |
| 306 * \returns the product of the two values |
| 307 */ |
269 friend int64x64_t & operator *= ( int64x64_t & lhs, const int64x64_t & rh
s); | 308 friend int64x64_t & operator *= ( int64x64_t & lhs, const int64x64_t & rh
s); |
| 309 /** |
| 310 * \ingroup highprec |
| 311 * Division operator. |
| 312 * \param lhs the left hand side value |
| 313 * \param rhs the right hand side value |
| 314 * \returns the division of the two values |
| 315 */ |
270 friend int64x64_t & operator /= ( int64x64_t & lhs, const int64x64_t & rh
s); | 316 friend int64x64_t & operator /= ( int64x64_t & lhs, const int64x64_t & rh
s); |
271 | 317 |
| 318 /** |
| 319 * \ingroup highprec |
| 320 * Negation operator. |
| 321 * \param lhs the left hand side value |
| 322 * \returns the negation of the value |
| 323 */ |
272 friend int64x64_t operator - (const int64x64_t & lhs); | 324 friend int64x64_t operator - (const int64x64_t & lhs); |
| 325 /** |
| 326 * \ingroup highprec |
| 327 * Not operator. |
| 328 * \param lhs the left hand side value |
| 329 * \returns the not of the value |
| 330 */ |
273 friend int64x64_t operator ! (const int64x64_t & lhs); | 331 friend int64x64_t operator ! (const int64x64_t & lhs); |
274 | 332 |
275 /** | 333 /** |
276 * Implement `*=`. | 334 * Implement `*=`. |
277 * | 335 * |
278 * \param [in] o The other factor. | 336 * \param [in] o The other factor. |
279 */··· | 337 */··· |
280 void Mul (const int64x64_t & o); | 338 void Mul (const int64x64_t & o); |
281 /** | 339 /** |
282 * Implement `/=`. | 340 * Implement `/=`. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 */ | 457 */ |
400 inline int64x64_t & operator /= (int64x64_t & lhs, const int64x64_t & rhs) | 458 inline int64x64_t & operator /= (int64x64_t & lhs, const int64x64_t & rhs) |
401 { | 459 { |
402 lhs.Div (rhs); | 460 lhs.Div (rhs); |
403 return lhs; | 461 return lhs; |
404 } | 462 } |
405 | 463 |
406 /** | 464 /** |
407 * \ingroup highprec | 465 * \ingroup highprec |
408 * Unary plus operator. | 466 * Unary plus operator. |
| 467 * \param lhs the left hand side value |
| 468 * \returns the sum of the values |
409 */ | 469 */ |
410 inline int64x64_t operator + (const int64x64_t & lhs) | 470 inline int64x64_t operator + (const int64x64_t & lhs) |
411 { | 471 { |
412 return lhs; | 472 return lhs; |
413 } | 473 } |
414 /** | 474 /** |
415 * \ingroup highprec | 475 * \ingroup highprec |
416 * Unary negation operator (change sign operator). | 476 * Unary negation operator (change sign operator). |
| 477 * \param lhs the left hand side value |
| 478 * \returns the negation of the value |
417 */ | 479 */ |
418 inline int64x64_t operator - (const int64x64_t & lhs) | 480 inline int64x64_t operator - (const int64x64_t & lhs) |
419 { | 481 { |
420 return int64x64_t (-lhs._v); | 482 return int64x64_t (-lhs._v); |
421 } | 483 } |
422 /** | 484 /** |
423 * \ingroup highprec | 485 * \ingroup highprec |
424 * Logical not operator. | 486 * Logical not operator. |
| 487 * \param lhs the left hand side value |
| 488 * \returns the not value |
425 */ | 489 */ |
426 inline int64x64_t operator ! (const int64x64_t & lhs) | 490 inline int64x64_t operator ! (const int64x64_t & lhs) |
427 { | 491 { |
428 return int64x64_t (!lhs._v); | 492 return int64x64_t (!lhs._v); |
429 } | 493 } |
430 | 494 |
431 | 495 |
432 } // namespace ns3 | 496 } // namespace ns3 |
433 | 497 |
434 #endif /* INT64X64_128_H */ | 498 #endif /* INT64X64_128_H */ |
LEFT | RIGHT |