| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-msse2" { target sse2_runtime } } |
| 3 |
! { dg-additional-options "-mavx" { target avx_runtime } } |
| 4 |
|
| 5 |
module SIMD4_mod |
| 6 |
contains |
| 7 |
subroutine work( b, n, m ) |
| 8 |
implicit none |
| 9 |
real :: b(n) |
| 10 |
integer :: i,n,m |
| 11 |
|
| 12 |
call init(b, n) |
| 13 |
|
| 14 |
!$omp simd safelen(16) |
| 15 |
do i = m+1, n |
| 16 |
b(i) = b(i-m) - 1.0 |
| 17 |
end do |
| 18 |
end subroutine work |
| 19 |
|
| 20 |
subroutine work_ref( b, n, m ) |
| 21 |
implicit none |
| 22 |
real :: b(n) |
| 23 |
integer :: i,n,m |
| 24 |
|
| 25 |
call init(b, n) |
| 26 |
|
| 27 |
do i = m+1, n |
| 28 |
b(i) = b(i-m) - 1.0 |
| 29 |
end do |
| 30 |
end subroutine work_ref |
| 31 |
|
| 32 |
subroutine init (b, n) |
| 33 |
real :: b(*) |
| 34 |
integer :: n, i, s |
| 35 |
|
| 36 |
s = -1 |
| 37 |
do i = 1, n |
| 38 |
b(i) = i * i * s |
| 39 |
s = -s |
| 40 |
end do |
| 41 |
|
| 42 |
end subroutine |
| 43 |
|
| 44 |
subroutine check (a, b, n) |
| 45 |
integer :: i, n |
| 46 |
real, parameter :: EPS = 0.000001 |
| 47 |
real :: diff, a(*), b(*) |
| 48 |
do i = 1, n |
| 49 |
diff = a(i) - b(i) |
| 50 |
if (diff > EPS .or. -diff > EPS) stop 1 |
| 51 |
end do |
| 52 |
end subroutine |
| 53 |
|
| 54 |
end module |
| 55 |
|
| 56 |
program SIMD4 |
| 57 |
use SIMD4_mod |
| 58 |
real :: b(128), b_ref(128) |
| 59 |
|
| 60 |
call work(b, 128, 32) |
| 61 |
call work_ref(b_ref, 128, 32) |
| 62 |
|
| 63 |
call check(b, b_ref, 128) |
| 64 |
end program |