@@ -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
@@ -55,8 +55,6 @@ API
* are we missing any ops?
- * shift operators
-
* error-checking:
* gcc_jit_context_new_unary_op: various checks needed
@@ -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
***********
@@ -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,
@@ -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 *
@@ -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
@@ -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);
}
/**********************************************************************