[PATCH] MIPS: improve Loongson-2E/2F/3A detection for -march=native

2014-01-09 Thread Huacai Chen
Hi all,

For human-readability, I submit a patch to Linux kernel to display
Loongson-2E/2F/3A in /proc/cpuinfo. But that break -march=native, this
patch fix that.

Regards,

Huacai

2014-01-10  Huacai Chen  

* config/mips/driver-native.c: improve Loongson-2E/2F/3A detection

---
 gcc/config/mips/driver-native.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/config/mips/driver-native.c b/gcc/config/mips/driver-native.c
index 3f1a8d0..63848d2 100644
--- a/gcc/config/mips/driver-native.c
+++ b/gcc/config/mips/driver-native.c
@@ -58,11 +58,17 @@ host_detect_local_cpu (int argc, const char **argv)
 if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0)
   {
if (strstr (buf, "Godson2 V0.2") != NULL
-   || strstr (buf, "Loongson-2 V0.2") != NULL)
+|| strstr (buf, "Loongson-2 V0.2") != NULL
+|| strstr (buf, "Loongson-2E") != NULL)
  cpu = "loongson2e";
else if (strstr (buf, "Godson2 V0.3") != NULL
-|| strstr (buf, "Loongson-2 V0.3") != NULL)
+|| strstr (buf, "Loongson-2 V0.3") != NULL
+|| strstr (buf, "Loongson-2F") != NULL)
  cpu = "loongson2f";
+   else if (strstr (buf, "Godson3 V0.5") != NULL
+|| strstr (buf, "Loongson-3 V0.5") != NULL
+|| strstr (buf, "Loongson-3A") != NULL)
+ cpu = "loongson3a";
else if (strstr (buf, "SiByte SB1") != NULL)
  cpu = "sb1";
else if (strstr (buf, "R5000") != NULL)
-- 
1.8.5.2



Re: [PATCH v3] LoongArch: add addr_global attribute

2022-07-29 Thread Huacai Chen via Gcc-patches
Hi, Lulu,

On Sat, Jul 30, 2022 at 11:13 AM Lulu Cheng  wrote:
>
>
> 在 2022/7/30 上午1:17, Xi Ruoyao 写道:
>
> Change v2 to v3:
> - Disable section anchor for addr_global symbols.
> - Use -O2 in test to make sure section anchor is disabled.
>
> --
>
> Background:
> https://lore.kernel.org/loongarch/d7670b60-2782-4642-995b-7baa01779...@loongson.cn/T/#e1d47e2fe185f2e2be8fdc0784f0db2f644119379
>
> Question:  Do you have a better name than "addr_global"?
>
> I think the name can be changed to "get_through_got". What do you think of it?
Is this the same thing as "movable" once we used internally?

