Assistance with Adding Custom Trigonometric Instructions to RISC-V ISA in Spike

92 views
Skip to first unread message

Boul chandra Garai

unread,
Jul 18, 2024, 1:33:02 AM (9 days ago) Jul 18
to RISC-V ISA Dev

Dear Team,

Has anyone successfully added custom trigonometric instructions to the Spike RISC-V ISA? I have been attempting to integrate these instructions but have encountered errors during the build and installation process of the RISC-V GNU toolchain.

I would greatly appreciate any guidance or suggestions on the procedures for adding these trigonometric instructions to Spike.

Thank you for your assistance.

--
Thanks & Regards
Mr. BOUL CHANDRA GARAI
e-mail:bga...@ursc.gov.in
Ph: 080-25082307(
O)/66469103(R)

Tommy Murphy

unread,
Jul 18, 2024, 4:32:20 AM (9 days ago) Jul 18
to Boul chandra Garai, RISC-V ISA Dev
You probably need to provide more information - e.g. what exactly you're doing, what goes wrong, build logs etc. 

It's not clear if you're having problems with adding the instructions to Spike, or the RISC-V GCC toolchain, or both. 

The Spike riscv-isa-sim and toolchain riscv-gnu-toolchain GitHub repositories should have some relevant information in the open and closed issues relating to adding custom instructions that may be of use to you.

Boul chandra Garai

unread,
Jul 19, 2024, 4:21:26 AM (8 days ago) Jul 19
to Tommy Murphy, RISC-V ISA Dev
Dear Team,
I am trying to add these new instructions SIN and COS in the following way:
image.png
The above figure shows the fields used for the two custom instructions, sine and cosine, and their values. The R-type format is used, but only with the opcode and funct3 fields. Because of the simple requirement of the custom instructions, rs2 and funct7 are left blank. The input angle values will be entered through rs1 while the trigonometric results are saved to rd.

So I have added he riscv_opcodes array in the binutils/opcodes/riscv-opc.c as follows:
{"sin",      0, INSN_CLASS_I,       "d,s",        MATCH_SIN, MASK_SIN, match_opcode, 0},
{"cos",      0, INSN_CLASS_I,       "d,s",        MATCH_COS, MASK_COS, match_opcode, 0},

And in the binutils/include/opcode/riscv-opc.h I have added the definitions for the MATCH/MASK as follows:
#define MATCH_SIN 0x0000400B
#define MASK_SIN  0xFE00707F
#define MATCH_COS 0x0000600B
#define MASK_COS  0xFE00707F
And declared these instructions as well:
DECLARE_INSN(sin, MATCH_SIN, MASK_SIN)
DECLARE_INSN(cos, MATCH_COS, MASK_COS)

with these when I am trying to build and install the riscv-gnu-toolchain again with the command as follows:
./configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gcv --with-abi=lp64d --with-sim=spike --enable-multilib
it is not running throwing errors as follows:
checking for riscv64-unknown-elf-gcc... riscv64-unknown-elf-gcc
checking whether the C compiler works... no
configure: error: in `/data/home/chandraboul/development/riscv-gnu-toolchain':
configure: error: C compiler cannot create executables
See `config.log' for more details
And in the config.log the identified error is showing as
Assembler messages:
Error: internal: bad RISC-V opcode (bits 0x1f00000 undefined or invalid): sin d,s
Fatal error: internal: broken assembler.  No assembly attempted
Internal error (Segmentation fault).

Tommy Murphy

unread,
Jul 19, 2024, 5:12:14 AM (8 days ago) Jul 19
to Boul chandra Garai, RISC-V ISA Dev
FWIW this issue describes how to add a simple custom instruction to the riscv-gnu-toolchain.


Bruce Hoult

unread,
Jul 19, 2024, 9:27:28 AM (8 days ago) Jul 19
to Boul chandra Garai, Tommy Murphy, RISC-V ISA Dev
Ok, so you're adding in the custom-0 space which is good.

But your masks are dodgy. If you're not using rs2 as input then you
should include those five bits in your masks to ensure you match only
rs2=0

> rs2 and funct7 are left blank

There is no such concept. 0000 is not blank, it is 0000.

I'm going to assume you actually mean to use FP registers not integer.
But that doesn't affect the instruction encoding.

Your ./configure for the toolchain looks weird, in particular the
--host, which I've never used but assume should be the system
compiler. Does that work without your patches?

