Commit 2be7f81a authored by apaj's avatar apaj
Browse files

Adapting GCD to Learning Journey

parent 80671b79
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+2 −0
Original line number Diff line number Diff line
*.original
*.inProgress
+19 −22
Original line number Diff line number Diff line
// See LICENSE.txt for license details.
// January 20th, 2018	- adapted to Learning Journey
package examples

import chisel3._
import Chisel._ 
 
class GCD extends Module { 
  val io = IO(new Bundle {
    val a  = Input(UInt(16.W))
    val b  = Input(UInt(16.W))
    val e  = Input(Bool())
    val z  = Output(UInt(16.W))
    val v  = Output(Bool())
  })

  val io = new Bundle { 
    val a  = UInt(INPUT,  16) 
    val b  = UInt(INPUT,  16) 
    val e  = Bool(INPUT) 
    val z  = UInt(OUTPUT, 16) 
    val v  = Bool(OUTPUT) 
  } 
  val x  = Reg(UInt()) 
  val y  = Reg(UInt()) 
  when   (x > y) {
    x := x - y
  }
    .elsewhen (x <= y) { y := y - x }

  when   (x > y) { x := x - y } 
  unless (x > y) { y := y - x } 
  when (io.e) { x := io.a; y := io.b } 
  io.z := x 
  io.v := y === 0.U
  io.v := y === UInt(0) 
}