mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[APInt] Add the truncOrSelf resizing operator to APInt
Truncates the APInt if the bit width is greater than the width specified, otherwise do nothing Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D91445
This commit is contained in:
parent
6292b13e69
commit
1a23665577
@ -1403,6 +1403,12 @@ public:
|
||||
/// extended, truncated, or left alone to make it that width.
|
||||
APInt zextOrTrunc(unsigned width) const;
|
||||
|
||||
/// Truncate to width
|
||||
///
|
||||
/// Make this APInt have the bit width given by \p width. The value is
|
||||
/// truncated or left alone to make it that width.
|
||||
APInt truncOrSelf(unsigned width) const;
|
||||
|
||||
/// Sign extend or truncate to width
|
||||
///
|
||||
/// Make this APInt have the bit width given by \p width. The value is sign
|
||||
|
@ -961,6 +961,12 @@ APInt APInt::sextOrTrunc(unsigned width) const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
APInt APInt::truncOrSelf(unsigned width) const {
|
||||
if (BitWidth > width)
|
||||
return trunc(width);
|
||||
return *this;
|
||||
}
|
||||
|
||||
APInt APInt::zextOrSelf(unsigned width) const {
|
||||
if (BitWidth < width)
|
||||
return zext(width);
|
||||
|
@ -2598,6 +2598,13 @@ TEST(APIntTest, sext) {
|
||||
EXPECT_EQ(63U, i32_neg1.countPopulation());
|
||||
}
|
||||
|
||||
TEST(APIntTest, truncOrSelf) {
|
||||
APInt val(32, 0xFFFFFFFF);
|
||||
EXPECT_EQ(0xFFFF, val.truncOrSelf(16));
|
||||
EXPECT_EQ(0xFFFFFFFF, val.truncOrSelf(32));
|
||||
EXPECT_EQ(0xFFFFFFFF, val.truncOrSelf(64));
|
||||
}
|
||||
|
||||
TEST(APIntTest, multiply) {
|
||||
APInt i64(64, 1234);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user