[PATCH v2 1/2] gcc: xtensa: add mdynconfig option

2024-04-01 Thread Alexey Lapshin
gcc/
* config/xtensa/elf.h (ASM_SPEC, LINK_SPEC): Pass dynconfig to
assembler/linker.
* config/xtensa/linux.h (ASM_SPEC, LINK_SPEC): Likewise.
* config/xtensa/uclinux.h (ASM_SPEC, LINK_SPEC): Likewise.
* config/xtensa/xtensa-dynconfig.cc: May build dynconfig path with
  dir in XTENSA_GNU_CONFIG and filename in mdynconfig option.
* doc/invoke.texi: Add XTENSA_GNU_CONFIG and mdynconfig doc.
---
 gcc/config/xtensa/elf.h   |  6 ++-
 gcc/config/xtensa/linux.h |  6 ++-
 gcc/config/xtensa/uclinux.h   |  6 ++-
 gcc/config/xtensa/xtensa-dynconfig.cc | 55 ++-
 gcc/config/xtensa/xtensa.opt  |  4 ++
 gcc/doc/invoke.texi   | 14 +++
 6 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
index aa14f9d0134..dd20cb310d0 100644
--- a/gcc/config/xtensa/elf.h
+++ b/gcc/config/xtensa/elf.h
@@ -49,7 +49,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LIB_SPEC
 #define LIB_SPEC "-lc -lsim -lc -lhandlers-sim -lhal"
@@ -69,7 +70,8 @@ along with GCC; see the file COPYING3.  If not see
   %{rdynamic:-export-dynamic} \
 %{static:-static}}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
index 03ec8e7254a..5a19af13dd3 100644
--- a/gcc/config/xtensa/linux.h
+++ b/gcc/config/xtensa/linux.h
@@ -46,7 +46,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 
@@ -60,7 +61,8 @@ along with GCC; see the file COPYING3.  If not see
 %{static-pie:-static -pie --no-dynamic-linker -z text} \
 %{static:-static}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/uclinux.h b/gcc/config/xtensa/uclinux.h
index 062e9640d64..7dd868e074a 100644
--- a/gcc/config/xtensa/uclinux.h
+++ b/gcc/config/xtensa/uclinux.h
@@ -53,13 +53,15 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
  "%{!no-elf2flt:%{!elf2flt*:-elf2flt}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/xtensa-dynconfig.cc 
b/gcc/config/xtensa/xtensa-dynconfig.cc
index 3bd2760e4d8..fe2559e1ed7 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.cc
+++ b/gcc/config/xtensa/xtensa-dynconfig.cc
@@ -22,6 +22,7 @@
 #include "coretypes.h"
 #include "diagnostic.h"
 #include "intl.h"
+#include "options.h"
 #define XTENSA_CONFIG_DEFINITION
 #include "xtensa-config.h"
 #include "xtensa-dynconfig.h"
@@ -67,6 +68,55 @@ dlerror (void)
 
 #define CONFIG_ENV_NAME "XTENSA_GNU_CONFIG"
 