Huacai
>
> Alternatives:
>
> 1. Just use "-mno-explicit-relocs -mla-local-with-abs" for kernel
> modules.  It's stupid IMO.
> 2. Implement a "-maddress-local-with-got" option for GCC and use it for
> kernel modules.  It seems too overkill: we might create many unnecessary
> GOT entries.
> 3. For all variables with a section attribute, consider it global.  It
> may make sense, but I just checked x86_64 and riscv and they don't do
> this.
> 4. Implement -mcmodel=extreme and use it for kernel modules.  To me
> "extreme" seems really too extreme.
> 5. More hacks in kernel. (Convert relocations against .data..percpu with
> objtool?  But objtool is not even implemented for LoongArch yet.)
>
> Note: I'll be mostly AFK in the following week.  My attempt to finish
> the kernel support for new relocs before going AFK now failed miserably
> :(.
>
> -- >8 --
>
> A linker script and/or a section attribute may locate a local object in
> some way unexpected by the code model, leading to a link failure.  This
> happens when the Linux kernel loads a module with "local" per-CPU
> variables.
>
> Add an attribute to explicitly mark an variable with the address
> unlimited by the code model so we would be able to work around such
> problems.
>
>
> Others I think are ok.


Re: [PATCH] Loongarch: Fix plugin header missing install.

2023-08-19 Thread Huacai Chen via Gcc-patches
Thank you very much, I think this should also be backported to Gcc12/13.

Huacai

On Sat, Aug 19, 2023 at 11:59 AM Chenghua Xu  wrote:
>
> Pushed as r14-3331.
>
> Thanks.
> chenglulu writes:
>
> > LGTM!
> >
> > 在 2023/8/16 上午9:48, Guo Jie 写道:
> >> gcc/ChangeLog:
> >>
> >>  * config/loongarch/t-loongarch: Add loongarch-driver.h into
> >>  TM_H. Add loongarch-def.h and loongarch-tune.h into
> >>  OPTIONS_H_EXTRA.
> >>
> >> Co-authored-by: Lulu Cheng 
> >> ---
> >>   gcc/config/loongarch/t-loongarch | 4 
> >>   1 file changed, 4 insertions(+)
> >>
> >> diff --git a/gcc/config/loongarch/t-loongarch 
> >> b/gcc/config/loongarch/t-loongarch
> >> index 6d6e3435d59..e73f4f437ef 100644
> >> --- a/gcc/config/loongarch/t-loongarch
> >> +++ b/gcc/config/loongarch/t-loongarch
> >> @@ -16,6 +16,10 @@
> >>   # along with GCC; see the file COPYING3.  If not see
> >>   # .
> >>   +TM_H += $(srcdir)/config/loongarch/loongarch-driver.h
> >> +OPTIONS_H_EXTRA += $(srcdir)/config/loongarch/loongarch-def.h \
> >> +   $(srcdir)/config/loongarch/loongarch-tune.h
> >> +
> >>   # Canonical target triplet from config.gcc
> >>   LA_MULTIARCH_TRIPLET = $(patsubst LA_MULTIARCH_TRIPLET=%,%,$\
> >>   $(filter LA_MULTIARCH_TRIPLET=%,$(tm_defines)))
>


Re: [PATCH v1] LoongArch: Add new code model 'emdium'.

2022-08-20 Thread Huacai Chen via Gcc-patches
Hi, Lulu,

I think there is a typo in your subject line.

Huacai

On Sat, Aug 20, 2022 at 5:05 PM Lulu Cheng  wrote:
>
> The function jump instruction in normal mode is 'bl',
> so the scope of the function jump is +-128MB.
>
> Now we've added support for 'medium' mode, this mode is
> to complete the function jump through two instructions:
> pcalau12i + jirl
> So in this mode the function jump range is increased to +-2GB.
>
> Compared with 'normal' mode, 'medium' mode only affects the
> jump range of functions.
>
> gcc/ChangeLog:
>
> * config/loongarch/genopts/loongarch-strings: Support code model 
> medium.
> * config/loongarch/genopts/loongarch.opt.in: Likewise.
> * config/loongarch/loongarch-def.c: Likewise.
> * config/loongarch/loongarch-def.h (CMODEL_LARGE): Likewise.
> (CMODEL_EXTREME): Likewise.
> (N_CMODEL_TYPES): Likewise.
> (CMODEL_MEDIUM): Likewise.
> * config/loongarch/loongarch-opts.cc: Likewise.
> * config/loongarch/loongarch-opts.h (TARGET_CMODEL_MEDIUM): Likewise.
> * config/loongarch/loongarch-str.h (STR_CMODEL_MEDIUM): Likewise.
> * config/loongarch/loongarch.cc (loongarch_call_tls_get_addr):
> Tls symbol Loading support medium mode.
> (loongarch_legitimize_call_address): When medium mode, make a symbolic
> jump with two instructions.
> (loongarch_option_override_internal): Support medium.
> * config/loongarch/loongarch.md (@pcalau12i): New template.
> (@sibcall_internal_1): New function call templates added to 
> support
> medium mode.
> (@sibcall_value_internal_1): Likewise.
> (@sibcall_value_multiple_internal_1): Likewise.
> (@call_internal_1): Likewise.
> (@call_value_internal_1): Likewise.
> (@call_value_multiple_internal_1): Likewise.
> * config/loongarch/loongarch.opt: Support medium.
> * config/loongarch/predicates.md: Add processing about medium mode.
> * doc/invoke.texi: Document for '-mcmodel=medium'.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/func-call-medium-1.c: New test.
> * gcc.target/loongarch/func-call-medium-2.c: New test.
> * gcc.target/loongarch/func-call-medium-3.c: New test.
> * gcc.target/loongarch/func-call-medium-4.c: New test.
> * gcc.target/loongarch/func-call-medium-5.c: New test.
> * gcc.target/loongarch/func-call-medium-6.c: New test.
> * gcc.target/loongarch/func-call-medium-7.c: New test.
> * gcc.target/loongarch/func-call-medium-8.c: New test.
> * gcc.target/loongarch/tls-gd-noplt.c: Add compile parameter 
> '-mexplicit-relocs'.
> ---
>  .../loongarch/genopts/loongarch-strings   |   1 +
>  gcc/config/loongarch/genopts/loongarch.opt.in |   3 +
>  gcc/config/loongarch/loongarch-def.c  |   1 +
>  gcc/config/loongarch/loongarch-def.h  |   7 +-
>  gcc/config/loongarch/loongarch-opts.cc|  15 ++-
>  gcc/config/loongarch/loongarch-opts.h |   1 +
>  gcc/config/loongarch/loongarch-str.h  |   1 +
>  gcc/config/loongarch/loongarch.cc | 123 +
>  gcc/config/loongarch/loongarch.md | 125 +-
>  gcc/config/loongarch/loongarch.opt|   3 +
>  gcc/config/loongarch/predicates.md|  15 ++-
>  gcc/doc/invoke.texi   |   3 +
>  .../gcc.target/loongarch/func-call-medium-1.c |  41 ++
>  .../gcc.target/loongarch/func-call-medium-2.c |  41 ++
>  .../gcc.target/loongarch/func-call-medium-3.c |  41 ++
>  .../gcc.target/loongarch/func-call-medium-4.c |  41 ++
>  .../gcc.target/loongarch/func-call-medium-5.c |  42 ++
>  .../gcc.target/loongarch/func-call-medium-6.c |  42 ++
>  .../gcc.target/loongarch/func-call-medium-7.c |  43 ++
>  .../gcc.target/loongarch/func-call-medium-8.c |  42 ++
>  .../gcc.target/loongarch/tls-gd-noplt.c   |   4 +-
>  21 files changed, 595 insertions(+), 40 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-1.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-2.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-3.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-4.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-5.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-6.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-7.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/func-call-medium-8.c
>
> diff --git a/gcc/config/loongarch/genopts/loongarch-strings 
> b/gcc/config/loongarch/genopts/loongarch-strings
> index cb88ed56b68..44ebb7ab10b 100644
> --- a/gcc/config/loongarch/genopts/loongarch-strings
> +++ b/gcc/config/loongarch/genopts/loongarch-strings
> @@ -54,5 +54,6 @@ OPTSTR_CMODEL   cmodel
>

Re: [PATCH] LoongArch: add -mdirect-extern-access option

2022-09-01 Thread Huacai Chen via Gcc-patches
Hi, Ruoyao,

On Thu, Sep 1, 2022 at 6:56 PM Xi Ruoyao  wrote:
>
> We'd like to introduce a new codegen option to align with the old
> "-Wa,-mla-global-with-pcrel" and avoid a performance & size regression
> building the Linux kernel with new-reloc toolchain.  And it should be
> also useful for building statically linked executables, firmwares (EDK2
> for example), and other OS kernels.
>
> OK for trunk?
This seems drop your (1)(2)(3) approach and do a similar thing as "a
new code model" discussed in another thread?

Huacai
>
> -- >8 --
>
> As a new target, LoongArch does not use copy relocation as it's
> problematic in some circumstances.  One bad consequence is we are
> emitting GOT for all accesses to all extern objects with default
> visibility.  The use of GOT is not needed in statically linked
> executables, OS kernels etc.  The GOT entry just wastes space, and the
> GOT access just slow down the execution in those environments.
>
> Before -mexplicit-relocs, we used "-Wa,-mla-global-with-pcrel" to tell
> the assembler not to use GOT for extern access.  But with
> -mexplicit-relocs, we have to opt the logic in GCC.
>
> The name "-mdirect-extern-access" is learnt from x86 port.
>
> gcc/ChangeLog:
>
> * config/loongarch/genopts/loongarch.opt.in: Add
> -mdirect-extern-access option.
> * config/loongarch/loongarch.opt: Regenerate.
> * config/loongarch/loongarch.cc (loongarch_classify_symbol):
> Don't use SYMBOL_GOT_DISP if TARGET_DIRECT_EXTERN_ACCESS.
> (loongarch_option_override_internal): Complain if
> -mdirect-extern-access is used with -fPIC or -fpic.
> * doc/invoke.texi: Document -mdirect-extern-access for
> LoongArch.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/direct-extern-1.c: New test.
> * gcc.target/loongarch/direct-extern-2.c: New test.
> ---
>  gcc/config/loongarch/genopts/loongarch.opt.in |  4 
>  gcc/config/loongarch/loongarch.cc |  5 -
>  gcc/config/loongarch/loongarch.opt|  4 
>  gcc/doc/invoke.texi   | 15 +++
>  .../gcc.target/loongarch/direct-extern-1.c|  6 ++
>  .../gcc.target/loongarch/direct-extern-2.c|  6 ++
>  6 files changed, 39 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/direct-extern-1.c
>  create mode 100644 gcc/testsuite/gcc.target/loongarch/direct-extern-2.c
>
> diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in 
> b/gcc/config/loongarch/genopts/loongarch.opt.in
> index ebdd9538d48..e10618777b2 100644
> --- a/gcc/config/loongarch/genopts/loongarch.opt.in
> +++ b/gcc/config/loongarch/genopts/loongarch.opt.in
> @@ -184,3 +184,7 @@ Enum(cmodel) String(@@STR_CMODEL_EXTREME@@) 
> Value(CMODEL_EXTREME)
>  mcmodel=
>  Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) 
> Init(CMODEL_NORMAL)
>  Specify the code model.
> +
> +mdirect-extern-access
> +Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0)
> +Avoid using the GOT to access external symbols.
> diff --git a/gcc/config/loongarch/loongarch.cc 
> b/gcc/config/loongarch/loongarch.cc
> index 77e3a105390..2875fa5b0f3 100644
> --- a/gcc/config/loongarch/loongarch.cc
> +++ b/gcc/config/loongarch/loongarch.cc
> @@ -1642,7 +1642,7 @@ loongarch_classify_symbol (const_rtx x)
>if (SYMBOL_REF_TLS_MODEL (x))
>  return SYMBOL_TLS;
>
> -  if (!loongarch_symbol_binds_local_p (x))
> +  if (!TARGET_DIRECT_EXTERN_ACCESS && !loongarch_symbol_binds_local_p (x))
>  return SYMBOL_GOT_DISP;
>
>tree t = SYMBOL_REF_DECL (x);
> @@ -6093,6 +6093,9 @@ loongarch_option_override_internal (struct gcc_options 
> *opts)
>if (loongarch_branch_cost == 0)
>  loongarch_branch_cost = loongarch_cost->branch_cost;
>
> +  if (TARGET_DIRECT_EXTERN_ACCESS && flag_shlib)
> +error ("%qs cannot be used for compiling a shared library",
> +  "-mdirect-extern-access");
>
>switch (la_target.cmodel)
>  {
> diff --git a/gcc/config/loongarch/loongarch.opt 
> b/gcc/config/loongarch/loongarch.opt
> index 6395234218b..96c811c850b 100644
> --- a/gcc/config/loongarch/loongarch.opt
> +++ b/gcc/config/loongarch/loongarch.opt
> @@ -191,3 +191,7 @@ Enum(cmodel) String(extreme) Value(CMODEL_EXTREME)
>  mcmodel=
>  Target RejectNegative Joined Enum(cmodel) Var(la_opt_cmodel) 
> Init(CMODEL_NORMAL)
>  Specify the code model.
> +
> +mdirect-extern-access
> +Target Var(TARGET_DIRECT_EXTERN_ACCESS) Init(0)
> +Avoid using the GOT to access external symbols.
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index e5eb525a2c1..d4e86682827 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -1016,6 +1016,7 @@ Objective-C and Objective-C++ Dialects}.
>  -memcpy  -mno-memcpy -mstrict-align -mno-strict-align @gol
>  -mmax-inline-memcpy-size=@var{n} @gol
>  -mexplicit-relocs -mno-explicit-relocs @gol
> +-mdirect-extern-access -mno-direct-extern-access @gol
>  -mcmodel=@var{