[PATCH][RFH] (3/3) Vectorize some builtins on x86_64 by using libgcc-math
Richard Guenther
rguenther@suse.de
Fri Nov 17 10:34:00 GMT 2006
On Thu, 16 Nov 2006, Paolo Bonzini wrote:
>
> > I need some help here in teaching the testsuite harness to add the
> > correct library path to libgcc-math.
>
> See libffi-init in libffi/testsuite/lib/libffi-dg.exp (I suggest these tests
> to be placed in libgcc-math/testsuite).
Ok, that seems to work (I copied stuff from libgomp instead).
So the testsuite part would look like the following. I guess we still
have to do something about -ftree-vectorize enabling linking with
libgcc-math though, as the gcc.dg/vect/ testsuite parts still cannot
find the library and so all link/run tests fail.
Any idea for that? Maybe require a completely different flag for
enabling libgcc-math linking?
Richard.
2006-11-17 Richard Guenther <rguenther@suse.de>
* Makefile.am: New file.
* lib/libgcc-math-dg.exp: New file.
* libgcc-math/c.exp: New file.
* libgcc-math/vect-fun-1.c: New testcase.
Index: testsuite/lib/libgcc-math-dg.exp
===================================================================
*** testsuite/lib/libgcc-math-dg.exp (revision 0)
--- testsuite/lib/libgcc-math-dg.exp (revision 0)
***************
*** 0 ****
--- 1,225 ----
+ # Damn dejagnu for not having proper library search paths for load_lib.
+ # We have to explicitly load everything that gcc-dg.exp wants to load.
+
+ proc load_gcc_lib { filename } {
+ global srcdir loaded_libs
+
+ load_file $srcdir/../../gcc/testsuite/lib/$filename
+ set loaded_libs($filename) ""
+ }
+
+ load_lib dg.exp
+ load_gcc_lib file-format.exp
+ load_gcc_lib target-supports.exp
+ load_gcc_lib target-supports-dg.exp
+ load_gcc_lib scanasm.exp
+ load_gcc_lib scandump.exp
+ load_gcc_lib scanrtl.exp
+ load_gcc_lib scantree.exp
+ load_gcc_lib scanipa.exp
+ load_gcc_lib prune.exp
+ load_gcc_lib target-libpath.exp
+ load_gcc_lib wrapper.exp
+ load_gcc_lib gcc-defs.exp
+ load_gcc_lib gcc-dg.exp
+ load_gcc_lib gfortran-dg.exp
+
+ set dg-do-what-default run
+
+ #
+ # GCC_UNDER_TEST is the compiler under test.
+ #
+
+ set libgcc_math_compile_options ""
+
+ #
+ # libgcc-math_init -- This gets run more than it should be....
+ #
+
+ if [info exists TOOL_OPTIONS] {
+ set multilibs [get_multilibs $TOOL_OPTIONS]
+ } else {
+ set multilibs [get_multilibs]
+ }
+
+ proc libgcc-math_init { args } {
+ global srcdir blddir objdir tool_root_dir
+ global libgcc_math_initialized
+ global tmpdir
+ global gluefile wrap_flags
+ global ALWAYS_CFLAGS
+ global CFLAGS
+ global TOOL_EXECUTABLE TOOL_OPTIONS
+ global GCC_UNDER_TEST
+ global TESTING_IN_BUILD_TREE
+ global target_triplet
+ global ld_library_path
+ global lang_test_file
+ global lang_library_path
+ global lang_link_flags
+
+ set blddir [lookfor_file [get_multilibs] libgcc-math]
+
+ # We set LC_ALL and LANG to C so that we get the same error
+ # messages as expected.
+ setenv LC_ALL C
+ setenv LANG C
+
+ if ![info exists GCC_UNDER_TEST] then {
+ if [info exists TOOL_EXECUTABLE] {
+ set GCC_UNDER_TEST $TOOL_EXECUTABLE
+ } else {
+ set GCC_UNDER_TEST "[find_gcc]"
+ }
+ }
+
+ if ![info exists tmpdir] {
+ set tmpdir "/tmp"
+ }
+
+ if [info exists gluefile] {
+ unset gluefile
+ }
+
+ if {![info exists CFLAGS]} {
+ set CFLAGS ""
+ }
+
+ # Locate libgcc.a so we don't need to account for different values of
+ # SHLIB_EXT on different platforms
+ set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
+ if {$gccdir != ""} {
+ set gccdir [file dirname $gccdir]
+ }
+
+ # Compute what needs to be put into LD_LIBRARY_PATH
+ set ld_library_path ".:${blddir}/.libs"
+
+ if { [info exists lang_test_file] && [file exists "${blddir}/"] } {
+ append ld_library_path ":${blddir}/${lang_library_path}"
+ }
+
+ # Compute what needs to be added to the existing LD_LIBRARY_PATH.
+ if {$gccdir != ""} {
+ append ld_library_path ":${gccdir}"
+ set compiler [lindex $GCC_UNDER_TEST 0]
+
+ if { [is_remote host] == 0 && [which $compiler] != 0 } {
+ foreach i "[exec $compiler --print-multi-lib]" {
+ set mldir ""
+ regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
+ set mldir [string trimright $mldir "\;@"]
+ if { "$mldir" == "." } {
+ continue
+ }
+ if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
+ append ld_library_path ":${gccdir}/${mldir}"
+ }
+ }
+ }
+ }
+ set_ld_library_path_env_vars
+
+ set ALWAYS_CFLAGS ""
+ lappend ALWAYS_CFLAGS "additional_flags=-B${blddir}/"
+ lappend ALWAYS_CFLAGS "additional_flags=-I${blddir}"
+ lappend ALWAYS_CFLAGS "additional_flags=-I${srcdir}/.."
+ lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/.libs -lgcc-math"
+ if { [info exists lang_test_file] && [file exists "${blddir}/"] } {
+ lappend ALWAYS_CFLAGS "ldflags=-L${blddir}/${lang_library_path} ${lang_link_flags}"
+ }
+
+ # We use atomic operations in the testcases to validate results.
+ if [istarget i?86-*-*] {
+ lappend ALWAYS_CFLAGS "additional_flags=-march=i486"
+ }
+ if [istarget sparc*-*-*] {
+ lappend ALWAYS_CFLAGS "additional_flags=-mcpu=v9"
+ }
+
+ if [info exists TOOL_OPTIONS] {
+ lappend ALWAYS_CFLAGS "additional_flags=$TOOL_OPTIONS"
+ }
+
+ # Make sure that lines are not wrapped. That can confuse the
+ # error-message parsing machinery.
+ lappend ALWAYS_CFLAGS "additional_flags=-fmessage-length=0"
+
+ # And, gee, turn on the vectorizer.
+ lappend ALWAYS_CFLAGS "additional_flags=-ftree-vectorize"
+ }
+
+ #
+ # libgcc-math_target_compile -- compile a source file
+ #
+
+ proc libgcc-math_target_compile { source dest type options } {
+ global tmpdir
+ global libgcc_math_compile_options
+ global gluefile wrap_flags
+ global ALWAYS_CFLAGS
+ global GCC_UNDER_TEST
+
+ libgcc-math_init
+
+ if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
+ lappend options "libs=${gluefile}"
+ lappend options "ldflags=${wrap_flags}"
+ }
+
+ lappend options "additional_flags=[libio_include_flags]"
+ lappend options "compiler=$GCC_UNDER_TEST"
+
+ set options [concat $libgcc_math_compile_options $options]
+
+ set options [concat "$ALWAYS_CFLAGS" $options]
+
+ set options [dg-additional-files-options $options $source]
+
+ set result [target_compile $source $dest $type $options]
+
+ return $result
+ }
+
+ # ??? The same as in standard.exp. Why doesn't anyone else have to
+ # define this?
+
+ proc libgcc-math_load { program args } {
+ if { [llength $args] > 0 } {
+ set program_args [lindex $args 0]
+ } else {
+ set program_args ""
+ }
+
+ if { [llength $args] > 1 } {
+ set input_file [lindex $args 1]
+ } else {
+ set input_file ""
+ }
+ return [remote_load target $program $program_args $input_file]
+ }
+
+ proc libgcc-math_option_help { } {
+ send_user " --additional_options,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
+ }
+
+ proc libgcc-math_option_proc { option } {
+ if [regexp "^--additional_options," $option] {
+ global libgcc_math_compile_options
+ regsub "--additional_options," $option "" option
+ foreach x [split $option ","] {
+ lappend libgcc_math_compile_options "additional_flags=$x"
+ }
+ return 1
+ } else {
+ return 0
+ }
+ }
+
+ proc libgcc-math-dg-test { prog do_what extra_tool_flags } {
+ return [gcc-dg-test-1 libgcc-math_target_compile $prog $do_what $extra_tool_flags]
+ }
+
+ proc libgcc-math-dg-prune { system text } {
+ return [gcc-dg-prune $system $text]
+ }
Index: testsuite/Makefile.am
===================================================================
*** testsuite/Makefile.am (revision 0)
--- testsuite/Makefile.am (revision 0)
***************
*** 0 ****
--- 1,13 ----
+ ## Process this file with automake to produce Makefile.in.
+
+ AUTOMAKE_OPTIONS = foreign dejagnu
+
+ # May be used by various substitution variables.
+ gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
+
+ EXPECT = $(shell if test -f $(top_builddir)/../expect/expect; then \
+ echo $(top_builddir)/../expect/expect; else echo expect; fi)
+
+ _RUNTEST = $(shell if test -f $(top_srcdir)/../dejagnu/runtest; then \
+ echo $(top_srcdir)/../dejagnu/runtest; else echo runtest; fi)
+ RUNTEST = "$(_RUNTEST) $(AM_RUNTESTFLAGS)"
Index: testsuite/libgcc-math/vect-fun-1.c
===================================================================
*** testsuite/libgcc-math/vect-fun-1.c (revision 0)
--- testsuite/libgcc-math/vect-fun-1.c (revision 0)
***************
*** 0 ****
--- 1,132 ----
+ /* { dg-do link { target x86_64-*-* } } */
+ /* { dg-options "-O1 -ffast-math -ftree-vectorize -fdump-tree-vect-details -std=c99" } */
+
+ #include <math.h>
+
+ double da[1000], db[1000];
+ float fa[1000], fb[1000], fc[1000];
+
+ void foo1(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = log (db[i]);
+ }
+
+ void foo2(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = log2 (db[i]);
+ }
+
+ void foo3(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = log10 (db[i]);
+ }
+
+ void foo4(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = exp (db[i]);
+ }
+
+ void foo5(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = sin (db[i]);
+ }
+
+ void foo6(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ da[i] = cos (db[i]);
+ }
+
+ void foo7(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = logf (fb[i]);
+ }
+
+ void foo8(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = log2f (fb[i]);
+ }
+
+ void foo9(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = log10f (fb[i]);
+ }
+
+ void foo10(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = expf (fb[i]);
+ }
+
+ void foo11(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = sinf (fb[i]);
+ }
+
+ void foo12(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = cosf (fb[i]);
+ }
+
+ void foo13(void)
+ {
+ unsigned i;
+ for (i = 0; i < 1000; i++)
+ fa[i] = powf (fb[i], fc[i]);
+ }
+
+ int main(void)
+ {
+ unsigned i;
+
+ for (i = 0; i < 1000; i++)
+ {
+ db[i] = 2;
+ fb[i] = 2;
+ fc[i] = 2;
+ }
+
+ for (i = 0; i < 100000; i++)
+ {
+ foo1();
+ foo2();
+ foo3();
+ foo4();
+ foo5();
+ foo6();
+ foo7();
+ foo8();
+ foo9();
+ foo10();
+ foo11();
+ foo12();
+ foo13();
+ }
+
+ return 0;
+ }
+
+ /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 14 "vect" { target x86_64-*-* } } } */
+ /* { dg-final { cleanup-tree-dump "vect" } } */
Index: testsuite/libgcc-math/c.exp
===================================================================
*** testsuite/libgcc-math/c.exp (revision 0)
--- testsuite/libgcc-math/c.exp (revision 0)
***************
*** 0 ****
--- 1,24 ----
+ if [info exists lang_library_path] then {
+ unset lang_library_path
+ unset lang_test_file
+ unset lang_link_flags
+ }
+
+ load_lib libgcc-math-dg.exp
+
+ # If a testcase doesn't have special options, use these.
+ if ![info exists DEFAULT_CFLAGS] then {
+ set DEFAULT_CFLAGS "-O2"
+ }
+
+ # Initialize dg.
+ dg-init
+
+ # Gather a list of all tests.
+ set tests [lsort [find $srcdir/$subdir *.c]]
+
+ # Main loop.
+ dg-runtest $tests "" $DEFAULT_CFLAGS
+
+ # All done.
+ dg-finish
More information about the Gcc-patches
mailing list