Merge "Emit warnings when linking against imprecise math functions"
This commit is contained in:
commit
3868759314
@ -261,7 +261,6 @@ LOCAL_SRC_FILES_arm64 := arm64/fenv.c $(libm_ld_src_files)
|
||||
LOCAL_C_INCLUDES_x86 := $(LOCAL_PATH)/i386 $(LOCAL_PATH)/i387
|
||||
LOCAL_SRC_FILES_x86 := i387/fenv.c
|
||||
|
||||
LOCAL_CFLAGS_x86_64 := -include $(LOCAL_PATH)/fpmath.h
|
||||
LOCAL_C_INCLUDES_x86_64 := $(LOCAL_PATH)/amd64 $(libm_ld_includes)
|
||||
LOCAL_SRC_FILES_x86_64 := amd64/fenv.c $(libm_ld_src_files)
|
||||
|
||||
|
@ -22,16 +22,34 @@ int (isinf)(double a1) { return __isinf(a1); }
|
||||
|
||||
int (isnanf)(float a1) { return __isnanf(a1); }
|
||||
|
||||
// FreeBSD falls back to the double variants of these functions as well.
|
||||
long double coshl(long double a1) { return cosh(a1); }
|
||||
long double erfcl(long double a1) { return erfc(a1); }
|
||||
long double erfl(long double a1) { return erf(a1); }
|
||||
long double lgammal(long double a1) { return lgamma(a1); }
|
||||
/*
|
||||
* On LP64 sizeof(long double) > sizeof(double) so functions which fall back
|
||||
* to their double variants lose precision. Emit a warning whenever something
|
||||
* links against such functions.
|
||||
* On LP32 sizeof(long double) == sizeof(double) so we don't need to warn.
|
||||
*/
|
||||
#ifdef __LP64__
|
||||
#define WARN_IMPRECISE(x) \
|
||||
__warn_references(x, # x " has lower than advertised precision");
|
||||
#else
|
||||
#define WARN_IMPRECISE(x)
|
||||
#endif //__LP64__
|
||||
|
||||
#define DECLARE_IMPRECISE(f) \
|
||||
long double f ## l(long double v) { return f(v); } \
|
||||
WARN_IMPRECISE(x)
|
||||
|
||||
DECLARE_IMPRECISE(cosh);
|
||||
DECLARE_IMPRECISE(erfc);
|
||||
DECLARE_IMPRECISE(erf);
|
||||
DECLARE_IMPRECISE(lgamma);
|
||||
DECLARE_IMPRECISE(sinh);
|
||||
DECLARE_IMPRECISE(tanh);
|
||||
DECLARE_IMPRECISE(tgamma);
|
||||
DECLARE_IMPRECISE(significand);
|
||||
|
||||
long double powl(long double a1, long double a2) { return pow(a1, a2); }
|
||||
long double sinhl(long double a1) { return sinh(a1); }
|
||||
long double tanhl(long double a1) { return tanh(a1); }
|
||||
long double tgammal(long double a1) { return tgamma(a1); }
|
||||
long double significandl(long double a1) { return significand(a1); }
|
||||
WARN_IMPRECISE(powl)
|
||||
|
||||
#ifndef __LP64__
|
||||
/*
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2013 David Chisnall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* If long double is not the same size as double, then these will lose
|
||||
* precision and we should emit a warning whenever something links against
|
||||
* them.
|
||||
*/
|
||||
#if (LDBL_MANT_DIG > 53)
|
||||
#define WARN_IMPRECISE(x) \
|
||||
__warn_references(x, # x " has lower than advertised precision");
|
||||
#else
|
||||
#define WARN_IMPRECISE(x)
|
||||
#endif
|
||||
/*
|
||||
* Declare the functions as weak variants so that other libraries providing
|
||||
* real versions can override them.
|
||||
*/
|
||||
#define DECLARE_WEAK(x)\
|
||||
__weak_reference(imprecise_## x, x);\
|
||||
WARN_IMPRECISE(x)
|
||||
|
||||
long double
|
||||
imprecise_powl(long double x, long double y)
|
||||
{
|
||||
|
||||
return pow(x, y);
|
||||
}
|
||||
DECLARE_WEAK(powl);
|
||||
|
||||
#define DECLARE_IMPRECISE(f) \
|
||||
long double imprecise_ ## f ## l(long double v) { return f(v); }\
|
||||
DECLARE_WEAK(f ## l)
|
||||
|
||||
DECLARE_IMPRECISE(cosh);
|
||||
DECLARE_IMPRECISE(erfc);
|
||||
DECLARE_IMPRECISE(erf);
|
||||
DECLARE_IMPRECISE(lgamma);
|
||||
DECLARE_IMPRECISE(sinh);
|
||||
DECLARE_IMPRECISE(tanh);
|
||||
DECLARE_IMPRECISE(tgamma);
|
Loading…
Reference in New Issue
Block a user