From patchwork Mon Jan 10 22:44:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 49819 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 300FF3835C1E for ; Mon, 10 Jan 2022 22:45:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 300FF3835C1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641854713; bh=J5OSx20z03a8mrtCDM0zU8dflBfazuaRH5XfRrvTBd8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=iZWZpgY+6KukP30qFLm/T7U+nMM0wobPeImrOJ0BEop+IIwodGBRzguujZUJRpG37 AubucwtjWxrUmgSAOBwpRd7XHNLNMPc4N8qDyEsgD6OhNrgPu8WHyl84AZyesK8UYU 4kylx7CiEdJo5g2FzO0DZSmX2IFs1JiUavzM6uOU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout1.netcologne.de (cc-smtpout1.netcologne.de [89.1.8.211]) by sourceware.org (Postfix) with ESMTPS id 4BCE43858C3A; Mon, 10 Jan 2022 22:44:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4BCE43858C3A Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id B0FEC13123; Mon, 10 Jan 2022 23:44:24 +0100 (CET) Received: from [IPv6:2a0a:a540:3bd5:0:7285:c2ff:fe6c:992d] (2a0a-a540-3bd5-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2a0a:a540:3bd5:0:7285:c2ff:fe6c:992d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id 295D111DEB; Mon, 10 Jan 2022 23:44:13 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches Subject: [power-ieee128, committed] Enable conversion selection via environment variable Message-ID: Date: Mon, 10 Jan 2022 23:44:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Language: en-US X-NetCologne-Spam: L X-Rspamd-Queue-Id: 295D111DEB X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Cc: Jakub Jelinek , Michael Meissner Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hello world, I have just pushed the attched patch to the branch. With this patch, the program tkoenig@gcc-fortran:~/Tst$ cat write_env.f90 program main real(kind=16) :: x character (len=30) :: conv x = 1/3._16 open (10,file="out.dat",status="replace",access="stream",form="unformatted") inquire(10,convert=conv) print *,conv write (10) 1/3._16 end program main gives the result: tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="r16_ibm:10" ./a.out && od -w64 -t x1 out.dat LITTLE_ENDIAN,R16_IBM 0000000 55 55 55 55 55 55 d5 3f 56 55 55 55 55 55 75 3c 0000020 tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="r16_ieee:10" ./a.out && od -w64 -t x1 out.dat LITTLE_ENDIAN,R16_IEEE 0000000 80 55 55 55 55 55 55 55 55 55 55 55 55 55 fd 3f 0000020 tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="big_endian:10;r16_ieee:10" ./a.out && od -w64 -t x1 out.dat BIG_ENDIAN,R16_IEEE 0000000 3f fd 55 55 55 55 55 55 55 55 55 55 55 55 55 80 0000020 so things look OK. In the next few days, I will do a bit more testing to see if I have missed any corner cases. So, the only thing missing is handling of the options, but I think that is not critical (and could be added later; two separate possibilities might just be enough for most users :-) So... time to merge the branch into trunk before stage 4 kicks in? Best regards Thomas Handle R16 conversion for POWER in the environment variables. This patch handles the environment variables for the REAL(KIND=16) variables like for the little/big-endian routines, so users without who have no access to the source or are unwilling to recompile can use this. Syntax is, for example GFORTRAN_CONVERT_UNIT="r16_ieee:10;little_endian:10" ./a.out libgfortran/ChangeLog: * runtime/environ.c (R16_IEEE): New macro. (R16_IBM): New macro. (next_token): Handle IBM R16 conversion cases. (push_token): Likewise. (mark_single): Likewise. (do_parse): Likewise, initialize endian. diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c index fe16c080797..ff10fe53f68 100644 --- a/libgfortran/runtime/environ.c +++ b/libgfortran/runtime/environ.c @@ -247,6 +247,11 @@ init_variables (void) #define SWAP 258 #define BIG 259 #define LITTLE 260 +#ifdef HAVE_GFC_REAL_17 +#define R16_IEEE 261 +#define R16_IBM 262 +#endif + /* Some space for additional tokens later. */ #define INTEGER 273 #define END (-1) @@ -392,6 +397,15 @@ next_token (void) result = match_word ("swap", SWAP); break; +#ifdef HAVE_GFC_REAL_17 + case 'r': + case 'R': + result = match_word ("r16_ieee", R16_IEEE); + if (result == ILLEGAL) + result = match_word ("r16_ibm", R16_IBM); + break; + +#endif case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': result = match_integer (); @@ -414,7 +428,8 @@ push_token (void) /* This is called when a unit is identified. If do_count is nonzero, increment the number of units by one. If do_count is zero, - put the unit into the table. */ + put the unit into the table. For POWER, we have to make sure that + we can also put in the conversion btween IBM and IEEE long double. */ static void mark_single (int unit) @@ -428,7 +443,11 @@ mark_single (int unit) } if (search_unit (unit, &i)) { +#ifdef HAVE_GFC_REAL_17 + elist[i].conv |= endian; +#else elist[i].conv = endian; +#endif } else { @@ -437,7 +456,11 @@ mark_single (int unit) n_elist += 1; elist[i].unit = unit; +#ifdef HAVE_GFC_REAL_17 + elist[i].conv |= endian; +#else elist[i].conv = endian; +#endif } } @@ -481,6 +504,8 @@ do_parse (void) /* Parse the string. First, let's look for a default. */ tok = next_token (); + endian = 0; + switch (tok) { case NATIVE: @@ -499,6 +524,15 @@ do_parse (void) endian = GFC_CONVERT_LITTLE; break; +#ifdef HAVE_GFC_REAL_17 + case R16_IEEE: + endian = GFC_CONVERT_R16_IEEE; + break; + + case R16_IBM: + endian = GFC_CONVERT_R16_IBM; + break; +#endif case INTEGER: /* A leading digit means that we are looking at an exception. Reset the position to the beginning, and continue processing @@ -571,6 +605,19 @@ do_parse (void) goto error; endian = GFC_CONVERT_BIG; break; +#ifdef HAVE_GFC_REAL_17 + case R16_IEEE: + if (next_token () != ':') + goto error; + endian = GFC_CONVERT_R16_IEEE; + break; + + case R16_IBM: + if (next_token () != ':') + goto error; + endian = GFC_CONVERT_R16_IBM; + break; +#endif case INTEGER: push_token ();