> On 7 May 2025, at 12:27, Karl Meakin <karl.mea...@arm.com> wrote:
> 
> 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_128MiB): New constant.
> (BRANCH_LEN_N_128MiB): likewise.
> (BRANCH_LEN_P_1MiB): likewise.
> (BRANCH_LEN_N_1MiB): likewise.
> (BRANCH_LEN_P_32KiB): likewise.
> (BRANCH_LEN_N_32KiB): likewise.
> (BRANCH_LEN_P_1KiB): likewise.
> (BRANCH_LEN_N_1KiB): likewise.

Ok.
Thanks,
Kyrill


> ---
> gcc/config/aarch64/aarch64.md | 68 ++++++++++++++++++++++++++---------
> 1 file changed, 52 insertions(+), 16 deletions(-)
> 
> diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
> index 23775ec58ca..ca5bd96a754 100644
> --- a/gcc/config/aarch64/aarch64.md
> +++ b/gcc/config/aarch64/aarch64.md
> @@ -696,7 +696,27 @@ (define_insn "jump"
>   [(set_attr "type" "branch")]
> )
> 
> +;; Maximum PC-relative positive/negative displacements for various branching
> +;; instructions.
> +(define_constants
> +  [
> +    ;; +/- 128MiB.  Used by B, BL.
> +    (BRANCH_LEN_P_128Mib  134217724)
> +    (BRANCH_LEN_N_128Mib -134217728)
> +
> +    ;; +/- 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)
> +
> +    ;; +/- 1KiB.  Used by CBB<cond>, CBH<cond>, CB<cond>.
> +    (BRANCH_LEN_P_1Kib  1020)
> +    (BRANCH_LEN_N_1Kib -1024)
> +  ]
> +)
> 
> ;; -------------------------------------------------------------------
> ;; Conditional jumps
> @@ -760,13 +780,17 @@ (define_insn "aarch64_bcond"
>   }
>   [(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)))]
> )
> @@ -823,13 +847,17 @@ (define_insn "aarch64_cb<optab><mode>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)))]
> )
> @@ -864,13 +892,17 @@ (define_insn "*cb<optab><mode>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)))]
> )
> @@ -925,13 +957,17 @@ (define_insn "@aarch64_tb<optab><ALLI:mode><GPI:mode>"
>   }
>   [(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)))]
> 
> -- 
> 2.45.2
> 

Reply via email to