OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 using namespace v8::internal; | 9 using namespace v8::internal; |
10 using namespace v8::internal::compiler; | 10 using namespace v8::internal::compiler; |
11 | 11 |
12 template <typename U> | 12 template <typename U> |
13 static void TypedArrayLoadHelper(const char* array_type) { | 13 static void TypedArrayLoadHelper(const char* array_type) { |
14 static const uint32_t kValues[] = { | 14 static const uint32_t kValues[] = { |
15 0x00000000, 0x00000001, 0x00000023, 0x00000042, 0x12345678, 0x87654321, | 15 0x00000000, 0x00000001, 0x00000023, 0x00000042, 0x12345678, 0x87654321, |
16 0x0000003f, 0x0000007f, 0x00003fff, 0x00007fff, 0x3fffffff, 0x7fffffff, | 16 0x0000003f, 0x0000007f, 0x00003fff, 0x00007fff, 0x3fffffff, 0x7fffffff, |
17 0x000000ff, 0x00000080, 0x0000ffff, 0x00008000, 0xffffffff, 0x80000000}; | 17 0x000000ff, 0x00000080, 0x0000ffff, 0x00008000, 0xffffffff, 0x80000000}; |
18 EmbeddedVector<char, 1024> values_buffer; | 18 EmbeddedVector<char, 1024> values_buffer; |
19 StringBuilder values_builder(values_buffer.start(), values_buffer.length()); | 19 StringBuilder values_builder(values_buffer.start(), values_buffer.length()); |
20 for (size_t i = 0; i < arraysize(kValues); ++i) { | 20 for (size_t i = 0; i < arraysize(kValues); ++i) { |
21 values_builder.AddFormatted("a[%d] = 0x%08x;", i, kValues[i]); | 21 values_builder.AddFormatted("a[%d] = 0x%08x;", i, kValues[i]); |
22 } | 22 } |
23 | 23 |
24 // Note that below source creates two different typed arrays with distinct | 24 // Note that below source creates two different typed arrays with the same |
25 // elements kind to get coverage for both access patterns: | 25 // elements kind to get coverage for both (on heap / with external backing |
26 // - IsFixedTypedArrayElementsKind(x) | 26 // store) access patterns. |
27 // - IsExternalArrayElementsKind(y) | |
28 const char* source = | 27 const char* source = |
29 "(function(a) {" | 28 "(function(a) {" |
30 " var x = (a = new %sArray(%d)); %s;" | 29 " var x = (a = new %sArray(%d)); %s;" |
31 " var y = (a = new %sArray(%d)); %s; %%TypedArrayGetBuffer(y);" | 30 " var y = (a = new %sArray(%d)); %s; %%TypedArrayGetBuffer(y);" |
32 " if (!%%HasFixed%sElements(x)) %%AbortJS('x');" | 31 " if (!%%HasFixed%sElements(x)) %%AbortJS('x');" |
33 " if (!%%HasExternal%sElements(y)) %%AbortJS('y');" | 32 " if (!%%HasFixed%sElements(y)) %%AbortJS('y');" |
34 " function f(a,b) {" | 33 " function f(a,b) {" |
35 " a = a | 0; b = b | 0;" | 34 " a = a | 0; b = b | 0;" |
36 " return x[a] + y[b];" | 35 " return x[a] + y[b];" |
37 " }" | 36 " }" |
38 " return f;" | 37 " return f;" |
39 "})()"; | 38 "})()"; |
40 EmbeddedVector<char, 1024> source_buffer; | 39 EmbeddedVector<char, 1024> source_buffer; |
41 SNPrintF(source_buffer, source, array_type, arraysize(kValues), | 40 SNPrintF(source_buffer, source, array_type, arraysize(kValues), |
42 values_buffer.start(), array_type, arraysize(kValues), | 41 values_buffer.start(), array_type, arraysize(kValues), |
43 values_buffer.start(), array_type, array_type); | 42 values_buffer.start(), array_type, array_type); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 static const uint32_t kValues[] = { | 76 static const uint32_t kValues[] = { |
78 0x00000000, 0x00000001, 0x00000023, 0x00000042, 0x12345678, 0x87654321, | 77 0x00000000, 0x00000001, 0x00000023, 0x00000042, 0x12345678, 0x87654321, |
79 0x0000003f, 0x0000007f, 0x00003fff, 0x00007fff, 0x3fffffff, 0x7fffffff, | 78 0x0000003f, 0x0000007f, 0x00003fff, 0x00007fff, 0x3fffffff, 0x7fffffff, |
80 0x000000ff, 0x00000080, 0x0000ffff, 0x00008000, 0xffffffff, 0x80000000}; | 79 0x000000ff, 0x00000080, 0x0000ffff, 0x00008000, 0xffffffff, 0x80000000}; |
81 EmbeddedVector<char, 1024> values_buffer; | 80 EmbeddedVector<char, 1024> values_buffer; |
82 StringBuilder values_builder(values_buffer.start(), values_buffer.length()); | 81 StringBuilder values_builder(values_buffer.start(), values_buffer.length()); |
83 for (size_t i = 0; i < arraysize(kValues); ++i) { | 82 for (size_t i = 0; i < arraysize(kValues); ++i) { |
84 values_builder.AddFormatted("a[%d] = 0x%08x;", i, kValues[i]); | 83 values_builder.AddFormatted("a[%d] = 0x%08x;", i, kValues[i]); |
85 } | 84 } |
86 | 85 |
87 // Note that below source creates two different typed arrays with distinct | 86 // Note that below source creates two different typed arrays with the same |
88 // elements kind to get coverage for both access patterns: | 87 // elements kind to get coverage for both (on heap/with external backing |
89 // - IsFixedTypedArrayElementsKind(x) | 88 // store) access patterns. |
90 // - IsExternalArrayElementsKind(y) | |
91 const char* source = | 89 const char* source = |
92 "(function(a) {" | 90 "(function(a) {" |
93 " var x = (a = new %sArray(%d)); %s;" | 91 " var x = (a = new %sArray(%d)); %s;" |
94 " var y = (a = new %sArray(%d)); %s; %%TypedArrayGetBuffer(y);" | 92 " var y = (a = new %sArray(%d)); %s; %%TypedArrayGetBuffer(y);" |
95 " if (!%%HasFixed%sElements(x)) %%AbortJS('x');" | 93 " if (!%%HasFixed%sElements(x)) %%AbortJS('x');" |
96 " if (!%%HasExternal%sElements(y)) %%AbortJS('y');" | 94 " if (!%%HasFixed%sElements(y)) %%AbortJS('y');" |
97 " function f(a,b) {" | 95 " function f(a,b) {" |
98 " a = a | 0; b = b | 0;" | 96 " a = a | 0; b = b | 0;" |
99 " var t = x[a];" | 97 " var t = x[a];" |
100 " x[a] = y[b];" | 98 " x[a] = y[b];" |
101 " y[b] = t;" | 99 " y[b] = t;" |
102 " t = y[b];" | 100 " t = y[b];" |
103 " y[b] = x[a];" | 101 " y[b] = x[a];" |
104 " x[a] = t;" | 102 " x[a] = t;" |
105 " return x[a] + y[b];" | 103 " return x[a] + y[b];" |
106 " }" | 104 " }" |
(...skipping 25 matching lines...) Expand all Loading... |
132 TypedArrayStoreHelper<int8_t>("Int8"); | 130 TypedArrayStoreHelper<int8_t>("Int8"); |
133 TypedArrayStoreHelper<uint8_t>("Uint8"); | 131 TypedArrayStoreHelper<uint8_t>("Uint8"); |
134 TypedArrayStoreHelper<int16_t>("Int16"); | 132 TypedArrayStoreHelper<int16_t>("Int16"); |
135 TypedArrayStoreHelper<uint16_t>("Uint16"); | 133 TypedArrayStoreHelper<uint16_t>("Uint16"); |
136 TypedArrayStoreHelper<int32_t>("Int32"); | 134 TypedArrayStoreHelper<int32_t>("Int32"); |
137 TypedArrayStoreHelper<uint32_t>("Uint32"); | 135 TypedArrayStoreHelper<uint32_t>("Uint32"); |
138 TypedArrayStoreHelper<float>("Float32"); | 136 TypedArrayStoreHelper<float>("Float32"); |
139 TypedArrayStoreHelper<double>("Float64"); | 137 TypedArrayStoreHelper<double>("Float64"); |
140 // TODO(mstarzinger): Add tests for ClampedUint8. | 138 // TODO(mstarzinger): Add tests for ClampedUint8. |
141 } | 139 } |
OLD | NEW |