pz9115 / riscv-gcc

GNU General Public License v2.0
5 stars 4 forks source link

builtin RISC-V P-extension intrinsic function invalid argument #27

Closed Junyan721113 closed 1 year ago

Junyan721113 commented 1 year ago

I used the riscv-gnu-toolchain and configured as follows:

sudo ./configure --prefix=/opt/riscv --with-arch=rv64imafd_zpn --with-abi=lp64d --with-gcc-src=/home/mzero/workspace/riscv-gcc --with-binutils-src=/home/mzero/workspace/riscv-binutils-gdb
sudo make linux -j12

Here the riscv-gcc/ directory above contains the p-ext-andes branch of this repo

The toolchain build succeeded

The following test is OK

mzero@t610:~/workspace/rvtest$ cat asm-test.cpp
#include <cstdio>

using namespace std;

int main() {
    unsigned long a = 0xCDEFCDEF;
    unsigned long b = 0x11111111;
    unsigned long c;
    asm volatile("UKADD16 %0, %1, %2" : "=r" (c) : "r" (a), "r" (b));
    printf("%x\n", c);
    return 0;
}
mzero@t610:~/workspace/rvtest$ ../rvgcc asm-test.cpp -o asm-test -march=rv64imafdp_zpn
mzero@t610:~/workspace/rvtest$ ../rvobjdump -d asm-test

...

0000000000010504 <main>:
   10504:       fd010113                addi    sp,sp,-48
   10508:       02113423                sd      ra,40(sp)
   1050c:       02813023                sd      s0,32(sp)
   10510:       03010413                addi    s0,sp,48
   10514:       000107b7                lui     a5,0x10
   10518:       5787b783                ld      a5,1400(a5) # 10578 <_IO_stdin_used+0x10>
   1051c:       fef43423                sd      a5,-24(s0)
   10520:       111117b7                lui     a5,0x11111
   10524:       11178793                addi    a5,a5,273 # 11111111 <__global_pointer$+0x110fe911>
   10528:       fef43023                sd      a5,-32(s0)
   1052c:       fe843783                ld      a5,-24(s0)
   10530:       fe043703                ld      a4,-32(s0)
   10534:       30e787f7                ukadd16 a5,a5,a4
   10538:       fcf43c23                sd      a5,-40(s0)
   1053c:       fd843583                ld      a1,-40(s0)
   10540:       000107b7                lui     a5,0x10
   10544:       57078513                addi    a0,a5,1392 # 10570 <_IO_stdin_used+0x8>
   10548:       ed9ff0ef                jal     ra,10420 <printf@plt>
   1054c:       00000793                li      a5,0
   10550:       00078513                mv      a0,a5
   10554:       02813083                ld      ra,40(sp)
   10558:       02013403                ld      s0,32(sp)
   1055c:       03010113                addi    sp,sp,48
   10560:       00008067                ret

The UKADD16 instruction in asm is correct

mzero@t610:~/workspace/rvtest$ cat intrin-test-2.cpp
#include <p_ext_intrinsic.h>
#include <stdio.h>
#include <stdint.h>

using namespace std;

int main() {
    uint16x4_t a = {0xABCD, 0xABCD, 0xABCD, 0xABCD};
    uint16x4_t b = {0x1111, 0x1111, 0x1111, 0x1111};
    uint16x4_t c = __rv__v_ukadd16(a, b);
    printf("%d\n", c);
    return 0;
}
mzero@t610:~/workspace/rvtest$ ../rvgcc intrin-test-2.cpp -o intrin-test-2 -march=rv64imafdp_zpn
mzero@t610:~/workspace/rvtest$ ../rvobjdump -d intrin-test-2

...