+#ifdef ENABLE_PLUGIN
+
+static char *get_xtensa_dynconfig_file (void)
+{
+  const char *xtensa_dynconfig_env = getenv (CONFIG_ENV_NAME);
+  if (!strlen (xtensa_dynconfig_file))
+{
+  if (xtensa_dynconfig_env && !strlen (lbasename (xtensa_dynconfig_env)))
+   {
+ /* XTENSA_GNU_CONFIG has directory path, but dynconfig file is not 
set */
+ return NULL;
+   }
+  else if (xtensa_dynconfig_env)
+   {
+ /* XTENSA_GNU_CONFIG has filepath */
+ return xstrdup (xtensa_dynconfig_env);
+   }
+  /* dynconfig is not set */
+  return NULL;
+}
+  if (!xtensa_dynconfig_env)
+{
+  /* XTENSA_GNU_CONFIG has filepath */
+  return xstrdup (xtensa_dynconfig_file);
+}
+  if (!strlen (lbasename (xtensa_dynconfig_env)))
+{
+  /* XTENSA_GNU_CONFIG has directory path and dynconfig file is set */
+  const size_t len = strlen (xtensa_dynconfig_env) +
+ strlen (xtensa_dynconfig_file) + 1;
+  char *path = ( char *) xmalloc (len);
+  strcpy (path, xtensa_dynconfig_env);
+  strcat (path, xtensa_dynconfig_file);
+  return path;
+}
+  if (strcmp (lbasename (xtensa_dynconfig_env),
+  

[PATCH v2 2/2] gcc: xtensa: add xtensa*-esp*-elf multilib

2024-04-01 Thread Alexey Lapshin
gcc/
* config.gcc: Add xtensa*-esp*-elf target.
* config/xtensa/t-esp-multilib: New file.
---
 gcc/config.gcc   |  6 ++
 gcc/config/xtensa/t-esp-multilib | 20 
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/config/xtensa/t-esp-multilib

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 17873ac2103..702ddf09f17 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3587,6 +3587,12 @@ xstormy16-*-elf)
 xtensa*-*-elf*)
tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
extra_options="${extra_options} xtensa/elf.opt"
+   tmake_file="${tmake_file} xtensa/t-xtensa"
+   case ${target} in
+   xtensa*-esp-elf*)
+   tmake_file="${tmake_file} xtensa/t-esp-multilib"
+   ;;
+   esac
;;
 xtensa*-*-linux*)
tm_file="${tm_file} elfos.h gnu-user.h linux.h glibc-stdint.h 
xtensa/linux.h"
diff --git a/gcc/config/xtensa/t-esp-multilib b/gcc/config/xtensa/t-esp-multilib
new file mode 100644
index 000..dfc0ac0e04c
--- /dev/null
+++ b/gcc/config/xtensa/t-esp-multilib
@@ -0,0 +1,20 @@
+# 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
+# .
+
+MULTILIB_OPTIONS = 
mdynconfig=xtensa_esp32.so/mdynconfig=xtensa_esp32s2.so/mdynconfig=xtensa_esp32s3.so
 fno-rtti
+MULTILIB_DIRNAMES = esp32 esp32s2 esp32s3 no-rtti
-- 
2.34.1




Re: [PATCH 0/3] Espressif xtensa chips multilib

2023-12-10 Thread Alexey Lapshin
Hi Max!

Could you please consider to merge patch 1 and patch 3?
Along with https://sourceware.org/pipermail/binutils/2023-July/128478.html

Regards,
Alexey


Re: [PATCH v2] xtensa: Fix the issue in "*extzvsi-1bit_addsubx"

2024-11-13 Thread Alexey Lapshin
Takayuki, thank you for the quick fix!

It seems works good now except only one degradation. Instead generating two 
instructions:


7   ptr += (i & 1);
   0x40078564 <+12>:extui   a9, a8, 0, 1
   0x40078567 <+15>:addx2   a2, a9, a2

Now it generates three:


7   ptr += (i & 1);
   0x40078564 <+12>:extui   a9, a8, 0, 1
   0x40078567 <+15>:addx2   a9, a9, a2
   0x4007856a <+18>:mov.n   a2, a9


Testcase to reproduce:


#include 

__attribute__((noinline))
void * func (short *ptr, uint8_t count)
{
for (unsigned i = 0; i < count; i++) {
ptr += (i & 1);
}
return ptr;
}

int main(void)
{
short buf[16] = {}; 
func(buf, 16);
}



[PATCH 0/3] Espressif xtensa chips multilib

2023-07-20 Thread Alexey Lapshin via Gcc-patches
This patch series introduces multilib support for Espressif XTENSA chips in gcc.
The addition of the "-mdynconfig=" option was necessary because the existing
environment variable XTENSA_GNU_CONFIG cannot be utilized for implementing 
multilib.
This is because multilib operates with gcc options rather than environment 
variables.

