Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. package bit_examples
  2.  
  3. import chisel3._
  4. import chisel3.experimental.MultiIOModule
  5. import chisel3.iotesters.PeekPokeTester
  6. import chisel3.util.Cat
  7.  
  8. import org.scalatest.{FreeSpec, Matchers}
  9.  
  10. //scalastyle:off magic.number
  11.  
  12. // Class and companion Object to support instantiation and initialization of
  13. // state due to the need to have subword assignment for vectors > 64-bits
  14. //
  15. // Fields in the bundle enumerate from to low. When converting this bundle
  16. // to UInt it is equivalent to Cat(Word1, Word0) or if subword assignment
  17. // was supported:
  18. //
  19. // state(127,64) := word1
  20. // state(63,0) := word0
  21. //
  22.  
  23. class State_Class extends Bundle {
  24. val word1 = UInt(64.W)
  25. val word0 = UInt(64.W)
  26. }
  27.  
  28. object State_Class {
  29. def init: State_Class = {
  30. val wire = Wire(new State_Class)
  31. wire.word1 := BigInt("a"*16, 16).U
  32. wire.word0 := BigInt("b"*16, 16).U
  33. wire
  34. }
  35. }
  36.  
  37. // Class and companion Object to support instantiation and initialization of
  38. // key due to the need to have subword assignment for vectors > 64-bits
  39. //
  40. class Key_Class extends Bundle {
  41. val word2 = UInt(64.W)
  42. val word1 = UInt(64.W)
  43. val word0 = UInt(64.W)
  44. }
  45.  
  46. object Key_Class {
  47. def init: Key_Class = {
  48. val wire = Wire(new Key_Class)
  49. wire.word2 := BigInt("c"*16, 16).U
  50. wire.word1 := BigInt("d"*16, 16).U
  51. wire.word0 := BigInt("e"*16, 16).U
  52. wire
  53. }
  54. }
  55.  
  56. class Example extends MultiIOModule {
  57. val stateOut = IO(Output((UInt((new State_Class).getWidth.W))))
  58. val keyOut = IO(Output((UInt((new Key_Class).getWidth.W))))
  59. val combinedOut = IO(Output((UInt((stateOut.getWidth + keyOut.getWidth).W))))
  60.  
  61. val state = RegInit(State_Class.init)
  62. val key = RegInit(Key_Class.init)
  63.  
  64. stateOut := state.asUInt
  65. keyOut := key.asUInt
  66.  
  67. combinedOut := Cat(stateOut, keyOut)
  68. }
  69.  
  70. class BitTests extends FreeSpec with Matchers {
  71. "example of uint conversion and and ordering of cat" in {
  72. iotesters.Driver.execute(Array(), () => new Example) { c =>
  73. new PeekPokeTester(c) {
  74. step(1)
  75.  
  76. peek(c.stateOut).toString(16) should be ("a"*16 + "b"*16)
  77. peek(c.keyOut).toString(16) should be ("c"*16 + "d"*16 + "e"*16)
  78. peek(c.combinedOut).toString(16) should be ("a"*16 + "b"*16 + "c"*16 + "d"*16 + "e"*16)
  79.  
  80. println(s"stateOut ${peek(c.stateOut).toString(16)}")
  81. println(s"keyOut ${peek(c.keyOut).toString(16)}")
  82. println(s"combined ${peek(c.combinedOut).toString(16)}")
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement