how to deal with new instructions gcc does not recognize

OP #2305501
Hi, guys

we aim to self make a FPU which has its own instruction set. For easy 
programming, we prefer c language to assembly code.

here's one of our instruction:
c language format: Bload(vd, value1, value2), we make it like a 
funciton. vd is a special register.
binary format: 31-26 opcode, 25-21 index of vd register, 20-16 opcode, 
15-11 index of the general register which keeps value1, 10-5 opcode, 4-0 
index of the general register which keeps value2.

we use gcc-inline-assembly to convert it to binary code. here's the 
solution:
#define Bload(vd, value1, value2)    \
  __asm__(        \
    "add  r16, r0, %0  \n\t"  \
    "add  r14, r0, %1  \n\t"  \
    ".long  %2  \n\t"    \
    :        \
    : "r"(value2), "r"(value1), 
"i"((0x3b<<26)+(vd<<21)+(14<<11)+(0x2c<<5)+16)  \
    : "r14", "r16");
i fix the general registers(r14, r16) which keep value1 and value2. then 
i make the binary code use "i" in inline-assembly. But disadvantage is 
in evidence: gcc does not understand my instruction, so i can not take 
it's advantage, such as selecting the most suitable general register and 
eliminating unnecessary copy from register to register.

what i want is deleting the first two add instruction, let gcc select 
register for me and tell me which register it selected. so i can make my 
own binary code using .long instruction. But i do not want to modify the 
gcc compiler to let it understand my instruction.

Thank you for your help
jie zhou wrote:
> what i want is deleting the first two add instruction, let gcc select
> register for me and tell me which register it selected. so i can make my
> own binary code using .long instruction. But i do not want to modify the
> gcc compiler to let it understand my instruction.

There are several approaches:

(A) You don't need to change GCC. It's sufficient to teach binutils the
    new instructions/instruction formats with the additinal benefit that
    you will see the new instructions in disassembly.

(B) Drag the arithmetic from C-level to (inline) assembly.  You will
    need an output modifier to print a GPR as it's number.  If your GCC
    port does not have it yet: add it.  It's TARGET_PRINT_OPERAND hook
    in your ./gcc/config/target/target.c, see GCC's internals
    documentation.
OP
Johann L. thank you very much for your help

> You don't need to change GCC. It's sufficient to teach binutils the
> new instructions/instruction formats with the additinal benefit that
> you will see the new instructions in disassembly.

i prefer to teaching gnu binutils the new instructions. in fact, i use 
microblaze gnu tools to compile my code. but how to teach gnu binutils? 
can you say some details?

Reply

A question of your own? This thread is over 15 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.