We already offer zextOrTrunc and it seems natural to offer the
same capability for sign extension.
This patch is a preparatory addition useful for future computeKnownBits
developments.
Differential D88937
[KnownBits] Add a sextOrTrunc method Authored by qcolombet on Oct 6 2020, 4:32 PM.
Details We already offer zextOrTrunc and it seems natural to offer the This patch is a preparatory addition useful for future computeKnownBits
Diff Detail
Unit Tests
Event TimelineComment Actions Hi @lebedev.ri ,
I didn't see a test for zextOrTrunc that I could mimic so I come up with something. Let me know what do you think. Cheers, Comment Actions Seems fine
| ||||||||||||
I guess i was thinking of something like this:
TEST(KnownBitsTest, GetMinMaxVal) { const unsigned NarrowerSize = 4; const unsigned BaseSize = 6; const unsigned WiderSize = 8; ForeachKnownBits(BaseSize, [&](const KnownBits &KnownBase) { for (unsigned Size : {NarrowerSize, BaseSize, WiderSize}) { KnownBits Test; if(Size == BaseSize) Test = KnownBase else Test = Size < BaseSize ? KnownBase.trunc(Size) : KnownBase.sext(Size); EXPECT_EQ(Test, KnownBase.sextOrTrunc(Size)); } }); }which seems pretty tautological i guess, so maybe we should go with your test.