public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Guide to adding intrinsic functions to gfortran
@ 2020-09-05 19:21 W Spector
  2020-09-05 19:35 ` Damian Rouson
  2020-09-06  9:28 ` Thomas Koenig
  0 siblings, 2 replies; 4+ messages in thread
From: W Spector @ 2020-09-05 19:21 UTC (permalink / raw)
  To: gfortran

Hi,

I'd like to explore adding a few intrinsic functions to gfortran for 
personal research.  (I've basically retired - so this is just for fun.) 
The functions would accept a 1D array of [real, integer, character 
string] as input.  They would return a 1D array of the same type as the 
input.

Are there any pointers to, say, a good email thread or other 
documentation on how to do this?  I haven't looked into the internals of 
gcc in about 20 years - and of course that was long before the gfortran 
front end existed.

If it matters, I've been building trunk versions of the gcc for many 
years.  I have typically updated my svn gcc repository before the build. 
  But thinking I should start with a clone of the git repository and 
create my own local branch for the work.

Walter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Guide to adding intrinsic functions to gfortran
  2020-09-05 19:21 Guide to adding intrinsic functions to gfortran W Spector
@ 2020-09-05 19:35 ` Damian Rouson
  2020-09-06  9:28 ` Thomas Koenig
  1 sibling, 0 replies; 4+ messages in thread
From: Damian Rouson @ 2020-09-05 19:35 UTC (permalink / raw)
  To: W Spector; +Cc: gfortran

Hi Walter,

Great to see you’re looking into working in gfortran.  I too build
up-to-date branches from source occasionally but haven’t yet contributed
source so I won’t have pointers to offer, but if you don’t mind sharing,
which intrinsic functions are you considering implementing?

Before cloning and branching, you might consider forking in case it’s
useful to be able to push to a different remote repository than than the
central one.

Damian

On Sat, Sep 5, 2020 at 12:21 W Spector via Fortran <fortran@gcc.gnu.org>
wrote:

> Hi,
>
>
>
> I'd like to explore adding a few intrinsic functions to gfortran for
>
> personal research.  (I've basically retired - so this is just for fun.)
>
> The functions would accept a 1D array of [real, integer, character
>
> string] as input.  They would return a 1D array of the same type as the
>
> input.
>
>
>
> Are there any pointers to, say, a good email thread or other
>
> documentation on how to do this?  I haven't looked into the internals of
>
> gcc in about 20 years - and of course that was long before the gfortran
>
> front end existed.
>
>
>
> If it matters, I've been building trunk versions of the gcc for many
>
> years.  I have typically updated my svn gcc repository before the build.
>
>   But thinking I should start with a clone of the git repository and
>
> create my own local branch for the work.
>
>
>
> Walter
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Guide to adding intrinsic functions to gfortran
  2020-09-05 19:21 Guide to adding intrinsic functions to gfortran W Spector
  2020-09-05 19:35 ` Damian Rouson
@ 2020-09-06  9:28 ` Thomas Koenig
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Koenig @ 2020-09-06  9:28 UTC (permalink / raw)
  To: W Spector, fortran

Am 05.09.20 um 21:21 schrieb W Spector via Fortran:
> Hi,
> 
> I'd like to explore adding a few intrinsic functions to gfortran for 
> personal research.  (I've basically retired - so this is just for fun.) 
> The functions would accept a 1D array of [real, integer, character 
> string] as input.  They would return a 1D array of the same type as the 
> input.
> 
> Are there any pointers to, say, a good email thread or other 
> documentation on how to do this?

If you don't know the gfortran front end, the first thing
you may want do read is

https://gcc.gnu.org/wiki/GFortranHacking .

Apart from that, there is no guide per se, but I can point
you at the implementation of FINDLOC, which was all in one
piece, and probably has everything you need and more.

You can find the initial patch at

https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=01ce9e31a02c8039d88e90f983735104417bf034

which has all the parts you may need to touch (plus a
few more).

Basically, you need to register your intrinsic in add_functions
in intrinsic.c.  The table there contains function pointers to
check, simplify and resolve.  You will need to implement all
three functions for your new intrinsic, you can find an
example in the patch (or numerous other examples in
check.c, simplify.c and iresolve.c).

For actually implementation, the best way is probably to write
C code without trying to inline it. You probably don't need to
touch trans-*.  Setting the function name to call in iresolve.c
should be enough for most cases.

If you want to add new source files to libgfortran, you will have
to edit libgfortran/Makefile.am and use --enable-maintainer-mode .
The latter is a medium-sized PITA, because you need to get the
versions of the required tools exactly right.

I would also avoid using files generated from m4 at the time being.
That is another steep learning curve.

I hope this helps somewhat.

Out of curiosity: What intrinsics are you trying to implement?

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Guide to adding intrinsic functions to gfortran
@ 2020-09-06 19:20 Walter Spector
  0 siblings, 0 replies; 4+ messages in thread
From: Walter Spector @ 2020-09-06 19:20 UTC (permalink / raw)
  To: Thomas Koenig, fortran

Thomas,

Thank you so much for the pointers.  I will look into them.

To get my feet wet, I want to write simplified versions of the old HPF sort_up() and sort_down() functions.  No DIM argument.  Sorting algorithms are complicated enough that they would likely be library routines, not in-lined.  (Though the C++ implementation of std::sort argues otherwise...)

After that, there are a number of other APL and J inspired functions that would be fun to do.  (I used to use APL a lot back in college days...)  Again it is all intended for personal experimentation with no time frames.

Walter


-----Original Message-----
>From: Thomas Koenig <tkoenig@netcologne.de>
>Sent: Sep 6, 2020 2:28 AM
>To: W Spector <w6ws@earthlink.net>, "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
>Subject: Re: Guide to adding intrinsic functions to gfortran
>
>Am 05.09.20 um 21:21 schrieb W Spector via Fortran:
>> Hi,
>> 
>> I'd like to explore adding a few intrinsic functions to gfortran for 
>> personal research.  (I've basically retired - so this is just for fun.) 
>> The functions would accept a 1D array of [real, integer, character 
>> string] as input.  They would return a 1D array of the same type as the 
>> input.
>> 
>> Are there any pointers to, say, a good email thread or other 
>> documentation on how to do this?
>
>If you don't know the gfortran front end, the first thing
>you may want do read is
>
>https://gcc.gnu.org/wiki/GFortranHacking .
>
>Apart from that, there is no guide per se, but I can point
>you at the implementation of FINDLOC, which was all in one
>piece, and probably has everything you need and more.
>
>You can find the initial patch at
>
>https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=01ce9e31a02c8039d88e90f983735104417bf034
>
>which has all the parts you may need to touch (plus a
>few more).
>
>Basically, you need to register your intrinsic in add_functions
>in intrinsic.c.  The table there contains function pointers to
>check, simplify and resolve.  You will need to implement all
>three functions for your new intrinsic, you can find an
>example in the patch (or numerous other examples in
>check.c, simplify.c and iresolve.c).
>
>For actually implementation, the best way is probably to write
>C code without trying to inline it. You probably don't need to
>touch trans-*.  Setting the function name to call in iresolve.c
>should be enough for most cases.
>
>If you want to add new source files to libgfortran, you will have
>to edit libgfortran/Makefile.am and use --enable-maintainer-mode .
>The latter is a medium-sized PITA, because you need to get the
>versions of the required tools exactly right.
>
>I would also avoid using files generated from m4 at the time being.
>That is another steep learning curve.
>
>I hope this helps somewhat.
>
>Out of curiosity: What intrinsics are you trying to implement?
>
>Best regards
>
>	Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-06 19:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 19:21 Guide to adding intrinsic functions to gfortran W Spector
2020-09-05 19:35 ` Damian Rouson
2020-09-06  9:28 ` Thomas Koenig
2020-09-06 19:20 Walter Spector

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).