From fea0b5bf88eb58ed05b8a7c8109c61f51fc578de Mon Sep 17 00:00:00 2001 From: Romain Dolbeau Date: Fri, 11 Jun 2021 13:20:38 +0200 Subject: [PATCH] Update K scalar to 0.9.2 --- BitManipZbb.scala | 32 +- CryptoZkb.scala => CryptoZbkb.scala | 162 +++++----- CryptoZkg.scala => CryptoZbkc.scala | 46 +-- CryptoZbkx.scala | 457 ++++++++++++++++++++++++++++ CryptoZknd.scala | 4 +- CryptoZkne.scala | 4 +- CryptoZks.scala | 4 +- Makefile | 21 +- data_aes.txt | 17 +- data_bitmanip.txt | 22 +- data_bitmanip_ZbbOnly.txt | 10 +- data_clmul.txt | 4 +- data_sm4.txt | 6 +- 13 files changed, 620 insertions(+), 169 deletions(-) rename CryptoZkb.scala => CryptoZbkb.scala (75%) rename CryptoZkg.scala => CryptoZbkc.scala (85%) create mode 100644 CryptoZbkx.scala diff --git a/BitManipZbb.scala b/BitManipZbb.scala index 54e6e33..cb6c3d0 100644 --- a/BitManipZbb.scala +++ b/BitManipZbb.scala @@ -4,6 +4,9 @@ package vexriscv.plugin import spinal.core._ import vexriscv.{Stageable, DecoderService, VexRiscv} object BitManipZbbPlugin { + object BitManipZbbCtrlgrevorcEnum extends SpinalEnum(binarySequential) { + val CTRL_ORCdotB, CTRL_REV8 = newElement() + } object BitManipZbbCtrlbitwiseEnum extends SpinalEnum(binarySequential) { val CTRL_ANDN, CTRL_ORN, CTRL_XNOR = newElement() } @@ -19,18 +22,15 @@ object BitManipZbbPlugin { object BitManipZbbCtrlsignextendEnum extends SpinalEnum(binarySequential) { val CTRL_SEXTdotB, CTRL_SEXTdotH, CTRL_ZEXTdotH = newElement() } - object BitManipZbbCtrlgrevorcEnum extends SpinalEnum(binarySequential) { - val CTRL_ORCdotB, CTRL_REV8 = newElement() - } object BitManipZbbCtrlEnum extends SpinalEnum(binarySequential) { - val CTRL_bitwise, CTRL_rotation, CTRL_minmax, CTRL_countzeroes, CTRL_signextend, CTRL_grevorc = newElement() + val CTRL_grevorc, CTRL_bitwise, CTRL_rotation, CTRL_minmax, CTRL_countzeroes, CTRL_signextend = newElement() } + object BitManipZbbCtrlgrevorc extends Stageable(BitManipZbbCtrlgrevorcEnum()) object BitManipZbbCtrlbitwise extends Stageable(BitManipZbbCtrlbitwiseEnum()) object BitManipZbbCtrlrotation extends Stageable(BitManipZbbCtrlrotationEnum()) object BitManipZbbCtrlminmax extends Stageable(BitManipZbbCtrlminmaxEnum()) object BitManipZbbCtrlcountzeroes extends Stageable(BitManipZbbCtrlcountzeroesEnum()) object BitManipZbbCtrlsignextend extends Stageable(BitManipZbbCtrlsignextendEnum()) - object BitManipZbbCtrlgrevorc extends Stageable(BitManipZbbCtrlgrevorcEnum()) object BitManipZbbCtrl extends Stageable(BitManipZbbCtrlEnum()) // Prologue @@ -446,6 +446,8 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv RS3_USE -> True, IS_BitManipZbb -> True ) + def ORCdotB_KEY = M"001010000111-----101-----0010011" + def REV8_KEY = M"011010011000-----101-----0010011" def ANDN_KEY = M"0100000----------111-----0110011" def ORN_KEY = M"0100000----------110-----0110011" def XNOR_KEY = M"0100000----------100-----0110011" @@ -461,11 +463,11 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv def SEXTdotB_KEY = M"011000000100-----001-----0010011" def SEXTdotH_KEY = M"011000000101-----001-----0010011" def ZEXTdotH_KEY = M"000010000000-----100-----0110011" - def ORCdotB_KEY = M"001010000111-----101-----0010011" - def REV8_KEY = M"011010011000-----101-----0010011" val decoderService = pipeline.service(classOf[DecoderService]) decoderService.addDefault(IS_BitManipZbb, False) decoderService.add(List( + ORCdotB_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_grevorc, BitManipZbbCtrlgrevorc -> BitManipZbbCtrlgrevorcEnum.CTRL_ORCdotB)), + REV8_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_grevorc, BitManipZbbCtrlgrevorc -> BitManipZbbCtrlgrevorcEnum.CTRL_REV8)), ANDN_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_bitwise, BitManipZbbCtrlbitwise -> BitManipZbbCtrlbitwiseEnum.CTRL_ANDN)), ORN_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_bitwise, BitManipZbbCtrlbitwise -> BitManipZbbCtrlbitwiseEnum.CTRL_ORN)), XNOR_KEY -> (binaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_bitwise, BitManipZbbCtrlbitwise -> BitManipZbbCtrlbitwiseEnum.CTRL_XNOR)), @@ -480,9 +482,7 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv CPOP_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_countzeroes, BitManipZbbCtrlcountzeroes -> BitManipZbbCtrlcountzeroesEnum.CTRL_CPOP)), SEXTdotB_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotB)), SEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotH)), - ZEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_ZEXTdotH)), - ORCdotB_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_grevorc, BitManipZbbCtrlgrevorc -> BitManipZbbCtrlgrevorcEnum.CTRL_ORCdotB)), - REV8_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_grevorc, BitManipZbbCtrlgrevorc -> BitManipZbbCtrlgrevorcEnum.CTRL_REV8)) + ZEXTdotH_KEY -> (unaryActions ++ List(BitManipZbbCtrl -> BitManipZbbCtrlEnum.CTRL_signextend, BitManipZbbCtrlsignextend -> BitManipZbbCtrlsignextendEnum.CTRL_ZEXTdotH)) )) } // override def setup override def build(pipeline: VexRiscv): Unit = { @@ -490,6 +490,10 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv import pipeline.config._ execute plug new Area{ import execute._ + val val_grevorc = input(BitManipZbbCtrlgrevorc).mux( + BitManipZbbCtrlgrevorcEnum.CTRL_ORCdotB -> fun_orcb(input(SRC1)).asBits, + BitManipZbbCtrlgrevorcEnum.CTRL_REV8 -> fun_rev8(input(SRC1)).asBits + ) // mux grevorc val val_bitwise = input(BitManipZbbCtrlbitwise).mux( BitManipZbbCtrlbitwiseEnum.CTRL_ANDN -> (input(SRC1) & ~input(SRC2)).asBits, BitManipZbbCtrlbitwiseEnum.CTRL_ORN -> (input(SRC1) | ~input(SRC2)).asBits, @@ -514,17 +518,13 @@ class BitManipZbbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv BitManipZbbCtrlsignextendEnum.CTRL_SEXTdotH -> (Bits(16 bits).setAllTo(input(SRC1)(15)) ## input(SRC1)(15 downto 0)).asBits, BitManipZbbCtrlsignextendEnum.CTRL_ZEXTdotH -> (B"16'x0000" ## input(SRC1)(15 downto 0)).asBits ) // mux signextend - val val_grevorc = input(BitManipZbbCtrlgrevorc).mux( - BitManipZbbCtrlgrevorcEnum.CTRL_ORCdotB -> fun_orcb(input(SRC1)).asBits, - BitManipZbbCtrlgrevorcEnum.CTRL_REV8 -> fun_rev8(input(SRC1)).asBits - ) // mux grevorc insert(BitManipZbb_FINAL_OUTPUT) := input(BitManipZbbCtrl).mux( + BitManipZbbCtrlEnum.CTRL_grevorc -> val_grevorc.asBits, BitManipZbbCtrlEnum.CTRL_bitwise -> val_bitwise.asBits, BitManipZbbCtrlEnum.CTRL_rotation -> val_rotation.asBits, BitManipZbbCtrlEnum.CTRL_minmax -> val_minmax.asBits, BitManipZbbCtrlEnum.CTRL_countzeroes -> val_countzeroes.asBits, - BitManipZbbCtrlEnum.CTRL_signextend -> val_signextend.asBits, - BitManipZbbCtrlEnum.CTRL_grevorc -> val_grevorc.asBits + BitManipZbbCtrlEnum.CTRL_signextend -> val_signextend.asBits ) // primary mux } // execute plug newArea val injectionStage = if(earlyInjection) execute else memory diff --git a/CryptoZkb.scala b/CryptoZbkb.scala similarity index 75% rename from CryptoZkb.scala rename to CryptoZbkb.scala index 65d7214..0ca9ab2 100644 --- a/CryptoZkb.scala +++ b/CryptoZbkb.scala @@ -3,35 +3,31 @@ package vexriscv.plugin import spinal.core._ import vexriscv.{Stageable, DecoderService, VexRiscv} -object CryptoZkbPlugin { - object CryptoZkbCtrlbitwiseEnum extends SpinalEnum(binarySequential) { - val CTRL_ANDN, CTRL_ORN, CTRL_XNOR = newElement() - } - object CryptoZkbCtrlrotationEnum extends SpinalEnum(binarySequential) { - val CTRL_ROL, CTRL_ROR = newElement() - } - object CryptoZkbCtrlpackEnum extends SpinalEnum(binarySequential) { - val CTRL_PACK, CTRL_PACKH, CTRL_PACKU = newElement() - } - object CryptoZkbCtrlxpermEnum extends SpinalEnum(binarySequential) { - val CTRL_XPERMdotB, CTRL_XPERMdotN = newElement() - } - object CryptoZkbCtrlgrevorcEnum extends SpinalEnum(binarySequential) { +object CryptoZbkbPlugin { + object CryptoZbkbCtrlgrevorcEnum extends SpinalEnum(binarySequential) { val CTRL_REV8, CTRL_REVdotB = newElement() } - object CryptoZkbCtrlshuffleEnum extends SpinalEnum(binarySequential) { + object CryptoZbkbCtrlshuffleEnum extends SpinalEnum(binarySequential) { val CTRL_UNZIP, CTRL_ZIP = newElement() } - object CryptoZkbCtrlEnum extends SpinalEnum(binarySequential) { - val CTRL_bitwise, CTRL_rotation, CTRL_pack, CTRL_xperm, CTRL_grevorc, CTRL_shuffle = newElement() + object CryptoZbkbCtrlbitwiseEnum extends SpinalEnum(binarySequential) { + val CTRL_ANDN, CTRL_ORN, CTRL_XNOR = newElement() } - object CryptoZkbCtrlbitwise extends Stageable(CryptoZkbCtrlbitwiseEnum()) - object CryptoZkbCtrlrotation extends Stageable(CryptoZkbCtrlrotationEnum()) - object CryptoZkbCtrlpack extends Stageable(CryptoZkbCtrlpackEnum()) - object CryptoZkbCtrlxperm extends Stageable(CryptoZkbCtrlxpermEnum()) - object CryptoZkbCtrlgrevorc extends Stageable(CryptoZkbCtrlgrevorcEnum()) - object CryptoZkbCtrlshuffle extends Stageable(CryptoZkbCtrlshuffleEnum()) - object CryptoZkbCtrl extends Stageable(CryptoZkbCtrlEnum()) + object CryptoZbkbCtrlrotationEnum extends SpinalEnum(binarySequential) { + val CTRL_ROL, CTRL_ROR = newElement() + } + object CryptoZbkbCtrlpackEnum extends SpinalEnum(binarySequential) { + val CTRL_PACK, CTRL_PACKH = newElement() + } + object CryptoZbkbCtrlEnum extends SpinalEnum(binarySequential) { + val CTRL_grevorc, CTRL_shuffle, CTRL_bitwise, CTRL_rotation, CTRL_pack = newElement() + } + object CryptoZbkbCtrlgrevorc extends Stageable(CryptoZbkbCtrlgrevorcEnum()) + object CryptoZbkbCtrlshuffle extends Stageable(CryptoZbkbCtrlshuffleEnum()) + object CryptoZbkbCtrlbitwise extends Stageable(CryptoZbkbCtrlbitwiseEnum()) + object CryptoZbkbCtrlrotation extends Stageable(CryptoZbkbCtrlrotationEnum()) + object CryptoZbkbCtrlpack extends Stageable(CryptoZbkbCtrlpackEnum()) + object CryptoZbkbCtrl extends Stageable(CryptoZbkbCtrlEnum()) // Prologue // function implementing the semantic of 32-bits generalized reverse @@ -390,10 +386,10 @@ object CryptoZkbPlugin { // End prologue } // object Plugin -class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] { - import CryptoZkbPlugin._ - object IS_CryptoZkb extends Stageable(Bool) - object CryptoZkb_FINAL_OUTPUT extends Stageable(Bits(32 bits)) +class CryptoZbkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] { + import CryptoZbkbPlugin._ + object IS_CryptoZbkb extends Stageable(Bool) + object CryptoZbkb_FINAL_OUTPUT extends Stageable(Bits(32 bits)) override def setup(pipeline: VexRiscv): Unit = { import pipeline.config._ val immediateActions = List[(Stageable[_ <: BaseType],Any)]( @@ -403,7 +399,7 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, - IS_CryptoZkb -> True + IS_CryptoZbkb -> True ) val binaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -413,7 +409,7 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, RS2_USE -> True, - IS_CryptoZkb -> True + IS_CryptoZbkb -> True ) val unaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -421,7 +417,7 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, - IS_CryptoZkb -> True + IS_CryptoZbkb -> True ) val ternaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -433,7 +429,7 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] RS1_USE -> True, RS2_USE -> True, RS3_USE -> True, - IS_CryptoZkb -> True + IS_CryptoZbkb -> True ) val immTernaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -444,41 +440,35 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, RS3_USE -> True, - IS_CryptoZkb -> True + IS_CryptoZbkb -> True ) + def REV8_KEY = M"011010011000-----101-----0010011" + def REVdotB_KEY = M"011010000111-----101-----0010011" + def ZIP_KEY = M"000010001111-----001-----0010011" + def UNZIP_KEY = M"000010001111-----101-----0010011" def ANDN_KEY = M"0100000----------111-----0110011" def ORN_KEY = M"0100000----------110-----0110011" def XNOR_KEY = M"0100000----------100-----0110011" def ROL_KEY = M"0110000----------001-----0110011" def ROR_KEY = M"0110000----------101-----0110011" def PACK_KEY = M"0000100----------100-----0110011" - def PACKU_KEY = M"0100100----------100-----0110011" def PACKH_KEY = M"0000100----------111-----0110011" - def XPERMdotN_KEY = M"0010100----------010-----0110011" - def XPERMdotB_KEY = M"0010100----------100-----0110011" def RORI_KEY = M"01100------------101-----0010011" - def REV8_KEY = M"011010011000-----101-----0010011" - def REVdotB_KEY = M"011010000111-----101-----0010011" - def ZIP_KEY = M"000010001111-----001-----0010011" - def UNZIP_KEY = M"000010001111-----101-----0010011" val decoderService = pipeline.service(classOf[DecoderService]) - decoderService.addDefault(IS_CryptoZkb, False) + decoderService.addDefault(IS_CryptoZbkb, False) decoderService.add(List( - ANDN_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_bitwise, CryptoZkbCtrlbitwise -> CryptoZkbCtrlbitwiseEnum.CTRL_ANDN)), - ORN_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_bitwise, CryptoZkbCtrlbitwise -> CryptoZkbCtrlbitwiseEnum.CTRL_ORN)), - XNOR_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_bitwise, CryptoZkbCtrlbitwise -> CryptoZkbCtrlbitwiseEnum.CTRL_XNOR)), - ROL_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_rotation, CryptoZkbCtrlrotation -> CryptoZkbCtrlrotationEnum.CTRL_ROL)), - ROR_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_rotation, CryptoZkbCtrlrotation -> CryptoZkbCtrlrotationEnum.CTRL_ROR)), - RORI_KEY -> (immediateActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_rotation, CryptoZkbCtrlrotation -> CryptoZkbCtrlrotationEnum.CTRL_ROR)), - PACK_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_pack, CryptoZkbCtrlpack -> CryptoZkbCtrlpackEnum.CTRL_PACK)), - PACKU_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_pack, CryptoZkbCtrlpack -> CryptoZkbCtrlpackEnum.CTRL_PACKU)), - PACKH_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_pack, CryptoZkbCtrlpack -> CryptoZkbCtrlpackEnum.CTRL_PACKH)), - XPERMdotN_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_xperm, CryptoZkbCtrlxperm -> CryptoZkbCtrlxpermEnum.CTRL_XPERMdotN)), - XPERMdotB_KEY -> (binaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_xperm, CryptoZkbCtrlxperm -> CryptoZkbCtrlxpermEnum.CTRL_XPERMdotB)), - REV8_KEY -> (unaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_grevorc, CryptoZkbCtrlgrevorc -> CryptoZkbCtrlgrevorcEnum.CTRL_REV8)), - REVdotB_KEY -> (unaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_grevorc, CryptoZkbCtrlgrevorc -> CryptoZkbCtrlgrevorcEnum.CTRL_REVdotB)), - ZIP_KEY -> (unaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_shuffle, CryptoZkbCtrlshuffle -> CryptoZkbCtrlshuffleEnum.CTRL_ZIP)), - UNZIP_KEY -> (unaryActions ++ List(CryptoZkbCtrl -> CryptoZkbCtrlEnum.CTRL_shuffle, CryptoZkbCtrlshuffle -> CryptoZkbCtrlshuffleEnum.CTRL_UNZIP)) + REV8_KEY -> (unaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_grevorc, CryptoZbkbCtrlgrevorc -> CryptoZbkbCtrlgrevorcEnum.CTRL_REV8)), + REVdotB_KEY -> (unaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_grevorc, CryptoZbkbCtrlgrevorc -> CryptoZbkbCtrlgrevorcEnum.CTRL_REVdotB)), + ZIP_KEY -> (unaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_shuffle, CryptoZbkbCtrlshuffle -> CryptoZbkbCtrlshuffleEnum.CTRL_ZIP)), + UNZIP_KEY -> (unaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_shuffle, CryptoZbkbCtrlshuffle -> CryptoZbkbCtrlshuffleEnum.CTRL_UNZIP)), + ANDN_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_bitwise, CryptoZbkbCtrlbitwise -> CryptoZbkbCtrlbitwiseEnum.CTRL_ANDN)), + ORN_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_bitwise, CryptoZbkbCtrlbitwise -> CryptoZbkbCtrlbitwiseEnum.CTRL_ORN)), + XNOR_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_bitwise, CryptoZbkbCtrlbitwise -> CryptoZbkbCtrlbitwiseEnum.CTRL_XNOR)), + ROL_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_rotation, CryptoZbkbCtrlrotation -> CryptoZbkbCtrlrotationEnum.CTRL_ROL)), + ROR_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_rotation, CryptoZbkbCtrlrotation -> CryptoZbkbCtrlrotationEnum.CTRL_ROR)), + RORI_KEY -> (immediateActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_rotation, CryptoZbkbCtrlrotation -> CryptoZbkbCtrlrotationEnum.CTRL_ROR)), + PACK_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_pack, CryptoZbkbCtrlpack -> CryptoZbkbCtrlpackEnum.CTRL_PACK)), + PACKH_KEY -> (binaryActions ++ List(CryptoZbkbCtrl -> CryptoZbkbCtrlEnum.CTRL_pack, CryptoZbkbCtrlpack -> CryptoZbkbCtrlpackEnum.CTRL_PACKH)) )) } // override def setup override def build(pipeline: VexRiscv): Unit = { @@ -486,46 +476,40 @@ class CryptoZkbPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] import pipeline.config._ execute plug new Area{ import execute._ - val val_bitwise = input(CryptoZkbCtrlbitwise).mux( - CryptoZkbCtrlbitwiseEnum.CTRL_ANDN -> (input(SRC1) & ~input(SRC2)).asBits, - CryptoZkbCtrlbitwiseEnum.CTRL_ORN -> (input(SRC1) | ~input(SRC2)).asBits, - CryptoZkbCtrlbitwiseEnum.CTRL_XNOR -> (input(SRC1) ^ ~input(SRC2)).asBits - ) // mux bitwise - val val_rotation = input(CryptoZkbCtrlrotation).mux( - CryptoZkbCtrlrotationEnum.CTRL_ROL -> input(SRC1).rotateLeft((input(SRC2)&31)(4 downto 0).asUInt).asBits, - CryptoZkbCtrlrotationEnum.CTRL_ROR -> input(SRC1).rotateRight((input(SRC2)&31)(4 downto 0).asUInt).asBits - ) // mux rotation - val val_pack = input(CryptoZkbCtrlpack).mux( - CryptoZkbCtrlpackEnum.CTRL_PACK -> (input(SRC2)(15 downto 0) ## input(SRC1)(15 downto 0)).asBits, - CryptoZkbCtrlpackEnum.CTRL_PACKH -> B"16'x0000" ## (input(SRC2)(7 downto 0) ## input(SRC1)(7 downto 0)).asBits, - CryptoZkbCtrlpackEnum.CTRL_PACKU -> (input(SRC2)(31 downto 16) ## input(SRC1)(31 downto 16)).asBits - ) // mux pack - val val_xperm = input(CryptoZkbCtrlxperm).mux( - CryptoZkbCtrlxpermEnum.CTRL_XPERMdotB -> fun_xperm_b(input(SRC1), input(SRC2)).asBits, - CryptoZkbCtrlxpermEnum.CTRL_XPERMdotN -> fun_xperm_n(input(SRC1), input(SRC2)).asBits - ) // mux xperm - val val_grevorc = input(CryptoZkbCtrlgrevorc).mux( - CryptoZkbCtrlgrevorcEnum.CTRL_REV8 -> fun_rev8(input(SRC1)).asBits, - CryptoZkbCtrlgrevorcEnum.CTRL_REVdotB -> fun_revdotb(input(SRC1)).asBits + val val_grevorc = input(CryptoZbkbCtrlgrevorc).mux( + CryptoZbkbCtrlgrevorcEnum.CTRL_REV8 -> fun_rev8(input(SRC1)).asBits, + CryptoZbkbCtrlgrevorcEnum.CTRL_REVdotB -> fun_revdotb(input(SRC1)).asBits ) // mux grevorc - val val_shuffle = input(CryptoZkbCtrlshuffle).mux( - CryptoZkbCtrlshuffleEnum.CTRL_UNZIP -> fun_unzip(input(SRC1)).asBits, - CryptoZkbCtrlshuffleEnum.CTRL_ZIP -> fun_zip(input(SRC1)).asBits + val val_shuffle = input(CryptoZbkbCtrlshuffle).mux( + CryptoZbkbCtrlshuffleEnum.CTRL_UNZIP -> fun_unzip(input(SRC1)).asBits, + CryptoZbkbCtrlshuffleEnum.CTRL_ZIP -> fun_zip(input(SRC1)).asBits ) // mux shuffle - insert(CryptoZkb_FINAL_OUTPUT) := input(CryptoZkbCtrl).mux( - CryptoZkbCtrlEnum.CTRL_bitwise -> val_bitwise.asBits, - CryptoZkbCtrlEnum.CTRL_rotation -> val_rotation.asBits, - CryptoZkbCtrlEnum.CTRL_pack -> val_pack.asBits, - CryptoZkbCtrlEnum.CTRL_xperm -> val_xperm.asBits, - CryptoZkbCtrlEnum.CTRL_grevorc -> val_grevorc.asBits, - CryptoZkbCtrlEnum.CTRL_shuffle -> val_shuffle.asBits + val val_bitwise = input(CryptoZbkbCtrlbitwise).mux( + CryptoZbkbCtrlbitwiseEnum.CTRL_ANDN -> (input(SRC1) & ~input(SRC2)).asBits, + CryptoZbkbCtrlbitwiseEnum.CTRL_ORN -> (input(SRC1) | ~input(SRC2)).asBits, + CryptoZbkbCtrlbitwiseEnum.CTRL_XNOR -> (input(SRC1) ^ ~input(SRC2)).asBits + ) // mux bitwise + val val_rotation = input(CryptoZbkbCtrlrotation).mux( + CryptoZbkbCtrlrotationEnum.CTRL_ROL -> input(SRC1).rotateLeft((input(SRC2)&31)(4 downto 0).asUInt).asBits, + CryptoZbkbCtrlrotationEnum.CTRL_ROR -> input(SRC1).rotateRight((input(SRC2)&31)(4 downto 0).asUInt).asBits + ) // mux rotation + val val_pack = input(CryptoZbkbCtrlpack).mux( + CryptoZbkbCtrlpackEnum.CTRL_PACK -> (input(SRC2)(15 downto 0) ## input(SRC1)(15 downto 0)).asBits, + CryptoZbkbCtrlpackEnum.CTRL_PACKH -> B"16'x0000" ## (input(SRC2)(7 downto 0) ## input(SRC1)(7 downto 0)).asBits + ) // mux pack + insert(CryptoZbkb_FINAL_OUTPUT) := input(CryptoZbkbCtrl).mux( + CryptoZbkbCtrlEnum.CTRL_grevorc -> val_grevorc.asBits, + CryptoZbkbCtrlEnum.CTRL_shuffle -> val_shuffle.asBits, + CryptoZbkbCtrlEnum.CTRL_bitwise -> val_bitwise.asBits, + CryptoZbkbCtrlEnum.CTRL_rotation -> val_rotation.asBits, + CryptoZbkbCtrlEnum.CTRL_pack -> val_pack.asBits ) // primary mux } // execute plug newArea val injectionStage = if(earlyInjection) execute else memory injectionStage plug new Area { import injectionStage._ - when (arbitration.isValid && input(IS_CryptoZkb)) { - output(REGFILE_WRITE_DATA) := input(CryptoZkb_FINAL_OUTPUT) + when (arbitration.isValid && input(IS_CryptoZbkb)) { + output(REGFILE_WRITE_DATA) := input(CryptoZbkb_FINAL_OUTPUT) } // when input is } // injectionStage plug newArea } // override def build diff --git a/CryptoZkg.scala b/CryptoZbkc.scala similarity index 85% rename from CryptoZkg.scala rename to CryptoZbkc.scala index 8e4223d..e6bb518 100644 --- a/CryptoZkg.scala +++ b/CryptoZbkc.scala @@ -3,11 +3,15 @@ package vexriscv.plugin import spinal.core._ import vexriscv.{Stageable, DecoderService, VexRiscv} -object CryptoZkgPlugin { - object CryptoZkgCtrlEnum extends SpinalEnum(binarySequential) { - val CTRL_CLMUL = newElement() +object CryptoZbkcPlugin { + object CryptoZbkcCtrlclmulEnum extends SpinalEnum(binarySequential) { + val CTRL_CLMUL, CTRL_CLMULRH = newElement() } - object CryptoZkgCtrl extends Stageable(CryptoZkgCtrlEnum()) + object CryptoZbkcCtrlEnum extends SpinalEnum(binarySequential) { + val CTRL_clmul = newElement() + } + object CryptoZbkcCtrlclmul extends Stageable(CryptoZbkcCtrlclmulEnum()) + object CryptoZbkcCtrl extends Stageable(CryptoZbkcCtrlEnum()) // Prologue def fun_clmul(rs1:Bits, rs2:Bits) : Bits = { @@ -86,10 +90,10 @@ object CryptoZkgPlugin { // End prologue } // object Plugin -class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] { - import CryptoZkgPlugin._ - object IS_CryptoZkg extends Stageable(Bool) - object CryptoZkg_FINAL_OUTPUT extends Stageable(Bits(32 bits)) +class CryptoZbkcPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] { + import CryptoZbkcPlugin._ + object IS_CryptoZbkc extends Stageable(Bool) + object CryptoZbkc_FINAL_OUTPUT extends Stageable(Bits(32 bits)) override def setup(pipeline: VexRiscv): Unit = { import pipeline.config._ val immediateActions = List[(Stageable[_ <: BaseType],Any)]( @@ -99,7 +103,7 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, - IS_CryptoZkg -> True + IS_CryptoZbkc -> True ) val binaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -109,7 +113,7 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, RS2_USE -> True, - IS_CryptoZkg -> True + IS_CryptoZbkc -> True ) val unaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -117,7 +121,7 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, - IS_CryptoZkg -> True + IS_CryptoZbkc -> True ) val ternaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -129,7 +133,7 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] RS1_USE -> True, RS2_USE -> True, RS3_USE -> True, - IS_CryptoZkg -> True + IS_CryptoZbkc -> True ) val immTernaryActions = List[(Stageable[_ <: BaseType],Any)]( SRC1_CTRL -> Src1CtrlEnum.RS, @@ -140,13 +144,15 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] BYPASSABLE_MEMORY_STAGE -> True, RS1_USE -> True, RS3_USE -> True, - IS_CryptoZkg -> True + IS_CryptoZbkc -> True ) def CLMUL_KEY = M"0000101----------001-----0110011" + def CLMULRH_KEY = M"0000101----------01------0110011" val decoderService = pipeline.service(classOf[DecoderService]) - decoderService.addDefault(IS_CryptoZkg, False) + decoderService.addDefault(IS_CryptoZbkc, False) decoderService.add(List( - CLMUL_KEY -> (binaryActions ++ List(CryptoZkgCtrl -> CryptoZkgCtrlEnum.CTRL_CLMUL)) + CLMUL_KEY -> (binaryActions ++ List(CryptoZbkcCtrl -> CryptoZbkcCtrlEnum.CTRL_clmul, CryptoZbkcCtrlclmul -> CryptoZbkcCtrlclmulEnum.CTRL_CLMUL)), + CLMULRH_KEY -> (binaryActions ++ List(CryptoZbkcCtrl -> CryptoZbkcCtrlEnum.CTRL_clmul, CryptoZbkcCtrlclmul -> CryptoZbkcCtrlclmulEnum.CTRL_CLMULRH)) )) } // override def setup override def build(pipeline: VexRiscv): Unit = { @@ -154,13 +160,17 @@ class CryptoZkgPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] import pipeline.config._ execute plug new Area{ import execute._ - insert(CryptoZkg_FINAL_OUTPUT) := fun_clmul(input(SRC1),input(SRC2)).asBits + val val_clmul = input(CryptoZbkcCtrlclmul).mux( + CryptoZbkcCtrlclmulEnum.CTRL_CLMUL -> fun_clmul(input(SRC1),input(SRC2)).asBits, + CryptoZbkcCtrlclmulEnum.CTRL_CLMULRH -> fun_clmulrh(input(SRC1),input(SRC2), input(INSTRUCTION)(12)).asBits + ) // mux clmul + insert(CryptoZbkc_FINAL_OUTPUT) := val_clmul.asBits } // execute plug newArea val injectionStage = if(earlyInjection) execute else memory injectionStage plug new Area { import injectionStage._ - when (arbitration.isValid && input(IS_CryptoZkg)) { - output(REGFILE_WRITE_DATA) := input(CryptoZkg_FINAL_OUTPUT) + when (arbitration.isValid && input(IS_CryptoZbkc)) { + output(REGFILE_WRITE_DATA) := input(CryptoZbkc_FINAL_OUTPUT) } // when input is } // injectionStage plug newArea } // override def build diff --git a/CryptoZbkx.scala b/CryptoZbkx.scala new file mode 100644 index 0000000..d85fce5 --- /dev/null +++ b/CryptoZbkx.scala @@ -0,0 +1,457 @@ +// WARNING: this is auto-generated code! +// See https://github.com/rdolbeau/VexRiscvBPluginGenerator/ +package vexriscv.plugin +import spinal.core._ +import vexriscv.{Stageable, DecoderService, VexRiscv} +object CryptoZbkxPlugin { + object CryptoZbkxCtrlxpermEnum extends SpinalEnum(binarySequential) { + val CTRL_XPERMdotB, CTRL_XPERMdotN = newElement() + } + object CryptoZbkxCtrlEnum extends SpinalEnum(binarySequential) { + val CTRL_xperm = newElement() + } + object CryptoZbkxCtrlxperm extends Stageable(CryptoZbkxCtrlxpermEnum()) + object CryptoZbkxCtrl extends Stageable(CryptoZbkxCtrlEnum()) +// Prologue + + // function implementing the semantic of 32-bits generalized reverse + def fun_grev( a:Bits, b:Bits ) : Bits = { + val x1 = ((b&B"32'x00000001")===B"32'x00000001") ? (((a & B"32'x55555555") |<< 1) | ((a & B"32'xAAAAAAAA") |>> 1)) | a + val x2 = ((b&B"32'x00000002")===B"32'x00000002") ? (((x1 & B"32'x33333333") |<< 2) | ((x1 & B"32'xCCCCCCCC") |>> 2)) | x1 + val x4 = ((b&B"32'x00000004")===B"32'x00000004") ? (((x2 & B"32'x0F0F0F0F") |<< 4) | ((x2 & B"32'xF0F0F0F0") |>> 4)) | x2 + val x8 = ((b&B"32'x00000008")===B"32'x00000008") ? (((x4 & B"32'x00FF00FF") |<< 8) | ((x4 & B"32'xFF00FF00") |>> 8)) | x4 + val x16 = ((b&B"32'x00000010")===B"32'x00000010") ? (((x8 & B"32'x0000FFFF") |<<16) | ((x8 & B"32'xFFFF0000") |>>16)) | x8 + x16 // return value + } + // function implementing the semantic of 32-bits generalized OR-combine + def fun_gorc( a:Bits, b:Bits ) : Bits = { + val x1 = ((b&B"32'x00000001")===B"32'x00000001") ? (a | ((a & B"32'x55555555") |<< 1) | ((a & B"32'xAAAAAAAA") |>> 1)) | a + val x2 = ((b&B"32'x00000002")===B"32'x00000002") ? (x1 | ((x1 & B"32'x33333333") |<< 2) | ((x1 & B"32'xCCCCCCCC") |>> 2)) | x1 + val x4 = ((b&B"32'x00000004")===B"32'x00000004") ? (x2 | ((x2 & B"32'x0F0F0F0F") |<< 4) | ((x2 & B"32'xF0F0F0F0") |>> 4)) | x2 + val x8 = ((b&B"32'x00000008")===B"32'x00000008") ? (x4 | ((x4 & B"32'x00FF00FF") |<< 8) | ((x4 & B"32'xFF00FF00") |>> 8)) | x4 + val x16 = ((b&B"32'x00000010")===B"32'x00000010") ? (x8 | ((x8 & B"32'x0000FFFF") |<<16) | ((x8 & B"32'xFFFF0000") |>>16)) | x8 + x16 // return value + } + + // helper function for the implementation of the generalized shuffles + def fun_shuffle32_stage(src:Bits, maskL:Bits, maskR:Bits, N:Int) : Bits = { + val x = src & ~(maskL | maskR) + val x2 = x | ((src |<< N) & maskL) | ((src |>> N) & maskR); + x2 // return value + } + // function implementing the semantic of 32-bits generalized shuffle + def fun_shfl32(a:Bits, b:Bits) : Bits = { + val x = a; + val x1 = ((b&B"32'x00000008")===B"32'x00000008") ? fun_shuffle32_stage(x , B"32'x00FF0000", B"32'x0000FF00", 8) | x; + val x2 = ((b&B"32'x00000004")===B"32'x00000004") ? fun_shuffle32_stage(x1, B"32'x0F000F00", B"32'x00F000F0", 4) | x1; + val x3 = ((b&B"32'x00000002")===B"32'x00000002") ? fun_shuffle32_stage(x2, B"32'x30303030", B"32'x0C0C0C0C", 2) | x2; + val x4 = ((b&B"32'x00000001")===B"32'x00000001") ? fun_shuffle32_stage(x3, B"32'x44444444", B"32'x22222222", 1) | x3; + x4 // return value + } + // function implementing the semantic of 32-bits generalized unshuffle + def fun_unshfl32(a:Bits, b:Bits) : Bits = { + val x = a; + val x1 = ((b&B"32'x00000001")===B"32'x00000001") ? fun_shuffle32_stage(x , B"32'x44444444", B"32'x22222222", 1) | x; + val x2 = ((b&B"32'x00000002")===B"32'x00000002") ? fun_shuffle32_stage(x1, B"32'x30303030", B"32'x0C0C0C0C", 2) | x1; + val x3 = ((b&B"32'x00000004")===B"32'x00000004") ? fun_shuffle32_stage(x2, B"32'x0F000F00", B"32'x00F000F0", 4) | x2; + val x4 = ((b&B"32'x00000008")===B"32'x00000008") ? fun_shuffle32_stage(x3, B"32'x00FF0000", B"32'x0000FF00", 8) | x3; + x4 // return value + } + + + // this is trying to look like DOI 10.2478/jee-2015-0054 + def fun_clz_NLCi(x:Bits): Bits = { + val r2 = (~(x(0) | x(1) | x(2) | x(3))) + val r1 = (~(x(2) | x(3))) + val r0 = (~(x(3) | (x(1) & ~x(2)))) + val r = r2 ## r1 ## r0 + r // return value + } + def fun_clz_BNE(a:Bits) : Bits = { + val a01 = ~(a(0) & a(1)) + val a23 = ~(a(2) & a(3)) + + val a45 = ~(a(4) & a(5)) + val a67 = ~(a(6) & a(7)) + + val a0123 = ~(a01 | a23) // also r(2) + val a4567 = ~(a45 | a67) + + val a56 = ~(a(5) & ~a(6)) + val a024 = (a(0) & a(2) & a(4)) // AND not NAND + val a13 = ~(a(1) & a(3)) + val a12 = ~(a(1) & ~a(2)) + + val r3 = ((a0123 & a4567)) // AND not NAND + val r2 = (a0123) + val r1 = (~(a01 | (~a23 & a45))) + val r0 = (~((~((a56) & (a024))) & (~((a13) & (a12) & (a(0)))))) + + val r = r3 ## r2 ## r1 ##r0 + + r // return value + } + // 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 nlc6 = fun_clz_NLCi(in(27 downto 24)) + val nlc5 = fun_clz_NLCi(in(23 downto 20)) + val nlc4 = fun_clz_NLCi(in(19 downto 16)) + val nlc3 = fun_clz_NLCi(in(15 downto 12)) + val nlc2 = fun_clz_NLCi(in(11 downto 8)) + val nlc1 = fun_clz_NLCi(in( 7 downto 4)) + val nlc0 = fun_clz_NLCi(in( 3 downto 0)) + val a = nlc0(2) ## nlc1(2) ## nlc2(2) ## nlc3(2) ## nlc4(2) ## nlc5(2) ## nlc6(2) ## nlc7(2) + val bne = fun_clz_BNE(a) + + val muxo = (bne(2 downto 0)).mux( + B"3'b000" -> nlc7(1 downto 0), + B"3'b001" -> nlc6(1 downto 0), + B"3'b010" -> nlc5(1 downto 0), + B"3'b011" -> nlc4(1 downto 0), + B"3'b100" -> nlc3(1 downto 0), + B"3'b101" -> nlc2(1 downto 0), + B"3'b110" -> nlc1(1 downto 0), + B"3'b111" -> nlc0(1 downto 0) + ) + val r = (bne(3)) ? B"6'b100000" | (B"1'b0" ## bne(2 downto 0) ## muxo(1 downto 0)) // 6 bits + + r.resize(32) // return value + } + + // naive popcnt + def fun_popcnt(in:Bits) : Bits = { + val r = in(0).asBits.resize(6).asUInt + in(1).asBits.resize(6).asUInt + in(2).asBits.resize(6).asUInt + in(3).asBits.resize(6).asUInt + + in(4).asBits.resize(6).asUInt + in(5).asBits.resize(6).asUInt + in(6).asBits.resize(6).asUInt + in(7).asBits.resize(6).asUInt + + in(8).asBits.resize(6).asUInt + in(9).asBits.resize(6).asUInt + in(10).asBits.resize(6).asUInt + in(11).asBits.resize(6).asUInt + + in(12).asBits.resize(6).asUInt + in(13).asBits.resize(6).asUInt + in(14).asBits.resize(6).asUInt + in(15).asBits.resize(6).asUInt + + in(16).asBits.resize(6).asUInt + in(17).asBits.resize(6).asUInt + in(18).asBits.resize(6).asUInt + in(19).asBits.resize(6).asUInt + + in(20).asBits.resize(6).asUInt + in(21).asBits.resize(6).asUInt + in(22).asBits.resize(6).asUInt + in(23).asBits.resize(6).asUInt + + in(24).asBits.resize(6).asUInt + in(25).asBits.resize(6).asUInt + in(26).asBits.resize(6).asUInt + in(27).asBits.resize(6).asUInt + + in(28).asBits.resize(6).asUInt + in(29).asBits.resize(6).asUInt + in(30).asBits.resize(6).asUInt + in(31).asBits.resize(6).asUInt + + r.asBits.resize(32) // return value + } + + //XPERMs + def fun_xperm_n(rs1:Bits, rs2:Bits) : Bits = { + val i0 = rs2(3 downto 0).asUInt + val i1 = rs2(7 downto 4).asUInt + val i2 = rs2(11 downto 8).asUInt + val i3 = rs2(15 downto 12).asUInt + val i4 = rs2(19 downto 16).asUInt + val i5 = rs2(23 downto 20).asUInt + val i6 = rs2(27 downto 24).asUInt + val i7 = rs2(31 downto 28).asUInt + val r0 = (i0).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r1 = (i1).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r2 = (i2).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r3 = (i3).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r4 = (i4).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r5 = (i5).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r6 = (i6).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + val r7 = (i7).mux( + 0 -> rs1(3 downto 0), + 1 -> rs1(7 downto 4), + 2 -> rs1(11 downto 8), + 3 -> rs1(15 downto 12), + 4 -> rs1(19 downto 16), + 5 -> rs1(23 downto 20), + 6 -> rs1(27 downto 24), + 7 -> rs1(31 downto 28), + default -> B"4'b0000" + ) + r7 ## r6 ## r5 ## r4 ## r3 ## r2 ## r1 ## r0 // return value + } + def fun_xperm_b(rs1:Bits, rs2:Bits) : Bits = { + val i0 = rs2(7 downto 0).asUInt; + val i1 = rs2(15 downto 8).asUInt; + val i2 = rs2(23 downto 16).asUInt; + val i3 = rs2(31 downto 24).asUInt; + val r0 = (i0).mux( + 0 -> rs1(7 downto 0), + 1 -> rs1(15 downto 8), + 2 -> rs1(23 downto 16), + 3 -> rs1(31 downto 24), + default -> B"8'b00000000" + ) + val r1 = (i1).mux( + 0 -> rs1(7 downto 0), + 1 -> rs1(15 downto 8), + 2 -> rs1(23 downto 16), + 3 -> rs1(31 downto 24), + default -> B"8'b00000000" + ) + val r2 = (i2).mux( + 0 -> rs1(7 downto 0), + 1 -> rs1(15 downto 8), + 2 -> rs1(23 downto 16), + 3 -> rs1(31 downto 24), + default -> B"8'b00000000" + ) + val r3 = (i3).mux( + 0 -> rs1(7 downto 0), + 1 -> rs1(15 downto 8), + 2 -> rs1(23 downto 16), + 3 -> rs1(31 downto 24), + default -> B"8'b00000000" + ) + r3 ## r2 ## r1 ## r0 // return value + } + def fun_xperm_h(rs1:Bits, rs2:Bits) : Bits = { + val i0 = rs2(15 downto 0).asUInt; + val i1 = rs2(31 downto 16).asUInt; + val r0 = (i0).mux( + 0 -> rs1(15 downto 0), + 1 -> rs1(31 downto 16), + default -> B"16'x0000" + ) + val r1 = (i1).mux( + 0 -> rs1(15 downto 0), + 1 -> rs1(31 downto 16), + default -> B"16'x0000" + ) + r1 ## r0 // return value + } + + def fun_fsl(rs1:Bits, rs3:Bits, rs2:Bits) : Bits = { + val rawshamt = (rs2 & B"32'x0000003F").asUInt + val shamt = (rawshamt >= 32) ? (rawshamt - 32) | (rawshamt) + val A = (shamt === rawshamt) ? (rs1) | (rs3) + val B = (shamt === rawshamt) ? (rs3) | (rs1) + val r = (shamt === 0) ? (A) | ((A |<< shamt) | (B |>> (32-shamt))) + + r // return value + } + + def fun_fsr(rs1:Bits, rs3:Bits, rs2:Bits) : Bits = { + val rawshamt = (rs2 & B"32'x0000003F").asUInt + val shamt = (rawshamt >= 32) ? (rawshamt - 32) | (rawshamt) + val A = (shamt === rawshamt) ? (rs1) | (rs3) + val B = (shamt === rawshamt) ? (rs3) | (rs1) + val r = (shamt === 0) ? (A) | ((A |>> shamt) | (B |<< (32-shamt))) + + r // return value + } + + def fun_bfp(rs1:Bits, rs2:Bits) : Bits = { + val off = rs2(20 downto 16).asUInt + val rawlen = rs2(27 downto 24).asUInt + val convlen = (rawlen === 0) ? (rawlen+16) | (rawlen) + val len = ((convlen + off) > 32) ? (32 - off) | (convlen) + val allones = B"16'xFFFF" + val lenones = (allones |>> (16-len)) + //val one = B"17'x00001" + //val lenones = (((one |<< len).asUInt) - 1).asBits; + val mask = (lenones.resize(32) |<< off); + val data = (rs2 & lenones.resize(32)) |<< off; + + val r = (rs1 & ~mask) | data + + r // return value + } + + + def fun_rev8(a:Bits) : Bits = { + val r = a(7 downto 0) ## a(15 downto 8) ## a(23 downto 16) ## a(31 downto 24) + + r // return value + } + def fun_orcb(a:Bits) : Bits = { + val x1 = (a | ((a & B"32'x55555555") |<< 1) | ((a & B"32'xAAAAAAAA") |>> 1)) + val x2 = (x1 | ((x1 & B"32'x33333333") |<< 2) | ((x1 & B"32'xCCCCCCCC") |>> 2)) + val x4 = (x2 | ((x2 & B"32'x0F0F0F0F") |<< 4) | ((x2 & B"32'xF0F0F0F0") |>> 4)) + + x4 // return value + } + def fun_revdotb(a:Bits) : Bits = { + val r = a(24) ## a(25) ## a(26) ## a(27) ## a(28) ## a(29) ## a(30) ## a(31) ## + a(16) ## a(17) ## a(18) ## a(19) ## a(20) ## a(21) ## a(22) ## a(23) ## + a( 8) ## a( 9) ## a(10) ## a(11) ## a(12) ## a(13) ## a(14) ## a(15) ## + a( 0) ## a( 1) ## a( 2) ## a( 3) ## a( 4) ## a( 5) ## a( 6) ## a( 7) + + r // return value; + } + // helper function for the implementation of the generalized shuffles + def fun_shuffle32bis_stage(src:Bits, maskL:Bits, maskR:Bits, N:Int) : Bits = { + val x = src & ~(maskL | maskR) + val x2 = x | ((src |<< N) & maskL) | ((src |>> N) & maskR); + x2 // return value + } + def fun_zip(a:Bits) : Bits = { + val x = a; + val x1 = fun_shuffle32bis_stage(x , B"32'x00FF0000", B"32'x0000FF00", 8) + val x2 = fun_shuffle32bis_stage(x1, B"32'x0F000F00", B"32'x00F000F0", 4) + val x3 = fun_shuffle32bis_stage(x2, B"32'x30303030", B"32'x0C0C0C0C", 2) + val x4 = fun_shuffle32bis_stage(x3, B"32'x44444444", B"32'x22222222", 1) + x4 // return value + } + def fun_unzip(a:Bits) : Bits = { + val x = a; + val x1 = fun_shuffle32bis_stage(x , B"32'x44444444", B"32'x22222222", 1) + val x2 = fun_shuffle32bis_stage(x1, B"32'x30303030", B"32'x0C0C0C0C", 2) + val x3 = fun_shuffle32bis_stage(x2, B"32'x0F000F00", B"32'x00F000F0", 4) + val x4 = fun_shuffle32bis_stage(x3, B"32'x00FF0000", B"32'x0000FF00", 8) + x4 // return value + } + +// End prologue +} // object Plugin +class CryptoZbkxPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] { + import CryptoZbkxPlugin._ + object IS_CryptoZbkx extends Stageable(Bool) + object CryptoZbkx_FINAL_OUTPUT extends Stageable(Bits(32 bits)) + override def setup(pipeline: VexRiscv): Unit = { + import pipeline.config._ + val immediateActions = List[(Stageable[_ <: BaseType],Any)]( + SRC1_CTRL -> Src1CtrlEnum.RS, + SRC2_CTRL -> Src2CtrlEnum.IMI, + REGFILE_WRITE_VALID -> True, + BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), + BYPASSABLE_MEMORY_STAGE -> True, + RS1_USE -> True, + IS_CryptoZbkx -> True + ) + val binaryActions = List[(Stageable[_ <: BaseType],Any)]( + SRC1_CTRL -> Src1CtrlEnum.RS, + SRC2_CTRL -> Src2CtrlEnum.RS, + REGFILE_WRITE_VALID -> True, + BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), + BYPASSABLE_MEMORY_STAGE -> True, + RS1_USE -> True, + RS2_USE -> True, + IS_CryptoZbkx -> True + ) + val unaryActions = List[(Stageable[_ <: BaseType],Any)]( + SRC1_CTRL -> Src1CtrlEnum.RS, + REGFILE_WRITE_VALID -> True, + BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), + BYPASSABLE_MEMORY_STAGE -> True, + RS1_USE -> True, + IS_CryptoZbkx -> True + ) + val ternaryActions = List[(Stageable[_ <: BaseType],Any)]( + SRC1_CTRL -> Src1CtrlEnum.RS, + SRC2_CTRL -> Src2CtrlEnum.RS, + SRC3_CTRL -> Src3CtrlEnum.RS, + REGFILE_WRITE_VALID -> True, + BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), + BYPASSABLE_MEMORY_STAGE -> True, + RS1_USE -> True, + RS2_USE -> True, + RS3_USE -> True, + IS_CryptoZbkx -> True + ) + val immTernaryActions = List[(Stageable[_ <: BaseType],Any)]( + SRC1_CTRL -> Src1CtrlEnum.RS, + SRC2_CTRL -> Src2CtrlEnum.IMI, + SRC3_CTRL -> Src3CtrlEnum.RS, + REGFILE_WRITE_VALID -> True, + BYPASSABLE_EXECUTE_STAGE -> Bool(earlyInjection), + BYPASSABLE_MEMORY_STAGE -> True, + RS1_USE -> True, + RS3_USE -> True, + IS_CryptoZbkx -> True + ) + def XPERMdotN_KEY = M"0010100----------010-----0110011" + def XPERMdotB_KEY = M"0010100----------100-----0110011" + val decoderService = pipeline.service(classOf[DecoderService]) + decoderService.addDefault(IS_CryptoZbkx, False) + decoderService.add(List( + XPERMdotN_KEY -> (binaryActions ++ List(CryptoZbkxCtrl -> CryptoZbkxCtrlEnum.CTRL_xperm, CryptoZbkxCtrlxperm -> CryptoZbkxCtrlxpermEnum.CTRL_XPERMdotN)), + XPERMdotB_KEY -> (binaryActions ++ List(CryptoZbkxCtrl -> CryptoZbkxCtrlEnum.CTRL_xperm, CryptoZbkxCtrlxperm -> CryptoZbkxCtrlxpermEnum.CTRL_XPERMdotB)) + )) + } // override def setup + override def build(pipeline: VexRiscv): Unit = { + import pipeline._ + import pipeline.config._ + execute plug new Area{ + import execute._ + val val_xperm = input(CryptoZbkxCtrlxperm).mux( + CryptoZbkxCtrlxpermEnum.CTRL_XPERMdotB -> fun_xperm_b(input(SRC1), input(SRC2)).asBits, + CryptoZbkxCtrlxpermEnum.CTRL_XPERMdotN -> fun_xperm_n(input(SRC1), input(SRC2)).asBits + ) // mux xperm + insert(CryptoZbkx_FINAL_OUTPUT) := val_xperm.asBits + } // execute plug newArea + val injectionStage = if(earlyInjection) execute else memory + injectionStage plug new Area { + import injectionStage._ + when (arbitration.isValid && input(IS_CryptoZbkx)) { + output(REGFILE_WRITE_DATA) := input(CryptoZbkx_FINAL_OUTPUT) + } // when input is + } // injectionStage plug newArea + } // override def build +} // class Plugin diff --git a/CryptoZknd.scala b/CryptoZknd.scala index f171877..9f318b0 100644 --- a/CryptoZknd.scala +++ b/CryptoZknd.scala @@ -933,8 +933,8 @@ class CryptoZkndPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] RS3_USE -> True, IS_CryptoZknd -> True ) - def aes32dsmi_KEY = M"--11111----------000000000110011" - def aes32dsi_KEY = M"--11101----------000000000110011" + def aes32dsmi_KEY = M"--11111----------000-----0110011" + def aes32dsi_KEY = M"--11101----------000-----0110011" val decoderService = pipeline.service(classOf[DecoderService]) decoderService.addDefault(IS_CryptoZknd, False) decoderService.add(List( diff --git a/CryptoZkne.scala b/CryptoZkne.scala index 0035441..3f8cf80 100644 --- a/CryptoZkne.scala +++ b/CryptoZkne.scala @@ -933,8 +933,8 @@ class CryptoZknePlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] RS3_USE -> True, IS_CryptoZkne -> True ) - def aes32esmi_KEY = M"--11011----------000000000110011" - def aes32esi_KEY = M"--11001----------000000000110011" + def aes32esmi_KEY = M"--11011----------000-----0110011" + def aes32esi_KEY = M"--11001----------000-----0110011" val decoderService = pipeline.service(classOf[DecoderService]) decoderService.addDefault(IS_CryptoZkne, False) decoderService.add(List( diff --git a/CryptoZks.scala b/CryptoZks.scala index f60e444..8fea8ce 100644 --- a/CryptoZks.scala +++ b/CryptoZks.scala @@ -399,8 +399,8 @@ class CryptoZksPlugin(earlyInjection : Boolean = true) extends Plugin[VexRiscv] ) def SM3P0_KEY = M"000100001000-----001-----0010011" def SM3P1_KEY = M"000100001001-----001-----0010011" - def SM4ED_KEY = M"--11000----------000000000110011" - def SM4KS_KEY = M"--11010----------000000000110011" + def SM4ED_KEY = M"--11000----------000-----0110011" + def SM4KS_KEY = M"--11010----------000-----0110011" val decoderService = pipeline.service(classOf[DecoderService]) decoderService.addDefault(IS_CryptoZks, False) decoderService.add(List( diff --git a/Makefile b/Makefile index 2451436..1c664c4 100644 --- a/Makefile +++ b/Makefile @@ -89,14 +89,19 @@ BitManipZbs.scala: gen_plugin data_bitmanip.txt BitManipZbt.scala: gen_plugin data_bitmanip.txt ./gen_plugin -n BitManipZbt -i data_bitmanip.txt -I Zbt >| $@ -CryptoZkb.scala: gen_plugin data_bitmanip.txt data_bitmanip_ZbbOnly.txt - ./gen_plugin -n CryptoZkb -i data_bitmanip.txt -i data_bitmanip_ZbbOnly.txt -I Zkb >| $@ +CryptoZbkb.scala: gen_plugin data_bitmanip.txt data_bitmanip_ZbbOnly.txt + ./gen_plugin -n CryptoZbkb -i data_bitmanip.txt -i data_bitmanip_ZbbOnly.txt -I Zbkb >| $@ -## CryptoZkg doesn't require clmulr, so not 100% the same as Zbc -CryptoZkg.scala: gen_plugin data_clmul.txt - ./gen_plugin -n CryptoZkg -i data_clmul.txt -I CLMUL -I CLMULH >| $@ +CryptoZbkx.scala: gen_plugin data_bitmanip.txt data_bitmanip_ZbbOnly.txt + ./gen_plugin -n CryptoZbkx -i data_bitmanip.txt -i data_bitmanip_ZbbOnly.txt -I Zbkx >| $@ -## Full Zkn is Zknd + Zkne + Zknh + Zkg + Zkb +## CryptoZbkc doesn't require clmulr, so not 100% the same as Zbc +## However the current implementation has just the one entry for clmulh & clmulr +## So in practice this is identical to BitManipZbc +CryptoZbkc.scala: gen_plugin data_clmul.txt + ./gen_plugin -n CryptoZbkc -i data_clmul.txt -I Zbkc >| $@ + +## Full Zkn is Zknd + Zkne + Zknh + Zbkc + Zkb ## For Zkb, beware the overlap with a lot of B plugins CryptoZknd.scala: gen_plugin data_aes.txt @@ -132,9 +137,9 @@ B: BitManipZba.scala BitManipZbb.scala BitManipZbbZbp.scala BitManipZbc.scala Bi P: PackedSIMDBase.scala PackedSIMDSlow.scala PackedSIMDWide.scala -Z: CryptoZkb.scala CryptoZkg.scala CryptoZknd.scala CryptoZkne.scala CryptoZknh.scala CryptoZks.scala +K: CryptoZbkb.scala CryptoZbkx.scala CryptoZbkc.scala CryptoZknd.scala CryptoZkne.scala CryptoZknh.scala CryptoZks.scala -scala: B P Z +scala: B P K include $(DEPXX) diff --git a/data_aes.txt b/data_aes.txt index e56665b..4ae8ab8 100644 --- a/data_aes.txt +++ b/data_aes.txt @@ -1,17 +1,10 @@ -//for v0.8 of K scalar -//#define MASK_AES32ESMI 0x3e00707f -//#define MATCH_AES32ESMI 0x36000033 -//#define MASK_AES32ESI 0x3e00707f -//#define MATCH_AES32ESI 0x32000033 -//bs 11011 rs2 rs1==rd 000 rd 0110011 aes32esmi -//bs 11001 rs2 rs1==rd 000 rd 0110011 aes32esi +//for v0.9.2 of K scalar +I aes32esmi aes32esmi --11011----------000-----0110011 aes Zkne +I aes32esi aes32esi --11001----------000-----0110011 aes Zkne -I aes32esmi aes32esmi --11011----------000000000110011 aes Zkne -I aes32esi aes32esi --11001----------000000000110011 aes Zkne - -I aes32dsmi aes32dsmi --11111----------000000000110011 aes Zknd -I aes32dsi aes32dsi --11101----------000000000110011 aes Zknd +I aes32dsmi aes32dsmi --11111----------000-----0110011 aes Zknd +I aes32dsi aes32dsi --11101----------000-----0110011 aes Zknd S aes32esmi "fun_aes32esmi(input(SRC2), input(SRC1), input(INSTRUCTION)(31 downto 30))" S aes32esi "fun_aes32esi(input(SRC2), input(SRC1), input(INSTRUCTION)(31 downto 30))" diff --git a/data_bitmanip.txt b/data_bitmanip.txt index a9df3a3..4df971e 100644 --- a/data_bitmanip.txt +++ b/data_bitmanip.txt @@ -28,13 +28,13 @@ // register-register // inst semant pattern group/mux ext1 ext2 ext3 ext4 ext5 // ---- ----- ------- --------- ---- ---- ---- ---- ---- -I ANDN ANDN 0100000----------111-----0110011 bitwise Zbb Zbp Zkb -I ORN ORN 0100000----------110-----0110011 bitwise Zbb Zbp Zkb -I XNOR XNOR 0100000----------100-----0110011 bitwise Zbb Zbp Zkb +I ANDN ANDN 0100000----------111-----0110011 bitwise Zbb Zbp Zbkb +I ORN ORN 0100000----------110-----0110011 bitwise Zbb Zbp Zbkb +I XNOR XNOR 0100000----------100-----0110011 bitwise Zbb Zbp Zbkb I SLO SLO 0010000----------001-----0110011 shift Zxx I SRO SRO 0010000----------101-----0110011 shift Zxx -I ROL ROL 0110000----------001-----0110011 rotation Zbb Zbp Zkb -I ROR ROR 0110000----------101-----0110011 rotation Zbb Zbp Zkb +I ROL ROL 0110000----------001-----0110011 rotation Zbb Zbp Zbkb +I ROR ROR 0110000----------101-----0110011 rotation Zbb Zbp Zbkb I SH1ADD SH1ADD 0010000----------010-----0110011 sh_add Zba I SH2ADD SH2ADD 0010000----------100-----0110011 sh_add Zba I SH3ADD SH3ADD 0010000----------110-----0110011 sh_add Zba @@ -52,11 +52,11 @@ I SHFL SHFL 0000100----------001-----0110011 shuffle Zbp I UNSHFL UNSHFL 0000100----------101-----0110011 shuffle Zbp //I BDECOMPRESS BDECOMPRESS 0100100----------110-----0110011 BDECOMPRESS //I BCOMPRESS BCOMPRESS 0000100----------110-----0110011 BCOMPRESS -I PACK PACK 0000100----------100-----0110011 pack Zbp Zbe Zbf Zkb -I PACKU PACKU 0100100----------100-----0110011 pack Zbp Zkb +I PACK PACK 0000100----------100-----0110011 pack Zbp Zbe Zbf Zbkb +I PACKU PACKU 0100100----------100-----0110011 pack Zbp //I BMATOR BMATOR 0000100----------011-----0110011 BMATOR //I BMATXOR BMATXOR 0100100----------011-----0110011 BMATXOR -I PACKH PACKH 0000100----------111-----0110011 pack Zbp Zbe Zbf Zkb +I PACKH PACKH 0000100----------111-----0110011 pack Zbp Zbe Zbf Zbkb I BFP BFP 0100100----------111-----0110011 BFP Zbf //I ADDdotUW ADDdotUW 0000100----------000-----0111011 ADDdotUW //I SLOW SLOW 0010000----------001-----0111011 SLOW @@ -79,14 +79,14 @@ I BFP BFP 0100100----------111-----0110011 BFP Zbf //I PACKW PACKW 0000100----------100-----0111011 PACKW //I PACKUW PACKUW 0100100----------100-----0111011 PACKUW //I BFPW BFPW 0100100----------111-----0111011 BFPW -I XPERMdotN XPERMdotN 0010100----------010-----0110011 xperm Zbp Zkb -I XPERMdotB XPERMdotB 0010100----------100-----0110011 xperm Zbp Zkb +I XPERMdotN XPERMdotN 0010100----------010-----0110011 xperm Zbp Zbkx +I XPERMdotB XPERMdotB 0010100----------100-----0110011 xperm Zbp Zbkx I XPERMdotH XPERMdotH 0010100----------110-----0110011 xperm Zbp //I XPERMdotW XPERMdotW 0010100----------000-----0110011 XPERMdotW // register-immediate (7bits) I SLOI SLO 00100------------001-----0010011 shift Zxx I SROI SRO 00100------------101-----0010011 shift Zxx -I RORI ROR 01100------------101-----0010011 rotation Zbb Zbp Zkb +I RORI ROR 01100------------101-----0010011 rotation Zbb Zbp Zbkb I BCLRI BCLR 01001------------001-----0010011 singlebit Zbs I BSETI BSET 00101------------001-----0010011 singlebit Zbs I BINVI BINV 01101------------001-----0010011 singlebit Zbs diff --git a/data_bitmanip_ZbbOnly.txt b/data_bitmanip_ZbbOnly.txt index c408323..6720d55 100644 --- a/data_bitmanip_ZbbOnly.txt +++ b/data_bitmanip_ZbbOnly.txt @@ -16,14 +16,14 @@ I ZEXTdotH ZEXTdotH 000010000000-----100-----0110011 signextend Zbb // ORC.B -> GORCI w/ imm = 7 (0000111) I ORCdotB ORCdotB 001010000111-----101-----0010011 grevorc Zbb // REV8 -> GREVI w/ imm == 24 (0011000) -I REV8 REV8 011010011000-----101-----0010011 grevorc Zbb Zkb -// those are for Zkb only +I REV8 REV8 011010011000-----101-----0010011 grevorc Zbb Zbkb +// those are for Zbkb only // REVdotB -> GREVI w/ imm == 7 (0000111) -I REVdotB REVdotB 011010000111-----101-----0010011 grevorc Zkb +I REVdotB REVdotB 011010000111-----101-----0010011 grevorc Zbkb // ZIP -> SHFLI w/ imm == 01111 -I ZIP ZIP 000010001111-----001-----0010011 shuffle Zkb +I ZIP ZIP 000010001111-----001-----0010011 shuffle Zbkb // UNZIP -> UNSHFLI w/ imm == 01111 -I UNZIP UNZIP 000010001111-----101-----0010011 shuffle Zkb +I UNZIP UNZIP 000010001111-----101-----0010011 shuffle Zbkb // SEMANTIC S REV8 "fun_rev8(input(SRC1))" diff --git a/data_clmul.txt b/data_clmul.txt index 5a7c527..a9e91d8 100644 --- a/data_clmul.txt +++ b/data_clmul.txt @@ -1,5 +1,5 @@ -I CLMUL CLMUL 0000101----------001-----0110011 clmul Zbc Zkg -I CLMULRH CLMULRH 0000101----------01------0110011 clmul Zbc Zkg +I CLMUL CLMUL 0000101----------001-----0110011 clmul Zbc Zbkc +I CLMULRH CLMULRH 0000101----------01------0110011 clmul Zbc Zbkc S CLMUL "fun_clmul(input(SRC1),input(SRC2))" S CLMULRH "fun_clmulrh(input(SRC1),input(SRC2), input(INSTRUCTION)(12))" diff --git a/data_sm4.txt b/data_sm4.txt index b761047..508febb 100644 --- a/data_sm4.txt +++ b/data_sm4.txt @@ -1,5 +1,7 @@ -I SM4ED SM4ED --11000----------000000000110011 sm4 Zks Zksed -I SM4KS SM4KS --11010----------000000000110011 sm4 Zks Zksed +//for v0.9.2 of K scalar + +I SM4ED SM4ED --11000----------000-----0110011 sm4 Zks Zksed +I SM4KS SM4KS --11010----------000-----0110011 sm4 Zks Zksed S SM4ED "fun_sm4ed(input(SRC1), input(SRC2), input(INSTRUCTION)(31 downto 30))" S SM4KS "fun_sm4ks(input(SRC1), input(SRC2), input(INSTRUCTION)(31 downto 30))"