0000000000010504 <main>:
   10504:       fd010113                addi    sp,sp,-48
   10508:       02113423                sd      ra,40(sp)
   1050c:       02813023                sd      s0,32(sp)
   10510:       03010413                addi    s0,sp,48
   10514:       000107b7                lui     a5,0x10
   10518:       5787b783                ld      a5,1400(a5) # 10578 <_IO_stdin_used+0x10>
   1051c:       fef43423                sd      a5,-24(s0)
   10520:       000107b7                lui     a5,0x10
   10524:       5807b783                ld      a5,1408(a5) # 10580 <_IO_stdin_used+0x18>
   10528:       fef43023                sd      a5,-32(s0)
   1052c:       fe843703                ld      a4,-24(s0)
   10530:       fe043783                ld      a5,-32(s0)
   10534:       30f707f7                ukadd16 a5,a4,a5
   10538:       fcf43c23                sd      a5,-40(s0)
   1053c:       fd843583                ld      a1,-40(s0)
   10540:       000107b7                lui     a5,0x10
   10544:       57078513                addi    a0,a5,1392 # 10570 <_IO_stdin_used+0x8>
   10548:       ed9ff0ef                jal     ra,10420 <printf@plt>
   1054c:       00000793                li      a5,0
   10550:       00078513                mv      a0,a5
   10554:       02813083                ld      ra,40(sp)
   10558:       02013403                ld      s0,32(sp)
   1055c:       03010113                addi    sp,sp,48
   10560:       00008067                ret

The UKADD16 instruction in uint16x4_t rvv_ukadd16(uint16x4_t a, uint16x4_t b) is correct

However, when I tried this, the error occured

mzero@t610:~/workspace/rvtest$ cat intrin-test.cpp
#include <p_ext_intrinsic.h>
#include <stdio.h>
#include <stdint.h>

using namespace std;

int main() {
    uint64_t a = 0xCDEFCDEFCDEFCDEF;
    uint64_t b = 0x1111111111111111;
    uint64_t c = __rv__ukadd16(a, b);
    printf("%d\n", c);
    return 0;
}
mzero@t610:~/workspace/rvtest$ ../rvgcc intrin-test.cpp -o intrin-test -march=rv64imafdp_zpn
In file included from intrin-test.cpp:1:
intrin-test.cpp: In function 'int main()':
intrin-test.cpp:10:18: error: invalid argument to built-in function
   10 |     uint64_t c = __rv__ukadd16(a, b);
      |                  ^~~~~~~~~~~~~

Did I do something incorrectly? Meanwhile does the p-ext-andes branch support uint64_t rvukadd16(uint64_t a, uint64_t b) now?

pz9115 commented 1 year ago

这个分支是Andes过去开发的分支,一直没有维护,你可以试试切换到 https://github.com/pz9115/riscv-gcc/tree/riscv-gcc-experiment-p-ext 这个子分支

Junyan721113 commented 1 year ago

感谢!我试试看

Junyan721113 commented 1 year ago

这个分支似乎有两个问题:

  1. riscvv64_ukadd16没有对应的__built_in函数
  2. 使用-march=rv64imafdp似乎不能正常编译__builtin_riscv_v64_ukadd16函数
pz9115 commented 1 year ago

这个分支似乎有两个问题:

  1. riscvv64_ukadd16没有对应的__built_in函数

这个应该是有定义的,参考:

https://github.com/pz9115/riscv-gcc/blob/2bc5611dc73030303900632e446c06c190ad1ed3/gcc/config/riscv/rvp_intrinsic.h#L1053

https://github.com/pz9115/riscv-gcc/blob/2bc5611dc73030303900632e446c06c190ad1ed3/gcc/config/riscv/riscv-builtins-rvp.def#LL539C82-L539C82

当时没有按照__riscv开头,后续等新的P扩展草案出现后我们会进行更新

  1. 使用-march=rv64imafdp似乎不能正常编译__builtin_riscv_v64_ukadd16函数

新版的子扩展需要用他们对应的名称来作为arch, 这样就不可以直接使用p来代表整个p扩展了,而应该使用对应的zpn,zprv,zpsf来精确表示需要使能的子扩展,例如-march=rv64gc_zpn_zprv

Junyan721113 commented 1 year ago

好的,感谢!