[PATCH v1] xen/riscv: improve check-extension() macro

Oleksii Kurochko posted 1 patch 1 week, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/6f37ce6b115b682118a8332b2a81b49358c88587.1714144943.git.oleksii.kurochko@gmail.com
xen/arch/riscv/arch.mk | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
[PATCH v1] xen/riscv: improve check-extension() macro
Posted by Oleksii Kurochko 1 week, 4 days ago
Now, the check-extension() macro has 1 argument instead of 2.
This change helps to reduce redundancy around usage of extensions
name (in the case of the zbb extension, the name was used 3 times).

To implement this, a new variable was introduced:
  <extension name>-insn
which represents the instruction support that is being checked.

Additionally, zbb-insn is updated to use $(comma) instead of ",".

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Suggested-by: Jan Beulich <jbeulich@suse.com>
---
 xen/arch/riscv/arch.mk | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/xen/arch/riscv/arch.mk b/xen/arch/riscv/arch.mk
index dd242c91d1..17827c302c 100644
--- a/xen/arch/riscv/arch.mk
+++ b/xen/arch/riscv/arch.mk
@@ -13,12 +13,21 @@ riscv-generic-flags := $(riscv-abi-y) -march=$(riscv-march-y)
 
 # check-extension: Check whether extenstion is supported by a compiler and
 #                  an assembler.
-# Usage: $(call check-extension,extension_name,"instr")
-check-extension = $(call as-insn,$(CC) $(riscv-generic-flags)_$(1),$(2),_$(1))
-
-zbb-insn := "andn t0, t0, t0"
-zbb := $(call check-extension,zbb,$(zbb-insn))
-zihintpause := $(call check-extension,zihintpause,"pause")
+# Usage: $(call check-extension,extension_name).
+#        it should be defined variable with following name:
+#          <extension name>-insn := "insn"
+#        which represents an instruction of extension support of which is
+#        going to be checked.
+define check-extension =
+$(eval $(1) := \
+	$(call as-insn,$(CC) $(riscv-generic-flags)_$(1),$(value $(1)-insn),_$(1)))
+endef
+
+zbb-insn := "andn t0$(comma)t0$(comma)t0"
+$(call check-extension,zbb)
+
+zihintpause-insn := "pause"
+$(call check-extension,zihintpause)
 
 extensions := $(zbb) $(zihintpause)
 
-- 
2.44.0
Re: [PATCH v1] xen/riscv: improve check-extension() macro
Posted by Jan Beulich 1 week, 1 day ago
On 26.04.2024 17:23, Oleksii Kurochko wrote:
> Now, the check-extension() macro has 1 argument instead of 2.
> This change helps to reduce redundancy around usage of extensions
> name (in the case of the zbb extension, the name was used 3 times).
> 
> To implement this, a new variable was introduced:
>   <extension name>-insn
> which represents the instruction support that is being checked.
> 
> Additionally, zbb-insn is updated to use $(comma) instead of ",".

Which is merely just-in-case, I suppose, but not strictly necessary
anymore?

> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> Suggested-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

Just as a remark: Tags want to be put in chronological order.

Jan
Re: [PATCH v1] xen/riscv: improve check-extension() macro
Posted by Oleksii 6 days, 1 hour ago
On Mon, 2024-04-29 at 15:30 +0200, Jan Beulich wrote:
> On 26.04.2024 17:23, Oleksii Kurochko wrote:
> > Now, the check-extension() macro has 1 argument instead of 2.
> > This change helps to reduce redundancy around usage of extensions
> > name (in the case of the zbb extension, the name was used 3 times).
> > 
> > To implement this, a new variable was introduced:
> >   <extension name>-insn
> > which represents the instruction support that is being checked.
> > 
> > Additionally, zbb-insn is updated to use $(comma) instead of ",".
> 
> Which is merely just-in-case, I suppose, but not strictly necessary
> anymore?
Sorry for late reply, you are right, this is not strictly necessary
anymore.

~ Oleksii

> 
> > Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> > Suggested-by: Jan Beulich <jbeulich@suse.com>
> 
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> 
> Just as a remark: Tags want to be put in chronological order.
> 
> Jan