merge CTZ and CLZ, seems to save some LUTs

This commit is contained in:
Romain Dolbeau 2021-02-27 08:23:05 -05:00
parent 29738d20b8
commit e870f3ebe7
11 changed files with 68 additions and 87 deletions

View file

@ -87,7 +87,11 @@ object BitManipBFPOnlyPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -113,11 +117,6 @@ object BitManipBFPOnlyPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -91,7 +91,11 @@ object BitManipZbaPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -117,11 +121,6 @@ object BitManipZbaPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -14,7 +14,7 @@ object BitManipZbbPlugin {
val CTRL_MAX, CTRL_MAXU, CTRL_MIN, CTRL_MINU = newElement() val CTRL_MAX, CTRL_MAXU, CTRL_MIN, CTRL_MINU = newElement()
} }
object BitManipZbbCtrlcountzeroesEnum extends SpinalEnum(binarySequential) { object BitManipZbbCtrlcountzeroesEnum extends SpinalEnum(binarySequential) {
val CTRL_CLZ, CTRL_CPOP, CTRL_CTZ = newElement() val CTRL_CLTZ, CTRL_CPOP = newElement()
} }
object BitManipZbbCtrlsignextendEnum extends SpinalEnum(binarySequential) { object BitManipZbbCtrlsignextendEnum extends SpinalEnum(binarySequential) {
val CTRL_SEXTdotB, CTRL_SEXTdotH, CTRL_ZEXTdotH = newElement() val CTRL_SEXTdotB, CTRL_SEXTdotH, CTRL_ZEXTdotH = newElement()
@ -111,7 +111,11 @@ object BitManipZbbPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -137,11 +141,6 @@ object BitManipZbbPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {
@ -457,8 +456,7 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv
def MAX_KEY = M"0000101----------110-----0110011" def MAX_KEY = M"0000101----------110-----0110011"
def MAXU_KEY = M"0000101----------111-----0110011" def MAXU_KEY = M"0000101----------111-----0110011"
def RORI_KEY = M"01100------------101-----0010011" def RORI_KEY = M"01100------------101-----0010011"
def CLZ_KEY = M"011000000000-----001-----0010011" def CLTZ_KEY = M"01100000000------001-----0010011"
def CTZ_KEY = M"011000000001-----001-----0010011"
def CPOP_KEY = M"011000000010-----001-----0010011" def CPOP_KEY = M"011000000010-----001-----0010011"
def SEXTdotB_KEY = M"011000000100-----001-----0010011" def SEXTdotB_KEY = M"011000000100-----001-----0010011"
def SEXTdotH_KEY = M"011000000101-----001-----0010011" def SEXTdotH_KEY = M"011000000101-----001-----0010011"
@ -478,8 +476,7 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv
MINU_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MINU)), MINU_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MINU)),
MAX_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MAX)), MAX_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MAX)),
MAXU_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MAXU)), MAXU_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_minmax, BitManipZbbCtrlminmax -> BitManipZbbCtrlminmaxEnum.CTRL_MAXU)),
CLZ_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CLZ)), CLTZ_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CLTZ)),
CTZ_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CTZ)),
CPOP_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CPOP)), CPOP_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CPOP)),
SEXTdotB_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotB)), SEXTdotB_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotB)),
SEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotH)), SEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotH)),
@ -509,9 +506,8 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv
BitManipZbbCtrlminmaxEnum.CTRL_MINU -> ((input(SRC1).asUInt < input(SRC2).asUInt) ? input(SRC1) | input(SRC2)).asBits BitManipZbbCtrlminmaxEnum.CTRL_MINU -> ((input(SRC1).asUInt < input(SRC2).asUInt) ? input(SRC1) | input(SRC2)).asBits
) // mux minmax ) // mux minmax
val val_countzeroes = input(BitManipZbbCtrlcountzeroes).mux( val val_countzeroes = input(BitManipZbbCtrlcountzeroes).mux(
BitManipZbbCtrlcountzeroesEnum.CTRL_CLZ -> fun_clz(input(SRC1)).asBits, BitManipZbbCtrlcountzeroesEnum.CTRL_CLTZ -> fun_cltz(input(SRC1), input(INSTRUCTION)(20)).asBits,
BitManipZbbCtrlcountzeroesEnum.CTRL_CPOP -> fun_popcnt(input(SRC1)).asBits, BitManipZbbCtrlcountzeroesEnum.CTRL_CPOP -> fun_popcnt(input(SRC1)).asBits
BitManipZbbCtrlcountzeroesEnum.CTRL_CTZ -> fun_ctz(input(SRC1)).asBits
) // mux countzeroes ) // mux countzeroes
val val_signextend = input(BitManipZbbCtrlsignextend).mux( val val_signextend = input(BitManipZbbCtrlsignextend).mux(
BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotB -> (Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0)).asBits, BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotB -> (Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0)).asBits,

View file

@ -29,7 +29,7 @@ object BitManipZbbZbpPlugin {
val CTRL_GORC, CTRL_GREV = newElement() val CTRL_GORC, CTRL_GREV = newElement()
} }
object BitManipZbbZbpCtrlcountzeroesEnum extends SpinalEnum(binarySequential) { object BitManipZbbZbpCtrlcountzeroesEnum extends SpinalEnum(binarySequential) {
val CTRL_CLZ, CTRL_CPOP, CTRL_CTZ = newElement() val CTRL_CLTZ, CTRL_CPOP = newElement()
} }
object BitManipZbbZbpCtrlsignextendEnum extends SpinalEnum(binarySequential) { object BitManipZbbZbpCtrlsignextendEnum extends SpinalEnum(binarySequential) {
val CTRL_SEXTdotB, CTRL_SEXTdotH = newElement() val CTRL_SEXTdotB, CTRL_SEXTdotH = newElement()
@ -127,7 +127,11 @@ object BitManipZbbZbpPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -153,11 +157,6 @@ object BitManipZbbZbpPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {
@ -443,8 +442,7 @@ class BitManipZbbZbpPlugin(earlyInjection : Boolean = true) extends Plugin[VexRi
def GREVI_KEY = M"01101------------101-----0010011" def GREVI_KEY = M"01101------------101-----0010011"
def SHFLI_KEY = M"000010-----------001-----0010011" def SHFLI_KEY = M"000010-----------001-----0010011"
def UNSHFLI_KEY = M"000010-----------101-----0010011" def UNSHFLI_KEY = M"000010-----------101-----0010011"
def CLZ_KEY = M"011000000000-----001-----0010011" def CLTZ_KEY = M"01100000000------001-----0010011"
def CTZ_KEY = M"011000000001-----001-----0010011"
def CPOP_KEY = M"011000000010-----001-----0010011" def CPOP_KEY = M"011000000010-----001-----0010011"
def SEXTdotB_KEY = M"011000000100-----001-----0010011" def SEXTdotB_KEY = M"011000000100-----001-----0010011"
def SEXTdotH_KEY = M"011000000101-----001-----0010011" def SEXTdotH_KEY = M"011000000101-----001-----0010011"
@ -475,8 +473,7 @@ class BitManipZbbZbpPlugin(earlyInjection : Boolean = true) extends Plugin[VexRi
XPERMdotH_KEY -> (binaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_xperm, BitManipZbbZbpCtrlxperm -> BitManipZbbZbpCtrlxpermEnum.CTRL_XPERMdotH)), XPERMdotH_KEY -> (binaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_xperm, BitManipZbbZbpCtrlxperm -> BitManipZbbZbpCtrlxpermEnum.CTRL_XPERMdotH)),
GORCI_KEY -> (immediateActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_grevorc, BitManipZbbZbpCtrlgrevorc -> BitManipZbbZbpCtrlgrevorcEnum.CTRL_GORC)), GORCI_KEY -> (immediateActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_grevorc, BitManipZbbZbpCtrlgrevorc -> BitManipZbbZbpCtrlgrevorcEnum.CTRL_GORC)),
GREVI_KEY -> (immediateActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_grevorc, BitManipZbbZbpCtrlgrevorc -> BitManipZbbZbpCtrlgrevorcEnum.CTRL_GREV)), GREVI_KEY -> (immediateActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_grevorc, BitManipZbbZbpCtrlgrevorc -> BitManipZbbZbpCtrlgrevorcEnum.CTRL_GREV)),
CLZ_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_countzeroes, BitManipZbbZbpCtrlcountzeroes -> BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CLZ)), CLTZ_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_countzeroes, BitManipZbbZbpCtrlcountzeroes -> BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CLTZ)),
CTZ_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_countzeroes, BitManipZbbZbpCtrlcountzeroes -> BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CTZ)),
CPOP_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_countzeroes, BitManipZbbZbpCtrlcountzeroes -> BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CPOP)), CPOP_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_countzeroes, BitManipZbbZbpCtrlcountzeroes -> BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CPOP)),
SEXTdotB_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_signextend, BitManipZbbZbpCtrlsignextend -> BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotB)), SEXTdotB_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_signextend, BitManipZbbZbpCtrlsignextend -> BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotB)),
SEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_signextend, BitManipZbbZbpCtrlsignextend -> BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotH)) SEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbZbpCtrl -> BitManipZbbZbpCtrlEnum.CTRL_signextend, BitManipZbbZbpCtrlsignextend -> BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotH))
@ -525,9 +522,8 @@ class BitManipZbbZbpPlugin(earlyInjection : Boolean = true) extends Plugin[VexRi
BitManipZbbZbpCtrlgrevorcEnum.CTRL_GREV -> fun_grev(input(SRC1), input(SRC2)).asBits BitManipZbbZbpCtrlgrevorcEnum.CTRL_GREV -> fun_grev(input(SRC1), input(SRC2)).asBits
) // mux grevorc ) // mux grevorc
val val_countzeroes = input(BitManipZbbZbpCtrlcountzeroes).mux( val val_countzeroes = input(BitManipZbbZbpCtrlcountzeroes).mux(
BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CLZ -> fun_clz(input(SRC1)).asBits, BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CLTZ -> fun_cltz(input(SRC1), input(INSTRUCTION)(20)).asBits,
BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CPOP -> fun_popcnt(input(SRC1)).asBits, BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CPOP -> fun_popcnt(input(SRC1)).asBits
BitManipZbbZbpCtrlcountzeroesEnum.CTRL_CTZ -> fun_ctz(input(SRC1)).asBits
) // mux countzeroes ) // mux countzeroes
val val_signextend = input(BitManipZbbZbpCtrlsignextend).mux( val val_signextend = input(BitManipZbbZbpCtrlsignextend).mux(
BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotB -> (Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0)).asBits, BitManipZbbZbpCtrlsignextendEnum.CTRL_SEXTdotB -> (Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0)).asBits,

View file

@ -91,7 +91,11 @@ object BitManipZbe1cyclePlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -117,11 +121,6 @@ object BitManipZbe1cyclePlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -91,7 +91,11 @@ object BitManipZbfPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -117,11 +121,6 @@ object BitManipZbfPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -115,7 +115,11 @@ object BitManipZbpPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -141,11 +145,6 @@ object BitManipZbpPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -91,7 +91,11 @@ object BitManipZbsPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -117,11 +121,6 @@ object BitManipZbsPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -91,7 +91,11 @@ object BitManipZbtPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -117,11 +121,6 @@ object BitManipZbtPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -111,7 +111,11 @@ object CryptoZkbPlugin {
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -137,11 +141,6 @@ object CryptoZkbPlugin {
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {

View file

@ -107,8 +107,7 @@ I UNSHFLI UNSHFL 000010-----------101-----0010011 shuffle Zbp
//I GORCIW GORCW 0010100----------101-----0011011 grevroc //I GORCIW GORCW 0010100----------101-----0011011 grevroc
//I GREVIW GREVW 0110100----------101-----0011011 grevroc //I GREVIW GREVW 0110100----------101-----0011011 grevroc
// unary register // unary register
I CLZ CLZ 011000000000-----001-----0010011 countzeroes Zbb I CLTZ CLTZ 01100000000------001-----0010011 countzeroes Zbb
I CTZ CTZ 011000000001-----001-----0010011 countzeroes Zbb
I CPOP CPOP 011000000010-----001-----0010011 countzeroes Zbb I CPOP CPOP 011000000010-----001-----0010011 countzeroes Zbb
//I BMATFLIP BMATFLIP 011000000011-----001-----0010011 BMATFLIP //I BMATFLIP BMATFLIP 011000000011-----001-----0010011 BMATFLIP
I SEXTdotB SEXTdotB 011000000100-----001-----0010011 signextend Zbb I SEXTdotB SEXTdotB 011000000100-----001-----0010011 signextend Zbb
@ -163,18 +162,17 @@ S MAXU "((input(SRC1).asUInt > input(SRC2).asUInt) ? input(SRC1) | input(SRC2))"
S XPERMdotN "fun_xperm_n(input(SRC1), input(SRC2))" S XPERMdotN "fun_xperm_n(input(SRC1), input(SRC2))"
S XPERMdotB "fun_xperm_b(input(SRC1), input(SRC2))" S XPERMdotB "fun_xperm_b(input(SRC1), input(SRC2))"
S XPERMdotH "fun_xperm_h(input(SRC1), input(SRC2))" S XPERMdotH "fun_xperm_h(input(SRC1), input(SRC2))"
S BFP "fun_bfp(input(SRC1), input(SRC2))"
// if 'SRC2' doesn't appear in the semantic, the code assume unary // if 'SRC2' doesn't appear in the semantic, the code assume unary
S SEXTdotB "(Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0))" S SEXTdotB "(Bits(24 bits).setAllTo(input(SRC1)(7)) ## input(SRC1)(7 downto 0))"
S SEXTdotH "(Bits(16 bits).setAllTo(input(SRC1)(15)) ## input(SRC1)(15 downto 0))" S SEXTdotH "(Bits(16 bits).setAllTo(input(SRC1)(15)) ## input(SRC1)(15 downto 0))"
S CLZ "fun_clz(input(SRC1))" S CLTZ "fun_cltz(input(SRC1), input(INSTRUCTION)(20))"
S CTZ "fun_ctz(input(SRC1))"
S CPOP "fun_popcnt(input(SRC1))" S CPOP "fun_popcnt(input(SRC1))"
// if 'SRC3' appear in the semantic, the code assume ternary // if 'SRC3' appear in the semantic, the code assume ternary
S CMIX "((input(SRC1) & input(SRC2)) | (input(SRC3) & ~input(SRC2)))" S CMIX "((input(SRC1) & input(SRC2)) | (input(SRC3) & ~input(SRC2)))"
S CMOV "((input(SRC2).asUInt =/= 0) ? input(SRC1) | input(SRC3))" S CMOV "((input(SRC2).asUInt =/= 0) ? input(SRC1) | input(SRC3))"
S FSL "fun_fsl(input(SRC1), input(SRC3), input(SRC2))" S FSL "fun_fsl(input(SRC1), input(SRC3), input(SRC2))"
S FSR "fun_fsr(input(SRC1), input(SRC3), input(SRC2))" S FSR "fun_fsr(input(SRC1), input(SRC3), input(SRC2))"
S BFP "fun_bfp(input(SRC1), input(SRC2))"
// PROLOGUE // PROLOGUE
P """ P """
@ -255,7 +253,11 @@ P """
r // return value r // return value
} }
def fun_clz(in:Bits) : Bits = { // For trailing count, count using use leading count on bit-reversed value
def fun_cltz(ino:Bits, ctz:Bool) : Bits = {
val inr = ino(0) ## ino(1) ## ino(2) ## ino(3) ## ino(4) ## ino(5) ## ino(6) ## ino(7) ## ino(8) ## ino(9) ## ino(10) ## ino(11) ## ino(12) ## ino(13) ## ino(14) ## ino(15) ## ino(16) ## ino(17) ## ino(18) ## ino(19) ## ino(20) ## ino(21) ## ino(22) ## ino(23) ## ino(24) ## ino(25) ## ino(26) ## ino(27) ## ino(28) ## ino(29) ## ino(30) ## ino(31)
val in = (ctz === True) ? (inr) | (ino)
val nlc7 = fun_clz_NLCi(in(31 downto 28)) val nlc7 = fun_clz_NLCi(in(31 downto 28))
val nlc6 = fun_clz_NLCi(in(27 downto 24)) val nlc6 = fun_clz_NLCi(in(27 downto 24))
val nlc5 = fun_clz_NLCi(in(23 downto 20)) val nlc5 = fun_clz_NLCi(in(23 downto 20))
@ -281,11 +283,6 @@ P """
r.resize(32) // return value r.resize(32) // return value
} }
// For trailing count, count using use leading count on bit-reversed value
def fun_ctz(in:Bits) : Bits = {
val inr = in(0) ## in(1) ## in(2) ## in(3) ## in(4) ## in(5) ## in(6) ## in(7) ## in(8) ## in(9) ## in(10) ## in(11) ## in(12) ## in(13) ## in(14) ## in(15) ## in(16) ## in(17) ## in(18) ## in(19) ## in(20) ## in(21) ## in(22) ## in(23) ## in(24) ## in(25) ## in(26) ## in(27) ## in(28) ## in(29) ## in(30) ## in(31)
fun_clz(inr) // return value
}
// naive popcnt // naive popcnt
def fun_popcnt(in:Bits) : Bits = { def fun_popcnt(in:Bits) : Bits = {