qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

prime.ssa (552B)


      1 # find the 10,001st prime
      2 # store it in a
      3 
      4 export
      5 function $test() {
      6 @start
      7 @loop
      8 	%n =w phi @start 5, @tloop %n, @yes %n1
      9 	%p =w phi @start 13, @tloop %p1, @yes %p1
     10 	%p1 =w add %p, 2
     11 @tloop
     12 	%t =w phi @loop 3, @next %t1
     13 	%r =w rem %p, %t
     14 	jnz %r, @next, @loop
     15 @next
     16 	%t1 =w add 2, %t
     17 	%tsq =w mul %t1, %t1
     18 	%c0 =w csgtw %tsq, %p
     19 	jnz %c0, @yes, @tloop
     20 @yes
     21 	%n1 =w add 1, %n
     22 	%c1 =w ceqw 10001, %n1
     23 	jnz %c1, @end, @loop
     24 @end
     25 	storew %p, $a
     26 	ret
     27 }
     28 
     29 # >>> driver
     30 # extern void test(void);
     31 # int a;
     32 # int main() { test(); return !(a == 104743); }
     33 # <<<