public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work096)] Make 'w' the __ibm128 suffix.
@ 2022-08-04 22:49 Michael Meissner
  0 siblings, 0 replies; only message in thread
From: Michael Meissner @ 2022-08-04 22:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2c88d13fe7db79d7fbb7deb2254922988542e733

commit 2c88d13fe7db79d7fbb7deb2254922988542e733
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Aug 4 18:49:19 2022 -0400

    Make 'w' the __ibm128 suffix.
    
    In writing code with __ibm128 support, it would be nice if we supported a suffix
    that marked __ibm128 constants.  The preprocessor lexer supports using either
    'q'/'Q' or 'w'/'W' as machine dependent suffixes.  The 'q'/'Q' suffix was
    already taken for __float128 constants, so I added 'w' or 'W' as the suffix for
    the __ibm128 constant.
    
    I went to the file doc/extend.texi to document using a 'w' or 'W' suffix, but it
    appears that we already had documented using 'w'/'W' for __ibm128.  This code
    adds this support to the GCC compiler.
    
    2022-08-04   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs6000.cc (rs6000_c_mode_for_suffix): Add support for
            using 'w' or 'W' as the __ibm128 bit constant.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/ibm128-suffix.c: New test.

Diff:
---
 gcc/config/rs6000/rs6000.cc                      | 15 ++----
 gcc/testsuite/gcc.target/powerpc/ibm128-suffix.c | 66 ++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 11 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 9d79fc0bb69..e13b6653fa9 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -23789,18 +23789,11 @@ rs6000_floatn_mode (int n, bool extended)
 static machine_mode
 rs6000_c_mode_for_suffix (char suffix)
 {
-  if (TARGET_FLOAT128_TYPE)
-    {
-      if (suffix == 'q' || suffix == 'Q')
-	return KFmode;
+  if (TARGET_FLOAT128_TYPE && (suffix == 'q' || suffix == 'Q'))
+    return KFmode;
 
-      /* At the moment, we are not defining a suffix for IBM extended double.
-	 If/when the default for -mabi=ieeelongdouble is changed, and we want
-	 to support __ibm128 constants in legacy library code, we may need to
-	 re-evalaute this decision.  Currently, c-lex.cc only supports 'w' and
-	 'q' as machine dependent suffixes.  The x86_64 port uses 'w' for
-	 __float80 constants.  */
-    }
+  else if (TARGET_IBM128 && (suffix == 'w' || suffix == 'W'))
+    return IFmode;
 
   return VOIDmode;
 }
diff --git a/gcc/testsuite/gcc.target/powerpc/ibm128-suffix.c b/gcc/testsuite/gcc.target/powerpc/ibm128-suffix.c
new file mode 100644
index 00000000000..5c3d0562c90
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/ibm128-suffix.c
@@ -0,0 +1,66 @@
+/* { dg-do run } */
+/* { dg-require-effective-target longdouble128 } */
+/* { dg-options "-O2" } */
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
+/* Test whether the 'w' suffix creates appropriate __ibm128 bit constants.  */
+
+#ifndef NUMBER
+#define NUMBER  123456789012345678901234567890123456.789
+#endif
+
+#define GLUE2(X,Y)      X ## Y
+#define GLUE(X,Y)       GLUE2(X,Y)
+
+/* Full 128-bit constant.  */
+__ibm128 i128_with_128bit_constant = GLUE(NUMBER,W);
+
+/* 64-bit constant that will fill in the bottom 64-bits with 0.  */
+__ibm128 i128_with_64bit_constant = NUMBER;
+
+/* 64-bit constant.  */
+double d64 = NUMBER;
+
+int
+main (void)
+{
+  double hi_1 = __builtin_unpack_ibm128 (i128_with_128bit_constant, 0);
+  double lo_1 = __builtin_unpack_ibm128 (i128_with_128bit_constant, 1);
+
+  double hi_2 = __builtin_unpack_ibm128 (i128_with_64bit_constant, 0);
+  double lo_2 = __builtin_unpack_ibm128 (i128_with_64bit_constant, 1);
+
+#ifdef DEBUG
+  printf ("i128_with_128bit_constant: (%.20g, %.20g)\n", hi_1, lo_1);
+  printf ("i128_with_64bit_constant: (%.20g, %.20g)\n", hi_2, lo_2);
+  printf ("d64: %.20g\n", d64);
+#endif
+
+  /* check sizes.  */
+  if (sizeof (NUMBER) != 8)
+    abort ();
+
+  if (sizeof (GLUE(NUMBER,W)) != 16)
+    abort ();
+
+  /* check if constant with 'w' suffix creates the full 128-bits.  */
+  if (hi_1 != d64 || lo_1 == 0.0)
+    abort ();
+
+  /* check if constant without 'w' suffix creates a 64-bit constant which is
+     zero extended to 128-bit.  */
+  if (hi_2 != d64 || lo_2 != 0.0)
+    abort ();
+
+#ifdef DEBUG
+  printf ("No errors\n");
+#endif
+
+  return 0;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-04 22:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 22:49 [gcc(refs/users/meissner/heads/work096)] Make 'w' the __ibm128 suffix Michael Meissner

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).