| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // VMOptions=--deoptimization_counter_threshold=1000 --optimization-counter-thre
shold=10 | |
| 5 | |
| 6 // Library tag to be able to run in html test framework. | |
| 7 library uint32x4_list_test; | |
| 8 | |
| 9 import 'package:expect/expect.dart'; | |
| 10 import 'dart:typed_data'; | |
| 11 | |
| 12 testLoadStore(array) { | |
| 13 Expect.equals(8, array.length); | |
| 14 Expect.isTrue(array is List<Uint32x4>); | |
| 15 array[0] = new Uint32x4(1, 2, 3, 4); | |
| 16 Expect.equals(1, array[0].x); | |
| 17 Expect.equals(2, array[0].y); | |
| 18 Expect.equals(3, array[0].z); | |
| 19 Expect.equals(4, array[0].w); | |
| 20 array[1] = array[0]; | |
| 21 array[0] = array[0].withX(9); | |
| 22 Expect.equals(9, array[0].x); | |
| 23 Expect.equals(2, array[0].y); | |
| 24 Expect.equals(3, array[0].z); | |
| 25 Expect.equals(4, array[0].w); | |
| 26 Expect.equals(1, array[1].x); | |
| 27 Expect.equals(2, array[1].y); | |
| 28 Expect.equals(3, array[1].z); | |
| 29 Expect.equals(4, array[1].w); | |
| 30 } | |
| 31 | |
| 32 testLoadStoreDeopt(array, index, value) { | |
| 33 array[index] = value; | |
| 34 Expect.equals(value.x, array[index].x); | |
| 35 Expect.equals(value.y, array[index].y); | |
| 36 Expect.equals(value.z, array[index].z); | |
| 37 Expect.equals(value.w, array[index].w); | |
| 38 } | |
| 39 | |
| 40 testLoadStoreDeoptDriver() { | |
| 41 Uint32x4List list = new Uint32x4List(4); | |
| 42 Uint32x4 value = new Uint32x4(1, 2, 3, 4); | |
| 43 for (int i = 0; i < 20; i++) { | |
| 44 testLoadStoreDeopt(list, 0, value); | |
| 45 } | |
| 46 try { | |
| 47 // Invalid index. | |
| 48 testLoadStoreDeopt(list, 5, value); | |
| 49 } catch (_) {} | |
| 50 for (int i = 0; i < 20; i++) { | |
| 51 testLoadStoreDeopt(list, 0, value); | |
| 52 } | |
| 53 try { | |
| 54 // null list. | |
| 55 testLoadStoreDeopt(null, 0, value); | |
| 56 } catch (_) {} | |
| 57 for (int i = 0; i < 20; i++) { | |
| 58 testLoadStoreDeopt(list, 0, value); | |
| 59 } | |
| 60 try { | |
| 61 // null value. | |
| 62 testLoadStoreDeopt(list, 0, null); | |
| 63 } catch (_) {} | |
| 64 for (int i = 0; i < 20; i++) { | |
| 65 testLoadStoreDeopt(list, 0, value); | |
| 66 } | |
| 67 try { | |
| 68 // non-smi index. | |
| 69 testLoadStoreDeopt(list, 3.14159, value); | |
| 70 } catch (_) {} | |
| 71 for (int i = 0; i < 20; i++) { | |
| 72 testLoadStoreDeopt(list, 0, value); | |
| 73 } | |
| 74 try { | |
| 75 // non-Uint32x4 value. | |
| 76 testLoadStoreDeopt(list, 0, 4.toDouble()); | |
| 77 } catch (_) {} | |
| 78 for (int i = 0; i < 20; i++) { | |
| 79 testLoadStoreDeopt(list, 0, value); | |
| 80 } | |
| 81 try { | |
| 82 // non-Uint32x4List list. | |
| 83 testLoadStoreDeopt([new Uint32x4(2, 3, 4, 5)], 0, value); | |
| 84 } catch (_) {} | |
| 85 for (int i = 0; i < 20; i++) { | |
| 86 testLoadStoreDeopt(list, 0, value); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 testListZero() { | |
| 91 Uint32x4List list = new Uint32x4List(1); | |
| 92 Expect.equals(0, list[0].x); | |
| 93 Expect.equals(0, list[0].y); | |
| 94 Expect.equals(0, list[0].z); | |
| 95 Expect.equals(0, list[0].w); | |
| 96 } | |
| 97 | |
| 98 testView(array) { | |
| 99 Expect.equals(8, array.length); | |
| 100 Expect.isTrue(array is List<Uint32x4>); | |
| 101 Expect.equals(0, array[0].x); | |
| 102 Expect.equals(1, array[0].y); | |
| 103 Expect.equals(2, array[0].z); | |
| 104 Expect.equals(3, array[0].w); | |
| 105 Expect.equals(4, array[1].x); | |
| 106 Expect.equals(5, array[1].y); | |
| 107 Expect.equals(6, array[1].z); | |
| 108 Expect.equals(7, array[1].w); | |
| 109 } | |
| 110 | |
| 111 testSublist(array) { | |
| 112 Expect.equals(8, array.length); | |
| 113 Expect.isTrue(array is Uint32x4List); | |
| 114 var a = array.sublist(0, 1); | |
| 115 Expect.equals(1, a.length); | |
| 116 Expect.equals(0, a[0].x); | |
| 117 Expect.equals(1, a[0].y); | |
| 118 Expect.equals(2, a[0].z); | |
| 119 Expect.equals(3, a[0].w); | |
| 120 a = array.sublist(1, 2); | |
| 121 Expect.equals(4, a[0].x); | |
| 122 Expect.equals(5, a[0].y); | |
| 123 Expect.equals(6, a[0].z); | |
| 124 Expect.equals(7, a[0].w); | |
| 125 a = array.sublist(0); | |
| 126 Expect.equals(a.length, array.length); | |
| 127 for (int i = 0; i < array.length; i++) { | |
| 128 Expect.equals(array[i].x, a[i].x); | |
| 129 Expect.equals(array[i].y, a[i].y); | |
| 130 Expect.equals(array[i].z, a[i].z); | |
| 131 Expect.equals(array[i].w, a[i].w); | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 main() { | |
| 136 var list; | |
| 137 | |
| 138 list = new Uint32x4List(8); | |
| 139 for (int i = 0; i < 20; i++) { | |
| 140 testLoadStore(list); | |
| 141 } | |
| 142 | |
| 143 Uint32List uint32List = new Uint32List(32); | |
| 144 for (int i = 0; i < uint32List.length; i++) { | |
| 145 uint32List[i] = i; | |
| 146 } | |
| 147 list = new Uint32x4List.view(uint32List.buffer); | |
| 148 for (int i = 0; i < 20; i++) { | |
| 149 testView(list); | |
| 150 } | |
| 151 for (int i = 0; i < 20; i++) { | |
| 152 testSublist(list); | |
| 153 } | |
| 154 for (int i = 0; i < 20; i++) { | |
| 155 testLoadStore(list); | |
| 156 } | |
| 157 for (int i = 0; i < 20; i++) { | |
| 158 testListZero(); | |
| 159 } | |
| 160 testLoadStoreDeoptDriver(); | |
| 161 } | |
| OLD | NEW |