|
| 1 | +-- |
| 2 | +-- SPDX-License-Identifier: BSD-2-Clause |
| 3 | +-- |
| 4 | +-- Copyright (c) 2019-2020 Alexandre Joannou |
| 5 | +-- Copyright (c) 2020 Peter Rugg |
| 6 | +-- Copyright (c) 2025 SCI Semiconductor |
| 7 | +-- All rights reserved. |
| 8 | +-- |
| 9 | +-- This software was developed by SRI International and the University of |
| 10 | +-- Cambridge Computer Laboratory (Department of Computer Science and |
| 11 | +-- Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the |
| 12 | +-- DARPA SSITH research programme. |
| 13 | +-- |
| 14 | +-- Redistribution and use in source and binary forms, with or without |
| 15 | +-- modification, are permitted provided that the following conditions |
| 16 | +-- are met: |
| 17 | +-- 1. Redistributions of source code must retain the above copyright |
| 18 | +-- notice, this list of conditions and the following disclaimer. |
| 19 | +-- 2. Redistributions in binary form must reproduce the above copyright |
| 20 | +-- notice, this list of conditions and the following disclaimer in the |
| 21 | +-- documentation and/or other materials provided with the distribution. |
| 22 | +-- |
| 23 | +-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 24 | +-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | +-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | +-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 27 | +-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 | +-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 29 | +-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | +-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | +-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 | +-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | +-- SUCH DAMAGE. |
| 34 | +-- |
| 35 | + |
| 36 | +{-| |
| 37 | + Module : RISCV.RV32_B |
| 38 | + Description : RISC-V RV32 bit manipulation extensions |
| 39 | +
|
| 40 | + The 'RISCV.RV32_B' module provides the description of the RISC-V RV32 |
| 41 | + Bit-Manipulation extension |
| 42 | +-} |
| 43 | + |
| 44 | +module RISCV.RV32_B ( |
| 45 | + -- * RV32 bitmanip, instruction definitions |
| 46 | + sh1add |
| 47 | +, sh2add |
| 48 | +, sh3add |
| 49 | +, andn |
| 50 | +, orn |
| 51 | +, xnor |
| 52 | +, clz |
| 53 | +, ctz |
| 54 | +, cpop |
| 55 | +, max |
| 56 | +, maxu |
| 57 | +, min |
| 58 | +, minu |
| 59 | +, sext_b |
| 60 | +, sext_h |
| 61 | +, zext_h |
| 62 | +, rol |
| 63 | +, ror |
| 64 | +, rori |
| 65 | +, orc_b |
| 66 | +, rev8 |
| 67 | +, clmul |
| 68 | +, clmulh |
| 69 | +, clmulr |
| 70 | +, bclr |
| 71 | +, bclri |
| 72 | +, bext |
| 73 | +, bexti |
| 74 | +, binv |
| 75 | +, binvi |
| 76 | +, bset |
| 77 | +, bseti |
| 78 | +, -- * RV32 bitmanip, others |
| 79 | + rv32_b_disass |
| 80 | +) where |
| 81 | + |
| 82 | +import RISCV.Helpers (prettyR, prettyI, prettyR_nors2) |
| 83 | +import InstrCodec (DecodeBranch, (-->), encode, Instruction) |
| 84 | +import Prelude hiding (min, max) |
| 85 | + |
| 86 | +-- Zba |
| 87 | +sh1add_raw = "0010000 rs2[4:0] rs1[4:0] 010 rd[4:0] 0110011" |
| 88 | +sh1add rd rs1 rs2 = encode sh1add_raw rs2 rs1 rd |
| 89 | +sh2add_raw = "0010000 rs2[4:0] rs1[4:0] 100 rd[4:0] 0110011" |
| 90 | +sh2add rd rs1 rs2 = encode sh2add_raw rs2 rs1 rd |
| 91 | +sh3add_raw = "0010000 rs2[4:0] rs1[4:0] 110 rd[4:0] 0110011" |
| 92 | +sh3add rd rs1 rs2 = encode sh3add_raw rs2 rs1 rd |
| 93 | + |
| 94 | +-- Zbb |
| 95 | +andn_raw = "0100000 rs2[4:0] rs1[4:0] 111 rd[4:0] 0110011" |
| 96 | +andn rd rs1 rs2 = encode andn_raw rs2 rs1 rd |
| 97 | +orn_raw = "0100000 rs2[4:0] rs1[4:0] 110 rd[4:0] 0110011" |
| 98 | +orn rd rs1 rs2 = encode orn_raw rs2 rs1 rd |
| 99 | +xnor_raw = "0100000 rs2[4:0] rs1[4:0] 100 rd[4:0] 0110011" |
| 100 | +xnor rd rs1 rs2 = encode xnor_raw rs2 rs1 rd |
| 101 | + |
| 102 | +clz_raw = "0110000 00000 rs1[4:0] 001 rd[4:0] 0010011" |
| 103 | +clz rd rs1 = encode clz_raw rs1 rd |
| 104 | +ctz_raw = "0110000 00001 rs1[4:0] 001 rd[4:0] 0010011" |
| 105 | +ctz rd rs1 = encode ctz_raw rs1 rd |
| 106 | + |
| 107 | +cpop_raw = "0110000 00010 rs1[4:0] 001 rd[4:0] 0010011" |
| 108 | +cpop rd rs1 = encode cpop_raw rs1 rd |
| 109 | + |
| 110 | +max_raw = "0000101 rs2[4:0] rs1[4:0] 110 rd[4:0] 0110011" |
| 111 | +max rd rs1 rs2 = encode max_raw rs2 rs1 rd |
| 112 | +maxu_raw = "0000101 rs2[4:0] rs1[4:0] 111 rd[4:0] 0110011" |
| 113 | +maxu rd rs1 rs2 = encode maxu_raw rs2 rs1 rd |
| 114 | + |
| 115 | +min_raw = "0000101 rs2[4:0] rs1[4:0] 100 rd[4:0] 0110011" |
| 116 | +min rd rs1 rs2 = encode min_raw rs2 rs1 rd |
| 117 | +minu_raw = "0000101 rs2[4:0] rs1[4:0] 101 rd[4:0] 0110011" |
| 118 | +minu rd rs1 rs2 = encode minu_raw rs2 rs1 rd |
| 119 | + |
| 120 | +sext_b_raw = "0110000 00100 rs1[4:0] 001 rd[4:0] 0010011" |
| 121 | +sext_b rd rs1 = encode sext_b_raw rs1 rd |
| 122 | +sext_h_raw = "0110000 00101 rs1[4:0] 001 rd[4:0] 0010011" |
| 123 | +sext_h rd rs1 = encode sext_h_raw rs1 rd |
| 124 | +zext_h_raw = "0000100 00000 rs1[4:0] 100 rd[4:0] 0110011" |
| 125 | +zext_h rd rs1 = encode zext_h_raw rs1 rd |
| 126 | + |
| 127 | +-- Bitwise rotation |
| 128 | + |
| 129 | +rol_raw = "0110000 rs2[4:0] rs1[4:0] 001 rd[4:0] 0110011" |
| 130 | +rol rd rs1 rs2 = encode rol_raw rs2 rs1 rd |
| 131 | +ror_raw = "0110000 rs2[4:0] rs1[4:0] 101 rd[4:0] 0110011" |
| 132 | +ror rd rs1 rs2 = encode ror_raw rs2 rs1 rd |
| 133 | + |
| 134 | +-- The RV64 and RV32 encodings differ by the width of the shamt field, with |
| 135 | +-- RV32 specifying that shamt[5] is 0. Import qualified if needed. |
| 136 | +rori_raw = "0110000 shamt[4:0] rs1[4:0] 101 rd[4:0] 0010011" |
| 137 | +rori rd rs1 shamt = encode rori_raw shamt rs1 rd |
| 138 | + |
| 139 | +orc_b_raw = "0010100 00111 rs1[4:0] 101 rd[4:0] 0010011" |
| 140 | +orc_b rd rs1 = encode orc_b_raw rs1 rd |
| 141 | +rev8_raw = "0110100 11000 rs1[4:0] 101 rd[4:0] 0010011" |
| 142 | +rev8 rd rs1 = encode rev8_raw rs1 rd |
| 143 | + |
| 144 | +-- Zbc |
| 145 | + |
| 146 | +clmul_raw = "0000101 rs2[4:0] rs1[4:0] 001 rd[4:0] 0110011" |
| 147 | +clmul rd rs1 rs2 = encode clmul_raw rs2 rs1 rd |
| 148 | +clmulh_raw = "0000101 rs2[4:0] rs1[4:0] 011 rd[4:0] 0110011" |
| 149 | +clmulh rd rs1 rs2 = encode clmulh_raw rs2 rs1 rd |
| 150 | +clmulr_raw = "0000101 rs2[4:0] rs1[4:0] 010 rd[4:0] 0110011" |
| 151 | +clmulr rd rs1 rs2 = encode clmulr_raw rs2 rs1 rd |
| 152 | + |
| 153 | +-- Zbs |
| 154 | + |
| 155 | +bclr_raw = "0100100 rs2[4:0] rs1[4:0] 001 rd[4:0] 0110011" |
| 156 | +bclr rd rs1 rs2 = encode bclr_raw rs2 rs1 rd |
| 157 | + |
| 158 | +-- The RV64 and RV32 encodings differ by the width of the shamt field, with |
| 159 | +-- RV32 specifying that shamt[5] is 0. Import qualified if needed. |
| 160 | +bclri_raw = "0100100 shamt[4:0] rs1[4:0] 001 rd[4:0] 0010011" |
| 161 | +bclri rd rs1 shamt = encode bclri_raw shamt rs1 rd |
| 162 | + |
| 163 | +bext_raw = "0100100 rs2[4:0] rs1[4:0] 101 rd[4:0] 0110011" |
| 164 | +bext rd rs1 rs2 = encode bext_raw rs2 rs1 rd |
| 165 | + |
| 166 | +-- The RV64 and RV32 encodings differ by the width of the shamt field, with |
| 167 | +-- RV32 specifying that shamt[5] is 0. Import qualified if needed. |
| 168 | +bexti_raw = "0100100 shamt[4:0] rs1[4:0] 101 rd[4:0] 0010011" |
| 169 | +bexti rd rs1 shamt = encode bexti_raw shamt rs1 rd |
| 170 | + |
| 171 | +binv_raw = "0110100 rs2[4:0] rs1[4:0] 001 rd[4:0] 0110011" |
| 172 | +binv rd rs1 rs2 = encode binv_raw rs2 rs1 rd |
| 173 | + |
| 174 | +-- The RV64 and RV32 encodings differ by the width of the shamt field, with |
| 175 | +-- RV32 specifying that shamt[5] is 0. Import qualified if needed. |
| 176 | +binvi_raw = "0110100 shamt[4:0] rs1[4:0] 001 rd[4:0] 0010011" |
| 177 | +binvi rd rs1 shamt = encode binvi_raw shamt rs1 rd |
| 178 | + |
| 179 | +bset_raw = "0010100 rs2[4:0] rs1[4:0] 001 rd[4:0] 0110011" |
| 180 | +bset rd rs1 rs2 = encode bset_raw rs2 rs1 rd |
| 181 | + |
| 182 | +-- The RV64 and RV32 encodings differ by the width of the shamt field, with |
| 183 | +-- RV32 specifying that shamt[5] is 0. Import qualified if needed. |
| 184 | +bseti_raw = "0010100 shamt[4:0] rs1[4:0] 001 rd[4:0] 0010011" |
| 185 | +bseti rd rs1 shamt = encode bseti_raw shamt rs1 rd |
| 186 | + |
| 187 | +rv32_b_disass :: [DecodeBranch String] |
| 188 | +rv32_b_disass = [ sh1add_raw --> prettyR "sh1add" |
| 189 | + , sh2add_raw --> prettyR "sh2add" |
| 190 | + , sh3add_raw --> prettyR "sh3add" |
| 191 | + , andn_raw --> prettyR "andn" |
| 192 | + , orn_raw --> prettyR "orn" |
| 193 | + , xnor_raw --> prettyR "xnor" |
| 194 | + , clz_raw --> prettyR_nors2 "clz" |
| 195 | + , ctz_raw --> prettyR_nors2 "ctz" |
| 196 | + , cpop_raw --> prettyR_nors2 "cpop" |
| 197 | + , max_raw --> prettyR "max" |
| 198 | + , maxu_raw --> prettyR "maxu" |
| 199 | + , min_raw --> prettyR "min" |
| 200 | + , minu_raw --> prettyR "minu" |
| 201 | + , sext_b_raw --> prettyR_nors2 "sext.b" |
| 202 | + , sext_h_raw --> prettyR_nors2 "sext.h" |
| 203 | + , zext_h_raw --> prettyR_nors2 "zext.h" |
| 204 | + , rol_raw --> prettyR "rol" |
| 205 | + , ror_raw --> prettyR "ror" |
| 206 | + , rori_raw --> prettyI "rori" |
| 207 | + , orc_b_raw --> prettyR_nors2 "orc.b" |
| 208 | + , rev8_raw --> prettyR_nors2 "rev8.b" |
| 209 | + , clmul_raw --> prettyR "clmul" |
| 210 | + , clmulh_raw --> prettyR "clmulh" |
| 211 | + , clmulr_raw --> prettyR "clmulr" |
| 212 | + , bclr_raw --> prettyR "bclr" |
| 213 | + , bclri_raw --> prettyI "bclri" |
| 214 | + , bext_raw --> prettyR "bext" |
| 215 | + , bexti_raw --> prettyI "bexti" |
| 216 | + , binv_raw --> prettyR "binv" |
| 217 | + , binvi_raw --> prettyI "binvi" |
| 218 | + , bset_raw --> prettyR "bset" |
| 219 | + , bseti_raw --> prettyI "bseti" |
| 220 | + ] |
0 commit comments