From 7059106468a27d088b7949d389ce636bed569aef Mon Sep 17 00:00:00 2001 From: Daniel Green Date: Fri, 7 Oct 2022 11:50:59 -0400 Subject: [PATCH 1/2] Bump MoarVM to get unsigned comparison ops --- tools/templates/MOAR_REVISION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/templates/MOAR_REVISION b/tools/templates/MOAR_REVISION index 5128ad803..d369a6238 100644 --- a/tools/templates/MOAR_REVISION +++ b/tools/templates/MOAR_REVISION @@ -1 +1 @@ -2022.07-9-g740f3bcbe +2022.07-16-g3ae8a31c1 From 9dcf422c296507e876ea2ba02fbf38407ecb9246 Mon Sep 17 00:00:00 2001 From: Daniel Green Date: Fri, 7 Oct 2022 11:51:22 -0400 Subject: [PATCH 2/2] Make unsigned comparison ops available The MoarVM and JVM implementations work, but the JS ones are completely untested. --- docs/ops.markdown | 7 ++++++ src/vm/js/Operations.nqp | 3 ++- src/vm/jvm/QAST/Compiler.nqp | 8 +++++++ .../jvm/runtime/org/raku/nqp/runtime/Ops.java | 22 +++++++++++++++++++ src/vm/moar/QAST/QASTOperationsMAST.nqp | 7 ++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/ops.markdown b/docs/ops.markdown index e0120384d..304499684 100644 --- a/docs/ops.markdown +++ b/docs/ops.markdown @@ -1980,6 +1980,7 @@ Output the given object to the filehandle. Returns the number of bytes written. * `cmp_n(num $l, num $r --> int)` * `cmp_s(str $l, str $r --> int)` * `cmp_I(Int $l, Int $r --> int)` +* `cmp_u(uint $l, uint $r --> int)` Compare two values, returns -1 if $l is greater than $r, 0 if they are equal, and 1 if $r is greater than $l. @@ -2014,6 +2015,7 @@ Return 0 if the parameter has a truthy value, 1 otherwise. * `iseq_n(num $l, num $r --> int)` * `iseq_s(str $l, str $r --> int)` * `iseq_I(Int $l, Int $r --> int)` +* `iseq_u(uint $l, uint $r --> int)` * `iseq_snfg(str $l, str $r --> int)` `js` Return 1 if the two parameters are equal, 0 otherwise. @@ -2025,6 +2027,7 @@ Return 1 if the two parameters are equal, 0 otherwise. * `isge_n(num $l, num $r --> int)` * `isge_s(str $l, str $r --> int)` * `isge_I(Int $l, Int $r --> int)` +* `isge_u(uint $l, uint $r --> int)` Return 1 if $l is greater than or equal to $r, otherwise 0. @@ -2033,6 +2036,7 @@ Return 1 if $l is greater than or equal to $r, otherwise 0. * `isgt_n(num $l, num $r --> int)` * `isgt_s(str $l, str $r --> int)` * `isgt_I(Int $l, Int $r --> int)` +* `isgt_u(uint $l, uint $r --> int)` Return 1 if the two parameters are equal if $l is greater than $r, otherwise 0. @@ -2041,6 +2045,7 @@ Return 1 if the two parameters are equal if $l is greater than $r, otherwise 0. * `isle_n(num $l, num $r --> int)` * `isle_s(str $l, str $r --> int)` * `isle_I(Int $l, Int $r --> int)` +* `isle_u(uint $l, uint $r --> int)` Return 1 if $l is less than or equal to $r, otherwise 0. @@ -2049,6 +2054,7 @@ Return 1 if $l is less than or equal to $r, otherwise 0. * `islt_n(num $l, num $r --> int)` * `islt_s(str $l, str $r --> int)` * `islt_I(Int $l, Int $r --> int)` +* `islt_u(uint $l, uint $r --> int)` Return 1 if $l is less than $r, otherwise 0. @@ -2057,6 +2063,7 @@ Return 1 if $l is less than $r, otherwise 0. * `isne_n(num $l, num $r --> int)` * `isne_s(str $l, str $r --> int)` * `isne_I(Int $l, Int $r --> int)` +* `isne_u(uint $l, uint $r --> int)` * `isne_snfg(str $l, str $r --> int)` `js` Return 1 if the two parameters are not equal, otherwise 0. diff --git a/src/vm/js/Operations.nqp b/src/vm/js/Operations.nqp index 92aa225e6..c7bf822ab 100644 --- a/src/vm/js/Operations.nqp +++ b/src/vm/js/Operations.nqp @@ -244,7 +244,7 @@ class QAST::OperationsJS { add_infix_op('concat', $T_STR, '+', $T_STR, $T_STR); - for ['_i', $T_INT, '_n', $T_NUM, '_s', $T_STR] -> $suffix, $type { + for ['_i', $T_INT, '_n', $T_NUM, '_s', $T_STR, '_u', $T_UINT64] -> $suffix, $type { add_infix_op('isle' ~ $suffix, $type, '<=', $type, $T_BOOL); add_infix_op('islt' ~ $suffix, $type, '<', $type, $T_BOOL); add_infix_op('isgt' ~ $suffix, $type, '>', $type, $T_BOOL); @@ -433,6 +433,7 @@ class QAST::OperationsJS { add_cmp_op('cmp_i', $T_INT); add_cmp_op('cmp_n', $T_NUM); add_cmp_op('cmp_s', $T_STR); + add_cmp_op('cmp_u', $T_UINT64); for -> $op { add_op($op, sub ($comp, $node, :$want) { diff --git a/src/vm/jvm/QAST/Compiler.nqp b/src/vm/jvm/QAST/Compiler.nqp index 7ff91baa6..4c03a37fe 100644 --- a/src/vm/jvm/QAST/Compiler.nqp +++ b/src/vm/jvm/QAST/Compiler.nqp @@ -2543,6 +2543,14 @@ QAST::OperationsJAST.map_classlib_core_op('isle_i', $TYPE_OPS, 'isle_i', [$RT_IN QAST::OperationsJAST.map_classlib_core_op('isgt_i', $TYPE_OPS, 'isgt_i', [$RT_INT, $RT_INT], $RT_INT); QAST::OperationsJAST.map_classlib_core_op('isge_i', $TYPE_OPS, 'isge_i', [$RT_INT, $RT_INT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('cmp_u', $TYPE_OPS, 'cmp_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('iseq_u', $TYPE_OPS, 'iseq_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('isne_u', $TYPE_OPS, 'isne_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('islt_u', $TYPE_OPS, 'islt_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('isle_u', $TYPE_OPS, 'isle_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('isgt_u', $TYPE_OPS, 'isgt_u', [$RT_UINT, $RT_UINT], $RT_INT); +QAST::OperationsJAST.map_classlib_core_op('isge_u', $TYPE_OPS, 'isge_u', [$RT_UINT, $RT_UINT], $RT_INT); + QAST::OperationsJAST.map_classlib_core_op('bool_I', $TYPE_OPS, 'bool_I', [$RT_OBJ], $RT_INT, :tc); QAST::OperationsJAST.map_classlib_core_op('cmp_I', $TYPE_OPS, 'cmp_I', [$RT_OBJ, $RT_OBJ], $RT_INT, :tc); QAST::OperationsJAST.map_classlib_core_op('iseq_I', $TYPE_OPS, 'iseq_I', [$RT_OBJ, $RT_OBJ], $RT_INT, :tc); diff --git a/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java b/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java index 0788639e8..38eb74799 100644 --- a/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java +++ b/src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java @@ -5515,6 +5515,28 @@ public static long isge_i(long a, long b) { return a >= b ? 1 : 0; } + public static long cmp_u(long a, long b) { + return Long.compareUnsigned(a, b); + } + public static long iseq_u(long a, long b) { + return Long.compareUnsigned(a, b) == 0 ? 1 : 0; + } + public static long isne_u(long a, long b) { + return Long.compareUnsigned(a, b) != 0 ? 1 : 0; + } + public static long islt_u(long a, long b) { + return Long.compareUnsigned(a, b) < 0 ? 1 : 0; + } + public static long isle_u(long a, long b) { + return Long.compareUnsigned(a, b) <= 0 ? 1 : 0; + } + public static long isgt_u(long a, long b) { + return Long.compareUnsigned(a, b) > 0 ? 1 : 0; + } + public static long isge_u(long a, long b) { + return Long.compareUnsigned(a, b) >= 0 ? 1 : 0; + } + public static long cmp_n(double a, double b) { if (a < b) { return -1; diff --git a/src/vm/moar/QAST/QASTOperationsMAST.nqp b/src/vm/moar/QAST/QASTOperationsMAST.nqp index 2a5f86b81..ac24a6c0c 100644 --- a/src/vm/moar/QAST/QASTOperationsMAST.nqp +++ b/src/vm/moar/QAST/QASTOperationsMAST.nqp @@ -2947,6 +2947,13 @@ my constant SIMPLE_OP_MAPPINGS := nqp::list_s( 'isle_i', 'le_i', 'isgt_i', 'gt_i', 'isge_i', 'ge_i', + 'cmp_u', 'cmp_u', + 'iseq_u', 'eq_u', + 'isne_u', 'ne_u', + 'islt_u', 'lt_u', + 'isle_u', 'le_u', + 'isgt_u', 'gt_u', + 'isge_u', 'ge_u', 'cmp_n', 'cmp_n', 'not_i', 'not_i', 'iseq_n', 'eq_n',