[gcc(refs/vendors/ARM/heads/morello)] morello: add Morello builtins (newlib set)

Matthew Malcomson matmal01@gcc.gnu.org
Wed Apr 6 09:58:32 GMT 2022


https://gcc.gnu.org/g:7a04fa6339adda2c9af087739cf37d78a84c2c12

commit 7a04fa6339adda2c9af087739cf37d78a84c2c12
Author: Przemyslaw Wirkus <przemyslaw.wirkus@arm.com>
Date:   Mon Mar 14 09:38:22 2022 +0000

    morello: add Morello builtins (newlib set)
    
    This patch is implementing subset of Morello builtins.
    
    Add new intrinsics
            __builtin_cheri_address_set
            __builtin_cheri_base_get
            __builtin_cheri_bounds_set
            __builtin_cheri_bounds_set_exact
            __builtin_cheri_global_data_get
            __builtin_cheri_length_get
            __builtin_cheri_perms_and
            __builtin_cheri_representable_alignment_mask
            __builtin_cheri_round_representable_length
            __builtin_cheri_seal
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/morello/builtin_cheri_address_set.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_base_get.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_bounds_set.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_bounds_set_exact.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_global_data_get.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_length_get.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_perms_and.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_representable_alignment_mask.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_round_representable_length.c: New test.
            * gcc.target/aarch64/morello/builtin_cheri_seal.c: New test.
    
    gcc/ChangeLog:
    
            * config/aarch64/aarch64-builtins.c (enum aarch64_builtins): Add new
            enums.
            (aarch64_init_morello_builtins): New builtins added.
            (aarch64_expand_morello_builtin): Handle new builtins expands.
            (aarch64_general_expand_builtin): Handle new builtins enums.
            * config/aarch64/aarch64-morello.md: New patterns to support Morello
            builtins.
            * config/aarch64/aarch64.md: Add new UNSPEC_CHERI_x values.

Diff:
---
 gcc/config/aarch64/aarch64-builtins.c              | 195 ++++++++++++++++++++-
 gcc/config/aarch64/aarch64-morello.md              |  98 +++++++++++
 gcc/config/aarch64/aarch64.md                      |  10 ++
 .../aarch64/morello/builtin_cheri_address_set.c    |  11 ++
 .../aarch64/morello/builtin_cheri_base_get.c       |  11 ++
 .../aarch64/morello/builtin_cheri_bounds_set.c     |  11 ++
 .../morello/builtin_cheri_bounds_set_exact.c       |  11 ++
 .../morello/builtin_cheri_global_data_get.c        |   9 +
 .../aarch64/morello/builtin_cheri_length_get.c     |  11 ++
 .../aarch64/morello/builtin_cheri_perms_and.c      |  12 ++
 .../builtin_cheri_representable_alignment_mask.c   |  11 ++
 .../builtin_cheri_round_representable_length.c     |  11 ++
 .../aarch64/morello/builtin_cheri_seal.c           |   9 +
 13 files changed, 409 insertions(+), 1 deletion(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 61afc1d9630..996e368f994 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -477,6 +477,18 @@ enum aarch64_builtins
   AARCH64_BUILTIN_RSQRT_V2DF,
   AARCH64_BUILTIN_RSQRT_V2SF,
   AARCH64_BUILTIN_RSQRT_V4SF,
+
+  AARCH64_MORELLO_BUILTIN_ADDRESS_SET,
+  AARCH64_MORELLO_BUILTIN_BASE_GET,
+  AARCH64_MORELLO_BUILTIN_BOUNDS_SET,
+  AARCH64_MORELLO_BUILTIN_BOUNDS_SET_EXACT,
+  AARCH64_MORELLO_BUILTIN_GLOBAL_DATA_GET,
+  AARCH64_MORELLO_BUILTIN_LENGTH_GET,
+  AARCH64_MORELLO_BUILTIN_PERMS_AND,
+  AARCH64_MORELLO_BUILTIN_REPR_ALIGNMENT_MASK,
+  AARCH64_MORELLO_BUILTIN_ROUND_REPR_LEN,
+  AARCH64_MORELLO_BUILTIN_SEAL,
+
   AARCH64_SIMD_BUILTIN_BASE,
   AARCH64_SIMD_BUILTIN_LANE_CHECK,
 #include "aarch64-simd-builtins.def"
@@ -641,7 +653,7 @@ aarch64_general_add_builtin (const char *name, tree type, unsigned int code,
 {
   code = (code << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_GENERAL;
   return add_builtin_function (name, type, code, BUILT_IN_MD,
-			       NULL, attrs);
+                              NULL, attrs);
 }
 
 static const char *
@@ -1416,6 +1428,70 @@ aarch64_init_fpsr_fpcr_builtins (void)
 				   AARCH64_BUILTIN_SET_FPSR64);
 }
 
