/* The bit field of immediate value in I-type instruction */ #define RV_I_IMM_SIGN_OPOFF 31 #define RV_I_IMM_11_0_OPOFF 20 #define RV_I_IMM_SIGN_OFF 12 #define RV_I_IMM_11_0_OFF 0 #define RV_I_IMM_11_0_MASK GENMASK(11, 0)
/* The bit field of immediate value in J-type instruction */ #define RV_J_IMM_SIGN_OPOFF 31 #define RV_J_IMM_10_1_OPOFF 21 #define RV_J_IMM_11_OPOFF 20 #define RV_J_IMM_19_12_OPOFF 12 #define RV_J_IMM_SIGN_OFF 20 #define RV_J_IMM_10_1_OFF 1 #define RV_J_IMM_11_OFF 11 #define RV_J_IMM_19_12_OFF 12 #define RV_J_IMM_10_1_MASK GENMASK(9, 0) #define RV_J_IMM_11_MASK GENMASK(0, 0) #define RV_J_IMM_19_12_MASK GENMASK(7, 0)
/* * U-type IMMs contain the upper 20bits [31:20] of an immediate with * the rest filled in by zeros, so no shifting required. Similarly, * bit31 contains the signed state, so no sign extension necessary.
*/ #define RV_U_IMM_SIGN_OPOFF 31 #define RV_U_IMM_31_12_OPOFF 0 #define RV_U_IMM_31_12_MASK GENMASK(31, 12)
/* The bit field of immediate value in B-type instruction */ #define RV_B_IMM_SIGN_OPOFF 31 #define RV_B_IMM_10_5_OPOFF 25 #define RV_B_IMM_4_1_OPOFF 8 #define RV_B_IMM_11_OPOFF 7 #define RV_B_IMM_SIGN_OFF 12 #define RV_B_IMM_10_5_OFF 5 #define RV_B_IMM_4_1_OFF 1 #define RV_B_IMM_11_OFF 11 #define RV_B_IMM_10_5_MASK GENMASK(5, 0) #define RV_B_IMM_4_1_MASK GENMASK(3, 0) #define RV_B_IMM_11_MASK GENMASK(0, 0)
/* * Get the immediate from a J-type instruction. * * @insn: instruction to process * Return: immediate
*/ staticinline s32 riscv_insn_extract_jtype_imm(u32 insn)
{ return RV_EXTRACT_JTYPE_IMM(insn);
}
/* * Update a J-type instruction with an immediate value. * * @insn: pointer to the jtype instruction * @imm: the immediate to insert into the instruction
*/ staticinlinevoid riscv_insn_insert_jtype_imm(u32 *insn, s32 imm)
{ /* drop the old IMMs, all jal IMM bits sit at 31:12 */
*insn &= ~GENMASK(31, 12);
*insn |= (RV_X(imm, RV_J_IMM_10_1_OFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OPOFF) |
(RV_X(imm, RV_J_IMM_11_OFF, RV_J_IMM_11_MASK) << RV_J_IMM_11_OPOFF) |
(RV_X(imm, RV_J_IMM_19_12_OFF, RV_J_IMM_19_12_MASK) << RV_J_IMM_19_12_OPOFF) |
(RV_X(imm, RV_J_IMM_SIGN_OFF, 1) << RV_J_IMM_SIGN_OPOFF);
}
/* * Put together one immediate from a U-type and I-type instruction pair. * * The U-type contains an upper immediate, meaning bits[31:12] with [11:0] * being zero, while the I-type contains a 12bit immediate. * Combined these can encode larger 32bit values and are used for example * in auipc + jalr pairs to allow larger jumps. * * @utype_insn: instruction containing the upper immediate * @itype_insn: instruction * Return: combined immediate
*/ staticinline s32 riscv_insn_extract_utype_itype_imm(u32 utype_insn, u32 itype_insn)
{
s32 imm;
/* * Update a set of two instructions (U-type + I-type) with an immediate value. * * Used for example in auipc+jalrs pairs the U-type instructions contains * a 20bit upper immediate representing bits[31:12], while the I-type * instruction contains a 12bit immediate representing bits[11:0]. * * This also takes into account that both separate immediates are * considered as signed values, so if the I-type immediate becomes * negative (BIT(11) set) the U-type part gets adjusted. * * @utype_insn: pointer to the utype instruction of the pair * @itype_insn: pointer to the itype instruction of the pair * @imm: the immediate to insert into the two instructions
*/ staticinlinevoid riscv_insn_insert_utype_itype_imm(u32 *utype_insn, u32 *itype_insn, s32 imm)
{ /* drop possible old IMM values */
*utype_insn &= ~(RV_U_IMM_31_12_MASK);
*itype_insn &= ~(RV_I_IMM_11_0_MASK << RV_I_IMM_11_0_OPOFF);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.