tls.ssa 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. thread data $i = align 4 {w 42}
  2. data $fmti = align 1 {b "i%d==%d\n", b 0}
  3. thread data $x = {w 1, w 2, w 3, w 4}
  4. data $fmtx = align 1 {b "*(x+%d)==%d\n", b 0}
  5. export
  6. function w $main() {
  7. @start
  8. %pthr =l alloc8 8
  9. %rval =l alloc8 8
  10. call $pthread_create(l %pthr, l 0, l $thread, l 0)
  11. %t =l load %pthr
  12. call $pthread_join(l %t, l %rval)
  13. %i0 =w loadw thread $i
  14. call $printf(l $fmti, ..., w 0, w %i0)
  15. %i1 =w load %rval
  16. call $printf(l $fmti, ..., w 1, w %i1)
  17. %a0 =l call $xaddr()
  18. %x0 =w load %a0
  19. call $printf(l $fmtx, ..., w 0, w %x0)
  20. %a4 =l call $xaddroff4()
  21. %x4 =w load %a4
  22. call $printf(l $fmtx, ..., w 4, w %x4)
  23. %a8 =l call $xaddroff(l 8)
  24. %x8 =w load %a8
  25. call $printf(l $fmtx, ..., w 8, w %x8)
  26. %xc =l call $xvalcnt(l 3)
  27. call $printf(l $fmtx, ..., w 12, w %xc)
  28. ret 0
  29. }
  30. function l $thread(l %arg) {
  31. @start
  32. %i3 =l add thread $i, 3
  33. storeb 24, %i3
  34. %ret =l loadsw thread $i
  35. ret %ret
  36. }
  37. function l $xaddr() {
  38. @start
  39. ret thread $x
  40. }
  41. function l $xaddroff4() {
  42. @start
  43. %a =l add 4, thread $x
  44. ret %a
  45. }
  46. function l $xaddroff(l %off) {
  47. @start
  48. %a =l add thread $x, %off
  49. ret %a
  50. }
  51. function w $xvalcnt(l %cnt) {
  52. @start
  53. %o =l mul 4, %cnt
  54. %a =l add thread $x, %o
  55. %x =w load %a
  56. ret %x
  57. }
  58. # >>> output
  59. # i0==42
  60. # i1==402653226
  61. # *(x+0)==1
  62. # *(x+4)==2
  63. # *(x+8)==3
  64. # *(x+12)==4
  65. # <<<