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

Side by Side Diff: tests/standalone/unboxed_int_converter_test.dart

Issue 504143003: Support Int32 representation for selected binary operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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) 2014, 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 UnboxedIntConverter for int32.
5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr
6
7 import "package:expect/expect.dart";
8 import "dart:typed_data";
9
10 int32_add(a, b, c) => (a * c) + (b * c);
11 int32_mul(a, b, c) => (a * c) * b;
12 int32_sub(a, b, c) => (a * c) - (b * c);
13 int32_shr(a, b, c) => (a * c * b) >> 16;
14 int32_shl(a, b, c) => (a * c * b) << 16;
15 int32_xor(a, b, c) => (a * c) ^ (b * c);
16 int32_or(a, b, c) => (a * c) | (b * c);
17 int32_and(a, b, c) => (a * c) & (b * c);
18
19 int32_to_mint(a, b) {
20 var sum = 0;
21 var j = 0;
22 for (var i = a; i <= b; i++) {
23 sum -= (j * ++j) & 0xff;
24 }
25
26 return 0xffffffff + sum;
27 }
28
29 mint_to_int32(a, c, d) {
30 return a * a * a * (c - d);
31 }
32
33 uint32_to_int32(a, c) {
34 return (a * a * a) * (c & 0xFFFFFFFF);
35
36 }
37
38 main() {
39 for (var j = 0; j < 1000; j++) {
40 Expect.equals(2, int32_add(1, 1, 1));
41 Expect.equals(1, int32_mul(1, 1, 1));
42 Expect.equals(0, int32_sub(1, 1, 1));
43 Expect.equals(0, int32_shr(1, 1, 1));
44 Expect.equals(1 << 16, int32_shl(1, 1, 1));
45 Expect.equals(0, int32_xor(1, 1, 1));
46 Expect.equals(1, int32_or(1, 1, 1));
47 Expect.equals(1, int32_and(1, 1, 1));
48 }
49
50 Expect.equals(0x7ffffffe, int32_add(0x7ffffffc ~/ 2, 1, 2));
51 Expect.equals(-0x80000000, int32_add(-0x7ffffffe ~/ 2, -1, 2));
52 Expect.equals(-0x80000002, int32_add(-0x7ffffffe ~/ 2, -2, 2)); // Overflow.
53 Expect.equals(0x7ffffffe, int32_sub(0x7ffffffc ~/ 2, -1, 2));
54 Expect.equals(-0x80000000, int32_sub(-0x7ffffffe ~/ 2, 1, 2));
55 Expect.equals(-0x80000002, int32_sub(-0x7ffffffe ~/ 2, 2, 2)); // Overflow.
56 Expect.equals(-0x7ffffffe, int32_mul(0x7ffffffe ~/ 2, -1, 2));
57 Expect.equals(-0x80000000, int32_mul(-0x80000000 ~/ 2, 1, 2));
58 Expect.equals(0x80000000, int32_mul(-0x80000000 ~/ 2, -1, 2)); // Overflow.
59 Expect.equals(0x60000000, int32_xor(0x40000000 ~/ 2, 0x20000000 ~/ 2, 2));
60 Expect.equals(0x00000000, int32_xor(0x40000000 ~/ 2, 0x40000000 ~/ 2, 2));
61 Expect.equals(0x60000000, int32_or(0x40000000 ~/ 2, 0x20000000 ~/ 2, 2));
62 Expect.equals(0x60000000, int32_or(0x60000000 ~/ 2, 0x40000000 ~/ 2, 2));
63 Expect.equals(0x00000000, int32_and(0x40000000 ~/ 2, 0x20000000 ~/ 2, 2));
64 Expect.equals(0x40000000, int32_and(0x60000000 ~/ 2, 0x40000000 ~/ 2, 2));
65 Expect.equals(1, int32_shr(1, 1 << 16, 1));
66 Expect.equals(-1 << 15, int32_shr(1 << 15, -(1 << 16), 1));
67 Expect.equals(-0x080000000, int32_shl(-1 << 15, 1, 1));
68 Expect.equals(-0x100000000, int32_shl(-1 << 16, 1, 1)); // Overflow.
69
70 Expect.equals(0, int32_shr(1, 1, 1));
71 Expect.equals(1 << 16, int32_shl(1, 1, 1));
72
73 for (var j = 0; j < 1000; j++) {
74 Expect.equals(4294839503, int32_to_mint(0, 1000));
75 Expect.equals(-8, mint_to_int32(2, 0x100000000, 0x100000001));
76 Expect.equals(8, uint32_to_int32(2, 0x100000001));
77 }
78 Expect.equals(8 * 0x80000001, uint32_to_int32(2, 0x180000001));
79 }
OLDNEW
« runtime/vm/intermediate_language.h ('K') | « tests/standalone/standalone.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698