Skip to content

Commit 391dde2

Browse files
committed
cmd/internal/obj/arm64: factor out constant classification code
This will allow for further improvements and deduplication. Change-Id: I9374fc2d16168ced06f3fcc9e558a9c85e24fd01 Reviewed-on: https://go-review.googlesource.com/c/go/+/650936 Reviewed-by: Fannie Zhang <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 535e0da commit 391dde2

File tree

1 file changed

+56
-51
lines changed

1 file changed

+56
-51
lines changed

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,61 @@ func rclass(r int16) int {
19021902
return C_GOK
19031903
}
19041904

1905+
// conclass classifies a constant.
1906+
func conclass(v int64) int {
1907+
if v == 0 {
1908+
return C_ZCON
1909+
}
1910+
if isaddcon(v) {
1911+
if v <= 0xFFF {
1912+
if isbitcon(uint64(v)) {
1913+
return C_ABCON0
1914+
}
1915+
return C_ADDCON0
1916+
}
1917+
if isbitcon(uint64(v)) {
1918+
return C_ABCON
1919+
}
1920+
if movcon(v) >= 0 {
1921+
return C_AMCON
1922+
}
1923+
if movcon(^v) >= 0 {
1924+
return C_AMCON
1925+
}
1926+
return C_ADDCON
1927+
}
1928+
1929+
t := movcon(v)
1930+
if t >= 0 {
1931+
if isbitcon(uint64(v)) {
1932+
return C_MBCON
1933+
}
1934+
return C_MOVCON
1935+
}
1936+
1937+
t = movcon(^v)
1938+
if t >= 0 {
1939+
if isbitcon(uint64(v)) {
1940+
return C_MBCON
1941+
}
1942+
return C_MOVCON
1943+
}
1944+
1945+
if isbitcon(uint64(v)) {
1946+
return C_BITCON
1947+
}
1948+
1949+
if isaddcon2(v) {
1950+
return C_ADDCON2
1951+
}
1952+
1953+
if uint64(v) == uint64(uint32(v)) || v == int64(int32(v)) {
1954+
return C_LCON
1955+
}
1956+
1957+
return C_VCON
1958+
}
1959+
19051960
// con32class reclassifies the constant of 32-bit instruction. Because the constant type is 32-bit,
19061961
// but saved in Offset which type is int64, con32class treats it as uint32 type and reclassifies it.
19071962
func (c *ctxt7) con32class(a *obj.Addr) int {
@@ -2164,57 +2219,7 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
21642219
if a.Reg != 0 && a.Reg != REGZERO {
21652220
break
21662221
}
2167-
v := c.instoffset
2168-
if v == 0 {
2169-
return C_ZCON
2170-
}
2171-
if isaddcon(v) {
2172-
if v <= 0xFFF {
2173-
if isbitcon(uint64(v)) {
2174-
return C_ABCON0
2175-
}
2176-
return C_ADDCON0
2177-
}
2178-
if isbitcon(uint64(v)) {
2179-
return C_ABCON
2180-
}
2181-
if movcon(v) >= 0 {
2182-
return C_AMCON
2183-
}
2184-
if movcon(^v) >= 0 {
2185-
return C_AMCON
2186-
}
2187-
return C_ADDCON
2188-
}
2189-
2190-
t := movcon(v)
2191-
if t >= 0 {
2192-
if isbitcon(uint64(v)) {
2193-
return C_MBCON
2194-
}
2195-
return C_MOVCON
2196-
}
2197-
2198-
t = movcon(^v)
2199-
if t >= 0 {
2200-
if isbitcon(uint64(v)) {
2201-
return C_MBCON
2202-
}
2203-
return C_MOVCON
2204-
}
2205-
2206-
if isbitcon(uint64(v)) {
2207-
return C_BITCON
2208-
}
2209-
2210-
if isaddcon2(v) {
2211-
return C_ADDCON2
2212-
}
2213-
2214-
if uint64(v) == uint64(uint32(v)) || v == int64(int32(v)) {
2215-
return C_LCON
2216-
}
2217-
return C_VCON
2222+
return conclass(c.instoffset)
22182223

22192224
case obj.NAME_EXTERN, obj.NAME_STATIC:
22202225
if a.Sym == nil {

0 commit comments

Comments
 (0)