Projects
openEuler:24.03:SP1:Everything:64G
gcc
_service:tar_scm:0020-simdmath-Enable-simdmath-...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:tar_scm:0020-simdmath-Enable-simdmath-on-kunpeng.patch of Package gcc
From 49ad10199dbdda2c36850a2617f5c985977939c5 Mon Sep 17 00:00:00 2001 From: bule <bule1@huawei.com> Date: Sun, 27 Aug 2023 16:49:42 +0800 Subject: [PATCH 20/22] [simdmath] Enable simdmath on kunpeng This enable simd math function supported by libmathlib on fortran/c/c++. Use -fsimdmath to turn on the generation of simdmath function. The supported functions can be found in simdmath.h. Add more simd declaration if you need more kinds of math functions. -msimdmath-64 is used to turn on 64-bit simd math functions which is not supported by libmathlib. Therefore, this option is default to off. --- gcc/c-family/c-opts.cc | 4 ++ gcc/common.opt | 4 ++ gcc/config/aarch64/aarch64.cc | 9 ++++- gcc/config/aarch64/aarch64.opt | 6 +++ gcc/fortran/scanner.cc | 3 ++ gcc/opts.cc | 17 ++++++++ .../gcc.target/aarch64/simd_pcs_attribute-3.c | 2 +- libgomp/Makefile.am | 4 +- libgomp/Makefile.in | 10 +++-- libgomp/configure | 4 +- libgomp/configure.ac | 2 +- libgomp/simdmath.h.in | 40 +++++++++++++++++++ libgomp/simdmath_f.h.in | 11 +++++ 13 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 libgomp/simdmath.h.in create mode 100644 libgomp/simdmath_f.h.in diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index a341a0617..5134f6128 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -801,6 +801,10 @@ c_common_post_options (const char **pfilename) if (cpp_opts->deps.style == DEPS_NONE) check_deps_environment_vars (); + if (flag_simdmath) + { + defer_opt (OPT_include, "simdmath.h"); + } handle_deferred_opts (); sanitize_cpp_opts (); diff --git a/gcc/common.opt b/gcc/common.opt index f5eef8a45..e9d580957 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2125,6 +2125,10 @@ fmath-errno Common Var(flag_errno_math) Init(1) Optimization SetByCombined Set errno after built-in math functions. +fsimdmath +Common Var(flag_simdmath) Init(0) Optimization +Enable auto-vectorize math functions for mathlib. This option will turn on -fno-math-errno and -fopenmp-simd. + fmax-errors= Common Joined RejectNegative UInteger Var(flag_max_errors) -fmax-errors=<number> Maximum number of errors to report. diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 226dc9dff..a3da4ca30 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -26904,8 +26904,13 @@ aarch64_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node, elt_bits = GET_MODE_BITSIZE (SCALAR_TYPE_MODE (base_type)); if (known_eq (clonei->simdlen, 0U)) { - count = 2; - vec_bits = (num == 0 ? 64 : 128); + /* Currently mathlib or sleef hasn't provide function for V2SF mode + simdclone of single precision functions. (e.g._ZCVnN2v_expf) + Therefore this mode is disabled by default to avoid link error. + Use -msimdmath-64 option to enable this mode. */ + count = flag_simdmath_64 ? 2 : 1; + vec_bits = ((num == 0 && flag_simdmath_64) ? 64 : 128); + clonei->simdlen = exact_div (vec_bits, elt_bits); } else diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index 92220b26e..a64b927e9 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -190,6 +190,12 @@ precision of square root results to about 16 bits for single precision and to 32 bits for double precision. If enabled, it implies -mlow-precision-recip-sqrt. +msimdmath-64 +Target Var(flag_simdmath_64) Optimization +Allow compiler to generate V2SF 64 bits simdclone of math functions, +which is not currently supported in mathlib or sleef. +Therefore this option is disabled by default. + mlow-precision-div Target Var(flag_mlow_precision_div) Optimization Enable the division approximation. Enabling this reduces diff --git a/gcc/fortran/scanner.cc b/gcc/fortran/scanner.cc index 2dff25147..63e262f51 100644 --- a/gcc/fortran/scanner.cc +++ b/gcc/fortran/scanner.cc @@ -2769,6 +2769,9 @@ gfc_new_file (void) if (flag_pre_include != NULL) load_file (flag_pre_include, NULL, false); + if (flag_simdmath) + load_file ("simdmath_f.h", NULL, false); + if (gfc_cpp_enabled ()) { gfc_cpp_preprocess (gfc_source_file); diff --git a/gcc/opts.cc b/gcc/opts.cc index b522ed7e2..c3cc2c169 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -322,6 +322,7 @@ static const char undocumented_msg[] = N_("This option lacks documentation."); static const char use_diagnosed_msg[] = N_("Uses of this option are diagnosed."); typedef char *char_p; /* For DEF_VEC_P. */ +static void set_simdmath_flags (struct gcc_options *opts, int set); static void set_debug_level (uint32_t dinfo, int extended, const char *arg, struct gcc_options *opts, @@ -2850,6 +2851,10 @@ common_handle_option (struct gcc_options *opts, dc->min_margin_width = value; break; + case OPT_fsimdmath: + set_simdmath_flags (opts, value); + break; + case OPT_fdump_: /* Deferred. */ break; @@ -3227,6 +3232,18 @@ common_handle_option (struct gcc_options *opts, return true; } +/* The following routines are used to set -fno-math-errno and -fopenmp-simd + to enable vector mathlib. */ +static void +set_simdmath_flags (struct gcc_options *opts, int set) +{ + if (set) + { + opts->x_flag_errno_math = 0; + opts->x_flag_openmp_simd = 1; + } +} + /* Used to set the level of strict aliasing warnings in OPTS, when no level is specified (i.e., when -Wstrict-aliasing, and not -Wstrict-aliasing=level was given). diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c index 95f6a6803..e0e0efa9d 100644 --- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c +++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Ofast" } */ +/* { dg-options "-Ofast -msimdmath-64" } */ __attribute__ ((__simd__)) __attribute__ ((__nothrow__ , __leaf__ , __const__)) diff --git a/libgomp/Makefile.am b/libgomp/Makefile.am index f8b2a06d6..8dfa160d6 100644 --- a/libgomp/Makefile.am +++ b/libgomp/Makefile.am @@ -75,10 +75,10 @@ libgomp_la_SOURCES += openacc.f90 endif nodist_noinst_HEADERS = libgomp_f.h -nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h +nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h simdmath.h if USE_FORTRAN nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \ - openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod + openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod simdmath_f.h endif LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in index 6f0cb7161..90fc326f0 100644 --- a/libgomp/Makefile.in +++ b/libgomp/Makefile.in @@ -147,7 +147,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs CONFIG_HEADER = config.h -CONFIG_CLEAN_FILES = omp.h omp_lib.h omp_lib.f90 libgomp_f.h \ +CONFIG_CLEAN_FILES = omp.h omp_lib.h simdmath.h simdmath_f.h omp_lib.f90 libgomp_f.h \ libgomp.spec CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; @@ -583,9 +583,9 @@ libgomp_la_SOURCES = alloc.c atomic.c barrier.c critical.c env.c \ @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBADD = libgomp.la $(PLUGIN_GCN_LIBS) @PLUGIN_GCN_TRUE@libgomp_plugin_gcn_la_LIBTOOLFLAGS = --tag=disable-static nodist_noinst_HEADERS = libgomp_f.h -nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h +nodist_libsubinclude_HEADERS = omp.h openacc.h acc_prof.h simdmath.h @USE_FORTRAN_TRUE@nodist_finclude_HEADERS = omp_lib.h omp_lib.f90 omp_lib.mod omp_lib_kinds.mod \ -@USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod +@USE_FORTRAN_TRUE@ openacc_lib.h openacc.f90 openacc.mod openacc_kinds.mod simdmath_f.h LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) LINK = $(LIBTOOL) --tag CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link \ @@ -676,6 +676,10 @@ omp.h: $(top_builddir)/config.status $(srcdir)/omp.h.in cd $(top_builddir) && $(SHELL) ./config.status $@ omp_lib.h: $(top_builddir)/config.status $(srcdir)/omp_lib.h.in cd $(top_builddir) && $(SHELL) ./config.status $@ +simdmath_f.h: $(top_builddir)/config.status $(srcdir)/simdmath_f.h.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +simdmath.h: $(top_builddir)/config.status $(srcdir)/simdmath.h.in + cd $(top_builddir) && $(SHELL) ./config.status $@ omp_lib.f90: $(top_builddir)/config.status $(srcdir)/omp_lib.f90.in cd $(top_builddir) && $(SHELL) ./config.status $@ libgomp_f.h: $(top_builddir)/config.status $(srcdir)/libgomp_f.h.in diff --git a/libgomp/configure b/libgomp/configure index 85fdb4d3f..471c957b7 100755 --- a/libgomp/configure +++ b/libgomp/configure @@ -17064,7 +17064,7 @@ fi -ac_config_files="$ac_config_files omp.h omp_lib.h omp_lib.f90 libgomp_f.h" +ac_config_files="$ac_config_files omp.h omp_lib.h simdmath.h simdmath_f.h omp_lib.f90 libgomp_f.h" ac_config_files="$ac_config_files Makefile testsuite/Makefile libgomp.spec" @@ -18215,6 +18215,8 @@ do "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "omp.h") CONFIG_FILES="$CONFIG_FILES omp.h" ;; "omp_lib.h") CONFIG_FILES="$CONFIG_FILES omp_lib.h" ;; + "simdmath.h") CONFIG_FILES="$CONFIG_FILES simdmath.h" ;; + "simdmath_f.h") CONFIG_FILES="$CONFIG_FILES simdmath_f.h" ;; "omp_lib.f90") CONFIG_FILES="$CONFIG_FILES omp_lib.f90" ;; "libgomp_f.h") CONFIG_FILES="$CONFIG_FILES libgomp_f.h" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; diff --git a/libgomp/configure.ac b/libgomp/configure.ac index a9b1f3973..1f81a0d30 100644 --- a/libgomp/configure.ac +++ b/libgomp/configure.ac @@ -472,7 +472,7 @@ CFLAGS="$save_CFLAGS" # Determine what GCC version number to use in filesystem paths. GCC_BASE_VER -AC_CONFIG_FILES(omp.h omp_lib.h omp_lib.f90 libgomp_f.h) +AC_CONFIG_FILES(omp.h omp_lib.h simdmath.h simdmath_f.h omp_lib.f90 libgomp_f.h) AC_CONFIG_FILES(Makefile testsuite/Makefile libgomp.spec) AC_CONFIG_FILES([testsuite/libgomp-test-support.pt.exp:testsuite/libgomp-test-support.exp.in]) AC_CONFIG_FILES([testsuite/libgomp-site-extra.exp]) diff --git a/libgomp/simdmath.h.in b/libgomp/simdmath.h.in new file mode 100644 index 000000000..ab91a4ec3 --- /dev/null +++ b/libgomp/simdmath.h.in @@ -0,0 +1,40 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#pragma omp declare simd simdlen(2) notinbranch +double cos (double x); + +#pragma omp declare simd simdlen(4) notinbranch +float cosf (float x); + +#pragma omp declare simd simdlen(2) notinbranch +double sin (double x); + +#pragma omp declare simd simdlen(4) notinbranch +float sinf (float x); + +#pragma omp declare simd simdlen(2) notinbranch +double exp (double x); + +#pragma omp declare simd simdlen(4) notinbranch +float expf (float x); + +#pragma omp declare simd simdlen(2) notinbranch +double log (double x); + +#pragma omp declare simd simdlen(4) notinbranch +float logf (float x); + +#pragma omp declare simd simdlen(2) notinbranch +double pow (double x, double y); + +#pragma omp declare simd simdlen(4) notinbranch +float powf (float x, float y); + +#pragma omp declare simd simdlen(4) notinbranch +float exp2f (float x); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/libgomp/simdmath_f.h.in b/libgomp/simdmath_f.h.in new file mode 100644 index 000000000..550595015 --- /dev/null +++ b/libgomp/simdmath_f.h.in @@ -0,0 +1,11 @@ +!GCC$ builtin (cos) attributes simd (notinbranch) +!GCC$ builtin (cosf) attributes simd (notinbranch) +!GCC$ builtin (sin) attributes simd (notinbranch) +!GCC$ builtin (sinf) attributes simd (notinbranch) +!GCC$ builtin (exp) attributes simd (notinbranch) +!GCC$ builtin (expf) attributes simd (notinbranch) +!GCC$ builtin (exp2f) attributes simd (notinbranch) +!GCC$ builtin (log) attributes simd (notinbranch) +!GCC$ builtin (logf) attributes simd (notinbranch) +!GCC$ builtin (pow) attributes simd (notinbranch) +!GCC$ builtin (powf) attributes simd (notinbranch) -- 2.33.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2