-
Notifications
You must be signed in to change notification settings - Fork 22
/
pgen_gcwb_amd64.go
75 lines (66 loc) · 2.07 KB
/
pgen_gcwb_amd64.go
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
/*
* Copyright 2022 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pgen
import (
`github.com/chenzhuoyu/iasm/x86_64`
`github.com/cloudwego/frugal/internal/atm/hir`
`github.com/cloudwego/frugal/internal/atm/rtx`
)
func (self *CodeGen) wbStorePointer(p *x86_64.Program, s hir.PointerRegister, d *x86_64.MemoryOperand) {
wb := x86_64.CreateLabel("_wb_store")
rt := x86_64.CreateLabel("_wb_return")
/* check for write barrier */
p.MOVQ (rtx.V_pWriteBarrier, RAX)
p.CMPB (0, Ptr(RAX, 0))
p.JNE (wb)
/* check for storing nil */
if s == hir.Pn {
p.MOVQ(0, d)
} else {
p.MOVQ(self.r(s), d)
}
/* set source pointer */
wbSetSrc := func() {
if s == hir.Pn {
p.XORL(EAX, EAX)
} else {
p.MOVQ(self.r(s), RAX)
}
}
/* set target slot pointer */
wbSetSlot := func() {
if !isSimpleMem(d) {
p.LEAQ(d.Retain(), RDI)
} else {
p.MOVQ(d.Addr.Memory.Base, RDI)
}
}
/* write barrier wrapper */
wbStoreFn := func(p *x86_64.Program) {
wbSetSrc ()
wbSetSlot ()
self.abiSpillReserved (p)
self.abiLoadReserved (p)
p.MOVQ (int64(rtx.F_gcWriteBarrier), RSI)
p.CALLQ (RSI)
self.abiSaveReserved (p)
self.abiRestoreReserved (p)
p.JMP (rt)
}
/* defer the call to the end of generated code */
p.Link(rt)
self.later(wb, wbStoreFn)
}