+/* Initialize Morello builtins.  */
+
+typedef struct
+{
+  const char *name;
+  unsigned int code;
+  tree type;
+} morello_builtins_data;
+
+#define morello_vaddr_t uint64_type_node
+static void
+aarch64_init_morello_builtins (void)
+{
+  tree const_void = build_qualified_type (void_type_node,
+                                          TYPE_QUAL_CONST);
+  tree cap_type_node = build_pointer_type_for_mode (void_type_node, CADImode,
+                                                    true);
+  tree const_cap_type_node = build_pointer_type_for_mode (const_void, CADImode,
+                                                    true);
+
+  morello_builtins_data data[10] = {
+    {"__builtin_cheri_address_set",
+     AARCH64_MORELLO_BUILTIN_ADDRESS_SET,
+     build_function_type_list (cap_type_node, cap_type_node, morello_vaddr_t,
+                               NULL_TREE)},
+    {"__builtin_cheri_base_get",
+     AARCH64_MORELLO_BUILTIN_BASE_GET,
+     build_function_type_list (morello_vaddr_t, cap_type_node, NULL_TREE)},
+    {"__builtin_cheri_bounds_set",
+     AARCH64_MORELLO_BUILTIN_BOUNDS_SET,
+     build_function_type_list (cap_type_node, cap_type_node, size_type_node,
+                               NULL_TREE)},
+    {"__builtin_cheri_bounds_set_exact",
+     AARCH64_MORELLO_BUILTIN_BOUNDS_SET_EXACT,
+     build_function_type_list (cap_type_node, cap_type_node, size_type_node,
+                               NULL_TREE)},
+    {"__builtin_cheri_global_data_get",
+     AARCH64_MORELLO_BUILTIN_GLOBAL_DATA_GET,
+     build_function_type_list (cap_type_node, NULL_TREE)},
+    {"__builtin_cheri_length_get",
+     AARCH64_MORELLO_BUILTIN_LENGTH_GET,
+     build_function_type_list (size_type_node, cap_type_node, NULL_TREE)},
+    {"__builtin_cheri_perms_and",
+     AARCH64_MORELLO_BUILTIN_PERMS_AND,
+     build_function_type_list (cap_type_node, cap_type_node, size_type_node,
+                               NULL_TREE)},
+    {"__builtin_cheri_representable_alignment_mask",
+     AARCH64_MORELLO_BUILTIN_REPR_ALIGNMENT_MASK,
+     build_function_type_list (size_type_node, size_type_node, NULL_TREE)},
+    {"__builtin_cheri_round_representable_length",
+     AARCH64_MORELLO_BUILTIN_ROUND_REPR_LEN,
+     build_function_type_list (size_type_node, size_type_node, NULL_TREE)},
+    {"__builtin_cheri_seal",
+     AARCH64_MORELLO_BUILTIN_SEAL,
+      build_function_type_list (cap_type_node, const_cap_type_node,
+                                cap_type_node, NULL_TREE)}
+  };
+
+  for (size_t i = 0; i < ARRAY_SIZE (data); ++i)
+    aarch64_builtin_decls[data[i].code]
+      = aarch64_general_add_builtin (data[i].name, data[i].type, data[i].code);
+}
+#undef morello_vaddr_t
+
 /* Initialize all builtins in the AARCH64_BUILTIN_GENERAL group.  */
 
 void
@@ -1449,6 +1525,9 @@ aarch64_general_init_builtins (void)
   if (!TARGET_ILP32)
     aarch64_init_pauth_hint_builtins ();
 
+  if (TARGET_MORELLO)
+    aarch64_init_morello_builtins ();
+
   if (TARGET_TME)
     aarch64_init_tme_builtins ();
 
@@ -2053,6 +2132,109 @@ aarch64_expand_fpsr_fpcr_getter (enum insn_code icode, machine_mode mode,
   return op.value;
 }
 
