Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1705)

Unified Diff: test/mjsunit/unbox-double-arrays.js

Issue 7307030: Implement ICs for FastDoubleArray loads and stores (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix asserts Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/unbox-double-arrays.js
diff --git a/test/mjsunit/unbox-double-arrays.js b/test/mjsunit/unbox-double-arrays.js
index 31918b3767b3afca85755466e3756662d57d37fd..53d6b875575c2fdecf36255737bd19bd682bed94 100644
--- a/test/mjsunit/unbox-double-arrays.js
+++ b/test/mjsunit/unbox-double-arrays.js
@@ -27,52 +27,255 @@
// Test dictionary -> double elements -> dictionary elements round trip
-var foo = new Array(500000);
+// Flags: --allow-natives-syntax --unbox-double-arrays
+var large_array_size = 500000;
+var approx_dict_to_elements_threshold = 69000;
-function func(a) {
- for (var i= 0; i < 100000; ++i ) {
- a[i] = i+0.5;
+function expected_array_value(i) {
+ if ((i % 2) == 0) {
+ return i;
+ } else {
+ return i + 0.5;
}
}
-func(foo);
-
-for (var i= 0; i < 100000; i += 500 ) {
- assertEquals(i+0.5, foo[i]);
+function force_to_fast_double_array(a) {
+ for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) {
+ a[i] = expected_array_value(i);
+ }
+ assertTrue(%HasFastDoubleElements(a));
}
-delete foo[5];
-// Don't use assertEquals for comparison to undefined due to
-assertTrue(undefined === foo[5]);
-assertTrue(undefined === foo[500000-1]);
-assertTrue(undefined === foo[-1]);
-assertEquals(500000, foo.length);
-
-// Cause the array to grow beyond it's JSArray length. This will double the
-// size of the capacity and force the array into "slow" dictionary case.
-foo[500001] = 50;
-assertEquals(50, foo[500001]);
-assertEquals(500002, foo.length);
-assertTrue(undefined === foo[5])
-assertTrue(undefined === foo[500000-1])
-assertTrue(undefined === foo[-1])
-assertEquals(500002, foo.length);
-
-// Test dictionary -> double elements -> fast elements.
-
-var foo2 = new Array(500000);
-func(foo2);
-delete foo2[5];
-
-// Convert back to fast elements and make sure the contents of the array are
-// unchanged.
-foo2[25] = new Object();
-for (var i= 0; i < 100000; i += 500 ) {
- if (i != 25 && i != 5) {
- assertEquals(i+0.5, foo2[i]);
+function testOneArrayType(allocator) {
+ var large_array = new allocator(500000);
+ force_to_fast_double_array(large_array);
+
+ for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) {
+ assertEquals(expected_array_value(i), large_array[i]);
+ }
+
+ function get_test_various_loads() {
+ return function test_various_loads(a, value_5, value_6, value_7) {
+ assertTrue(%HasFastDoubleElements(a));
+ assertEquals(value_5, a[5]);
+ assertEquals(value_6, a[6]);
+ assertEquals(value_7, a[7]);
+ assertEquals(undefined, a[large_array_size-1]);
+ assertEquals(undefined, a[-1]);
+ assertEquals(large_array_size, a.length);
+ assertTrue(%HasFastDoubleElements(a));
+ }
+ }
+
+ function get_test_various_stores() {
+ return function test_various_stores(a, value_5, value_6, value_7) {
+ assertTrue(%HasFastDoubleElements(a));
+ a[5] = value_5;
+ a[6] = value_6;
+ a[7] = value_7;
+ assertTrue(%HasFastDoubleElements(a));
+ }
+ }
+
+ // Run tests up to three times to make sure both runtime and IC implementation
+ // (premonomorphic and monomorphic) of KeyedLoad access works in various
+ // cases.
+
+ // Test double and integer values
+ test_various_loads = get_test_various_loads();
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+
+ // Test NaN values
+ test_various_stores = get_test_various_stores();
+ test_various_stores(large_array, NaN, -NaN, expected_array_value(7));
+
+ test_various_loads(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(7));
+
+ // Test Infinity values
+ test_various_stores = get_test_various_stores();
+ test_various_stores(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+
+ test_various_loads(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+
+ // Test the hole for the default runtime implementation.
+ delete large_array[5];
+ delete large_array[6];
+ test_various_loads = get_test_various_loads();
+ test_various_loads(large_array,
+ undefined,
+ undefined,
+ expected_array_value(7));
+
+ // Test the keyed load IC implementation when the value is the hole.
+ test_various_loads = get_test_various_loads();
+ test_various_stores(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ delete large_array[5];
+ delete large_array[6];
+ test_various_loads(large_array,
+ undefined,
+ undefined,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ undefined,
+ undefined,
+ expected_array_value(7));
+
+ // Test both runtime and IC variants of double array stores for normal
+ // values (double and integer).
+ test_various_stores = get_test_various_stores();
+ test_various_stores(large_array,
+ expected_array_value(4),
+ expected_array_value(5),
+ expected_array_value(6));
+ test_various_loads(large_array,
+ expected_array_value(4),
+ expected_array_value(5),
+ expected_array_value(6));
+ test_various_stores(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+
+ // Test stores of NaN to make sure they don't get mistaken for the
+ // hole. Test both runtime and IC implementation.
+ test_various_stores = get_test_various_stores();
+ test_various_stores(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(6));
+ test_various_loads(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(6));
+ test_various_stores(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_stores(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ NaN,
+ -NaN,
+ expected_array_value(7));
+
+ // Test stores of Infinity to make sure they don't get mistaken for the
+ // hole. Test both runtime and IC implementation.
+ test_various_stores = get_test_various_stores();
+ test_various_stores(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(6));
+ test_various_loads(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(6));
+ test_various_stores(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_loads(large_array,
+ expected_array_value(5),
+ expected_array_value(6),
+ expected_array_value(7));
+ test_various_stores(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+ test_various_loads(large_array,
+ Infinity,
+ -Infinity,
+ expected_array_value(7));
+
+ delete large_array[5];
+
+ // Make sure that we haven't converted from fast double.
+ assertTrue(%HasFastDoubleElements(large_array));
+ // Cause the array to grow beyond it's JSArray length. This will double the
+ // size of the capacity and force the array into "slow" dictionary case.
+ large_array[large_array_size+1] = 50;
+ assertTrue(%HasDictionaryElements(large_array));
+ assertEquals(50, large_array[large_array_size+1]);
+ assertEquals(large_array_size+2, large_array.length);
+ assertEquals(undefined, large_array[5]);
+ assertEquals(undefined, large_array[large_array_size-1]);
+ assertEquals(undefined, large_array[-1]);
+ assertEquals(large_array_size+2, large_array.length);
+
+ // Test dictionary -> double elements -> fast elements.
+ var large_array2 = new allocator(large_array_size);
+ force_to_fast_double_array(large_array2);
+ delete large_array2[5];
+
+ // Convert back to fast elements and make sure the contents of the array are
+ // unchanged.
+ large_array2[25] = new Object();
+ assertTrue(%HasFastElements(large_array2));
+ for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) {
+ if (i != 25 && i != 5) {
+ assertEquals(expected_array_value(i), large_array2[i]);
+ }
}
+ assertEquals(undefined, large_array2[5])
+ assertEquals(undefined, large_array2[large_array_size-1])
+ assertEquals(undefined, large_array2[-1])
+ assertEquals(large_array_size, large_array2.length);
}
-assertTrue(undefined === foo2[5])
-assertTrue(undefined === foo2[500000-1])
-assertTrue(undefined === foo2[-1])
-assertEquals(500000, foo2.length);
+
+testOneArrayType(Array);
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698