1.1 --- a/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Thu Jan 31 20:19:38 2013 +0100
1.2 +++ b/emul/mini/src/main/resources/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js Thu Jan 31 20:37:12 2013 +0100
1.3 @@ -109,6 +109,16 @@
1.4 return low;
1.5 };
1.6
1.7 +Number.prototype.xor64 = function(x) {
1.8 + var low = this ^ x;
1.9 + low += (low < 0) ? (__m32+1) : 0;
1.10 + if (this.hi || x.hi) {
1.11 + var hi = this.hi ^ x.hi;
1.12 + return hi.next32(low);
1.13 + };
1.14 + return low;
1.15 +};
1.16 +
1.17 Number.prototype.shl64 = function(x) {
1.18 if (x >= 32) {
1.19 var hi = (this << (x - 32)) | 0;
2.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Jan 31 20:19:38 2013 +0100
2.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Jan 31 20:37:12 2013 +0100
2.3 @@ -594,7 +594,7 @@
2.4 emit(out, "@1 ^= @2;", smapper.getI(1), smapper.popI());
2.5 break;
2.6 case opc_lxor:
2.7 - emit(out, "@1 ^= @2;", smapper.getL(1), smapper.popL());
2.8 + emit(out, "@1 = @1.xor64(@2)", smapper.getL(1), smapper.popL());
2.9 break;
2.10 case opc_ineg:
2.11 emit(out, "@1 = -@1;", smapper.getI(0));
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Jan 31 20:19:38 2013 +0100
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Jan 31 20:37:12 2013 +0100
3.3 @@ -275,6 +275,36 @@
3.4 );
3.5 }
3.6
3.7 + @Test public void longXor1() throws Exception {
3.8 + final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el;
3.9 + assertExec("Long binary XOR",
3.10 + Numbers.class, "xorL__J_3B_3B",
3.11 + Double.valueOf(res),
3.12 + new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
3.13 + new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
3.14 + );
3.15 + }
3.16 +
3.17 + @Test public void longXor2() throws Exception {
3.18 + final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el;
3.19 + assertExec("Long binary XOR",
3.20 + Numbers.class, "xorL__J_3B_3B",
3.21 + Double.valueOf(res),
3.22 + new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
3.23 + new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
3.24 + );
3.25 + }
3.26 +
3.27 + @Test public void longXor3() throws Exception {
3.28 + final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el;
3.29 + assertExec("Long binary XOR",
3.30 + Numbers.class, "xorL__J_3B_3B",
3.31 + Double.valueOf(res),
3.32 + new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
3.33 + new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
3.34 + );
3.35 + }
3.36 +
3.37 private static CharSequence codeSeq;
3.38 private static Invocable code;
3.39
4.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Jan 31 20:19:38 2013 +0100
4.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Jan 31 20:37:12 2013 +0100
4.3 @@ -127,4 +127,12 @@
4.4 DataInputStream disY = new DataInputStream(isY);
4.5 return (disX.readLong() | disY.readLong());
4.6 }
4.7 +
4.8 + public static long xorL(byte[] arrX, byte[] arrY) throws IOException {
4.9 + ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
4.10 + DataInputStream disX = new DataInputStream(isX);
4.11 + ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
4.12 + DataInputStream disY = new DataInputStream(isY);
4.13 + return (disX.readLong() ^ disY.readLong());
4.14 + }
4.15 }