The ultimate goal here is to implement a custom instruction (multiply and accumulate for integers) on RISC-V ISA with the riscv-gnu-toolchain. I have extensively looked into the different articles and forums where people have inquired about this previously and came up with the following:
You can add the instruction to riscv-binutils (which is nice but not really what I am trying to accomplish).
You can add the instruction to GCC (if it is simple enough) by adding the instruction pattern to the machine description file (riscv.md).
I have tried adding my instruction to the riscv.md file and the compilation seems to be fine until it builds libc (this is a newlib build of riscv-gnu-toolchain by the way) where it fails.
What I added to riscv.md:
(define_insn "macsi4"
[(set (match_operand: SI 0 "register_operand" "=r")
(plus: SI (mult: SI (match_operand: SI 1 "register_operand" "r")
(match_operand: SI 2 "register_operand" "r"))
(match_operand: SI 3 "register_operand" "r")))]
"TARGET_MUL"
{ return TARGET_64BIT ? "macw\t%0, %1, %2, %3" : "mac\t%0, %1, %2, %3" ; }
[(set_attr "type" "arith")
(set_attr "mode" "SI")])
What is output when building riscv-gnu-toolchain fails:
riscv64-unknown-elf-ar rc ../libc.a
riscv64-unknown-elf-ar: ../stdlib/lib.a: No such file or directory
riscv64-unknown-elf-ar: ../search/lib.a: No such file or directory
riscv64-unknown-elf-ar: ../stdio/lib.a: No such file or directory
riscv64-unknown-elf-ar: ../time/lib.a: No such file or directory
riscv64-unknown-elf-ranlib libc.a
rm -rf tmp
So is there a tutorial or a series of steps you could give me to adding this instruction to RISCV-GCC?
Any response would be greatly appreciated.
-Justin