+/* Expand an expression EXP (coded with FCODE) for Morello builtins for given TARGET.
+   If IGNORE is set, builtin return value is unused.
+*/
+rtx
+aarch64_expand_morello_builtin (tree exp, rtx target, int fcode)
+{
+  expand_operand ops[3];
+
+  switch (fcode)
+    {
+    case AARCH64_MORELLO_BUILTIN_ADDRESS_SET:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1));
+        create_output_operand (&ops[0], target, CADImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        create_input_operand (&ops[2], op1, DImode);
+        expand_insn (CODE_FOR_replace_address_value_cadi, 3, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_BASE_GET:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        create_output_operand (&ops[0], target, DImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        expand_insn (CODE_FOR_aarch64_cap_base_get, 2, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_BOUNDS_SET:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1));
+        create_output_operand (&ops[0], target, CADImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        create_input_operand (&ops[2], op1, DImode);
+        expand_insn (CODE_FOR_aarch64_cap_bounds_set, 3, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_BOUNDS_SET_EXACT:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1));
+        create_output_operand (&ops[0], target, CADImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        create_input_operand (&ops[2], op1, DImode);
+        expand_insn (CODE_FOR_aarch64_cap_bounds_set_exact, 3, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_GLOBAL_DATA_GET:
+      {
+        create_output_operand (&ops[0], target, CADImode);
+        expand_insn (CODE_FOR_aarch64_cap_global_data_get, 1, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_LENGTH_GET:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        create_output_operand (&ops[0], target, DImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        expand_insn (CODE_FOR_aarch64_cap_length_get, 2, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_PERMS_AND:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1));
+        create_output_operand (&ops[0], target, CADImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        create_input_operand (&ops[2], op1, DImode);
+        expand_insn (CODE_FOR_aarch64_cap_perms_and, 3, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_REPR_ALIGNMENT_MASK:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        create_output_operand (&ops[0], target, DImode);
+        create_input_operand (&ops[1], op0, DImode);
+        expand_insn (CODE_FOR_aarch64_cap_repr_align_mask, 2, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_ROUND_REPR_LEN:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        create_output_operand (&ops[0], target, DImode);
+        create_input_operand (&ops[1], op0, DImode);
+        expand_insn (CODE_FOR_aarch64_cap_round_repr_len, 2, ops);
+        return ops[0].value;
+      }
+    case AARCH64_MORELLO_BUILTIN_SEAL:
+      {
+        rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+        rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1));
+        create_output_operand (&ops[0], target, CADImode);
+        create_input_operand (&ops[1], op0, CADImode);
+        create_input_operand (&ops[2], op1, CADImode);
+        expand_insn (CODE_FOR_aarch64_cap_seal, 3, ops);
+        return ops[0].value;
+      }
+    }
+
+  gcc_unreachable ();
+}
+
 /* Expand an expression EXP that calls built-in function FCODE,
    with result going to TARGET if that's convenient.  IGNORE is true
    if the result of the builtin is ignored.  */
@@ -2161,6 +2343,17 @@ aarch64_general_expand_builtin (unsigned int fcode, tree exp, rtx target,
       emit_insn (GEN_FCN (CODE_FOR_aarch64_fjcvtzs) (target, op0));
       return target;
 
+    case AARCH64_MORELLO_BUILTIN_ADDRESS_SET:
+    case AARCH64_MORELLO_BUILTIN_BASE_GET:
+    case AARCH64_MORELLO_BUILTIN_BOUNDS_SET:
+    case AARCH64_MORELLO_BUILTIN_BOUNDS_SET_EXACT:
+    case AARCH64_MORELLO_BUILTIN_GLOBAL_DATA_GET:
+    case AARCH64_MORELLO_BUILTIN_LENGTH_GET:
+    case AARCH64_MORELLO_BUILTIN_PERMS_AND:
+    case AARCH64_MORELLO_BUILTIN_REPR_ALIGNMENT_MASK:
+    case AARCH64_MORELLO_BUILTIN_ROUND_REPR_LEN:
+    case AARCH64_MORELLO_BUILTIN_SEAL:
+      return aarch64_expand_morello_builtin (exp, target, fcode);
     case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ0_V2SF:
     case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ90_V2SF:
     case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ180_V2SF:
diff --git a/gcc/config/aarch64/aarch64-morello.md b/gcc/config/aarch64/aarch64-morello.md
index 1340e9c8fc8..7d4f83ed62d 100644
--- a/gcc/config/aarch64/aarch64-morello.md
+++ b/gcc/config/aarch64/aarch64-morello.md
@@ -66,3 +66,101 @@
   adr\\t%0, %c1
   adrp\\t%0, %A1"
 )
+
+;; CHERI builtins helpers.
+
+(define_insn "aarch64_cap_base_get"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+        (unspec:DI [(match_operand:CADI 1 "register_operand" "rk")]
+            UNSPEC_CHERI_BASE_GET))
+  ]
+  "TARGET_MORELLO"
+  "gcbase\\t%0, %1"
+)
+
+(define_insn "aarch64_cap_length_get"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+        (unspec:DI [(match_operand:CADI 1 "register_operand" "rk")]
+            UNSPEC_CHERI_LEN_GET))
+  ]
+  "TARGET_MORELLO"
+  "gclen\\t%0, %1"
+)
+
+(define_insn "aarch64_cap_repr_align_mask"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+        (unspec:DI [(match_operand:DI 1 "register_operand" "r")]
+            UNSPEC_CHERI_REPR_ALIGN_MASK)
+    )]
+  "TARGET_MORELLO"
+  "rrmask\\t%0, %1"
+)
+
+(define_insn "aarch64_cap_round_repr_len"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+        (unspec:DI [(match_operand:DI 1 "register_operand" "r")]
+           UNSPEC_CHERI_ROUND_REPR_LEN)
+    )]
+  "TARGET_MORELLO"
+  "rrlen\\t%0, %1"
+)
+
+(define_insn "aarch64_cap_bounds_set"
+  [(set (match_operand:CADI 0 "register_operand" "=rk")
+        (unspec:CADI [(match_operand:CADI 1 "register_operand" "rk")
+          (match_operand:DI 2 "register_operand" "r")]
+            UNSPEC_CHERI_BOUNDS_SET))
+  ]
+  "TARGET_MORELLO"
+  "scbnds\\t%0, %1, %2"
+)
+
+(define_insn "aarch64_cap_bounds_set_exact"
+  [(set (match_operand:CADI 0 "register_operand" "=rk")
+        (unspec:CADI [(match_operand:CADI 1 "register_operand" "rk")
+          (match_operand:DI 2 "register_operand" "r")]
+            UNSPEC_CHERI_BOUNDS_SET_EXACT))
+  ]
+  "TARGET_MORELLO"
+  "scbndse\\t%0, %1, %2"
+)
+
+(define_insn "aarch64_cap_seal"
+  [(set (match_operand:CADI 0 "register_operand" "=rk")
+        (unspec:CADI [(match_operand:CADI 1 "register_operand" "rk")
+          (match_operand:CADI 2 "register_operand" "rk")]
+            UNSPEC_CHERI_SEAL))
+  ]
+  "TARGET_MORELLO"
+  "seal\\t%0, %1, %2"
+)
+
+(define_insn "aarch64_cap_clear_perm"
+  [(set (match_operand:CADI 0 "register_operand" "=rk")
+        (unspec:CADI [(match_operand:CADI 1 "register_operand" "rk")
+          (match_operand:DI 2 "register_operand" "r")]
+            UNSPEC_CHERI_CLEAR_PERM))
+  ]
+  "TARGET_MORELLO"
+  "clrperm\\t%0, %1, %2"
+)
+
+(define_insn "aarch64_cap_global_data_get"
+  [(set (match_operand:CADI 0 "register_operand" "=rk")
+        (unspec:CADI [(const_int 0)]
+            UNSPEC_CHERI_GLOBAL_DATA_GET))]
+  "TARGET_MORELLO"
+  "mrs\\t%0, DDC"
+)
+
+(define_expand "aarch64_cap_perms_and"
+  [(match_operand:CADI 0 "register_operand")
+   (match_operand:CADI 1 "register_operand")
+   (match_operand:DI 2 "register_operand")]
+  "TARGET_MORELLO"
+  {
+    emit_insn (gen_one_cmpldi2 (operands[2], operands[2]));
+    emit_insn (gen_aarch64_cap_clear_perm (operands[0], operands[1], operands[2]));
+    DONE;
+  }
+)
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 9a04bc047aa..063cd1cd94d 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -136,6 +136,16 @@
     UNSPEC_AUTIBSP
     UNSPEC_CALLEE_ABI
     UNSPEC_CASESI
