Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Internal Register File (Custom Instructions)

Hello.

I'm a (very) beginner of NiosII and VHDL, and have just managed to make a

sample custom instruction (Combinatorial) like the following,

thanks to ug_nios2_custom_instruction.pdf.

unsigned char input[BUFF_SIZE], output[BUFF_SIZE];

:

for(i=0; input!='\0'; i++)

{

output = (unsigned char) ALT_CI_PROC_ONE_CHAR((int)input[i]);

}

:

Now, I'd like to extend the instruction to deal with the strings instead of chars.

I mean, something like the following is preferable.

unsigned char input[BUFF_SIZE], output[BUFF_SIZE];

:

ALT_CI_PROC_STRING(input, output);

:

To do this, I should use Custom Instructions(Internal Register File), right?

Could anyone tell me where I can get the examples of VHDL for this?

Or ... any other suggestions are welcome.

Thanks.

shino

11 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Not sure why you added to an old thread.

    You probably want something like:

    /* There are 'int __builtin_custom_inii(int op, int a, int b)'
     * (and similar) wrappers for custom instructions defined by gcc itself.
     * But none for the 'c' variants that do not use the main register file.
     * The one below is useful when the 'b' field is used as a sub-opcode.*/
    __attribute__((always_inline))
    static __inline__ uint32_t
    custom_inic(const uint32_t op, uint32_t a, const uint32_t b)
    {
        uint32_t result;
        __asm__ ( "custom\t%1, %0, %2, c%3"
            : "=r" (result) : "n" (op), "r" (a), "n" (b));
        return result;
    }

    Read the gcc documentation for __asm__ for more details.

    If your instruction saves state, then you probably need __asm__ volatile.