It is not possible to use full path in "-mdynconfig=" because it could be 
different
on users machines and because multilib syntax already reserves the directory
delimiter character. So, it designed to contain dynconfig filename which would 
not
change in toolchain.

Also, the XTENSA_GNU_CONFIG environment variable usage was changed to include 
both
the dynconfig file fullpath or dynconfigs directory. This change was made to 
overcome
the limitations of modifying LD_LIBRARY_PATH on macOS host machines.


[PATCH 1/3] gcc: xtensa: add mdynconfig option

2023-07-20 Thread Alexey Lapshin via Gcc-patches
gcc/
* config/xtensa/elf.h (ASM_SPEC, LINK_SPEC): Pass dynconfig to
assembler/linker.
* config/xtensa/linux.h (ASM_SPEC, LINK_SPEC): Likewise.
* config/xtensa/uclinux.h (ASM_SPEC, LINK_SPEC): Likewise.
* config/xtensa/xtensa-dynconfig.cc: May build dynconfig path with
  dir in XTENSA_GNU_CONFIG and filename in mdynconfig option.
* doc/invoke.texi: Add XTENSA_GNU_CONFIG and mdynconfig doc.
---
 gcc/config/xtensa/elf.h   |  6 ++-
 gcc/config/xtensa/linux.h |  6 ++-
 gcc/config/xtensa/uclinux.h   |  6 ++-
 gcc/config/xtensa/xtensa-dynconfig.cc | 55 ++-
 gcc/config/xtensa/xtensa.opt  |  4 ++
 gcc/doc/invoke.texi   | 14 +++
 6 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/gcc/config/xtensa/elf.h b/gcc/config/xtensa/elf.h
index 715b3a0b1d2..6683edea1de 100644
--- a/gcc/config/xtensa/elf.h
+++ b/gcc/config/xtensa/elf.h
@@ -49,7 +49,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LIB_SPEC
 #define LIB_SPEC "-lc -lsim -lc -lhandlers-sim -lhal"
@@ -69,7 +70,8 @@ along with GCC; see the file COPYING3.  If not see
   %{rdynamic:-export-dynamic} \
 %{static:-static}}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/linux.h b/gcc/config/xtensa/linux.h
index e684e7deebf..928e8c36923 100644
--- a/gcc/config/xtensa/linux.h
+++ b/gcc/config/xtensa/linux.h
@@ -46,7 +46,8 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #define GLIBC_DYNAMIC_LINKER "/lib/ld.so.1"
 
@@ -60,7 +61,8 @@ along with GCC; see the file COPYING3.  If not see
 %{static-pie:-static -pie --no-dynamic-linker -z text} \
 %{static:-static}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/uclinux.h b/gcc/config/xtensa/uclinux.h
index da9e619fb05..68c209bbebb 100644
--- a/gcc/config/xtensa/uclinux.h
+++ b/gcc/config/xtensa/uclinux.h
@@ -53,13 +53,15 @@ along with GCC; see the file COPYING3.  If not see
   %{mauto-litpools:--auto-litpools} \
   %{mno-auto-litpools:--no-auto-litpools} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LINK_SPEC
 #define LINK_SPEC \
  "%{!no-elf2flt:%{!elf2flt*:-elf2flt}} \
   %{mabi=windowed:--abi-windowed} \
-  %{mabi=call0:--abi-call0}"
+  %{mabi=call0:--abi-call0} \
+  %{mdynconfig=*:--dynconfig=%*}"
 
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
diff --git a/gcc/config/xtensa/xtensa-dynconfig.cc 
b/gcc/config/xtensa/xtensa-dynconfig.cc
index 9aea9f253c2..3d6938a134b 100644
--- a/gcc/config/xtensa/xtensa-dynconfig.cc
+++ b/gcc/config/xtensa/xtensa-dynconfig.cc
@@ -22,6 +22,7 @@
 #include "coretypes.h"
 #include "diagnostic.h"
 #include "intl.h"