On Fri, Jul 19, 2024 at 8:21 PM Boul chandra Garai <baul...@gmail.com> wrote:
>
> Dear Team,
> I am trying to add these new instructions SIN and COS in the following way:
>
> On Thu, Jul 18, 2024 at 2:02 PM Tommy Murphy <tommy_...@hotmail.com> wrote:
>>
>> You probably need to provide more information - e.g. what exactly you're doing, what goes wrong, build logs etc.
>>
>> It's not clear if you're having problems with adding the instructions to Spike, or the RISC-V GCC toolchain, or both.
>>
>> The Spike riscv-isa-sim and toolchain riscv-gnu-toolchain GitHub repositories should have some relevant information in the open and closed issues relating to adding custom instructions that may be of use to you.
>
>
>
> --
> Thanks & Regards
> Mr. BOUL CHANDRA GARAI
> e-mail:bga...@ursc.gov.in
> Ph: 080-25082307(O)/66469103(R)
>
> --
> You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
> To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/CAMCa%3D5fMx2rYgejyQYzcffpEZ5ED7eimvih9bZsMH2JthT%3D4bA%40mail.gmail.com.

Boul chandra Garai

unread,
Jul 19, 2024, 10:43:35 AM (8 days ago) Jul 19
to Bruce Hoult, Tommy Murphy, RISC-V ISA Dev
Hello Team,
Before adding these fsin.s and fcos.s instructions, I had added those mod, fact, gcd examples given in different pointers. And when I am commenting these lines for fsin and fcos instruction, it is going through smoothly. Can you please help me to figure out where I am missing for fsin and fcos instructions?
As pointed out by Bruce Hoult, I have modified the rs2==0 and changed the following: 
1. Now I have added he riscv_opcodes array in the binutils/opcodes/riscv-opc.c as follows:
{"fsin.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FSIN, MASK_FSIN, match_opcode, 0},
{"fcos.s", 0, INSN_CLASS_F_INX, "d,s", MATCH_FCOS, MASK_FCOS, match_opcode, 0},

2. And in the binutils/include/opcode/riscv-opc.h I have added the definitions for the MATCH/MASK as follows:

#define MATCH_FSIN 0x30000053
#define MASK_FSIN 0xfff0007f
#define MATCH_FCOS 0x38000053
#define MASK_FCOS 0xfff0007f
And declared these instructions as well:
DECLARE_INSN(fsin_s, MATCH_FSIN, MASK_FSIN)
DECLARE_INSN(fcos_s, MATCH_FCOS, MASK_FCOS)

Rationale behind FSIN Instruction MATCH_FSIN 0x30000053

For the fsin.s instruction:

  • funct7 = 0x06 (bits 25-31)
  • rs2 = 0 (bits 20-24)
  • funct3 = 0x0 (bits 12-14)
  • opcode = 0x53 (bits 0-6)
with these also when I am trying to build and install the riscv-gnu-toolchain again with the command as follows:
./configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gcv --with-abi=lp64d --with-sim=spike --enable-multilib
it is not running throwing same errors shown previously as follows:
checking for riscv64-unknown-elf-gcc... riscv64-unknown-elf-gcc
checking whether the C compiler works... no
configure: error: in `/data/home/chandraboul/development/riscv-gnu-toolchain':
configure: error: C compiler cannot create executables
See `config.log' for more details
And in the config.log the identified error is showing as
cat config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by riscv-toolchain configure 1.0, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ ./configure --prefix=/data/home/chandraboul/development/riscv-spike --host=riscv64-unknown-elf --with-arch=rv64gcv --with-abi=lp64d --with-sim=spike --enable-multilib

## --------- ##
## Platform. ##
## --------- ##

hostname = resiliente-1949
uname -m = x86_64
uname -r = 6.2.0-39-generic
uname -s = Linux
uname -v = #40~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 16 10:53:04 UTC 2

/usr/bin/uname -p = x86_64
/bin/uname -X     = unknown

/bin/arch              = x86_64
/usr/bin/arch -k       = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo      = unknown
/bin/machine           = unknown
/usr/bin/oslevel       = unknown
/bin/universe          = unknown

PATH: /data/home/chandraboul/development/riscv-spike/bin
PATH: /data/home/chandraboul/development/riscv-spike/riscv64-unknown-elf/bin
PATH: /data/home/chandraboul/development/riscv-spike/bin
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /sbin
PATH: /bin
PATH: /usr/games
PATH: /usr/local/games
PATH: /snap/bin
PATH: /usr/local/cuda-12.3/bin


## ----------- ##
## Core tests. ##
## ----------- ##

configure:1934: checking for riscv64-unknown-elf-gcc
configure:1961: result: riscv64-unknown-elf-gcc
configure:2230: checking for C compiler version
configure:2239: riscv64-unknown-elf-gcc --version >&5
riscv64-unknown-elf-gcc (gc891d8dc23e) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:2250: $? = 0
configure:2239: riscv64-unknown-elf-gcc -v >&5
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/data/home/chandraboul/development/riscv-spike/libexec/gcc/riscv64-unknown-elf/13.2.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /data/home/chandraboul/development/riscv-gnu-toolchain/gcc/configure --target=riscv64-unknown-elf --prefix=/data/home/chandraboul/development/riscv-spike --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=gc891d8dc23e --with-system-zlib --enable-tls --with-newlib --with-sysroot=/data/home/chandraboul/development/riscv-spike/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=.././gcc --enable-multilib --with-abi=lp64d --with-arch=rv64gcv --with-tune=rocket --with-isa-spec=20191213 'CFLAGS_FOR_TARGET=-Os    -mcmodel=medlow' 'CXXFLAGS_FOR_TARGET=-Os    -mcmodel=medlow'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 13.2.0 (gc891d8dc23e)
configure:2250: $? = 0
configure:2239: riscv64-unknown-elf-gcc -V >&5
riscv64-unknown-elf-gcc: error: unrecognized command-line option '-V'
riscv64-unknown-elf-gcc: fatal error: no input files
compilation terminated.
configure:2250: $? = 1
configure:2239: riscv64-unknown-elf-gcc -qversion >&5
riscv64-unknown-elf-gcc: error: unrecognized command-line option '-qversion'; did you mean '--version'?
riscv64-unknown-elf-gcc: fatal error: no input files
compilation terminated.
configure:2250: $? = 1
configure:2270: checking whether the C compiler works
configure:2292: riscv64-unknown-elf-gcc -march=rv64gcv -mabi=lp64d   conftest.c  >&5
configure:2296: $? = 0
configure:2344: result: yes
configure:2347: checking for C compiler default output file name
configure:2349: result: a.out
configure:2355: checking for suffix of executables
configure:2362: riscv64-unknown-elf-gcc -o conftest -march=rv64gcv -mabi=lp64d   conftest.c  >&5
configure:2366: $? = 0
configure:2388: result:
configure:2410: checking whether we are cross compiling
configure:2418: riscv64-unknown-elf-gcc -o conftest -march=rv64gcv -mabi=lp64d   conftest.c  >&5
configure:2422: $? = 0
configure:2429: ./conftest
./configure: line 2431: ./conftest: cannot execute binary file: Exec format error
configure:2433: $? = 126
configure:2448: result: yes
configure:2453: checking for suffix of object files
configure:2475: riscv64-unknown-elf-gcc -c -march=rv64gcv -mabi=lp64d  conftest.c >&5
configure:2479: $? = 0
configure:2500: result: o
configure:2504: checking whether we are using the GNU C compiler
configure:2523: riscv64-unknown-elf-gcc -c -march=rv64gcv -mabi=lp64d  conftest.c >&5
configure:2523: $? = 0
configure:2532: result: yes
configure:2541: checking whether riscv64-unknown-elf-gcc accepts -g
configure:2561: riscv64-unknown-elf-gcc -c -g  conftest.c >&5
configure:2561: $? = 0
configure:2602: result: yes
configure:2619: checking for riscv64-unknown-elf-gcc option to accept ISO C89
configure:2682: riscv64-unknown-elf-gcc  -c -march=rv64gcv -mabi=lp64d  conftest.c >&5
configure:2682: $? = 0
configure:2695: result: none needed
configure:2715: checking for grep that handles long lines and -e
configure:2773: result: /usr/bin/grep
configure:2778: checking for fgrep
configure:2840: result: /usr/bin/grep -F
configure:2845: checking for grep that handles long lines and -e
configure:2903: result: /usr/bin/grep
configure:2911: checking for bash
configure:2942: result: /bin/bash
configure:3013: checking for __gmpz_init in -lgmp
configure:3038: riscv64-unknown-elf-gcc -o conftest -march=rv64gcv -mabi=lp64d   conftest.c -lgmp   >&5
/data/home/chandraboul/development/riscv-spike/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lgmp: No such file or directory
collect2: error: ld returned 1 exit status
configure:3038: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "riscv-toolchain"
| #define PACKAGE_TARNAME "riscv-toolchain"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "riscv-toolchain 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char __gmpz_init ();
| int
| main ()
| {
| return __gmpz_init ();
|   ;
|   return 0;
| }
configure:3047: result: no
configure:3060: checking for mpfr_init in -lmpfr
configure:3085: riscv64-unknown-elf-gcc -o conftest -march=rv64gcv -mabi=lp64d   conftest.c -lmpfr   >&5
/data/home/chandraboul/development/riscv-spike/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lmpfr: No such file or directory
collect2: error: ld returned 1 exit status
configure:3085: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "riscv-toolchain"
| #define PACKAGE_TARNAME "riscv-toolchain"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "riscv-toolchain 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char mpfr_init ();
| int
| main ()
| {
| return mpfr_init ();
|   ;
|   return 0;
| }
configure:3094: result: no
configure:3107: checking for mpc_init2 in -lmpc
configure:3132: riscv64-unknown-elf-gcc -o conftest -march=rv64gcv -mabi=lp64d   conftest.c -lmpc   >&5
/data/home/chandraboul/development/riscv-spike/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lmpc: No such file or directory
collect2: error: ld returned 1 exit status
configure:3132: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "riscv-toolchain"
| #define PACKAGE_TARNAME "riscv-toolchain"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "riscv-toolchain 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char mpc_init2 ();
| int
| main ()
| {
| return mpc_init2 ();
|   ;
|   return 0;
| }
configure:3141: result: no
configure:3164: checking for curl
configure:3182: found /usr/bin/curl
configure:3195: result: /usr/bin/curl
configure:3205: checking for wget
configure:3223: found /usr/bin/wget
configure:3236: result: /usr/bin/wget
configure:3246: checking for ftp
configure:3264: found /usr/bin/ftp
configure:3277: result: /usr/bin/ftp
configure:4071: creating ./config.status

## ---------------------- ##
## Running config.status. ##
## ---------------------- ##

This file was extended by riscv-toolchain config.status 1.0, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  CONFIG_FILES    =
  CONFIG_HEADERS  =
  CONFIG_LINKS    =
  CONFIG_COMMANDS =
  $ ./config.status

on resiliente-1949

config.status:769: creating Makefile
config.status:769: creating scripts/wrapper/awk/awk
config.status:769: creating scripts/wrapper/sed/sed

## ---------------- ##
## Cache variables. ##
## ---------------- ##

ac_cv_c_compiler_gnu=yes
ac_cv_env_CC_set=set
ac_cv_env_CC_value=riscv64-unknown-elf-gcc
ac_cv_env_CFLAGS_set=set
ac_cv_env_CFLAGS_value='-march=rv64gcv -mabi=lp64d'
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=set
ac_cv_env_host_alias_value=riscv64-unknown-elf
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_lib_gmp___gmpz_init=no
ac_cv_lib_mpc_mpc_init2=no
ac_cv_lib_mpfr_mpfr_init=no
ac_cv_objext=o
ac_cv_path_BASH=/bin/bash
ac_cv_path_CURL=/usr/bin/curl
ac_cv_path_FGREP='/usr/bin/grep -F'
ac_cv_path_FTP=/usr/bin/ftp
ac_cv_path_GAWK=/usr/bin/gawk
ac_cv_path_GREP=/usr/bin/grep
ac_cv_path_GSED=/usr/bin/sed
ac_cv_path_WGET=/usr/bin/wget
ac_cv_prog_CC=riscv64-unknown-elf-gcc
ac_cv_prog_cc_c89=
ac_cv_prog_cc_g=yes

## ----------------- ##
## Output variables. ##
## ----------------- ##

BASH='/bin/bash'
CC='riscv64-unknown-elf-gcc'
CFLAGS='-march=rv64gcv -mabi=lp64d'
CPPFLAGS=''
CURL='/usr/bin/curl'
DEFS='-DPACKAGE_NAME=\"riscv-toolchain\" -DPACKAGE_TARNAME=\"riscv-toolchain\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"riscv-toolchain\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\"'
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
EXEEXT=''
FETCHER='/usr/bin/curl -L -o - --ftp-pasv --retry 10'
FGREP='/usr/bin/grep -F'
FTP='/usr/bin/ftp'
GAWK='/usr/bin/gawk'
GREP='/usr/bin/grep'
GSED='/usr/bin/sed'
LDFLAGS=''
LIBOBJS=''
LIBS=''
LTLIBOBJS=''
NEED_GCC_EXTERNAL_LIBRARIES='true'
OBJEXT='o'
PACKAGE_BUGREPORT=''
PACKAGE_NAME='riscv-toolchain'
PACKAGE_STRING='riscv-toolchain 1.0'
PACKAGE_TARNAME='riscv-toolchain'
PACKAGE_URL=''
PACKAGE_VERSION='1.0'
PATH_SEPARATOR=':'
SHELL='/bin/bash'
WGET='/usr/bin/wget'
WITH_ABI='--with-abi=lp64d'
WITH_ARCH='--with-arch=rv64gcv'
WITH_ISA_SPEC='--with-isa-spec=20191213'
WITH_SIM='spike'
WITH_TUNE='--with-tune=rocket'
ac_ct_CC=''
bindir='${exec_prefix}/bin'
build_alias=''
cmodel='-mcmodel=medlow'
configure_host=''
datadir='${datarootdir}'
datarootdir='${prefix}/share'
debug_info=''
default_target='newlib'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
enable_default_pie='--disable-default-pie'
enable_gdb='--enable-gdb'
enable_host_gcc='--disable-host-gcc'
enable_libsanitizer='--disable-libsanitizer'
enable_llvm='--disable-llvm'
exec_prefix='${prefix}'
extra_multilib_test=''
gcc_checking=''
glibc_multilib_names='rv32imac-ilp32 rv32imafdc-ilp32d rv64imac-lp64 rv64imafdc-lp64d'
host_alias='riscv64-unknown-elf'
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
multilib_flags='--enable-multilib'
multilib_gen=''
musl_multilib_names='rv64imac-lp64 rv64imafdc-lp64d'
newlib_multilib_names='rv32i-ilp32 rv32iac-ilp32 rv32im-ilp32 rv32imac-ilp32 rv32imafc-ilp32f rv64imac-lp64 rv64imafdc-lp64d'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/data/home/chandraboul/development/riscv-spike'
program_transform_name='s,x,x,'
psdir='${docdir}'
qemu_targets='riscv64-linux-user,riscv32-linux-user'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''
target_cflags=''
target_cxxflags=''
with_binutils_src='$(srcdir)/binutils'
with_dejagnu_src='$(srcdir)/dejagnu'
with_gcc_src='$(srcdir)/gcc'
with_gdb_src='$(srcdir)/gdb'
with_glibc_src='$(srcdir)/glibc'
with_guile=''
with_linux_headers_src='$(srcdir)/linux-headers/include'
with_llvm_src='$(srcdir)/llvm'
with_musl_src='$(srcdir)/musl'
with_newlib_src='$(srcdir)/newlib'
with_pk_src='$(srcdir)/pk'
with_qemu_src='$(srcdir)/qemu'
with_spike_src='$(srcdir)/spike'
with_system_zlib='--with-system-zlib'

## ----------- ##
## confdefs.h. ##
## ----------- ##

/* confdefs.h */
#define PACKAGE_NAME "riscv-toolchain"
#define PACKAGE_TARNAME "riscv-toolchain"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_STRING "riscv-toolchain 1.0"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""

configure: exit 0

Boul chandra Garai

unread,
Jul 20, 2024, 12:31:02 AM (7 days ago) Jul 20
to Bruce Hoult, Tommy Murphy, RISC-V ISA Dev
From some other place I got to know that I need to change the opcodes as "d,s,t" or "d,a". Even if the "t" is unused, that parameter is telling the RISC-V system how to parse the instruction. If we use the wrong letters, the instruction cannot be parsed.  So I had changed it to "d,s,t" and with that the build and installation process was successful, but it is not recognizing the fsin.s instructions when I am trying the following:
$ riscv64-unknown-elf-as -o test.o -a <<< "fsin.s fa5, fa5, x0"

{standard input}: Assembler messages:

{standard input}:1: Error: unrecognized opcode `fsin.s fa5,fa5,x0'

GAS LISTING   page 1







   1               fsin.s fa5,fa5,x0




GAS LISTING   page 2







NO DEFINED SYMBOLS




NO UNDEFINED SYMBOLS

 But if I try with gcd as follows: it is showing properly:
$ riscv64-unknown-elf-as -o test.o -a <<< "gcd a5, a5, x0"

GAS LISTING   page 1







   1 0000 A7E70700 gcd a5,a5,x0




GAS LISTING   page 2







DEFINED SYMBOLS

    {standard input}:1      .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0




NO UNDEFINED SYMBOLS



CAn you please guide me if it should be "g,s,t" or "g,a" or there are some other errors also in my instructions definition?

Boul chandra Garai

unread,
Jul 20, 2024, 1:17:02 AM (7 days ago) Jul 20
to Bruce Hoult, Tommy Murphy, RISC-V ISA Dev
Now I have defined fsin.s is a single precession floating point instruction which takes inputs from a single source resister and put the computed value to the destination register, checking with this command line is correct? now it is not telling unrecognisation instruction but suggesting it as illegal operands as follows:
$ riscv64-unknown-elf-as -o test.o -a <<< "fsin.s fa5, fa5"
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fsin.s fa5,fa5'

GAS LISTING   page 1


   1               fsin.s fa5,fa5

GAS LISTING   page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS
$ riscv64-unknown-elf-as -o test.o -a <<< "fsin.s fa5, fa5, x0"
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fsin.s fa5,fa5,x0'

GAS LISTING   page 1


   1               fsin.s fa5,fa5,x0

GAS LISTING   page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS

Boul chandra Garai

unread,
Jul 20, 2024, 6:46:24 AM (7 days ago) Jul 20
to Bruce Hoult, Tommy Murphy, RISC-V ISA Dev
I have added six new instructions as follows modulus(mod), gcd, fact, fsin.s, fcos.s and ftan.s. Once the build process over I am giving the following command to check these newly added instructions and I could see that the three instructon mod, gcd and fact is showing output as expected, but fsin.s, fcos.s and ftan.s instruction is throwing output as illegal operands. I had defined the fsin.s, fcos.s and ftan.s similar to single precision fsqrt.s instructions. Please suggest/guide me if I am making any mistake in these process so that these trigonometric instructions work properly:

(i) In the first step i have open up binutils/opcodes/riscv-opc.c and added these six instructions to the riscv_opcodes array.

{"mod",      0, INSN_CLASS_I,       "d,s,t",         MATCH_MOD, MASK_MOD, match_opcode, 0 },
{"gcd",      0, INSN_CLASS_I,       "d,s,t",         MATCH_GCD, MASK_GCD, match_opcode, 0 },
{"fact",      0, INSN_CLASS_I,       "d,a",         MATCH_FACT, MASK_FACT, match_opcode, 0 },
// Single-precision floating-point instruction subset similar to fsqrt.s
{"fsin.s",    0, INSN_CLASS_F_INX,   "d,s",       MATCH_FSIN_S|MASK_RM, MASK_FSIN_S|MASK_RM, match_opcode, 0 },
{"fsin.s",    0, INSN_CLASS_F_INX,   "d,s,m",     MATCH_FSIN_S, MASK_FSIN_S, match_opcode, 0 },
{"fcos.s",    0, INSN_CLASS_F_INX,   "d,s",       MATCH_FCOS_S|MASK_RM, MASK_FCOS_S|MASK_RM, match_opcode, 0 },
{"fcos.s",    0, INSN_CLASS_F_INX,   "d,s,m",     MATCH_FCOS_S, MASK_FCOS_S, match_opcode, 0 },
{"ftan.s",    0, INSN_CLASS_F_INX,   "d,s",       MATCH_FTAN_S|MASK_RM, MASK_FTAN_S|MASK_RM, match_opcode, 0 },
{"ftan.s",    0, INSN_CLASS_F_INX,   "d,s,m",     MATCH_FTAN_S, MASK_FTAN_S, match_opcode, 0 },

(ii) Next, I have open up binutils/include/opcode/riscv-opc.h and added in definitions for the MATCH/MASK:
#define MATCH_GCD 0x6027
#define MASK_GCD 0xfe00707f
#define MATCH_FACT 0x2b
#define MASK_FACT 0x7f
#define MATCH_MOD 0x200006b
#define MASK_MOD 0xfe00707f
#define MATCH_FSIN_S 0x59000053
#define MASK_FSIN_S  0xfff0007f
#define MATCH_FCOS_S 0x5b000053
#define MASK_FCOS_S  0xfff0007f
#define MATCH_FTAN_S 0x5d000053
#define MASK_FTAN_S  0xfff0007f

Further down, where we are declaring our instructions, I have added each of them:

DECLARE_INSN(mod, MATCH_MOD, MASK_MOD)
DECLARE_INSN(gcd, MATCH_GCD, MASK_GCD)
DECLARE_INSN(fact, MATCH_FACT, MASK_FACT)
DECLARE_INSN(fsin_s, MATCH_FSIN_S, MASK_FSIN_S)
DECLARE_INSN(fcos_s, MATCH_FCOS_S, MASK_FCOS_S)
DECLARE_INSN(ftan_s, MATCH_FTAN_S, MASK_FTAN_S)

(iii) Then after executing the following configuration script built and build and installed the riscv-gnu-toolchain as per the commands you suggested earlier:

# then run the config command as follows:
./configure --prefix=$RISCV --host=riscv64-unknown-elf --with-arch=rv64gcv --with-abi=lp64d --with-sim=spike --enable-multilib
# next execute the build and installed command
sudo make -j$(nproc) && sudo make build-sim

(iv)Once the build process over I am giving the following command to check these newly added instructions and I could see that the three instructon mod, gcd and fact is showing output as expected, but fsin.s, fcos.s and ftan.s instruction is throwing output as illegal operands. I had defined the fsin.s, fcos.s and ftan.s similar to single precision fsqrt.s instructions:
$ echo "mod a5, a5, a3" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING   page 1


   1 0000 EB87D702 mod a5,a5,a3


GAS LISTING   page 2


DEFINED SYMBOLS
    {standard input}:1      .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0

NO UNDEFINED SYMBOLS
$ echo "gcd a5, a5, a3" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING   page 1


   1 0000 A7E7D700 gcd a5,a5,a3


GAS LISTING   page 2


DEFINED SYMBOLS
    {standard input}:1      .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0

NO UNDEFINED SYMBOLS

$ echo "fact a5, 0x0" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING   page 1


   1 0000 AB070000 fact a5,0x0


GAS LISTING   page 2


DEFINED SYMBOLS
    {standard input}:1      .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0

NO UNDEFINED SYMBOLS


$ echo "fsqrt.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
GAS LISTING   page 1


   1 0000 D3F70758 fsqrt.s fa5,fa5

GAS LISTING   page 2


DEFINED SYMBOLS
    {standard input}:1      .text:0000000000000000 $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zifencei2p0_zmmul1p0

NO UNDEFINED SYMBOLS
$ echo "fsin.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a

{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fsin.s fa5,fa5'
GAS LISTING   page 1


   1               fsin.s fa5,fa5

GAS LISTING   page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS

$ echo "fcos.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `fcos.s fa5,fa5'
GAS LISTING   page 1


   1               fcos.s fa5,fa5


GAS LISTING   page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS
$ echo "ftan.s fa5, fa5" | riscv64-unknown-elf-as -o test.o -a
{standard input}: Assembler messages:
{standard input}:1: Error: illegal operands `ftan.s fa5,fa5'
GAS LISTING   page 1


   1               ftan.s fa5,fa5


GAS LISTING   page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS

Craig Topper

unread,
Jul 21, 2024, 12:51:39 PM (6 days ago) Jul 21
to RISC-V ISA Dev, Boul chandra Garai, Tommy Murphy, RISC-V ISA Dev, Bruce Hoult
Doesn't fqrt.s use "D,S" not "d,s"? Capitalization matters.

Tommy Murphy

unread,
Jul 21, 2024, 4:07:00 PM (6 days ago) Jul 21
to Craig Topper, RISC-V ISA Dev, Boul chandra Garai, RISC-V ISA Dev, Bruce Hoult
For completeness, and to avoid unnecessary duplication, this issue is also discussed, and seems to be resolved, here: 


Boul chandra Garai

unread,
Jul 21, 2024, 8:51:23 PM (5 days ago) Jul 21
to Tommy Murphy, Craig Topper, RISC-V ISA Dev, Bruce Hoult
Thank you. Yes, after changing its capital "D, S", it looks fine. Thank you for the help.

On Mon, Jul 22, 2024 at 1:36 AM Tommy Murphy <tommy_...@hotmail.com> wrote:
For completeness, and to avoid unnecessary duplication, this issue is also discussed, and seems to be resolved, here: 




Reply all
Reply to author
Forward
0 new messages