public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [jit] Add shift operators
Date: Wed, 01 Jan 2014 00:00:00 -0000	[thread overview]
Message-ID: <1411501367-7304-1-git-send-email-dmalcolm@redhat.com> (raw)

Committed to branch dmalcolm/jit:

With this commit, jit.sum has:
	# of expected passes		4600

gcc/jit/ChangeLog.jit:
	* TODO.rst (API): Shift operators are done.
	* docs/topics/expressions.rst (Binary): Add shift operators.
	* internal-api.c (binary_op_strings): Likewise.
	(gcc::jit::playback::context::new_binary_op): Likewise.
	* libgccjit.h (enum gcc_jit_binary_op): Likewise.

gcc/testsuite/ChangeLog.jit:
	* jit.dg/test-expressions.c (make_tests_of_binary_ops): Add
	shift operators.
	(verify_binary_ops): Likewise.
---
 gcc/jit/ChangeLog.jit                   |  8 +++++++
 gcc/jit/TODO.rst                        |  2 --
 gcc/jit/docs/topics/expressions.rst     | 22 +++++++++++++++++++
 gcc/jit/internal-api.c                  | 12 ++++++++++-
 gcc/jit/libgccjit.h                     | 12 ++++++++++-
 gcc/testsuite/ChangeLog.jit             |  6 ++++++
 gcc/testsuite/jit.dg/test-expressions.c | 38 +++++++++++++++++++++++++++++++++
 7 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 1f408b3..4db5e66 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,5 +1,13 @@
 2014-09-23  David Malcolm  <dmalcolm@redhat.com>
 
+	* TODO.rst (API): Shift operators are done.
+	* docs/topics/expressions.rst (Binary): Add shift operators.
+	* internal-api.c (binary_op_strings): Likewise.
+	(gcc::jit::playback::context::new_binary_op): Likewise.
+	* libgccjit.h (enum gcc_jit_binary_op): Likewise.
+
+2014-09-23  David Malcolm  <dmalcolm@redhat.com>
+
 	* TODO.rst: Rename "Initial Release" section to "API", and
 	remove completed items: builtins, docs, pkgconfig file, fuzz
 	testing.  Move ability to name contexts and stmt_list per block
diff --git a/gcc/jit/TODO.rst b/gcc/jit/TODO.rst
index 086d084..c1ea024 100644
--- a/gcc/jit/TODO.rst
+++ b/gcc/jit/TODO.rst
@@ -55,8 +55,6 @@ API
 
 * are we missing any ops?
 
-  * shift operators
-
 * error-checking:
 
     * gcc_jit_context_new_unary_op: various checks needed
