From: Richard Sandiford <richard.sandiford@arm.com>
To: xuchenghua@loongson.cn
Cc: gcc-patches@gcc.gnu.org, chenglulu@loongson.cn,
joseph@codesourcery.com
Subject: Re: [PATCH v8 06/12] LoongArch Port: Builtin functions.
Date: Tue, 08 Mar 2022 18:43:36 +0000 [thread overview]
Message-ID: <mptmti0i8tj.fsf@arm.com> (raw)
In-Reply-To: <20220304071809.3082015-7-xuchenghua@loongson.cn> (xuchenghua@loongson.cn's message of "Fri, 4 Mar 2022 15:18:03 +0800")
xuchenghua@loongson.cn writes:
> +#ifndef _GCC_LOONGARCH_BASE_INTRIN_H
> +#define _GCC_LOONGARCH_BASE_INTRIN_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +typedef struct drdtime
> +{
> + unsigned long dvalue;
> + unsigned long dtimeid;
> +} __drdtime_t;
> +
> +typedef struct rdtime
> +{
> + unsigned int value;
> + unsigned int timeid;
> +} __rdtime_t;
> +
> +#ifdef __loongarch64
> +extern __inline __drdtime_t
> +__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
> +__builtin_loongarch_rdtime_d (void)
> +{
> + __drdtime_t drdtime;
> + __asm__ volatile (
> + "rdtime.d\t%[val],%[tid]\n\t"
> + : [val]"=&r"(drdtime.dvalue),[tid]"=&r"(drdtime.dtimeid)
> + :);
> + return drdtime;
It's usually better to use __foo names for local variables and
parameters, in case the user defines a macro called (in this case)
drdtime.
> +}
> +#define __rdtime_d __builtin_loongarch_rdtime_d
Are both of these names “public”? In other words, can users use
__builtin_longarch_rdtime_d directly, instead of using __rdtime_d?
If only __rdtime_d is public then it might be better to define
the function directly, since that will give better error messages.
> […]
> +#if defined __loongarch64
> +/* Assembly instruction format: ui5, rj, si12. */
> +/* Data types in instruction templates: VOID, USI, UDI, SI. */
> +#define __dcacop(/*ui5*/ _1, /*unsigned long int*/ _2, /*si12*/ _3) \
> + ((void) __builtin_loongarch_dcacop ((_1), (unsigned long int) (_2), (_3)))
> +#else
> +#error "Don't support this ABI."
“Unsupported ABI” might be better. Same for the rest of the file.
> +#endif
> […]
> +/* Invoke MACRO (COND) for each fcmp.cond.{s/d} condition. */
> +#define LARCH_FP_CONDITIONS(MACRO) \
> + MACRO (f), \
> + MACRO (un), \
> + MACRO (eq), \
> + MACRO (ueq), \
> + MACRO (olt), \
> + MACRO (ult), \
> + MACRO (ole), \
> + MACRO (ule), \
> + MACRO (sf), \
> + MACRO (ngle), \
> + MACRO (seq), \
> + MACRO (ngl), \
> + MACRO (lt), \
> + MACRO (nge), \
> + MACRO (le), \
> + MACRO (ngt)
> +
> +/* Enumerates the codes above as LARCH_FP_COND_<X>. */
> +#define DECLARE_LARCH_COND(X) LARCH_FP_COND_##X
> +enum loongarch_fp_condition
> +{
> + LARCH_FP_CONDITIONS (DECLARE_LARCH_COND)
> +};
> +#undef DECLARE_LARCH_COND
> +
> +/* Index X provides the string representation of LARCH_FP_COND_<X>. */
> +#define STRINGIFY(X) #X
> +const char *const
> +loongarch_fp_conditions[16]= {LARCH_FP_CONDITIONS (STRINGIFY)};
> +#undef STRINGIFY
It doesn't look like the code above is needed, since none of the current
built-ins have a condition code attached.
Same applies to the later “cond” field and related comments.
> +
> +/* Declare an availability predicate for built-in functions that require
> + * COND to be true. NAME is the main part of the predicate's name. */
Formatting nit: GNU style is not to have the “*” at the start
of the line.
> +#define AVAIL_ALL(NAME, COND) \
> + static unsigned int \
> + loongarch_builtin_avail_##NAME (void) \
> + { \
> + return (COND) ? 1 : 0; \
> + }
> +
> +static unsigned int
> +loongarch_builtin_avail_default (void)
> +{
> + return 1;
> +}
> +/* This structure describes a single built-in function. */
> +struct loongarch_builtin_description
Very minor nit, sorry, but: missing blank line before the comment.
> […]
> +/* Loongson support crc. */
> +#define CODE_FOR_loongarch_crc_w_b_w CODE_FOR_crc_w_b_w
> +#define CODE_FOR_loongarch_crc_w_h_w CODE_FOR_crc_w_h_w
> +#define CODE_FOR_loongarch_crc_w_w_w CODE_FOR_crc_w_w_w
> +#define CODE_FOR_loongarch_crc_w_d_w CODE_FOR_crc_w_d_w
> +#define CODE_FOR_loongarch_crcc_w_b_w CODE_FOR_crcc_w_b_w
> +#define CODE_FOR_loongarch_crcc_w_h_w CODE_FOR_crcc_w_h_w
> +#define CODE_FOR_loongarch_crcc_w_w_w CODE_FOR_crcc_w_w_w
> +#define CODE_FOR_loongarch_crcc_w_d_w CODE_FOR_crcc_w_d_w
> +
> +/* Privileged state instruction. */
> +#define CODE_FOR_loongarch_cpucfg CODE_FOR_cpucfg
> +#define CODE_FOR_loongarch_asrtle_d CODE_FOR_asrtle_d
> +#define CODE_FOR_loongarch_asrtgt_d CODE_FOR_asrtgt_d
> +#define CODE_FOR_loongarch_csrrd CODE_FOR_csrrd
> +#define CODE_FOR_loongarch_dcsrrd CODE_FOR_dcsrrd
> +#define CODE_FOR_loongarch_csrwr CODE_FOR_csrwr
> +#define CODE_FOR_loongarch_dcsrwr CODE_FOR_dcsrwr
> +#define CODE_FOR_loongarch_csrxchg CODE_FOR_csrxchg
> +#define CODE_FOR_loongarch_dcsrxchg CODE_FOR_dcsrxchg
> +#define CODE_FOR_loongarch_iocsrrd_b CODE_FOR_iocsrrd_b
> +#define CODE_FOR_loongarch_iocsrrd_h CODE_FOR_iocsrrd_h
> +#define CODE_FOR_loongarch_iocsrrd_w CODE_FOR_iocsrrd_w
> +#define CODE_FOR_loongarch_iocsrrd_d CODE_FOR_iocsrrd_d
> +#define CODE_FOR_loongarch_iocsrwr_b CODE_FOR_iocsrwr_b
> +#define CODE_FOR_loongarch_iocsrwr_h CODE_FOR_iocsrwr_h
> +#define CODE_FOR_loongarch_iocsrwr_w CODE_FOR_iocsrwr_w
> +#define CODE_FOR_loongarch_iocsrwr_d CODE_FOR_iocsrwr_d
> +#define CODE_FOR_loongarch_lddir CODE_FOR_lddir
> +#define CODE_FOR_loongarch_dlddir CODE_FOR_dlddir
> +#define CODE_FOR_loongarch_ldpte CODE_FOR_ldpte
> +#define CODE_FOR_loongarch_dldpte CODE_FOR_dldpte
> +#define CODE_FOR_loongarch_cacop CODE_FOR_cacop
> +#define CODE_FOR_loongarch_dcacop CODE_FOR_dcacop
> +#define CODE_FOR_loongarch_dbar CODE_FOR_dbar
> +#define CODE_FOR_loongarch_ibar CODE_FOR_ibar
Unless there's a reason not to, it would be better to add “loongarch_”
to the names of the .md patterns instead. That removes the need for
the list above, but it also reduces the risk of an accidental clash
with target-independent pattern names.
Looks good to me otherwise, thanks.
Richard
next prev parent reply other threads:[~2022-03-08 18:43 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-04 7:17 [PATCH v8 00/12] Add LoongArch support xuchenghua
2022-03-04 7:17 ` [PATCH v8 01/12] LoongArch Port: Regenerate configure xuchenghua
2022-03-04 7:17 ` [PATCH v8 02/12] LoongArch Port: gcc build xuchenghua
2022-03-06 10:29 ` Richard Sandiford
2022-03-06 10:34 ` Andreas Schwab
2022-03-04 7:18 ` [PATCH v8 03/12] LoongArch Port: Regenerate gcc/configure xuchenghua
2022-03-04 7:18 ` [PATCH v8 04/12] LoongArch Port: Machine description files xuchenghua
2022-03-06 16:16 ` Richard Sandiford
2022-03-07 3:59 ` 程璐璐
2022-03-19 9:40 ` 程璐璐
2022-03-07 20:15 ` Xi Ruoyao
2022-03-10 6:26 ` 程璐璐
2022-03-04 7:18 ` [PATCH v8 05/12] LoongArch Port: Machine description C files and .h files xuchenghua
2022-03-07 18:17 ` Richard Sandiford
2022-03-19 9:35 ` 程璐璐
2022-03-04 7:18 ` [PATCH v8 06/12] LoongArch Port: Builtin functions xuchenghua
2022-03-08 18:43 ` Richard Sandiford [this message]
2022-03-04 7:18 ` [PATCH v8 07/12] LoongArch Port: Builtin macros xuchenghua
2022-03-04 7:18 ` [PATCH v8 08/12] LoongArch Port: libgcc xuchenghua
2022-03-08 18:59 ` Richard Sandiford
2022-03-08 19:37 ` Andreas Schwab
2022-03-04 7:18 ` [PATCH v8 09/12] LoongArch Port: Regenerate libgcc/configure xuchenghua
2022-03-04 7:18 ` [PATCH v8 10/12] LoongArch Port: libgomp xuchenghua
2022-03-04 7:18 ` [PATCH v8 11/12] LoongArch Port: gcc/testsuite xuchenghua
2022-03-08 19:06 ` Richard Sandiford
2022-03-04 7:18 ` [PATCH v8 12/12] LoongArch Port: Add doc xuchenghua
2022-03-08 19:53 ` Richard Sandiford
2022-03-04 20:02 ` [PATCH v8 00/12] Add LoongArch support Xi Ruoyao
2022-03-05 1:36 ` Paul Hua
2022-03-05 1:39 ` Paul Hua
2022-03-05 9:21 ` Xi Ruoyao
2022-03-08 19:57 ` Richard Sandiford
2022-03-15 14:35 ` Xi Ruoyao
2022-03-16 12:31 ` 程璐璐
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mptmti0i8tj.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=chenglulu@loongson.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).