ivan-pi / fc8

Fortran CHIP-8 interpreter
GNU General Public License v3.0
7 stars 1 forks source link

nvfortran shiftr/shiftl #9

Open ivan-pi opened 1 year ago

ivan-pi commented 1 year ago

Quoting the response I got from NVIDIA:

These are special cases for the ishft intrinsic that nvfortran does support. Supporting shiftr and shiftl have been added to our work list. . but we do not have a time line yet for their availability in nvfortran at the time .

We incidentally see also failure in your workaround.f90 . Here is the alternate workaround that uses the ishft intrinsic in case it can facilitate you .


module mod
contains
elemental integer function shiftr(i,n)
integer,intent(in) :: i, n
shiftr = ishft(i,-n)
end function

elemental integer function shiftl(i,n) integer,intent(in) :: i, n shiftl = ishft(i,n) end function end module

use mod integer :: i i = 42 i = shiftr(i,5) i = shiftl(i,5) print *, i end


My workaround was, 

```fortran
integer :: i
external :: shiftr, shiftl
i = 42
i = shiftr(i,5)
i = shiftl(i,5)
print *, i
end

pure integer function shiftr(i,n)
integer, value :: i, n
shiftr = rshift(i,n)
end function

pure integer function shiftl(i,n)
integer, value :: i, n
shiftl = lshift(i,n)
end function