summary refs log tree commit diff
path: root/test/prime.ssa
blob: 12d0273d0209441ba78cb499a8d6c6896ac51b8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# find the 10,001st prime
# store it in a

function $test() {
@start
@loop
	%n =w phi @start 5, @tloop %n, @yes %n1
	%p =w phi @start 13, @tloop %p1, @yes %p1
	%p1 =w add %p, 2
@tloop
	%t =w phi @loop 3, @next %t1
	%r =w rem %p, %t
	jnz %r, @next, @loop
@next
	%t1 =w add 2, %t
	%tsq =w mul %t1, %t1
	%c0 =w csgtw %tsq, %p
	jnz %c0, @yes, @tloop
@yes
	%n1 =w add 1, %n
	%c1 =w ceqw 10001, %n1
	jnz %c1, @end, @loop
@end
	storew %p, $a
	ret
}

# >>> driver
# extern void test(void);
# int a;
# int main() { test(); return !(a == 104743); }
# <<<