diff options
| author | Chick Markley | 2017-02-07 21:54:24 -0800 |
|---|---|---|
| committer | GitHub | 2017-02-07 21:54:24 -0800 |
| commit | 32885ac312c25e8f056ef7bddecbd00720548b96 (patch) | |
| tree | fb6bd7fd5224a535bf654e94a96890b2679a76e2 /src/test/scala/chiselTests/FixedPointSpec.scala | |
| parent | c9beeeb1408f760309524f44a2dbd1c4f6d116b6 (diff) | |
Fix up Absolute value #abs (#491)
* Fix up Absolute value #abs
Defines #abs in Num
Implement #abs in UInt
Change #abs in SInt to return an SInt
Change #abs in FixedPoint to return a FixedPoint
Added a couple of tests
Add some scala style suppression to Bits so I can read code in IntelliJ
* Per review
Add tests that abs works for positive values
Added SInt and UInt tests for abs to new underpopulated IntegerMathSpec
Used fixed point literals in fixed points abs definition
Diffstat (limited to 'src/test/scala/chiselTests/FixedPointSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/FixedPointSpec.scala | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index bfbb4e46..d0557e66 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -21,23 +21,31 @@ class FixedPointLiteralSpec extends FlatSpec with Matchers { } class FixedPointFromBitsTester extends BasicTester { - val uint = 3.U(4.W) - val sint = -3.S - val fp = FixedPoint.fromDouble(3.0, width = 4, binaryPoint = 0) - val fp_tpe = FixedPoint(4.W, 1.BP) - val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) - val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1) - val fp_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) - - val uint2fp = fp_tpe.fromBits(uint) - val sint2fp = fp_tpe.fromBits(sint) - val fp2fp = fp_tpe.fromBits(fp) - - assert(uint2fp === uint_result) - assert(sint2fp === sint_result) - assert(fp2fp === fp_result) - - stop() + val uint = 3.U(4.W) + val sint = -3.S + + val fp = FixedPoint.fromDouble(3.0, width = 4, binaryPoint = 0) + val fp_tpe = FixedPoint(4.W, 1.BP) + val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) + val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1) + val fp_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) + + val uint2fp = fp_tpe.fromBits(uint) + val sint2fp = fp_tpe.fromBits(sint) + val fp2fp = fp_tpe.fromBits(fp) + + val negativefp = -3.5.F(binaryPoint = 4) + val positivefp = 3.5.F(binaryPoint = 4) + + assert(uint2fp === uint_result) + assert(sint2fp === sint_result) + assert(fp2fp === fp_result) + + assert(positivefp.abs() === positivefp) + assert(negativefp.abs() === positivefp) + assert(negativefp.abs() =/= negativefp) + + stop() } class SBP extends Module { |
