Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: tests/standalone/float_array_test.dart

Issue 11087087: Apply John's change (Issue 11077007: Intrinsify Float64 array access on ia32 and x64.). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // Dart test program for testing native float arrays. 5 // Dart test program for testing native float arrays.
6 6
7 // Library tag to be able to run in html test framework. 7 // Library tag to be able to run in html test framework.
8 #library("FloatArrayTest.dart"); 8 #library("FloatArrayTest.dart");
9 9
10 #import('dart:scalarlist'); 10 #import('dart:scalarlist');
11 11
12 void testCreateFloatArray() { 12 void testCreateFloat32Array() {
13 Float32List floatArray; 13 Float32List floatArray;
14 14
15 floatArray = new Float32List(0); 15 floatArray = new Float32List(0);
16 Expect.equals(0, floatArray.length); 16 Expect.equals(0, floatArray.length);
17 17
18 floatArray = new Float32List(10); 18 floatArray = new Float32List(10);
19 Expect.equals(10, floatArray.length); 19 Expect.equals(10, floatArray.length);
20 for (int i = 0; i < 10; i++) { 20 for (int i = 0; i < 10; i++) {
21 Expect.equals(0.0, floatArray[i]); 21 Expect.equals(0.0, floatArray[i]);
22 } 22 }
23 } 23 }
24 24
25 void testSetRange() { 25 void testSetRange32() {
26 Float32List floatArray = new Float32List(3); 26 Float32List floatArray = new Float32List(3);
27 27
28 List<num> list = [10.0, 11.0, 12.0]; 28 List<num> list = [10.0, 11.0, 12.0];
29 floatArray.setRange(0, 3, list); 29 floatArray.setRange(0, 3, list);
30 for (int i = 0; i < 3; i++) { 30 for (int i = 0; i < 3; i++) {
31 Expect.equals(10 + i, floatArray[i]); 31 Expect.equals(10 + i, floatArray[i]);
32 } 32 }
33 33
34 floatArray[0] = 20.0; 34 floatArray[0] = 20.0;
35 floatArray[1] = 21.0; 35 floatArray[1] = 21.0;
36 floatArray[2] = 22.0; 36 floatArray[2] = 22.0;
37 list.setRange(0, 3, floatArray); 37 list.setRange(0, 3, floatArray);
38 for (int i = 0; i < 3; i++) { 38 for (int i = 0; i < 3; i++) {
39 Expect.equals(20 + i, list[i]); 39 Expect.equals(20 + i, list[i]);
40 } 40 }
41 41
42 floatArray.setRange(1, 2, const [8.0, 9.0]); 42 // 4.0e40 is larger than the largest representable float.
43 floatArray.setRange(1, 2, const [8.0, 4.0e40]);
43 Expect.equals(20, floatArray[0]); 44 Expect.equals(20, floatArray[0]);
44 Expect.equals(8, floatArray[1]); 45 Expect.equals(8, floatArray[1]);
45 Expect.equals(9, floatArray[2]); 46 Expect.equals(double.INFINITY, floatArray[2]);
46 } 47 }
47 48
48 void testIndexOutOfRange() { 49 void testIndexOutOfRange32() {
49 Float32List floatArray = new Float32List(3); 50 Float32List floatArray = new Float32List(3);
50 List<num> list = const [0.0, 1.0, 2.0, 3.0]; 51 List<num> list = const [0.0, 1.0, 2.0, 3.0];
51 52
52 Expect.throws(() { 53 Expect.throws(() {
53 floatArray[5] = 2.0; 54 floatArray[5] = 2.0;
54 }); 55 });
55 Expect.throws(() { 56 Expect.throws(() {
56 floatArray.setRange(0, 4, list); 57 floatArray.setRange(0, 4, list);
57 }); 58 });
58 59
59 Expect.throws(() { 60 Expect.throws(() {
60 floatArray.setRange(3, 1, list); 61 floatArray.setRange(3, 1, list);
61 }); 62 });
62 } 63 }
63 64
64 void testIndexOf() { 65 void testIndexOf32() {
65 var list = new Float32List(10); 66 var list = new Float32List(10);
66 for (int i = 0; i < list.length; i++) { 67 for (int i = 0; i < list.length; i++) {
67 list[i] = i + 10.0; 68 list[i] = i + 10.0;
68 } 69 }
69 Expect.equals(0, list.indexOf(10)); 70 Expect.equals(0, list.indexOf(10));
70 Expect.equals(5, list.indexOf(15)); 71 Expect.equals(5, list.indexOf(15));
71 Expect.equals(9, list.indexOf(19)); 72 Expect.equals(9, list.indexOf(19));
72 Expect.equals(-1, list.indexOf(20)); 73 Expect.equals(-1, list.indexOf(20));
73 74
74 list = new Float32List(10); 75 list = new Float32List(10);
75 for (int i = 0; i < list.length; i++) { 76 for (int i = 0; i < list.length; i++) {
76 list[i] = i + 10.0; 77 list[i] = i + 10.0;
77 } 78 }
78 Expect.equals(0, list.indexOf(10.0)); 79 Expect.equals(0, list.indexOf(10.0));
79 Expect.equals(5, list.indexOf(15.0)); 80 Expect.equals(5, list.indexOf(15.0));
80 Expect.equals(9, list.indexOf(19.0)); 81 Expect.equals(9, list.indexOf(19.0));
81 Expect.equals(-1, list.indexOf(20.0)); 82 Expect.equals(-1, list.indexOf(20.0));
82 } 83 }
83 84
85 void testCreateFloat64Array() {
86 Float64List floatArray;
87
88 floatArray = new Float64List(0);
89 Expect.equals(0, floatArray.length);
90
91 floatArray = new Float64List(10);
92 Expect.equals(10, floatArray.length);
93 for (int i = 0; i < 10; i++) {
94 Expect.equals(0.0, floatArray[i]);
95 }
96 }
97
98 void testSetRange64() {
99 Float64List floatArray = new Float64List(3);
100
101 List<num> list = [10.0, 11.0, 12.0];
102 floatArray.setRange(0, 3, list);
103 for (int i = 0; i < 3; i++) {
104 Expect.equals(10 + i, floatArray[i]);
105 }
106
107 floatArray[0] = 20.0;
108 floatArray[1] = 21.0;
109 floatArray[2] = 22.0;
110 list.setRange(0, 3, floatArray);
111 for (int i = 0; i < 3; i++) {
112 Expect.equals(20 + i, list[i]);
113 }
114
115 // Unlike Float32Array we can properly represent 4.0e40
116 floatArray.setRange(1, 2, const [8.0, 4.0e40]);
117 Expect.equals(20, floatArray[0]);
118 Expect.equals(8, floatArray[1]);
119 Expect.equals(4.0e40, floatArray[2]);
120 }
121
122 void testIndexOutOfRange64() {
123 Float64List floatArray = new Float64List(3);
124 List<num> list = const [0.0, 1.0, 2.0, 3.0];
125
126 Expect.throws(() {
127 floatArray[5] = 2.0;
128 });
129 Expect.throws(() {
130 floatArray.setRange(0, 4, list);
131 });
132
133 Expect.throws(() {
134 floatArray.setRange(3, 1, list);
135 });
136 }
137
138 void testIndexOf64() {
139 var list = new Float64List(10);
140 for (int i = 0; i < list.length; i++) {
141 list[i] = i + 10.0;
142 }
143 Expect.equals(0, list.indexOf(10));
144 Expect.equals(5, list.indexOf(15));
145 Expect.equals(9, list.indexOf(19));
146 Expect.equals(-1, list.indexOf(20));
147
148 list = new Float64List(10);
149 for (int i = 0; i < list.length; i++) {
150 list[i] = i + 10.0;
151 }
152 Expect.equals(0, list.indexOf(10.0));
153 Expect.equals(5, list.indexOf(15.0));
154 Expect.equals(9, list.indexOf(19.0));
155 Expect.equals(-1, list.indexOf(20.0));
156 }
157
84 main() { 158 main() {
85 for (int i = 0; i < 2000; i++) { 159 for (int i = 0; i < 2000; i++) {
86 testCreateFloatArray(); 160 testCreateFloat32Array();
87 testSetRange(); 161 testSetRange32();
88 testIndexOutOfRange(); 162 testIndexOutOfRange32();
89 testIndexOf(); 163 testIndexOf32();
164 }
165 for (int i = 0; i < 2000; i++) {
166 testCreateFloat64Array();
167 testSetRange64();
168 testIndexOutOfRange64();
169 testIndexOf64();
90 } 170 }
91 } 171 }
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698