Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bitwise operations on big integers.
  • Loading branch information
jnthn committed Apr 7, 2013
1 parent cc05609 commit 2a293ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/QAST/JASTCompiler.nqp
Expand Up @@ -1665,11 +1665,17 @@ QAST::OperationsJAST.map_classlib_core_op('popcompsc', $TYPE_OPS, 'popcompsc', [

# bitwise opcodes
QAST::OperationsJAST.map_classlib_core_op('bitor_i', $TYPE_OPS, 'bitor_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitor_I', $TYPE_OPS, 'bitor_I', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('bitxor_i', $TYPE_OPS, 'bitxor_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitxor_I', $TYPE_OPS, 'bitxor_I', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('bitand_i', $TYPE_OPS, 'bitand_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitand_I', $TYPE_OPS, 'bitand_I', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('bitneg_i', $TYPE_OPS, 'bitneg_i', [$RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitneg_I', $TYPE_OPS, 'bitneg_I', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('bitshiftl_i', $TYPE_OPS, 'bitshiftl_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitshiftl_I', $TYPE_OPS, 'bitshiftl_I', [$RT_OBJ, $RT_INT, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('bitshiftr_i', $TYPE_OPS, 'bitshiftr_i', [$RT_INT, $RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitneg_i', $TYPE_OPS, 'bitneg_i', [$RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('bitshiftr_I', $TYPE_OPS, 'bitshiftr_I', [$RT_OBJ, $RT_INT, $RT_OBJ], $RT_OBJ, :tc);

# relational opcodes
QAST::OperationsJAST.map_classlib_core_op('cmp_i', $TYPE_OPS, 'cmp_i', [$RT_INT, $RT_INT], $RT_INT);
Expand Down
24 changes: 24 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -3191,6 +3191,30 @@ public static SixModelObject mod_I(SixModelObject a, SixModelObject b, SixModelO
return makeBI(tc, type, getBI(tc, a).mod(getBI(tc, b)));
}

public static SixModelObject bitor_I(SixModelObject a, SixModelObject b, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).or(getBI(tc, b)));
}

public static SixModelObject bitxor_I(SixModelObject a, SixModelObject b, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).xor(getBI(tc, b)));
}

public static SixModelObject bitand_I(SixModelObject a, SixModelObject b, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).and(getBI(tc, b)));
}

public static SixModelObject bitneg_I(SixModelObject a, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).not());
}

public static SixModelObject bitshiftl_I(SixModelObject a, long b, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).shiftLeft((int)b));
}

public static SixModelObject bitshiftr_I(SixModelObject a, long b, SixModelObject type, ThreadContext tc) {
return makeBI(tc, type, getBI(tc, a).shiftRight((int)b));
}

/* Evaluation of code; JVM-specific ops. */
public static SixModelObject compilejast(String dump, ThreadContext tc) {
EvalResult res = new EvalResult();
Expand Down

0 comments on commit 2a293ae

Please sign in to comment.