public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [fixed-point] Add tests for unary and binary operators
@ 2007-03-01  0:46 Fu, Chao-Ying
  0 siblings, 0 replies; only message in thread
From: Fu, Chao-Ying @ 2007-03-01  0:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Thekkath, Radhika, Stephens, Nigel

[-- Attachment #1: Type: text/plain, Size: 721 bytes --]

Hi,

  This patch fixed bugs when setting the maximum value for SSADD, SSSUB and SSNEG.
Two new fixed-point tests are added.  Thanks!

Regards,
Chao-ying

gcc/ChangeLog
2007-02-28  Chao-ying Fu  <fu@mips.com>

	* config/fixed-bit.c (stdio.h): Remove include.
	(FIXED_SSADD): Test x >= 0 to set the maximum value.
	(FIXED_SSSUB): Test x >= 0 to set the maximum value.
	(FIXED_SSNEG): Test x >= 0 to set the maximum value.
	* config/mips/mips.md (mips-fixed.md): Comment it out to test the
	emulation library.

gcc/testsuite/ChangeLog
2007-02-28  Chao-ying Fu  <fu@mips.com>

	* gcc.dg/fixed-ponit/unary.c: New test for unary operators.
	* gcc.dg/fixed-ponit/binary.c: New test for binary operators.

[-- Attachment #2: gcc.diff --]
[-- Type: application/octet-stream, Size: 12836 bytes --]

Index: config/fixed-bit.c
===================================================================
--- config/fixed-bit.c	(revision 122380)
+++ config/fixed-bit.c	(working copy)
@@ -37,8 +37,6 @@
    TA_MODE, UTA_MODE.
    Then, all operators for this machine mode will be created.  */
 
-#include <stdio.h>
-
 #include "tconfig.h"
 #include "tsystem.h"
 #include "coretypes.h"
@@ -83,7 +81,7 @@
         {
           z = 1;
           z = z << I_F_BITS;
-          if (x > 0)
+          if (x >= 0)
             z--;
         }
     }
@@ -155,7 +153,7 @@
         {
           z = 1;
           z = z << I_F_BITS;
-          if (x > 0)
+          if (x >= 0)
             z--;
         }
     }
@@ -564,7 +562,7 @@
         {
           z = 1;
           z = z << I_F_BITS;
-          if (x > 0)
+          if (x >= 0)
             z--;
         }
     }
Index: config/mips/mips.md
===================================================================
--- config/mips/mips.md	(revision 122380)
+++ config/mips/mips.md	(working copy)
@@ -5515,4 +5515,4 @@
 
 (include "mips-dsp.md")
 
