This fixes fenv results for atomic operations on FP values in the test
gcc.dg/atomic/c11-atomic-exec-5.c
gcc/
* config/xtensa/xtensa.cc (xtensa_atomic_assign_expand_fenv):
New declaration.
(TARGET_ATOMIC_ASSIGN_EXPAND_FENV): New macro.
(XTENSA_BUILTIN_GET_FSR, XTENSA_BUILTIN_SET_FSR): New constants.
(xtensa_init_builtins): Create decls for
__builtin_xtensa_get_fsr () and __builtin_xtensa_set_fsr ().
(xtensa_fold_builtin): Return NULL for XTENSA_BUILTIN_GET_FSR
and XTENSA_BUILTIN_SET_FSR.
(xtensa_expand_builtin): Expand __builtin_xtensa_get_fsr () to
the get_fsr instruction and __builtin_xtensa_set_fsr () to the
set_fsr.
(xtensa_atomic_assign_expand_fenv): New function.
* config/xtensa/xtensa.md (UNSPECV_GET_FSR, UNSPECV_SET_FSR):
New constants.
(get_fsr, set_fsr): New patterns.
gcc/testsuite/
* gcc.target/xtensa/builtin-fsr.c: New test.
---
gcc/config/xtensa/xtensa.cc | 64 +++++++++++++++++++
gcc/config/xtensa/xtensa.md | 20 ++++++
gcc/testsuite/gcc.target/xtensa/builtin-fsr.c | 15 +++++
3 files changed, 99 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/xtensa/builtin-fsr.c
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 66879b724a2c..ad7b2eea34db 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -157,6 +157,7 @@ static void xtensa_init_builtins (void);
static tree xtensa_fold_builtin (tree, int, tree *, bool);
static rtx xtensa_expand_builtin (tree, rtx, rtx, machine_mode, int);
static tree xtensa_builtin_decl (unsigned, bool);
+static void xtensa_atomic_assign_expand_fenv (tree *, tree *, tree *);
static void xtensa_va_start (tree, rtx);
static bool xtensa_frame_pointer_required (void);
static rtx xtensa_static_chain (const_tree, bool);
@@ -291,6 +292,9 @@ static tree xtensa_handle_force_l32_attribute (tree *,
tree, tree, int, bool *);
#undef TARGET_BUILTIN_DECL
#define TARGET_BUILTIN_DECL xtensa_builtin_decl
+#undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
+#define TARGET_ATOMIC_ASSIGN_EXPAND_FENV xtensa_atomic_assign_expand_fenv
+
#undef TARGET_PREFERRED_RELOAD_CLASS
#define TARGET_PREFERRED_RELOAD_CLASS xtensa_preferred_reload_class
#undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
@@ -4410,6 +4414,8 @@ xtensa_gimplify_va_arg_expr (tree valist, tree type,
gimple_seq *pre_p,
enum xtensa_builtin
{
XTENSA_BUILTIN_UMULSIDI3,
+ XTENSA_BUILTIN_GET_FSR,
+ XTENSA_BUILTIN_SET_FSR,
XTENSA_BUILTIN_max
};
@@ -4430,6 +4436,27 @@ xtensa_init_builtins (void)
xtensa_builtin_decls[XTENSA_BUILTIN_UMULSIDI3] = decl;
TREE_NOTHROW (decl) = 1;
TREE_READONLY (decl) = 1;
+
+ if (TARGET_HARD_FLOAT)
+ {
+ ftype = build_function_type_list (unsigned_intSI_type_node,
+ NULL_TREE);
+
+ decl = add_builtin_function ("__builtin_xtensa_get_fsr", ftype,
+ XTENSA_BUILTIN_GET_FSR, BUILT_IN_MD,
+ "__xtensa_get_fsr", NULL_TREE);
+ xtensa_builtin_decls[XTENSA_BUILTIN_GET_FSR] = decl;
+ TREE_NOTHROW (decl) = 1;
+
+ ftype = build_function_type_list (void_type_node,
+ unsigned_intSI_type_node, NULL_TREE);
+
+ decl = add_builtin_function ("__builtin_xtensa_set_fsr", ftype,
+ XTENSA_BUILTIN_SET_FSR, BUILT_IN_MD,
+ "__xtensa_set_fsr", NULL_TREE);
+ xtensa_builtin_decls[XTENSA_BUILTIN_SET_FSR] = decl;
+ TREE_NOTHROW (decl) = 1;
+ }
}
@@ -4452,6 +4479,10 @@ xtensa_fold_builtin (tree fndecl, int n_args
ATTRIBUTE_UNUSED, tree *args,
fold_convert (unsigned_intDI_type_node, arg1));
break;
+ case XTENSA_BUILTIN_GET_FSR:
+ case XTENSA_BUILTIN_SET_FSR:
+ break;
+
default:
internal_error ("bad builtin code");
break;
@@ -4478,6 +4509,23 @@ xtensa_expand_builtin (tree exp, rtx target,
implement it. If not, just call the function. */
return expand_call (exp, target, ignore);
+ case XTENSA_BUILTIN_GET_FSR:
+ {
+ expand_operand ops[1];
+ create_output_operand (&ops[0], target, SImode);
+ expand_insn (CODE_FOR_get_fsr, 1, ops);
+ return ops[0].value;
+ }
+
+ case XTENSA_BUILTIN_SET_FSR:
+ {
+ rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
+ expand_operand ops[1];
+ create_input_operand (&ops[0], op0, SImode);
+ expand_insn (CODE_FOR_set_fsr, 1, ops);
+ return const0_rtx;
+ }
+
default:
internal_error ("bad builtin code");
}
@@ -4492,6 +4540,22 @@ xtensa_builtin_decl (unsigned code, bool initialize_p
ATTRIBUTE_UNUSED)
return xtensa_builtin_decls[code];
}
+static void
+xtensa_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
+{
+ if (!TARGET_HARD_FLOAT)
+ return;
+
+ tree get_fsr = xtensa_builtin_decls[XTENSA_BUILTIN_GET_FSR];
+ tree set_fsr = xtensa_builtin_decls[XTENSA_BUILTIN_SET_FSR];
+ tree old_flags = create_tmp_var_raw (unsigned_type_node);
+
+ *hold = build4 (TARGET_EXPR, unsigned_type_node, old_flags,
+ build_call_expr (get_fsr, 0), NULL_TREE, NULL_TREE);
+ *clear = build_call_expr (set_fsr, 1, old_flags);
+ *update = NULL_TREE;
+}
+
/* Worker function for TARGET_PREFERRED_RELOAD_CLASS. */
static reg_class_t
diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 157236c2c319..ab2dd16ec131 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -54,6 +54,8 @@
UNSPECV_EH_RETURN
UNSPECV_SET_TP
UNSPECV_BLOCKAGE
+ UNSPECV_GET_FSR
+ UNSPECV_SET_FSR
])
;; This code iterator allows signed and unsigned widening multiplications
@@ -1656,6 +1658,24 @@
(set_attr "mode" "<MODE>")
(set_attr "length" "3")])
+(define_insn "get_fsr"
+ [(set (match_operand:SI 0 "register_operand" "=a")
+ (unspec_volatile:SI [(const_int 0)] UNSPECV_GET_FSR))]
+ "TARGET_HARD_FLOAT"
+ "rur.fsr\t%0"
+ [(set_attr "type" "farith")
+ (set_attr "mode" "SI")
+ (set_attr "length" "3")])
+
+(define_insn "set_fsr"
+ [(unspec_volatile [(match_operand:SI 0 "register_operand" "r")]
+ UNSPECV_SET_FSR)]
+ "TARGET_HARD_FLOAT"
+ "wur.fsr\t%0"
+ [(set_attr "type" "farith")
+ (set_attr "mode" "SI")
+ (set_attr "length" "3")])
+
;; 64-bit floating point moves
(define_expand "movdf"
diff --git a/gcc/testsuite/gcc.target/xtensa/builtin-fsr.c
b/gcc/testsuite/gcc.target/xtensa/builtin-fsr.c
new file mode 100644
index 000000000000..6ec18c71a45f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/xtensa/builtin-fsr.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target hard_float } */
+
+unsigned int get(void)
+{
+ return __builtin_xtensa_get_fsr();
+}
+
+void set(unsigned int fsr)
+{
+ __builtin_xtensa_set_fsr(fsr);
+}
+
+/* { dg-final { scan-assembler-times "rur.fsr" 1 } } */
+/* { dg-final { scan-assembler-times "wur.fsr" 1 } } */
--
2.47.3