diff --git a/gcc/jit/docs/topics/expressions.rst b/gcc/jit/docs/topics/expressions.rst
index 357ccf2..98d8e92 100644
--- a/gcc/jit/docs/topics/expressions.rst
+++ b/gcc/jit/docs/topics/expressions.rst
@@ -198,6 +198,8 @@ Binary Operation                          C equivalent
 :c:macro:`GCC_JIT_BINARY_OP_BITWISE_OR`   `x | y`
 :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_AND`  `x && y`
 :c:macro:`GCC_JIT_BINARY_OP_LOGICAL_OR`   `x || y`
+:c:macro:`GCC_JIT_BINARY_OP_LSHIFT`       `x << y`
+:c:macro:`GCC_JIT_BINARY_OP_RSHIFT`       `x >> y`
 ========================================  ============
 
 .. c:macro:: GCC_JIT_BINARY_OP_PLUS
@@ -306,6 +308,26 @@ Binary Operation                          C equivalent
 
    in C.
 
+.. c:macro:: GCC_JIT_BINARY_OP_LSHIFT
+
+   Left shift; analogous to:
+
+   .. code-block:: c
+
+     (EXPR_A) << (EXPR_B)
+
+   in C.
+
+.. c:macro:: GCC_JIT_BINARY_OP_RSHIFT
+
+   Right shift; analogous to:
+
+   .. code-block:: c
+
+     (EXPR_A) >> (EXPR_B)
+
+   in C.
+
 Comparisons
 ***********
 
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index 8d9a2d2..a22cc5c 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -2064,7 +2064,9 @@ static const char * const binary_op_strings[] = {
   "^", /* GCC_JIT_BINARY_OP_BITWISE_XOR */
   "|", /* GCC_JIT_BINARY_OP_BITWISE_OR */
   "&&", /* GCC_JIT_BINARY_OP_LOGICAL_AND */
-  "||" /* GCC_JIT_BINARY_OP_LOGICAL_OR */
+  "||", /* GCC_JIT_BINARY_OP_LOGICAL_OR */
+  "<<", /* GCC_JIT_BINARY_OP_LSHIFT */
+  ">>", /* GCC_JIT_BINARY_OP_RSHIFT */
 };
 
 recording::string *
@@ -3138,6 +3140,14 @@ new_binary_op (location *loc,
       node_b = as_truth_value (node_b, loc);
       inner_op = TRUTH_ORIF_EXPR;
       break;
+
+    case GCC_JIT_BINARY_OP_LSHIFT:
+      inner_op = LSHIFT_EXPR;
+      break;
+
+    case GCC_JIT_BINARY_OP_RSHIFT:
+      inner_op = RSHIFT_EXPR;
+      break;
     }
 
   tree inner_expr = build2 (inner_op,
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 29d3389..0ca1e92 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -682,7 +682,17 @@ enum gcc_jit_binary_op
   /* Logical OR; analogous to:
        (EXPR_A) || (EXPR_B)
      in C.  */
-  GCC_JIT_BINARY_OP_LOGICAL_OR
+  GCC_JIT_BINARY_OP_LOGICAL_OR,
+
+  /* Left shift; analogous to:
+       (EXPR_A) << (EXPR_B)
+     in C.  */
+  GCC_JIT_BINARY_OP_LSHIFT,
+
+  /* Right shift; analogous to:
+       (EXPR_A) >> (EXPR_B)
+     in C.  */
+  GCC_JIT_BINARY_OP_RSHIFT
 };
 
 extern gcc_jit_rvalue *
diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit
index 8fbd16c..e882b05 100644
--- a/gcc/testsuite/ChangeLog.jit
+++ b/gcc/testsuite/ChangeLog.jit
@@ -1,3 +1,9 @@
+2014-09-23  David Malcolm  <dmalcolm@redhat.com>
+
+	* jit.dg/test-expressions.c (make_tests_of_binary_ops): Add
+	shift operators.
+	(verify_binary_ops): Likewise.
+
 2014-09-18  David Malcolm  <dmalcolm@redhat.com>
 
 	* jit.dg/jit.exp: When constructing "tests", add the example files
diff --git a/gcc/testsuite/jit.dg/test-expressions.c b/gcc/testsuite/jit.dg/test-expressions.c
index 4873098..eb986f3 100644
--- a/gcc/testsuite/jit.dg/test-expressions.c
+++ b/gcc/testsuite/jit.dg/test-expressions.c
@@ -219,6 +219,18 @@ make_tests_of_binary_ops (gcc_jit_context *ctxt)
 			    GCC_JIT_BINARY_OP_LOGICAL_OR,
 			    "test_BINARY_OP_LOGICAL_OR_on_int"),
     "a || b");
+  CHECK_STRING_VALUE (
+    make_test_of_binary_op (ctxt,
+			    int_type,
+			    GCC_JIT_BINARY_OP_LSHIFT,
+			    "test_BINARY_OP_LSHIFT_on_int"),
+    "a << b");
+  CHECK_STRING_VALUE (
+    make_test_of_binary_op (ctxt,
+			    int_type,
+			    GCC_JIT_BINARY_OP_RSHIFT,
+			    "test_BINARY_OP_RSHIFT_on_int"),
+    "a >> b");
 }
 
 static void
@@ -309,6 +321,32 @@ verify_binary_ops (gcc_jit_result *result)
   CHECK_VALUE (test_BINARY_OP_LOGICAL_OR_on_int (42, 0), 1);
   CHECK_VALUE (test_BINARY_OP_LOGICAL_OR_on_int (0, -13), 1);
   CHECK_VALUE (test_BINARY_OP_LOGICAL_OR_on_int (1997, 1998), 1);
+
+  test_fn test_BINARY_OP_LSHIFT_on_int =
+    (test_fn)gcc_jit_result_get_code (result,
+				      "test_BINARY_OP_LSHIFT_on_int");
+  CHECK_NON_NULL (test_BINARY_OP_LSHIFT_on_int);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (0, 0), 0);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (0, 1), 0);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (0, 2), 0);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (1, 0), 1);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (1, 1), 2);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (1, 2), 4);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (1, 3), 8);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (3, 0), 3);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (3, 1), 6);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (3, 5), 3 * 32);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (42, 0), 42);
+  CHECK_VALUE (test_BINARY_OP_LSHIFT_on_int (42, 1), 84);
+
+  test_fn test_BINARY_OP_RSHIFT_on_int =
+    (test_fn)gcc_jit_result_get_code (result,
+				      "test_BINARY_OP_RSHIFT_on_int");
+  CHECK_NON_NULL (test_BINARY_OP_RSHIFT_on_int);
+  CHECK_VALUE (test_BINARY_OP_RSHIFT_on_int (0, 0), 0);
+  CHECK_VALUE (test_BINARY_OP_RSHIFT_on_int (42, 0), 42);
+  CHECK_VALUE (test_BINARY_OP_RSHIFT_on_int (42, 1), 21);
+  CHECK_VALUE (test_BINARY_OP_RSHIFT_on_int (42, 2), 10);
 }
 
 /**********************************************************************
-- 
1.7.11.7

                 reply	other threads:[~2014-09-23 19:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411501367-7304-1-git-send-email-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jit@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).