# HG changeset patch # User Martin Soch # Date 1360254259 -3600 # Node ID 6cad41d877d2b27a3713d99df3fe5d7fcdaa6f2d # Parent ff57af563cb86521fa4ee990a5294dfa91423945 Final part of Long tests moved from vm/.../NumberTest to vmtest/.../LongArithmeticTest diff -r ff57af563cb8 -r 6cad41d877d2 vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Feb 07 16:11:53 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Feb 07 17:24:19 2013 +0100 @@ -144,186 +144,6 @@ ); } - @Test public void longShiftL1() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 5; - assertExec("Long << 5", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longShiftL2() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 32; - assertExec("Long << 32", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 32); - } - - @Test public void longShiftL3() throws Exception { - final long res = 0x00fa37d7763e0ca1l << 45; - assertExec("Long << 45", - Numbers.class, "shlL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longShiftR1() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 5; - assertExec("Long >> 5", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longShiftR2() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 32; - assertExec("Long >> 32", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 32); - } - - @Test public void longShiftR3() throws Exception { - final long res = 0x00fa37d7763e0ca1l >> 45; - assertExec("Long >> 45", - Numbers.class, "shrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longUShiftR1() throws Exception { - final long res = 0x00fa37d7763e0ca1l >>> 5; - assertExec("Long >>> 5", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longUShiftR2() throws Exception { - final long res = 0x00fa37d7763e0ca1l >>> 45; - assertExec("Long >>> 45", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longUShiftR3() throws Exception { - final long res = 0xf0fa37d7763e0ca1l >>> 5; - assertExec("Long >>> 5", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 5); - } - - @Test public void longUShiftR4() throws Exception { - final long res = 0xf0fa37d7763e0ca1l >>> 45; - assertExec("Long >>> 45", - Numbers.class, "ushrL__J_3BI", - Double.valueOf(res), - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - 45); - } - - @Test public void longAnd() throws Exception { - final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el; - assertExec("LOng binary AND", - Numbers.class, "andL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longOr() throws Exception { - final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el; - assertExec("Long binary OR", - Numbers.class, "orL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor1() throws Exception { - final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor2() throws Exception { - final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longXor3() throws Exception { - final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el; - assertExec("Long binary XOR", - Numbers.class, "xorL__J_3B_3B", - Double.valueOf(res), - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } - ); - } - - @Test public void longCompareSameNumbers() throws Exception { - assertExec("Long compare same numbers", - Numbers.class, "compareL__I_3B_3BI", - 0.0, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longComparePositiveNumbers() throws Exception { - assertExec("Long compare positive numbers", - Numbers.class, "compareL__I_3B_3BI", - -1.0, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longCompareNegativeNumbers() throws Exception { - assertExec("Long compare negative numbers", - Numbers.class, "compareL__I_3B_3BI", - 1.0, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - 0 - ); - } - - @Test public void longCompareMixedNumbers() throws Exception { - assertExec("Long compare mixed numbers", - Numbers.class, "compareL__I_3B_3BI", - -1.0, - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, - 0 - ); - } - private static CharSequence codeSeq; private static Invocable code; diff -r ff57af563cb8 -r 6cad41d877d2 vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Feb 07 16:11:53 2013 +0100 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Feb 07 17:24:19 2013 +0100 @@ -67,86 +67,4 @@ static String floatToString() { return new Float(7.0).toString().toString(); } - - public static long shlL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() << nBits); - } - - public static long shrL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() >> nBits); - } - - public static long ushrL(byte[] arrValue, int nBits) throws IOException { - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue); - DataInputStream disValue = new DataInputStream(isValue); - return (disValue.readLong() >>> nBits); - } - - public static long andL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() & disY.readLong()); - } - - public static long orL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() | disY.readLong()); - } - - public static long xorL(byte[] arrX, byte[] arrY) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - return (disX.readLong() ^ disY.readLong()); - } - - public static int compareL(byte[] arrX, byte[] arrY, - int zero) throws IOException { - ByteArrayInputStream isX = new ByteArrayInputStream(arrX); - DataInputStream disX = new DataInputStream(isX); - ByteArrayInputStream isY = new ByteArrayInputStream(arrY); - DataInputStream disY = new DataInputStream(isY); - final long x = disX.readLong(); - final long y = disY.readLong(); - - final int xyResult = compareL(x, y, zero); - final int yxResult = compareL(y, x, zero); - - return ((xyResult + yxResult) == 0) ? xyResult : -2; - } - - private static int compareL(long x, long y, int zero) { - int result = -2; - int trueCount = 0; - - x += zero; - if (x == y) { - result = 0; - ++trueCount; - } - - x += zero; - if (x < y) { - result = -1; - ++trueCount; - } - - x += zero; - if (x > y) { - result = 1; - ++trueCount; - } - - return (trueCount == 1) ? result : -2; - } } diff -r ff57af563cb8 -r 6cad41d877d2 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Thu Feb 07 16:11:53 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Thu Feb 07 17:24:19 2013 +0100 @@ -48,7 +48,63 @@ } private static long neg(long x) { - return -x; + return (-x); + } + + private static long shl(long x, int b) { + return (x << b); + } + + private static long shr(long x, int b) { + return (x >> b); + } + + private static long ushr(long x, int b) { + return (x >>> b); + } + + private static long and(long x, long y) { + return (x & y); + } + + private static long or(long x, long y) { + return (x | y); + } + + private static long xor(long x, long y) { + return (x ^ y); + } + + public static int compare(long x, long y, int zero) { + final int xyResult = compareL(x, y, zero); + final int yxResult = compareL(y, x, zero); + + return ((xyResult + yxResult) == 0) ? xyResult : -2; + } + + private static int compareL(long x, long y, int zero) { + int result = -2; + int trueCount = 0; + + x += zero; + if (x == y) { + result = 0; + ++trueCount; + } + + x += zero; + if (x < y) { + result = -1; + ++trueCount; + } + + x += zero; + if (x > y) { + result = 1; + ++trueCount; + } + + return (trueCount == 1) ? result : -2; } @Compare public long conversion() { @@ -195,6 +251,82 @@ return mod(0x7fff800000000000l, 0x800000000001l); } + @Compare public long shiftL1() { + return shl(0x00fa37d7763e0ca1l, 5); + } + + @Compare public long shiftL2() { + return shl(0x00fa37d7763e0ca1l, 32); + } + + @Compare public long shiftL3() { + return shl(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long shiftR1() { + return shr(0x00fa37d7763e0ca1l, 5); + } + + @Compare public long shiftR2() { + return shr(0x00fa37d7763e0ca1l, 32); + } + + @Compare public long shiftR3() { + return shr(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long uShiftR1() { + return ushr(0x00fa37d7763e0ca1l, 5); + } + + @Compare public long uShiftR2() { + return ushr(0x00fa37d7763e0ca1l, 45); + } + + @Compare public long uShiftR3() { + return ushr(0xf0fa37d7763e0ca1l, 5); + } + + @Compare public long uShiftR4() { + return ushr(0xf0fa37d7763e0ca1l, 45); + } + + @Compare public long and1() { + return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long or1() { + return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long xor1() { + return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el); + } + + @Compare public long xor2() { + return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el); + } + + @Compare public long xor3() { + return xor(0x00000000763e0ca1l, 0x00000000ff00123el); + } + + @Compare public int compareSameNumbers() { + return compare(0x0000000000000000l, 0x0000000000000000l, 0); + } + + @Compare public int comparePositiveNumbers() { + return compare(0x0000000000200000l, 0x0000000010000000l, 0); + } + + @Compare public int compareNegativeNumbers() { + return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0); + } + + @Compare public int compareMixedNumbers() { + return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0); + } + @Factory public static Object[] create() { return VMTest.create(LongArithmeticTest.class);