| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 a = new Int16Array(2); | 54 a = new Int16Array(2); |
| 55 assertEquals(2, a.BYTES_PER_ELEMENT); | 55 assertEquals(2, a.BYTES_PER_ELEMENT); |
| 56 | 56 |
| 57 // Test Float64Arrays. | 57 // Test Float64Arrays. |
| 58 function get(a, index) { | 58 function get(a, index) { |
| 59 return a[index]; | 59 return a[index]; |
| 60 } | 60 } |
| 61 function set(a, index, value) { | 61 function set(a, index, value) { |
| 62 a[index] = value; | 62 a[index] = value; |
| 63 } | 63 } |
| 64 | 64 function temp() { |
| 65 var array = new Float64Array(2); | 65 var array = new Float64Array(2); |
| 66 for (var i = 0; i < 5; i++) { | 66 for (var i = 0; i < 5; i++) { |
| 67 set(array, 0, 2.5); | 67 set(array, 0, 2.5); |
| 68 assertEquals(2.5, array[0]); | 68 assertEquals(2.5, array[0]); |
| 69 } | 69 } |
| 70 %OptimizeFunctionOnNextCall(set); | 70 %OptimizeFunctionOnNextCall(set); |
| 71 set(array, 0, 2.5); | 71 set(array, 0, 2.5); |
| 72 assertEquals(2.5, array[0]); | 72 assertEquals(2.5, array[0]); |
| 73 set(array, 1, 3.5); | 73 set(array, 1, 3.5); |
| 74 assertEquals(3.5, array[1]); | 74 assertEquals(3.5, array[1]); |
| 75 for (var i = 0; i < 5; i++) { | 75 for (var i = 0; i < 5; i++) { |
| 76 assertEquals(2.5, get(array, 0)); | 76 assertEquals(2.5, get(array, 0)); |
| 77 assertEquals(3.5, array[1]); | 77 assertEquals(3.5, array[1]); |
| 78 } | 78 } |
| 79 %OptimizeFunctionOnNextCall(get); | 79 %OptimizeFunctionOnNextCall(get); |
| 80 assertEquals(2.5, get(array, 0)); | 80 assertEquals(2.5, get(array, 0)); |
| 81 assertEquals(3.5, get(array, 1)); | 81 assertEquals(3.5, get(array, 1)); |
| 82 } |
| 82 | 83 |
| 83 // Test loads and stores. | 84 // Test loads and stores. |
| 84 types = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, | 85 types = [Array, Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, |
| 85 Uint32Array, PixelArray, Float32Array, Float64Array]; | 86 Uint32Array, PixelArray, Float32Array, Float64Array]; |
| 86 | 87 |
| 88 test_result_nan = [NaN, 0, 0, 0, 0, 0, 0, 0, NaN, NaN]; |
| 89 test_result_low_int = [-1, -1, 255, -1, 65535, -1, 0xFFFFFFFF, 0, -1, -1]; |
| 90 test_result_middle = [253.75, -3, 253, 253, 253, 253, 253, 254, 253.75, 253.75]; |
| 91 test_result_high_int = [256, 0, 0, 256, 256, 256, 256, 255, 256, 256]; |
| 92 |
| 87 const kElementCount = 40; | 93 const kElementCount = 40; |
| 88 | 94 |
| 89 function test_load(array, sum) { | 95 function test_load(array, sum) { |
| 90 for (var i = 0; i < kElementCount; i++) { | 96 for (var i = 0; i < kElementCount; i++) { |
| 91 sum += array[i]; | 97 sum += array[i]; |
| 92 } | 98 } |
| 93 return sum; | 99 return sum; |
| 94 } | 100 } |
| 95 | 101 |
| 96 function test_load_const_key(array, sum) { | 102 function test_load_const_key(array, sum) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 return sum; | 113 return sum; |
| 108 } | 114 } |
| 109 | 115 |
| 110 function test_store_const_key(array, sum) { | 116 function test_store_const_key(array, sum) { |
| 111 sum += array[0] = 1; | 117 sum += array[0] = 1; |
| 112 sum += array[1] = 2; | 118 sum += array[1] = 2; |
| 113 sum += array[2] = 3; | 119 sum += array[2] = 3; |
| 114 return sum; | 120 return sum; |
| 115 } | 121 } |
| 116 | 122 |
| 117 function run_test(test_func, array, expected_sum_per_run) { | 123 |
| 124 function test_store_middle_double(array, sum) { |
| 125 array[0] = 253.75; |
| 126 return array[0]; |
| 127 } |
| 128 |
| 129 |
| 130 function test_store_high_double(array, sum) { |
| 131 array[0] = 256.25; |
| 132 return array[0]; |
| 133 } |
| 134 |
| 135 function test_store_high_double(array, sum) { |
| 136 array[0] = 256.25; |
| 137 return array[0]; |
| 138 } |
| 139 |
| 140 function test_store_low_int(array, sum) { |
| 141 array[0] = -1; |
| 142 return array[0]; |
| 143 } |
| 144 |
| 145 function test_store_high_int(array, sum) { |
| 146 array[0] = 256; |
| 147 return array[0]; |
| 148 } |
| 149 |
| 150 function test_store_nan(array, sum) { |
| 151 array[0] = NaN; |
| 152 return array[0]; |
| 153 } |
| 154 |
| 155 const kRuns = 10; |
| 156 |
| 157 function run_test(test_func, array, expected_result) { |
| 118 for (var i = 0; i < 5; i++) test_func(array, 0); | 158 for (var i = 0; i < 5; i++) test_func(array, 0); |
| 119 %OptimizeFunctionOnNextCall(test_func); | 159 %OptimizeFunctionOnNextCall(test_func); |
| 120 const kRuns = 10; | |
| 121 var sum = 0; | 160 var sum = 0; |
| 122 for (var i = 0; i < kRuns; i++) { | 161 for (var i = 0; i < kRuns; i++) { |
| 123 sum = test_func(array, sum); | 162 sum = test_func(array, sum); |
| 124 } | 163 } |
| 125 assertEquals(sum, expected_sum_per_run * kRuns); | 164 assertEquals(expected_result, sum); |
| 126 %DeoptimizeFunction(test_func); | 165 %DeoptimizeFunction(test_func); |
| 127 gc(); // Makes V8 forget about type information for test_func. | 166 gc(); // Makes V8 forget about type information for test_func. |
| 128 } | 167 } |
| 129 | 168 |
| 130 for (var t = 0; t < types.length; t++) { | 169 for (var t = 0; t < types.length; t++) { |
| 131 var type = types[t]; | 170 var type = types[t]; |
| 171 print ("type = " + t); |
| 132 var a = new type(kElementCount); | 172 var a = new type(kElementCount); |
| 133 for (var i = 0; i < kElementCount; i++) { | 173 for (var i = 0; i < kElementCount; i++) { |
| 134 a[i] = i; | 174 a[i] = i; |
| 135 } | 175 } |
| 136 | 176 |
| 137 // Run test functions defined above. | 177 // Run test functions defined above. |
| 138 run_test(test_load, a, 780); | 178 run_test(test_load, a, 780 * kRuns); |
| 139 run_test(test_load_const_key, a, 3); | 179 run_test(test_load_const_key, a, 3 * kRuns); |
| 140 run_test(test_store, a, 820); | 180 run_test(test_store, a, 820 * kRuns); |
| 141 run_test(test_store_const_key, a, 6); | 181 run_test(test_store_const_key, a, 6 * kRuns); |
| 142 | 182 run_test(test_store_low_int, a, test_result_low_int[t]); |
| 183 run_test(test_store_high_int, a, test_result_high_int[t]); |
| 184 run_test(test_store_nan, a, test_result_nan[t]); |
| 185 run_test(test_store_middle_double, a, test_result_middle[t]); |
| 186 |
| 143 // Test the correct behavior of the |length| property (which is read-only). | 187 // Test the correct behavior of the |length| property (which is read-only). |
| 144 assertEquals(kElementCount, a.length); | 188 if (t != 0) { |
| 145 a.length = 2; | 189 assertEquals(kElementCount, a.length); |
| 146 assertEquals(kElementCount, a.length); | 190 a.length = 2; |
| 147 assertTrue(delete a.length); | 191 assertEquals(kElementCount, a.length); |
| 148 a.length = 2 | 192 assertTrue(delete a.length); |
| 149 assertEquals(2, a.length); | 193 a.length = 2; |
| 194 assertEquals(2, a.length); |
| 195 } |
| 150 } | 196 } |
| OLD | NEW |