| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-O2" } |
| 3 |
! { dg-additional-options "-O2 -march=armv8.3-a" { target arm_v8_3a_complex_neon_hw } } |
| 4 |
|
| 5 |
module util |
| 6 |
use iso_fortran_env, only: real64, int64 |
| 7 |
implicit none |
| 8 |
contains |
| 9 |
pure logical function bitwise_eq(x, y) |
| 10 |
complex(real64), intent(in) :: x, y |
| 11 |
integer(int64) :: xr, xi, yr, yi |
| 12 |
xr = transfer(real(x,kind=real64), 0_int64) |
| 13 |
xi = transfer(aimag(x), 0_int64) |
| 14 |
yr = transfer(real(y,kind=real64), 0_int64) |
| 15 |
yi = transfer(aimag(y), 0_int64) |
| 16 |
bitwise_eq = (xr == yr) .and. (xi == yi) |
| 17 |
end function bitwise_eq |
| 18 |
|
| 19 |
subroutine check_equal(tag, got, ref, nfail) |
| 20 |
character(*), intent(in) :: tag |
| 21 |
complex(real64), intent(in) :: got(:), ref(:) |
| 22 |
integer, intent(inout) :: nfail |
| 23 |
integer :: i |
| 24 |
do i = 1, size(got) |
| 25 |
if (.not. bitwise_eq(got(i), ref(i))) then |
| 26 |
nfail = nfail + 1 |
| 27 |
write(*,'(A,": mismatch at i=",I0, " got=",2ES16.8," ref=",2ES16.8)') & |
| 28 |
trim(tag), i, real(got(i)), aimag(got(i)), real(ref(i)), aimag(ref(i)) |
| 29 |
end if |
| 30 |
end do |
| 31 |
end subroutine check_equal |
| 32 |
end module util |
| 33 |
|
| 34 |
module fcmla_ops |
| 35 |
use iso_fortran_env, only: real64 |
| 36 |
implicit none |
| 37 |
contains |
| 38 |
subroutine c_add_ab(n, a, c, b) ! C += A * B |
| 39 |
!GCC$ ATTRIBUTES noinline :: c_add_ab |
| 40 |
integer, intent(in) :: n |
| 41 |
complex(real64), intent(in) :: a |
| 42 |
complex(real64), intent(inout) :: c(*) |
| 43 |
complex(real64), intent(in) :: b(*) |
| 44 |
integer :: k |
| 45 |
do k = 1, n |
| 46 |
c(k) = c(k) + a * b(k) |
| 47 |
end do |
| 48 |
end subroutine c_add_ab |
| 49 |
|
| 50 |
subroutine c_sub_ab(n, a, c, b) ! C -= A * B |
| 51 |
!GCC$ ATTRIBUTES noinline :: c_sub_ab |
| 52 |
integer, intent(in) :: n |
| 53 |
complex(real64), intent(in) :: a |
| 54 |
complex(real64), intent(inout) :: c(*) |
| 55 |
complex(real64), intent(in) :: b(*) |
| 56 |
integer :: k |
| 57 |
do k = 1, n |
| 58 |
c(k) = c(k) - a * b(k) |
| 59 |
end do |
| 60 |
end subroutine c_sub_ab |
| 61 |
|
| 62 |
subroutine c_add_a_conjb(n, a, c, b) ! C += A * conj(B) |
| 63 |
!GCC$ ATTRIBUTES noinline :: c_add_a_conjb |
| 64 |
integer, intent(in) :: n |
| 65 |
complex(real64), intent(in) :: a |
| 66 |
complex(real64), intent(inout) :: c(*) |
| 67 |
complex(real64), intent(in) :: b(*) |
| 68 |
integer :: k |
| 69 |
do k = 1, n |
| 70 |
c(k) = c(k) + a * conjg(b(k)) |
| 71 |
end do |
| 72 |
end subroutine c_add_a_conjb |
| 73 |
|
| 74 |
subroutine c_sub_a_conjb(n, a, c, b) ! C -= A * conj(B) |
| 75 |
!GCC$ ATTRIBUTES noinline :: c_sub_a_conjb |
| 76 |
integer, intent(in) :: n |
| 77 |
complex(real64), intent(in) :: a |
| 78 |
complex(real64), intent(inout) :: c(*) |
| 79 |
complex(real64), intent(in) :: b(*) |
| 80 |
integer :: k |
| 81 |
do k = 1, n |
| 82 |
c(k) = c(k) - a * conjg(b(k)) |
| 83 |
end do |
| 84 |
end subroutine c_sub_a_conjb |
| 85 |
end module fcmla_ops |
| 86 |
|
| 87 |
program fcmla_accum_pairs |
| 88 |
use iso_fortran_env, only: real64 |
| 89 |
use util |
| 90 |
use fcmla_ops |
| 91 |
implicit none |
| 92 |
|
| 93 |
integer, parameter :: n = 4 |
| 94 |
complex(real64) :: a, b(n), c0(n) |
| 95 |
complex(real64) :: c_add_ab_got(n), c_add_ab_ref(n) |
| 96 |
complex(real64) :: c_sub_ab_got(n), c_sub_ab_ref(n) |
| 97 |
complex(real64) :: c_add_conjb_got(n), c_add_conjb_ref(n) |
| 98 |
complex(real64) :: c_sub_conjb_got(n), c_sub_conjb_ref(n) |
| 99 |
integer :: i, fails |
| 100 |
|
| 101 |
! Constants (include a signed-zero lane) |
| 102 |
a = cmplx( 2.0_real64, -3.0_real64, kind=real64) |
| 103 |
b(1) = cmplx( 1.5_real64, -2.0_real64, kind=real64) |
| 104 |
b(2) = cmplx(-4.0_real64, 5.0_real64, kind=real64) |
| 105 |
b(3) = cmplx(-0.0_real64, 0.0_real64, kind=real64) |
| 106 |
b(4) = cmplx( 0.25_real64, 3.0_real64, kind=real64) |
| 107 |
|
| 108 |
c0(1) = cmplx( 1.0_real64, -2.0_real64, kind=real64) |
| 109 |
c0(2) = cmplx( 3.0_real64, -4.0_real64, kind=real64) |
| 110 |
c0(3) = cmplx(-5.0_real64, 6.0_real64, kind=real64) |
| 111 |
c0(4) = cmplx( 0.0_real64, 0.0_real64, kind=real64) |
| 112 |
|
| 113 |
! Run each form |
| 114 |
c_add_ab_got = c0; call c_add_ab (n, a, c_add_ab_got, b) |
| 115 |
c_sub_ab_got = c0; call c_sub_ab (n, a, c_sub_ab_got, b) |
| 116 |
c_add_conjb_got = c0; call c_add_a_conjb(n, a, c_add_conjb_got, b) |
| 117 |
c_sub_conjb_got = c0; call c_sub_a_conjb(n, a, c_sub_conjb_got, b) |
| 118 |
|
| 119 |
! Scalar references |
| 120 |
do i = 1, n |
| 121 |
c_add_ab_ref(i) = c0(i) + a * b(i) |
| 122 |
c_sub_ab_ref(i) = c0(i) - a * b(i) |
| 123 |
c_add_conjb_ref(i) = c0(i) + a * conjg(b(i)) |
| 124 |
c_sub_conjb_ref(i) = c0(i) - a * conjg(b(i)) |
| 125 |
end do |
| 126 |
|
| 127 |
! Bitwise checks |
| 128 |
fails = 0 |
| 129 |
call check_equal("C += A*B ", c_add_ab_got, c_add_ab_ref, fails) |
| 130 |
call check_equal("C -= A*B ", c_sub_ab_got, c_sub_ab_ref, fails) |
| 131 |
call check_equal("C += A*conj(B) ", c_add_conjb_got, c_add_conjb_ref, fails) |
| 132 |
call check_equal("C -= A*conj(B) ", c_sub_conjb_got, c_sub_conjb_ref, fails) |
| 133 |
|
| 134 |
if (fails == 0) then |
| 135 |
stop 0 |
| 136 |
else |
| 137 |
stop 1 |
| 138 |
end if |
| 139 |
end program fcmla_accum_pairs |
| 140 |
|