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

Unified Diff: tests/language/div_with_power_of_two_test.dart

Issue 12091100: Use SAR for positive divident by a power-of two constant divisor. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/div_with_power_of_two_test.dart
===================================================================
--- tests/language/div_with_power_of_two_test.dart (revision 0)
+++ tests/language/div_with_power_of_two_test.dart (revision 0)
@@ -0,0 +1,103 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+// Test division by power of two.
+// Test that results before and after optimization are the same.
+
+// [function, [list of tuples argument/result]].
+var expectedResults =
+ [ [divBy1,
+ [[134217730, 134217730],
+ [-134217730, -134217730],
+ [10, 10],
+ [-10, -10]]],
+ [divByNeg1,
+ [[134217730, -134217730],
+ [-134217730, 134217730],
+ [10, -10],
+ [-10, 10]]],
+ [divBy2,
+ [[134217730, 67108865],
+ [-134217730, -67108865],
+ [10, 5],
+ [-10, -5]]],
+ [divByNeg2,
+ [[134217730, -67108865],
+ [-134217730, 67108865],
+ [10, -5],
+ [-10, 5]]],
+ [divBy4,
+ [[134217730, 33554432],
+ [-134217730, -33554432],
+ [10, 2],
+ [-10, -2]]],
+ [divByNeg4,
+ [[134217730, -33554432],
+ [-134217730, 33554432],
+ [10, -2],
+ [-10, 2]]],
+ [divBy134217728,
+ [[134217730, 1],
+ [-134217730, -1],
+ [10, 0],
+ [-10, 0]]],
+ [divByNeg134217728,
+ [[134217730, -1],
+ [-134217730, 1],
+ [10, 0],
+ [-10, 0]]],
+ // Use different functions for 64 bit arguments.
+ [divBy4_,
+ [[549755813990, 137438953497],
+ [-549755813990, -137438953497],
+ [288230925907525632, 72057731476881408],
+ [-288230925907525632, -72057731476881408]]],
+ [divByNeg4_,
+ [[549755813990, -137438953497],
+ [-549755813990, 137438953497],
+ [288230925907525632, -72057731476881408],
+ [-288230925907525632, 72057731476881408]]],
+ [divBy549755813888,
+ [[549755813990, 1],
+ [-549755813990, -1],
+ [288230925907525632, 524289],
+ [-288230925907525632, -524289]]],
+ [divByNeg549755813888,
+ [[549755813990, -1],
+ [-549755813990, 1],
+ [288230925907525632, -524289],
+ [-288230925907525632, 524289]]],
+ ];
+
+divBy0(a) => a ~/ 0;
+divBy1(a) => a ~/ 1;
+divByNeg1(a) => a ~/ -1;
+divBy2(a) => a ~/ 2;
+divByNeg2(a) => a ~/ -2;
+divBy4(a) => a ~/ 4;
+divByNeg4(a) => a ~/ -4;
+divBy134217728(a) => a ~/ 134217728;
+divByNeg134217728(a) => a ~/ -134217728;
+
+divBy4_(a) => a ~/ 4;
+divByNeg4_(a) => a ~/ -4;
+divBy549755813888(a) => a ~/ 549755813888;
+divByNeg549755813888(a) => a ~/ -549755813888;
+
+main() {
+ for (int i = 0; i < 8000; i++) {
+ for (var e in expectedResults) {
+ Function f = e[0];
+ List values = e[1];
+ for (var v in values) {
+ int arg = v[0];
+ int res = v[1];
+ Expect.equals(res, f(arg));
+ }
+ }
+ try {
+ divBy0(4);
+ Expect.fail("Should have thrown exception.");
+ } on IntegerDivisionByZeroException catch (e) {}
+ }
+}
« no previous file with comments | « runtime/vm/intermediate_language_x64.cc ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698