1ec601bf9f
/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 * Makefile.def: Add libquadmath; build it with language=fortran. * configure.ac: Add libquadmath. * Makefile.tpl: Handle multiple libs in check-[+language+]. * Makefile.in: Regenerate. * configure: Regenerate. libquadmath/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 Initial implementation and checkin. gcc/fortran/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 * gfortranspec.c (find_spec_file): New function. (lang_specific_driver): Try to find .spec file and use it. * trans-io.c (iocall): Define * IOCALL_X_REAL128/COMPLEX128(,write). (gfc_build_io_library_fndecls): Build decl for __float128 I/O. (transfer_expr): Call __float128 I/O functions. * trans-types.c (gfc_init_kinds): Allow kind-16 belonging to __float128. gcc/testsuite/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 * gfortran.dg/quad_1.f90: New. * lib/gcc-defs.exp (gcc-set-multilib-library-path): Use also compiler arguments. * lib/gfortran.exp (gfortran_link_flags): Add libquadmath to library search path; call gcc-set-multilib-library-path with arguments such that libgfortran.spec is found. (gfortran_init): Add path for libgfortran.spec to GFORTRAN_UNDER_TEST. libgomp/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 * configure.ac: * configure: Regenerate. libgfortran/ 2010-11-13 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> Tobias Burnus <burnus@net-b.de> PR fortran/32049 * Makefile.am: Add missing pow_r16_i4.c, add transfer128.c, link libquadmath, if used. * acinclude.m4 (LIBGFOR_CHECK_FLOAT128): Add. * configure.ac: Use it, touch spec file. * gfortran.map: Add pow_r16_i4 and transfer_(real,complex)128(,write) functions. * intrinsics/cshift0.c (cshift0): Handle __float128 type. * intrinsics/erfc_scaled_inc.c: Ditto. * intrinsics/pack_generic.c (pack): Ditto * intrinsics/spread_generic.c (spread): Ditto. * intrinsics/unpack_generic.c (unpack1): Ditto. * io/read.c (convert_real): Ditto. * io/transfer.c: Update comments. * io/transfer128.c: New file. * io/write_float.def (write_float): Handle __float128 type. * libgfortran.h: #include quadmath_weak.h, define __builtin_infq and nanq. * m4/mtype.m4: Handle __float128 type. * runtime/in_pack_generic.c (internal_pack): Ditto. * runtime/in_unpack_generic.c (internal_unpack): Ditto. * kinds-override.h: New file. * libgfortran.spec.in: Ditto. * generated/pow_r16_i4.c: Generated. * Makefile.in: Regenerate. * configure: Regenerate. * config.h: Regenerate. * bessel_r10.c: Regenerate. * bessel_r16.c: Regenerate. * bessel_r4.c: Regenerate. * bessel_r8.c: Regenerate. * exponent_r16.c: Regenerate. * fraction_r16.c: Regenerate. * nearest_r16.c: Regenerate. * norm2_r10.c: Regenerate. * norm2_r16.c: Regenerate. * norm2_r4.c: Regenerate. * norm2_r8.c: Regenerate. * rrspacing_r16.c: Regenerate. * set_exponent_r16.c: Regenerate. * spacing_r16.c: Regenerate. Co-Authored-By: Tobias Burnus <burnus@net-b.de> From-SVN: r166825
213 lines
5.2 KiB
C
213 lines
5.2 KiB
C
/* Implementation of the NORM2 intrinsic
|
|
Copyright 2010 Free Software Foundation, Inc.
|
|
Contributed by Tobias Burnus <burnus@net-b.de>
|
|
|
|
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"
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#if defined (HAVE_GFC_REAL_10) && defined (HAVE_GFC_REAL_10) && defined (HAVE_SQRTL) && defined (HAVE_FABSL)
|
|
|
|
#define MATHFUNC(funcname) funcname ## l
|
|
#define BUILTINMATHFUNC(funcname) MATHFUNC(funcname)
|
|
|
|
|
|
extern void norm2_r10 (gfc_array_r10 * const restrict,
|
|
gfc_array_r10 * const restrict, const index_type * const restrict);
|
|
export_proto(norm2_r10);
|
|
|
|
void
|
|
norm2_r10 (gfc_array_r10 * const restrict retarray,
|
|
gfc_array_r10 * const restrict array,
|
|
const index_type * const restrict pdim)
|
|
{
|
|
index_type count[GFC_MAX_DIMENSIONS];
|
|
index_type extent[GFC_MAX_DIMENSIONS];
|
|
index_type sstride[GFC_MAX_DIMENSIONS];
|
|
index_type dstride[GFC_MAX_DIMENSIONS];
|
|
const GFC_REAL_10 * restrict base;
|
|
GFC_REAL_10 * restrict dest;
|
|
index_type rank;
|
|
index_type n;
|
|
index_type len;
|
|
index_type delta;
|
|
index_type dim;
|
|
int continue_loop;
|
|
|
|
/* Make dim zero based to avoid confusion. */
|
|
dim = (*pdim) - 1;
|
|
rank = GFC_DESCRIPTOR_RANK (array) - 1;
|
|
|
|
len = GFC_DESCRIPTOR_EXTENT(array,dim);
|
|
if (len < 0)
|
|
len = 0;
|
|
delta = GFC_DESCRIPTOR_STRIDE(array,dim);
|
|
|
|
for (n = 0; n < dim; n++)
|
|
{
|
|
sstride[n] = GFC_DESCRIPTOR_STRIDE(array,n);
|
|
extent[n] = GFC_DESCRIPTOR_EXTENT(array,n);
|
|
|
|
if (extent[n] < 0)
|
|
extent[n] = 0;
|
|
}
|
|
for (n = dim; n < rank; n++)
|
|
{
|
|
sstride[n] = GFC_DESCRIPTOR_STRIDE(array, n + 1);
|
|
extent[n] = GFC_DESCRIPTOR_EXTENT(array, n + 1);
|
|
|
|
if (extent[n] < 0)
|
|
extent[n] = 0;
|
|
}
|
|
|
|
if (retarray->data == NULL)
|
|
{
|
|
size_t alloc_size, str;
|
|
|
|
for (n = 0; n < rank; n++)
|
|
{
|
|
if (n == 0)
|
|
str = 1;
|
|
else
|
|
str = GFC_DESCRIPTOR_STRIDE(retarray,n-1) * extent[n-1];
|
|
|
|
GFC_DIMENSION_SET(retarray->dim[n], 0, extent[n] - 1, str);
|
|
|
|
}
|
|
|
|
retarray->offset = 0;
|
|
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
|
|
|
|
alloc_size = sizeof (GFC_REAL_10) * GFC_DESCRIPTOR_STRIDE(retarray,rank-1)
|
|
* extent[rank-1];
|
|
|
|
if (alloc_size == 0)
|
|
{
|
|
/* Make sure we have a zero-sized array. */
|
|
GFC_DIMENSION_SET(retarray->dim[0], 0, -1, 1);
|
|
return;
|
|
|
|
}
|
|
else
|
|
retarray->data = internal_malloc_size (alloc_size);
|
|
}
|
|
else
|
|
{
|
|
if (rank != GFC_DESCRIPTOR_RANK (retarray))
|
|
runtime_error ("rank of return array incorrect in"
|
|
" NORM intrinsic: is %ld, should be %ld",
|
|
(long int) (GFC_DESCRIPTOR_RANK (retarray)),
|
|
(long int) rank);
|
|
|
|
if (unlikely (compile_options.bounds_check))
|
|
bounds_ifunction_return ((array_t *) retarray, extent,
|
|
"return value", "NORM");
|
|
}
|
|
|
|
for (n = 0; n < rank; n++)
|
|
{
|
|
count[n] = 0;
|
|
dstride[n] = GFC_DESCRIPTOR_STRIDE(retarray,n);
|
|
if (extent[n] <= 0)
|
|
len = 0;
|
|
}
|
|
|
|
base = array->data;
|
|
dest = retarray->data;
|
|
|
|
continue_loop = 1;
|
|
while (continue_loop)
|
|
{
|
|
const GFC_REAL_10 * restrict src;
|
|
GFC_REAL_10 result;
|
|
src = base;
|
|
{
|
|
|
|
GFC_REAL_10 scale;
|
|
result = 0;
|
|
scale = 1;
|
|
if (len <= 0)
|
|
*dest = 0;
|
|
else
|
|
{
|
|
for (n = 0; n < len; n++, src += delta)
|
|
{
|
|
|
|
if (*src != 0)
|
|
{
|
|
GFC_REAL_10 absX, val;
|
|
absX = MATHFUNC(fabs) (*src);
|
|
if (scale < absX)
|
|
{
|
|
val = scale / absX;
|
|
result = 1 + result * val * val;
|
|
scale = absX;
|
|
}
|
|
else
|
|
{
|
|
val = absX / scale;
|
|
result += val * val;
|
|
}
|
|
}
|
|
}
|
|
result = scale * MATHFUNC(sqrt) (result);
|
|
*dest = result;
|
|
}
|
|
}
|
|
/* Advance to the next element. */
|
|
count[0]++;
|
|
base += sstride[0];
|
|
dest += dstride[0];
|
|
n = 0;
|
|
while (count[n] == extent[n])
|
|
{
|
|
/* When we get to the end of a dimension, reset it and increment
|
|
the next dimension. */
|
|
count[n] = 0;
|
|
/* We could precalculate these products, but this is a less
|
|
frequently used path so probably not worth it. */
|
|
base -= sstride[n] * extent[n];
|
|
dest -= dstride[n] * extent[n];
|
|
n++;
|
|
if (n == rank)
|
|
{
|
|
/* Break out of the look. */
|
|
continue_loop = 0;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
count[n]++;
|
|
base += sstride[n];
|
|
dest += dstride[n];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|