Distinction from loop-invariant code Loop invariant



a loop invariant (loop-invariant property) distinguished loop-invariant code; note loop invariant (noun) versus loop-invariant (adjective). loop-invariant code consists of statements or expressions can moved outside body of loop without affecting semantics of program; such transformations, called loop-invariant code motion, performed compilers optimize programs. loop-invariant code example (in c programming language) is



where calculations x = y+z , x*x can moved before loop, resulting in equivalent, faster, program:



in contrast, e.g. property 0<=i && i<=n loop invariant both original , optimized program, not part of code, hence doesn t make sense speak of moving out of loop .


loop-invariant code may induce corresponding loop-invariant property. above example, easiest way see consider program loop invariant code computed both before , within loop:



a loop-invariant property of code (x1==x2 && t1==x2*x2) || i==0, indicating values computed before loop agree computed within (except before first iteration).







Comments

Popular posts from this blog

2016–2017 : Return to Super Rugby Southern Kings

Description Goubau line

Hornets Oklahoma City