base: Introduce versions of mul(Uns|S)igned which return two values.
This makes code which needs to call lots of different sized multiplications. Change-Id: Id0d28be4c304214171840e7916c2e90ecfcd3840 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42360 Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "base/bitfield.hh"
|
||||
|
||||
@@ -223,6 +224,24 @@ mulSigned(std::make_signed_t<T> &high, std::make_signed_t<T> &low,
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr std::pair<std::make_unsigned_t<T>, std::make_unsigned_t<T>>
|
||||
mulUnsigned(std::make_unsigned_t<T> val_a, std::make_unsigned_t<T> val_b)
|
||||
{
|
||||
std::make_unsigned_t<T> hi, low;
|
||||
mulUnsigned<T>(hi, low, val_a, val_b);
|
||||
return {hi, low};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static constexpr std::pair<std::make_signed_t<T>, std::make_signed_t<T>>
|
||||
mulSigned(std::make_signed_t<T> val_a, std::make_signed_t<T> val_b)
|
||||
{
|
||||
std::make_signed_t<T> hi, low;
|
||||
mulSigned<T>(hi, low, val_a, val_b);
|
||||
return {hi, low};
|
||||
};
|
||||
|
||||
/**
|
||||
* This function is used to align addresses in memory.
|
||||
*
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <tuple>
|
||||
|
||||
#include "base/intmath.hh"
|
||||
|
||||
@@ -220,6 +221,12 @@ TEST(IntmathTest, mulUnsignedWide)
|
||||
EXPECT_EQ(hi, 0x1);
|
||||
EXPECT_EQ(low, 0xfffffffffffffffe);
|
||||
|
||||
hi = 0;
|
||||
low = 0;
|
||||
std::tie(hi, low) = mulUnsigned<uint64_t>(a, b);
|
||||
EXPECT_EQ(hi, 0x1);
|
||||
EXPECT_EQ(low, 0xfffffffffffffffe);
|
||||
|
||||
a = 0;
|
||||
b = 0x5555555555555555;
|
||||
mulUnsigned<uint64_t>(hi, low, a, b);
|
||||
@@ -243,6 +250,12 @@ TEST(IntmathTest, mulSignedWide)
|
||||
EXPECT_EQ(hi, 0x3fffffffffffffff);
|
||||
EXPECT_EQ(low, -0x8000000000000000);
|
||||
|
||||
hi = 0;
|
||||
low = 0;
|
||||
std::tie(hi, low) = mulSigned<int64_t>(a, b);
|
||||
EXPECT_EQ(hi, 0x3fffffffffffffff);
|
||||
EXPECT_EQ(low, -0x8000000000000000);
|
||||
|
||||
a = 0;
|
||||
b = -0x5555555555555555;
|
||||
mulSigned<int64_t>(hi, low, a, b);
|
||||
|
||||
Reference in New Issue
Block a user