1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: util_Int64.h 4 5 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 28559 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_UTIL_UTIL_INT64_H_ 17 #define NN_UTIL_UTIL_INT64_H_ 18 19 #include <nn/types.h> 20 #include <nn/util/util_StaticAssert.h> 21 #include <nn/util/util_TypeTraits.h> 22 23 #ifdef __cplusplus 24 25 namespace nn { namespace util { 26 27 template <typename Base, typename Tag = void> 28 struct Int64 29 { 30 bit32 lo; 31 bit32 hi; Int64Int6432 Int64() {} Int64Int6433 Int64(Base s) : lo(static_cast<bit32>(s)), hi(static_cast<bit32>(s >> 32)) {} BaseInt6434 operator Base() const { return (static_cast<Base>(hi) << 32) | static_cast<Base>(lo); } 35 Int64& operator++() { Base lhs = *this; lhs++; *this = lhs; return *this; } 36 Int64& operator--() { Base lhs = *this; lhs--; *this = lhs; return *this; } 37 Int64& operator+=(Base rhs) { Base lhs = *this; lhs += rhs; *this = lhs; return *this; } 38 Int64& operator-=(Base rhs) { Base lhs = *this; lhs -= rhs; *this = lhs; return *this; } 39 Int64& operator*=(Base rhs) { Base lhs = *this; lhs *= rhs; *this = lhs; return *this; } 40 Int64& operator/=(Base rhs) { Base lhs = *this; lhs /= rhs; *this = lhs; return *this; } 41 Int64& operator%=(Base rhs) { Base lhs = *this; lhs %= rhs; *this = lhs; return *this; } 42 Int64& operator|=(Base rhs) { Base lhs = *this; lhs |= rhs; *this = lhs; return *this; } 43 Int64& operator&=(Base rhs) { Base lhs = *this; lhs &= rhs; *this = lhs; return *this; } 44 Int64& operator^=(Base rhs) { Base lhs = *this; lhs ^= rhs; *this = lhs; return *this; } 45 Int64& operator<<=(int rhs) { Base lhs = *this; lhs <<= rhs; *this = lhs; return *this; } 46 Int64& operator>>=(int rhs) { Base lhs = *this; lhs >>= rhs; *this = lhs; return *this; } 47 Int64 operator++(int) { Base lhs = *this; *this = lhs + 1; return Int64(lhs); } 48 Int64 operator--(int) { Base lhs = *this; *this = lhs - 1; return Int64(lhs); } 49 Int64Int6450 Int64(const Int64<Base, void>& other) : lo(other.lo), hi(other.hi) {} 51 #pragma push 52 #pragma diag_suppress 554 Int64Int6453 operator Int64<Base, void>() const { return static_cast<Base>(*this); } 54 #pragma pop 55 56 bool operator==(Int64 rhs) const { return this->hi == rhs.hi && this->lo == rhs.lo; } 57 bool operator!=(Int64 rhs) const { return !(*this == rhs); } 58 friend bool operator==(Int64 lhs, Base rhs) { return static_cast<Base>(lhs) == rhs; } 59 friend bool operator!=(Int64 lhs, Base rhs) { return !(lhs == rhs); } 60 friend bool operator==(Base lhs, Int64 rhs) { return lhs == static_cast<Base>(rhs); } 61 friend bool operator!=(Base lhs, Int64 rhs) { return !(lhs == rhs); } 62 63 bool operator<(Int64 rhs) const { return static_cast<Base>(*this) < static_cast<Base>(rhs); } 64 bool operator>(Int64 rhs) const { return rhs < *this; } 65 bool operator<(Base rhs) const { return static_cast<Base>(*this) < rhs; } 66 bool operator>(Base rhs) const { return rhs < *this; } 67 bool operator<=(Int64 rhs) const { return !(*this > rhs); } 68 bool operator>=(Int64 rhs) const { return !(*this < rhs); } 69 bool operator<=(Base rhs) const { return !(static_cast<Base>(*this) > rhs); } 70 bool operator>=(Base rhs) const { return !(static_cast<Base>(*this) < rhs); } 71 }; 72 73 }} 74 75 76 #endif 77 78 #endif 79