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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Test division by power of two.
5 // Test that results before and after optimization are the same.
6
7 class TestValue {
8 final int argument;
9 final int result;
10 final Function function;
11 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.
12 }
13
14
15 divBy4(a) => a ~/ 4;
16 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.
17 divBy134217728(a) => a ~/ 134217728;
18 divByNeg134217728(a) => a ~/ -134217728;
19
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.
20 divBy4_(a) => a ~/ 4;
21 divByNeg4_(a) => a ~/ - 4;
Florian Schneider 2013/02/04 13:04:03 /s/- 4/-4/
srdjan 2013/02/04 19:02:33 Done.
22 divBy549755813888(a) => a ~/ 549755813888;
23 divByNeg549755813888(a) => a ~/ -549755813888;
24
25
26 test(dividends, testFunctions) {
27 var tests = new List();
28 for (Function f in testFunctions) {
29 for (int d in dividends) {
30 tests.add(new TestValue(f, d));
31 }
32 }
33 // Optimize.
34 for (int i = 0; i < 10000; i++) {
35 for (var f in testFunctions) {
36 f(10);
37 }
38 }
39
40 for (var t in tests) {
41 Expect.equals(t.result, t.function(t.argument));
42 }
43 }
44
45
46 main() {
47 // 32 bits.
48 var dividends = const [134217730, -134217730, 10, -10];
49 var testFunctions = const [divBy4, divByNeg4,
50 divBy134217728, divByNeg134217728];
51 test(dividends, testFunctions);
52 // 64 bits, use different functions, 64 bit arguments.
53 dividends = const [549755813990, -549755813990,
54 288230925907525632, -288230925907525632];
55 testFunctions = const [divBy4_, divByNeg4_,
56 divBy549755813888, divByNeg549755813888];
57 test(dividends, testFunctions);
58 }
OLDNEW
« 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