]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AArch64: add constants for branch displacements
authorKarl Meakin <karl.meakin@arm.com>
Thu, 3 Jul 2025 11:48:29 +0000 (12:48 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 3 Jul 2025 11:48:29 +0000 (12:48 +0100)
Extract the hardcoded values for the minimum PC-relative displacements
into named constants and document them.

gcc/ChangeLog:

* config/aarch64/aarch64.md (BRANCH_LEN_P_1MiB): New constant.
(BRANCH_LEN_N_1MiB): Likewise.
(BRANCH_LEN_P_32KiB): Likewise.
(BRANCH_LEN_N_32KiB): Likewise.

gcc/config/aarch64/aarch64.md

index 8ce991e2f351d04a43f863d0e6fa4266c471d948..3f37ea6cff7ce0e67483ec21726a9baed5f0d7b0 100644 (file)
   [(set_attr "type" "branch")]
 )
 
+;; Maximum PC-relative positive/negative displacements for various branching
+;; instructions.
+(define_constants
+  [
+    ;; +/- 1MiB.  Used by B.<cond>, CBZ, CBNZ.
+    (BRANCH_LEN_P_1MiB  1048572)
+    (BRANCH_LEN_N_1MiB -1048576)
 
+    ;; +/- 32KiB.  Used by TBZ, TBNZ.
+    (BRANCH_LEN_P_32KiB  32764)
+    (BRANCH_LEN_N_32KiB -32768)
+  ]
+)
 
 ;; -------------------------------------------------------------------
 ;; Conditional jumps
   }
   [(set_attr "type" "branch")
    (set (attr "length")
-       (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 2) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 4)
                      (const_int 8)))
    (set (attr "far_branch")
-       (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 2) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 0)
                      (const_int 1)))]
 )
   }
   [(set_attr "type" "branch")
    (set (attr "length")
-       (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 1) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 4)
                      (const_int 8)))
    (set (attr "far_branch")
-       (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 2) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 0)
                      (const_int 1)))]
 )
   }
   [(set_attr "type" "branch")
    (set (attr "length")
-       (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -32768))
-                          (lt (minus (match_dup 1) (pc)) (const_int 32764)))
+       (if_then_else (and (ge (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_N_32KiB))
+                          (lt (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_P_32KiB)))
                      (const_int 4)
                      (const_int 8)))
    (set (attr "far_branch")
-       (if_then_else (and (ge (minus (match_dup 1) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 1) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 1) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 0)
                      (const_int 1)))]
 )
   }
   [(set_attr "type" "branch")
    (set (attr "length")
-       (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -32768))
-                          (lt (minus (match_dup 2) (pc)) (const_int 32764)))
+       (if_then_else (and (ge (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_N_32KiB))
+                          (lt (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_P_32KiB)))
                      (const_int 4)
                      (const_int 8)))
    (set (attr "far_branch")
-       (if_then_else (and (ge (minus (match_dup 2) (pc)) (const_int -1048576))
-                          (lt (minus (match_dup 2) (pc)) (const_int 1048572)))
+       (if_then_else (and (ge (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_N_1MiB))
+                          (lt (minus (match_dup 2) (pc))
+                              (const_int BRANCH_LEN_P_1MiB)))
                      (const_int 0)
                      (const_int 1)))]