* [COMMITTED 1/2] gcc: xtensa: add data alignment properties to dynconfig
@ 2023-04-19 19:46 Max Filippov
2023-04-19 19:46 ` [COMMITTED 2/2] gcc: xtensa: add -m[no-]strict-align option Max Filippov
0 siblings, 1 reply; 2+ messages in thread
From: Max Filippov @ 2023-04-19 19:46 UTC (permalink / raw)
To: gcc-patches; +Cc: Max Filippov
gcc/
* config/xtensa/xtensa-dynconfig.cc (xtensa_get_config_v4): New
function.
include/
* xtensa-dynconfig.h (xtensa_config_v4): New struct.
(XCHAL_DATA_WIDTH, XCHAL_UNALIGNED_LOAD_EXCEPTION)
(XCHAL_UNALIGNED_STORE_EXCEPTION, XCHAL_UNALIGNED_LOAD_HW)
(XCHAL_UNALIGNED_STORE_HW, XTENSA_CONFIG_V4_ENTRY_LIST): New
definitions.
(XTENSA_CONFIG_INSTANCE_LIST): Add xtensa_config_v4 instance.
(XTENSA_CONFIG_ENTRY_LIST): Add XTENSA_CONFIG_V4_ENTRY_LIST.
---
gcc/config/xtensa/xtensa-dynconfig.cc | 18 ++++++++
include/xtensa-dynconfig.h | 59 ++++++++++++++++++++++++++-
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/gcc/config/xtensa/xtensa-dynconfig.cc b/gcc/config/xtensa/xtensa-dynconfig.cc
index 9aea9f253c25..12dce4d1b2aa 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.cc
+++ b/gcc/config/xtensa/xtensa-dynconfig.cc
@@ -182,6 +182,24 @@ const struct xtensa_config_v3 *xtensa_get_config_v3 (void)
return config;
}
+const struct xtensa_config_v4 *xtensa_get_config_v4 (void)
+{
+ static const struct xtensa_config_v4 *config;
+ static const struct xtensa_config_v4 def = {
+ 16, /* xchal_data_width */
+ 1, /* xchal_unaligned_load_exception */
+ 1, /* xchal_unaligned_store_exception */
+ 0, /* xchal_unaligned_load_hw */
+ 0, /* xchal_unaligned_store_hw */
+ };
+
+ if (!config)
+ config = (const struct xtensa_config_v4 *) xtensa_load_config ("xtensa_config_v4",
+ &xtensa_config_v4,
+ &def);
+ return config;
+}
+
const char * const *xtensa_get_config_strings (void)
{
static const char * const *config_strings;
diff --git a/include/xtensa-dynconfig.h b/include/xtensa-dynconfig.h
index 2cc15cc99112..48877ebb6b61 100644
--- a/include/xtensa-dynconfig.h
+++ b/include/xtensa-dynconfig.h
@@ -112,6 +112,15 @@ struct xtensa_config_v3
int xchal_have_xea3;
};
+struct xtensa_config_v4
+{
+ int xchal_data_width;
+ int xchal_unaligned_load_exception;
+ int xchal_unaligned_store_exception;
+ int xchal_unaligned_load_hw;
+ int xchal_unaligned_store_hw;
+};
+
typedef struct xtensa_isa_internal_struct xtensa_isa_internal;
extern const void *xtensa_load_config (const char *name,
@@ -120,6 +129,7 @@ extern const void *xtensa_load_config (const char *name,
extern const struct xtensa_config_v1 *xtensa_get_config_v1 (void);
extern const struct xtensa_config_v2 *xtensa_get_config_v2 (void);
extern const struct xtensa_config_v3 *xtensa_get_config_v3 (void);
+extern const struct xtensa_config_v4 *xtensa_get_config_v4 (void);
#ifdef XTENSA_CONFIG_DEFINITION
@@ -207,6 +217,26 @@ extern const struct xtensa_config_v3 *xtensa_get_config_v3 (void);
#define XCHAL_HAVE_XEA3 0
#endif
+#ifndef XCHAL_DATA_WIDTH
+#define XCHAL_DATA_WIDTH 16
+#endif
+
+#ifndef XCHAL_UNALIGNED_LOAD_EXCEPTION
+#define XCHAL_UNALIGNED_LOAD_EXCEPTION 1
+#endif
+
+#ifndef XCHAL_UNALIGNED_STORE_EXCEPTION
+#define XCHAL_UNALIGNED_STORE_EXCEPTION 1
+#endif
+
+#ifndef XCHAL_UNALIGNED_LOAD_HW
+#define XCHAL_UNALIGNED_LOAD_HW 0
+#endif
+
+#ifndef XCHAL_UNALIGNED_STORE_HW
+#define XCHAL_UNALIGNED_STORE_HW 0
+#endif
+
#define XTENSA_CONFIG_ENTRY(a) a
#define XTENSA_CONFIG_V1_ENTRY_LIST \
@@ -276,6 +306,13 @@ extern const struct xtensa_config_v3 *xtensa_get_config_v3 (void);
XTENSA_CONFIG_ENTRY(XCHAL_HAVE_EXCLUSIVE), \
XTENSA_CONFIG_ENTRY(XCHAL_HAVE_XEA3)
+#define XTENSA_CONFIG_V4_ENTRY_LIST \
+ XTENSA_CONFIG_ENTRY(XCHAL_DATA_WIDTH), \
+ XTENSA_CONFIG_ENTRY(XCHAL_UNALIGNED_LOAD_EXCEPTION), \
+ XTENSA_CONFIG_ENTRY(XCHAL_UNALIGNED_STORE_EXCEPTION), \
+ XTENSA_CONFIG_ENTRY(XCHAL_UNALIGNED_LOAD_HW), \
+ XTENSA_CONFIG_ENTRY(XCHAL_UNALIGNED_STORE_HW)
+
#define XTENSA_CONFIG_INSTANCE_LIST \
const struct xtensa_config_v1 xtensa_config_v1 = { \
XTENSA_CONFIG_V1_ENTRY_LIST, \
@@ -285,12 +322,16 @@ const struct xtensa_config_v2 xtensa_config_v2 = { \
}; \
const struct xtensa_config_v3 xtensa_config_v3 = { \
XTENSA_CONFIG_V3_ENTRY_LIST, \
+}; \
+const struct xtensa_config_v4 xtensa_config_v4 = { \
+ XTENSA_CONFIG_V4_ENTRY_LIST, \
}
#define XTENSA_CONFIG_ENTRY_LIST \
XTENSA_CONFIG_V1_ENTRY_LIST, \
XTENSA_CONFIG_V2_ENTRY_LIST, \
- XTENSA_CONFIG_V3_ENTRY_LIST
+ XTENSA_CONFIG_V3_ENTRY_LIST, \
+ XTENSA_CONFIG_V4_ENTRY_LIST
#else /* XTENSA_CONFIG_DEFINITION */
@@ -482,6 +523,22 @@ const struct xtensa_config_v3 xtensa_config_v3 = { \
#undef XCHAL_HAVE_XEA3
#define XCHAL_HAVE_XEA3 (xtensa_get_config_v3 ()->xchal_have_xea3)
+
+#undef XCHAL_DATA_WIDTH
+#define XCHAL_DATA_WIDTH (xtensa_get_config_v4 ()->xchal_data_width)
+
+#undef XCHAL_UNALIGNED_LOAD_EXCEPTION
+#define XCHAL_UNALIGNED_LOAD_EXCEPTION (xtensa_get_config_v4 ()->xchal_unaligned_load_exception)
+
+#undef XCHAL_UNALIGNED_STORE_EXCEPTION
+#define XCHAL_UNALIGNED_STORE_EXCEPTION (xtensa_get_config_v4 ()->xchal_unaligned_store_exception)
+
+#undef XCHAL_UNALIGNED_LOAD_HW
+#define XCHAL_UNALIGNED_LOAD_HW (xtensa_get_config_v4 ()->xchal_unaligned_load_hw)
+
+#undef XCHAL_UNALIGNED_STORE_HW
+#define XCHAL_UNALIGNED_STORE_HW (xtensa_get_config_v4 ()->xchal_unaligned_store_hw)
+
#endif /* XTENSA_CONFIG_DEFINITION */
#ifdef __cplusplus
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [COMMITTED 2/2] gcc: xtensa: add -m[no-]strict-align option
2023-04-19 19:46 [COMMITTED 1/2] gcc: xtensa: add data alignment properties to dynconfig Max Filippov
@ 2023-04-19 19:46 ` Max Filippov
0 siblings, 0 replies; 2+ messages in thread
From: Max Filippov @ 2023-04-19 19:46 UTC (permalink / raw)
To: gcc-patches; +Cc: Max Filippov
gcc/
* config/xtensa/xtensa-opts.h: New header.
* config/xtensa/xtensa.h (STRICT_ALIGNMENT): Redefine as
xtensa_strict_align.
* config/xtensa/xtensa.cc (xtensa_option_override): When
-m[no-]strict-align is not specified in the command line set
xtensa_strict_align to 0 if the hardware supports both unaligned
loads and stores or to 1 otherwise.
* config/xtensa/xtensa.opt (mstrict-align): New option.
* doc/invoke.texi (Xtensa Options): Document -m[no-]strict-align.
---
gcc/config/xtensa/xtensa-opts.h | 28 ++++++++++++++++++++++++++++
gcc/config/xtensa/xtensa.cc | 4 ++++
gcc/config/xtensa/xtensa.h | 2 +-
gcc/config/xtensa/xtensa.opt | 7 +++++++
gcc/doc/invoke.texi | 14 +++++++++++++-
5 files changed, 53 insertions(+), 2 deletions(-)
create mode 100644 gcc/config/xtensa/xtensa-opts.h
diff --git a/gcc/config/xtensa/xtensa-opts.h b/gcc/config/xtensa/xtensa-opts.h
new file mode 100644
index 000000000000..f0b8f5b3bfe7
--- /dev/null
+++ b/gcc/config/xtensa/xtensa-opts.h
@@ -0,0 +1,28 @@
+/* Definitions for option handling for Xtensa.
+ Copyright (C) 2023 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#ifndef XTENSA_OPTS_H
+#define XTENSA_OPTS_H
+
+/* Undefined state for the -mstrict-alignment option */
+enum xtensa_strict_alignment_setting {
+ XTENSA_STRICT_ALIGNMENT_UNDEFINED = -1,
+};
+
+#endif
diff --git a/gcc/config/xtensa/xtensa.cc b/gcc/config/xtensa/xtensa.cc
index 7287aa7a258a..9e5d314e143e 100644
--- a/gcc/config/xtensa/xtensa.cc
+++ b/gcc/config/xtensa/xtensa.cc
@@ -2792,6 +2792,10 @@ xtensa_option_override (void)
if (xtensa_windowed_abi == -1)
xtensa_windowed_abi = TARGET_WINDOWED_ABI_DEFAULT;
+ if (xtensa_strict_alignment == XTENSA_STRICT_ALIGNMENT_UNDEFINED)
+ xtensa_strict_alignment = !XCHAL_UNALIGNED_LOAD_HW
+ || !XCHAL_UNALIGNED_STORE_HW;
+
if (! TARGET_THREADPTR)
targetm.have_tls = false;
diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 8ebf37cab33a..34e06afcff48 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -143,7 +143,7 @@ along with GCC; see the file COPYING3. If not see
/* Set this nonzero if move instructions will actually fail to work
when given unaligned data. */
-#define STRICT_ALIGNMENT 1
+#define STRICT_ALIGNMENT (xtensa_strict_alignment)
/* Promote integer modes smaller than a word to SImode. Set UNSIGNEDP
for QImode, because there is no 8-bit load from memory with sign
diff --git a/gcc/config/xtensa/xtensa.opt b/gcc/config/xtensa/xtensa.opt
index 3a129a4c0393..f16b53bf409f 100644
--- a/gcc/config/xtensa/xtensa.opt
+++ b/gcc/config/xtensa/xtensa.opt
@@ -18,6 +18,9 @@
; along with GCC; see the file COPYING3. If not see
; <http://www.gnu.org/licenses/>.
+HeaderInclude
+config/xtensa/xtensa-opts.h
+
mconst16
Target Mask(CONST16)
Use CONST16 instruction to load constants.
@@ -64,3 +67,7 @@ Use call0 ABI.
mabi=windowed
Target RejectNegative Var(xtensa_windowed_abi, 1)
Use windowed registers ABI.
+
+mstrict-align
+Target Var(xtensa_strict_alignment) Init(XTENSA_STRICT_ALIGNMENT_UNDEFINED)
+Do not use unaligned memory references.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 57fb170ca4cc..54dcccbc148c 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1474,7 +1474,8 @@ See RS/6000 and PowerPC Options.
-mtarget-align -mno-target-align
-mlongcalls -mno-longcalls
-mabi=@var{abi-type}
--mextra-l32r-costs=@var{cycles}}
+-mextra-l32r-costs=@var{cycles}
+-mstrict-align -mno-strict-align}
@emph{zSeries Options}
See S/390 and zSeries Options.
@@ -34401,6 +34402,17 @@ instructions, in clock cycles. This affects, when optimizing for speed,
whether loading a constant from literal pool using @code{L32R} or
synthesizing the constant from a small one with a couple of arithmetic
instructions. The default value is 0.
+
+@opindex mstrict-align
+@opindex mno-strict-align
+@item -mstrict-align
+@itemx -mno-strict-align
+Avoid or allow generating memory accesses that may not be aligned on a natural
+object boundary as described in the architecture specification.
+The default is @option{-mno-strict-align} for cores that support both
+unaligned loads and stores in hardware and @option{-mstrict-align} for all
+other cores.
+
@end table
@node zSeries Options
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-19 19:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 19:46 [COMMITTED 1/2] gcc: xtensa: add data alignment properties to dynconfig Max Filippov
2023-04-19 19:46 ` [COMMITTED 2/2] gcc: xtensa: add -m[no-]strict-align option Max Filippov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).