[Patch, libgfortran] Add const restrict to intrinsic functions
Janne Blomqvist
jblomqvi@cc.hut.fi
Sat Nov 26 12:58:00 GMT 2005
Hi,
the attached patch adds const restrict to the arguments for the
intrinsic functions in the m4/ directory.
This is in line with Fortran argument passing, and might provide some
further optimization, such as vectorizing.
--
Janne Blomqvist
-------------- next part --------------
libgfortran ChangeLog:
2005-11-26 Janne Blomqvist <jb@gcc.gnu.org>
* m4/*: Add const restrict to function arguments.
* generated/*: Regenerate.
-------------- next part --------------
Index: m4/transpose.m4
===================================================================
--- m4/transpose.m4 (revision 107541)
+++ m4/transpose.m4 (working copy)
@@ -35,11 +35,13 @@ include(iparm.m4)dnl
`#if defined (HAVE_'rtype_name`)'
-extern void transpose_`'rtype_code (rtype * ret, rtype * source);
+extern void transpose_`'rtype_code (rtype * const restrict ret,
+ rtype * const restrict source);
export_proto(transpose_`'rtype_code);
void
-transpose_`'rtype_code (rtype * ret, rtype * source)
+transpose_`'rtype_code (rtype * const restrict ret,
+ rtype * const restrict source)
{
/* r.* indicates the return array. */
index_type rxstride, rystride;
Index: m4/iforeach.m4
===================================================================
--- m4/iforeach.m4 (revision 107541)
+++ m4/iforeach.m4 (working copy)
@@ -4,17 +4,19 @@ dnl This file is part of the GNU Fortran
dnl Distributed under the GNU GPL with exception. See COPYING for details.
define(START_FOREACH_FUNCTION,
`
-extern void name`'rtype_qual`_'atype_code (rtype * retarray, atype *array);
+extern void name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
+ atype * const restrict array);
export_proto(name`'rtype_qual`_'atype_code);
void
-name`'rtype_qual`_'atype_code (rtype * retarray, atype *array)
+name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
+ atype * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
- atype_name *base;
+ const atype_name *base;
rtype_name *dest;
index_type rank;
index_type n;
@@ -111,12 +113,14 @@ define(FINISH_FOREACH_FUNCTION,
}')dnl
define(START_MASKED_FOREACH_FUNCTION,
`
-extern void `m'name`'rtype_qual`_'atype_code (rtype *, atype *, gfc_array_l4 *);
+extern void `m'name`'rtype_qual`_'atype_code (rtype * const restrict,
+ atype * const restrict, gfc_array_l4 * const restrict);
export_proto(`m'name`'rtype_qual`_'atype_code);
void
-`m'name`'rtype_qual`_'atype_code (rtype * retarray, atype *array,
- gfc_array_l4 * mask)
+`m'name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
+ atype * const restrict array,
+ gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
@@ -124,7 +128,7 @@ void
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
rtype_name *dest;
- atype_name *base;
+ const atype_name *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
Index: m4/eoshift1.m4
===================================================================
--- m4/eoshift1.m4 (revision 107541)
+++ m4/eoshift1.m4 (working copy)
@@ -38,9 +38,12 @@ include(iparm.m4)dnl
`#if defined (HAVE_'atype_name`)'
static void
-eoshift1 (gfc_array_char *ret, const gfc_array_char *array, const atype *h,
- const char *pbound, const atype_name *pwhich, index_type size,
- char filler)
+eoshift1 (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const char * const restrict pbound,
+ const atype_name * const restrict pwhich,
+ index_type size, char filler)
{
/* r.* indicates the return array. */
index_type rstride[GFC_MAX_DIMENSIONS];
@@ -219,32 +222,40 @@ eoshift1 (gfc_array_char *ret, const gfc
}
}
-void eoshift1_`'atype_kind (gfc_array_char *, const gfc_array_char *,
- const atype *, const char *, const atype_name *);
+void eoshift1_`'atype_kind (gfc_array_char * const restrict,
+ const gfc_array_char * const restrict,
+ const atype * const restrict, const char * const restrict,
+ const atype_name * const restrict);
export_proto(eoshift1_`'atype_kind);
void
-eoshift1_`'atype_kind (gfc_array_char *ret, const gfc_array_char *array,
- const atype *h, const char *pbound,
- const atype_name *pwhich)
+eoshift1_`'atype_kind (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const char * const restrict pbound,
+ const atype_name * const restrict pwhich)
{
eoshift1 (ret, array, h, pbound, pwhich, GFC_DESCRIPTOR_SIZE (array), 0);
}
-void eoshift1_`'atype_kind`'_char (gfc_array_char *, GFC_INTEGER_4,
- const gfc_array_char *, const atype *,
- const char *, const atype_name *,
- GFC_INTEGER_4, GFC_INTEGER_4);
+void eoshift1_`'atype_kind`'_char (gfc_array_char * const restrict,
+ GFC_INTEGER_4,
+ const gfc_array_char * const restrict,
+ const atype * const restrict,
+ const char * const restrict,
+ const atype_name * const restrict,
+ GFC_INTEGER_4, GFC_INTEGER_4);
export_proto(eoshift1_`'atype_kind`'_char);
void
-eoshift1_`'atype_kind`'_char (gfc_array_char *ret,
- GFC_INTEGER_4 ret_length __attribute__((unused)),
- const gfc_array_char *array, const atype *h,
- const char *pbound, const atype_name *pwhich,
- GFC_INTEGER_4 array_length,
- GFC_INTEGER_4 bound_length
- __attribute__((unused)))
+eoshift1_`'atype_kind`'_char (gfc_array_char * const restrict ret,
+ GFC_INTEGER_4 ret_length __attribute__((unused)),
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const char * const restrict pbound,
+ const atype_name * const restrict pwhich,
+ GFC_INTEGER_4 array_length,
+ GFC_INTEGER_4 bound_length __attribute__((unused)))
{
eoshift1 (ret, array, h, pbound, pwhich, array_length, ' ');
}
Index: m4/eoshift3.m4
===================================================================
--- m4/eoshift3.m4 (revision 107541)
+++ m4/eoshift3.m4 (working copy)
@@ -38,9 +38,12 @@ include(iparm.m4)dnl
`#if defined (HAVE_'atype_name`)'
static void
-eoshift3 (gfc_array_char *ret, const gfc_array_char *array, const atype *h,
- const gfc_array_char *bound, const atype_name *pwhich,
- index_type size, char filler)
+eoshift3 (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const gfc_array_char * const restrict bound,
+ const atype_name * const restrict pwhich,
+ index_type size, char filler)
{
/* r.* indicates the return array. */
index_type rstride[GFC_MAX_DIMENSIONS];
@@ -237,36 +240,41 @@ eoshift3 (gfc_array_char *ret, const gfc
}
}
-extern void eoshift3_`'atype_kind (gfc_array_char *, const gfc_array_char *,
- const atype *, const gfc_array_char *,
- const atype_name *);
+extern void eoshift3_`'atype_kind (gfc_array_char * const restrict,
+ const gfc_array_char * const restrict,
+ const atype * const restrict,
+ const gfc_array_char * const restrict,
+ const atype_name *);
export_proto(eoshift3_`'atype_kind);
void
-eoshift3_`'atype_kind (gfc_array_char *ret, const gfc_array_char *array,
- const atype *h, const gfc_array_char *bound,
- const atype_name *pwhich)
+eoshift3_`'atype_kind (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const gfc_array_char * const restrict bound,
+ const atype_name * const restrict pwhich)
{
eoshift3 (ret, array, h, bound, pwhich, GFC_DESCRIPTOR_SIZE (array), 0);
}
-extern void eoshift3_`'atype_kind`'_char (gfc_array_char *, GFC_INTEGER_4,
- const gfc_array_char *,
- const atype *,
- const gfc_array_char *,
- const atype_name *, GFC_INTEGER_4,
- GFC_INTEGER_4);
+extern void eoshift3_`'atype_kind`'_char (gfc_array_char * const restrict,
+ GFC_INTEGER_4,
+ const gfc_array_char * const restrict,
+ const atype * const restrict,
+ const gfc_array_char * const restrict,
+ const atype_name * const restrict,
+ GFC_INTEGER_4, GFC_INTEGER_4);
export_proto(eoshift3_`'atype_kind`'_char);
void
-eoshift3_`'atype_kind`'_char (gfc_array_char *ret,
- GFC_INTEGER_4 ret_length __attribute__((unused)),
- const gfc_array_char *array, const atype *h,
- const gfc_array_char *bound,
- const atype_name *pwhich,
- GFC_INTEGER_4 array_length,
- GFC_INTEGER_4 bound_length
- __attribute__((unused)))
+eoshift3_`'atype_kind`'_char (gfc_array_char * const restrict ret,
+ GFC_INTEGER_4 ret_length __attribute__((unused)),
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const gfc_array_char * const restrict bound,
+ const atype_name * const restrict pwhich,
+ GFC_INTEGER_4 array_length,
+ GFC_INTEGER_4 bound_length __attribute__((unused)))
{
eoshift3 (ret, array, h, bound, pwhich, array_length, ' ');
}
Index: m4/dotprodl.m4
===================================================================
--- m4/dotprodl.m4 (revision 107541)
+++ m4/dotprodl.m4 (working copy)
@@ -36,14 +36,16 @@ include(iparm.m4)dnl
`#if defined (HAVE_'rtype_name`)'
-extern rtype_name dot_product_`'rtype_code (gfc_array_l4 *, gfc_array_l4 *);
+extern rtype_name dot_product_`'rtype_code (gfc_array_l4 * const restrict,
+ gfc_array_l4 * const restrict);
export_proto(dot_product_`'rtype_code);
rtype_name
-dot_product_`'rtype_code (gfc_array_l4 * a, gfc_array_l4 * b)
+dot_product_`'rtype_code (gfc_array_l4 * const restrict a,
+ gfc_array_l4 * const restrict b)
{
- GFC_LOGICAL_4 *pa;
- GFC_LOGICAL_4 *pb;
+ const GFC_LOGICAL_4 * restrict pa;
+ const GFC_LOGICAL_4 * restrict pb;
index_type count;
index_type astride;
index_type bstride;
Index: m4/shape.m4
===================================================================
--- m4/shape.m4 (revision 107541)
+++ m4/shape.m4 (working copy)
@@ -36,11 +36,13 @@ include(iparm.m4)dnl
`#if defined (HAVE_'rtype_name`)'
-extern void shape_`'rtype_kind (rtype * ret, const rtype * array);
+extern void shape_`'rtype_kind (rtype * const restrict ret,
+ const rtype * const restrict array);
export_proto(shape_`'rtype_kind);
void
-shape_`'rtype_kind (rtype * ret, const rtype * array)
+shape_`'rtype_kind (rtype * const restrict ret,
+ const rtype * const restrict array)
{
int n;
index_type stride;
Index: m4/cshift1.m4
===================================================================
--- m4/cshift1.m4 (revision 107541)
+++ m4/cshift1.m4 (working copy)
@@ -38,8 +38,11 @@ include(iparm.m4)dnl
`#if defined (HAVE_'atype_name`)'
static void
-cshift1 (gfc_array_char * ret, const gfc_array_char * array,
- const atype * h, const atype_name * pwhich, index_type size)
+cshift1 (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const atype_name * const restrict pwhich,
+ index_type size)
{
/* r.* indicates the return array. */
index_type rstride[GFC_MAX_DIMENSIONS];
@@ -195,30 +198,36 @@ cshift1 (gfc_array_char * ret, const gfc
}
}
-void cshift1_`'atype_kind (gfc_array_char *, const gfc_array_char *,
- const atype *, const atype_name *);
+void cshift1_`'atype_kind (gfc_array_char * const restrict,
+ const gfc_array_char * const restrict,
+ const atype * const restrict,
+ const atype_name * const restrict);
export_proto(cshift1_`'atype_kind);
void
-cshift1_`'atype_kind (gfc_array_char * ret,
- const gfc_array_char * array,
- const atype * h, const atype_name * pwhich)
+cshift1_`'atype_kind (gfc_array_char * const restrict ret,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const atype_name * const restrict pwhich)
{
cshift1 (ret, array, h, pwhich, GFC_DESCRIPTOR_SIZE (array));
}
-void cshift1_`'atype_kind`'_char (gfc_array_char * ret, GFC_INTEGER_4,
- const gfc_array_char * array,
- const atype * h, const atype_name * pwhich,
- GFC_INTEGER_4);
+void cshift1_`'atype_kind`'_char (gfc_array_char * const restrict ret,
+ GFC_INTEGER_4,
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const atype_name * const restrict pwhich,
+ GFC_INTEGER_4);
export_proto(cshift1_`'atype_kind`'_char);
void
-cshift1_`'atype_kind`'_char (gfc_array_char * ret,
- GFC_INTEGER_4 ret_length __attribute__((unused)),
- const gfc_array_char * array,
- const atype * h, const atype_name * pwhich,
- GFC_INTEGER_4 array_length)
+cshift1_`'atype_kind`'_char (gfc_array_char * const restrict ret,
+ GFC_INTEGER_4 ret_length __attribute__((unused)),
+ const gfc_array_char * const restrict array,
+ const atype * const restrict h,
+ const atype_name * const restrict pwhich,
+ GFC_INTEGER_4 array_length)
{
cshift1 (ret, array, h, pwhich, array_length);
}
Index: m4/dotprod.m4
===================================================================
--- m4/dotprod.m4 (revision 107541)
+++ m4/dotprod.m4 (working copy)
@@ -38,15 +38,16 @@ include(iparm.m4)dnl
typedef GFC_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) char_array;
-extern rtype_name dot_product_`'rtype_code (rtype * a, rtype * b);
+extern rtype_name dot_product_`'rtype_code (rtype * const restrict a,
+ rtype * const restrict b);
export_proto(dot_product_`'rtype_code);
/* Both parameters will already have been converted to the result type. */
rtype_name
-dot_product_`'rtype_code (rtype * a, rtype * b)
+dot_product_`'rtype_code (rtype * const restrict a, rtype * const restrict b)
{
- rtype_name *pa;
- rtype_name *pb;
+ const rtype_name * restrict pa;
+ const rtype_name * restrict pb;
rtype_name res;
index_type count;
index_type astride;
Index: m4/dotprodc.m4
===================================================================
--- m4/dotprodc.m4 (revision 107541)
+++ m4/dotprodc.m4 (working copy)
@@ -39,15 +39,16 @@ include(iparm.m4)dnl
typedef GFC_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) char_array;
-extern rtype_name dot_product_`'rtype_code (rtype * a, rtype * b);
+extern rtype_name dot_product_`'rtype_code (rtype * const restrict a,
+ rtype * const restrict b);
export_proto(dot_product_`'rtype_code);
/* Both parameters will already have been converted to the result type. */
rtype_name
-dot_product_`'rtype_code (rtype * a, rtype * b)
+dot_product_`'rtype_code (rtype * const restrict a, rtype * const restrict b)
{
- rtype_name *pa;
- rtype_name *pb;
+ const rtype_name * restrict pa;
+ const rtype_name * restrict pb;
rtype_name res;
rtype_name conjga;
index_type count;
Index: m4/reshape.m4
===================================================================
--- m4/reshape.m4 (revision 107541)
+++ m4/reshape.m4 (working copy)
@@ -42,13 +42,19 @@ typedef GFC_ARRAY_DESCRIPTOR(1, index_ty
return array. */
dnl Only the kind (ie size) is used to name the function.
-extern void reshape_`'rtype_ccode (rtype *, rtype *, shape_type *,
- rtype *, shape_type *);
+extern void reshape_`'rtype_ccode (rtype * const restrict,
+ rtype * const restrict,
+ shape_type * const restrict,
+ rtype * const restrict,
+ shape_type * const restrict);
export_proto(reshape_`'rtype_ccode);
void
-reshape_`'rtype_ccode (rtype * ret, rtype * source, shape_type * shape,
- rtype * pad, shape_type * order)
+reshape_`'rtype_ccode (rtype * const restrict ret,
+ rtype * const restrict source,
+ shape_type * const restrict shape,
+ rtype * const restrict pad,
+ shape_type * const restrict order)
{
/* r.* indicates the return array. */
index_type rcount[GFC_MAX_DIMENSIONS];
Index: m4/ifunction.m4
===================================================================
--- m4/ifunction.m4 (revision 107541)
+++ m4/ifunction.m4 (working copy)
@@ -19,18 +19,21 @@ dnl You should not return or break from
dnl Care should also be taken to avoid using the names defined in iparm.m4
define(START_ARRAY_FUNCTION,
`
-extern void name`'rtype_qual`_'atype_code (rtype *, atype *, index_type *);
+extern void name`'rtype_qual`_'atype_code (rtype * const restrict,
+ atype * const restrict, const index_type * const restrict);
export_proto(name`'rtype_qual`_'atype_code);
void
-name`'rtype_qual`_'atype_code (rtype *retarray, atype *array, index_type *pdim)
+name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
+ atype * 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];
- atype_name *base;
- rtype_name *dest;
+ const atype_name * restrict base;
+ rtype_name * restrict dest;
index_type rank;
index_type n;
index_type len;
@@ -102,7 +105,7 @@ name`'rtype_qual`_'atype_code (rtype *re
while (base)
{
- atype_name *src;
+ const atype_name * restrict src;
rtype_name result;
src = base;
{
@@ -152,22 +155,25 @@ define(FINISH_ARRAY_FUNCTION,
}')dnl
define(START_MASKED_ARRAY_FUNCTION,
`
-extern void `m'name`'rtype_qual`_'atype_code (rtype *, atype *, index_type *,
- gfc_array_l4 *);
+extern void `m'name`'rtype_qual`_'atype_code (rtype * const restrict,
+ atype * const restrict, const index_type * const restrict,
+ gfc_array_l4 * const restrict);
export_proto(`m'name`'rtype_qual`_'atype_code);
void
-`m'name`'rtype_qual`_'atype_code (rtype * retarray, atype * array,
- index_type *pdim, gfc_array_l4 * mask)
+`m'name`'rtype_qual`_'atype_code (rtype * const restrict retarray,
+ atype * const restrict array,
+ const index_type * const restrict pdim,
+ gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
- rtype_name *dest;
- atype_name *base;
- GFC_LOGICAL_4 *mbase;
+ rtype_name * restrict dest;
+ const atype_name * restrict base;
+ const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
@@ -258,8 +264,8 @@ void
while (base)
{
- atype_name *src;
- GFC_LOGICAL_4 *msrc;
+ const atype_name * restrict src;
+ const GFC_LOGICAL_4 * restrict msrc;
rtype_name result;
src = base;
msrc = mbase;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20051126/1c8679d3/attachment.sig>
More information about the Fortran
mailing list