sifive / freedom-tools

Tools for SiFive's Freedom Platform
217 stars 52 forks source link

macroFail – RISC-V #88

Closed Peter-Butler closed 2 years ago

Peter-Butler commented 2 years ago

GNU assembler version 2.35 (riscv-none-embed) using BFD version (xPack GNU RISC-V Embedded GCC x86_64) 2.35 I am using 64-bit Windows 10.

macroFail.s: Assembler messages: macroFail.s:24: Error: illegal operands sll t1,/reg,/cnt' macroFail.s:24: Error: unrecognized opcodeslr/reg,/reg,32-/cnt' macroFail.s:24: Error: unrecognized opcode `or/reg,/reg,t1' macroFail.s:25: Error: too many positional arguments (Last line is repeated a total of four times.)

I have been programming computers mostly in assembly for over 50 years. I am now learning RISC-V assembly. The attached .S file was extracted and simplified from my attempt to implement the ChaCha20 encryption algorithm for RISC-V.

I have three other issues and one idea:

1) Painful, but I have a workaround… The .reg pseudo is missing from the RISC-V version. I would rather write “cc5 .reg x16” than “#define cc5 x16” and then use the C preprocessor.

2) Easy workaround, but it forces bad practice… .data keyTab: .space 16 theKey = .-Tbl ## this is what I want to say .text lw x9,theKey

Best practice is to let the assembler define offsets into structures from within the structure. To make it work I have to write “theKey = 16”. The difference between two symbols in the same segment is an absolute value. Or am I’m missing something?

3) No literal pool. I can’t write “lw x3,=keyTab”. The workaround is only mildly annoying.

Idea) RISC-V has multiple extensions defined with single-letter codes. Provide some way to specify which extension code(s) apply to the current assembly. (At this point I am only using the base 32-bit ISA.) Provide some text format to add ISA extensions, possibly with a text-to-useful-binary-format tool. The binary to be used by the assembler.

f:\gnuWin\xpacks\xpack-dev-tools-riscv-none-embed-gcc.content\bin\riscv-none-embed-as -alm=macroFail.lst macroFail.s

macroFail.S: .macro rol,reg,cnt sll t1,\reg,\cnt slr \reg,\reg,32-\cnt or \reg,\reg,t1 .endm

    .macro   qr,a,b,c,d
    add     \a,\a,\b
    xor     \d,\d,\a
    rol     \d,\d,16
     add     \c,\c,\d
     xor     \b,\b,\c
     rol     \d,\d,12
    add     \a,\a,\b
    xor     \d,\d,\a
    rol     \d,\d,8
     add     \c,\c,\d
     xor     \b,\b,\c
     rol     \b,\b,7
    .endm

mix: rol x4,12 qr x4,x5,x6,x7

Peter-Butler commented 2 years ago

I fixed my macro .macro roli,dest,source,cnt slli t1,\source,\cnt srli \dest,\source,(32-\cnt) or \dest,\dest,t1 .endm The other items might be worth a look or two.