diff options
author | Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2009-05-29 21:27:54 +0000 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2009-05-29 23:27:54 +0200 |
commit | 0a05c536a636a6420ef3e00df0e3e7f6d4b9584e (patch) | |
tree | 15665f2df8a4d85574fbc4266b51a7743c5198fb /libgfortran | |
parent | 2017c37012b695fe8ab6604a2f7c415d964e7839 (diff) | |
download | gcc-0a05c536a636a6420ef3e00df0e3e7f6d4b9584e.zip gcc-0a05c536a636a6420ef3e00df0e3e7f6d4b9584e.tar.gz gcc-0a05c536a636a6420ef3e00df0e3e7f6d4b9584e.tar.bz2 |
re PR fortran/40019 (LEADZ and TRAILZ give wrong results)
2009-05-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/40019
* trans-types.c (gfc_build_uint_type): Make nonstatic.
* trans.h (gfor_fndecl_clz128, gfor_fndecl_ctz128): New
* prototypes.
* trans-types.h (gfc_build_uint_type): Add prototype.
* trans-decl.c (gfc_build_intrinsic_function_decls): Build
gfor_fndecl_clz128 and gfor_fndecl_ctz128.
* trans-intrinsic.c (gfc_conv_intrinsic_leadz,
gfc_conv_intrinsic_trailz): Call the right builtins or library
functions, and cast arguments to unsigned types first.
* simplify.c (gfc_simplify_leadz): Deal with negative arguments.
2009-05-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/40019
* intrinsics/bit_intrinsics.c: New file.
* gfortran.map (GFORTRAN_1.2): New list.
* Makefile.am: Add intrinsics/bit_intrinsics.c.
* Makefile.in: Regenerate.
2009-05-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/40019
* gfortran.dg/leadz_trailz_1.f90: New test.
* gfortran.dg/leadz_trailz_2.f90: New test.
From-SVN: r147987
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 8 | ||||
-rw-r--r-- | libgfortran/Makefile.am | 1 | ||||
-rw-r--r-- | libgfortran/Makefile.in | 21 | ||||
-rw-r--r-- | libgfortran/gfortran.map | 7 | ||||
-rw-r--r-- | libgfortran/intrinsics/bit_intrinsics.c | 138 |
5 files changed, 169 insertions, 6 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 7519578..2d27d03 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2009-05-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> + + PR fortran/40019 + * intrinsics/bit_intrinsics.c: New file. + * gfortran.map (GFORTRAN_1.2): New list. + * Makefile.am: Add intrinsics/bit_intrinsics.c. + * Makefile.in: Regenerate. + 2009-05-29 Janne Blomqvist <jb@gcc.gnu.org> PR libfortran/40190 diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index ce73ff2..f5f92df 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -62,6 +62,7 @@ intrinsics/associated.c \ intrinsics/abort.c \ intrinsics/access.c \ intrinsics/args.c \ +intrinsics/bit_intrinsics.c \ intrinsics/c99_functions.c \ intrinsics/chdir.c \ intrinsics/chmod.c \ diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 8d356d5..ce2b5a2 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -416,9 +416,9 @@ am__libgfortran_la_SOURCES_DIST = runtime/backtrace.c \ io/size_from_kind.c io/transfer.c io/unit.c io/unix.c \ io/write.c io/fbuf.c intrinsics/associated.c \ intrinsics/abort.c intrinsics/access.c intrinsics/args.c \ - intrinsics/c99_functions.c intrinsics/chdir.c \ - intrinsics/chmod.c intrinsics/clock.c intrinsics/cpu_time.c \ - intrinsics/cshift0.c intrinsics/ctime.c \ + intrinsics/bit_intrinsics.c intrinsics/c99_functions.c \ + intrinsics/chdir.c intrinsics/chmod.c intrinsics/clock.c \ + intrinsics/cpu_time.c intrinsics/cshift0.c intrinsics/ctime.c \ intrinsics/date_and_time.c intrinsics/dtime.c intrinsics/env.c \ intrinsics/eoshift0.c intrinsics/eoshift2.c \ intrinsics/erfc_scaled.c intrinsics/etime.c intrinsics/exit.c \ @@ -711,9 +711,9 @@ am__objects_35 = close.lo file_pos.lo format.lo inquire.lo \ intrinsics.lo list_read.lo lock.lo open.lo read.lo \ size_from_kind.lo transfer.lo unit.lo unix.lo write.lo fbuf.lo am__objects_36 = associated.lo abort.lo access.lo args.lo \ - c99_functions.lo chdir.lo chmod.lo clock.lo cpu_time.lo \ - cshift0.lo ctime.lo date_and_time.lo dtime.lo env.lo \ - eoshift0.lo eoshift2.lo erfc_scaled.lo etime.lo exit.lo \ + bit_intrinsics.lo c99_functions.lo chdir.lo chmod.lo clock.lo \ + cpu_time.lo cshift0.lo ctime.lo date_and_time.lo dtime.lo \ + env.lo eoshift0.lo eoshift2.lo erfc_scaled.lo etime.lo exit.lo \ fnum.lo gerror.lo getcwd.lo getlog.lo getXid.lo hostnm.lo \ ierrno.lo ishftc.lo iso_c_generated_procs.lo iso_c_binding.lo \ kill.lo link.lo malloc.lo mvbits.lo move_alloc.lo \ @@ -990,6 +990,7 @@ intrinsics/associated.c \ intrinsics/abort.c \ intrinsics/access.c \ intrinsics/args.c \ +intrinsics/bit_intrinsics.c \ intrinsics/c99_functions.c \ intrinsics/chdir.c \ intrinsics/chmod.c \ @@ -1804,6 +1805,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/args.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/associated.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/backtrace.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bit_intrinsics.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c99_functions.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chdir.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chmod.Plo@am__quote@ @@ -5322,6 +5324,13 @@ args.lo: intrinsics/args.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o args.lo `test -f 'intrinsics/args.c' || echo '$(srcdir)/'`intrinsics/args.c +bit_intrinsics.lo: intrinsics/bit_intrinsics.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT bit_intrinsics.lo -MD -MP -MF "$(DEPDIR)/bit_intrinsics.Tpo" -c -o bit_intrinsics.lo `test -f 'intrinsics/bit_intrinsics.c' || echo '$(srcdir)/'`intrinsics/bit_intrinsics.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/bit_intrinsics.Tpo" "$(DEPDIR)/bit_intrinsics.Plo"; else rm -f "$(DEPDIR)/bit_intrinsics.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='intrinsics/bit_intrinsics.c' object='bit_intrinsics.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o bit_intrinsics.lo `test -f 'intrinsics/bit_intrinsics.c' || echo '$(srcdir)/'`intrinsics/bit_intrinsics.c + c99_functions.lo: intrinsics/c99_functions.c @am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT c99_functions.lo -MD -MP -MF "$(DEPDIR)/c99_functions.Tpo" -c -o c99_functions.lo `test -f 'intrinsics/c99_functions.c' || echo '$(srcdir)/'`intrinsics/c99_functions.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/c99_functions.Tpo" "$(DEPDIR)/c99_functions.Plo"; else rm -f "$(DEPDIR)/c99_functions.Tpo"; exit 1; fi diff --git a/libgfortran/gfortran.map b/libgfortran/gfortran.map index 93973d5..c8de09c 100644 --- a/libgfortran/gfortran.map +++ b/libgfortran/gfortran.map @@ -1090,6 +1090,13 @@ GFORTRAN_1.1 { _gfortran_unpack1_char4; } GFORTRAN_1.0; + +GFORTRAN_1.2 { + global: + _gfortran_clz128; + _gfortran_ctz128; +} GFORTRAN_1.1; + F2C_1.0 { global: _gfortran_f2c_specific__abs_c4; diff --git a/libgfortran/intrinsics/bit_intrinsics.c b/libgfortran/intrinsics/bit_intrinsics.c new file mode 100644 index 0000000..92f5f03 --- /dev/null +++ b/libgfortran/intrinsics/bit_intrinsics.c @@ -0,0 +1,138 @@ +/* Implementation of the bit intrinsics not implemented as GCC builtins. + Copyright (C) 2009 Free Software Foundation, Inc. + +This file is part of the GNU Fortran runtime library (libgfortran). + +Libgfortran is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public +License as published by the Free Software Foundation; either +version 3 of the License, or (at your option) any later version. + +Libgfortran 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 General Public License for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +#include "libgfortran.h" + + +#ifdef HAVE_GFC_INTEGER_16 +extern int clz128 (GFC_INTEGER_16); +export_proto(clz128); + +int +clz128 (GFC_INTEGER_16 x) +{ + int res = 127; + + // We can't write 0xFFFFFFFFFFFFFFFF0000000000000000, so we work around it + if (x & ((__uint128_t) 0xFFFFFFFFFFFFFFFF << 64)) + { + res -= 64; + x >>= 64; + } + + if (x & 0xFFFFFFFF00000000) + { + res -= 32; + x >>= 32; + } + + if (x & 0xFFFF0000) + { + res -= 16; + x >>= 16; + } + + if (x & 0xFF00) + { + res -= 8; + x >>= 8; + } + + if (x & 0xF0) + { + res -= 4; + x >>= 4; + } + + if (x & 0xC) + { + res -= 2; + x >>= 2; + } + + if (x & 0x2) + { + res -= 1; + x >>= 1; + } + + return res; +} +#endif + + +#ifdef HAVE_GFC_INTEGER_16 +extern int ctz128 (GFC_INTEGER_16); +export_proto(ctz128); + +int +ctz128 (GFC_INTEGER_16 x) +{ + int res = 0; + + if ((x & 0xFFFFFFFFFFFFFFFF) == 0) + { + res += 64; + x >>= 64; + } + + if ((x & 0xFFFFFFFF) == 0) + { + res += 32; + x >>= 32; + } + + if ((x & 0xFFFF) == 0) + { + res += 16; + x >>= 16; + } + + if ((x & 0xFF) == 0) + { + res += 8; + x >>= 8; + } + + if ((x & 0xF) == 0) + { + res += 4; + x >>= 4; + } + + if ((x & 0x3) == 0) + { + res += 2; + x >>= 2; + } + + if ((x & 0x1) == 0) + { + res += 1; + x >>= 1; + } + + return res; +} +#endif |