OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); | 118 assertKind(element_kind.external_byte_elements, new Int8Array(9001)); |
119 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); | 119 assertKind(element_kind.external_unsigned_byte_elements, new Uint8Array(007)); |
120 assertKind(element_kind.external_short_elements, new Int16Array(666)); | 120 assertKind(element_kind.external_short_elements, new Int16Array(666)); |
121 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); | 121 assertKind(element_kind.external_unsigned_short_elements, new Uint16Array(42)); |
122 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); | 122 assertKind(element_kind.external_int_elements, new Int32Array(0xF)); |
123 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); | 123 assertKind(element_kind.external_unsigned_int_elements, new Uint32Array(23)); |
124 assertKind(element_kind.external_float_elements, new Float32Array(7)); | 124 assertKind(element_kind.external_float_elements, new Float32Array(7)); |
125 assertKind(element_kind.external_double_elements, new Float64Array(0)); | 125 assertKind(element_kind.external_double_elements, new Float64Array(0)); |
126 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); | 126 assertKind(element_kind.external_pixel_elements, new PixelArray(512)); |
| 127 |
| 128 // Crankshaft support for smi-only array elements. |
| 129 function monomorphic(array) { |
| 130 for (var i = 0; i < 3; i++) { |
| 131 array[i] = i + 10; |
| 132 } |
| 133 assertKind(element_kind.fast_smi_only_elements, array); |
| 134 for (var i = 0; i < 3; i++) { |
| 135 var a = array[i]; |
| 136 assertEquals(i + 10, a); |
| 137 } |
| 138 } |
| 139 var smi_only = [1, 2, 3]; |
| 140 for (var i = 0; i < 3; i++) monomorphic(smi_only); |
| 141 %OptimizeFunctionOnNextCall(monomorphic); |
| 142 monomorphic(smi_only); |
| 143 function polymorphic(array, expected_kind) { |
| 144 array[1] = 42; |
| 145 assertKind(expected_kind, array); |
| 146 var a = array[1]; |
| 147 assertEquals(42, a); |
| 148 } |
| 149 var smis = [1, 2, 3]; |
| 150 var strings = ["one", "two", "three"]; |
| 151 var doubles = [0, 0, 0]; doubles[0] = 1.5; doubles[1] = 2.5; doubles[2] = 3.5; |
| 152 assertKind(support_smi_only_arrays |
| 153 ? element_kind.fast_double_elements |
| 154 : element_kind.fast_elements, |
| 155 doubles); |
| 156 for (var i = 0; i < 3; i++) { |
| 157 polymorphic(smis, element_kind.fast_smi_only_elements); |
| 158 polymorphic(strings, element_kind.fast_elements); |
| 159 polymorphic(doubles, support_smi_only_arrays |
| 160 ? element_kind.fast_double_elements |
| 161 : element_kind.fast_elements); |
| 162 } |
| 163 %OptimizeFunctionOnNextCall(polymorphic); |
| 164 polymorphic(smis, element_kind.fast_smi_only_elements); |
| 165 polymorphic(strings, element_kind.fast_elements); |
| 166 polymorphic(doubles, support_smi_only_arrays |
| 167 ? element_kind.fast_double_elements |
| 168 : element_kind.fast_elements); |
| 169 |
| 170 // Crankshaft support for smi-only elements in dynamic array literals. |
| 171 function get(foo) { return foo; } // Used to generate dynamic values. |
| 172 |
| 173 //function crankshaft_test(expected_kind) { |
| 174 function crankshaft_test() { |
| 175 var a = [get(1), get(2), get(3)]; |
| 176 assertKind(element_kind.fast_smi_only_elements, a); |
| 177 var b = [get(1), get(2), get("three")]; |
| 178 assertKind(element_kind.fast_elements, b); |
| 179 var c = [get(1), get(2), get(3.5)]; |
| 180 // The full code generator doesn't support conversion to fast_double_elements |
| 181 // yet. Crankshaft does, but only with --smi-only-arrays support. |
| 182 if ((%GetOptimizationStatus(crankshaft_test) & 1) && |
| 183 support_smi_only_arrays) { |
| 184 assertKind(element_kind.fast_double_elements, c); |
| 185 } else { |
| 186 assertKind(element_kind.fast_elements, c); |
| 187 } |
| 188 } |
| 189 for (var i = 0; i < 3; i++) { |
| 190 crankshaft_test(); |
| 191 } |
| 192 %OptimizeFunctionOnNextCall(crankshaft_test); |
| 193 crankshaft_test(); |
OLD | NEW |