[PATCH 1/1] LoongArch: Fix ptr mangling/demangling features.

Xi Ruoyao xry111@xry111.site
Sun Aug 21 13:29:07 GMT 2022


On Thu, 2022-08-18 at 10:19 +0800, caiyinyu wrote:
> -/* Load or store to/from a pc-relative EXPR into/from G, using T.
> +/* Load a pc-relative EXPR into G, using T.
>     Note G and T are register names.  */
> -#define LDST_PCREL(OP, G, T,  EXPR) \
> -  pcalau12i T, %pc_hi20(EXPR); \
> -  OP       G, T, %pc_lo12(EXPR);
> +#define LD_PCREL(G, EXPR) \
> +  la.pcrel  G, EXPR; \
> +  REG_L            G,  G,  0;

I'd write

#if HAVE_LOONGARCH_EXPLICIT_RELOCS
# define LDST_PCREL(OP, G, T,  EXPR) \
    pcalau12i T, %pc_hi20(EXPR); \
    OP       G, T, %pc_lo12(EXPR);
#else
# define LD_PCREL(G, EXPR) \
    la.pcrel  G, EXPR; \
    REG_L            G,  G,  0;
#endif

And in configure.ac:

AC_CACHE_CHECK(whether explicit relocs can be used,
               libc_cv_loongarch_explicit_relocs, [dnl
cat > conftest.s << EOF
x: pcalau12i $t0, %pc_hi20(x)
EOF
libc_cv_loongarch_explicit_relocs=no
if AC_TRY_COMMAND(${CC-cc} -c $CFLAGS conftest.s -o conftest.o 1>&AS_MESSAGE_LOG_FD); then
  libc_cv_loongarch_explicit_relocs=yes
fi
rm -f conftest*])
if test $libc_cv_loongarch_explicit_relocs = yes; then
  AC_DEFINE(HAVE_LOONGARCH_EXPLICIT_RELOCS)
fi

This is a micro optimization but two instructions is smaller than 3
instructions anyway :).

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


More information about the Libc-alpha mailing list