@@ -165,21 +165,6 @@ private predicate maxPhiInputRank(SsaPhiNode phi, int rix) {
165165 rix = max ( int r | rankedPhiInput ( phi , _, _, r ) )
166166}
167167
168- private int gcdLim ( ) { result = 128 }
169-
170- /**
171- * Gets the greatest common divisor of `x` and `y`. This is restricted to small
172- * inputs and the case when `x` and `y` are not relatively prime.
173- */
174- private int gcd ( int x , int y ) {
175- result != 1 and
176- result = x .abs ( ) and
177- y = 0 and
178- x in [ - gcdLim ( ) .. gcdLim ( ) ]
179- or
180- result = gcd ( y , x % y ) and y != 0 and x in [ - gcdLim ( ) .. gcdLim ( ) ]
181- }
182-
183168/**
184169 * Gets the remainder of `val` modulo `mod`.
185170 *
@@ -203,7 +188,7 @@ private predicate phiSelfModulus(
203188 edge .phiInput ( phi , inp ) and
204189 phibound .getSsa ( ) = phi and
205190 ssaModulus ( inp , edge , phibound , v , m ) and
206- mod = gcd ( m , v ) and
191+ mod = m . gcd ( v ) and
207192 mod != 1
208193 )
209194}
@@ -233,14 +218,14 @@ private predicate phiModulusRankStep(SsaPhiNode phi, Bound b, int val, int mod,
233218 rankedPhiInput ( phi , inp , edge , rix ) and
234219 phiModulusRankStep ( phi , b , v1 , m1 , rix - 1 ) and
235220 ssaModulus ( inp , edge , b , v2 , m2 ) and
236- mod = gcd ( gcd ( m1 , m2 ) , v1 - v2 )
221+ mod = m1 . gcd ( m2 ) . gcd ( v1 - v2 )
237222 )
238223 or
239224 exists ( int m2 |
240225 rankedPhiInput ( phi , inp , edge , rix ) and
241226 phiModulusRankStep ( phi , b , v1 , m1 , rix - 1 ) and
242227 phiSelfModulus ( phi , inp , edge , m2 ) and
243- mod = gcd ( m1 , m2 )
228+ mod = m1 . gcd ( m2 )
244229 )
245230 )
246231}
@@ -301,15 +286,15 @@ predicate exprModulus(Expr e, Bound b, int val, int mod) {
301286 cond = e and
302287 condExprBranchModulus ( cond , true , b , v1 , m1 ) and
303288 condExprBranchModulus ( cond , false , b , v2 , m2 ) and
304- mod = gcd ( gcd ( m1 , m2 ) , v1 - v2 ) and
289+ mod = m1 . gcd ( m2 ) . gcd ( v1 - v2 ) and
305290 mod != 1 and
306291 val = remainder ( v1 , mod )
307292 )
308293 or
309294 exists ( Bound b1 , Bound b2 , int v1 , int v2 , int m1 , int m2 |
310295 addModulus ( e , true , b1 , v1 , m1 ) and
311296 addModulus ( e , false , b2 , v2 , m2 ) and
312- mod = gcd ( m1 , m2 ) and
297+ mod = m1 . gcd ( m2 ) and
313298 mod != 1 and
314299 val = remainder ( v1 + v2 , mod )
315300 |
@@ -321,7 +306,7 @@ predicate exprModulus(Expr e, Bound b, int val, int mod) {
321306 exists ( int v1 , int v2 , int m1 , int m2 |
322307 subModulus ( e , true , b , v1 , m1 ) and
323308 subModulus ( e , false , any ( ZeroBound zb ) , v2 , m2 ) and
324- mod = gcd ( m1 , m2 ) and
309+ mod = m1 . gcd ( m2 ) and
325310 mod != 1 and
326311 val = remainder ( v1 - v2 , mod )
327312 )
0 commit comments