Skip to content

Commit 14f9195

Browse files
committed
cmd/compile/internal/mips64: copy cmd/compile/internal/ppc64
Just a mechanical copy, no code changes. This is to reduce code difference when adding the mips64 port. Change-Id: Id06e975f414a7b09f4827167b30813b228a3bfaf Reviewed-on: https://go-review.googlesource.com/14324 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 5cc86c6 commit 14f9195

File tree

8 files changed

+3383
-0
lines changed

8 files changed

+3383
-0
lines changed
+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package ppc64
6+
7+
import (
8+
"cmd/compile/internal/gc"
9+
"cmd/internal/obj"
10+
"cmd/internal/obj/ppc64"
11+
)
12+
13+
func blockcopy(n, res *gc.Node, osrc, odst, w int64) {
14+
// determine alignment.
15+
// want to avoid unaligned access, so have to use
16+
// smaller operations for less aligned types.
17+
// for example moving [4]byte must use 4 MOVB not 1 MOVW.
18+
align := int(n.Type.Align)
19+
20+
var op int
21+
switch align {
22+
default:
23+
gc.Fatalf("sgen: invalid alignment %d for %v", align, n.Type)
24+
25+
case 1:
26+
op = ppc64.AMOVBU
27+
28+
case 2:
29+
op = ppc64.AMOVHU
30+
31+
case 4:
32+
op = ppc64.AMOVWZU // there is no lwau, only lwaux
33+
34+
case 8:
35+
op = ppc64.AMOVDU
36+
}
37+
38+
if w%int64(align) != 0 {
39+
gc.Fatalf("sgen: unaligned size %d (align=%d) for %v", w, align, n.Type)
40+
}
41+
c := int32(w / int64(align))
42+
43+
// if we are copying forward on the stack and
44+
// the src and dst overlap, then reverse direction
45+
dir := align
46+
47+
if osrc < odst && int64(odst) < int64(osrc)+w {
48+
dir = -dir
49+
}
50+
51+
var dst gc.Node
52+
var src gc.Node
53+
if n.Ullman >= res.Ullman {
54+
gc.Agenr(n, &dst, res) // temporarily use dst
55+
gc.Regalloc(&src, gc.Types[gc.Tptr], nil)
56+
gins(ppc64.AMOVD, &dst, &src)
57+
if res.Op == gc.ONAME {
58+
gc.Gvardef(res)
59+
}
60+
gc.Agen(res, &dst)
61+
} else {
62+
if res.Op == gc.ONAME {
63+
gc.Gvardef(res)
64+
}
65+
gc.Agenr(res, &dst, res)
66+
gc.Agenr(n, &src, nil)
67+
}
68+
69+
var tmp gc.Node
70+
gc.Regalloc(&tmp, gc.Types[gc.Tptr], nil)
71+
72+
// set up end marker
73+
var nend gc.Node
74+
75+
// move src and dest to the end of block if necessary
76+
if dir < 0 {
77+
if c >= 4 {
78+
gc.Regalloc(&nend, gc.Types[gc.Tptr], nil)
79+
gins(ppc64.AMOVD, &src, &nend)
80+
}
81+
82+
p := gins(ppc64.AADD, nil, &src)
83+
p.From.Type = obj.TYPE_CONST
84+
p.From.Offset = w
85+
86+
p = gins(ppc64.AADD, nil, &dst)
87+
p.From.Type = obj.TYPE_CONST
88+
p.From.Offset = w
89+
} else {
90+
p := gins(ppc64.AADD, nil, &src)
91+
p.From.Type = obj.TYPE_CONST
92+
p.From.Offset = int64(-dir)
93+
94+
p = gins(ppc64.AADD, nil, &dst)
95+
p.From.Type = obj.TYPE_CONST
96+
p.From.Offset = int64(-dir)
97+
98+
if c >= 4 {
99+
gc.Regalloc(&nend, gc.Types[gc.Tptr], nil)
100+
p := gins(ppc64.AMOVD, &src, &nend)
101+
p.From.Type = obj.TYPE_ADDR
102+
p.From.Offset = w
103+
}
104+
}
105+
106+
// move
107+
// TODO: enable duffcopy for larger copies.
108+
if c >= 4 {
109+
p := gins(op, &src, &tmp)
110+
p.From.Type = obj.TYPE_MEM
111+
p.From.Offset = int64(dir)
112+
ploop := p
113+
114+
p = gins(op, &tmp, &dst)
115+
p.To.Type = obj.TYPE_MEM
116+
p.To.Offset = int64(dir)
117+
118+
p = gins(ppc64.ACMP, &src, &nend)
119+
120+
gc.Patch(gc.Gbranch(ppc64.ABNE, nil, 0), ploop)
121+
gc.Regfree(&nend)
122+
} else {
123+
// TODO(austin): Instead of generating ADD $-8,R8; ADD
124+
// $-8,R7; n*(MOVDU 8(R8),R9; MOVDU R9,8(R7);) just
125+
// generate the offsets directly and eliminate the
126+
// ADDs. That will produce shorter, more
127+
// pipeline-able code.
128+
var p *obj.Prog
129+
for {
130+
tmp14 := c
131+
c--
132+
if tmp14 <= 0 {
133+
break
134+
}
135+
136+
p = gins(op, &src, &tmp)
137+
p.From.Type = obj.TYPE_MEM
138+
p.From.Offset = int64(dir)
139+
140+
p = gins(op, &tmp, &dst)
141+
p.To.Type = obj.TYPE_MEM
142+
p.To.Offset = int64(dir)
143+
}
144+
}
145+
146+
gc.Regfree(&dst)
147+
gc.Regfree(&src)
148+
gc.Regfree(&tmp)
149+
}
+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package ppc64
6+
7+
import (
8+
"cmd/compile/internal/gc"
9+
"cmd/internal/obj"
10+
"cmd/internal/obj/ppc64"
11+
)
12+
13+
var thechar int = '9'
14+
15+
var thestring string = "ppc64"
16+
17+
var thelinkarch *obj.LinkArch
18+
19+
func linkarchinit() {
20+
thestring = obj.Getgoarch()
21+
gc.Thearch.Thestring = thestring
22+
if thestring == "ppc64le" {
23+
thelinkarch = &ppc64.Linkppc64le
24+
} else {
25+
thelinkarch = &ppc64.Linkppc64
26+
}
27+
gc.Thearch.Thelinkarch = thelinkarch
28+
}
29+
30+
var MAXWIDTH int64 = 1 << 50
31+
32+
/*
33+
* go declares several platform-specific type aliases:
34+
* int, uint, and uintptr
35+
*/
36+
var typedefs = []gc.Typedef{
37+
{"int", gc.TINT, gc.TINT64},
38+
{"uint", gc.TUINT, gc.TUINT64},
39+
{"uintptr", gc.TUINTPTR, gc.TUINT64},
40+
}
41+
42+
func betypeinit() {
43+
gc.Widthptr = 8
44+
gc.Widthint = 8
45+
gc.Widthreg = 8
46+
}
47+
48+
func Main() {
49+
gc.Thearch.Thechar = thechar
50+
gc.Thearch.Thestring = thestring
51+
gc.Thearch.Thelinkarch = thelinkarch
52+
gc.Thearch.Typedefs = typedefs
53+
gc.Thearch.REGSP = ppc64.REGSP
54+
gc.Thearch.REGCTXT = ppc64.REGCTXT
55+
gc.Thearch.REGCALLX = ppc64.REG_R3
56+
gc.Thearch.REGCALLX2 = ppc64.REG_R4
57+
gc.Thearch.REGRETURN = ppc64.REG_R3
58+
gc.Thearch.REGMIN = ppc64.REG_R0
59+
gc.Thearch.REGMAX = ppc64.REG_R31
60+
gc.Thearch.FREGMIN = ppc64.REG_F0
61+
gc.Thearch.FREGMAX = ppc64.REG_F31
62+
gc.Thearch.MAXWIDTH = MAXWIDTH
63+
gc.Thearch.ReservedRegs = resvd
64+
65+
gc.Thearch.Betypeinit = betypeinit
66+
gc.Thearch.Cgen_hmul = cgen_hmul
67+
gc.Thearch.Cgen_shift = cgen_shift
68+
gc.Thearch.Clearfat = clearfat
69+
gc.Thearch.Defframe = defframe
70+
gc.Thearch.Dodiv = dodiv
71+
gc.Thearch.Excise = excise
72+
gc.Thearch.Expandchecks = expandchecks
73+
gc.Thearch.Getg = getg
74+
gc.Thearch.Gins = gins
75+
gc.Thearch.Ginscmp = ginscmp
76+
gc.Thearch.Ginscon = ginscon
77+
gc.Thearch.Ginsnop = ginsnop
78+
gc.Thearch.Gmove = gmove
79+
gc.Thearch.Linkarchinit = linkarchinit
80+
gc.Thearch.Peep = peep
81+
gc.Thearch.Proginfo = proginfo
82+
gc.Thearch.Regtyp = regtyp
83+
gc.Thearch.Sameaddr = sameaddr
84+
gc.Thearch.Smallindir = smallindir
85+
gc.Thearch.Stackaddr = stackaddr
86+
gc.Thearch.Blockcopy = blockcopy
87+
gc.Thearch.Sudoaddable = sudoaddable
88+
gc.Thearch.Sudoclean = sudoclean
89+
gc.Thearch.Excludedregs = excludedregs
90+
gc.Thearch.RtoB = RtoB
91+
gc.Thearch.FtoB = RtoB
92+
gc.Thearch.BtoR = BtoR
93+
gc.Thearch.BtoF = BtoF
94+
gc.Thearch.Optoas = optoas
95+
gc.Thearch.Doregbits = doregbits
96+
gc.Thearch.Regnames = regnames
97+
98+
gc.Main()
99+
gc.Exit(0)
100+
}

0 commit comments

Comments
 (0)