Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoling-yi committed Jan 19, 2024
1 parent bc948ec commit 5cb5cb0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/main/scala/simd/PE.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import chisel3.util._
// control signals for the basic processing element, related to the post-processing algorithm
class PECtrl extends Bundle {

/** @input
* input_zp_i, input zero point
* @input
* output_zp_i, output zero point
* @input
* multiplier_i, scaling factor
* @input
* shift_i, shift number
* @input
* max_int_i, maximum number for clamping
* @input
* min_int_i, minimum number for clamping
* @input
* double_round_i, if double round
*/
val input_zp_i = (SInt(SIMDConstant.constantType.W))
val output_zp_i = (SInt(SIMDConstant.constantType.W))
// ! this port has different data width
Expand Down Expand Up @@ -57,6 +72,7 @@ class PE extends Module with RequireAsyncReset {
var2 := (var1 >> 1.U) + io.ctrl_i.output_zp_i
}

// clamping
overflow := var2 > io.ctrl_i.max_int_i
underflow := var2 < io.ctrl_i.min_int_i
var3 := Mux(
Expand Down
51 changes: 46 additions & 5 deletions src/test/scala/simd/PETest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ trait HasRandomTestGen {
val input: Int = random.nextInt(math.pow(2, 28).toInt)
val inputZp: Byte = random.nextInt(256).toByte
val outputZp: Byte = random.nextInt(256).toByte
val realMult: Float = random.nextFloat() / math.pow(2, 31).toFloat * 16
var shift: Byte = random.nextInt(38).toByte
if (shift < 0)
shift = (-shift).toByte
Expand Down Expand Up @@ -130,12 +129,14 @@ class PEManualTest
}

// manually random data test
// golden test grab from c spec
// test rtl with c-spec from
// https://gist.github.com/jorendumoulin/83352a1e84501ec4a7b3790461fee2bf
verify(267082502, -59, -118, 8192, 34, 127, -128, true.B, 9)
verify(71671912, -23, -126, 65536, 37, 127, -128, true.B, -92)
verify(61791880, -54, 115, 67108864, 47, 127, -128, true.B, 127)
verify(118289203, 55, 56, 536870912, 50, 127, -128, true.B, 112)
verify(182938555, -69, -118, 16777216, 45, 127, -128, true.B, -31)
verify(182938555, -69, -118, 1566, 65, 127, -128, true, -128)

// test if the golden model matches c spec
assert(
Expand All @@ -158,11 +159,51 @@ class PEManualTest
127,
-128,
doubleRound = true
) &&
127 == postProcessingGoldenModel(
61791880,
-54,
115,
67108864,
47,
127,
-128,
doubleRound = true
)
&& 112 == postProcessingGoldenModel(
118289203,
55,
56,
536870912,
50,
127,
-128,
doubleRound = true
) &&
-31 == postProcessingGoldenModel(
182938555,
-69,
-118,
16777216,
45,
127,
-128,
doubleRound = true
)
- 128 == postProcessingGoldenModel(
182938555,
-69,
-118,
1566,
65,
127,
-128,
doubleRound = true
)
)

// batch test
val testNum = 10
val testNum = 100
for (i <- 0 until testNum) {
// gen random test data
val (
Expand All @@ -175,7 +216,7 @@ class PEManualTest
minInt,
doubleRound
) = RandomTestGen()

// gen golden value
val goldenValue = postProcessingGoldenModel(
input,
Expand All @@ -187,7 +228,7 @@ class PEManualTest
minInt,
doubleRound
)

// verify the dut result with golden value
verify(
input,
Expand Down

0 comments on commit 5cb5cb0

Please sign in to comment.