Greetings,
I tried to add a new assembly instruction to riscv-gcc, the new instruction is: "checki rdi,rs1,rs2".I want riscv-gcc to insert my assembly statement before the array's assignment statement during compilation.
For example:
int func1()
{
int a[10];
int b[10];
a[0] = 1;
}
int func2()
{
int a[10];
int b[10];
...
...
a[2] = b[3];
}
I want riscv-gcc to compile the above code to do the following:
int fun1(){
int a[10];
int b[10];
<----------- checki rdi,rs1,rs2
// insert my custom assembly code
a[0] = 1;
}
int func2()
{
int a[10];
int b[10];
...
...
<----------- checki rdi,rs1,rs2
// insert my custom assembly code
a[2] = b[3];
}
What I have done before:
I added a new custom instruction(checki rdi,rs1,rs2) in RISC-V Toolchain and simulated it sucessesfully. I wrote a test sample and compiled it successfully with riscv-gcc:
#include <stdio.h>
int main(){
int a,b,c;
a = 5;
b = 2;
asm volatile
(
"checki %[z], %[x], %[y]\n\t"
: [z] "=r" (c)
: [x] "r" (a), [y] "r" (b)
)
if ( c != 1 ){
printf("\n[[FAILED]]\n");
return -1;
}
printf("\n[[PASSED]]\n");
return 0;
}
What steps should I follow to complete my work and what materials can I refer to?
Thanks in advance.