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; |
(...skipping 11 matching lines...) Expand all Loading... |
22 for (unsigned i = 0; i < size; i++) { | 22 for (unsigned i = 0; i < size; i++) { |
23 values_builder.AddFormatted("a[%d] = 0x%08x;", i, values[i]); | 23 values_builder.AddFormatted("a[%d] = 0x%08x;", i, values[i]); |
24 } | 24 } |
25 | 25 |
26 // Note that below source creates two different typed arrays with distinct | 26 // Note that below source creates two different typed arrays with distinct |
27 // elements kind to get coverage for both access patterns: | 27 // elements kind to get coverage for both access patterns: |
28 // - IsFixedTypedArrayElementsKind(x) | 28 // - IsFixedTypedArrayElementsKind(x) |
29 // - IsExternalArrayElementsKind(y) | 29 // - IsExternalArrayElementsKind(y) |
30 const char* source = | 30 const char* source = |
31 "(function(a) {" | 31 "(function(a) {" |
32 " var x = (a = new %1$sArray(%2$d)); %3$s;" | 32 " var x = (a = new %sArray(%d)); %s;" |
33 " var y = (a = new %1$sArray(%2$d)); %3$s; %%TypedArrayGetBuffer(y);" | 33 " var y = (a = new %sArray(%d)); %s; %%TypedArrayGetBuffer(y);" |
34 " if (!%%HasFixed%1$sElements(x)) %%AbortJS('x');" | 34 " if (!%%HasFixed%sElements(x)) %%AbortJS('x');" |
35 " if (!%%HasExternal%1$sElements(y)) %%AbortJS('y');" | 35 " if (!%%HasExternal%sElements(y)) %%AbortJS('y');" |
36 " function f(a,b) {" | 36 " function f(a,b) {" |
37 " a = a | 0; b = b | 0;" | 37 " a = a | 0; b = b | 0;" |
38 " return x[a] + y[b];" | 38 " return x[a] + y[b];" |
39 " }" | 39 " }" |
40 " return f;" | 40 " return f;" |
41 "})()"; | 41 "})()"; |
42 EmbeddedVector<char, 1024> source_buffer; | 42 EmbeddedVector<char, 1024> source_buffer; |
43 SNPrintF(source_buffer, source, array_type, size, values_buffer.start()); | 43 SNPrintF(source_buffer, source, array_type, size, values_buffer.start(), |
| 44 array_type, size, values_buffer.start(), array_type, array_type); |
44 | 45 |
45 FunctionTester T( | 46 FunctionTester T( |
46 source_buffer.start(), | 47 source_buffer.start(), |
47 CompilationInfo::kContextSpecializing | CompilationInfo::kTypingEnabled); | 48 CompilationInfo::kContextSpecializing | CompilationInfo::kTypingEnabled); |
48 for (unsigned i = 0; i < size; i++) { | 49 for (unsigned i = 0; i < size; i++) { |
49 for (unsigned j = 0; j < size; j++) { | 50 for (unsigned j = 0; j < size; j++) { |
50 double value_a = static_cast<U>(values[i]); | 51 double value_a = static_cast<U>(values[i]); |
51 double value_b = static_cast<U>(values[j]); | 52 double value_b = static_cast<U>(values[j]); |
52 double expected = value_a + value_b; | 53 double expected = value_a + value_b; |
53 T.CheckCall(T.Val(expected), T.Val(i), T.Val(j)); | 54 T.CheckCall(T.Val(expected), T.Val(i), T.Val(j)); |
54 } | 55 } |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 | 59 |
59 TEST(TypedArrayLoad) { | 60 TEST(TypedArrayLoad) { |
60 FLAG_typed_array_max_size_in_heap = 256; | 61 FLAG_typed_array_max_size_in_heap = 256; |
61 TypedArrayLoadHelper<int8_t>("Int8"); | 62 TypedArrayLoadHelper<int8_t>("Int8"); |
62 TypedArrayLoadHelper<uint8_t>("Uint8"); | 63 TypedArrayLoadHelper<uint8_t>("Uint8"); |
63 TypedArrayLoadHelper<int16_t>("Int16"); | 64 TypedArrayLoadHelper<int16_t>("Int16"); |
64 TypedArrayLoadHelper<uint16_t>("Uint16"); | 65 TypedArrayLoadHelper<uint16_t>("Uint16"); |
65 TypedArrayLoadHelper<int32_t>("Int32"); | 66 TypedArrayLoadHelper<int32_t>("Int32"); |
66 TypedArrayLoadHelper<uint32_t>("Uint32"); | 67 TypedArrayLoadHelper<uint32_t>("Uint32"); |
67 TypedArrayLoadHelper<double>("Float64"); | 68 TypedArrayLoadHelper<double>("Float64"); |
68 // TODO(mstarzinger): Add tests for Float32. | 69 // TODO(mstarzinger): Add tests for Float32. |
69 // TODO(mstarzinger): Add tests for ClampedUint8. | 70 // TODO(mstarzinger): Add tests for ClampedUint8. |
70 } | 71 } |
OLD | NEW |