Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling to RISC-V #288

Open
davidmallasen opened this issue Jul 1, 2022 · 8 comments
Open

Compiling to RISC-V #288

davidmallasen opened this issue Jul 1, 2022 · 8 comments
Assignees

Comments

@davidmallasen
Copy link
Contributor

Hello!

I'm having some trouble using Universal for RISC-V. I have a small test project with the following directories:

test_universal/
    build/
    src/
        mymain.cpp
    CMakeLists.txt

The content of CMakeLists.txt is:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example)

set(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++)

set(SRC_FOLDER "${CMAKE_CURRENT_LIST_DIR}/src")

include_directories("~/universal-3.52/include")

add_executable(test_posit ${SRC_FOLDER}/mymain.cpp)
set_property(TARGET test_posit PROPERTY CXX_STANDARD 17)

When executing:

mkdir build
cd build
cmake ..
make

I get the following errors:

[ 50%] Building CXX object CMakeFiles/test_posit.dir/src/mymain.cpp.o
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp: In function 'void sw::universal::extract_fp_components(long double, bool&, int&, long double&, long long unsigned int&)':
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:195:57: error: static assertion failed: This function only works when long double significant is <= 64 bit.
  195 |  static_assert(std::numeric_limits<long double>::digits <= 64, "This function only works when long double significant is <= 64 bit.");
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:203:9: error: 'frexpl' was not declared in this scope; did you mean 'frexpf'?
  203 |   _fr = frexpl(fp, &_exponent);
      |         ^~~~~~
      |         frexpf
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp: At global scope:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:23:7: error: redefinition of 'union sw::universal::long_double_decoder'
   23 | union long_double_decoder {
      |       ^~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:23:7: note: previous definition of 'union sw::universal::long_double_decoder'
   23 | union long_double_decoder {
      |       ^~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:33:13: error: redefinition of 'void sw::universal::extractFields(long double, bool&, uint64_t&, uint64_t&)'
   33 | inline void extractFields(long double value, bool& s, uint64_t& rawExponentBits, uint64_t& rawFractionBits) {
      |             ^~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:33:13: note: 'void sw::universal::extractFields(long double, bool&, uint64_t&, uint64_t&)' previously defined here
   33 | inline void extractFields(long double value, bool& s, uint64_t& rawExponentBits, uint64_t& rawFractionBits) {
      |             ^~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:42:20: error: redefinition of 'std::string sw::universal::to_base2_scientific(long double)'
   42 | inline std::string to_base2_scientific(long double number) {
      |                    ^~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:42:20: note: 'std::string sw::universal::to_base2_scientific(long double)' previously defined here
   42 | inline std::string to_base2_scientific(long double number) {
      |                    ^~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:57:20: error: redefinition of 'std::string sw::universal::to_hex(long double)'
   57 | inline std::string to_hex(long double number) {
      |                    ^~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:57:20: note: 'std::string sw::universal::to_hex(long double)' previously defined here
   57 | inline std::string to_hex(long double number) {
      |                    ^~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:66:20: error: redefinition of 'std::string sw::universal::to_binary(long double, bool)'
   66 | inline std::string to_binary(long double number, bool bNibbleMarker = false) {
      |                    ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:66:20: note: 'std::string sw::universal::to_binary(long double, bool)' previously defined here
   66 | inline std::string to_binary(long double number, bool bNibbleMarker = false) {
      |                    ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:100:20: error: redefinition of 'std::string sw::universal::to_triple(long double)'
  100 | inline std::string to_triple(long double number) {
      |                    ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:100:20: note: 'std::string sw::universal::to_triple(long double)' previously defined here
  100 | inline std::string to_triple(long double number) {
      |                    ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:135:20: error: redefinition of 'std::string sw::universal::color_print(long double)'
  135 | inline std::string color_print(long double number) {
      |                    ^~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:406,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/gcc_long_double.hpp:135:20: note: 'std::string sw::universal::color_print(long double)' previously defined here
  135 | inline std::string color_print(long double number) {
      |                    ^~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:407,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp: In function 'void sw::universal::extract_fp_components(long double, bool&, int&, long double&, uint64_t&)':
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:181:31: error: static assertion failed: This function only works when long double is 128 bits.
  181 |  static_assert(sizeof(double) == 16, "This function only works when long double is 128 bits.");
      |                ~~~~~~~~~~~~~~~^~~~~
/home/david/universal-3.52/include/universal/native/nonconstexpr/riscv_long_double.hpp:183:8: error: 'frexpl' was not declared in this scope; did you mean 'frexpf'?
  183 |  _fr = frexpl(fp, &_exponent);
      |        ^~~~~~
      |        frexpf
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:20,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/error_and_gamma.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::erf(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/error_and_gamma.hpp:16:30: error: 'erf' is not a member of 'std'; did you mean 'ref'?
   16 |  return posit<nbits,es>(std::erf(double(x)));
      |                              ^~~
      |                              ref
/home/david/universal-3.52/include/universal/number/posit/math/error_and_gamma.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::erfc(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/error_and_gamma.hpp:22:30: error: 'erfc' is not a member of 'std'; did you mean 'errc'?
   22 |  return posit<nbits,es>(std::erfc(double(x)));
      |                              ^~~~
      |                              errc
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:21,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/exponent.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::exp2(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/exponent.hpp:33:18: error: 'exp2' is not a member of 'std'; did you mean 'exp'?
   33 |  double d = std::exp2(double(x));
      |                  ^~~~
      |                  exp
/home/david/universal-3.52/include/universal/number/posit/math/exponent.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::expm1(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/exponent.hpp:52:30: error: 'expm1' is not a member of 'std'; did you mean 'exp'?
   52 |  return posit<nbits,es>(std::expm1(double(x)));
      |                              ^~~~~
      |                              exp
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:22,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/fractional.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::remainder(sw::universal::posit<nbits, es>, sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/fractional.hpp:20:30: error: 'remainder' is not a member of 'std'
   20 |  return posit<nbits,es>(std::remainder(double(x), double(y)));
      |                              ^~~~~~~~~
/home/david/universal-3.52/include/universal/number/posit/math/fractional.hpp:20:30: note: suggested alternatives:
In file included from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:45,
                 from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:9,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/math.h:336:15: note:   'remainder'
  336 | extern double remainder (double, double);
      |               ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:22,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/fractional.hpp:19:17: note:   'sw::universal::remainder'
   19 | posit<nbits,es> remainder(posit<nbits,es> x, posit<nbits,es> y) {
      |                 ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:23,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::atanh(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:37:45: error: no matching function for call to 'atanh(double)'
   37 |  return posit<nbits,es>(std::atanh(double(x)));
      |                                             ^
In file included from /home/david/universal-3.52/include/universal/number/posit/math/complex.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:19,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1833:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::atanh(const std::complex<_Tp>&)'
 1833 |     atanh(const std::complex<_Tp>& __z)
      |     ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1833:5: note:   template argument deduction/substitution failed:
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:23,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:37:45: note:   mismatched types 'const std::complex<_Tp>' and 'double'
   37 |  return posit<nbits,es>(std::atanh(double(x)));
      |                                             ^
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::acosh(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:43:45: error: no matching function for call to 'acosh(double)'
   43 |  return posit<nbits,es>(std::acosh(double(x)));
      |                                             ^
In file included from /home/david/universal-3.52/include/universal/number/posit/math/complex.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:19,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1750:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::acosh(const std::complex<_Tp>&)'
 1750 |     acosh(const std::complex<_Tp>& __z)
      |     ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1750:5: note:   template argument deduction/substitution failed:
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:23,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:43:45: note:   mismatched types 'const std::complex<_Tp>' and 'double'
   43 |  return posit<nbits,es>(std::acosh(double(x)));
      |                                             ^
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::asinh(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:49:45: error: no matching function for call to 'asinh(double)'
   49 |  return posit<nbits,es>(std::asinh(double(x)));
      |                                             ^
In file included from /home/david/universal-3.52/include/universal/number/posit/math/complex.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:19,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1789:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::asinh(const std::complex<_Tp>&)'
 1789 |     asinh(const std::complex<_Tp>& __z)
      |     ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/complex:1789:5: note:   template argument deduction/substitution failed:
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:23,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hyperbolic.hpp:49:45: note:   mismatched types 'const std::complex<_Tp>' and 'double'
   49 |  return posit<nbits,es>(std::asinh(double(x)));
      |                                             ^
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:24,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::hypot(sw::universal::posit<nbits, es>, sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp:48:55: error: no matching function for call to 'hypot(double, double)'
   48 |  return posit<nbits,es>(std::hypot(double(x),double(y)));
      |                                                       ^
In file included from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:9,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1868:3: note: candidate: 'float std::hypot(float, float, float)'
 1868 |   hypot(float __x, float __y, float __z)
      |   ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1868:3: note:   candidate expects 3 arguments, 2 provided
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1872:3: note: candidate: 'double std::hypot(double, double, double)'
 1872 |   hypot(double __x, double __y, double __z)
      |   ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1872:3: note:   candidate expects 3 arguments, 2 provided
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1876:3: note: candidate: 'long double std::hypot(long double, long double, long double)'
 1876 |   hypot(long double __x, long double __y, long double __z)
      |   ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1876:3: note:   candidate expects 3 arguments, 2 provided
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1881:5: note: candidate: 'template<class _Tp, class _Up, class _Vp> typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type std::hypot(_Tp, _Up, _Vp)'
 1881 |     hypot(_Tp __x, _Up __y, _Vp __z)
      |     ^~~~~
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:1881:5: note:   template argument deduction/substitution failed:
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:24,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp:48:55: note:   candidate expects 3 arguments, 2 provided
   48 |  return posit<nbits,es>(std::hypot(double(x),double(y)));
      |                                                       ^
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::hypotf(sw::universal::posit<nbits, es>, sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp:53:30: error: 'hypotf' is not a member of 'std'; did you mean 'hypot'?
   53 |  return posit<nbits,es>(std::hypotf(float(x),float(y)));
      |                              ^~~~~~
      |                              hypot
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::hypotl(sw::universal::posit<nbits, es>, sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/hypot.hpp:58:30: error: 'hypotl' is not a member of 'std'; did you mean 'hypot'?
   58 |  return posit<nbits,es>(std::hypotl((long double)(x),(long double)(y)));
      |                              ^~~~~~
      |                              hypot
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:25,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/logarithm.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::log2(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/logarithm.hpp:22:30: error: 'log2' is not a member of 'std'; did you mean 'log'?
   22 |  return posit<nbits,es>(std::log2(double(x)));
      |                              ^~~~
      |                              log
/home/david/universal-3.52/include/universal/number/posit/math/logarithm.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::log1p(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/logarithm.hpp:34:30: error: 'log1p' is not a member of 'std'; did you mean 'log10'?
   34 |  return posit<nbits,es>(std::log1p(double(x)));
      |                              ^~~~~
      |                              log10
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:49,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_riscv.hpp: At global scope:
/home/david/universal-3.52/include/universal/native/ieee754_riscv.hpp:15:7: error: redefinition of 'class sw::universal::ieee754_parameter<float>'
   15 | class ieee754_parameter<float> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:47,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_gcc.hpp:16:7: note: previous definition of 'class sw::universal::ieee754_parameter<float>'
   16 | class ieee754_parameter<float> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:49,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_riscv.hpp:32:7: error: redefinition of 'class sw::universal::ieee754_parameter<double>'
   32 | class ieee754_parameter<double> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:47,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_gcc.hpp:38:7: note: previous definition of 'class sw::universal::ieee754_parameter<double>'
   38 | class ieee754_parameter<double> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:49,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_riscv.hpp:52:7: error: redefinition of 'class sw::universal::ieee754_parameter<long double>'
   52 | class ieee754_parameter<long double> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/native/ieee754.hpp:47,
                 from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754_gcc.hpp:63:7: note: previous definition of 'class sw::universal::ieee754_parameter<long double>'
   63 | class ieee754_parameter<long double> {
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/math/sqrt.hpp:7,
                 from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:29,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/native/ieee754.hpp: In function 'Real sw::universal::ulp(const Real&)':
/home/david/universal-3.52/include/universal/native/ieee754.hpp:97:14: error: 'nextafter' is not a member of 'std'
   97 |  return std::nextafter(a, a + a/2.0f) - a;
      |              ^~~~~~~~~
/home/david/universal-3.52/include/universal/native/ieee754.hpp:97:14: note: suggested alternatives:
In file included from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:45,
                 from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:9,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/math.h:308:15: note:   'nextafter'
  308 | extern double nextafter (double, double);
      |               ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:27,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/next.hpp:27:17: note:   'sw::universal::nextafter'
   27 | posit<nbits,es> nextafter(posit<nbits,es> x, posit<nbits, es> target) {
      |                 ^~~~~~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:31,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::trunc(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:16:30: error: 'trunc' is not a member of 'std'
   16 |  return posit<nbits,es>(std::trunc(double(x)));
      |                              ^~~~~
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:16:30: note: suggested alternatives:
In file included from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:45,
                 from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:9,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/math.h:321:15: note:   'trunc'
  321 | extern double trunc (double);
      |               ^~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:31,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:15:17: note:   'sw::universal::trunc'
   15 | posit<nbits,es> trunc(posit<nbits,es> x) {
      |                 ^~~~~
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp: In function 'sw::universal::posit<nbits, es> sw::universal::round(sw::universal::posit<nbits, es>)':
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:22:30: error: 'round' is not a member of 'std'
   22 |  return posit<nbits,es>(std::round(double(x)));
      |                              ^~~~~
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:22:30: note: suggested alternatives:
In file included from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/cmath:45,
                 from /home/david/universal-3.52/include/universal/native/nonconstexpr754.hpp:9,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:12,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/math.h:318:15: note:   'round'
  318 | extern double round (double);
      |               ^~~~~
In file included from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/condition_variable:38,
                 from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/shared_mutex:37,
                 from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/memory_resource:40,
                 from /home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/regex:66,
                 from /home/david/universal-3.52/include/universal/number/posit/posit_parse.hpp:8,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:58,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/riscv/riscv64-unknown-elf/include/c++/10.2.0/chrono:853:7: note:   'std::chrono::round'
  853 |       round(const time_point<_Clock, _Dur>& __tp)
      |       ^~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/mathlib.hpp:31,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:89,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/number/posit/math/truncate.hpp:21:17: note:   'sw::universal::round'
   21 | posit<nbits,es> round(posit<nbits,es> x) {
      |                 ^~~~~
In file included from /home/david/universal-3.52/include/universal/number/posit/posit_impl.hpp:39,
                 from /home/david/universal-3.52/include/universal/number/posit/posit.hpp:59,
                 from /home/david/test_universal/src/mymain.cpp:3:
/home/david/universal-3.52/include/universal/internal/bitblock/bitblock.hpp:591:20: note:   'sw::universal::internal::round'
  591 | bitblock<tgt_size> round(const bitblock<src_size>& src, size_t n)
      |                    ^~~~~
make[2]: *** [CMakeFiles/test_posit.dir/build.make:63: CMakeFiles/test_posit.dir/src/mymain.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/test_posit.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

The cpp file includes <universal/number/posit/posit.hpp>, and the same small code is working when compiling in Ubuntu by default without the

set(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++)

line in CMakeLists.txt. I have also tried using clang++ with the same result. Any insights into how to solve this? Thanks!

@ghost
Copy link

ghost commented Jul 3, 2022

@davidmallasen thanks for bringing this up. This will take a bit of work to resolve as different compilers provide different supporting structures. The errors reported indicate that the math library offered has some different assumptions. Good news is that I am very interested to get the RISC-V environment clean and in the regular regression line-up.

This is going to be a porting exercise discovering what the RISC-V compiler, runtime, and library environment constraints are and organizing the code accordingly. If you can tell me how to recreate your environment so we can collaborate that would be the first step.

@davidmallasen
Copy link
Contributor Author

Hello @theo-lemurian

To recreate the RISC-V environment on a Ubuntu 22.04 machine:
In home directory of user user:

git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain

sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

./configure --prefix=/home/user/riscv --enable-multilib
make
cd ..

In ~/.bashrc add: export PATH="$PATH:/home/user/riscv/bin/"

source .bashrc

git clone https://github.com/stillwater-sc/universal.git

mkdir test_universal
cd test_universal
mkdir src
mkdir build
cd src

Create file main.cpp:

#include <universal/number/posit/posit.hpp>

int main() {
    sw::universal::posit<32,2> a = 1;
    std::cout << to_hex(a.get()) << std::endl;
    return 0;
}
cd ..

Create file CMakeLists.txt:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example)

set(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++)

set(SRC_FOLDER "${CMAKE_CURRENT_LIST_DIR}/src")

include_directories("~/universal/include")

add_executable(test_posit ${SRC_FOLDER}/main.cpp)
set_property(TARGET test_posit PROPERTY CXX_STANDARD 17)

Then:

cd build
cmake ..
make

I hope this helps.
David

@ghost
Copy link

ghost commented Jul 11, 2022

Tried over the weekend to create a RISC-V Qemu setup but was unsuccessful. Do you have any guidance?

@Ravenwater
Copy link
Contributor

finally got a risc-v environment. Now I can reproduce your errors. There is some restructuring required to have gcc and risc-v play nice together. I'll work on that this week. In the mean time, maybe you can help me decipher this error:

stillwater@3e7deb69f9bc:~/test/build$ make
[ 50%] Building CXX object CMakeFiles/test_posit.dir/src/main.cpp.o
[100%] Linking CXX executable test_posit
riscv64-unknown-elf-g++: error: unrecognized command-line option '-rdynamic'
make[2]: *** [CMakeFiles/test_posit.dir/build.make:97: test_posit] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_posit.dir/all] Error 2

Any idea where this -rdynamic flag comes from?

@Ravenwater
Copy link
Contributor

@davidmallasen ^^^

@davidmallasen
Copy link
Contributor Author

Hello @Ravenwater ,

I don't use qemu so I don't know about that, but great hearing that you could get the risc-v environment working.

I've never used that flag, so I'm not sure where it comes from. Searching online it seems that it is part of the linking process, maybe that helps to figure it out?
From the gcc documentation: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
A more detailed explanation: https://stackoverflow.com/questions/36692315/what-exactly-does-rdynamic-do-and-when-exactly-is-it-needed

@Ravenwater
Copy link
Contributor

Ravenwater commented Jul 19, 2022

@davidmallasen got the basics up and running. Looks like the mathlib in the RISC-V toolchain is a couple of decades behind, so I need to understand what their roadmap is for them to support a compliant <cmath>. I will stub out all the functions they are not yet supporting to see if we can get this up and running. Once we get something working, it will be easier to track their progress and integrate with their future releases.

@davidmallasen
Copy link
Contributor Author

Perfect, sounds like a good solution @Ravenwater

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants