dart-sdk/tests/language/vm/bitnot_int_test.dart
Robert Nystrom 2034061433 Migrate language_2/vm to NNBD.
Change-Id: I313a57ed7c7ea2ada75065f55a7367376f6bdae5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152183
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2020-06-25 20:39:23 +00:00

45 lines
1.1 KiB
Dart

// Copyright (c) 2019, 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.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
import "package:expect/expect.dart";
// Tests for long bit-not under 64-bit arithmetic wrap-around semantics.
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
final int maxInt64 = 0x7fffffffffffffff;
final int minInt64 = 0x8000000000000000;
int bitnot(int x) {
return ~x;
}
doConstant() {
Expect.equals(0, bitnot(-1));
Expect.equals(-1, bitnot(0));
Expect.equals(-2, bitnot(1));
Expect.equals(minInt32, bitnot(maxInt32));
Expect.equals(maxInt32, bitnot(minInt32));
Expect.equals(minInt64, bitnot(maxInt64));
Expect.equals(maxInt64, bitnot(minInt64)); // sic!
}
doVar() {
int d = 0;
for (int i = -88; i < 10; i++) {
d += bitnot(i);
}
Expect.equals(3773, d);
}
main() {
// Repeat tests to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
doConstant();
doVar();
}
}