All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] tcg: add dup_const_tl wrapper
@ 2021-10-03 21:42 Philipp Tomsich
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Philipp Tomsich @ 2021-10-03 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Alistair Francis, Philipp Tomsich

dup_const always generates a uint64_t, which may exceed the size of a
target_long (generating warnings with recent-enough compilers).

To ensure that we can use dup_const both for 64bit and 32bit targets,
this adds dup_const_tl, which either maps back to dup_const (for 64bit
targets) or provides a similar implementation using 32bit constants.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>

---

Changes in v2:
- Changed dup_const_tl to enforce the sanity check with
  qemu_build_not_reached as requested in the review.

 include/tcg/tcg.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 44ccd86f3e..1bb6c0ce3e 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -1272,6 +1272,18 @@ uint64_t dup_const(unsigned vece, uint64_t c);
         : (qemu_build_not_reached_always(), 0))                    \
      : dup_const(VECE, C))
 
+#if TARGET_LONG_BITS == 64
+# define dup_const_tl  dup_const
+#else
+# define dup_const_tl(VECE, C)                                     \
+    (__builtin_constant_p(VECE)                                    \
+     ? (  (VECE) == MO_8  ? 0x01010101ul * (uint8_t)(C)            \
+        : (VECE) == MO_16 ? 0x00010001ul * (uint16_t)(C)           \
+        : (VECE) == MO_32 ? 0x00000001ul * (uint32_t)(C)           \
+        : (qemu_build_not_reached_always(), 0))                    \
+     :  (target_long)dup_const(VECE, C))
+#endif
+
 /*
  * Memory helpers that will be used by TCG generated code.
  */
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant
  2021-10-03 21:42 [PATCH v2 1/2] tcg: add dup_const_tl wrapper Philipp Tomsich
@ 2021-10-03 21:42 ` Philipp Tomsich
  2021-10-04  7:43   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2021-10-04  0:38 ` [PATCH v2 1/2] tcg: add dup_const_tl wrapper Richard Henderson
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 8+ messages in thread
From: Philipp Tomsich @ 2021-10-03 21:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Alistair Francis, Philipp Tomsich

We need to use the newly introduced dup_const_tl in orc.b to legalise
the truncation (to target_long) of the constant generated with dup_const.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---

(no changes since v1)

 target/riscv/insn_trans/trans_rvb.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
index 2927353d9b..185c3e9a60 100644
--- a/target/riscv/insn_trans/trans_rvb.c.inc
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
@@ -249,7 +249,7 @@ static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a)
 static void gen_orc_b(TCGv ret, TCGv source1)
 {
     TCGv  tmp = tcg_temp_new();
-    TCGv  ones = tcg_constant_tl(dup_const(MO_8, 0x01));
+    TCGv  ones = tcg_constant_tl(dup_const_tl(MO_8, 0x01));
 
     /* Set lsb in each byte if the byte was zero. */
     tcg_gen_sub_tl(tmp, source1, ones);
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] tcg: add dup_const_tl wrapper
  2021-10-03 21:42 [PATCH v2 1/2] tcg: add dup_const_tl wrapper Philipp Tomsich
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
@ 2021-10-04  0:38 ` Richard Henderson
  2021-10-04  7:43 ` Philippe Mathieu-Daudé
  2021-10-05  2:22 ` Richard Henderson
  3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2021-10-04  0:38 UTC (permalink / raw)
  To: Philipp Tomsich, qemu-devel; +Cc: Alistair Francis

On 10/3/21 5:42 PM, Philipp Tomsich wrote:
> dup_const always generates a uint64_t, which may exceed the size of a
> target_long (generating warnings with recent-enough compilers).
> 
> To ensure that we can use dup_const both for 64bit and 32bit targets,
> this adds dup_const_tl, which either maps back to dup_const (for 64bit
> targets) or provides a similar implementation using 32bit constants.
> 
> Signed-off-by: Philipp Tomsich<philipp.tomsich@vrull.eu>
> 
> ---

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] tcg: add dup_const_tl wrapper
  2021-10-03 21:42 [PATCH v2 1/2] tcg: add dup_const_tl wrapper Philipp Tomsich
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
  2021-10-04  0:38 ` [PATCH v2 1/2] tcg: add dup_const_tl wrapper Richard Henderson
@ 2021-10-04  7:43 ` Philippe Mathieu-Daudé
  2021-10-05  2:22 ` Richard Henderson
  3 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-04  7:43 UTC (permalink / raw)
  To: Philipp Tomsich, qemu-devel; +Cc: Alistair Francis, Richard Henderson

