aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2017-07-02 12:34:52 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2017-07-02 12:34:52 +0000
commitb677e2f67f72a8de2b0099f6548e42e4054c180f (patch)
tree404add44be33b9d6e666bd7780a716859b0e48fd /libgfortran
parentb0e84cf75a6732833bb52f6c2445ad59bf4aa9d9 (diff)
downloadgcc-b677e2f67f72a8de2b0099f6548e42e4054c180f.zip
gcc-b677e2f67f72a8de2b0099f6548e42e4054c180f.tar.gz
gcc-b677e2f67f72a8de2b0099f6548e42e4054c180f.tar.bz2
eoshift0.c: For contiguous arrays, use block algorithm.
2017-07-02 Thomas Koenig <tkoenig@gcc.gnu.org> * intrinsics/eoshift0.c: For contiguous arrays, use block algorithm. Use memcpy where possible. 2017-07-02 Thomas Koenig <tkoenig@gcc.gnu.org> * gfortran/eoshift_3.f90: New test. From-SVN: r249882
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog5
-rw-r--r--libgfortran/intrinsics/eoshift0.c144
2 files changed, 113 insertions, 36 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 778056b..fb69c81 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-02 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ * intrinsics/eoshift0.c: For contiguous arrays, use
+ block algorithm. Use memcpy where possible.
+
2017-06-26 Jim Wilson <jim.wilson@r3-a15.aus-colo>
PR libfortran/81195
diff --git a/libgfortran/intrinsics/eoshift0.c b/libgfortran/intrinsics/eoshift0.c
index 53a9a89..24a23c3 100644
--- a/libgfortran/intrinsics/eoshift0.c
+++ b/libgfortran/intrinsics/eoshift0.c
@@ -53,7 +53,8 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
index_type len;
index_type n;
index_type arraysize;
-
+ bool do_blocked;
+
/* The compiler cannot figure out that these are set, initialize
them to avoid warnings. */
len = 0;
@@ -102,38 +103,93 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
count[0] = 0;
sstride[0] = -1;
rstride[0] = -1;
- n = 0;
- for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
+
+ if (which > 0)
{
- if (dim == which)
- {
- roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
- if (roffset == 0)
- roffset = size;
- soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
- if (soffset == 0)
- soffset = size;
- len = GFC_DESCRIPTOR_EXTENT(array,dim);
- }
- else
- {
- count[n] = 0;
- extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
- rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
- sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
- n++;
- }
+ /* Test if both ret and array are contiguous. */
+ size_t r_ex, a_ex;
+ r_ex = 1;
+ a_ex = 1;
+ do_blocked = true;
+ dim = GFC_DESCRIPTOR_RANK (array);
+ for (n = 0; n < dim; n ++)
+ {
+ index_type rs, as;
+ rs = GFC_DESCRIPTOR_STRIDE (ret, n);
+ if (rs != r_ex)
+ {
+ do_blocked = false;
+ break;
+ }
+ as = GFC_DESCRIPTOR_STRIDE (array, n);
+ if (as != a_ex)
+ {
+ do_blocked = false;
+ break;
+ }
+ r_ex *= GFC_DESCRIPTOR_EXTENT (ret, n);
+ a_ex *= GFC_DESCRIPTOR_EXTENT (array, n);
+ }
}
- if (sstride[0] == 0)
- sstride[0] = size;
- if (rstride[0] == 0)
- rstride[0] = size;
+ else
+ do_blocked = false;
- dim = GFC_DESCRIPTOR_RANK (array);
- rstride0 = rstride[0];
- sstride0 = sstride[0];
- rptr = ret->base_addr;
- sptr = array->base_addr;
+ n = 0;
+
+ if (do_blocked)
+ {
+ /* For contiguous arrays, use the relationship that
+
+ dimension(n1,n2,n3) :: a, b
+ b = eoshift(a,sh,3)
+
+ can be dealt with as if
+
+ dimension(n1*n2*n3) :: an, bn
+ bn = eoshift(a,sh*n1*n2,1)
+
+ so a block move can be used for dim>1. */
+ len = GFC_DESCRIPTOR_STRIDE(array, which)
+ * GFC_DESCRIPTOR_EXTENT(array, which);
+ shift *= GFC_DESCRIPTOR_STRIDE(array, which);
+ roffset = size;
+ soffset = size;
+ for (dim = which + 1; dim < GFC_DESCRIPTOR_RANK (array); dim++)
+ {
+ count[n] = 0;
+ extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
+ rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+ sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
+ n++;
+ }
+ count[n] = 0;
+ dim = GFC_DESCRIPTOR_RANK (array) - which;
+ }
+ else
+ {
+ for (dim = 0; dim < GFC_DESCRIPTOR_RANK (array); dim++)
+ {
+ if (dim == which)
+ {
+ roffset = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+ if (roffset == 0)
+ roffset = size;
+ soffset = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
+ if (soffset == 0)
+ soffset = size;
+ len = GFC_DESCRIPTOR_EXTENT(array,dim);
+ }
+ else
+ {
+ count[n] = 0;
+ extent[n] = GFC_DESCRIPTOR_EXTENT(array,dim);
+ rstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(ret,dim);
+ sstride[n] = GFC_DESCRIPTOR_STRIDE_BYTES(array,dim);
+ n++;
+ }
+ }
+ dim = GFC_DESCRIPTOR_RANK (array);
+ }
if ((shift >= 0 ? shift : -shift) > len)
{
@@ -148,6 +204,11 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
len = len + shift;
}
+ rstride0 = rstride[0];
+ sstride0 = sstride[0];
+ rptr = ret->base_addr;
+ sptr = array->base_addr;
+
while (rptr)
{
/* Do the shift for this dimension. */
@@ -161,12 +222,23 @@ eoshift0 (gfc_array_char * ret, const gfc_array_char * array,
src = sptr;
dest = &rptr[-shift * roffset];
}
- for (n = 0; n < len; n++)
- {
- memcpy (dest, src, size);
- dest += roffset;
- src += soffset;
- }
+ /* If the elements are contiguous, perform a single block move. */
+
+ if (soffset == size && roffset == size)
+ {
+ size_t chunk = size * len;
+ memcpy (dest, src, chunk);
+ dest += chunk;
+ }
+ else
+ {
+ for (n = 0; n < len; n++)
+ {
+ memcpy (dest, src, size);
+ dest += roffset;
+ src += soffset;
+ }
+ }
if (shift >= 0)
{
n = shift;