Skip to content

Commit 700353e

Browse files
committed
fix(DifftestBundle): fix incorrect C++ type declarations during code generation
When generating `arrayType`, not all 8-bit-aligned types are valid in C++. For example, if someone defines a 41-bit-wide signal, it may result in generating an unsupported C++ type like uint48_t instead of a valid uint64_t. This change ensures that for any given bit width, a C++-supported type is generated.
1 parent 826fe99 commit 700353e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/scala/Difftest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ sealed trait DifftestBundle extends Bundle with DifftestWithCoreid { this: Difft
116116
val isRemoved = isFlatten && Seq("valid", "address").contains(name)
117117
if (!isRemoved) {
118118
// Align elem to 8 bytes for bundle enabled to split when Delta
119-
val elemSize = if (this.supportsDelta && aligned) (size + 7) / 8 * 8 else size
119+
val elemSize = if (this.supportsDelta && aligned) (size + 7) / 8 * 8 else math.pow(2, log2Ceil(size)).toInt
120120
val arrayType = s"uint${elemSize * 8}_t"
121121
val arrayWidth = if (elem.length == 1) "" else s"[${elem.length}]"
122122
cpp += f" $arrayType%-8s $name$arrayWidth;"

0 commit comments

Comments
 (0)