On 10/3/21 23:42, Philipp Tomsich wrote:
> dup_const always generates a uint64_t, which may exceed the size of a
> target_long (generating warnings with recent-enough compilers).
> 
> To ensure that we can use dup_const both for 64bit and 32bit targets,
> this adds dup_const_tl, which either maps back to dup_const (for 64bit
> targets) or provides a similar implementation using 32bit constants.
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
> 
> ---
> 
> Changes in v2:
> - Changed dup_const_tl to enforce the sanity check with
>   qemu_build_not_reached as requested in the review.
> 
>  include/tcg/tcg.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
@ 2021-10-04  7:43   ` Philippe Mathieu-Daudé
  2021-10-06 22:26   ` Alistair Francis
  2021-10-06 22:42   ` Alistair Francis
  2 siblings, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-04  7:43 UTC (permalink / raw)
  To: Philipp Tomsich, qemu-devel; +Cc: Alistair Francis, Richard Henderson

On 10/3/21 23:42, Philipp Tomsich wrote:
> We need to use the newly introduced dup_const_tl in orc.b to legalise
> the truncation (to target_long) of the constant generated with dup_const.
> 
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> 
> (no changes since v1)
> 
>  target/riscv/insn_trans/trans_rvb.c.inc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] tcg: add dup_const_tl wrapper
  2021-10-03 21:42 [PATCH v2 1/2] tcg: add dup_const_tl wrapper Philipp Tomsich
                   ` (2 preceding siblings ...)
  2021-10-04  7:43 ` Philippe Mathieu-Daudé
@ 2021-10-05  2:22 ` Richard Henderson
  3 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2021-10-05  2:22 UTC (permalink / raw)
  To: Philipp Tomsich, qemu-devel; +Cc: Alistair Francis

On 10/3/21 2:42 PM, Philipp Tomsich wrote:
> dup_const always generates a uint64_t, which may exceed the size of a
> target_long (generating warnings with recent-enough compilers).
> 
> To ensure that we can use dup_const both for 64bit and 32bit targets,
> this adds dup_const_tl, which either maps back to dup_const (for 64bit
> targets) or provides a similar implementation using 32bit constants.
> 
> Signed-off-by: Philipp Tomsich<philipp.tomsich@vrull.eu>
> 
> ---
> 
> Changes in v2:
> - Changed dup_const_tl to enforce the sanity check with
>    qemu_build_not_reached as requested in the review.

Queueing this one patch through tcg-next.
I'll let Alistair take the other through riscv.

r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
  2021-10-04  7:43   ` Philippe Mathieu-Daudé
@ 2021-10-06 22:26   ` Alistair Francis
  2021-10-06 22:42   ` Alistair Francis
  2 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-10-06 22:26 UTC (permalink / raw)
  To: Philipp Tomsich
  Cc: Alistair Francis, Richard Henderson, qemu-devel@nongnu.org Developers

On Mon, Oct 4, 2021 at 7:44 AM Philipp Tomsich <philipp.tomsich@vrull.eu> wrote:
>
> We need to use the newly introduced dup_const_tl in orc.b to legalise
> the truncation (to target_long) of the constant generated with dup_const.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>
> (no changes since v1)
>
>  target/riscv/insn_trans/trans_rvb.c.inc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
> index 2927353d9b..185c3e9a60 100644
> --- a/target/riscv/insn_trans/trans_rvb.c.inc
> +++ b/target/riscv/insn_trans/trans_rvb.c.inc
> @@ -249,7 +249,7 @@ static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a)
>  static void gen_orc_b(TCGv ret, TCGv source1)
>  {
>      TCGv  tmp = tcg_temp_new();
> -    TCGv  ones = tcg_constant_tl(dup_const(MO_8, 0x01));
> +    TCGv  ones = tcg_constant_tl(dup_const_tl(MO_8, 0x01));
>
>      /* Set lsb in each byte if the byte was zero. */
>      tcg_gen_sub_tl(tmp, source1, ones);
> --
> 2.25.1
>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant
  2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
  2021-10-04  7:43   ` Philippe Mathieu-Daudé
  2021-10-06 22:26   ` Alistair Francis
@ 2021-10-06 22:42   ` Alistair Francis
  2 siblings, 0 replies; 8+ messages in thread
From: Alistair Francis @ 2021-10-06 22:42 UTC (permalink / raw)
  To: Philipp Tomsich
  Cc: Alistair Francis, Richard Henderson, qemu-devel@nongnu.org Developers

On Mon, Oct 4, 2021 at 7:44 AM Philipp Tomsich <philipp.tomsich@vrull.eu> wrote:
>
> We need to use the newly introduced dup_const_tl in orc.b to legalise
> the truncation (to target_long) of the constant generated with dup_const.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks, I have applied this.

I squashed it into the original commit to ensure there are no build regressions.

Alistair


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-06 22:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-03 21:42 [PATCH v2 1/2] tcg: add dup_const_tl wrapper Philipp Tomsich
2021-10-03 21:42 ` [PATCH v2 2/2] target/riscv: Use dup_const_tl in orc.b to legalise truncation of constant Philipp Tomsich
2021-10-04  7:43   ` Philippe Mathieu-Daudé
2021-10-06 22:26   ` Alistair Francis
2021-10-06 22:42   ` Alistair Francis
2021-10-04  0:38 ` [PATCH v2 1/2] tcg: add dup_const_tl wrapper Richard Henderson
2021-10-04  7:43 ` Philippe Mathieu-Daudé
2021-10-05  2:22 ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.