From 303c21178a3e28cc8ef3400877d416fd955737e0 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 30 May 2009 13:12:22 +0200 Subject: cdatn fix --- ue4/mycpu/cdatn.h | 53 ++++++++++++++++------------------------------------- ue4/mycpu/mycpu.cpp | 2 +- 2 files changed, 17 insertions(+), 38 deletions(-) diff --git a/ue4/mycpu/cdatn.h b/ue4/mycpu/cdatn.h index cd6573a..4e68f0b 100644 --- a/ue4/mycpu/cdatn.h +++ b/ue4/mycpu/cdatn.h @@ -68,13 +68,16 @@ class CDatN * @param width maximum width * @return - * @globalvars none - * @exception none + * @exception std::runtime_error * @pre none * @post none */ CDatN(const int newval, unsigned width = 31) : m_value(((1 << width) - 1) & newval), m_width(width) - {} + { + if (width < 2 || width > 32) + throw std::runtime_error("width must be between 2 and 32"); + } /** * @method getValue @@ -148,8 +151,7 @@ class CDatN */ CDatN &operator=(const int& newval) { - m_value = newval; - align(); + m_value = ((1 << m_width) - 1) & newval; return *this; } @@ -165,8 +167,7 @@ class CDatN */ CDatN& operator+=(const CDatN& x) { - m_value += x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value + x.m_value); return *this; } @@ -182,8 +183,7 @@ class CDatN */ CDatN& operator-=(const CDatN& x) { - m_value -= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value - x.m_value); return *this; } @@ -199,8 +199,7 @@ class CDatN */ CDatN& operator*=(const CDatN& x) { - m_value *= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value * x.m_value); return *this; } @@ -216,8 +215,7 @@ class CDatN */ CDatN& operator/=(const CDatN& x) { - m_value /= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value / x.m_value); return *this; } @@ -233,8 +231,7 @@ class CDatN */ CDatN& operator%=(const CDatN& x) { - m_value %= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value % x.m_value); return *this; } @@ -250,8 +247,7 @@ class CDatN */ CDatN& operator|=(const CDatN& x) { - m_value |= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value | x.m_value); return *this; } @@ -267,8 +263,7 @@ class CDatN */ CDatN& operator&=(const CDatN& x) { - m_value &= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value & x.m_value); return *this; } @@ -284,8 +279,7 @@ class CDatN */ CDatN& operator^=(const CDatN& x) { - m_value ^= x.m_value; - align(); + m_value = ((1 << m_width) - 1) & (m_value ^ x.m_value); return *this; } @@ -301,8 +295,7 @@ class CDatN */ CDatN& operator++() { - m_value++; - align(); + m_value = ((1 << m_width) - 1) & (m_value + 1); return *this; } @@ -353,25 +346,11 @@ class CDatN friend std::istream& operator>>(std::istream & stream, CDatN& cdat) { stream >> cdat.m_value; - cdat.align(); + cdat.m_value = ((1 << cdat.m_width) - 1) & cdat.m_value; return stream; } protected: - /** - * @method align - * @brief aligns value by width - * @return - - * @globalvars none - * @exception none - * @pre none - * @post bit count of m_value trimmed to width - */ - inline void align() - { - m_value &= ((1 << m_width) - 1); - } - /* members */ /** internal value of datatype */ int m_value; diff --git a/ue4/mycpu/mycpu.cpp b/ue4/mycpu/mycpu.cpp index e9525d2..aefe0cb 100644 --- a/ue4/mycpu/mycpu.cpp +++ b/ue4/mycpu/mycpu.cpp @@ -180,7 +180,7 @@ int main(int argc, char* argv[]) return 1; } - if (bc < 2 || bc > 31) + if (bc < 2 || bc > 32) { cerr << me << ": Paramater 'format' must be inbetween 2 and 32." << endl; return 1; -- cgit v1.2.3