Files
sdk/tests/standalone/medium_integer_test.dart
T
fschneider@google.com 6632f191c4 Support for unboxed 64-bit integer bitwise operations and equality on ia32.
This CL adds AND, OR, XOR and == operations on unboxed 64-bit integers
(aka. mints).

Unboxed mints are stored in xmm registers. Each xmm register location
has an additional bit to keep track of its value representation.

Unboxed mints are materialized on the heap on deoptmization in the same way as
unboxed doubles.

The SSE instructions used are available on all CPUs that support SSE 4.1.
Review URL: https://codereview.chromium.org//10968059

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@13112 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-02 11:25:53 +00:00

114 lines
2.9 KiB
Dart

// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Testing Mints. Note that the tests may not work on 64-bit machines,
// as Smi's would be used to represent many of the numbers.
#library("MediumIntegerTest.dart");
class MediumIntegerTest {
static int getMint() {
return 1234567890123456789;
}
static testSmiOverflow() {
int a = 1073741823;
int b = 1073741822;
Expect.equals(2147483645, a + b);
Expect.equals(1152921501385621506, a * b);
Expect.equals(-2147483645, -a - b);
}
static testMintAdd() {
// Mint and Smi.
var a = 1234567890123456789;
var b = 2;
Expect.equals(1234567890123456791, a + b);
Expect.equals(1234567890123456791, b + a);
a = 9223372036854775807;
Expect.equals(9223372036854775808, a + 1);
// Mint and Mint.
a = 100000000000000001;
Expect.equals(200000000000000002, a + a);
a = 9223372036854775800;
b = 1000000000000000000;
Expect.equals(10223372036854775800, a + b);
// Mint and Bigint.
a = 100000000000000001;
b = 10000000000000000001;
Expect.equals(10100000000000000002, a + b);
// Mint and double.
a = 100000000000.0;
b = 100000000000;
Expect.equals(200000000000.0, a + b);
Expect.equals(200000000000.0, b + a);
}
static testMintSub() {
// Mint and Smi.
var a = 1234567890123456789;
var b = 2;
Expect.equals(1234567890123456787, a - b);
a = -9223372036854775808;
Expect.equals(-9223372036854775809, a - 1);
// Mint and Mint.
a = 1234567890123456789;
b = 1000000000000000000;
Expect.equals(234567890123456789, a - b);
a = -9223372036854775808;
b = 1000000000000000000;
Expect.equals(-10223372036854775808, a - b);
}
static testMintDiv() {
// Mint and Smi.
var a = 1234567890123456788;
var b = 2;
Expect.equals(617283945061728394.0, a / b);
}
static testMintMul() {
// Mint and Smi.
var a = 4611686018427387904;
var b = 10;
Expect.equals(46116860184273879040, a * b);
b = 1000000000000000000;
Expect.equals(4611686018427387904000000000000000000, a * b);
}
static testMintAnd(mint) {
// Issue 1845.
final int t = 0;
var res = mint & (t - 1);
Expect.equals(mint, res);
}
static void testMain() {
Expect.equals(1234567890123456789, getMint());
testSmiOverflow();
testMintAdd();
testMintSub();
testMintMul();
testMintDiv();
testMintAnd(-1925149952);
testMintAnd(1925149952);
testMintAnd(0x100000001);
var a = 100000000000;
var b = 100000000001;
Expect.equals(false, a.hashCode() == b.hashCode());
Expect.equals(true, a.hashCode() == (b - 1).hashCode());
}
}
main() {
for (int i = 0; i < 4000; i++) {
MediumIntegerTest.testMain();
}
}