This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: Improving math function wrappers


On Thu, 16 Mar 2017, Florian Weimer wrote:

> We have recently removed the PID cache from the TCB.  We could store the errno
> value there, instead of going through __errno_location.  (Code outside glibc
> would still use __errno_location, of course.)

Code in glibc's libraries should already be setting the TLS initial-exec 
errno variable directly (that's how __set_errno is defined in 
include/errno.h).  But any case that sets errno should not be 
performance-critical; the issue is the effects on performance of non-error 
cases with finite arguments (which should just be checking if the result 
is non-finite or zero, depending on the function - but the issue raised 
here was consequent need to save the arguments for subsequent checks in 
the unlikely case to see whether e.g. a NaN result was an error or from a 
NaN argument, and it's possible the code in the error case might have 
other prologue/epilogue effects that don't get shrink-wrapped away).

Most of the time the checks either duplicate ones already present in the 
main function implementation, or could be localized to an unlikely case 
within that implementation, hence the notion that setting errno in the 
main function implementation makes sense (along with avoiding extra stack 
frame setup etc.).

If we set errno in some main function implementations I think we should be 
clear that adding a wrapper is still a fine way to fix one of the 
remaining bugs about missing errno setting in cases where 
architecture-specific implementations are involved, with the option of 
optimizing later by moving away from that wrapper.

-- 
Joseph S. Myers
joseph@codesourcery.com


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