dart-sdk/tests/corelib/bigint_div_test.dart
Ryan Macnak d34e7b0500 [vm, compiler] RISC-V BigInt intrinsics.
Note that unlike x86 and ARM, RISC-V has no carry flag, so we must synthesize the carry in a GPR using sltu.

TEST=ci, RSA
Change-Id: I24898cb8b7166d5769ae98c535ec29b2206340d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235063
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-03-08 18:08:44 +00:00

84 lines
4.1 KiB
Dart

// Copyright (c) 2022, 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.
// Testing Bigints with and without intrinsics.
// VMOptions=--intrinsify --no-enable-asserts
// VMOptions=--intrinsify --enable-asserts
// VMOptions=--no-intrinsify --enable-asserts
// VMOptions=--no-intrinsify --no-enable-asserts
import "package:expect/expect.dart";
expectQuotient(aString, bString, expectedString) {
BigInt a = BigInt.parse(aString, radix: 16);
BigInt b = BigInt.parse(bString, radix: 16);
BigInt expected = BigInt.parse(expectedString, radix: 16);
BigInt actual = a ~/ b;
String actualString = actual.toRadixString(16);
print("$aString ~/ $bString");
print(" = $actualString (expected $expectedString)");
Expect.equals(expected, actual);
}
main() {
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"d4cba13fac3ee22b996ff6856c27c1f6d88aef0e", "1");
expectQuotient("d4cba13fac3ee22b996ff6856c27c1f6d88aef0e",
"d87becaa3701c97b31b5b8084f2b5b34e7857092", "0");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"a13fac3ee22b996ff6856c27c1f6d88aef0e", "157b1");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"3fac3ee22b996ff6856c27c1f6d88aef0e", "36662bd");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"ac3ee22b996ff6856c27c1f6d88aef0e", "141bfd63e");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"3ee22b996ff6856c27c1f6d88aef0e", "3714fb67de7");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092", "1",
"d87becaa3701c97b31b5b8084f2b5b34e7857092");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"d4cba13fac3ee22b996ff6856c27c1f6d88aef0e", "-1");
expectQuotient("-d4cba13fac3ee22b996ff6856c27c1f6d88aef0e",
"d87becaa3701c97b31b5b8084f2b5b34e7857092", "0");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"a13fac3ee22b996ff6856c27c1f6d88aef0e", "-157b1");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"3fac3ee22b996ff6856c27c1f6d88aef0e", "-36662bd");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"ac3ee22b996ff6856c27c1f6d88aef0e", "-141bfd63e");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"3ee22b996ff6856c27c1f6d88aef0e", "-3714fb67de7");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092", "1",
"-d87becaa3701c97b31b5b8084f2b5b34e7857092");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-d4cba13fac3ee22b996ff6856c27c1f6d88aef0e", "-1");
expectQuotient("d4cba13fac3ee22b996ff6856c27c1f6d88aef0e",
"-d87becaa3701c97b31b5b8084f2b5b34e7857092", "0");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-a13fac3ee22b996ff6856c27c1f6d88aef0e", "-157b1");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-3fac3ee22b996ff6856c27c1f6d88aef0e", "-36662bd");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-ac3ee22b996ff6856c27c1f6d88aef0e", "-141bfd63e");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-3ee22b996ff6856c27c1f6d88aef0e", "-3714fb67de7");
expectQuotient("d87becaa3701c97b31b5b8084f2b5b34e7857092", "-1",
"-d87becaa3701c97b31b5b8084f2b5b34e7857092");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-d4cba13fac3ee22b996ff6856c27c1f6d88aef0e", "1");
expectQuotient("-d4cba13fac3ee22b996ff6856c27c1f6d88aef0e",
"-d87becaa3701c97b31b5b8084f2b5b34e7857092", "0");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-a13fac3ee22b996ff6856c27c1f6d88aef0e", "157b1");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-3fac3ee22b996ff6856c27c1f6d88aef0e", "36662bd");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-ac3ee22b996ff6856c27c1f6d88aef0e", "141bfd63e");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092",
"-3ee22b996ff6856c27c1f6d88aef0e", "3714fb67de7");
expectQuotient("-d87becaa3701c97b31b5b8084f2b5b34e7857092", "-1",
"d87becaa3701c97b31b5b8084f2b5b34e7857092");
}