aboutsummaryrefslogtreecommitdiff
path: root/gcc
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 /gcc
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 'gcc')
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gfortran.dg/eoshift_3.f90178
2 files changed, 182 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 07b2c9d..ac9c6a6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-02 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ * gfortran/eoshift_3.f90: New test.
+
2017-07-02 Richard Sandiford <richard.sandiford@linaro.org>
* gcc.dg/strlenopt-32.c: New testcase.
diff --git a/gcc/testsuite/gfortran.dg/eoshift_3.f90 b/gcc/testsuite/gfortran.dg/eoshift_3.f90
new file mode 100644
index 0000000..d1087aa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/eoshift_3.f90
@@ -0,0 +1,178 @@
+! { dg-do run }
+! Check that eoshift works for three-dimensional arrays.
+module x
+ implicit none
+contains
+ subroutine eoshift_0 (array, shift, boundary, dim, res)
+ real, dimension(:,:,:), intent(in) :: array
+ real, dimension(:,:,:), intent(out) :: res
+ integer, value :: shift
+ real, optional, intent(in) :: boundary
+ integer, optional, intent(in) :: dim
+ integer :: s1, s2, s3
+ integer :: n1, n2, n3
+
+ real :: b
+ integer :: d
+ if (present(boundary)) then
+ b = boundary
+ else
+ b = 0.0
+ end if
+
+ if (present(dim)) then
+ d = dim
+ else
+ d = 1
+ end if
+
+ n1 = size(array,1)
+ n2 = size(array,2)
+ n3 = size(array,3)
+
+ select case(dim)
+ case(1)
+ if (shift > 0) then
+ shift = min(shift, n1)
+ do s3=1,n3
+ do s2=1,n2
+ do s1= 1, n1 - shift
+ res(s1,s2,s3) = array(s1+shift,s2,s3)
+ end do
+ do s1 = n1 - shift + 1,n1
+ res(s1,s2,s3) = b
+ end do
+ end do
+ end do
+
+ else
+ shift = max(shift, -n1)
+ do s3=1,n3
+ do s2=1,n2
+ do s1=1,-shift
+ res(s1,s2,s3) = b
+ end do
+ do s1= 1-shift,n1
+ res(s1,s2,s3) = array(s1+shift,s2,s3)
+ end do
+ end do
+ end do
+ end if
+
+ case(2)
+ if (shift > 0) then
+ shift = min(shift, n2)
+ do s3=1,n3
+ do s2=1, n2 - shift
+ do s1=1,n1
+ res(s1,s2,s3) = array(s1,s2+shift,s3)
+ end do
+ end do
+ do s2=n2 - shift + 1, n2
+ do s1=1,n1
+ res(s1,s2,s3) = b
+ end do
+ end do
+ end do
+ else
+ shift = max(shift, -n2)
+ do s3=1,n3
+ do s2=1,-shift
+ do s1=1,n1
+ res(s1,s2,s3) = b
+ end do
+ end do
+ do s2=1-shift,n2
+ do s1=1,n1
+ res(s1,s2,s3) = array(s1,s2+shift,s3)
+ end do
+ end do
+ end do
+ end if
+
+ case(3)
+ if (shift > 0) then
+ shift = min(shift, n3)
+ do s3=1,n3 - shift
+ do s2=1, n2
+ do s1=1,n1
+ res(s1,s2,s3) = array(s1,s2,s3+shift)
+ end do
+ end do
+ end do
+ do s3=n3 - shift + 1, n3
+ do s2=1, n2
+ do s1=1,n1
+ res(s1,s2,s3) = b
+ end do
+ end do
+ end do
+ else
+ shift = max(shift, -n3)
+ do s3=1,-shift
+ do s2=1,n2
+ do s1=1,n1
+ res(s1,s2,s3) = b
+ end do
+ end do
+ end do
+ do s3=1-shift,n3
+ do s2=1,n2
+ do s1=1,n1
+ res(s1,s2,s3) = array(s1,s2,s3+shift)
+ end do
+ end do
+ end do
+ end if
+
+ case default
+ stop "Illegal dim"
+ end select
+ end subroutine eoshift_0
+end module x
+
+program main
+ use x
+ implicit none
+ integer, parameter :: n1=2,n2=4,n3=2
+ real, dimension(n1,n2,n3) :: a,b,c
+ integer :: dim, shift, shift_lim
+ call random_number(a)
+
+ do dim=1,3
+ if (dim == 1) then
+ shift_lim = n1 + 1
+ else if (dim == 2) then
+ shift_lim = n2 + 1
+ else
+ shift_lim = n3 + 1
+ end if
+ do shift=-shift_lim, shift_lim
+ b = eoshift(a,shift,dim=dim)
+ call eoshift_0 (a, shift=shift, dim=dim, res=c)
+ if (any (b /= c)) then
+ print *,"dim = ", dim, "shift = ", shift
+ call abort
+ end if
+ end do
+ end do
+ call random_number(b)
+ c = b
+
+ do dim=1,3
+ if (dim == 1) then
+ shift_lim = n1/2 + 1
+ else if (dim == 2) then
+ shift_lim = n2/2 + 1
+ else
+ shift_lim = n3/2 + 1
+ end if
+
+ do shift=-shift_lim, shift_lim
+ b(1:n1:2,:,:) = eoshift(a(1:n1/2,:,:),shift,dim=dim)
+ call eoshift_0 (a(1:n1/2,:,:), shift=shift, dim=dim, res=c(1:n1:2,:,:))
+ if (any (b /= c)) call abort
+ end do
+ end do
+
+end program main