diff mbox series

[v2,1/2] tcg: add dup_const_tl wrapper

Message ID 20211003214243.3813425-1-philipp.tomsich@vrull.eu
State New
Headers show
Series [v2,1/2] tcg: add dup_const_tl wrapper | expand

Commit Message

Philipp Tomsich Oct. 3, 2021, 9:42 p.m. UTC
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(+)

Comments

Richard Henderson Oct. 4, 2021, 12:38 a.m. UTC | #1
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~
Philippe Mathieu-Daudé Oct. 4, 2021, 7:43 a.m. UTC | #2
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>
Richard Henderson Oct. 5, 2021, 2:22 a.m. UTC | #3
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~
diff mbox series

Patch

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.
  */