]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/arm64: factor out constant classification code
authorJoel Sing <joel@sing.id.au>
Thu, 20 Feb 2025 11:53:51 +0000 (22:53 +1100)
committerJoel Sing <joel@sing.id.au>
Sat, 29 Mar 2025 13:30:04 +0000 (06:30 -0700)
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>
src/cmd/internal/obj/arm64/asm7.go

index 2e03d65b0da190ab39096a7ca8edd260d151beb6..0fc7815e4195b457f899a34593bea6920d8836fe 100644 (file)
@@ -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 {