+#include "options.h"
 #define XTENSA_CONFIG_DEFINITION
 #include "xtensa-config.h"
 #include "xtensa-dynconfig.h"
@@ -67,6 +68,55 @@ dlerror (void)
 
 #define CONFIG_ENV_NAME "XTENSA_GNU_CONFIG"
 
+#ifdef ENABLE_PLUGIN
+
+static char *get_xtensa_dynconfig_file (void)
+{
+  const char *xtensa_dynconfig_env = getenv (CONFIG_ENV_NAME);
+  if (!strlen (xtensa_dynconfig_file))
+{
+  if (xtensa_dynconfig_env && !strlen (lbasename (xtensa_dynconfig_env)))
+   {
+ /* XTENSA_GNU_CONFIG has directory path, but dynconfig file is not 
set */
+ return NULL;
+   }
+  else if (xtensa_dynconfig_env)
+   {
+ /* XTENSA_GNU_CONFIG has filepath */
+ return xstrdup (xtensa_dynconfig_env);
+   }
+  /* dynconfig is not set */
+  return NULL;
+}
+  if (!xtensa_dynconfig_env)
+{
+  /* XTENSA_GNU_CONFIG has filepath */
+  return xstrdup (xtensa_dynconfig_file);
+}
+  if (!strlen (lbasename (xtensa_dynconfig_env)))
+{
+  /* XTENSA_GNU_CONFIG has directory path and dynconfig file is set */
+  const size_t len = strlen (xtensa_dynconfig_env) +
+ strlen (xtensa_dynconfig_file) + 1;
+  char *path = ( char *) xmalloc (len);
+  strcpy (path, xtensa_dynconfig_env);
+  strcat (path, xtensa_dynconfig_file);
+  return path;
+}
+  if (strcmp (lbasename (xtensa_dynconfig_env),
+  

[PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
gcc/
* config/xtensa/xtensa.h (XCHAL_HAVE_BE, XCHAL_HAVE_DENSITY,
  XCHAL_HAVE_CONST16, XCHAL_HAVE_ABS, XCHAL_HAVE_ADDX,
  XCHAL_HAVE_L32R, XSHAL_USE_ABSOLUTE_LITERALS,
  XSHAL_HAVE_TEXT_SECTION_LITERALS, XCHAL_HAVE_MAC16,
  XCHAL_HAVE_MUL16, XCHAL_HAVE_MUL32, XCHAL_HAVE_MUL32_HIGH,
  XCHAL_HAVE_DIV32, XCHAL_HAVE_NSA, XCHAL_HAVE_MINMAX,
  XCHAL_HAVE_SEXT, XCHAL_HAVE_LOOPS, XCHAL_HAVE_THREADPTR,
  XCHAL_HAVE_RELEASE_SYNC, XCHAL_HAVE_S32C1I,
  XCHAL_HAVE_BOOLEANS, XCHAL_HAVE_FP, XCHAL_HAVE_FP_DIV,
  XCHAL_HAVE_FP_RECIP, XCHAL_HAVE_FP_SQRT,
  XCHAL_HAVE_FP_RSQRT, XCHAL_HAVE_FP_POSTINC, XCHAL_HAVE_DFP,
  XCHAL_HAVE_DFP_DIV, XCHAL_HAVE_DFP_RECIP,
  XCHAL_HAVE_DFP_SQRT, XCHAL_HAVE_DFP_RSQRT,
  XCHAL_HAVE_WINDOWED, XCHAL_NUM_AREGS,
  XCHAL_HAVE_WIDE_BRANCHES, XCHAL_HAVE_PREDICTED_BRANCHES,
  XCHAL_ICACHE_SIZE, XCHAL_DCACHE_SIZE,
  XCHAL_ICACHE_LINESIZE, XCHAL_DCACHE_LINESIZE,
  XCHAL_ICACHE_LINEWIDTH, XCHAL_DCACHE_LINEWIDTH,
  XCHAL_DCACHE_IS_WRITEBACK, XCHAL_HAVE_MMU,
  XCHAL_MMU_MIN_PTE_PAGE_SIZE, XCHAL_HAVE_DEBUG,
  XCHAL_NUM_IBREAK, XCHAL_NUM_DBREAK, XCHAL_DEBUGLEVEL,
  XCHAL_MAX_INSTRUCTION_SIZE, XCHAL_INST_FETCH_WIDTH,
  XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0,
  XCHAL_M_STAGE, XTENSA_MARCH_LATEST, XTENSA_MARCH_EARLIEST,
  XCHAL_HAVE_CLAMPS, XCHAL_HAVE_DEPBITS,
  XCHAL_HAVE_EXCLUSIVE, XCHAL_HAVE_XEA3): Add builtin-macros
  with values from dynconfig.
---
 gcc/config/xtensa/xtensa.h | 62 ++
 1 file changed, 62 insertions(+)

diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 8ebf37cab33..a65b674915b 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3.  If not see
 #endif
 
 
+#define XTENSA_CPU_CPP_BUILTIN(OPT) builtin_define_with_int_value (#OPT, OPT)
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
   do { \
@@ -82,6 +83,67 @@ along with GCC; see the file COPYING3.  If not see
   builtin_define ("__XTENSA_SOFT_FLOAT__");
\
 for (builtin = xtensa_get_config_strings (); *builtin; ++builtin)  \
   builtin_define (*builtin);   \
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BE); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DENSITY);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_CONST16);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ABS);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_ADDX);   
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_L32R);   
\
+XTENSA_CPU_CPP_BUILTIN(XSHAL_USE_ABSOLUTE_LITERALS);   \
+XTENSA_CPU_CPP_BUILTIN(XSHAL_HAVE_TEXT_SECTION_LITERALS);  \
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MAC16);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL16);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MUL32_HIGH); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DIV32);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_NSA);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_MINMAX); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_SEXT);   
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_LOOPS);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_THREADPTR);  
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_RELEASE_SYNC);   \
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_S32C1I); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_BOOLEANS);   
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_DIV); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RECIP);   
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_SQRT);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_RSQRT);   
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_FP_POSTINC); 
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAVE_DFP_DIV);
\
+XTENSA_CPU_CPP_BUILTIN(XCHAL_HAV

[PATCH 3/3] gcc: xtensa: add xtensa*-esp*-elf multilib

2023-07-20 Thread Alexey Lapshin via Gcc-patches
gcc/
* config.gcc: Add xtensa*-esp*-elf target.
* config/xtensa/t-esp-multilib: New file.
---
 gcc/config.gcc   |  6 ++
 gcc/config/xtensa/t-esp-multilib | 20 
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/config/xtensa/t-esp-multilib

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 6fd1594480a..f972c71a0b2 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3512,6 +3512,12 @@ xstormy16-*-elf)
 xtensa*-*-elf*)
tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
extra_options="${extra_options} xtensa/elf.opt"
+   tmake_file="${tmake_file} xtensa/t-xtensa"
+   case ${target} in
+   xtensa*-esp-elf*)
+   tmake_file="${tmake_file} xtensa/t-esp-multilib"
+   ;;
+   esac
;;
 xtensa*-*-linux*)
tm_file="${tm_file} elfos.h gnu-user.h linux.h glibc-stdint.h 
xtensa/linux.h"
diff --git a/gcc/config/xtensa/t-esp-multilib b/gcc/config/xtensa/t-esp-multilib
new file mode 100644
index 000..dfc0ac0e04c
--- /dev/null
+++ b/gcc/config/xtensa/t-esp-multilib
@@ -0,0 +1,20 @@
+# 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
+# .
+
+MULTILIB_OPTIONS = 
mdynconfig=xtensa_esp32.so/mdynconfig=xtensa_esp32s2.so/mdynconfig=xtensa_esp32s3.so
 fno-rtti
+MULTILIB_DIRNAMES = esp32 esp32s2 esp32s3 no-rtti
-- 
2.34.1


Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
Oops, missed this loop while implementing...

I had a problem with building esp chips multilib until added my changes.

This loop looks like just defines a macro without value.
But the value must be set to make it work correctly.
It uses builtin_define() instead builtin_define_with_int_value()

