Re: __fp16 is ambiguous error in C++

2021-06-25 Thread Jonathan Wakely via Gcc
> foo.c:6:23: error: call of overloaded 'exp(__fp16&)' is ambiguous

__fp16 isn't ambiguous, calling std::exp with an argument of that type
is ambiguous, because the standard library doesn't provide an overload
for that type.

It could be added (probably defined to cast to float and use the
overload for float), but we would need to do it for every function in
. It's a simple matter of programming, but somebody needs to
do the work.



Re: __fp16 is ambiguous error in C++

2021-06-25 Thread Jim Wilson
On Thu, Jun 24, 2021 at 7:26 PM ALO via Gcc  wrote:

> foo.c: In function '__fp16 foo(__fp16, __fp16)':
> foo.c:6:23: error: call of overloaded 'exp(__fp16&)' is ambiguous
> 6 | return a + std::exp(b);
> | ^
>

No, there isn't a solution for this.  You might want to try an ARM port
clang/gcc to see what they do, but it probably isn't much better than the
RISC-V port.  Looks like the same gcc result to me with a quick check.  And
note that only the non-upstream V extension branch for RISC-V has the
__fp16 support because the vector extension depends on it.  It is hard to
argue for changes when the official RISC-V GCC port has no __fp16 support.

Kito started a related thread in March, and there was tentative agreement
to add _Float16 support to the GCC C++ front end.
https://gcc.gnu.org/pipermail/gcc/2021-March/234971.html
That may or may not help you.

I think it will be difficult to do anything useful here until the C and C++
standards figure out how they want half-float support to work.  If we do
something before then, it will probably end up incompatible with the
official solution and we will end up stuck with a mess.

Jim


__fp16 is ambiguous error in C++

2021-06-24 Thread ALO via Gcc
#include 

__fp16 foo (__fp16 a, __fp16 b)
{
return a + std::exp(b);
}

compiler options:
=

riscv64-unknown-linux-gnu-g++ foo.c -march=rv64gc_zfh -mabi=lp64

error:
==

foo.c: In function '__fp16 foo(__fp16, __fp16)':
foo.c:6:23: error: call of overloaded 'exp(__fp16&)' is ambiguous
6 | return a + std::exp(b);
| ^
In file included from $INSTALL/sysroot/usr/include/features.h:465,
from 
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/riscv64-unknown-linux-gnu/bits/os_defines.h:39,
from 
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/riscv64-unknown-linux-gnu/bits/c++config.h:518,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:41,
from $INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/math.h:36,
from foo.c:2:
$INSTALL/sysroot/usr/include/bits/mathcalls.h:95:1: note: candidate: 'double 
exp(double)'
95 | __MATHCALL_VEC (exp,, (Mdouble __x));
| ^~
In file included from 
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/math.h:36,
from foo.c:2:
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:222:3: note: 
candidate: 'constexpr float std::exp(float)'
222 | exp(float __x)
| ^~~
$INSTALL/riscv64-unknown-linux-gnu/include/c++/10.2.0/cmath:226:3: note: 
candidate: 'constexpr long double std::exp(long double)'
226 | exp(long double __x)
| ^~~

I think there is no prototype of __fp16 in libmath of glibc,
I could cast '__fp16' to 'float' or 'double' to fix this issue with modifying 
code, it's not invisible for developers :(

Is there any other method to fix this ?

Maybe there is some c++ compiler's option for this ?

— Jojo