1! Test the MERGE_BITS intrinsic
2!
3! { dg-do run }
4! { dg-options "-ffree-line-length-none" }
5
6  interface run_merge
7    procedure run_merge_1
8    procedure run_merge_2
9    procedure run_merge_4
10    procedure run_merge_8
11  end interface
12
13#define CHECK(I,J,K) \
14  if (merge_bits(I,J,K) /= ior(iand(I,K),iand(J,not(K)))) call abort ; \
15  if (run_merge(I,J,K) /= merge_bits(I,J,K)) call abort
16
17  CHECK(13_1,18_1,22_1)
18  CHECK(-13_1,18_1,22_1)
19  CHECK(13_1,-18_1,22_1)
20  CHECK(13_1,18_1,-22_1)
21
22  CHECK(13_2,18_2,22_2)
23  CHECK(-13_2,18_2,22_2)
24  CHECK(13_2,-18_2,22_2)
25  CHECK(13_2,18_2,-22_2)
26
27  CHECK(13_4,18_4,22_4)
28  CHECK(-13_4,18_4,22_4)
29  CHECK(13_4,-18_4,22_4)
30  CHECK(13_4,18_4,-22_4)
31
32  CHECK(13_8,18_8,22_8)
33  CHECK(-13_8,18_8,22_8)
34  CHECK(13_8,-18_8,22_8)
35  CHECK(13_8,18_8,-22_8)
36
37contains
38
39  function run_merge_1 (i, j, k) result(res)
40    integer(kind=1) :: i, j, k, res
41    res = merge_bits(i,j,k)
42  end function
43  function run_merge_2 (i, j, k) result(res)
44    integer(kind=2) :: i, j, k, res
45    res = merge_bits(i,j,k)
46  end function
47  function run_merge_4 (i, j, k) result(res)
48    integer(kind=4) :: i, j, k, res
49    res = merge_bits(i,j,k)
50  end function
51  function run_merge_8 (i, j, k) result(res)
52    integer(kind=8) :: i, j, k, res
53    res = merge_bits(i,j,k)
54  end function
55end
56