From 2d290c08986148de5d8743773c4c30102d42897c Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 6 Mar 2012 15:16:30 +0100 Subject: [PATCH] Preliminary 'log2()' and 'log2f()' implementation The 'log2()' and 'log2f()' functions have been added in FreeBSD's libc version 9.0.0, but they are missing in version 8.2.0, which is used in Genode. This patch provides preliminary implementations of these functions until the Genode libc gets updated to version 9.0.0 or above. Fixes #143. --- libports/lib/mk/gallium-aux.mk | 3 --- libports/lib/mk/libm.mk | 6 ++++++ libports/src/lib/libc/log2.c | 26 ++++++++++++++++++++++++ libports/src/lib/libc/patches/log2.patch | 22 ++++++++++++++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 libports/src/lib/libc/log2.c create mode 100644 libports/src/lib/libc/patches/log2.patch diff --git a/libports/lib/mk/gallium-aux.mk b/libports/lib/mk/gallium-aux.mk index 53256a9d56..31c5cce365 100644 --- a/libports/lib/mk/gallium-aux.mk +++ b/libports/lib/mk/gallium-aux.mk @@ -19,9 +19,6 @@ SRC_C += u_format_access.c u_format_table.c # remove non-needed files from list SRC_C := $(filter-out u_indices.c u_unfilled_indices.c u_debug_memory.c,$(SRC_C)) -# definition of 'log2' that is missing in FreeBSD's libc -CC_OPT_u_math = -D'log2(x)=(log(x)/log(2))' - # dim build noise CC_OPT_draw_vertex += -Wno-unused-but-set-variable CC_OPT_draw_vs_varient += -Wno-enum-compare diff --git a/libports/lib/mk/libm.mk b/libports/lib/mk/libm.mk index cad66a5258..79bcb9e773 100644 --- a/libports/lib/mk/libm.mk +++ b/libports/lib/mk/libm.mk @@ -67,6 +67,9 @@ SRC_C = $(wildcard $(LIBM_DIR)/src/*.c) \ $(wildcard $(LIBM_DIR)/bsdsrc/*.c) SRC_C := $(filter-out $(FILTER_OUT),$(notdir $(SRC_C))) +# remove on update to version 9 +SRC_C += log2.c + # # 'e_rem_pio2.c' uses '__inline' # @@ -76,4 +79,7 @@ vpath %.c $(LIBM_DIR)/src vpath %.c $(LIBM_DIR)/ld80 vpath %.c $(LIBM_DIR)/bsdsrc +# remove on update to version 9 +vpath log2.c $(REP_DIR)/src/lib/libc + SHARED_LIB = yes diff --git a/libports/src/lib/libc/log2.c b/libports/src/lib/libc/log2.c new file mode 100644 index 0000000000..64f7cf6f2b --- /dev/null +++ b/libports/src/lib/libc/log2.c @@ -0,0 +1,26 @@ +/* + * \brief Preliminary 'log2()' and 'log2f()' implementations + * \author Christian Prochaska + * \date 2012-03-06 + */ + +/* + * Copyright (C) 2008-2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include + + +double log2(double x) +{ + return log(x) / log(2); +} + + +float log2f(float x) +{ + return logf(x) / logf(2); +} diff --git a/libports/src/lib/libc/patches/log2.patch b/libports/src/lib/libc/patches/log2.patch new file mode 100644 index 0000000000..6f7fc232a0 --- /dev/null +++ b/libports/src/lib/libc/patches/log2.patch @@ -0,0 +1,22 @@ +- add 'log2()' and 'log2f()' declarations +- this patch is only needed for FreeBSD libc versions < 9 + +diff --git a/msun/src/math.h b/msun/src/math.h +--- msun/src/math.h ++++ msun/src/math.h +@@ -204,6 +204,7 @@ + double ldexp(double, int); + double log(double); + double log10(double); ++double log2(double); + double modf(double, double *); /* fundamentally !__pure2 */ + + double pow(double, double); +@@ -317,6 +318,7 @@ + int ilogbf(float) __pure2; + float ldexpf(float, int); + float log10f(float); ++float log2f(float); + float log1pf(float); + float logf(float); + float modff(float, float *); /* fundamentally !__pure2 */