From 4dcfa34c1877b64090c4ee83b3cb58a7f9e9a3d8 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 7 Mar 2021 22:33:13 -0800 Subject: [PATCH] arch-arm,base,dev: Eliminate the power() function from intmath.hh. This function causes problems with gcc 5 which incorrectly complains about the call to warn_if inside a constexpr function. That should only be an error if a call to a non-constexpr is unavoidable, and even then the compiler isn't required to emit a diagnostic. Rather than drop the warning, or add ifdefs to deal with these defective versions of gcc, this change eliminates the power() function entirely. Most inputs to this function would overflow anyway, which is reportedly why no integer version of an exponentiation function is defined in the standard library, and all uses of this function can easily and more efficiently be replaced by simple left and right shifts. Finally, by eliminating the power() function, we also remove the dependence on base/logging.hh. Change-Id: I4d014163883d12db46da4ee752696c8225534ee8 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42504 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/arch/arm/isa/insts/data64.isa | 2 +- src/base/intmath.hh | 20 -------------------- src/base/intmath.test.cc | 7 ------- src/dev/arm/timer_cpulocal.cc | 11 +++++------ src/dev/arm/timer_sp804.cc | 4 ++-- 5 files changed, 8 insertions(+), 36 deletions(-) diff --git a/src/arch/arm/isa/insts/data64.isa b/src/arch/arm/isa/insts/data64.isa index 1cd17b79a2..46a046becf 100644 --- a/src/arch/arm/isa/insts/data64.isa +++ b/src/arch/arm/isa/insts/data64.isa @@ -382,7 +382,7 @@ let {{ Request::Flags memAccessFlags = Request::CACHE_BLOCK_ZERO; EA = XBase; assert(!(Dczid & 0x10)); - uint64_t op_size = power(2, Dczid + 2); + uint64_t op_size = 1ULL << (Dczid + 2); EA &= ~(op_size - 1); ''' diff --git a/src/base/intmath.hh b/src/base/intmath.hh index ba2017782a..85ee52544d 100644 --- a/src/base/intmath.hh +++ b/src/base/intmath.hh @@ -46,28 +46,8 @@ #include #include "base/bitfield.hh" -#include "base/logging.hh" #include "base/types.hh" -/** - * @ingroup api_base_utils - */ -static constexpr uint64_t -power(uint32_t n, uint32_t e) -{ - uint64_t result = 1; - uint64_t component = n; - while (e) { - uint64_t last = result; - if (e & 0x1) - result *= component; - warn_if(result < last, "power() overflowed!"); - e >>= 1; - component *= component; - } - return result; -} - /** * @ingroup api_base_utils */ diff --git a/src/base/intmath.test.cc b/src/base/intmath.test.cc index e953a7e735..b4bd2a5445 100644 --- a/src/base/intmath.test.cc +++ b/src/base/intmath.test.cc @@ -54,13 +54,6 @@ TEST(IntmathTest, isPowerOf2) EXPECT_FALSE(isPowerOf2(1679616)); } -TEST(IntmathTest, power) -{ - EXPECT_EQ(65536, power(2, 16)); - EXPECT_EQ(9765625, power(5, 10)); - EXPECT_EQ(43046721, power(power(3, 4), 4)); -} - TEST(IntmathTest, floorLog2) { EXPECT_EQ(0, floorLog2(1)); diff --git a/src/dev/arm/timer_cpulocal.cc b/src/dev/arm/timer_cpulocal.cc index 760adf5959..3b120f6e77 100644 --- a/src/dev/arm/timer_cpulocal.cc +++ b/src/dev/arm/timer_cpulocal.cc @@ -123,8 +123,7 @@ CpuLocalTimer::Timer::read(PacketPtr pkt, Addr daddr) timerZeroEvent.when(), parent->clockPeriod(), timerControl.prescalar); time = timerZeroEvent.when() - curTick(); - time = time / parent->clockPeriod() / - power(16, timerControl.prescalar); + time = (time / parent->clockPeriod()) >> (4 * timerControl.prescalar); DPRINTF(Timer, "-- returning counter at %d\n", time); pkt->setLE(time); break; @@ -143,8 +142,8 @@ CpuLocalTimer::Timer::read(PacketPtr pkt, Addr daddr) watchdogZeroEvent.when(), parent->clockPeriod(), watchdogControl.prescalar); time = watchdogZeroEvent.when() - curTick(); - time = time / parent->clockPeriod() / - power(16, watchdogControl.prescalar); + time = (time / parent->clockPeriod()) >> + (4 * watchdogControl.prescalar); DPRINTF(Timer, "-- returning counter at %d\n", time); pkt->setLE(time); break; @@ -269,7 +268,7 @@ CpuLocalTimer::Timer::restartTimerCounter(uint32_t val) if (!timerControl.enable) return; - Tick time = parent->clockPeriod() * power(16, timerControl.prescalar); + Tick time = parent->clockPeriod() << (4 * timerControl.prescalar); time *= val; if (timerZeroEvent.scheduled()) { @@ -287,7 +286,7 @@ CpuLocalTimer::Timer::restartWatchdogCounter(uint32_t val) if (!watchdogControl.enable) return; - Tick time = parent->clockPeriod() * power(16, watchdogControl.prescalar); + Tick time = parent->clockPeriod() << (4 * watchdogControl.prescalar); time *= val; if (watchdogZeroEvent.scheduled()) { diff --git a/src/dev/arm/timer_sp804.cc b/src/dev/arm/timer_sp804.cc index 6403a7716f..f69da13c4b 100644 --- a/src/dev/arm/timer_sp804.cc +++ b/src/dev/arm/timer_sp804.cc @@ -96,7 +96,7 @@ Sp804::Timer::read(PacketPtr pkt, Addr daddr) zeroEvent.when(), clock, control.timerPrescale); Tick time; time = zeroEvent.when() - curTick(); - time = time / clock / power(16, control.timerPrescale); + time = (time / clock) >> (4 * control.timerPrescale); DPRINTF(Timer, "-- returning counter at %d\n", time); pkt->setLE(time); break; @@ -182,7 +182,7 @@ Sp804::Timer::restartCounter(uint32_t val) if (!control.timerEnable) return; - Tick time = clock * power(16, control.timerPrescale); + Tick time = clock << (4 * control.timerPrescale); if (control.timerSize) time *= val; else