generated from schoeberl/chisel-empty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
87 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
/* | ||
* Dummy file to start a Chisel project. | ||
* | ||
* Author: Martin Schoeberl ([email protected]) | ||
* | ||
*/ | ||
|
||
package vfrope | ||
|
||
import chisel3._ | ||
|
@@ -33,7 +26,7 @@ class RoPEModule_Int(width:Int) extends Module{ | |
sinCosLUT.io.angle := m_theta_i | ||
sinVal := sinCosLUT.io.sinOut | ||
cosVal := sinCosLUT.io.cosOut | ||
|
||
outReg(0) := inReg(0) * cosVal - inReg(1) * sinVal | ||
outReg(1) := inReg(1) * cosVal + inReg(0) * sinVal | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package vfrope | ||
|
||
import chisel3._ | ||
import chisel3.experimental.FixedPoint | ||
import chisel3.util.Cat | ||
|
||
class FixedPointAdder(width: Int, binaryPoint: Int) extends Module { | ||
val io = IO(new Bundle { | ||
val a = Input(FixedPoint(width.W, binaryPoint.BP)) | ||
val b = Input(FixedPoint(width.W, binaryPoint.BP)) | ||
val out = Output(FixedPoint((width+1).W, binaryPoint.BP)) | ||
}) | ||
|
||
io.out := io.a + io.b | ||
} | ||
|
||
class FixedPointMultiplier(width: Int, binaryPoint: Int) extends Module { | ||
val io = IO(new Bundle { | ||
val a = Input(FixedPoint(width.W, binaryPoint.BP)) | ||
val b = Input(FixedPoint(width.W, binaryPoint.BP)) | ||
val out = Output(FixedPoint((2*width).W, (2*binaryPoint).BP)) | ||
}) | ||
|
||
io.out := io.a * io.b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package vfrope | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package vfrope | ||
|
||
import chisel3._ | ||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import chisel3.experimental.FixedPoint | ||
import chisel3.util.Cat | ||
|
||
class FixedPointArithmeticTest extends AnyFlatSpec with ChiselScalatestTester { | ||
behavior of "FixedPointAdder" | ||
|
||
it should "correctly add fixed point numbers" in { | ||
test(new FixedPointAdder(16, 8)) { c => | ||
def fp(n: Double): BigInt = BigInt((n * (1 << 8)).round.toInt) | ||
|
||
val testCases = Seq( | ||
(1.5, 2.25, 3.75), | ||
(-1.5, 2.25, 0.75), | ||
(3.25, -1.75, 1.5), | ||
(-2.5, -1.75, -4.25) | ||
) | ||
|
||
for ((a, b, expected) <- testCases) { | ||
c.io.a.poke(FixedPoint.fromDouble(a, 16.W, 8.BP)) | ||
c.io.b.poke(FixedPoint.fromDouble(b, 16.W, 8.BP)) | ||
c.clock.step() | ||
c.io.out.expect(FixedPoint.fromDouble(expected, 17.W, 8.BP)) | ||
} | ||
} | ||
} | ||
|
||
behavior of "FixedPointMultiplier" | ||
|
||
it should "correctly multiply fixed point numbers" in { | ||
test(new FixedPointMultiplier(16, 8)) { c => | ||
def fp(n: Double): BigInt = BigInt((n * (1 << 8)).round.toInt) | ||
|
||
val testCases = Seq( | ||
(1.5, 2.25, 3.375), | ||
(-1.5, 2.25, -3.375), | ||
(3.25, -1.75, -5.6875), | ||
(-2.5, -1.75, 4.375) | ||
) | ||
|
||
for ((a, b, expected) <- testCases) { | ||
c.io.a.poke(FixedPoint.fromDouble(a, 16.W, 8.BP)) | ||
c.io.b.poke(FixedPoint.fromDouble(b, 16.W, 8.BP)) | ||
c.clock.step() | ||
c.io.out.expect(FixedPoint.fromDouble(expected, 32.W, 16.BP)) | ||
} | ||
} | ||
} | ||
} |