types.hh (10839:10cac0f0f419) | types.hh (11004:2c347b12cc9c) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 28 unchanged lines hidden (view full) --- 37#ifndef __BASE_TYPES_HH__ 38#define __BASE_TYPES_HH__ 39 40#include <inttypes.h> 41 42#include <cassert> 43#include <memory> 44#include <ostream> | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 28 unchanged lines hidden (view full) --- 37#ifndef __BASE_TYPES_HH__ 38#define __BASE_TYPES_HH__ 39 40#include <inttypes.h> 41 42#include <cassert> 43#include <memory> 44#include <ostream> |
45#include <stdexcept> |
|
45 46#include "base/refcnt.hh" 47 48/** uint64_t constant */ 49#define ULL(N) ((uint64_t)N##ULL) 50/** int64_t constant */ 51#define LL(N) ((int64_t)N##LL) 52 --- 32 unchanged lines hidden (view full) --- 85 86 private: 87 88 /** Member holding the actual value. */ 89 uint64_t c; 90 91 public: 92 | 46 47#include "base/refcnt.hh" 48 49/** uint64_t constant */ 50#define ULL(N) ((uint64_t)N##ULL) 51/** int64_t constant */ 52#define LL(N) ((int64_t)N##LL) 53 --- 32 unchanged lines hidden (view full) --- 86 87 private: 88 89 /** Member holding the actual value. */ 90 uint64_t c; 91 92 public: 93 |
94#ifndef SWIG // SWIG gets confused by constexpr |
|
93 /** Explicit constructor assigning a value. */ | 95 /** Explicit constructor assigning a value. */ |
96 explicit constexpr Cycles(uint64_t _c) : c(_c) { } 97#else |
|
94 explicit Cycles(uint64_t _c) : c(_c) { } | 98 explicit Cycles(uint64_t _c) : c(_c) { } |
99#endif |
|
95 96 /** Default constructor for parameter classes. */ 97 Cycles() : c(0) { } 98 99#ifndef SWIG // keep the operators away from SWIG 100 101 /** Converting back to the value type. */ | 100 101 /** Default constructor for parameter classes. */ 102 Cycles() : c(0) { } 103 104#ifndef SWIG // keep the operators away from SWIG 105 106 /** Converting back to the value type. */ |
102 operator uint64_t() const { return c; } | 107 constexpr operator uint64_t() const { return c; } |
103 104 /** Prefix increment operator. */ 105 Cycles& operator++() 106 { ++c; return *this; } 107 108 /** Prefix decrement operator. Is only temporarily used in the O3 CPU. */ 109 Cycles& operator--() 110 { assert(c != 0); --c; return *this; } 111 112 /** In-place addition of cycles. */ | 108 109 /** Prefix increment operator. */ 110 Cycles& operator++() 111 { ++c; return *this; } 112 113 /** Prefix decrement operator. Is only temporarily used in the O3 CPU. */ 114 Cycles& operator--() 115 { assert(c != 0); --c; return *this; } 116 117 /** In-place addition of cycles. */ |
113 const Cycles& operator+=(const Cycles& cc) | 118 Cycles& operator+=(const Cycles& cc) |
114 { c += cc.c; return *this; } 115 116 /** Greater than comparison used for > Cycles(0). */ | 119 { c += cc.c; return *this; } 120 121 /** Greater than comparison used for > Cycles(0). */ |
117 bool operator>(const Cycles& cc) const | 122 constexpr bool operator>(const Cycles& cc) const |
118 { return c > cc.c; } 119 | 123 { return c > cc.c; } 124 |
120 const Cycles operator +(const Cycles& b) const | 125 constexpr Cycles operator +(const Cycles& b) const |
121 { return Cycles(c + b.c); } 122 | 126 { return Cycles(c + b.c); } 127 |
123 const Cycles operator -(const Cycles& b) const 124 { assert(c >= b.c); return Cycles(c - b.c); } | 128 constexpr Cycles operator -(const Cycles& b) const 129 { 130 return c >= b.c ? Cycles(c - b.c) : 131 throw std::invalid_argument("RHS cycle value larger than LHS"); 132 } |
125 | 133 |
126 const Cycles operator <<(const int32_t shift) | 134 constexpr Cycles operator <<(const int32_t shift) const |
127 { return Cycles(c << shift); } 128 | 135 { return Cycles(c << shift); } 136 |
129 const Cycles operator >>(const int32_t shift) | 137 constexpr Cycles operator >>(const int32_t shift) const |
130 { return Cycles(c >> shift); } 131 132 friend std::ostream& operator<<(std::ostream &out, const Cycles & cycles); 133 134#endif // SWIG not touching operators 135 136}; 137 --- 59 unchanged lines hidden --- | 138 { return Cycles(c >> shift); } 139 140 friend std::ostream& operator<<(std::ostream &out, const Cycles & cycles); 141 142#endif // SWIG not touching operators 143 144}; 145 --- 59 unchanged lines hidden --- |