OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/v8.h" |
| 6 |
| 7 #include "test/cctest/compiler/function-tester.h" |
| 8 |
| 9 using namespace v8::internal; |
| 10 using namespace v8::internal::compiler; |
| 11 |
| 12 template <typename U> |
| 13 static void TypedArrayLoadHelper(const char* array_type) { |
| 14 const int64_t values[] = { |
| 15 0x00000000, 0x00000001, 0x00000023, 0x00000042, 0x12345678, 0x87654321, |
| 16 0x0000003f, 0x0000007f, 0x00003fff, 0x00007fff, 0x3fffffff, 0x7fffffff, |
| 17 0x000000ff, 0x00000080, 0x0000ffff, 0x00008000, 0xffffffff, 0x80000000, |
| 18 }; |
| 19 size_t size = arraysize(values); |
| 20 EmbeddedVector<char, 1024> values_buffer; |
| 21 StringBuilder values_builder(values_buffer.start(), values_buffer.length()); |
| 22 for (unsigned i = 0; i < size; i++) { |
| 23 values_builder.AddFormatted("a[%d] = 0x%08x;", i, values[i]); |
| 24 } |
| 25 |
| 26 // Note that below source creates two different typed arrays with distinct |
| 27 // elements kind to get coverage for both access patterns: |
| 28 // - IsFixedTypedArrayElementsKind(x) |
| 29 // - IsExternalArrayElementsKind(y) |
| 30 const char* source = |
| 31 "(function(a) {" |
| 32 " var x = (a = new %1$sArray(%2$d)); %3$s;" |
| 33 " var y = (a = new %1$sArray(%2$d)); %3$s; %%TypedArrayGetBuffer(y);" |
| 34 " if (!%%HasFixed%1$sElements(x)) %%AbortJS('x');" |
| 35 " if (!%%HasExternal%1$sElements(y)) %%AbortJS('y');" |
| 36 " function f(a,b) {" |
| 37 " a = a | 0; b = b | 0;" |
| 38 " return x[a] + y[b];" |
| 39 " }" |
| 40 " return f;" |
| 41 "})()"; |
| 42 EmbeddedVector<char, 1024> source_buffer; |
| 43 SNPrintF(source_buffer, source, array_type, size, values_buffer.start()); |
| 44 |
| 45 FunctionTester T(source_buffer.start(), true); |
| 46 for (unsigned i = 0; i < size; i++) { |
| 47 for (unsigned j = 0; j < size; j++) { |
| 48 double value_a = static_cast<U>(values[i]); |
| 49 double value_b = static_cast<U>(values[j]); |
| 50 double expected = value_a + value_b; |
| 51 T.CheckCall(T.Val(expected), T.Val(i), T.Val(j)); |
| 52 } |
| 53 } |
| 54 } |
| 55 |
| 56 |
| 57 TEST(TypedArrayLoad) { |
| 58 FLAG_turbo_types = true; |
| 59 FLAG_typed_array_max_size_in_heap = 256; |
| 60 TypedArrayLoadHelper<int8_t>("Int8"); |
| 61 TypedArrayLoadHelper<uint8_t>("Uint8"); |
| 62 TypedArrayLoadHelper<int16_t>("Int16"); |
| 63 TypedArrayLoadHelper<uint16_t>("Uint16"); |
| 64 TypedArrayLoadHelper<int32_t>("Int32"); |
| 65 TypedArrayLoadHelper<uint32_t>("Uint32"); |
| 66 TypedArrayLoadHelper<double>("Float64"); |
| 67 // TODO(mstarzinger): Add tests for Float32. |
| 68 // TODO(mstarzinger): Add tests for ClampedUint8. |
| 69 } |
OLD | NEW |