Open niuzhi1221 opened 7 months ago
Hello niuzhi1221, You could able to resolve the issue? Actually I am also trying to implement some custom instructions, but not able to figure it out after adding these custom instructions how to execute my targeted workload using these custom instructions. It will be really helpful if you have figured it our and guide me to implement it.
After seeing this C function:
double clamp (double x ) { return x < 0 ? 0 : x > 1 ? 1 : x ; }
I want to design a custom instruction named 'clp' , it uses F extesnion. The instruction format I designed is as follows:clp rd rs1 rs2 rs3 rm 26..25=1 6..2=0x15 1..0=3
First , I add the MASK_CLP and MATCH_CLP toriscv-gnu-toolchain/riscv-binutils /include/opcode/riscv-opc.h
. Then, inriscv-gnu-toolchain/riscv-binutils/opcodes/riscv-opc.c
I add the following content:{"clp", 0, INSN_CLASS_D_INX, "D,S,T,R", MATCH_CLP|MASK_RM, MASK_CLP|MASK_RM, match_opcode, 0}, {"clp", 0, INSN_CLASS_D_INX, "D,S,T,R,m", MATCH_CLP, MASK_CLP, match_opcode, 0},
After that , I recompiled my toolchain. To achieve command functionality, I want to simulate theclp
instruction in Spike.So I firstly add MATCH_CLP and MASK_CLP inspike/riscv/encoding.h
, then I make a file named clp.h inspike/riscv/insns
, I add the following content:require_either_extension('D', EXT_ZDINX);
require_fp;
softfloat_roundingMode = RM;
if(f64_lt(FRS1_D, FRS2_D)){
WRITE_FRD_D(FRS1_D);
}
else if(f64_lt(FRS3_D,FRS1_D)){
WRITE_FRD_D(FRS3_D);
}
else
WRITE_FRD_D(FRS2_D);
set_fp_exceptions;
Then , inspike/riscv/riscv.mk.in
file, I add this: inspike/disasm/disasm.cc
file , I add this: Then I recompiled my spike. I write a test C program namedclamp.c
: But I can't use commandspike pk clamp
to simulate it:Sincerely looking forward to your help!