|
| 1 | +/* |
| 2 | +Copyright 2020 The Regents of the University of California (Regents) |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package chisel3.iotesters |
| 18 | + |
| 19 | +import chisel3._ |
| 20 | +import chisel3.experimental.Interval |
| 21 | +import chisel3.internal.firrtl.IntervalRange |
| 22 | +import org.scalatest.{FreeSpec, Matchers} |
| 23 | + |
| 24 | +class IntervalShifter(val bitWidth: Int, val binaryPoint: Int, val fixedShiftSize: Int) extends Module { |
| 25 | + val dynamicShifterWidth = 3 |
| 26 | + |
| 27 | + val io = IO(new Bundle { |
| 28 | + val inValue = Input(Interval(IntervalRange(bitWidth.W, binaryPoint.BP))) |
| 29 | + val dynamicShiftValue = Input(UInt(dynamicShifterWidth.W)) |
| 30 | + val shiftRightResult: Option[Interval] = if(fixedShiftSize < bitWidth) { |
| 31 | + Some(Output(Interval(IntervalRange((bitWidth - fixedShiftSize).W, binaryPoint.BP)))) |
| 32 | + } |
| 33 | + else { |
| 34 | + None |
| 35 | + } |
| 36 | + val shiftLeftResult = Output(Interval(IntervalRange((bitWidth + fixedShiftSize).W, binaryPoint.BP))) |
| 37 | + val dynamicShiftRightResult = Output(Interval(IntervalRange(bitWidth.W, binaryPoint.BP))) |
| 38 | + val dynamicShiftLeftResult = Output( |
| 39 | + Interval(IntervalRange((bitWidth + (1 << dynamicShifterWidth) - 1).W, binaryPoint.BP)) |
| 40 | + ) |
| 41 | + }) |
| 42 | + |
| 43 | + io.shiftLeftResult := io.inValue << fixedShiftSize |
| 44 | + io.shiftRightResult.foreach { out => |
| 45 | + out := (io.inValue >> fixedShiftSize).asInstanceOf[Interval].squeeze(out) |
| 46 | + } |
| 47 | + io.dynamicShiftLeftResult := io.inValue << io.dynamicShiftValue |
| 48 | + io.dynamicShiftRightResult := io.inValue >> io.dynamicShiftValue |
| 49 | +} |
| 50 | + |
| 51 | +class IntervalShiftLeftSpec extends FreeSpec with Matchers { |
| 52 | + "Shift left of interval used to create Dshlw problem in CheckTypes" in { |
| 53 | + val backendName = "treadle" |
| 54 | + val defaultWidth = 8 |
| 55 | + val binaryPoint = 0 |
| 56 | + val fixedShiftSize = 1 |
| 57 | + Driver.execute( |
| 58 | + Array( |
| 59 | + "--backend-name", backendName, |
| 60 | + "--target-dir", s"test_run_dir/interval-shift-test-$fixedShiftSize-$binaryPoint.BP" |
| 61 | + ), |
| 62 | + () => new IntervalShifter(bitWidth = 8, binaryPoint = binaryPoint, fixedShiftSize = fixedShiftSize) |
| 63 | + |
| 64 | + ) { c => |
| 65 | + new PeekPokeTester(c) { |
| 66 | + |
| 67 | + } |
| 68 | + } should be(true) |
| 69 | + } |
| 70 | +} |
0 commit comments