This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
IA64 HP-UX math library patch
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 27 Aug 2002 11:11:38 -0700 (PDT)
- Subject: IA64 HP-UX math library patch
- Reply-to: sje at cup dot hp dot com
Here is a patch for C89 conformance on IA64 HP-UX that I'd like to check
in. The default math library routines on IA64 HP-UX do not set errno.
If setting errno is desired then you have to call a different routine.
This patch uses the builtin pragma in HP's header file to change the
assembly language level routine name of the math functions if strict C89
conformance was requested.
Comments and/or Approval?
Steve Ellcey
sje@cup.hp.com
2002-08-27 Steve Ellcey <sje@cup.hp.com>
* config/ia64/hpux.h (REGISTER_TARGET_PRAGMAS): Register pragma
handling routine for builtin pragma.
(HPUX_C89_MATHLIB_NAME_LIST): Define list of math functions
with alternative names that set errno.
* ia64-protos.h (ia64_hpux_handle_builtin_pragma): Registered
pragma handling routine.
* ia64.c (ia64_hpux_handle_builtin_pragma): Ditto.
(ia64_hpux_add_pragma_builtin) New subroutine used by above.
If builtin pragma seen for math routine and C89 conformance is
requested use different math function in order to set errno.
*** gcc.orig/gcc/config/ia64/hpux.h Tue Aug 20 15:10:09 2002
--- gcc/gcc/config/ia64/hpux.h Tue Aug 27 09:52:15 2002
*************** Boston, MA 02111-1307, USA. */
*** 121,123 ****
--- 121,237 ----
#undef PAD_VARARGS_DOWN
#define PAD_VARARGS_DOWN (!AGGREGATE_TYPE_P (type))
+
+ #define REGISTER_TARGET_PRAGMAS(PFILE) \
+ cpp_register_pragma (PFILE, 0, "builtin", ia64_hpux_handle_builtin_pragma)
+
+ /* List of standard math functions which do not set matherr by default
+ and which have a different version which does set errno and which we
+ want to call *if* we have seen an extern for the routine and we have
+ asked for strict C89 compatibility. */
+
+ #define HPUX_C89_MATHLIB_NAME_LIST \
+ {"acos", "_Acos_e#"}, \
+ {"acosd", "_Acosd_e#"}, \
+ {"acosdf", "_Acosdf_e#"}, \
+ {"acosdl", "_Acosdl_e#"}, \
+ {"acosdw", "_Acosdw_e#"}, \
+ {"acosf", "_Acosf_e#"}, \
+ {"acosh", "_Acosh_e#"}, \
+ {"acoshf", "_Acoshf_e#"}, \
+ {"acoshl", "_Acoshl_e#"}, \
+ {"acoshw", "_Acoshw_e#"}, \
+ {"acosl", "_Acosl_e#"}, \
+ {"acosw", "_Acosw_e#"}, \
+ {"asin", "_Asin_e#"}, \
+ {"asind", "_Asind_e#"}, \
+ {"asindf", "_Asindf_e#"}, \
+ {"asindl", "_Asindl_e#"}, \
+ {"asindw", "_Asindw_e#"}, \
+ {"asinf", "_Asinf_e#"}, \
+ {"asinl", "_Asinl_e#"}, \
+ {"asinw", "_Asinw_e#"}, \
+ {"atanh", "_Atanh_e#"}, \
+ {"atanhf", "_Atanhf_e#"}, \
+ {"atanhl", "_Atanhl_e#"}, \
+ {"atanhw", "_Atanhw_e#"}, \
+ {"cosh", "_Cosh_e#"}, \
+ {"coshf", "_Coshf_e#"}, \
+ {"coshl", "_Coshl_e#"}, \
+ {"coshw", "_Coshw_e#"}, \
+ {"exp2", "_Exp2_e#"}, \
+ {"exp2f", "_Exp2f_e#"}, \
+ {"exp2l", "_Exp2l_e#"}, \
+ {"exp2w", "_Exp2w_e#"}, \
+ {"exp", "_Exp_e#"}, \
+ {"expf", "_Expf_e#"}, \
+ {"expl", "_Expl_e#"}, \
+ {"expm1", "_Expm1_e#"}, \
+ {"expm1f", "_Expm1f_e#"}, \
+ {"expm1l", "_Expm1l_e#"}, \
+ {"expm1w", "_Expm1w_e#"}, \
+ {"expw", "_Expw_e#"}, \
+ {"fmod", "_Fmod_e#"}, \
+ {"fmodf", "_Fmodf_e#"}, \
+ {"fmodl", "_Fmodl_e#"}, \
+ {"fmodw", "_Fmodw_e#"}, \
+ {"gamma", "_Gamma_e#"}, \
+ {"gammaf", "_Gammaf_e#"}, \
+ {"gammal", "_Gammal_e#"}, \
+ {"gammaw", "_Gammaw_e#"}, \
+ {"ldexp", "_Ldexp_e#"}, \
+ {"ldexpf", "_Ldexpf_e#"}, \
+ {"ldexpl", "_Ldexpl_e#"}, \
+ {"ldexpw", "_Ldexpw_e#"}, \
+ {"lgamma", "_Lgamma_e#"}, \
+ {"lgammaf", "_Lgammaf_e#"}, \
+ {"lgammal", "_Lgammal_e#"}, \
+ {"lgammaw", "_Lgammaw_e#"}, \
+ {"log10", "_Log10_e#"}, \
+ {"log10f", "_Log10f_e#"}, \
+ {"log10l", "_Log10l_e#"}, \
+ {"log10w", "_Log10w_e#"}, \
+ {"log1p", "_Log1p_e#"}, \
+ {"log1pf", "_Log1pf_e#"}, \
+ {"log1pl", "_Log1pl_e#"}, \
+ {"log1pw", "_Log1pw_e#"}, \
+ {"log2", "_Log2_e#"}, \
+ {"log2f", "_Log2f_e#"}, \
+ {"log2l", "_Log2l_e#"}, \
+ {"log2w", "_Log2w_e#"}, \
+ {"log", "_Log_e#"}, \
+ {"logb", "_Logb_e#"}, \
+ {"logbf", "_Logbf_e#"}, \
+ {"logbl", "_Logbl_e#"}, \
+ {"logbw", "_Logbw_e#"}, \
+ {"logf", "_Logf_e#"}, \
+ {"logl", "_Logl_e#"}, \
+ {"logw", "_Logw_e#"}, \
+ {"nextafter", "_Nextafter_e#"}, \
+ {"nextafterf", "_Nextafterf_e#"}, \
+ {"nextafterl", "_Nextafterl_e#"}, \
+ {"nextafterw", "_Nextafterw_e#"}, \
+ {"pow", "_Pow_e#"}, \
+ {"powf", "_Powf_e#"}, \
+ {"powl", "_Powl_e#"}, \
+ {"poww", "_Poww_e#"}, \
+ {"remainder", "_Remainder_e#"}, \
+ {"remainderf", "_Remainderf_e#"}, \
+ {"remainderl", "_Remainderl_e#"}, \
+ {"remainderw", "_Remainderw_e#"}, \
+ {"scalb", "_Scalb_e#"}, \
+ {"scalbf", "_Scalbf_e#"}, \
+ {"scalbl", "_Scalbl_e#"}, \
+ {"scalbw", "_Scalbw_e#"}, \
+ {"sinh", "_Sinh_e#"}, \
+ {"sinhf", "_Sinhf_e#"}, \
+ {"sinhl", "_Sinhl_e#"}, \
+ {"sinhw", "_Sinhw_e#"}, \
+ {"sqrt", "_Sqrt_e#"}, \
+ {"sqrtf", "_Sqrtf_e#"}, \
+ {"sqrtl", "_Sqrtl_e#"}, \
+ {"sqrtw", "_Sqrtw_e#"}, \
+ {"tgamma", "_Tgamma_e#"}, \
+ {"tgammaf", "_Tgammaf_e#"}, \
+ {"tgammal", "_Tgammal_e#"}, \
+ {"tgammaw", "_Tgammaw_e#"}
*** gcc.orig/gcc/config/ia64/ia64-protos.h Tue Aug 20 15:10:15 2002
--- gcc/gcc/config/ia64/ia64-protos.h Wed Aug 21 16:17:18 2002
*************** extern void sbss_section PARAMS ((void))
*** 144,146 ****
--- 144,150 ----
/* expr.h defines ARGS_SIZE_RTX and `enum direction'. */
extern enum direction ia64_hpux_function_arg_padding PARAMS ((enum machine_mode, tree));
#endif /* ARGS_SIZE_RTX */
+
+ #ifdef GCC_C_PRAGMA_H
+ extern void ia64_hpux_handle_builtin_pragma PARAMS ((cpp_reader *));
+ #endif
*** gcc.orig/gcc/config/ia64/ia64.c Tue Aug 20 15:10:21 2002
--- gcc/gcc/config/ia64/ia64.c Tue Aug 27 10:43:13 2002
*************** Boston, MA 02111-1307, USA. */
*** 42,47 ****
--- 42,50 ----
#include "toplev.h"
#include "sched-int.h"
#include "timevar.h"
+ #include "cpplib.h"
+ #include "c-common.h"
+ #include "c-pragma.h"
#include "target.h"
#include "target-def.h"
#include "tm_p.h"
*************** static void ia64_aix_unique_section PARA
*** 171,176 ****
--- 174,180 ----
static void ia64_aix_select_rtx_section PARAMS ((enum machine_mode, rtx,
unsigned HOST_WIDE_INT))
ATTRIBUTE_UNUSED;
+ static void ia64_hpux_add_pragma_builtin PARAMS ((tree func));
/* Table of valid machine attributes. */
static const struct attribute_spec ia64_attribute_table[] =
*************** ia64_hpux_function_arg_padding (mode, ty
*** 8049,8054 ****
--- 8053,8112 ----
&& int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
: GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
? downward : upward);
+ }
+
+ void
+ ia64_hpux_handle_builtin_pragma (pfile)
+ cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+ /* #pragma builtin name, name, name */
+
+ enum cpp_ttype type;
+ tree x;
+
+ type = c_lex (&x);
+ while (type == CPP_NAME)
+ {
+ ia64_hpux_add_pragma_builtin (x);
+ type = c_lex (&x);
+ if (type == CPP_COMMA)
+ type = c_lex (&x);
+ }
+ if (type != CPP_EOF)
+ warning ("malformed #pragma builtin");
+ }
+
+ typedef struct c89_mathlib_names
+ {
+ const char *realname; /* User visible function name. */
+ const char *c89name; /* libm special name needed to set errno. */
+ } c89_mathlib_names;
+
+ static const c89_mathlib_names c89_mathlib_name_list [] =
+ {
+ #ifdef HPUX_C89_MATHLIB_NAME_LIST
+ HPUX_C89_MATHLIB_NAME_LIST
+ #endif
+ };
+
+ static void
+ ia64_hpux_add_pragma_builtin (func)
+ tree func;
+ {
+ int i;
+
+ if (!flag_isoc94 && flag_iso)
+ {
+ for (i = 0; i < ARRAY_SIZE (c89_mathlib_name_list); i++)
+ {
+ if (!strcmp(c89_mathlib_name_list[i].realname,
+ IDENTIFIER_POINTER (func)))
+ {
+ add_to_renaming_pragma_list(func,
+ get_identifier(c89_mathlib_name_list[i].c89name));
+ }
+ }
+ }
}
/* Switch to the section to which we should output X. The only thing