#include <inttypes.h>
+#include <cassert>
+
/** uint64_t constant */
#define ULL(N) ((uint64_t)N##ULL)
/** int64_t constant */
typedef int64_t Counter;
/**
- * Clock cycle count type.
- * @note using an unsigned breaks the cache.
+ * Tick count type.
*/
-typedef int64_t Tick;
-typedef uint64_t UTick;
+typedef uint64_t Tick;
-const Tick MaxTick = LL(0x7fffffffffffffff);
+const Tick MaxTick = ULL(0xffffffffffffffff);
+
+/**
+ * Cycles is a wrapper class for representing cycle counts, i.e. a
+ * relative difference between two points in time, expressed in a
+ * number of clock cycles.
+ *
+ * The Cycles wrapper class is a type-safe alternative to a
+ * typedef, aiming to avoid unintentional mixing of cycles and ticks
+ * in the code base.
+ *
+ * Operators are defined inside an ifndef block to avoid swig touching
+ * them. Note that there is no overloading of the bool operator as the
+ * compiler is allowed to turn booleans into integers and this causes
+ * a whole range of issues in a handful locations. The solution to
+ * this problem would be to use the safe bool idiom, but for now we
+ * make do without the test and use the more elaborate comparison >
+ * Cycles(0).
+ */
+class Cycles
+{
+
+ private:
+
+ /** Member holding the actual value. */
+ uint64_t c;
+
+ public:
+
+ /** Explicit constructor assigning a value. */
+ explicit Cycles(uint64_t _c) : c(_c) { }
+
+ /** Default constructor for parameter classes. */
+ Cycles() : c(0) { }
+
+#ifndef SWIG // keep the operators away from SWIG
+
+ /** Converting back to the value type. */
+ operator uint64_t() const { return c; }
+
+ /** Prefix increment operator. */
+ Cycles& operator++()
+ { ++c; return *this; }
+
+ /** Prefix decrement operator. Is only temporarily used in the O3 CPU. */
+ Cycles& operator--()
+ { assert(c != 0); --c; return *this; }
+
+ /** In-place addition of cycles. */
+ const Cycles& operator+=(const Cycles& cc)
+ { c += cc.c; return *this; }
+
+ /** Greater than comparison used for > Cycles(0). */
+ bool operator>(const Cycles& cc) const
+ { return c > cc.c; }
+
+#endif // SWIG not touching operators
+
+};
/**
* Address type
typedef int16_t ThreadID;
const ThreadID InvalidThreadID = (ThreadID)-1;
+/**
+ * Port index/ID type, and a symbolic name for an invalid port id.
+ */
+typedef int16_t PortID;
+const PortID InvalidPortID = (PortID)-1;
+
class FaultBase;
template <class T> class RefCountingPtr;
typedef RefCountingPtr<FaultBase> Fault;