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

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, 11 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
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,58 @@
+// 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.
+
+class TestValue {
+ final int argument;
+ final int result;
+ final Function function;
+ TestValue(func, arg) : function = func, argument = arg, result = func(arg) {}
Florian Schneider 2013/02/04 13:04:03 How do you prevent func from already being optimiz
srdjan 2013/02/04 19:02:33 Added expected values as well.
+}
+
+
+divBy4(a) => a ~/ 4;
+divByNeg4(a) => a ~/ - 4;
Florian Schneider 2013/02/04 13:04:03 Remove extra space after - /s/- 4/-4/
srdjan 2013/02/04 19:02:33 Done.
+divBy134217728(a) => a ~/ 134217728;
+divByNeg134217728(a) => a ~/ -134217728;
+
Florian Schneider 2013/02/04 13:04:03 Please add tests for the special cases: a ~/ 0 a
srdjan 2013/02/04 19:02:33 Done.
+divBy4_(a) => a ~/ 4;
+divByNeg4_(a) => a ~/ - 4;
Florian Schneider 2013/02/04 13:04:03 /s/- 4/-4/
srdjan 2013/02/04 19:02:33 Done.
+divBy549755813888(a) => a ~/ 549755813888;
+divByNeg549755813888(a) => a ~/ -549755813888;
+
+
+test(dividends, testFunctions) {
+ var tests = new List();
+ for (Function f in testFunctions) {
+ for (int d in dividends) {
+ tests.add(new TestValue(f, d));
+ }
+ }
+ // Optimize.
+ for (int i = 0; i < 10000; i++) {
+ for (var f in testFunctions) {
+ f(10);
+ }
+ }
+
+ for (var t in tests) {
+ Expect.equals(t.result, t.function(t.argument));
+ }
+}
+
+
+main() {
+ // 32 bits.
+ var dividends = const [134217730, -134217730, 10, -10];
+ var testFunctions = const [divBy4, divByNeg4,
+ divBy134217728, divByNeg134217728];
+ test(dividends, testFunctions);
+ // 64 bits, use different functions, 64 bit arguments.
+ dividends = const [549755813990, -549755813990,
+ 288230925907525632, -288230925907525632];
+ testFunctions = const [divBy4_, divByNeg4_,
+ divBy549755813888, divByNeg549755813888];
+ test(dividends, testFunctions);
+}
« runtime/vm/intermediate_language_x64.cc ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698