From 8ed4f0a02cd936f717f5af0c15b64fedddd5af54 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Mon, 23 Aug 2010 11:18:40 -0500 Subject: ARM: Add I/O devices for booting linux --HG-- rename : src/dev/arm/Versatile.py => src/dev/arm/RealView.py rename : src/dev/arm/versatile.cc => src/dev/arm/realview.cc rename : src/dev/arm/versatile.hh => src/dev/arm/realview.hh --- src/base/intmath.hh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/base') diff --git a/src/base/intmath.hh b/src/base/intmath.hh index a2960e750..b8c83f05a 100644 --- a/src/base/intmath.hh +++ b/src/base/intmath.hh @@ -33,6 +33,7 @@ #include +#include "base/misc.hh" #include "base/types.hh" // Returns the prime number one less than n. @@ -74,6 +75,27 @@ isPowerOf2(T n) return n != 0 && leastSigBit(n) == n; } +inline uint64_t +power(uint32_t n, uint32_t e) +{ + if (e > 20) + warn("Warning, power() function is quite slow for large exponents\n"); + + if (e == 0) + return 1; + + uint64_t result = n; + uint64_t old_result = 0; + for (int x = 1; x < e; x++) { + old_result = result; + result *= n; + if (old_result > result) + warn("power() overflowed!\n"); + } + return result; +} + + inline int floorLog2(unsigned x) { -- cgit v1.2.3