aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj
diff options
context:
space:
mode:
authorJoel Sing <joel@sing.id.au>2025-02-20 22:53:51 +1100
committerJoel Sing <joel@sing.id.au>2025-03-29 06:30:04 -0700
commit391dde29a37f3fd450f7d61e3f220930e0164b89 (patch)
tree7db6af800862a503bbb0a879b331ca121b43c25d /src/cmd/internal/obj
parent535e0daefd5ae1364df148c69fc893a068267605 (diff)
downloadgo-391dde29a37f3fd450f7d61e3f220930e0164b89.tar.xz
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 <Fannie.Zhang@arm.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/cmd/internal/obj')
-rw-r--r--src/cmd/internal/obj/arm64/asm7.go107
1 files changed, 56 insertions, 51 deletions
diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go
index 2e03d65b0d..0fc7815e41 100644
--- a/src/cmd/internal/obj/arm64/asm7.go
+++ b/src/cmd/internal/obj/arm64/asm7.go
@@ -1902,6 +1902,61 @@ func rclass(r int16) int {
return C_GOK
}
+// conclass classifies a constant.
+func conclass(v int64) int {
+ if v == 0 {
+ return C_ZCON
+ }
+ if isaddcon(v) {
+ if v <= 0xFFF {
+ if isbitcon(uint64(v)) {
+ return C_ABCON0
+ }
+ return C_ADDCON0
+ }
+ if isbitcon(uint64(v)) {
+ return C_ABCON
+ }
+ if movcon(v) >= 0 {
+ return C_AMCON
+ }
+ if movcon(^v) >= 0 {
+ return C_AMCON
+ }
+ return C_ADDCON
+ }
+
+ t := movcon(v)
+ if t >= 0 {
+ if isbitcon(uint64(v)) {
+ return C_MBCON
+ }
+ return C_MOVCON
+ }
+
+ t = movcon(^v)
+ if t >= 0 {
+ if isbitcon(uint64(v)) {
+ return C_MBCON
+ }
+ return C_MOVCON
+ }
+
+ if isbitcon(uint64(v)) {
+ return C_BITCON
+ }
+
+ if isaddcon2(v) {
+ return C_ADDCON2
+ }
+
+ if uint64(v) == uint64(uint32(v)) || v == int64(int32(v)) {
+ return C_LCON
+ }
+
+ return C_VCON
+}
+
// con32class reclassifies the constant of 32-bit instruction. Because the constant type is 32-bit,
// but saved in Offset which type is int64, con32class treats it as uint32 type and reclassifies it.
func (c *ctxt7) con32class(a *obj.Addr) int {
@@ -2164,57 +2219,7 @@ func (c *ctxt7) aclass(a *obj.Addr) int {
if a.Reg != 0 && a.Reg != REGZERO {
break
}
- v := c.instoffset
- if v == 0 {
- return C_ZCON
- }
- if isaddcon(v) {
- if v <= 0xFFF {
- if isbitcon(uint64(v)) {
- return C_ABCON0
- }
- return C_ADDCON0
- }
- if isbitcon(uint64(v)) {
- return C_ABCON
- }
- if movcon(v) >= 0 {
- return C_AMCON
- }
- if movcon(^v) >= 0 {
- return C_AMCON
- }
- return C_ADDCON
- }
-
- t := movcon(v)
- if t >= 0 {
- if isbitcon(uint64(v)) {
- return C_MBCON
- }
- return C_MOVCON
- }
-
- t = movcon(^v)
- if t >= 0 {
- if isbitcon(uint64(v)) {
- return C_MBCON
- }
- return C_MOVCON
- }
-
- if isbitcon(uint64(v)) {
- return C_BITCON
- }
-
- if isaddcon2(v) {
- return C_ADDCON2
- }
-
- if uint64(v) == uint64(uint32(v)) || v == int64(int32(v)) {
- return C_LCON
- }
- return C_VCON
+ return conclass(c.instoffset)
case obj.NAME_EXTERN, obj.NAME_STATIC:
if a.Sym == nil {