summary refs log tree commit diff
path: root/test/tls.ssa
blob: a17dda97a9dcc74e49555623f4f682c7edd38adf (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
thread data $i = align 4 {w 42}
data $fmti = align 1 {b "i%d==%d\n", b 0}

thread data $x = {w 1, w 2, w 3, w 4}
data $fmtx = align 1 {b "*(x+%d)==%d\n", b 0}

export
function w $main() {
@start
	%pthr =l alloc8 8
	%rval =l alloc8 8
	call $pthread_create(l %pthr, l 0, l $thread, l 0)
	%t =l load %pthr
	call $pthread_join(l %t, l %rval)
	%i0 =w loadw thread $i
	call $printf(l $fmti, ..., w 0, w %i0)
	%i1 =w load %rval
	call $printf(l $fmti, ..., w 1, w %i1)

	%a0 =l call $xaddr()
	%x0 =w load %a0
	call $printf(l $fmtx, ..., w 0, w %x0)
	%a4 =l call $xaddroff4()
	%x4 =w load %a4
	call $printf(l $fmtx, ..., w 4, w %x4)
	%a8 =l call $xaddroff(l 8)
	%x8 =w load %a8
	call $printf(l $fmtx, ..., w 8, w %x8)
	%xc =l call $xvalcnt(l 3)
	call $printf(l $fmtx, ..., w 12, w %xc)
	ret 0
}

function l $thread(l %arg) {
@start
	%i3 =l add thread $i, 3
	storeb 24, %i3
	%ret =l loadsw thread $i
	ret %ret
}

function l $xaddr() {
@start
	ret thread $x
}

function l $xaddroff4() {
@start
	%a =l add 4, thread $x
	ret %a
}

function l $xaddroff(l %off) {
@start
	%a =l add thread $x, %off
	ret %a
}

function w $xvalcnt(l %cnt) {
@start
	%o =l mul 4, %cnt
	%a =l add thread $x, %o
	%x =w load %a
	ret %x
}

# >>> output
# i0==42
# i1==402653226
# *(x+0)==1
# *(x+4)==2
# *(x+8)==3
# *(x+12)==4
# <<<