Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 } | |
| OLD | NEW |