Hi Saurabh,

> On 20 Aug 2024, at 17:44, saurabh....@arm.com wrote:
> 
> External email: Use caution opening links or attachments
> 
> 
> The AArch64 FEAT_FAMINMAX extension is optional from Armv9.2-a and
> mandatory from Armv9.5-a. It introduces instructions for computing the
> floating point absolute maximum and minimum of the two vectors element-wise.
> 
> This patch introduces AdvSIMD faminmax intrinsics. The intrinsics of
> this extension are implemented as the following builtin functions:
> * vamax_f16
> * vamaxq_f16
> * vamax_f32
> * vamaxq_f32
> * vamaxq_f64
> * vamin_f16
> * vaminq_f16
> * vamin_f32
> * vaminq_f32
> * vaminq_f64
> 
> gcc/ChangeLog:
> 
>        * config/aarch64/aarch64-builtins.cc
>        (enum aarch64_builtins): New enum values for faminmax builtins.
>        (aarch64_init_faminmax_builtins): New function to declare new
> builtins.
>        (handle_arm_neon_h): Modify to call
> aarch64_init_faminmax_builtins.
>        (aarch64_general_check_builtin_call): Modify to check whether
> +faminmax flag is being used and printing error message if not being
> used.
>        (aarch64_expand_builtin_faminmax): New function to emit
> instructions of this extension.
>        (aarch64_general_expand_builtin): Modify to call
> aarch64_expand_builtin_faminmax.
>        * config/aarch64/aarch64-option-extensions.def
>        (AARCH64_OPT_EXTENSION): Introduce new flag for this
> extension.
>        * config/aarch64/aarch64-simd.md
>        (aarch64_<faminmax_uns_op><mode>): Instruction pattern for
> faminmax intrinsics.
>        * config/aarch64/aarch64.h
>        (TARGET_FAMINMAX): Introduce new flag for this extension.
>        * config/aarch64/iterators.md: Introduce new iterators for
>          faminmax intrinsics.
>        * config/arm/types.md: Introduce neon_fp_aminmax<q> attributes.
>        * doc/invoke.texi: Document extension in AArch64 Options.
> 
> gcc/testsuite/ChangeLog:
> 
>        * gcc.target/aarch64/simd/faminmax-builtins-no-flag.c: New test.
>        * gcc.target/aarch64/simd/faminmax-builtins.c: New test.

This is almost ready but...


> ---
> gcc/config/aarch64/aarch64-builtins.cc        | 126 ++++++++++++++++++
> .../aarch64/aarch64-option-extensions.def     |   2 +
> gcc/config/aarch64/aarch64-simd.md            |  11 ++
> gcc/config/aarch64/aarch64.h                  |   4 +
> gcc/config/aarch64/iterators.md               |   9 ++
> gcc/config/arm/types.md                       |   6 +
> gcc/doc/invoke.texi                           |   2 +
> .../aarch64/simd/faminmax-builtins-no-flag.c  |  10 ++
> .../aarch64/simd/faminmax-builtins.c          | 115 ++++++++++++++++
> 9 files changed, 285 insertions(+)
> create mode 100644 
> gcc/testsuite/gcc.target/aarch64/simd/faminmax-builtins-no-flag.c
> create mode 100644 gcc/testsuite/gcc.target/aarch64/simd/faminmax-builtins.c
> 
> <v4-0001-aarch64-Add-AdvSIMD-faminmax-intrinsics.patch>

…
+static rtx
+aarch64_expand_builtin_faminmax (unsigned int fcode, tree exp, rtx target)
+{
+ machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
+ rtx op0 = force_reg (mode, expand_normal (CALL_EXPR_ARG (exp, 0)));
+ rtx op1 = force_reg (mode, expand_normal (CALL_EXPR_ARG (exp, 1)));
+
+ enum insn_code icode;
+ if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMAX4H)
+ icode = CODE_FOR_aarch64_famaxv4hf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMAX8H)
+ icode = CODE_FOR_aarch64_famaxv8hf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMAX2S)
+ icode = CODE_FOR_aarch64_famaxv2sf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMAX4S)
+ icode = CODE_FOR_aarch64_famaxv4sf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMAX2D)
+ icode = CODE_FOR_aarch64_famaxv2df;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMIN4H)
+ icode = CODE_FOR_aarch64_faminv4hf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMIN8H)
+ icode = CODE_FOR_aarch64_faminv8hf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMIN2S)
+ icode = CODE_FOR_aarch64_faminv2sf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMIN4S)
+ icode = CODE_FOR_aarch64_faminv4sf;
+ else if (fcode == AARCH64_FAMINMAX_BUILTIN_FAMIN2D)
+ icode = CODE_FOR_aarch64_faminv2df;
+ else
+ gcc_unreachable ();
+
+ rtx pat = GEN_FCN (icode) (target, op0, op1);
+

I’m very sorry for not spotting this earlier, but we now have a mechanism for 
avoiding these if-else-if chains.
If you mark the aarch64_<faminmax_uns_op><mode> pattern in aarch64.md with “@“ 
i.e. “@aarch64_<faminmax_uns_op><mode>”
Then you should be able to say:
icode = code_for_aarch64_famax (mode);
and
icode = code_for_aarch64_famin (mode);

You can then write this part as a more compact switch statement with 
fallthroughs for the famax and famin cases.

Ok with that change.
Thanks,
Kyrill


Reply via email to