commit eda2db573741eef29f4d1f1e759a83e7cd468a94
parent 1ec70daee6b5a93973067c937c70e3f9e08c0fbe
Author: Quentin Carbonneaux <quentin@c9x.me>
Date: Sun, 2 Apr 2023 16:58:48 +0200
tests for thread-local addresses
Diffstat:
M | test/tls.ssa | | | 50 | +++++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 47 insertions(+), 3 deletions(-)
diff --git a/test/tls.ssa b/test/tls.ssa
@@ -1,5 +1,8 @@
thread data $i = align 4 {w 42}
-data $fmt = align 1 {b "i%d==%d\n", b 0}
+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() {
@@ -10,9 +13,21 @@ function w $main() {
%t =l load %pthr
call $pthread_join(l %t, l %rval)
%i0 =w loadw thread $i
- call $printf(l $fmt, ..., w 0, w %i0)
+ call $printf(l $fmti, ..., w 0, w %i0)
%i1 =w load %rval
- call $printf(l $fmt, ..., w 1, w %i1)
+ 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
}
@@ -24,7 +39,36 @@ function l $thread(l %arg) {
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
# <<<