Skip to content

Commit 460e843

Browse files
authored
[RISCV] Add getSameRatioLMUL (#69570)
To calculate the LMUL with the same SEW/LMUL ratio when providing EEW.
1 parent b1a6b2c commit 460e843

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ unsigned RISCVVType::getSEWLMULRatio(unsigned SEW, RISCVII::VLMUL VLMul) {
206206
return (SEW * 8) / LMul;
207207
}
208208

209+
RISCVII::VLMUL RISCVVType::getSameRatioLMUL(unsigned SEW, RISCVII::VLMUL VLMUL,
210+
unsigned EEW) {
211+
unsigned Ratio = RISCVVType::getSEWLMULRatio(SEW, VLMUL);
212+
unsigned EMULFixedPoint = (EEW * 8) / Ratio;
213+
bool Fractional = EMULFixedPoint < 8;
214+
unsigned EMUL = Fractional ? 8 / EMULFixedPoint : EMULFixedPoint / 8;
215+
return RISCVVType::encodeLMUL(EMUL, Fractional);
216+
}
217+
209218
// Include the auto-generated portion of the compress emitter.
210219
#define GEN_UNCOMPRESS_INSTR
211220
#define GEN_COMPRESS_INSTR

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ void printVType(unsigned VType, raw_ostream &OS);
535535

536536
unsigned getSEWLMULRatio(unsigned SEW, RISCVII::VLMUL VLMul);
537537

538+
RISCVII::VLMUL getSameRatioLMUL(unsigned SEW, RISCVII::VLMUL VLMUL,
539+
unsigned EEW);
538540
} // namespace RISCVVType
539541

540542
namespace RISCVRVC {

llvm/unittests/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(LLVM_LINK_COMPONENTS
1313

1414
add_llvm_target_unittest(RISCVTests
1515
MCInstrAnalysisTest.cpp
16+
RISCVBaseInfoTest.cpp
1617
)
1718

1819
set_property(TARGET RISCVTests PROPERTY FOLDER "Tests/UnitTests/TargetTests")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===- RISCVBaseInfoTest.cpp - RISCVBaseInfo unit tests ----------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "MCTargetDesc/RISCVBaseInfo.h"
10+
11+
#include "gtest/gtest.h"
12+
13+
using namespace llvm;
14+
15+
namespace {
16+
TEST(RISCVBaseInfo, CheckSameRatioLMUL) {
17+
// Smaller LMUL.
18+
EXPECT_EQ(RISCVII::LMUL_1,
19+
RISCVVType::getSameRatioLMUL(16, RISCVII::LMUL_2, 8));
20+
EXPECT_EQ(RISCVII::LMUL_F2,
21+
RISCVVType::getSameRatioLMUL(16, RISCVII::LMUL_1, 8));
22+
// Smaller fractional LMUL.
23+
EXPECT_EQ(RISCVII::LMUL_F8,
24+
RISCVVType::getSameRatioLMUL(16, RISCVII::LMUL_F4, 8));
25+
// Bigger LMUL.
26+
EXPECT_EQ(RISCVII::LMUL_2,
27+
RISCVVType::getSameRatioLMUL(8, RISCVII::LMUL_1, 16));
28+
EXPECT_EQ(RISCVII::LMUL_1,
29+
RISCVVType::getSameRatioLMUL(8, RISCVII::LMUL_F2, 16));
30+
// Bigger fractional LMUL.
31+
EXPECT_EQ(RISCVII::LMUL_F2,
32+
RISCVVType::getSameRatioLMUL(8, RISCVII::LMUL_F4, 16));
33+
}
34+
} // namespace

0 commit comments

Comments
 (0)