I will check how it could be soved with the loop approach.


Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
I see now, thanks for the explanation, I will try to rebuild toolchain without 
this particular patch.

BTW, what do you thing about placing config from newlib overlay to dynconfig?


Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
On Thu, 2023-07-20 at 08:25 -0700, Max Filippov wrote:
> But it defines them with their respective values.
> Just notice that it adds two leading underscores in front of the names.

Why builtin macros were defined with prefix?
With this approach I also need define it somewhere:

#define XTHAL_ABI_WINDOWED  __XTHAL_ABI_WINDOWED
#define XTHAL_ABI_CALL0 __XTHAL_ABI_CALL0
.


Or add prefix to macros in existing code that also looks not good..

I want to get idea why toolchain can't have builtin macros with the same names?


Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
On Thu, 2023-07-20 at 10:43 -0700, Max Filippov wrote:
> Bonus points for keeping backwards
> compatibility with the overlay-based configuration method (:

Got you, thanks!


Re: [PATCH 2/3] gcc: xtensa: use dynconfig settings as builtin-macros

2023-07-20 Thread Alexey Lapshin via Gcc-patches
Please consider to review another two pathes then.
This would be nice to have it in upstream


[PATCH] xtensa: Add workaround for pSRAM cache issue in ESP32

2022-10-12 Thread Alexey Lapshin via Gcc-patches
From a2b425031f5b06dd51cd3ca34fe4f3620b93a944 Mon Sep 17 00:00:00 2001
From: Jeroen Domburg 
Date: Sat, 12 Aug 2017 23:10:12 +0800
Subject: [PATCH] xtensa: Add workaround for pSRAM cache issue in ESP32

Xtensa does a load/store inversion when a load and a store to the same
address is found in the 5 affected stages of the pipeline: with a load
done
_after_ the store in code, the Xtensa will move it _before_ the store
in
execution.
Unfortunately, the ESP32 pSRAM cache messes up handling these
when an interrupt happens during these. This reorg step inserts NOPs
between loads and stores so this never occurs.

Workarounds:

  ESP32_PSRAM_FIX_NOPS:
   The handling issue also shows up when doing a store to an 8 or 16-
bit
   memory location followed by a larger (16 or 32-bit) sized load from
that
   location within the time it takes to grab a cache line from external
RAM
   (which is at least 80 cycles). The cache will confuse the load and
store,
   resulting in the bytes not set by the store to be read as garbage.
To fix
   this, we insert a memory barrier with NOP instructions after each
8/16-bit
   store that isn't followed by another store.

  ESP32_PSRAM_FIX_MEMW (default):
   Explicitly insert a memory barrier instead of nops.
   Slower than nops, but faster than just adding memws everywhere.

  ESP32_PSRAM_FIX_DUPLDST:
Explicitly insert a load after every store:
- Instruction is s32i:
Insert l32i from that address to the source register
immediately after,
plus a duplicated s32i after that.
- Instruction is s8i/s16i:
Note and insert a memw before a load.
(The same as ESP32_PSRAM_FIX_MEMW)
- If any of the args are volatile, no touch:
The memw resulting from that will fix everything.
---
 gcc/config.gcc  |   5 +
 gcc/config/xtensa/t-esp32-psram-fix |  22 ++
 gcc/config/xtensa/xtensa-opts.h |  34 +++
 gcc/config/xtensa/xtensa.cc | 444 
 gcc/config/xtensa/xtensa.h  |   1 +
 gcc/config/xtensa/xtensa.md |  46 ++-
 gcc/config/xtensa/xtensa.opt|  31 ++
 7 files changed, 580 insertions(+), 3 deletions(-)
 create mode 100644 gcc/config/xtensa/t-esp32-psram-fix
 create mode 100644 gcc/config/xtensa/xtensa-opts.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index e73cb848c2d..a407e8407f0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3457,6 +3457,11 @@ xstormy16-*-elf)
