I have added six new instructions as follows modulus(mod), gcd, fact, fsin.s, fcos.s and ftan.s. Once the build process over I am giving the following command to check these newly added instructions and I could see that the three instructon mod, gcd and fact is showing output as expected, but fsin.s, fcos.s and ftan.s instruction is throwing output as illegal operands. I had defined the fsin.s, fcos.s and ftan.s similar to single precision fsqrt.s instructions. Please suggest/guide me if I am making any mistake in these process so that these trigonometric instructions work properly:
(i) In the first step i have open up binutils/opcodes/riscv-opc.c and added these six instructions to the riscv_opcodes array.
{"mod", 0, INSN_CLASS_I, "d,s,t", MATCH_MOD, MASK_MOD, match_opcode, 0 },
{"gcd", 0, INSN_CLASS_I, "d,s,t", MATCH_GCD, MASK_GCD, match_opcode, 0 },
{"fact", 0, INSN_CLASS_I, "d,a", MATCH_FACT, MASK_FACT, match_opcode, 0 },
// Single-precision floating-point instruction subset similar to fsqrt.s
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FSIN_S|MASK_RM, MASK_FSIN_S|MASK_RM, match_opcode, 0 },
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s,m", MATCH_FSIN_S, MASK_FSIN_S, match_opcode, 0 },
{"fcos.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FCOS_S|MASK_RM, MASK_FCOS_S|MASK_RM, match_opcode, 0 },
{"fcos.s", 0, INSN_CLASS_F_INX, "d,s,m", MATCH_FCOS_S, MASK_FCOS_S, match_opcode, 0 },
{"ftan.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FTAN_S|MASK_RM, MASK_FTAN_S|MASK_RM, match_opcode, 0 },
{"ftan.s", 0, INSN_CLASS_F_INX, "d,s,m", MATCH_FTAN_S, MASK_FTAN_S, match_opcode, 0 },
(ii) Next, I have open up binutils/include/opcode/riscv-opc.h and added in definitions for the MATCH/MASK:
#define MATCH_GCD 0x6027
#define MASK_GCD 0xfe00707f
#define MATCH_FACT 0x2b
#define MASK_FACT 0x7f
#define MATCH_MOD 0x200006b
#define MASK_MOD 0xfe00707f
#define MATCH_FSIN_S 0x59000053
#define MASK_FSIN_S 0xfff0007f
#define MATCH_FCOS_S 0x5b000053
#define MASK_FCOS_S 0xfff0007f
#define MATCH_FTAN_S 0x5d000053
#define MASK_FTAN_S 0xfff0007f
Further down, where we are declaring our instructions, I have added each of them:
DECLARE_INSN(mod, MATCH_MOD, MASK_MOD)
DECLARE_INSN(gcd, MATCH_GCD, MASK_GCD)
DECLARE_INSN(fact, MATCH_FACT, MASK_FACT)
DECLARE_INSN(fsin_s, MATCH_FSIN_S, MASK_FSIN_S)
DECLARE_INSN(fcos_s, MATCH_FCOS_S, MASK_FCOS_S)
DECLARE_INSN(ftan_s, MATCH_FTAN_S, MASK_FTAN_S)
(iii) Then after executing the following configuration script built and build and installed the riscv-gnu-toolchain as per the commands you suggested earlier:
# then run the config command as follows:
./configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gcv --with-abi=lp64d --with-sim=spike --enable-multilib
# next execute the build and installed command
sudo make -j$(nproc) && sudo make build-sim
(iv)Once the build process over I am giving the following command to check these newly added instructions and I could see that the three instructon mod, gcd and fact is showing output as expected, but fsin.s, fcos.s and ftan.s instruction is throwing output as illegal operands. I had defined the fsin.s, fcos.s and ftan.s similar to single precision fsqrt.s instructions:
$ echo "mod a5, a5, a3" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING page 1
1 0000 EB87D702 mod a5,a5,a3
GAS LISTING page 2
DEFINED SYMBOLS
{standard input}:1 .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0
NO UNDEFINED SYMBOLS
$ echo "gcd a5, a5, a3" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING page 1
1 0000 A7E7D700 gcd a5,a5,a3
GAS LISTING page 2
DEFINED SYMBOLS
{standard input}:1 .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0
NO UNDEFINED SYMBOLS
$ echo "fact a5, 0x0" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING page 1
1 0000 AB070000 fact a5,0x0
GAS LISTING page 2
DEFINED SYMBOLS
{standard input}:1 .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0
NO UNDEFINED SYMBOLS
$ echo "fsqrt.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING page 1
1 0000 D3F70758 fsqrt.s fa5,fa5
GAS LISTING page 2
DEFINED SYMBOLS
{standard input}:1 .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0
NO UNDEFINED SYMBOLS
$ echo "fsin.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fsin.s fa5,fa5'
GAS LISTING page 1
1 fsin.s fa5,fa5
GAS LISTING page 2
NO DEFINED SYMBOLS
NO UNDEFINED SYMBOLS
$ echo "fcos.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fcos.s fa5,fa5'
GAS LISTING page 1
1 fcos.s fa5,fa5
GAS LISTING page 2
NO DEFINED SYMBOLS
NO UNDEFINED SYMBOLS
$ echo "ftan.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `ftan.s fa5,fa5'
GAS LISTING page 1
1 ftan.s fa5,fa5
GAS LISTING page 2
NO DEFINED SYMBOLS
NO UNDEFINED SYMBOLS