Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(frontend): prune the least significant bit of PC #3949

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/main/scala/xiangshan/frontend/Pc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/***************************************************************************************
* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
* Copyright (c) 2020-2021 Peng Cheng Laboratory
*
* XiangShan is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

package xiangshan.frontend

import chisel3._
import chisel3.util._

class Pc(val length: Int) extends Bundle {
val pc: UInt = UInt((length - 1).W)

def apply(): UInt = Cat(pc, 0.U(1.W))

def apply(x: Int): Bool = apply()(x)

def apply(x: Int, y: Int): UInt = apply()(x, y)

def :=(x: UInt): Unit = {
assert(length == x.getWidth)
pc := x(length - 1, 1)
}

def +(offset: UInt): Pc = PcInit(apply() + offset)

def ===(that: Pc): Bool = {
assert(length == that.length)
pc === that.pc
}

def =/=(that: Pc): Bool = { // scalastyle:ignore method.name
assert(length == that.length)
pc =/= that.pc
}
}

object Pc {
def apply(length: Int): Pc = new Pc(length)
}

object PcInit {
def apply(fullPc: UInt): Pc = {
val pc = Wire(new Pc(fullPc.getWidth))
pc := fullPc
pc
}
}
2 changes: 1 addition & 1 deletion utility