extra_options=stormy16/stormy16.opt
tmake_file="stormy16/t-stormy16"
;;
+xtensa*-esp32-elf*)
+   tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
+   tmake_file="${tmake_file} xtensa/t-esp32-psram-fix"
+   extra_options="${extra_options} xtensa/elf.opt"
+   ;;
 xtensa*-*-elf*)
tm_file="${tm_file} elfos.h newlib-stdint.h xtensa/elf.h"
extra_options="${extra_options} xtensa/elf.opt"
diff --git a/gcc/config/xtensa/t-esp32-psram-fix b/gcc/config/xtensa/t-
esp32-psram-fix
new file mode 100644
index 000..78fe54d4852
--- /dev/null
+++ b/gcc/config/xtensa/t-esp32-psram-fix
@@ -0,0 +1,22 @@
+# Copyright (C) 2022 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
+# .
+
+$(out_object_file): gt-xtensa.h
+
+MULTILIB_OPTIONS = mfix-esp32-psram-cache-issue
+MULTILIB_DIRNAMES = esp32-psram
diff --git a/gcc/config/xtensa/xtensa-opts.h
b/gcc/config/xtensa/xtensa-opts.h
new file mode 100644
index 000..73c2015a016
--- /dev/null
+++ b/gcc/config/xtensa/xtensa-opts.h
@@ -0,0 +1,34 @@
+/* Definitions of option handling for Tensilica's Xtensa target
machine.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   Contributed by Espressif 
+
+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
+.  */
+
+
+
+#ifndef XTENSA_OPTS_H
+#define XTENSA_OPTS_H
+
+enum

[RFC] tree-optimization: fix optimize-out variables passed into func to alloc

2023-01-17 Thread Alexey Lapshin via Gcc-patches
After updating to GCC newer than 11.4.0 we found that some code started
to fail if it was built with size optimization (-Os).
You can find testsuite for reproduction in the attached patch.

The simplified version affected code looks like this:

void alloc_function (unsigned char **data_p) {
  *data_p = malloc (8);
  assert(*data_p != NULL);
}
int main () {
  int *data;
  alloc_function (&data);
  printf ("data pointer is %p", data); // prints NULL(compile with -Os)
}

If the type of passed argument is equal to the type in alloc_function
declaration it works perfectly. Also helps change one or both types to
void.

I found that issue started to appear from commit
d119f34c952f8718fdbabc63e2f369a16e92fa07
if-statement which leads to this issue was found and after being
removed seems it works well.

Could you please elaborate on what cases exactly this checking should
optimize?
I think it should also contain at least one more check for accessing
variable's memory to write..


---
 gcc/testsuite/gcc.dg/tree-ssa/alloc-in-func.c | 17 +
 gcc/tree-ssa-alias.cc |  2 --
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/alloc-in-func.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alloc-in-func.c
b/gcc/testsuite/gcc.dg/tree-ssa/alloc-in-func.c
new file mode 100644
index 000..b30c1cedcb9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/alloc-in-func.c
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+
+#define assert(x) if (!(x)) __builtin_abort ()
+
+static inline void alloc_function (unsigned char **data_p)
+{
+*data_p = (unsigned char *) __builtin_malloc (10);
+assert (*data_p != (void *)0);
+}
+
+int main ()
+{
+int *data = (void *)0;
+alloc_function ((unsigned char **) &data);
+assert (data != (void *)0);
+}
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index b8f107dfa52..9068db300e5 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2608,8 +2608,6 @@ modref_may_conflict (const gcall *stmt,
  if (num_tests >= max_tests)
return true;
  alias_stats.modref_tests++;
- if (!alias_sets_conflict_p (base_set, base_node->base))
-   continue;
  num_tests++;
}
 
-- 
2.34.1