Improving math function wrappers
Szabolcs Nagy
szabolcs.nagy@arm.com
Fri Apr 7 15:54:00 GMT 2017
On 04/04/17 18:25, Szabolcs Nagy wrote:
> On 16/03/17 18:24, Joseph Myers wrote:
>> On Thu, 16 Mar 2017, Szabolcs Nagy wrote:
>>> On 16/03/17 14:29, Joseph Myers wrote:
>>>> On Thu, 16 Mar 2017, Wilco Dijkstra wrote:
>>>>
>>>>> Given other languages don't even have the concept of errno, C99 doesn't
>>>>> require it, and no application ever reads errno, it is inefficient to
>>>>> force the use of the wrappers in almost all cases.
>>>>
>>>> C99 not requiring it was an incompatible quiet change from C90.
>>>
>>> i think glibc only has to set errno when user code is
>>> compiled with c89 compatibility and even then only for
>>> math functions that were defined in c89 and then only
>>> guarantee correct errno setting in default rounding mode
>>> (c89 code cannot access the fenv).
>>
>> Incompatible quiet change means a good idea to implement the compatible
>> mode ((math_errhandling & MATH_ERRNO) != 0) as far as possible. Just like
>> it's a good idea to avoid size_t wider than unsigned long.
>
> i think this would be a valid argument if
>
> (math_errhandling & MATH_ERRNO) != 0
>
> was the only way to get backward compatibility,
> but that's not the case: errno can be clobbered
> any time and thus c89 backward compatibility can
> be maintained with
>
> (math_errhandling & MATH_ERRNO) == 0
>
> in which case there is no requirement for non-c89
> math functions to set errno (or getting errno
> right in non-default fenv) and thus the wrapper
> can be removed from all single and long double
> precision functions (and kept for double prec
> c89 functions if glibc cares about compatibility).
>
hm this was not correct: errno cannot be arbitrarily
clobbered, it either has to be set correctly or left
unchanged, but this does not change my argument:
backward compatibility can be maintained more easily
with (math_errhandling & MATH_ERRNO) == 0.
http://port70.net/~nsz/c/c11/n1570.html#7.12.1p7
>> Compilers for non-C languages without the concept of these functions
>> setting errno can of course default to -fno-math-errno by default (and
>> built-in no-errno functions that can be used with -fmath-errno is
>> otherwise enabled would also be desirable for fma, sqrt, etc.).
>
> then fortran can only use no-errno functions
> when those can be inlined, since extern calls
> use the standard libc symbols which set errno
> in glibc.
>
More information about the Libc-alpha
mailing list