6 module procedure ilog2_8
7 module procedure ilog2_4
8 module procedure ilog2_2
9 module procedure ilog2_1
13 ! log
(x
+1)/log
(2) unless x
=maxint
, in which case log
(x
)/log
(2)
14 module procedure i1log2_8
15 module procedure i1log2_4
16 module procedure i1log2_2
17 module procedure i1log2_1
22 ! ----------------------------------------------------------------
24 function i1log2_8
(ival
)
26 integer(kind
=8), value
:: ival
27 integer(kind
=8)::i1log2_8
28 integer(kind
=8), parameter :: one
=1
29 if(ival
+one
<ival
) then
30 i1log2_8
=ilog2_8
(ival
)
32 i1log2_8
=ilog2_8
(ival
+one
)
36 ! ----------------------------------------------------------------
38 function i1log2_4
(ival
)
40 integer(kind
=4), value
:: ival
41 integer(kind
=4)::i1log2_4
42 integer(kind
=4), parameter :: one
=1
43 if(ival
+one
<ival
) then
44 i1log2_4
=ilog2_4
(ival
)
46 i1log2_4
=ilog2_4
(ival
+one
)
50 ! ----------------------------------------------------------------
52 function i1log2_2
(ival
)
54 integer(kind
=2), value
:: ival
55 integer(kind
=2)::i1log2_2
56 integer(kind
=2), parameter :: one
=1
57 if(ival
+one
<ival
) then
58 i1log2_2
=ilog2_2
(ival
)
60 i1log2_2
=ilog2_2
(ival
+one
)
64 ! ----------------------------------------------------------------
66 function i1log2_1
(ival
)
68 integer(kind
=1), value
:: ival
69 integer(kind
=1)::i1log2_1
70 integer(kind
=1), parameter :: one
=1
71 if(ival
+one
<ival
) then
72 i1log2_1
=ilog2_1
(ival
)
74 i1log2_1
=ilog2_1
(ival
+one
)
78 ! ----------------------------------------------------------------
80 function ilog2_8
(i_in
)
82 integer(kind
=8), value
:: i_in
83 integer(kind
=8)::ilog2_8
,i
87 if(iand
(i
,i
-1)/=0) then
88 !write(0,*) 'iand i-1'
91 if(iand
(i
,Z
'FFFFFFFF00000000')/=0) then
94 !write(0,*) 'iand ffffffff',i
,ilog2_8
96 if(iand
(i
,Z
'00000000FFFF0000')/=0) then
99 !write(0,*) 'iand ffff' ,i
,ilog2_8
101 if(iand
(i
,Z
'000000000000FF00')/=0) then
104 !write(0,*) 'iand ff',i
,ilog2_8
106 if(iand
(i
,Z
'00000000000000F0')/=0) then
109 !write(0,*) 'iand f',i
,ilog2_8
111 if(iand
(i
,Z
'000000000000000C')/=0) then
114 !write(0,*) 'iand c',i
,ilog2_8
116 if(iand
(i
,Z
'0000000000000002')/=0) then
119 !write(0,*) 'iand 2',i
,ilog2_8
123 ! ----------------------------------------------------------------
125 function ilog2_4
(i_in
)
127 integer(kind
=4), value
:: i_in
128 integer(kind
=4)::ilog2_4
,i
132 if(iand
(i
,i
-1)/=0) then
133 !write(0,*) 'iand i-1'
136 if(iand
(i
,Z
'FFFF0000')/=0) then
139 !write(0,*) 'iand ffff' ,i
,ilog2_4
141 if(iand
(i
,Z
'0000FF00')/=0) then
144 !write(0,*) 'iand ff',i
,ilog2_4
146 if(iand
(i
,Z
'000000F0')/=0) then
149 !write(0,*) 'iand f',i
,ilog2_4
151 if(iand
(i
,Z
'0000000C')/=0) then
154 !write(0,*) 'iand c',i
,ilog2_4
156 if(iand
(i
,Z
'00000002')/=0) then
159 !write(0,*) 'iand 2',i
,ilog2_4
163 ! ----------------------------------------------------------------
165 function ilog2_2
(i_in
)
167 integer(kind
=2), value
:: i_in
168 integer(kind
=2)::ilog2_2
,i
172 ! WPS modification
for the XL compiler
173 ! if(iand
(i
,i
-1)/=0) then
174 if(iand
(i
,i
-1_2
)/=0) then
175 !write(0,*) 'iand i-1'
178 if(iand
(i
,Z
'FF00')/=0) then
181 !write(0,*) 'iand ff',i
,ilog2_2
183 if(iand
(i
,Z
'00F0')/=0) then
186 !write(0,*) 'iand f',i
,ilog2_2
188 if(iand
(i
,Z
'000C')/=0) then
191 !write(0,*) 'iand c',i
,ilog2_2
193 if(iand
(i
,Z
'0002')/=0) then
196 !write(0,*) 'iand 2',i
,ilog2_2
200 ! ----------------------------------------------------------------
202 function ilog2_1
(i_in
)
204 integer(kind
=1), value
:: i_in
205 integer(kind
=1)::ilog2_1
,i
209 ! WPS modification
for the XL compiler
210 ! if(iand
(i
,i
-1)/=0) then
211 if(iand
(i
,i
-1_1
)/=0) then
212 !write(0,*) 'iand i-1'
215 if(iand
(i
,Z
'F0')/=0) then
218 !write(0,*) 'iand f',i
,ilog2_1
220 if(iand
(i
,Z
'0C')/=0) then
223 !write(0,*) 'iand c',i
,ilog2_1
225 if(iand
(i
,Z
'02')/=0) then
228 !write(0,*) 'iand 2',i
,ilog2_1
232 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
233 c$$$ TEST PROGRAM FOR THIS MODULE
234 c$$$ program test_intmath
237 c$$$ real(kind=16) :: temp
238 c$$$ real(kind=16), parameter :: alog2=log(2.0_16)
239 c$$$ integer(kind=8), parameter :: &
240 c$$$ & one=1,big=Z'7FFFFFFFFFFFFFFF',small=-2000000_8, &
241 c$$$ & check=Z'1FFFFFFF'
242 c$$$ integer(kind=8) :: ival, iret
243 c$$$ !$OMP PARALLEL DO PRIVATE(ival,temp,iret)
244 c$$$ do ival=small,big
245 c$$$ 10 format(Z16,' -- MISMATCH: ',I0,'=>',I0,' (',I0,' = ',F0.10,')')
246 c$$$ 20 format(Z16,' -- OKAY: ',I0,'=>',I0,' (',I0,' = ',F0.10,')')
247 c$$$ if(ival+one<ival) then
248 c$$$ temp=log(real(max(ival,one),kind=16))/alog2
250 c$$$ temp=log(real(max(ival+one,one),kind=16))/alog2
252 c$$$ iret=i1log2(ival)
253 c$$$ if(iret/=ceiling(temp) .or. ival==0 .or. ival==check) then
255 c$$$ if(iret/=ceiling(temp)) then
256 c$$$ print 10, ival, ival, iret,ceiling(temp),temp
258 c$$$ print 20, ival, ival, iret,ceiling(temp),temp
260 c$$$ !$OMP END CRITICAL
263 c$$$ !$OMP END PARALLEL DO
264 c$$$ end program test_intmath