diff mbox

Add s_sincosf_data.c

Message ID 20171216135753.GA15371@intel.com
State New, archived
Headers show

Commit Message

H.J. Lu Dec. 16, 2017, 1:57 p.m. UTC
Add s_sincosf_data.c to data between sinf, cosf and sincosf.

Tested on x86-64.  It reduced the read-only data size by 352 bytes.

On Skylake, bench-sincosf reports performance change:

            Before        After         Change
max        148.062       144.118          3%
min        9.408         9.418            -0.1%
mean       21.5507       21.8225          -1%

OK for master?

H.J.
----
	* math/Makefile (type-float-routines): Add s_sincosf_data.
	* sysdeps/ieee754/flt-32/math_config.h (SINCOSF_PIO2_TABLE):
	New.
	(SINCOSF_INVPIO4_TABLE): Likewise.
	(SINCOSF_DOUBLE_ONES): Likewise.
	(__sincosf_data): Likewise.
	* sysdeps/ieee754/flt-32/s_sincosf.h: Include "math_config.h".
	(pio2_table): Replaced with __sincosf_data.
	(invpio4_table): Likewise.
	(ones): Likewise.
	* sysdeps/ieee754/flt-32/s_sincosf_data.c: New file.
---
 math/Makefile                           |  2 +-
 sysdeps/ieee754/flt-32/math_config.h    | 11 +++++++++
 sysdeps/ieee754/flt-32/s_sincosf.h      | 26 ++++-----------------
 sysdeps/ieee754/flt-32/s_sincosf_data.c | 41 +++++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+), 22 deletions(-)
 create mode 100644 sysdeps/ieee754/flt-32/s_sincosf_data.c

Comments

Joseph Myers Dec. 18, 2017, 5:18 p.m. UTC | #1
I would expect this to add dummy s_sincosf_data.c files for architectures 
with their own sinf/cosf/sincosf implementations (I think that's 
sysdeps/ia64/fpu and sysdeps/m68k/m680x0/fpu at least) to avoid 
unnecessarily building this data where it won't be used.
diff mbox

Patch

diff --git a/math/Makefile b/math/Makefile
index cba9ce9405..8762f20059 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -120,7 +120,7 @@  type-double-routines := branred doasin dosincos halfulp mpa mpatan2	\
 # float support
 type-float-suffix := f
 type-float-routines := k_rem_pio2f math_errf e_exp2f_data e_logf_data	\
-		       e_log2f_data e_powf_log2_data
+		       e_log2f_data e_powf_log2_data s_sincosf_data
 
 # _Float128 support
 type-float128-suffix := f128
diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h
index e5a830b442..c2bc72805c 100644
--- a/sysdeps/ieee754/flt-32/math_config.h
+++ b/sysdeps/ieee754/flt-32/math_config.h
@@ -161,4 +161,15 @@  extern const struct powf_log2_data
   double poly[POWF_LOG2_POLY_ORDER];
 } __powf_log2_data attribute_hidden;
 
+/* Shared between sinf, cosf and sincosf.  */
+#define SINCOSF_PIO2_TABLE	6
+#define SINCOSF_INVPIO4_TABLE	8
+#define SINCOSF_DOUBLE_ONES	2
+extern const struct sincosf_data
+{
+  double pio2_table[SINCOSF_PIO2_TABLE];
+  double invpio4_table[SINCOSF_INVPIO4_TABLE];
+  double ones[SINCOSF_DOUBLE_ONES];
+} __sincosf_data attribute_hidden;
+
 #endif
diff --git a/sysdeps/ieee754/flt-32/s_sincosf.h b/sysdeps/ieee754/flt-32/s_sincosf.h
index b0110fc2af..89855c757f 100644
--- a/sysdeps/ieee754/flt-32/s_sincosf.h
+++ b/sysdeps/ieee754/flt-32/s_sincosf.h
@@ -16,6 +16,8 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include "math_config.h"
+
 /* Chebyshev constants for cos, range -PI/4 - PI/4.  */
 static const double C0 = -0x1.ffffffffe98aep-2;
 static const double C1 =  0x1.55555545c50c7p-5;
@@ -48,27 +50,9 @@  static const double inv_PI_4 = 0x1.45f306dc9c883p+0; /* 4/PI.  */
 #define FLOAT_EXPONENT_SHIFT 23
 #define FLOAT_EXPONENT_BIAS 127
 
-static const double pio2_table[] = {
-  0 * M_PI_2,
-  1 * M_PI_2,
-  2 * M_PI_2,
-  3 * M_PI_2,
-  4 * M_PI_2,
-  5 * M_PI_2
-};
-
-static const double invpio4_table[] = {
-  0x0p+0,
-  0x1.45f306cp+0,
-  0x1.c9c882ap-28,
-  0x1.4fe13a8p-58,
-  0x1.f47d4dp-85,
-  0x1.bb81b6cp-112,
-  0x1.4acc9ep-142,
-  0x1.0e4107cp-169
-};
-
-static const double ones[] = { 1.0, -1.0 };
+#define pio2_table	__sincosf_data.pio2_table
+#define invpio4_table	__sincosf_data.invpio4_table
+#define ones		__sincosf_data.ones
 
 /* Compute the sine value using Chebyshev polynomials where
    THETA is the range reduced absolute value of the input
diff --git a/sysdeps/ieee754/flt-32/s_sincosf_data.c b/sysdeps/ieee754/flt-32/s_sincosf_data.c
new file mode 100644
index 0000000000..d999ac5dfc
--- /dev/null
+++ b/sysdeps/ieee754/flt-32/s_sincosf_data.c
@@ -0,0 +1,41 @@ 
+/* Shared data between sinf, cosf and sincosf.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "math_config.h"
+
+const struct sincosf_data __sincosf_data = {
+  .pio2_table = {
+    0 * M_PI_2,
+    1 * M_PI_2,
+    2 * M_PI_2,
+    3 * M_PI_2,
+    4 * M_PI_2,
+    5 * M_PI_2
+  },
+  .invpio4_table = {
+    0x0p+0,
+    0x1.45f306cp+0,
+    0x1.c9c882ap-28,
+    0x1.4fe13a8p-58,
+    0x1.f47d4dp-85,
+    0x1.bb81b6cp-112,
+    0x1.4acc9ep-142,
+    0x1.0e4107cp-169
+  },
+  .ones = { 1.0, -1.0 }
+};