public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] API extension: add GCC_JIT_UNARY_OP_ABS to enum gcc_jit_unary_op
@ 2015-01-01  0:00 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2015-01-01  0:00 UTC (permalink / raw)
  To: jit, gcc-patches; +Cc: David Malcolm

This adds GCC_JIT_UNARY_OP_ABS to the end of enum gcc_jit_unary_op,
and so should not change ABI.

Takes jit.sum from:
  # of expected passes       6121
to:
  # of expected passes       6196

Committed to trunk as r219321.

gcc/jit/ChangeLog:
	* docs/topics/expressions.rst (Unary Operations): Add
	GCC_JIT_UNARY_OP_ABS.
	* jit-playback.c (gcc::jit::playback::context::new_unary_op):
	Likewise.
	* jit-recording.c (unary_op_strings): Likewise.
	* libgccjit.c (gcc_jit_context_new_unary_op): Update checking
	of "op" to reflect addition of GCC_JIT_UNARY_OP_ABS.
	* libgccjit.h (enum gcc_jit_unary_op): Add GCC_JIT_UNARY_OP_ABS.
	* docs/_build/texinfo/libgccjit.texi: Regenerate.

gcc/testsuite/ChangeLog:
	* jit.dg/test-expressions.c (make_tests_of_unary_ops): Add test of
	GCC_JIT_UNARY_OP_ABS.
	(verify_unary_ops): Likewise.
---
 gcc/jit/docs/topics/expressions.rst     | 11 +++++++++++
 gcc/jit/jit-playback.c                  |  4 ++++
 gcc/jit/jit-recording.c                 |  1 +
 gcc/jit/libgccjit.c                     |  2 +-
 gcc/jit/libgccjit.h                     |  8 +++++++-
 gcc/testsuite/jit.dg/test-expressions.c | 13 +++++++++++++
 6 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst
index 1cf9641..72a1085 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -137,6 +137,7 @@ Unary Operation                             C equivalent
 :c:macro:`GCC_JIT_UNARY_OP_MINUS`           `-(EXPR)`
 :c:macro:`GCC_JIT_UNARY_OP_BITWISE_NEGATE`  `~(EXPR)`
 :c:macro:`GCC_JIT_UNARY_OP_LOGICAL_NEGATE`  `!(EXPR)`
+:c:macro:`GCC_JIT_UNARY_OP_ABS`             `abs (EXPR)`
 ==========================================  ============
 
 .. c:macro:: GCC_JIT_UNARY_OP_MINUS
@@ -170,6 +171,16 @@ Unary Operation                             C equivalent
 
     in C.
 
+.. c:macro:: GCC_JIT_UNARY_OP_ABS
+
+    Absolute value of an arithmetic expression; analogous to:
+
+    .. code-block:: c
+
+        abs (EXPR)
+
+    in C.
+
 Binary Operations
 *****************
 
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index cf42e5a..013ee0f 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -615,6 +615,10 @@ new_unary_op (location *loc,
       if (loc)
 	set_tree_location (inner_result, loc);
       return new rvalue (this, inner_result);
+
+    case GCC_JIT_UNARY_OP_ABS:
+      inner_op = ABS_EXPR;
+      break;
     }
 
   inner_result = build1 (inner_op,
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index d228274..dc7a7fb 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -2797,6 +2797,7 @@ static const char * const unary_op_strings[] = {
   "-", /* GCC_JIT_UNARY_OP_MINUS */
   "~", /* GCC_JIT_UNARY_OP_BITWISE_NEGATE */
   "!", /* GCC_JIT_UNARY_OP_LOGICAL_NEGATE */
+  "abs ", /* GCC_JIT_UNARY_OP_ABS */
 };
 
 recording::string *
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index bd0ae91..6853bb0 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -1180,7 +1180,7 @@ gcc_jit_context_new_unary_op (gcc_jit_context *ctxt,
   /* LOC can be NULL.  */
   RETURN_NULL_IF_FAIL_PRINTF1 (
     (op >= GCC_JIT_UNARY_OP_MINUS
-     && op <= GCC_JIT_UNARY_OP_LOGICAL_NEGATE),
+     && op <= GCC_JIT_UNARY_OP_ABS),
     ctxt, loc,
     "unrecognized value for enum gcc_jit_unary_op: %i",
     op);
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index e89635c..2049795 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -649,7 +649,13 @@ enum gcc_jit_unary_op
   /* Logical negation of an arithmetic or pointer value; analogous to:
        !(EXPR)
      in C.  */
-  GCC_JIT_UNARY_OP_LOGICAL_NEGATE
+  GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
+
+  /* Absolute value of an arithmetic expression; analogous to:
+       abs (EXPR)
+     in C.  */
+  GCC_JIT_UNARY_OP_ABS
+
 };
 
 extern gcc_jit_rvalue *
diff --git a/gcc/testsuite/jit.dg/test-expressions.c b/gcc/testsuite/jit.dg/test-expressions.c
index 87abb76..7e33b56 100644
--- a/gcc/testsuite/jit.dg/test-expressions.c
+++ b/gcc/testsuite/jit.dg/test-expressions.c
@@ -73,6 +73,12 @@ make_tests_of_unary_ops (gcc_jit_context *ctxt)
 			   GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
 			   "test_UNARY_OP_LOGICAL_NEGATE_on_int"),
     "!(a)");
+  CHECK_STRING_VALUE (
+    make_test_of_unary_op (ctxt,
+			   int_type,
+			   GCC_JIT_UNARY_OP_ABS,
+			   "test_UNARY_OP_ABS_on_int"),
+    "abs (a)");
 }
 
 static void
@@ -104,6 +110,13 @@ verify_unary_ops (gcc_jit_result *result)
   CHECK_VALUE (test_UNARY_OP_LOGICAL_NEGATE_on_int (42), 0);
   CHECK_VALUE (test_UNARY_OP_LOGICAL_NEGATE_on_int (-5), 0);
 
+  test_fn test_UNARY_OP_ABS_on_int =
+    (test_fn)gcc_jit_result_get_code (result,
+				      "test_UNARY_OP_ABS_on_int");
+  CHECK_NON_NULL (test_UNARY_OP_ABS_on_int);
+  CHECK_VALUE (test_UNARY_OP_ABS_on_int (0), 0);
+  CHECK_VALUE (test_UNARY_OP_ABS_on_int (42), 42);
+  CHECK_VALUE (test_UNARY_OP_ABS_on_int (-5), 5);
 }
 
 /**********************************************************************
-- 
1.8.5.3

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

only message in thread, other threads:[~2015-01-07 20:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-01  0:00 [PATCH, committed] API extension: add GCC_JIT_UNARY_OP_ABS to enum gcc_jit_unary_op David Malcolm

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