new proposal to vector intrinsics in Fortran
Sa Liu
SALIU@de.ibm.com
Wed Nov 28 22:17:00 GMT 2007
Hello,
After the abortion of the discussion about integrating target specific
vector intrinsic functions in Gfortran frontend (
http://gcc.gnu.org/ml/fortran/2007-10/msg00230.html), we then tried to
find a workaround to minimize changes in frontend code.
As Fortran 2003 allows calling C functions in Fortran program, we could
create for each backend a Fortran interface module, which consists of a
list of functions, binding with their target builtins. By using this
module, the Fortran program can call the builtin functions, as if they
were normal C functions.
Taken a SPU intrinsic spu_sync as an simple example:
module spu_intrinsics
use, intrinsic :: iso_c_binding
implicit none
interface
subroutine spu_sync() bind(c, name="__builtin_si_sync")
end subroutine spu_sync
end interface
end module spu_intrinsics
program driver
use spu_intrinsics
call spu_sync()
end program driver
When reading the generated mod file, the spu_sync symbol is then saved in
the program's namespace, and the binding label __builtin_si_sync could be
used to connect the backend builtin. The only change we need in Fortran
frontend, is then to bind these symbols' backend_decl with their function
decls.
Fortunately we already have these decls in frontend. When the frontend
initialize builtins, it also calls targetm.init_buitins() to initialize
backend builtins. The idea here is to build a new gfc_namspace, say
backend_intrinsic_namespace, then keep the decls in it, and later bind the
decls with there corresponding symbols in the interface module.
We thought about building the new namespace in gfc_builtin_function, and
in gfc_get_extern_function_decl, search the decl in this namespace, link
the symbol with it if found any, before the frontend builds a new one.
Through the backend_decl the frontend can then resolve the intrinsic
functions.
Besides, we would still like to add the vector data type extension to
Fortran frontend. The vector types could be initialized based on supported
vector modes of a certain target, and by this means the other platform
could manipulate their own vector data. The ISO-C bindings are to be
extended with the new vector types too. Of course the whole vector stuff
will be hidden behind a flag, and the users who don't program with vector
will not be disturbed by this new feature.
Is this something probably acceptable by Gfortran? Any ideas, revisions,
suggestions, criticisms... are welcome!
Thanks!
Sa
More information about the Fortran
mailing list