From patchwork Tue Mar 6 17:02:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 144961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 50F2CB6F98 for ; Wed, 7 Mar 2012 04:03:06 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1331658187; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=Dp+cNQD RP653PzgYhP6f9cd/X58=; b=BpqRkGEE3p5cdGYBeegfaOhiV3fnhbq/1msZ+Fs jFUl/WSu7LEllrmu5ws7tj1ZWs8JJdcyL3ij44AinU/lLZ8uScvSZBX3sTyHHj7S AzhvqoI5bT72hovfSypdbcHfCAtRSO+KKsnTzHf1Zc2D/Q3nHOUgH2xil4xNqCGc uU2k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=m4WtCXqXsOzgi3JBUE55KXIibKstQlNbnhFy8+a8JQJN+7jPwAsjLWhR5qHQdu yhCz5h3XWfVBcVK4nIubUuogsIzJBhQDjI6yZZDrLxc7ooptXio/9PPhf09yypAB 5TMQlsUEevWn28BNFsarZmpheapIBfnuE0yvEDHar5i1Y=; Received: (qmail 4883 invoked by alias); 6 Mar 2012 17:02:56 -0000 Received: (qmail 4857 invoked by uid 22791); 6 Mar 2012 17:02:53 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SUBJ_OBFU_PUNCT_FEW, SUBJ_OBFU_PUNCT_MANY, TW_SV X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Mar 2012 17:02:38 +0000 Received: from [192.168.178.22] (port-92-204-104-94.dynamic.qsc.de [92.204.104.94]) by mx01.qsc.de (Postfix) with ESMTP id 40BD73CA1F; Tue, 6 Mar 2012 18:02:32 +0100 (CET) Message-ID: <4F564327.7060502@net-b.de> Date: Tue, 06 Mar 2012 18:02:31 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120215 Thunderbird/10.0.2 MIME-Version: 1.0 To: gfortran , gcc patches Subject: [Fortran-dev] Merged from trunk; [patch, committed] ISO_Fortran_binding.h Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Dear Paul, dear all, I have merged (Rev. 184999) the trunk (Rev. 184980) to the fortran-dev branch, which now followed GCC 4.8. Additionally, I have committed to the fortran-dev branch (Rev. 185004) the first rough and incomplete version of ISO_Fortran_binding.h, which tries to follow TS 29113. In terms of the generated code, it should mostly be a no op, except that GFC_DIMENSION_SET now also sets the extent. (See attachment. I wrote it some weeks ago, but I think it makes sense to have it already in svn despite its embryonic state.) The library currently does not set "sm" - thus, it breaks if the compiler itself expects this. The library currently also only handles the old ubound/stride - thus, if the compiler does not properly set those, it will also fail. I have not checked what the compiler currently uses. At least in simple cases, it sets both the old ubound/stride and the new sm/extent. The "sm" information needs the element size in bytes. In order to obtain it, it is insufficient to modify only libgfortran.h's macros - thus, a larger patch is required. Most convenient would be if one could directly convert the code to only use sm/extent, but it should be also possible to write the code such that also ubound/stride are set. But before starting this, the compiler itself needs to be in a reasonable state such that one can easily assign the breakage. - It might be, but I have not looked at the generated code for more than a year. - Additional, new code (inline sum and other features) might have to be first updated, though, updating after the library changes might be also possible. Tobias PS: I do *not* intent to work on fortran-dev in the next weeks. However, I might work on it during the 4.8 development. Index: libgfortran/ChangeLog.fortran-dev =================================================================== --- libgfortran/ChangeLog.fortran-dev (revision 184980) +++ libgfortran/ChangeLog.fortran-dev (working copy) @@ -1,3 +1,10 @@ +2012-03-06 Tobias Burnus + + * ISO_Fortran_binding.h: New. + * libgfortran.h: Include it. + (descriptor_dimension): Replace by a CFI_dim_t typedef. + (GFC_DIMENSION_SET): Also set extent. + 2010-09-01 Paul Thomas * libgfortran.h: Add 'sm' and 'extent' fields to structure Index: libgfortran/libgfortran.h =================================================================== --- libgfortran/libgfortran.h (revision 184980) +++ libgfortran/libgfortran.h (working copy) @@ -319,26 +319,13 @@ internal_proto(big_endian); # endif #endif -typedef struct descriptor_dimension -{ - index_type _stride; - index_type _lbound; - index_type _ubound; - index_type _sm; - index_type _extent; -} -descriptor_dimension; +#include "ISO_Fortran_binding.h" -#define GFC_ARRAY_DESCRIPTOR(r, type) \ -struct {\ - type *data;\ - size_t offset;\ - index_type dtype;\ - index_type size;\ - descriptor_dimension dim[r];\ -} +typedef CFI_dim_t descriptor_dimension; +#define GFC_ARRAY_DESCRIPTOR(r, type) CFI_GFC_CDESC_T (r, type) + /* Commonly used array descriptor types. */ typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void; typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char; @@ -381,23 +368,31 @@ typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data) #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype) -#define GFC_DIMENSION_LBOUND(dim) ((dim)._lbound) +#define GFC_DIMENSION_LBOUND(dim) ((dim).lower_bound) +/* Old. */ #define GFC_DIMENSION_UBOUND(dim) ((dim)._ubound) -#define GFC_DIMENSION_STRIDE(dim) ((dim)._stride) -#define GFC_DIMENSION_EXTENT(dim) ((dim)._ubound + 1 - (dim)._lbound) +#define GFC_DIMENSION_EXTENT(dim) ((dim).ubound + 1 - (dim).lower_bound) + +/* New. */ +/* + #define GFC_DIMENSION_UBOUND(dim) ((dim).lower_bound + (dim).extent - 1) + #define GFC_DIMENSION_EXTENT(dim) ((dim).extent) +*/ + #define GFC_DIMENSION_SET(dim,lb,ub,str) \ do \ { \ - (dim)._lbound = lb; \ + (dim).lower_bound = lb; \ (dim)._ubound = ub; \ + (dim).extent = ub-lb+1; \ (dim)._stride = str; \ } while (0) -#define GFC_DESCRIPTOR_LBOUND(desc,i) ((desc)->dim[i]._lbound) +#define GFC_DESCRIPTOR_LBOUND(desc,i) ((desc)->dim[i].lower_bound) #define GFC_DESCRIPTOR_UBOUND(desc,i) ((desc)->dim[i]._ubound) #define GFC_DESCRIPTOR_EXTENT(desc,i) ((desc)->dim[i]._ubound + 1 \ - - (desc)->dim[i]._lbound) + - (desc)->dim[i].lower_bound) #define GFC_DESCRIPTOR_EXTENT_BYTES(desc,i) \ (GFC_DESCRIPTOR_EXTENT(desc,i) * GFC_DESCRIPTOR_SIZE(desc)) Index: libgfortran/ISO_Fortran_binding.h =================================================================== --- libgfortran/ISO_Fortran_binding.h (revision 0) +++ libgfortran/ISO_Fortran_binding.h (working copy) @@ -0,0 +1,176 @@ +/* ISO_Fortran_binding.h of GCC's GNU Fortran compiler. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of the GNU Fortran runtime library (libgfortran) +Libgfortran is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libgfortran is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libquadmath; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + + +/* Definitions as defined by ISO/IEC Technical Specification TS 29113 + on Further Interoperability of Fortran with C. + Note: The technical specification only mandates the presence of certain + members; there might be additional compiler-specific fields. */ + + +#ifndef ISO_FORTRAN_BINDING_H +#define ISO_FORTRAN_BINDING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include /* For size_t and ptrdiff_t. */ + + +/* Constants, defined as macros. */ + +#define CFI_VERSION 1 +#define CFI_MAX_RANK 15 + +#define CFI_attribute_pointer 1 +#define CFI_attribute_allocatable 2 +#define CFI_attribute_other 3 + + +/* FIXME: Those values have to match the compiler itself. + "NOTE 8.5: The specifiers for two intrinsic types can have the same value. + For example, CFI_type_int and CFI_type_int32_t might have the same value." + + "The value for CFI_type_other shall be negative and distinct from all other + type specifiers. CFI_type_struct specifies a C structure that is + interoperable with a Fortran derived type; its value shall be positive and + distinct from all other type specifiers. If a C type is not interoperable + with a Fortran type and kind supported by the Fortran processor, its macro + shall evaluate to a negative value. Otherwise, the value for an intrinsic + type shall be positive." */ + +#define CFI_type_signed_char 1 +#define CFI_type_short 2 +#define CFI_type_int 3 +#define CFI_type_long 4 +#define CFI_type_long_long 5 +#define CFI_type_size_t 6 +#define CFI_type_int8_t 7 +#define CFI_type_int16_t 8 +#define CFI_type_int32_t 9 +#define CFI_type_int64_t 10 +#define CFI_type_int_least8_t 11 +#define CFI_type_int_least16_t 12 +#define CFI_type_int_least32_t 13 +#define CFI_type_int_least64_t 14 +#define CFI_type_int_fast8_t 15 +#define CFI_type_int_fast16_t 16 +#define CFI_type_int_fast32_t 17 +#define CFI_type_int_fast64_t 18 +#define CFI_type_intmax_t 19 +#define CFI_type_intptr_t 20 +#define CFI_type_ptrdiff_t 21 +#define CFI_type_float 22 +#define CFI_type_double 23 +#define CFI_type_long_double 24 +#define CFI_type_float_Complex 25 +#define CFI_type_double_Complex 26 +#define CFI_type_long_double_Complex 27 +#define CFI_type_Bool 28 +#define CFI_type_char 29 +#define CFI_type_cptr 30 +#define CFI_type_cfunptr 31 +#define CFI_type_struct 32 +#define CFI_type_other -5 + +#define CFI_SUCCESS 0 +#define CFI_ERROR_BASE_ADDR_NULL 1 +#define CFI_ERROR_BASE_ADDR_NOT_NULL 2 +#define CFI_INVALID_ELEM_LEN 3 +#define CFI_INVALID_RANK 4 +#define CFI_INVALID_TYPE 5 +#define CFI_INVALID_ATTRIBUTE 6 +#define CFI_INVALID_EXTENT 7 +#define CFI_INVALID_DESCRIPTOR 8 +#define CFI_ERROR_MEM_ALLOCATION 9 +#define CFI_ERROR_OUT_OF_BOUNDS 10 + + +/* Types definitions. */ + +typedef ptrdiff_t CFI_index_t; +typedef int32_t CFI_attribute_t; +typedef int32_t CFI_type_t; +typedef int32_t CFI_rank_t; + +typedef struct CFI_dim_t +{ + CFI_index_t _stride; /* gfortran extension. */ + CFI_index_t lower_bound; + CFI_index_t _ubound; /* gfortran extension. */ + CFI_index_t sm; + CFI_index_t extent; +} +CFI_dim_t; + +typedef struct CFI_cdesc_t +{ + void *data; /* FIXME: Should be "base_addr". */ + size_t elem_len; + int version; + CFI_rank_t rank; + CFI_type_t type; + CFI_attribute_t attribute; + /*FIXME: corank? Other information? Padding? Or not needed + due to "version"? */ + CFI_dim_t dim[CFI_MAX_RANK]; /* Must be last field */ +} +CFI_cdesc_t; + + +/* gfortran extension: Type-specific array descriptor. + FIXME: Shall be the same as CFI_cdesc_t at the end. */ + +#define CFI_GFC_CDESC_T(r, type) \ +struct {\ + type *data;\ + size_t offset;\ + CFI_index_t dtype;\ + CFI_index_t size;\ + CFI_dim_t dim[r];\ +} + +#define CFI_CDESC_T(r) CFI_GFC_CDESC_T (r, void) + + +/* Functions. */ + +void *CFI_address (const CFI_cdesc_t *dv, const CFI_index_t subscripts[]); +int CFI_allocate (CFI_cdesc_t *dv, const CFI_index_t lower_bounds[], + const CFI_index_t upper_bounds[], size_t elem_len); +int CFI_deallocate (CFI_cdesc_t *dv); +int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute, + CFI_type_t type, size_t elem_len, CFI_rank_t rank, + const CFI_index_t extents[]); +int CFI_is_contiguous (const CFI_cdesc_t *dv); +int CFI_section (CFI_cdesc_t *result, const CFI_cdesc_t *source, + const CFI_index_t lower_bounds[], + const CFI_index_t upper_bounds[], + const CFI_index_t strides[]); +int CFI_select_part (CFI_cdesc_t *result, const CFI_cdesc_t *source, + size_t displacement, size_t elem_len); +int CFI_setpointer (CFI_cdesc_t *result, CFI_cdesc_t *source, + const CFI_index_t lower_bounds[]); + +#ifdef __cplusplus +} +#endif + +#endif /* ISO_FORTRAN_BINDING_H */