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

Side by Side Diff: tests/standalone/53bit_overflow_test.dart

Issue 16664003: Improvements to 53-bit overflow checking. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | « tests/standalone/53bit_overflow_literal_test.dart ('k') | tests/standalone/standalone.status » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 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 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 // VMOptions=--throw_on_javascript_int_overflow 5 // VMOptions=--throw_on_javascript_int_overflow --optimization_counter_threshold =10
6 6
7 7
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
11 11
12 int double_to_int_throws() { 12 double dti_arg;
13 double d = 1.9e16; 13 int double_to_int() {
14 return d.toInt(); 14 return dti_arg.toInt();
15 } 15 }
16 16
17 17
18 int integer_add_throws() { 18 int ia_arg1;
19 return (1 << 52) + (1 << 52); 19 int ia_arg2;
20 int integer_add() {
21 return ia_arg1 + ia_arg2;
20 } 22 }
21 23
22 24
23 int i64list_throws() { 25 int is_arg;
24 var i64l = new Int64List(16); 26 int integer_shift() {
25 i64l[0] = (1 << 54); 27 return is_arg << 1;
26 return i64l[0];
27 } 28 }
28 29
29 30
30 int double_to_int() { 31 int max_add_throws() {
31 double d = 1.9e14; 32 return 0xFFFFFFFFFFFFF + 1;
32 return d.toInt();
33 } 33 }
34 34
35 35
36 int integer_add() { 36 int min_sub_throws() {
37 return (1 << 50) + (1 << 50); 37 return -0xFFFFFFFFFFFFF - 2;
38 }
39
40
41 int n_arg;
42 int negate() {
43 return -n_arg;
44 }
45
46
47 int max_literal() {
48 return 0xFFFFFFFFFFFFF;
49 }
50
51
52 int min_literal() {
53 var min_literal = -0xFFFFFFFFFFFFF - 1;
54 return min_literal;
38 } 55 }
39 56
40 57
41 main() { 58 main() {
42 Expect.throws(double_to_int_throws, (e) => e is FiftyThreeBitOverflowError); 59 Expect.equals(0xFFFFFFFFFFFFF, max_literal());
43 Expect.throws(integer_add_throws, (e) => e is FiftyThreeBitOverflowError); 60 Expect.equals(-0xFFFFFFFFFFFFF - 1, min_literal());
44 Expect.throws(i64list_throws, (e) => e is FiftyThreeBitOverflowError); 61
45 Expect.equals(190000000000000, double_to_int()); 62 // Run the tests once before optimizations.
46 Expect.equals(1 << 51, integer_add()); 63 dti_arg = 1.9e16;
64 Expect.throws(double_to_int, (e) => e is FiftyThreeBitOverflowError);
65
66 ia_arg1 = (1 << 51);
67 ia_arg2 = (1 << 51);
68 Expect.throws(integer_add, (e) => e is FiftyThreeBitOverflowError);
69
70 n_arg = -0xFFFFFFFFFFFFF - 1;
71 Expect.throws(negate, (e) => e is FiftyThreeBitOverflowError);
72
73 is_arg = (1 << 51);
74 Expect.throws(integer_shift, (e) => e is FiftyThreeBitOverflowError);
75
76 Expect.throws(max_add_throws, (e) => e is FiftyThreeBitOverflowError);
77 Expect.throws(min_sub_throws, (e) => e is FiftyThreeBitOverflowError);
78
79 for (int i = 0; i < 20; i++) {
80 dti_arg = i.toDouble();
81 // Expect.throws calls through the closure, so we have to here, too.
82 var f = double_to_int;
83 Expect.equals(i, f());
84
85 ia_arg1 = i;
86 ia_arg2 = i;
87 f = integer_add;
88 Expect.equals(i + i, f());
89
90 n_arg = i;
91 f = negate;
92 Expect.equals(-i, f());
93
94 is_arg = i;
95 f = integer_shift;
96 Expect.equals(i << 1, f());
97 }
98
99 // The optimized functions should now deoptimize and throw the error.
100 dti_arg = 1.9e16;
101 Expect.throws(double_to_int, (e) => e is FiftyThreeBitOverflowError);
102
103 ia_arg1 = (1 << 51);
104 ia_arg2 = (1 << 51);
105 Expect.throws(integer_add, (e) => e is FiftyThreeBitOverflowError);
106
107 n_arg = -0xFFFFFFFFFFFFF - 1;
108 Expect.throws(negate, (e) => e is FiftyThreeBitOverflowError);
109
110 is_arg = (1 << 51);
111 Expect.throws(integer_shift, (e) => e is FiftyThreeBitOverflowError);
112
113 Expect.throws(max_add_throws, (e) => e is FiftyThreeBitOverflowError);
114 Expect.throws(min_sub_throws, (e) => e is FiftyThreeBitOverflowError);
47 } 115 }
OLDNEW
« no previous file with comments | « tests/standalone/53bit_overflow_literal_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698