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 <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2021-03-07 22:33:13 -08:00
parent 85ff3c1371
commit 4dcfa34c18
5 changed files with 8 additions and 36 deletions

View File

@@ -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);
'''

View File

@@ -46,28 +46,8 @@
#include <type_traits>
#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
*/

View File

@@ -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));

View File

@@ -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<uint32_t>(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<uint32_t>(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()) {

View File

@@ -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<uint32_t>(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