[PATCH][RFC]Overloading intrinsics
Martin Liška
mliska@suse.cz
Thu Nov 1 14:53:00 GMT 2018
On 10/31/18 8:58 PM, Toon Moene wrote:
> On 10/30/2018 04:40 PM, Martin Liška wrote:
>
> Did anyone ever helped you with this error message ? I haven't seen a reply to the list to that effect ...
Hello.
No, you're the first one who replied. Thanks for it.
>
>> Now I've tried to separate real module and it's usage and I see strange error:
>>
>> $ cat ~/Programming/testcases/module.f90
>> module vector_math
>> Â Â interface
>> Â Â Â Â function sin(arg)
>> Â Â Â Â Â Â !GCC$ attributes simd_notinbranch :: sin
>> Â Â Â Â Â Â real, intent(in) :: arg
>> Â Â Â Â Â Â real :: sin
>> Â Â Â Â end function sin
>> Â Â end interface
>> end module
>>
>> $ ./xgcc -B. -Ofast -c ~/Programming/testcases/module.f90
>>
>> $ cat ~/Programming/testcases/use.f90
>> program test_overloaded_intrinsic
>> Â Â use vector_math
>> Â Â real(4) :: x(3200), y(3200), z(3200)
>>
>> Â Â ! this should be using simd clone
>> Â Â y = sin(x)
>> Â Â print *, y
>>
>> Â Â ! this not
>> Â Â z = cos(x)
>> Â Â print *, z
>>
>> Â Â z = sin (z)
>> Â Â print *, z
>> end
>>
>> $ ./xgcc -B. -Ofast -c ~/Programming/testcases/use.f90
>> /home/marxin/Programming/testcases/use.f90:6:10:
>>
>> Â Â Â Â 6 |Â Â y = sin(x)
>> Â Â Â Â Â Â |Â Â Â Â Â Â Â Â Â 1
>> Error: Rank mismatch in argument âargâ at (1) (scalar and rank-1)
>> /home/marxin/Programming/testcases/use.f90:13:11:
>>
>> Â Â Â 13 |Â Â z = sin (z)
>> Â Â Â Â Â Â |Â Â Â Â Â Â Â Â Â Â 1
>> Error: Rank mismatch in argument âargâ at (1) (scalar and rank-1)
>
> What is happening here is that you define an EXTERNAL function "sin" which, according to your declaration [ I left out the GCC attribute ]:
>
>>Â Â Â Â Â function sin(arg)
>>Â Â Â Â Â Â Â real, intent(in) :: arg
>>Â Â Â Â Â Â Â real :: sin
>
> is a real function of a scalar argument returning a scalar result.
>
> However, in using it, you pass it 32000 element arrays of reals (you don't need, and should omit, the (4) on the real declaration).
>
> This works for the INTRINSIC functions "sin", "cos", etc., because the Fortran language declares them to be ELEMENTAL.
I see!
>
> This means that, while you can pass them a scalar argument and get a scalar result, you can also pass them a rank-N array and get a rank-N array result OF THE SAME SHAPE.
>
> I wonder if it works to change the declaration to:
>
>>Â Â Â Â Â elemental real function sin(arg)
>>Â Â Â Â Â Â Â real, intent(in) :: arg
>>Â Â Â Â Â Â Â real :: sin
>
> which declares a user-defined, EXTERNAL, ELEMENTAL function called "sin".
I can confirm that adding ELEMENTAL removes the compilation error.
Now I slightly adjusted the 0001-Support-simd-attribute-propagation-for-a-vector_math.patch patch:
- I do not math match module by name
- I mark simd flag in mio_symbol, which is the place where a module symbol is created.
Now I'm able to add 'use vector_math' directive to my test:
module vector_math
interface
elemental function sin(arg)
!GCC$ attributes simd_notinbranch :: sin
real, intent(in) :: arg
real :: sin
end function sin
end interface
end module
program test_overloaded_intrinsic
use vector_math
real :: x(3200), y(3200), z(3200)
! this should be using simd clone
y = sin(x)
print *, y
! this not
z = cos(x)
print *, z
z = sin (z)
print *, z
end
However, now I need significant hacking in resolve.c in order to persuade Fortran FE
that my "sin" function (being external module function)
can really be seen as intrinsic (please see 0002-* patch).
Any ideas how to make the resolution working without hacking?
Thank you,
Martin
>
> Hope this helps,
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Bend-symbol-resolution-in-fortran.patch
Type: text/x-patch
Size: 1247 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20181101/aa16617a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Support-simd-attribute-propagation-for-a-vector_math.patch
Type: text/x-patch
Size: 6543 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20181101/aa16617a/attachment-0001.bin>
More information about the Fortran
mailing list