-(include "mips-fixed.md")
+; (include "mips-fixed.md")
Index: testsuite/gcc.dg/fixed-point/unary.c
===================================================================
--- testsuite/gcc.dg/fixed-point/unary.c	(revision 0)
+++ testsuite/gcc.dg/fixed-point/unary.c	(revision 0)
@@ -0,0 +1,241 @@
+/* { dg-do run } */
+/* { dg-options "-std=gnu99" } */
+
+extern void abort (void);
+
+/* Check unary operators ++ -- + - !.  */
+
+#define INCDEC(TYPE,POSTFIX) \
+  { TYPE a = 0.0 ## POSTFIX; \
+    if (a++ != 0.0 ## POSTFIX) \
+      abort(); \
+    if (a != 1.0 ## POSTFIX) \
+      abort(); \
+    if (a-- != 1.0 ## POSTFIX) \
+      abort(); \
+    if (a != 0.0 ## POSTFIX) \
+      abort(); \
+    if (++a != 1.0 ## POSTFIX) \
+      abort(); \
+    if (a != 1.0 ## POSTFIX) \
+      abort(); \
+    if (--a != 0.0 ## POSTFIX) \
+      abort(); \
+    if (a != 0.0 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_INCDEC(TYPE,POSTFIX) \
+  { TYPE a = 0.9 ## POSTFIX; \
+    if (++a != 1.0 ## POSTFIX) \
+      abort(); \
+    a = -0.1 ## POSTFIX; \
+    if (--a != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_UNS_INCDEC(TYPE,POSTFIX) \
+  { TYPE a = 0.9 ## POSTFIX; \
+    if (++a != 1.0 ## POSTFIX) \
+      abort(); \
+    a = 0.1 ## POSTFIX; \
+    if (--a != 0.0 ## POSTFIX) \
+      abort(); \
+  }
+
+#define PLUS(TYPE,POSTFIX) \
+  { TYPE a = 0.1 ## POSTFIX; \
+    if (+a != 0.1 ## POSTFIX) \
+      abort(); \
+  }
+
+#define NEG(TYPE,POSTFIX) \
+  { TYPE a = -0.1 ## POSTFIX; \
+    if (-a != 0.1 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_NEG(TYPE,POSTFIX) \
+  { TYPE a = -0.5 ## POSTFIX - 0.5 ## POSTFIX; \
+    if (-a != 1.0 ## POSTFIX) \
+      abort(); \
+  }
+
+#define UNS_NEG(TYPE,POSTFIX) \
+  { TYPE a = 0.0 ## POSTFIX; \
+    if (-a != 0.0 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_UNS_NEG(TYPE,POSTFIX) \
+  { TYPE a = 0.5 ## POSTFIX; \
+    if (-a != 0.0 ## POSTFIX) \
+      abort(); \
+  }
+
+#define LOGNEG(TYPE,POSTFIX) \
+  { TYPE a = 0.0 ## POSTFIX; \
+    TYPE b = 0.1 ## POSTFIX; \
+    if (!a != 1) \
+      abort(); \
+    if (!b != 0) \
+      abort(); \
+  }
+
+int main ()
+{
+  INCDEC(short _Fract, hr);
+  INCDEC(_Fract, r);
+  INCDEC(long _Fract, lr);
+  INCDEC(long long _Fract, llr);
+  INCDEC(unsigned short _Fract, uhr);
+  INCDEC(unsigned _Fract, ur);
+  INCDEC(unsigned long _Fract, ulr);
+  INCDEC(unsigned long long _Fract, ullr);
+  INCDEC(_Sat short _Fract, hr);
+  INCDEC(_Sat _Fract, r);
+  INCDEC(_Sat long _Fract, lr);
+  INCDEC(_Sat long long _Fract, llr);
+  INCDEC(_Sat unsigned short _Fract, uhr);
+  INCDEC(_Sat unsigned _Fract, ur);
+  INCDEC(_Sat unsigned long _Fract, ulr);
+  INCDEC(_Sat unsigned long long _Fract, ullr);
+  INCDEC(short _Accum, hk);
+  INCDEC(_Accum, k);
+  INCDEC(long _Accum, lk);
+  INCDEC(long long _Accum, llk);
+  INCDEC(unsigned short _Accum, uhk);
+  INCDEC(unsigned _Accum, uk);
+  INCDEC(unsigned long _Accum, ulk);
+  INCDEC(unsigned long long _Accum, ullk);
+  INCDEC(_Sat short _Accum, hk);
+  INCDEC(_Sat _Accum, k);
+  INCDEC(_Sat long _Accum, lk);
+  INCDEC(_Sat long long _Accum, llk);
+  INCDEC(_Sat unsigned short _Accum, uhk);
+  INCDEC(_Sat unsigned _Accum, uk);
+  INCDEC(_Sat unsigned long _Accum, ulk);
+  INCDEC(_Sat unsigned long long _Accum, ullk);
+
+  FRACT_SAT_INCDEC(_Sat short _Fract, hr);
+  FRACT_SAT_INCDEC(_Sat _Fract, r);
+  FRACT_SAT_INCDEC(_Sat long _Fract, lr);
+  FRACT_SAT_INCDEC(_Sat long long _Fract, llr);
+
+  FRACT_SAT_UNS_INCDEC(_Sat unsigned short _Fract, uhr);
+  FRACT_SAT_UNS_INCDEC(_Sat unsigned _Fract, ur);
+  FRACT_SAT_UNS_INCDEC(_Sat unsigned long _Fract, ulr);
+  FRACT_SAT_UNS_INCDEC(_Sat unsigned long long _Fract, ullr);
+
+  PLUS(short _Fract, hr);
+  PLUS(_Fract, r);
+  PLUS(long _Fract, lr);
+  PLUS(long long _Fract, llr);
+  PLUS(unsigned short _Fract, uhr);
+  PLUS(unsigned _Fract, ur);
+  PLUS(unsigned long _Fract, ulr);
+  PLUS(unsigned long long _Fract, ullr);
+  PLUS(_Sat short _Fract, hr);
+  PLUS(_Sat _Fract, r);
+  PLUS(_Sat long _Fract, lr);
+  PLUS(_Sat long long _Fract, llr);
+  PLUS(_Sat unsigned short _Fract, uhr);
+  PLUS(_Sat unsigned _Fract, ur);
+  PLUS(_Sat unsigned long _Fract, ulr);
+  PLUS(_Sat unsigned long long _Fract, ullr);
+  PLUS(short _Accum, hk);
+  PLUS(_Accum, k);
+  PLUS(long _Accum, lk);
+  PLUS(long long _Accum, llk);
+  PLUS(unsigned short _Accum, uhk);
+  PLUS(unsigned _Accum, uk);
+  PLUS(unsigned long _Accum, ulk);
+  PLUS(unsigned long long _Accum, ullk);
+  PLUS(_Sat short _Accum, hk);
+  PLUS(_Sat _Accum, k);
+  PLUS(_Sat long _Accum, lk);
+  PLUS(_Sat long long _Accum, llk);
+  PLUS(_Sat unsigned short _Accum, uhk);
+  PLUS(_Sat unsigned _Accum, uk);
+  PLUS(_Sat unsigned long _Accum, ulk);
+  PLUS(_Sat unsigned long long _Accum, ullk);
+
+  NEG(short _Fract, hr);
+  NEG(_Fract, r);
+  NEG(long _Fract, lr);
+  NEG(long long _Fract, llr);
+  NEG(_Sat short _Fract, hr);
+  NEG(_Sat _Fract, r);
+  NEG(_Sat long _Fract, lr);
+  NEG(_Sat long long _Fract, llr);
+  NEG(short _Accum, hk);
+  NEG(_Accum, k);
+  NEG(long _Accum, lk);
+  NEG(long long _Accum, llk);
+  NEG(_Sat short _Accum, hk);
+  NEG(_Sat _Accum, k);
+  NEG(_Sat long _Accum, lk);
+  NEG(_Sat long long _Accum, llk);
+
+  FRACT_SAT_NEG(_Sat short _Fract, hr);
+  FRACT_SAT_NEG(_Sat _Fract, r);
+  FRACT_SAT_NEG(_Sat long _Fract, lr);
+  FRACT_SAT_NEG(_Sat long long _Fract, llr);
+
+  UNS_NEG(short _Fract, hr);
+  UNS_NEG(_Fract, r);
+  UNS_NEG(long _Fract, lr);
+  UNS_NEG(long long _Fract, llr);
+  UNS_NEG(_Sat short _Fract, hr);
+  UNS_NEG(_Sat _Fract, r);
+  UNS_NEG(_Sat long _Fract, lr);
+  UNS_NEG(_Sat long long _Fract, llr);
+  UNS_NEG(short _Accum, hk);
+  UNS_NEG(_Accum, k);
+  UNS_NEG(long _Accum, lk);
+  UNS_NEG(long long _Accum, llk);
+  UNS_NEG(_Sat short _Accum, hk);
+  UNS_NEG(_Sat _Accum, k);
+  UNS_NEG(_Sat long _Accum, lk);
+  UNS_NEG(_Sat long long _Accum, llk);
+
+  FRACT_SAT_UNS_NEG(_Sat unsigned short _Fract, uhr);
+  FRACT_SAT_UNS_NEG(_Sat unsigned _Fract, ur);
+  FRACT_SAT_UNS_NEG(_Sat unsigned long _Fract, ulr);
+  FRACT_SAT_UNS_NEG(_Sat unsigned long long _Fract, ullr);
+
+  LOGNEG(short _Fract, hr);
+  LOGNEG(_Fract, r);
+  LOGNEG(long _Fract, lr);
+  LOGNEG(long long _Fract, llr);
+  LOGNEG(unsigned short _Fract, uhr);
+  LOGNEG(unsigned _Fract, ur);
+  LOGNEG(unsigned long _Fract, ulr);
+  LOGNEG(unsigned long long _Fract, ullr);
+  LOGNEG(_Sat short _Fract, hr);
+  LOGNEG(_Sat _Fract, r);
+  LOGNEG(_Sat long _Fract, lr);
+  LOGNEG(_Sat long long _Fract, llr);
+  LOGNEG(_Sat unsigned short _Fract, uhr);
+  LOGNEG(_Sat unsigned _Fract, ur);
+  LOGNEG(_Sat unsigned long _Fract, ulr);
+  LOGNEG(_Sat unsigned long long _Fract, ullr);
+  LOGNEG(short _Accum, hk);
+  LOGNEG(_Accum, k);
+  LOGNEG(long _Accum, lk);
+  LOGNEG(long long _Accum, llk);
+  LOGNEG(unsigned short _Accum, uhk);
+  LOGNEG(unsigned _Accum, uk);
+  LOGNEG(unsigned long _Accum, ulk);
+  LOGNEG(unsigned long long _Accum, ullk);
+  LOGNEG(_Sat short _Accum, hk);
+  LOGNEG(_Sat _Accum, k);
+  LOGNEG(_Sat long _Accum, lk);
+  LOGNEG(_Sat long long _Accum, llk);
+  LOGNEG(_Sat unsigned short _Accum, uhk);
+  LOGNEG(_Sat unsigned _Accum, uk);
+  LOGNEG(_Sat unsigned long _Accum, ulk);
+  LOGNEG(_Sat unsigned long long _Accum, ullk);
+
+  return 0;
+}
Index: testsuite/gcc.dg/fixed-point/binary.c
===================================================================
--- testsuite/gcc.dg/fixed-point/binary.c	(revision 0)
+++ testsuite/gcc.dg/fixed-point/binary.c	(revision 0)
@@ -0,0 +1,150 @@
+/* { dg-do run } */
+/* { dg-options "-std=gnu99" } */
+
+extern void abort (void);
+
+/* Check binary operators + - * / << >> < <= >= > == != += -= *= /= <<= >>=.  */
+
+#define BINARY(TYPE,POSTFIX) \
+  { TYPE a = 0.5 ## POSTFIX; \
+    TYPE b = 0.25 ## POSTFIX; \
+    if (a + b != 0.75 ## POSTFIX) \
+      abort(); \
+    if (a - b != 0.25 ## POSTFIX) \
+      abort(); \
+    if (a * b != 0.125 ## POSTFIX) \
+      abort(); \
+    if (b / a != 0.5 ## POSTFIX) \
+      abort(); \
+    if (b << 1 != a) \
+      abort(); \
+    if (a >> 1 != b) \
+      abort(); \
+    if (a < b != 0) \
+      abort(); \
+    if (a <= b != 0) \
+      abort(); \
+    if (a > b != 1) \
+      abort(); \
+    if (a >= b != 1) \
+      abort(); \
+    if (a == b != 0) \
+      abort(); \
+    if (a != b != 1) \
+      abort(); \
+    a += b; \
+    if (a != 0.75 ## POSTFIX) \
+      abort(); \
+    a -= b; \
+    if (a != 0.5 ## POSTFIX) \
+      abort(); \
+    a *= b; \
+    if (a != 0.125 ## POSTFIX) \
+      abort(); \
+    a /= b; \
+    if (a != 0.5 ## POSTFIX) \
+      abort(); \
+    a >>= 2; \
+    if (a != 0.125 ## POSTFIX) \
+      abort(); \
+    a <<= 1; \
+    if (a != 0.25 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_BINARY(TYPE,POSTFIX) \
+  { TYPE a = 0.7 ## POSTFIX; \
+    TYPE b = 0.9 ## POSTFIX; \
+    if (a + b != 1.0 ## POSTFIX) \
+      abort(); \
+    a = -0.7 ## POSTFIX; \
+    b = -0.9 ## POSTFIX; \
+    if (a + b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
+      abort(); \
+    a = 0.7 ## POSTFIX; \
+    b = -0.9 ## POSTFIX; \
+    if (a - b != 1.0 ## POSTFIX) \
+      abort(); \
+    a = -0.7 ## POSTFIX; \
+    b = 0.9 ## POSTFIX; \
+    if (a - b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
+      abort(); \
+    a = -0.5 ## POSTFIX - 0.5 ## POSTFIX; \
+    if (a * a != 1.0 ## POSTFIX) \
+      abort(); \
+    a = 0.8 ## POSTFIX; \
+    b = 0.5 ## POSTFIX; \
+    if (a / b != 1.0 ## POSTFIX) \
+      abort(); \
+    a = -0.8 ## POSTFIX; \
+    b = 0.5 ## POSTFIX; \
+    if (a / b != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
+      abort(); \
+    a = 0.1 ## POSTFIX; \
+    if (a << 4 != 1.0 ## POSTFIX) \
+      abort(); \
+    a = -0.8 ## POSTFIX; \
+    if (a << 4 != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
+      abort(); \
+  }
+
+#define FRACT_SAT_UNS_BINARY(TYPE,POSTFIX) \
+  { TYPE a = 0.7 ## POSTFIX; \
+    TYPE b = 0.9 ## POSTFIX; \
+    if (a + b != 1.0 ## POSTFIX) \
+      abort(); \
+    if (a - b != 0.0 ## POSTFIX) \
+      abort(); \
+    if (b / a != 1.0 ## POSTFIX) \
+      abort(); \
+    if (a << 1 != 1.0 ## POSTFIX) \
+      abort(); \
+  }
+
+int main ()
+{
+  BINARY(short _Fract, hr);
+  BINARY(_Fract, r);
+  BINARY(long _Fract, lr);
+  BINARY(long long _Fract, llr);
+  BINARY(unsigned short _Fract, uhr);
+  BINARY(unsigned _Fract, ur);
+  BINARY(unsigned long _Fract, ulr);
+  BINARY(unsigned long long _Fract, ullr);
+  BINARY(_Sat short _Fract, hr);
+  BINARY(_Sat _Fract, r);
+  BINARY(_Sat long _Fract, lr);
+  BINARY(_Sat long long _Fract, llr);
+  BINARY(_Sat unsigned short _Fract, uhr);
+  BINARY(_Sat unsigned _Fract, ur);
+  BINARY(_Sat unsigned long _Fract, ulr);
+  BINARY(_Sat unsigned long long _Fract, ullr);
+  BINARY(short _Accum, hk);
+  BINARY(_Accum, k);
+  BINARY(long _Accum, lk);
+  BINARY(long long _Accum, llk);
+  BINARY(unsigned short _Accum, uhk);
+  BINARY(unsigned _Accum, uk);
+  BINARY(unsigned long _Accum, ulk);
+  BINARY(unsigned long long _Accum, ullk);
+  BINARY(_Sat short _Accum, hk);
+  BINARY(_Sat _Accum, k);
+  BINARY(_Sat long _Accum, lk);
+  BINARY(_Sat long long _Accum, llk);
+  BINARY(_Sat unsigned short _Accum, uhk);
+  BINARY(_Sat unsigned _Accum, uk);
+  BINARY(_Sat unsigned long _Accum, ulk);
+  BINARY(_Sat unsigned long long _Accum, ullk);
+
+  FRACT_SAT_BINARY(_Sat short _Fract, hr);
+  FRACT_SAT_BINARY(_Sat _Fract, r);
+  FRACT_SAT_BINARY(_Sat long _Fract, lr);
+  FRACT_SAT_BINARY(_Sat long long _Fract, llr);
+
+  FRACT_SAT_UNS_BINARY(_Sat unsigned short _Fract, uhr);
+  FRACT_SAT_UNS_BINARY(_Sat unsigned _Fract, ur);
+  FRACT_SAT_UNS_BINARY(_Sat unsigned long _Fract, ulr);
+  FRACT_SAT_UNS_BINARY(_Sat unsigned long long _Fract, ullr);
+
+  return 0;
+}

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

only message in thread, other threads:[~2007-03-01  0:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-01  0:46 [fixed-point] Add tests for unary and binary operators Fu, Chao-Ying

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