[llvm] [APInt] Restore multiplicativeInverse with explicit modulus and better testing (PR #87812)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 6 00:42:28 PDT 2024


================
@@ -3258,6 +3258,54 @@ TEST(APIntTest, MultiplicativeInverseExaustive) {
   }
 }
 
+TEST(APIntTest, ModularMultiplicativeInverseSpecific) {
+  // Test a single modulus for all known inverses and non-inverses.
+  int BitWidth = 8;
+  APInt Modulus(BitWidth, 26);
+  int Values[12] = {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
+  int Inverses[12] = {1, 9, 21, 15, 3, 19, 7, 23, 11, 5, 17, 25};
+  int NonInvertibleElements[14] = {0,  2,  4,  6,  8,  10, 12,
+                                   13, 14, 16, 18, 20, 22, 24};
+
+  for (size_t i = 0; i < 12; ++i) {
----------------
jayfoad wrote:

`i` should be capital, but can you use a range-based loop to avoid repeating the `12`? Maybe something like:
```suggestion
  for (auto [Val, Inv] : {{1, 1}, {3, 9}, ...}) {
```

https://github.com/llvm/llvm-project/pull/87812


More information about the llvm-commits mailing list