-
Notifications
You must be signed in to change notification settings - Fork 8
/
ctrie-cas.lisp
153 lines (124 loc) · 4.75 KB
/
ctrie-cas.lisp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
;;;;; -*- mode: common-lisp; common-lisp-style: modern; coding: utf-8; -*-
;;;;;
(in-package "SB-VM")
;;
;; These cas extensions are credited entirely to the genius of Paul Khuong,
;; Nikodemus, et. al. They are incorporated here to facilitate experimentation
;; and further development
(handler-bind ((simple-error
(lambda (condition) (declare (ignore condition))
(invoke-restart 'continue))))
(sb-c:defknown cl-ctrie::spin-hint
()
(values))
(sb-c:defknown cl-ctrie::xadd-word-sap
(system-area-pointer word)
word)
(sb-c:defknown cl-ctrie::cas-word-sap
(system-area-pointer word word)
word)
(sb-c:defknown cl-ctrie::cas-byte-sap
(system-area-pointer (unsigned-byte 8) (unsigned-byte 8))
(unsigned-byte 8)))
(sb-c:define-vop (cl-ctrie::spin-hint)
(:translate cl-ctrie::spin-hint)
(:policy :fast-safe)
(:generator 5
(sb-assem:inst sb-vm::pause)))
(sb-c:define-vop (cl-ctrie::cas-byte-sap)
(:translate cl-ctrie::cas-byte-sap)
(:policy :fast-safe)
(:args (sap :scs (sb-vm::sap-reg) :to :eval)
(old :scs (sb-vm::unsigned-reg) :target rax)
(new :scs (sb-vm::unsigned-reg)))
(:temporary (:sc descriptor-reg :offset rax-offset
:from (:argument 1) :to :result :target result) rax)
(:results (result :scs (sb-vm::unsigned-reg)))
(:arg-types system-area-pointer sb-vm::unsigned-num sb-vm::unsigned-num)
(:result-types sb-vm::unsigned-num)
(:generator 5
(sb-vm::move rax old)
(sb-vm::inst sb-vm::cmpxchg (sb-vm::make-ea :byte :base sap)
(make-byte-tn new) :lock)
(sb-vm::inst sb-vm::movzx result al-tn)))
(sb-c:define-vop (cl-ctrie::cas-word-sap)
(:translate cl-ctrie::cas-word-sap)
(:policy :fast-safe)
(:args (sap :scs (sb-vm::sap-reg) :to :eval)
(old :scs (sb-vm::unsigned-reg) :target eax)
(new :scs (sb-vm::unsigned-reg)))
(:arg-types system-area-pointer sb-vm::unsigned-num sb-vm::unsigned-num)
(:temporary (:sc sb-vm::unsigned-reg :offset sb-vm::rax-offset
:from (:argument 1) :to :result :target r) eax)
(:results (r :scs (sb-vm::unsigned-reg)))
(:result-types sb-vm::unsigned-num)
(:generator 10
(sb-vm::move eax old)
(sb-vm::inst sb-vm::cmpxchg (sb-vm::make-ea :qword :base sap) new :lock)
(sb-vm::move r eax)))
(define-vop (cl-ctrie::xadd-word-sap)
(:translate cl-ctrie::xadd-word-sap)
(:policy :fast-safe)
(:args (sap :scs (sap-reg) :to :eval)
(inc :scs (unsigned-reg) :target result))
(:results (result :scs (unsigned-reg)))
(:arg-types system-area-pointer unsigned-num)
(:result-types unsigned-num)
(:generator 5
(inst xadd (make-ea :qword :base sap)
inc :lock)
(move result inc)))
(defun cl-ctrie::spin-hint ()
(cl-ctrie::spin-hint))
(defun cl-ctrie::cas-word-sap (sap old new)
(declare (type system-area-pointer sap)
(word old new))
(cl-ctrie::cas-word-sap sap old new))
(defun cl-ctrie::cas-byte-sap (sap old new)
(declare (type system-area-pointer sap)
(type (unsigned-byte 8) old new))
(cl-ctrie::cas-byte-sap sap old new))
(defun cl-ctrie::xadd-word-sap (sap word)
(declare (type system-area-pointer sap)
(type sb-vm:word word))
(cl-ctrie::xadd-word-sap sap word))
(defun cl-ctrie::get-vector-addr (vector)
(logandc2 (sb-kernel:get-lisp-obj-address vector) sb-vm:lowtag-mask))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TLS VOPs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; see cell.lisp:symbol-value
(eval-when (:compile-toplevel)
(define-vop (tls-ref)
(:args (index :scs (descriptor-reg)))
(:results (value :scs (descriptor-reg)))
#+x86-64
(:generator 5
(inst mov value (make-ea :qword
:base thread-base-tn
:index index :scale 1)))
#+x86
(:generator 5
(inst fs-segment-prefix)
(inst mov value (make-ea :dword :base index))))
(define-vop (tls-set)
(:args (value :scs (descriptor-reg))
(index :scs (descriptor-reg)))
(:results)
#+x86-64
(:generator 5
(inst mov (make-ea :qword
:base thread-base-tn
:index index :scale 1)
value))
#+x86
(:generator 5
(inst fs-segment-prefix)
(inst mov (make-ea :dword :base index) value)))
(define-vop (%set-symbol-global-value)
(:args (value :scs (descriptor-reg))
(symbol :scs (descriptor-reg)))
(:results)
#+(or x86-64 x86)
(:generator 5
(storew value symbol symbol-value-slot other-pointer-lowtag))))