+    UNSPEC_CHERI_ADDR_SET
+    UNSPEC_CHERI_BOUNDS_SET
+    UNSPEC_CHERI_BOUNDS_SET_EXACT
+    UNSPEC_CHERI_BASE_GET
+    UNSPEC_CHERI_CLEAR_PERM
+    UNSPEC_CHERI_GLOBAL_DATA_GET
+    UNSPEC_CHERI_LEN_GET
+    UNSPEC_CHERI_REPR_ALIGN_MASK
+    UNSPEC_CHERI_ROUND_REPR_LEN
+    UNSPEC_CHERI_SEAL
     UNSPEC_CRC32B
     UNSPEC_CRC32CB
     UNSPEC_CRC32CH
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_address_set.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_address_set.c
new file mode 100644
index 00000000000..9b558e777bd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_address_set.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+typedef long long vaddr_t;
+
+void * __capability
+bar (void * __capability c, vaddr_t s) {
+  return __builtin_cheri_address_set (c, s);
+}
+
+/* { dg-final { scan-assembler-times {scvalue\tc[0-9]+, c[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_base_get.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_base_get.c
new file mode 100644
index 00000000000..af8db4ba1df
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_base_get.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+typedef long long vaddr_t;
+
+vaddr_t
+foo (void * __capability cap) {
+  return __builtin_cheri_base_get (cap);
+}
+
+/* { dg-final { scan-assembler-times {gcbase\tx[0-9]+, c[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set.c
new file mode 100644
index 00000000000..45bb6c3b060
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+#include <stddef.h>
+
+void * __capability
+foo (void * __capability c, size_t x) {
+  return __builtin_cheri_bounds_set(c, x);
+}
+
+/* { dg-final { scan-assembler-times {scbnds\tc[0-9]+, c[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set_exact.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set_exact.c
new file mode 100644
index 00000000000..ade31136e3e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_bounds_set_exact.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+#include <stddef.h>
+
+void * __capability
+foo (void * __capability c, size_t x) {
+  return __builtin_cheri_bounds_set_exact(c, x);
+}
+
+/* { dg-final { scan-assembler-times {scbndse\tc[0-9]+, c[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_global_data_get.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_global_data_get.c
new file mode 100644
index 00000000000..5cbb3f07102
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_global_data_get.c
@@ -0,0 +1,9 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+void * __capability
+foo (void) {
+  return __builtin_cheri_global_data_get();
+}
+
+/* { dg-final { scan-assembler-times {mrs\tc[0-9]+, DDC} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_length_get.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_length_get.c
new file mode 100644
index 00000000000..3a98a485ee3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_length_get.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+#include <stddef.h> 
+
+size_t
+foo (void * __capability cap) {
+  return __builtin_cheri_length_get(cap);
+}
+
+/* { dg-final { scan-assembler-times {gclen\tx[0-9]+, c[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_perms_and.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_perms_and.c
new file mode 100644
index 00000000000..690979bf283
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_perms_and.c
@@ -0,0 +1,12 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+#include <stddef.h>
+
+void * __capability
+foo (void * __capability c, size_t x) {
+  return __builtin_cheri_perms_and(c, x);
+}
+
+/* { dg-final { scan-assembler-times {mvn\tx[0-9]+, x[0-9]+} 1 } } */
+/* { dg-final { scan-assembler-times {clrperm\tc[0-9]+, c[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_representable_alignment_mask.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_representable_alignment_mask.c
new file mode 100644
index 00000000000..878e80179d1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_representable_alignment_mask.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+typedef long long vaddr_t;
+
+vaddr_t
+baz (vaddr_t len) {
+  return __builtin_cheri_representable_alignment_mask (len);
+}
+
+/* { dg-final { scan-assembler-times {rrmask\tx[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_round_representable_length.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_round_representable_length.c
new file mode 100644
index 00000000000..d41e9d716fc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_round_representable_length.c
@@ -0,0 +1,11 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+typedef long long vaddr_t;
+
+vaddr_t
+foo (vaddr_t len) {
+  return __builtin_cheri_round_representable_length (len);
+}
+
+/* { dg-final { scan-assembler-times {rrlen\tx[0-9]+, x[0-9]+} 1 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_seal.c b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_seal.c
new file mode 100644
index 00000000000..9c708688d03
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/builtin_cheri_seal.c
@@ -0,0 +1,9 @@
+/* { dg-do compile { target aarch64*-*-* } } */
+/* { dg-additional-options "-march=morello+c64 -mabi=purecap" } */
+
+const void * __capability
+foo (const void * __capability c1, void * __capability c2) {
+  return __builtin_cheri_seal(c1, c2);
+}
+
+/* { dg-final { scan-assembler-times {seal\tc[0-9]+, c[0-9]+, c[0-9]+} 1 } } */


More information about the Gcc-cvs mailing list