This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] New expf, exp2f, logf, log2f and powf implementations


On 17/10/17 12:40, Szabolcs Nagy wrote:
> On 13/10/17 10:13, Corinna Vinschen wrote:
>>
>> Pushed.
>>
> 
> sorry, i did not realize that there are internal calls
> to __ieee754_logf and __ieee754_expf from various math
> functions.
> 
> in the new math code i only define logf and expf symbols.
> (same for powf, but __ieee754_powf is not used in newlib)
> 
> i can reintroduce the __ieee754* symbols as trivial wrappers
> or weak aliases or macro redirect.
> 
> i think a macro is probably the best since there is no
> requirement to make these symbols extern linkable, they are
> purely implementation internal so fdlibm.h could have:
> 
> #if !__OBSOLETE_MATH
> # define __ieee754_expf(x) expf(x)
> # define __ieee754_logf(x) logf(x)
> # define __ieee754_powf(x,y) powf(x,y)
> #endif
> 
> this changes the semantics a bit: __ieee754_* symbols didn't
> do error handling previously, however the error code paths
> should not really matter for internal calls, if they are ever
> reached then at worst errno is set spuriously in the new code.
> 
> does this sound ok?
> 

implemented this approach in the attached patch, verified
that there are no longer undefined __ieee754_* symbols.

adding __ieee754* symbol aliases is safer in principle
(e.g. user defined expf would not override internal calls),
but i'm not sure if i can use weak alias in newlib, so
i went with the macros.

>From 23753d87bfcf048c5fa0a297d7cce48b733b696b Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue, 17 Oct 2017 12:41:20 +0100
Subject: [PATCH] fix internal __ieee754_expf and __ieee754_logf calls

The recently added new math code inlines error handling instead of using
error handling wrappers around __ieee754* internal symbols, and thus the
__ieee754* symbols are no longer provided.

However __ieee754_expf and __ieee754_logf are used in the implementation
of a number of other math functions.  These symbols are safe to redirect
to the external expf and logf symbols, because those names are always
reserved when single precision math functions are reserved and the
additional error handling code is either not reached or there will be
an error in the final result that will override an internal spurious
errno setting.

For consistency all of __ieee754_expf, __ieee754_logf and __ieee754_powf
are redirected using a macro.
---
 newlib/libm/common/fdlibm.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
index 821e4dedb..4523e8b2a 100644
--- a/newlib/libm/common/fdlibm.h
+++ b/newlib/libm/common/fdlibm.h
@@ -225,6 +225,17 @@ extern float __ieee754_scalbf __P((float,int));
 extern float __ieee754_scalbf __P((float,float));
 #endif
 
+#if !__OBSOLETE_MATH
+/* The new math code does not provide separate wrapper function
+   for error handling, so the extern symbol is called directly.
+   This is valid as long as there are no namespace issues (the
+   extern symbol is reserved whenever the caller is reserved)
+   and there are no observable error handling side effects.  */
+# define __ieee754_expf(x) expf(x)
+# define __ieee754_logf(x) logf(x)
+# define __ieee754_powf(x,y) powf(x,y)
+#endif
+
 /* float versions of fdlibm kernel functions */
 extern float __kernel_sinf __P((float,float,int));
 extern float __kernel_cosf __P((float,float));
-- 
2.11.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]