* [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 14:50 ` Philippe Mathieu-Daudé
2026-09-29 21:31 ` Matt Turner
2026-09-27 8:58 ` [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS Richard Henderson
` (99 subsequent siblings)
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/qemu/compiler.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 4c49f52eb07..3661dc5fbaa 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -25,6 +25,14 @@
#define QEMU_PACKED __attribute__((packed))
#define QEMU_ALIGNED(X) __attribute__((aligned(X)))
+#define QEMU_ARG_NONNULL __attribute__((nonnull))
+#define QEMU_ARG_LIST_NONNULL(...) __attribute__((nonnull(__VA_LIST__)))
+#define QEMU_RET_NONNULL __attribute__((returns_nonnull))
+#define QEMU_RET_ARG_NONNULL \
+ __attribute__((returns_nonnull, nonnull))
+#define QEMU_RET_ARG_LIST_NONNULL(...) \
+ __attribute__((returns_nonnull, nonnull(__VA_ARGS__)))
+
#ifndef glue
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes
2026-09-27 8:58 ` [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes Richard Henderson
@ 2026-09-27 14:50 ` Philippe Mathieu-Daudé
2026-09-29 21:31 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 14:50 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/qemu/compiler.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes
2026-09-27 8:58 ` [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes Richard Henderson
2026-09-27 14:50 ` Philippe Mathieu-Daudé
@ 2026-09-29 21:31 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 21:31 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:00 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/qemu/compiler.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index 4c49f52eb07..3661dc5fbaa 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -25,6 +25,14 @@
> #define QEMU_PACKED __attribute__((packed))
> #define QEMU_ALIGNED(X) __attribute__((aligned(X)))
>
> +#define QEMU_ARG_NONNULL __attribute__((nonnull))
> +#define QEMU_ARG_LIST_NONNULL(...) __attribute__((nonnull(__VA_LIST__)))
__VA_LIST__? Supposed to be __VA_ARGS__? Doesn't appear to be used in
the series, which is probably why it builds.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
2026-09-27 8:58 ` [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:51 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 003/101] tcg: Annontate functions in tcg.h with QEMU_*_NONNULL Richard Henderson
` (98 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/qemu/compiler.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 3661dc5fbaa..8fa4552ef8f 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -230,6 +230,13 @@
# define QEMU_UNINITIALIZED
#endif
+/*
+ * Alias the current function definition to another.
+ */
+
+#define QEMU_ALIAS(N) \
+ __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__, N)))))
+
/*
* http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
*
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS
2026-09-27 8:58 ` [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS Richard Henderson
@ 2026-09-27 15:51 ` Philippe Mathieu-Daudé
2026-09-27 22:35 ` Richard Henderson
0 siblings, 1 reply; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 15:51 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88, Pierrick Bouvier
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/qemu/compiler.h | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index 3661dc5fbaa..8fa4552ef8f 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -230,6 +230,13 @@
> # define QEMU_UNINITIALIZED
> #endif
>
> +/*
> + * Alias the current function definition to another.
> + */
> +
> +#define QEMU_ALIAS(N) \
> + __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__, N)))))
> +
> /*
> * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
> *
On macOS:
../../tcg/tcg-op.c:1820:38: error: aliases are not supported on darwin
1820 | void tcg_gen_discard_ptr(TCGv_ptr a)
QEMU_ALIAS(tcg_gen_discard_i64);
| ^
include/qemu/compiler.h:238:20: note: expanded from macro 'QEMU_ALIAS'
238 | __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__,
N)))))
| ^
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS
2026-09-27 15:51 ` Philippe Mathieu-Daudé
@ 2026-09-27 22:35 ` Richard Henderson
2026-09-28 16:23 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 22:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: mattst88, Pierrick Bouvier
On 9/27/26 08:51, Philippe Mathieu-Daudé wrote:
> On 27/9/26 10:58, Richard Henderson wrote:
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>> include/qemu/compiler.h | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
>> index 3661dc5fbaa..8fa4552ef8f 100644
>> --- a/include/qemu/compiler.h
>> +++ b/include/qemu/compiler.h
>> @@ -230,6 +230,13 @@
>> # define QEMU_UNINITIALIZED
>> #endif
>> +/*
>> + * Alias the current function definition to another.
>> + */
>> +
>> +#define QEMU_ALIAS(N) \
>> + __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__, N)))))
>> +
>> /*
>> * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
>> *
>
> On macOS:
>
> ../../tcg/tcg-op.c:1820:38: error: aliases are not supported on darwin
> 1820 | void tcg_gen_discard_ptr(TCGv_ptr a)
> QEMU_ALIAS(tcg_gen_discard_i64);
> | ^
> include/qemu/compiler.h:238:20: note: expanded from macro 'QEMU_ALIAS'
> 238 | __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__,
> N)))))
> | ^
>
Bah. Ok.
r~
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS
2026-09-27 22:35 ` Richard Henderson
@ 2026-09-28 16:23 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 16:23 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88, Pierrick Bouvier
On 28/9/26 00:35, Richard Henderson wrote:
> On 9/27/26 08:51, Philippe Mathieu-Daudé wrote:
>> On 27/9/26 10:58, Richard Henderson wrote:
>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>> include/qemu/compiler.h | 7 +++++++
>>> 1 file changed, 7 insertions(+)
>>>
>>> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
>>> index 3661dc5fbaa..8fa4552ef8f 100644
>>> --- a/include/qemu/compiler.h
>>> +++ b/include/qemu/compiler.h
>>> @@ -230,6 +230,13 @@
>>> # define QEMU_UNINITIALIZED
>>> #endif
>>> +/*
>>> + * Alias the current function definition to another.
>>> + */
>>> +
>>> +#define QEMU_ALIAS(N) \
>>> + __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__, N)))))
>>> +
>>> /*
>>> * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
>>> *
>>
>> On macOS:
>>
>> ../../tcg/tcg-op.c:1820:38: error: aliases are not supported on darwin
>> 1820 | void tcg_gen_discard_ptr(TCGv_ptr a)
>> QEMU_ALIAS(tcg_gen_discard_i64);
>> | ^
>> include/qemu/compiler.h:238:20: note: expanded from macro 'QEMU_ALIAS'
>> 238 |
>> __attribute__((alias(stringify(glue(__USER_LABEL_PREFIX__, N)))))
>> | ^
>>
>
> Bah. Ok.
Otherwise for QEMU_ALIAS idea:
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 003/101] tcg: Annontate functions in tcg.h with QEMU_*_NONNULL
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
2026-09-27 8:58 ` [PATCH v5 001/101] include/qemu/compiler: Add QEMU_*_NONNULL attributes Richard Henderson
2026-09-27 8:58 ` [PATCH v5 002/101] include/qemu/compiler: Define QEMU_ALIAS Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 14:52 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 004/101] tcg: Annontate functions in tcg-op-mem.h " Richard Henderson
` (97 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg.h | 58 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 46 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 7669dc1c2db..16ac528340a 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -478,9 +478,10 @@ static inline TCGTemp *arg_temp(TCGArg a)
}
#ifdef CONFIG_DEBUG_TCG
-size_t temp_idx(TCGTemp *ts);
-TCGTemp *tcgv_i32_temp(TCGv_i32 v);
+QEMU_ARG_NONNULL size_t temp_idx(TCGTemp *ts);
+QEMU_RET_ARG_NONNULL TCGTemp *tcgv_i32_temp(TCGv_i32 v);
#else
+QEMU_ARG_NONNULL
static inline size_t temp_idx(TCGTemp *ts)
{
return ts - tcg_ctx->temps;
@@ -491,104 +492,124 @@ static inline size_t temp_idx(TCGTemp *ts)
* its index means that we don't use 0. That leaves offset 0 free for
* a NULL representation without having to leave index 0 unused.
*/
+QEMU_RET_ARG_NONNULL
static inline TCGTemp *tcgv_i32_temp(TCGv_i32 v)
{
return (void *)tcg_ctx + (uintptr_t)v;
}
#endif
+QEMU_RET_ARG_NONNULL
static inline TCGTemp *tcgv_i64_temp(TCGv_i64 v)
{
return tcgv_i32_temp((TCGv_i32)v);
}
+QEMU_RET_ARG_NONNULL
static inline TCGTemp *tcgv_i128_temp(TCGv_i128 v)
{
return tcgv_i32_temp((TCGv_i32)v);
}
+QEMU_RET_ARG_NONNULL
static inline TCGTemp *tcgv_ptr_temp(TCGv_ptr v)
{
return tcgv_i32_temp((TCGv_i32)v);
}
+QEMU_RET_ARG_NONNULL
static inline TCGTemp *tcgv_vec_temp(TCGv_vec v)
{
return tcgv_i32_temp((TCGv_i32)v);
}
+QEMU_ARG_NONNULL
static inline TCGArg tcgv_i32_arg(TCGv_i32 v)
{
return temp_arg(tcgv_i32_temp(v));
}
+QEMU_ARG_NONNULL
static inline TCGArg tcgv_i64_arg(TCGv_i64 v)
{
return temp_arg(tcgv_i64_temp(v));
}
+QEMU_ARG_NONNULL
static inline TCGArg tcgv_i128_arg(TCGv_i128 v)
{
return temp_arg(tcgv_i128_temp(v));
}
+QEMU_ARG_NONNULL
static inline TCGArg tcgv_ptr_arg(TCGv_ptr v)
{
return temp_arg(tcgv_ptr_temp(v));
}
+QEMU_ARG_NONNULL
static inline TCGArg tcgv_vec_arg(TCGv_vec v)
{
return temp_arg(tcgv_vec_temp(v));
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_i32 temp_tcgv_i32(TCGTemp *t)
{
(void)temp_idx(t); /* trigger embedded assert */
return (TCGv_i32)((void *)t - (void *)tcg_ctx);
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_i64 temp_tcgv_i64(TCGTemp *t)
{
return (TCGv_i64)temp_tcgv_i32(t);
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_i128 temp_tcgv_i128(TCGTemp *t)
{
return (TCGv_i128)temp_tcgv_i32(t);
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_ptr temp_tcgv_ptr(TCGTemp *t)
{
return (TCGv_ptr)temp_tcgv_i32(t);
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_vaddr temp_tcgv_vaddr(TCGTemp *t)
{
return (TCGv_vaddr)temp_tcgv_i32(t);
}
+QEMU_RET_ARG_NONNULL
static inline TCGv_vec temp_tcgv_vec(TCGTemp *t)
{
return (TCGv_vec)temp_tcgv_i32(t);
}
+QEMU_ARG_NONNULL
static inline TCGArg tcg_get_insn_param(TCGOp *op, unsigned arg)
{
return op->args[arg];
}
+QEMU_ARG_NONNULL
static inline void tcg_set_insn_param(TCGOp *op, unsigned arg, TCGArg v)
{
op->args[arg] = v;
}
+QEMU_ARG_NONNULL
static inline uint64_t tcg_get_insn_start_param(TCGOp *op, unsigned arg)
{
tcg_debug_assert(arg < INSN_START_WORDS);
return tcg_get_insn_param(op, arg);
}
+QEMU_ARG_NONNULL
static inline void tcg_set_insn_start_param(TCGOp *op, unsigned arg, uint64_t v)
{
tcg_debug_assert(arg < INSN_START_WORDS);
@@ -617,9 +638,9 @@ static inline bool tcg_op_buf_full(void)
/* pool based memory allocation */
/* user-mode: mmap_lock must be held for tcg_malloc_internal. */
-void *tcg_malloc_internal(TCGContext *s, int size);
-void tcg_pool_reset(TCGContext *s);
-TranslationBlock *tcg_tb_alloc(TCGContext *s);
+QEMU_RET_ARG_NONNULL void *tcg_malloc_internal(TCGContext *s, int size);
+QEMU_ARG_NONNULL void tcg_pool_reset(TCGContext *s);
+QEMU_ARG_NONNULL TranslationBlock *tcg_tb_alloc(TCGContext *s);
void tcg_region_reset_all(void);
@@ -632,7 +653,7 @@ size_t tcg_code_capacity(void);
*
* Insert @tb into the region trees.
*/
-void tcg_tb_insert(TranslationBlock *tb);
+QEMU_ARG_NONNULL void tcg_tb_insert(TranslationBlock *tb);
/**
* tcg_tb_remove:
@@ -640,7 +661,7 @@ void tcg_tb_insert(TranslationBlock *tb);
*
* Remove @tb from the region trees.
*/
-void tcg_tb_remove(TranslationBlock *tb);
+QEMU_ARG_NONNULL void tcg_tb_remove(TranslationBlock *tb);
/**
* tcg_tb_lookup:
@@ -674,6 +695,7 @@ void tcg_tb_foreach(GTraverseFunc func, gpointer user_data);
size_t tcg_nb_tbs(void);
/* user-mode: Called with mmap_lock held. */
+QEMU_RET_NONNULL
static inline void *tcg_malloc(int size)
{
TCGContext *s = tcg_ctx;
@@ -692,8 +714,10 @@ static inline void *tcg_malloc(int size)
}
}
+QEMU_ARG_NONNULL
void tcg_func_start(TCGContext *s);
+QEMU_ARG_NONNULL
int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start);
void tb_target_set_jmp_target(const TranslationBlock *, int,
@@ -783,7 +807,10 @@ void tcg_gen_call7(void *func, TCGHelperInfo *, TCGTemp *ret,
TCGTemp *, TCGTemp *, TCGTemp *, TCGTemp *,
TCGTemp *, TCGTemp *, TCGTemp *);
+QEMU_RET_NONNULL
TCGOp *tcg_emit_op(TCGOpcode opc, unsigned nargs);
+
+QEMU_ARG_NONNULL
void tcg_op_remove(TCGContext *s, TCGOp *op);
/**
@@ -794,10 +821,13 @@ void tcg_op_remove(TCGContext *s, TCGOp *op);
* a starting point with tcg_last_op(), speculatively emit opcodes,
* then decide whether or not to keep those opcodes after the fact.
*/
+QEMU_ARG_NONNULL
void tcg_remove_ops_after(TCGOp *op);
+QEMU_ARG_NONNULL
void tcg_optimize(TCGContext *s);
+QEMU_RET_NONNULL
TCGLabel *gen_new_label(void);
/**
@@ -806,7 +836,7 @@ TCGLabel *gen_new_label(void);
*
* Encode a label for storage in the TCG opcode stream.
*/
-
+QEMU_ARG_NONNULL
static inline TCGArg label_arg(TCGLabel *l)
{
return (uintptr_t)l;
@@ -837,7 +867,7 @@ static inline TCGLabel *arg_label(TCGArg i)
* This version relies on GCC's void pointer arithmetic to get the
* correct result.
*/
-
+QEMU_ARG_NONNULL
static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
{
return a - b;
@@ -851,7 +881,7 @@ static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
* Produce a pc-relative difference, from the current code_ptr
* to the destination address.
*/
-
+QEMU_ARG_NONNULL
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
{
return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_ptr));
@@ -865,6 +895,7 @@ static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
* Produce a difference, from the beginning of the current TB code
* to the destination address.
*/
+QEMU_ARG_NONNULL
static inline ptrdiff_t tcg_tbrel_diff(TCGContext *s, const void *target)
{
return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_buf));
@@ -877,7 +908,7 @@ static inline ptrdiff_t tcg_tbrel_diff(TCGContext *s, const void *target)
* Compute the current code size within the translation block.
* This is used to fill in qemu's data structures for goto_tb.
*/
-
+QEMU_ARG_NONNULL
static inline size_t tcg_current_code_size(TCGContext *s)
{
return tcg_ptr_byte_diff(s->code_ptr, s->code_buf);
@@ -935,12 +966,15 @@ static inline size_t tcg_current_code_size(TCGContext *s)
#define TB_EXIT_REQUESTED 3
#ifdef CONFIG_TCG_INTERPRETER
+QEMU_ARG_NONNULL
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
-typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
+typedef QEMU_ARG_NONNULL uintptr_t
+ tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
extern tcg_prologue_fn *tcg_qemu_tb_exec;
#endif
+QEMU_ARG_NONNULL
void tcg_register_jit(const void *buf, size_t buf_size);
/* Return zero if the tuple (opc, type, vece) is unsupportable;
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 004/101] tcg: Annontate functions in tcg-op-mem.h with QEMU_*_NONNULL
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (2 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 003/101] tcg: Annontate functions in tcg.h with QEMU_*_NONNULL Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 14:50 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 005/101] tcg: Annontate functions in tcg-internal.h " Richard Henderson
` (96 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-mem.h | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
index ea35a02fb40..29e7c02f256 100644
--- a/include/tcg/tcg-op-mem.h
+++ b/include/tcg/tcg-op-mem.h
@@ -28,50 +28,50 @@ typedef TCGv_i64 TCGv_va;
#error
#endif
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_st_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_ld_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_st_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_ld_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
-static inline void
+QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
{
tcg_gen_qemu_st_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
#define DEF_ATOMIC2(N, S) \
- static inline void N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S v, \
- TCGArg i, MemOp m) \
+ QEMU_ARG_NONNULL static inline void \
+ N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S v, TCGArg i, MemOp m) \
{ N##_##S##_chk(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
#define DEF_ATOMIC3(N, S) \
- static inline void N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S o, \
- TCGv_##S n, TCGArg i, MemOp m) \
+ QEMU_ARG_NONNULL static inline void \
+ N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S o, TCGv_##S n, TCGArg i, MemOp m) \
{ N##_##S##_chk(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i32)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 005/101] tcg: Annontate functions in tcg-internal.h with QEMU_*_NONNULL
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (3 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 004/101] tcg: Annontate functions in tcg-op-mem.h " Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 14:50 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 006/101] tcg: Use QEMU_ALIAS to define most tcg_gen_*_ptr Richard Henderson
` (95 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-internal.h | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index e35440dc8c0..2620c23b448 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -41,53 +41,55 @@ extern unsigned int tcg_max_ctxs;
#endif
void tcg_region_init(size_t tb_size, int splitwx, unsigned max_threads);
-bool tcg_region_alloc(TCGContext *s);
-void tcg_region_thread_initial_alloc(TCGContext *s);
-void tcg_region_prologue_set(TCGContext *s);
+QEMU_ARG_NONNULL bool tcg_region_alloc(TCGContext *s);
+QEMU_ARG_NONNULL void tcg_region_thread_initial_alloc(TCGContext *s);
+QEMU_ARG_NONNULL void tcg_region_prologue_set(TCGContext *s);
-static inline void *tcg_call_func(TCGOp *op)
+QEMU_RET_ARG_NONNULL static inline void *tcg_call_func(TCGOp *op)
{
return (void *)(uintptr_t)op->args[TCGOP_CALLO(op) + TCGOP_CALLI(op)];
}
-static inline const TCGHelperInfo *tcg_call_info(TCGOp *op)
+QEMU_RET_ARG_NONNULL static inline const TCGHelperInfo *tcg_call_info(TCGOp *op)
{
return (void *)(uintptr_t)op->args[TCGOP_CALLO(op) + TCGOP_CALLI(op) + 1];
}
-static inline unsigned tcg_call_flags(TCGOp *op)
+QEMU_ARG_NONNULL static inline unsigned tcg_call_flags(TCGOp *op)
{
return tcg_call_info(op)->flags;
}
-static inline TCGv_i64 TCGV128_LOW(TCGv_i128 t)
+QEMU_RET_ARG_NONNULL static inline TCGv_i64 TCGV128_LOW(TCGv_i128 t)
{
return temp_tcgv_i64(tcgv_i128_temp(t) + HOST_BIG_ENDIAN);
}
-static inline TCGv_i64 TCGV128_HIGH(TCGv_i128 t)
+QEMU_RET_ARG_NONNULL static inline TCGv_i64 TCGV128_HIGH(TCGv_i128 t)
{
return temp_tcgv_i64(tcgv_i128_temp(t) + !HOST_BIG_ENDIAN);
}
bool tcg_target_has_memory_bswap(MemOp memop);
-TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind);
+QEMU_RET_NONNULL TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind);
/*
* Locate or create a read-only temporary that is a constant.
* This kind of temporary need not be freed, but for convenience
* will be silently ignored by tcg_temp_free_*.
*/
-TCGTemp *tcg_constant_internal(TCGType type, int64_t val);
+QEMU_RET_NONNULL TCGTemp *tcg_constant_internal(TCGType type, int64_t val);
-TCGOp *tcg_gen_op1(TCGOpcode, TCGType, TCGArg);
-TCGOp *tcg_gen_op2(TCGOpcode, TCGType, TCGArg, TCGArg);
-TCGOp *tcg_gen_op3(TCGOpcode, TCGType, TCGArg, TCGArg, TCGArg);
-TCGOp *tcg_gen_op4(TCGOpcode, TCGType, TCGArg, TCGArg, TCGArg, TCGArg);
-TCGOp *tcg_gen_op5(TCGOpcode, TCGType, TCGArg, TCGArg, TCGArg, TCGArg, TCGArg);
-TCGOp *tcg_gen_op6(TCGOpcode, TCGType, TCGArg, TCGArg,
- TCGArg, TCGArg, TCGArg, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op1(TCGOpcode, TCGType, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op2(TCGOpcode, TCGType, TCGArg, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op3(TCGOpcode, TCGType, TCGArg, TCGArg, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op4(TCGOpcode, TCGType, TCGArg, TCGArg,
+ TCGArg, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op5(TCGOpcode, TCGType, TCGArg, TCGArg,
+ TCGArg, TCGArg, TCGArg);
+QEMU_RET_NONNULL TCGOp *tcg_gen_op6(TCGOpcode, TCGType, TCGArg, TCGArg,
+ TCGArg, TCGArg, TCGArg, TCGArg);
void vec_gen_2(TCGOpcode, TCGType, unsigned, TCGArg, TCGArg);
void vec_gen_3(TCGOpcode, TCGType, unsigned, TCGArg, TCGArg, TCGArg);
@@ -95,8 +97,10 @@ void vec_gen_4(TCGOpcode, TCGType, unsigned, TCGArg, TCGArg, TCGArg, TCGArg);
void vec_gen_6(TCGOpcode opc, TCGType type, unsigned vece, TCGArg r,
TCGArg a, TCGArg b, TCGArg c, TCGArg d, TCGArg e);
+QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
+QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 006/101] tcg: Use QEMU_ALIAS to define most tcg_gen_*_ptr
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (4 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 005/101] tcg: Annontate functions in tcg-internal.h " Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-29 12:41 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 007/101] tcg: Use QEMU_*_NONULL with all tcg_gen_*_ptr Richard Henderson
` (94 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Now that we've dropped 32-bit host support, TCGv_ptr
is always TCGv_i64. Do not drop the type difference,
as that's still helpful conceptually, but define the
functions as aliases, exactly sharing code.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 99 +++++--------------------------------
tcg/tcg-op.c | 18 +++++++
2 files changed, 31 insertions(+), 86 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 9b321f959c0..1e826b62574 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -497,95 +497,22 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t);
/* Host pointer ops */
-#if UINTPTR_MAX == UINT32_MAX
-# define PTR i32
-# define NAT TCGv_i32
-#else
-# define PTR i64
-# define NAT TCGv_i64
-#endif
-
TCGv_ptr tcg_constant_ptr_int(intptr_t x);
#define tcg_constant_ptr(X) tcg_constant_ptr_int((intptr_t)(X))
-static inline void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o)
-{
- glue(tcg_gen_ld_,PTR)((NAT)r, a, o);
-}
+void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
+void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
-static inline void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o)
-{
- glue(tcg_gen_st_, PTR)((NAT)r, a, o);
-}
-
-static inline void tcg_gen_discard_ptr(TCGv_ptr a)
-{
- glue(tcg_gen_discard_,PTR)((NAT)a);
-}
-
-static inline void tcg_gen_add_ptr(TCGv_ptr r, TCGv_ptr a, TCGv_ptr b)
-{
- glue(tcg_gen_add_,PTR)((NAT)r, (NAT)a, (NAT)b);
-}
-
-static inline void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b)
-{
- glue(tcg_gen_addi_,PTR)((NAT)r, (NAT)a, b);
-}
-
-static inline void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s)
-{
- glue(tcg_gen_mov_,PTR)((NAT)d, (NAT)s);
-}
-
-static inline void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s)
-{
- glue(tcg_gen_movi_,PTR)((NAT)d, s);
-}
-
-static inline void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a,
- intptr_t b, TCGLabel *label)
-{
- glue(tcg_gen_brcondi_,PTR)(cond, (NAT)a, b, label);
-}
-
-static inline void tcg_gen_ext_i32_ptr(TCGv_ptr r, TCGv_i32 a)
-{
-#if UINTPTR_MAX == UINT32_MAX
- tcg_gen_mov_i32((NAT)r, a);
-#else
- tcg_gen_ext_i32_i64((NAT)r, a);
-#endif
-}
-
-static inline void tcg_gen_trunc_i64_ptr(TCGv_ptr r, TCGv_i64 a)
-{
-#if UINTPTR_MAX == UINT32_MAX
- tcg_gen_extrl_i64_i32((NAT)r, a);
-#else
- tcg_gen_mov_i64((NAT)r, a);
-#endif
-}
-
-static inline void tcg_gen_extu_ptr_i64(TCGv_i64 r, TCGv_ptr a)
-{
-#if UINTPTR_MAX == UINT32_MAX
- tcg_gen_extu_i32_i64(r, (NAT)a);
-#else
- tcg_gen_mov_i64(r, (NAT)a);
-#endif
-}
-
-static inline void tcg_gen_trunc_ptr_i32(TCGv_i32 r, TCGv_ptr a)
-{
-#if UINTPTR_MAX == UINT32_MAX
- tcg_gen_mov_i32(r, (NAT)a);
-#else
- tcg_gen_extrl_i64_i32(r, (NAT)a);
-#endif
-}
-
-#undef PTR
-#undef NAT
+void tcg_gen_discard_ptr(TCGv_ptr a);
+void tcg_gen_add_ptr(TCGv_ptr r, TCGv_ptr a, TCGv_ptr b);
+void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b);
+void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s);
+void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s);
+void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a,
+ intptr_t b, TCGLabel *label);
+void tcg_gen_ext_i32_ptr(TCGv_ptr r, TCGv_i32 a);
+void tcg_gen_trunc_i64_ptr(TCGv_ptr r, TCGv_i64 a);
+void tcg_gen_extu_ptr_i64(TCGv_i64 r, TCGv_ptr a);
+void tcg_gen_trunc_ptr_i32(TCGv_i32 r, TCGv_ptr a);
#endif /* TCG_TCG_OP_COMMON_H */
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2c88f4f7ca9..b738863ea69 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -2730,3 +2730,21 @@ void tcg_gen_lookup_and_goto_ptr(void)
tcg_gen_op1i(INDEX_op_goto_ptr, TCG_TYPE_PTR, tcgv_ptr_arg(ptr));
tcg_temp_free_ptr(ptr);
}
+
+/*
+ * We only support 64-bit hosts, so TCGv_ptr always resolves to TCGv_i64.
+ */
+
+void tcg_gen_discard_ptr(TCGv_ptr a) QEMU_ALIAS(tcg_gen_discard_i64);
+void tcg_gen_add_ptr(TCGv_ptr r, TCGv_ptr a, TCGv_ptr b) QEMU_ALIAS(tcg_gen_add_i64);
+void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b) QEMU_ALIAS(tcg_gen_addi_i64);
+void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s) QEMU_ALIAS(tcg_gen_mov_i64);
+void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s) QEMU_ALIAS(tcg_gen_movi_i64);
+void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a, intptr_t b, TCGLabel *label)
+ QEMU_ALIAS(tcg_gen_brcondi_i64);
+void tcg_gen_ext_i32_ptr(TCGv_ptr r, TCGv_i32 a) QEMU_ALIAS(tcg_gen_ext_i32_i64);
+void tcg_gen_trunc_i64_ptr(TCGv_ptr r, TCGv_i64 a) QEMU_ALIAS(tcg_gen_mov_i64);
+void tcg_gen_extu_ptr_i64(TCGv_i64 r, TCGv_ptr a) QEMU_ALIAS(tcg_gen_mov_i64);
+void tcg_gen_trunc_ptr_i32(TCGv_i32 r, TCGv_ptr a) QEMU_ALIAS(tcg_gen_extrl_i64_i32);
+void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o) QEMU_ALIAS(tcg_gen_ld_i64);
+void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o) QEMU_ALIAS(tcg_gen_st_i64);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 006/101] tcg: Use QEMU_ALIAS to define most tcg_gen_*_ptr
2026-09-27 8:58 ` [PATCH v5 006/101] tcg: Use QEMU_ALIAS to define most tcg_gen_*_ptr Richard Henderson
@ 2026-09-29 12:41 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:41 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Now that we've dropped 32-bit host support, TCGv_ptr
> is always TCGv_i64. Do not drop the type difference,
> as that's still helpful conceptually, but define the
> functions as aliases, exactly sharing code.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 99 +++++--------------------------------
> tcg/tcg-op.c | 18 +++++++
> 2 files changed, 31 insertions(+), 86 deletions(-)
Assuming all the toolchains we use understand QEMU_ALIAS():
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 007/101] tcg: Use QEMU_*_NONULL with all tcg_gen_*_ptr
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (5 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 006/101] tcg: Use QEMU_ALIAS to define most tcg_gen_*_ptr Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 14:53 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 008/101] tcg: Prepare for easy temp lifetimes Richard Henderson
` (93 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1e826b62574..888f00d5f24 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -497,22 +497,22 @@ void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t);
/* Host pointer ops */
-TCGv_ptr tcg_constant_ptr_int(intptr_t x);
+QEMU_RET_NONNULL TCGv_ptr tcg_constant_ptr_int(intptr_t x);
#define tcg_constant_ptr(X) tcg_constant_ptr_int((intptr_t)(X))
-void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
-void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
+QEMU_ARG_NONNULL void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
+QEMU_ARG_NONNULL void tcg_gen_st_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o);
-void tcg_gen_discard_ptr(TCGv_ptr a);
-void tcg_gen_add_ptr(TCGv_ptr r, TCGv_ptr a, TCGv_ptr b);
-void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b);
-void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s);
-void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s);
-void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a,
- intptr_t b, TCGLabel *label);
-void tcg_gen_ext_i32_ptr(TCGv_ptr r, TCGv_i32 a);
-void tcg_gen_trunc_i64_ptr(TCGv_ptr r, TCGv_i64 a);
-void tcg_gen_extu_ptr_i64(TCGv_i64 r, TCGv_ptr a);
-void tcg_gen_trunc_ptr_i32(TCGv_i32 r, TCGv_ptr a);
+QEMU_ARG_NONNULL void tcg_gen_discard_ptr(TCGv_ptr a);
+QEMU_ARG_NONNULL void tcg_gen_add_ptr(TCGv_ptr r, TCGv_ptr a, TCGv_ptr b);
+QEMU_ARG_NONNULL void tcg_gen_addi_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t b);
+QEMU_ARG_NONNULL void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s);
+QEMU_ARG_NONNULL void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s);
+QEMU_ARG_NONNULL void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a,
+ intptr_t b, TCGLabel *label);
+QEMU_ARG_NONNULL void tcg_gen_ext_i32_ptr(TCGv_ptr r, TCGv_i32 a);
+QEMU_ARG_NONNULL void tcg_gen_trunc_i64_ptr(TCGv_ptr r, TCGv_i64 a);
+QEMU_ARG_NONNULL void tcg_gen_extu_ptr_i64(TCGv_i64 r, TCGv_ptr a);
+QEMU_ARG_NONNULL void tcg_gen_trunc_ptr_i32(TCGv_i32 r, TCGv_ptr a);
#endif /* TCG_TCG_OP_COMMON_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 008/101] tcg: Prepare for easy temp lifetimes
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (6 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 007/101] tcg: Use QEMU_*_NONULL with all tcg_gen_*_ptr Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:14 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_* Richard Henderson
` (92 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-temp-internal.h | 2 ++
tcg/tcg-internal.h | 5 +++++
tcg/tcg.c | 4 ++++
3 files changed, 11 insertions(+)
diff --git a/include/tcg/tcg-temp-internal.h b/include/tcg/tcg-temp-internal.h
index 98f91e68b70..932ad1aeebe 100644
--- a/include/tcg/tcg-temp-internal.h
+++ b/include/tcg/tcg-temp-internal.h
@@ -31,6 +31,8 @@
void tcg_temp_free_internal(TCGTemp *);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(TCGTemp, tcg_temp_free_internal)
+
void tcg_temp_free_i32(TCGv_i32 arg);
void tcg_temp_free_i64(TCGv_i64 arg);
void tcg_temp_free_i128(TCGv_i128 arg);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 2620c23b448..d480d10878c 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -74,6 +74,11 @@ bool tcg_target_has_memory_bswap(MemOp memop);
QEMU_RET_NONNULL TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind);
+static inline TCGTemp *tcg_temp_new_ebb(TCGType type)
+{
+ return tcg_temp_new_internal(type, TEMP_EBB);
+}
+
/*
* Locate or create a read-only temporary that is a constant.
* This kind of temporary need not be freed, but for convenience
diff --git a/tcg/tcg.c b/tcg/tcg.c
index ecc1f54c1bf..9f2f929e273 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -2201,6 +2201,10 @@ void tcg_temp_free_internal(TCGTemp *ts)
{
TCGContext *s = tcg_ctx;
+ if (ts == NULL) {
+ return;
+ }
+
switch (ts->kind) {
case TEMP_CONST:
case TEMP_TB:
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (7 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 008/101] tcg: Prepare for easy temp lifetimes Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-29 12:42 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_* Richard Henderson
` (91 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Begin sharing code in the expansion of operations
for various TCG types.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 29 +++++++++++++--
tcg/tcg-internal.h | 23 ++++++++++++
include/tcg/tcg-op-def.h.inc | 4 +++
tcg/tcg-op.c | 69 ++++++++++++++++++++++++++++--------
4 files changed, 109 insertions(+), 16 deletions(-)
create mode 100644 include/tcg/tcg-op-def.h.inc
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 888f00d5f24..eba3ad4f93c 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -88,6 +88,33 @@ void tcg_gen_lookup_and_goto_ptr(void);
void tcg_gen_plugin_cb(unsigned from);
void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
+/*
+ * Construct operations from templates.
+ */
+
+#define DEF2(NAME, T1, T2) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2);
+
+#define TCGV glue(TCGv,TExt)
+#define TExt _i32
+#define TINT int32_t
+
+#include "tcg-op-def.h.inc"
+
+#undef TExt
+#undef TINT
+
+#define TExt _i64
+#define TINT int64_t
+
+#include "tcg-op-def.h.inc"
+
+#undef TExt
+#undef TINT
+#undef TCGV
+
+#undef DEF2
+
/* 32 bit ops */
void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg);
@@ -172,7 +199,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
void tcg_gen_discard_i32(TCGv_i32 arg);
-void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
@@ -294,7 +320,6 @@ void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_discard_i64(TCGv_i64 arg);
-void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index d480d10878c..3568157ebb5 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -102,6 +102,12 @@ void vec_gen_4(TCGOpcode, TCGType, unsigned, TCGArg, TCGArg, TCGArg, TCGArg);
void vec_gen_6(TCGOpcode opc, TCGType type, unsigned vece, TCGArg r,
TCGArg a, TCGArg b, TCGArg c, TCGArg d, TCGArg e);
+static inline void tcg_gen_op_tt(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1)
+{
+ tcg_gen_op2(opc, type, temp_arg(t0), temp_arg(t1));
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
@@ -114,4 +120,21 @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op,
*/
bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
+/*
+ * Declarations of templated TCGv_i32 and TCGv_i64 operations.
+ */
+
+#define DEF2(NAME, T1, T2) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2);
+
+#define TCGV TCGTemp *
+#define TINT int64_t
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TINT
+#undef TCGV
+
+#undef DEF2
+
#endif /* TCG_INTERNAL_H */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
new file mode 100644
index 00000000000..c76e83396ae
--- /dev/null
+++ b/include/tcg/tcg-op-def.h.inc
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: MIT */
+/* Templated TCGv_i32 and TCGv_i64 operations */
+
+DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index b738863ea69..77ed34fcb8f 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -315,6 +315,61 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
tcg_gen_op2(INDEX_op_plugin_mem_cb, 0, tcgv_i64_arg(addr), meminfo);
}
+/*
+ * Templated TCGv_i32 and TCGv_i64 operations.
+ */
+
+#define DEF2(NAME, T1, T2) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b)); }
+
+#define C_TCGv_i32 tcgv_i32_temp
+#define C_TCGv_i64 tcgv_i64_temp
+#define C_int32_t
+#define C_int64_t
+
+#define TCGV glue(TCGv,TExt)
+#define TExt _i32
+#define TINT int32_t
+#define TYPE TCG_TYPE_I32
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TExt
+#undef TINT
+#undef TYPE
+
+#define TExt _i64
+#define TINT int64_t
+#define TYPE TCG_TYPE_I64
+
+#include "tcg/tcg-op-def.h.inc"
+
+#undef TExt
+#undef TINT
+#undef TCGV
+#undef TYPE
+
+#undef C_TCGv_i32
+#undef C_TCGv_i64
+#undef C_int32_t
+#undef C_int64_t
+
+#undef DEF2
+
+/*
+ * Generic expansions for templated operations.
+ * We have used compiler type checks to ensure all TCGTemp
+ * are of the proper type.
+ */
+
+void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ if (src != dst) {
+ tcg_gen_op_tt(INDEX_op_mov, type, dst, src);
+ }
+}
+
/* 32 bit ops */
void tcg_gen_discard_i32(TCGv_i32 arg)
@@ -322,13 +377,6 @@ void tcg_gen_discard_i32(TCGv_i32 arg)
tcg_gen_op1_i32(INDEX_op_discard, TCG_TYPE_I32, arg);
}
-void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- if (ret != arg) {
- tcg_gen_op2_i32(INDEX_op_mov, ret, arg);
- }
-}
-
void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
{
tcg_gen_mov_i32(ret, tcg_constant_i32(arg));
@@ -1396,13 +1444,6 @@ void tcg_gen_discard_i64(TCGv_i64 arg)
tcg_gen_op1_i64(INDEX_op_discard, TCG_TYPE_I64, arg);
}
-void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- if (ret != arg) {
- tcg_gen_op2_i64(INDEX_op_mov, ret, arg);
- }
-}
-
void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
{
tcg_gen_mov_i64(ret, tcg_constant_i64(arg));
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_*
2026-09-27 8:58 ` [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_* Richard Henderson
@ 2026-09-29 12:42 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:42 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Begin sharing code in the expansion of operations
> for various TCG types.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 29 +++++++++++++--
> tcg/tcg-internal.h | 23 ++++++++++++
> include/tcg/tcg-op-def.h.inc | 4 +++
> tcg/tcg-op.c | 69 ++++++++++++++++++++++++++++--------
> 4 files changed, 109 insertions(+), 16 deletions(-)
> create mode 100644 include/tcg/tcg-op-def.h.inc
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (8 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:18 ` Philippe Mathieu-Daudé
2026-09-27 15:31 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 011/101] tcg: Generic expansion of tcg_gen_discard_* Richard Henderson
` (90 subsequent siblings)
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index eba3ad4f93c..55571653c7b 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -117,7 +117,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg);
void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -224,7 +223,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg);
void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index c76e83396ae..e55a9f99939 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -2,3 +2,4 @@
/* Templated TCGv_i32 and TCGv_i64 operations */
DEF2(mov, TCGV, TCGV)
+DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 77ed34fcb8f..b2fa509cd1f 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -370,6 +370,11 @@ void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
}
}
+void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
+{
+ tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
+}
+
/* 32 bit ops */
void tcg_gen_discard_i32(TCGv_i32 arg)
@@ -377,11 +382,6 @@ void tcg_gen_discard_i32(TCGv_i32 arg)
tcg_gen_op1_i32(INDEX_op_discard, TCG_TYPE_I32, arg);
}
-void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
-{
- tcg_gen_mov_i32(ret, tcg_constant_i32(arg));
-}
-
void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
tcg_gen_op3_i32(INDEX_op_add, ret, arg1, arg2);
@@ -1444,11 +1444,6 @@ void tcg_gen_discard_i64(TCGv_i64 arg)
tcg_gen_op1_i64(INDEX_op_discard, TCG_TYPE_I64, arg);
}
-void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
-{
- tcg_gen_mov_i64(ret, tcg_constant_i64(arg));
-}
-
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld8u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-27 8:58 ` [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_* Richard Henderson
@ 2026-09-27 15:18 ` Philippe Mathieu-Daudé
2026-09-27 15:31 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 15:18 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 15 +++++----------
> 3 files changed, 6 insertions(+), 12 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-27 8:58 ` [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_* Richard Henderson
2026-09-27 15:18 ` Philippe Mathieu-Daudé
@ 2026-09-27 15:31 ` Philippe Mathieu-Daudé
2026-09-27 17:57 ` Richard Henderson
1 sibling, 1 reply; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 15:31 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 15 +++++----------
> 3 files changed, 6 insertions(+), 12 deletions(-)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 77ed34fcb8f..b2fa509cd1f 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -370,6 +370,11 @@ void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
> }
> }
>
> +void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
Maybe this commit (the first converting opcode with an integer arg)
could have a description explaining / reminding now all args are
passed as int64_t.
> +{
> + tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
> +}
> +
> /* 32 bit ops */
>
> void tcg_gen_discard_i32(TCGv_i32 arg)
> @@ -377,11 +382,6 @@ void tcg_gen_discard_i32(TCGv_i32 arg)
> tcg_gen_op1_i32(INDEX_op_discard, TCG_TYPE_I32, arg);
> }
>
> -void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
> -{
> - tcg_gen_mov_i32(ret, tcg_constant_i32(arg));
> -}
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-27 15:31 ` Philippe Mathieu-Daudé
@ 2026-09-27 17:57 ` Richard Henderson
2026-09-29 12:45 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 17:57 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: mattst88
On 9/27/26 08:31, Philippe Mathieu-Daudé wrote:
> On 27/9/26 10:58, Richard Henderson wrote:
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>> include/tcg/tcg-op-common.h | 2 --
>> include/tcg/tcg-op-def.h.inc | 1 +
>> tcg/tcg-op.c | 15 +++++----------
>> 3 files changed, 6 insertions(+), 12 deletions(-)
>
>
>> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
>> index 77ed34fcb8f..b2fa509cd1f 100644
>> --- a/tcg/tcg-op.c
>> +++ b/tcg/tcg-op.c
>> @@ -370,6 +370,11 @@ void tcg_gen_mov(TCGType type, TCGTemp *dst,
>> TCGTemp *src)
>> }
>> }
>> +void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
>
> Maybe this commit (the first converting opcode with an integer arg)
> could have a description explaining / reminding now all args are
> passed as int64_t.
Where would you place such a comment that would be useful?
I can't see how or where.
r~
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-27 17:57 ` Richard Henderson
@ 2026-09-29 12:45 ` Philippe Mathieu-Daudé
2026-10-02 6:35 ` Richard Henderson
0 siblings, 1 reply; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:45 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 19:57, Richard Henderson wrote:
[*]
> On 9/27/26 08:31, Philippe Mathieu-Daudé wrote:
>> On 27/9/26 10:58, Richard Henderson wrote:
>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>> include/tcg/tcg-op-common.h | 2 --
>>> include/tcg/tcg-op-def.h.inc | 1 +
>>> tcg/tcg-op.c | 15 +++++----------
>>> 3 files changed, 6 insertions(+), 12 deletions(-)
>>
>>
>>> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
>>> index 77ed34fcb8f..b2fa509cd1f 100644
>>> --- a/tcg/tcg-op.c
>>> +++ b/tcg/tcg-op.c
>>> @@ -370,6 +370,11 @@ void tcg_gen_mov(TCGType type, TCGTemp *dst,
>>> TCGTemp *src)
>>> }
>>> }
>>> +void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
>>
>> Maybe this commit (the first converting opcode with an integer arg)
>> could have a description explaining / reminding now all args are
>> passed as int64_t.
> Where would you place such a comment that would be useful?
> I can't see how or where.
In the commit description? [*]. Smth in the lines of "We've dropped
32-bit host support; now all integer are passed as 64-bit arguments."
Anyway,
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_*
2026-09-29 12:45 ` Philippe Mathieu-Daudé
@ 2026-10-02 6:35 ` Richard Henderson
0 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-10-02 6:35 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: mattst88
On 9/29/26 14:45, Philippe Mathieu-Daudé wrote:
> On 27/9/26 19:57, Richard Henderson wrote:
>
> [*]
>
>> On 9/27/26 08:31, Philippe Mathieu-Daudé wrote:
>>> On 27/9/26 10:58, Richard Henderson wrote:
>>>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>>>> ---
>>>> include/tcg/tcg-op-common.h | 2 --
>>>> include/tcg/tcg-op-def.h.inc | 1 +
>>>> tcg/tcg-op.c | 15 +++++----------
>>>> 3 files changed, 6 insertions(+), 12 deletions(-)
>>>
>>>
>>>> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
>>>> index 77ed34fcb8f..b2fa509cd1f 100644
>>>> --- a/tcg/tcg-op.c
>>>> +++ b/tcg/tcg-op.c
>>>> @@ -370,6 +370,11 @@ void tcg_gen_mov(TCGType type, TCGTemp *dst,
>>>> TCGTemp *src)
>>>> }
>>>> }
>>>> +void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
>>>
>>> Maybe this commit (the first converting opcode with an integer arg)
>>> could have a description explaining / reminding now all args are
>>> passed as int64_t.
>> Where would you place such a comment that would be useful?
>> I can't see how or where.
> In the commit description? [*]. Smth in the lines of "We've dropped
> 32-bit host support; now all integer are passed as 64-bit arguments."
>
> Anyway,
So there's some confusion then.
The argument for tcg_gen_movi_i32 is still int32_t. The new internal
function uses the union of tcg_gen_movi_{i32,i64}.
So the comment you're suggesting is wrong -- there is no API change.
r~
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 011/101] tcg: Generic expansion of tcg_gen_discard_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (9 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 010/101] tcg: Generic expansion of tcg_gen_movi_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:20 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 012/101] tcg: Generic expansion of tcg_gen_add_* Richard Henderson
` (89 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 6 +++---
tcg/tcg-internal.h | 3 +++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
4 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 55571653c7b..1dce1c6809e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -92,6 +92,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
* Construct operations from templates.
*/
+#define DEF1(NAME, T1) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1);
#define DEF2(NAME, T1, T2) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2);
@@ -113,6 +115,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef TINT
#undef TCGV
+#undef DEF1
#undef DEF2
/* 32 bit ops */
@@ -197,8 +200,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-void tcg_gen_discard_i32(TCGv_i32 arg);
-
void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
@@ -317,7 +318,6 @@ void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_discard_i64(TCGv_i64 arg);
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 3568157ebb5..ed1f5f20f83 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -124,6 +124,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
* Declarations of templated TCGv_i32 and TCGv_i64 operations.
*/
+#define DEF1(NAME, T1) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1);
#define DEF2(NAME, T1, T2) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2);
@@ -135,6 +137,7 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef TINT
#undef TCGV
+#undef DEF1
#undef DEF2
#endif /* TCG_INTERNAL_H */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index e55a9f99939..8c61a75cd09 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: MIT */
/* Templated TCGv_i32 and TCGv_i64 operations */
+DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index b2fa509cd1f..046b10962fe 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -114,16 +114,6 @@ TCGOp * NI tcg_gen_op6(TCGOpcode opc, TCGType type, TCGArg a1, TCGArg a2,
# define DNI
#endif
-static void DNI tcg_gen_op1_i32(TCGOpcode opc, TCGType type, TCGv_i32 a1)
-{
- tcg_gen_op1(opc, type, tcgv_i32_arg(a1));
-}
-
-static void DNI tcg_gen_op1_i64(TCGOpcode opc, TCGType type, TCGv_i64 a1)
-{
- tcg_gen_op1(opc, type, tcgv_i64_arg(a1));
-}
-
static TCGOp * DNI tcg_gen_op1i(TCGOpcode opc, TCGType type, TCGArg a1)
{
return tcg_gen_op1(opc, type, a1);
@@ -319,6 +309,10 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
* Templated TCGv_i32 and TCGv_i64 operations.
*/
+#define DEF1(NAME, T1) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a)); }
+
#define DEF2(NAME, T1, T2) \
void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b) \
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b)); }
@@ -355,6 +349,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_int32_t
#undef C_int64_t
+#undef DEF1
#undef DEF2
/*
@@ -363,6 +358,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
* are of the proper type.
*/
+void tcg_gen_discard(TCGType type, TCGTemp *src)
+{
+ tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -377,11 +377,6 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
/* 32 bit ops */
-void tcg_gen_discard_i32(TCGv_i32 arg)
-{
- tcg_gen_op1_i32(INDEX_op_discard, TCG_TYPE_I32, arg);
-}
-
void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
tcg_gen_op3_i32(INDEX_op_add, ret, arg1, arg2);
@@ -1439,11 +1434,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
/* 64-bit ops */
-void tcg_gen_discard_i64(TCGv_i64 arg)
-{
- tcg_gen_op1_i64(INDEX_op_discard, TCG_TYPE_I64, arg);
-}
-
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld8u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 012/101] tcg: Generic expansion of tcg_gen_add_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (10 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 011/101] tcg: Generic expansion of tcg_gen_discard_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:20 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 013/101] tcg: Generic expansion of tcg_gen_addi_* Richard Henderson
` (88 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 5 +++--
tcg/tcg-internal.h | 9 +++++++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 20 ++++++++++----------
4 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1dce1c6809e..3d72d338277 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -96,6 +96,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1);
#define DEF2(NAME, T1, T2) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2);
+#define DEF3(NAME, T1, T2, T3) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3);
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -117,6 +119,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef DEF1
#undef DEF2
+#undef DEF3
/* 32 bit ops */
@@ -210,7 +213,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -315,7 +317,6 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index ed1f5f20f83..0da1a9c440c 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -108,6 +108,12 @@ static inline void tcg_gen_op_tt(TCGOpcode opc, TCGType type,
tcg_gen_op2(opc, type, temp_arg(t0), temp_arg(t1));
}
+static inline void tcg_gen_op_ttt(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1, TCGTemp *t2)
+{
+ tcg_gen_op3(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2));
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
@@ -128,6 +134,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1);
#define DEF2(NAME, T1, T2) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2);
+#define DEF3(NAME, T1, T2, T3) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3);
#define TCGV TCGTemp *
#define TINT int64_t
@@ -139,5 +147,6 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF1
#undef DEF2
+#undef DEF3
#endif /* TCG_INTERNAL_H */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 8c61a75cd09..73b1ec3d057 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: MIT */
/* Templated TCGv_i32 and TCGv_i64 operations */
+DEF3(add, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 046b10962fe..a17a9db8203 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -317,6 +317,10 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b) \
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b)); }
+#define DEF3(NAME, T1, T2, T3) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), glue(C_,T3)(c)); }
+
#define C_TCGv_i32 tcgv_i32_temp
#define C_TCGv_i64 tcgv_i64_temp
#define C_int32_t
@@ -351,6 +355,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef DEF1
#undef DEF2
+#undef DEF3
/*
* Generic expansions for templated operations.
@@ -358,6 +363,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
* are of the proper type.
*/
+void tcg_gen_add(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_add, type, dst, src1, src2);
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -377,11 +387,6 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
/* 32 bit ops */
-void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_add, ret, arg1, arg2);
-}
-
void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* some cases can be optimized here */
@@ -1489,11 +1494,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_add, ret, arg1, arg2);
-}
-
void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_sub, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 013/101] tcg: Generic expansion of tcg_gen_addi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (11 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 012/101] tcg: Generic expansion of tcg_gen_add_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:21 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 014/101] tcg: Generic expansion of tcg_gen_sub_* Richard Henderson
` (87 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 29 +++++++++--------------------
3 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 3d72d338277..db1405f9ebe 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -226,7 +225,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 73b1ec3d057..faa83a09b2a 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -2,6 +2,7 @@
/* Templated TCGv_i32 and TCGv_i64 operations */
DEF3(add, TCGV, TCGV, TCGV)
+DEF3(addi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a17a9db8203..17fcc889906 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -368,6 +368,15 @@ void tcg_gen_add(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_add, type, dst, src1, src2);
}
+void tcg_gen_addi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ tcg_gen_add(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -387,16 +396,6 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
/* 32 bit ops */
-void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- /* some cases can be optimized here */
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else {
- tcg_gen_add_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
tcg_gen_op3_i32(INDEX_op_sub, ret, arg1, arg2);
@@ -1534,16 +1533,6 @@ void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op3_i64(INDEX_op_mul, ret, arg1, arg2);
}
-void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- /* some cases can be optimized here */
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else {
- tcg_gen_add_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
{
if (arg1 == 0) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 014/101] tcg: Generic expansion of tcg_gen_sub_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (12 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 013/101] tcg: Generic expansion of tcg_gen_addi_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:22 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_* Richard Henderson
` (86 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 3 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 13 ++++---------
3 files changed, 5 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index db1405f9ebe..8444044ed57 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -212,7 +212,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -315,8 +314,6 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
-
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index faa83a09b2a..51d5ec6e06a 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -6,3 +6,4 @@ DEF3(addi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
+DEF3(sub, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 17fcc889906..2865de65d39 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -394,13 +394,13 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
}
-/* 32 bit ops */
-
-void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
+void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
- tcg_gen_op3_i32(INDEX_op_sub, ret, arg1, arg2);
+ tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
}
+/* 32 bit ops */
+
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
{
if (arg1 == 0) {
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_sub, ret, arg1, arg2);
-}
-
void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_and, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (13 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 014/101] tcg: Generic expansion of tcg_gen_sub_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:31 ` Philippe Mathieu-Daudé
2026-09-29 21:53 ` Matt Turner
2026-09-27 8:58 ` [PATCH v5 016/101] tcg: Generic expansion of tcg_gen_neg_* Richard Henderson
` (85 subsequent siblings)
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 8444044ed57..ff15e3b88ae 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -124,7 +124,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
-void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -225,7 +224,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
-void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 51d5ec6e06a..55249c4dd6f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -7,3 +7,4 @@ DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(sub, TCGV, TCGV, TCGV)
+DEF3(subi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2865de65d39..9bcf79ccbfc 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -399,6 +399,11 @@ void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
}
+void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_gen_addi(type, dst, src1, -src2);
+}
+
/* 32 bit ops */
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
@@ -410,11 +415,6 @@ void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
}
}
-void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_gen_addi_i32(ret, arg1, -arg2);
-}
-
void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
{
tcg_gen_op2_i32(INDEX_op_neg, ret, arg);
@@ -1537,11 +1537,6 @@ void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
}
}
-void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_gen_addi_i64(ret, arg1, -arg2);
-}
-
void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_op2_i64(INDEX_op_neg, ret, arg);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_*
2026-09-27 8:58 ` [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_* Richard Henderson
@ 2026-09-27 15:31 ` Philippe Mathieu-Daudé
2026-09-29 21:53 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 15:31 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 15 +++++----------
> 3 files changed, 6 insertions(+), 12 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_*
2026-09-27 8:58 ` [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_* Richard Henderson
2026-09-27 15:31 ` Philippe Mathieu-Daudé
@ 2026-09-29 21:53 ` Matt Turner
2026-09-29 23:36 ` Matt Turner
2026-10-02 6:33 ` Richard Henderson
1 sibling, 2 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 21:53 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:00 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 15 +++++----------
> 3 files changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 8444044ed57..ff15e3b88ae 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -124,7 +124,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> /* 32 bit ops */
>
> void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
> -void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> @@ -225,7 +224,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
> /* 64 bit ops */
>
> void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
> -void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index 51d5ec6e06a..55249c4dd6f 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -7,3 +7,4 @@ DEF1(discard, TCGV)
> DEF2(mov, TCGV, TCGV)
> DEF2(movi, TCGV, TINT)
> DEF3(sub, TCGV, TCGV, TCGV)
> +DEF3(subi, TCGV, TCGV, TINT)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 2865de65d39..9bcf79ccbfc 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -399,6 +399,11 @@ void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
> }
>
> +void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> +{
> + tcg_gen_addi(type, dst, src1, -src2);
Double check me on this, but since src2's type changed from int32_t to
int64_t, I think this will produce a value that isn't sign-extended
for I32.
E.g. for I32 with src2 == INT32_MIN this now produces 0x80000000
rather than the 0xffffffff80000000 the old code produced.
tcg_constant_internal() doesn't canonicalize, so we end up with an I32
constant that isn't sign-extended, which optimize.c assumes can't
happen.
Going to make a quick sweep over the rest of the series to look for
this issue specifically.
> +}
> +
> /* 32 bit ops */
>
> void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
> @@ -410,11 +415,6 @@ void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
> }
> }
>
> -void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
> -{
> - tcg_gen_addi_i32(ret, arg1, -arg2);
> -}
> -
> void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
> {
> tcg_gen_op2_i32(INDEX_op_neg, ret, arg);
> @@ -1537,11 +1537,6 @@ void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
> }
> }
>
> -void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
> -{
> - tcg_gen_addi_i64(ret, arg1, -arg2);
> -}
> -
> void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
> {
> tcg_gen_op2_i64(INDEX_op_neg, ret, arg);
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_*
2026-09-29 21:53 ` Matt Turner
@ 2026-09-29 23:36 ` Matt Turner
2026-10-02 6:33 ` Richard Henderson
1 sibling, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:36 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Tue, Sep 29, 2026 at 5:53 PM Matt Turner <mattst88@gmail.com> wrote:
>
> On Sun, Sep 27, 2026 at 5:00 AM Richard Henderson
> <richard.henderson@linaro.org> wrote:
> >
> > Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> > ---
> > include/tcg/tcg-op-common.h | 2 --
> > include/tcg/tcg-op-def.h.inc | 1 +
> > tcg/tcg-op.c | 15 +++++----------
> > 3 files changed, 6 insertions(+), 12 deletions(-)
> >
> > diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> > index 8444044ed57..ff15e3b88ae 100644
> > --- a/include/tcg/tcg-op-common.h
> > +++ b/include/tcg/tcg-op-common.h
> > @@ -124,7 +124,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> > /* 32 bit ops */
> >
> > void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
> > -void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> > void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> > void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> > void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> > @@ -225,7 +224,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
> > /* 64 bit ops */
> >
> > void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
> > -void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> > void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> > void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> > void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> > diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> > index 51d5ec6e06a..55249c4dd6f 100644
> > --- a/include/tcg/tcg-op-def.h.inc
> > +++ b/include/tcg/tcg-op-def.h.inc
> > @@ -7,3 +7,4 @@ DEF1(discard, TCGV)
> > DEF2(mov, TCGV, TCGV)
> > DEF2(movi, TCGV, TINT)
> > DEF3(sub, TCGV, TCGV, TCGV)
> > +DEF3(subi, TCGV, TCGV, TINT)
> > diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> > index 2865de65d39..9bcf79ccbfc 100644
> > --- a/tcg/tcg-op.c
> > +++ b/tcg/tcg-op.c
> > @@ -399,6 +399,11 @@ void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> > tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
> > }
> >
> > +void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> > +{
> > + tcg_gen_addi(type, dst, src1, -src2);
>
> Double check me on this, but since src2's type changed from int32_t to
> int64_t, I think this will produce a value that isn't sign-extended
> for I32.
>
> E.g. for I32 with src2 == INT32_MIN this now produces 0x80000000
> rather than the 0xffffffff80000000 the old code produced.
> tcg_constant_internal() doesn't canonicalize, so we end up with an I32
> constant that isn't sign-extended, which optimize.c assumes can't
> happen.
>
> Going to make a quick sweep over the rest of the series to look for
> this issue specifically.
Found similar cases in 087 and 096. If this is a real problem, it
might be simplest to sign-extend I32 values in tcg_constant_internal()
rather than fix each caller?
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_*
2026-09-29 21:53 ` Matt Turner
2026-09-29 23:36 ` Matt Turner
@ 2026-10-02 6:33 ` Richard Henderson
1 sibling, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-10-02 6:33 UTC (permalink / raw)
To: Matt Turner; +Cc: qemu-devel
On 9/29/26 23:53, Matt Turner wrote:
>> +void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
>> +{
>> + tcg_gen_addi(type, dst, src1, -src2);
>
> Double check me on this, but since src2's type changed from int32_t to
> int64_t, I think this will produce a value that isn't sign-extended
> for I32.
>
> E.g. for I32 with src2 == INT32_MIN this now produces 0x80000000
> rather than the 0xffffffff80000000 the old code produced.
> tcg_constant_internal() doesn't canonicalize, so we end up with an I32
> constant that isn't sign-extended, which optimize.c assumes can't
> happen.
Hmm. I was just about to say that it'll be re-extended when creating
the TEMP_CONST in tcg_constant_internal, but that turns out not to be
the case.
I'll fix it there. Thanks for noticing.
r~
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 016/101] tcg: Generic expansion of tcg_gen_neg_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (14 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 015/101] tcg: Generic expansion of tcg_gen_subi_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:32 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 017/101] tcg: Generic expansion of tcg_gen_subfi_* Richard Henderson
` (84 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 3 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ff15e3b88ae..bce6be377ca 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -218,7 +218,6 @@ void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
@@ -327,8 +326,6 @@ void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg);
-
/* Size changing operations. */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 55249c4dd6f..b5ede945115 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -6,5 +6,6 @@ DEF3(addi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
+DEF2(neg, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 9bcf79ccbfc..37135fcf4b3 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -394,6 +394,11 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
}
+void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -415,11 +420,6 @@ void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
}
}
-void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- tcg_gen_op2_i32(INDEX_op_neg, ret, arg);
-}
-
void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
tcg_gen_op3_i32(INDEX_op_and, ret, arg1, arg2);
@@ -1537,11 +1537,6 @@ void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
}
}
-void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- tcg_gen_op2_i64(INDEX_op_neg, ret, arg);
-}
-
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 017/101] tcg: Generic expansion of tcg_gen_subfi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (15 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 016/101] tcg: Generic expansion of tcg_gen_neg_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:32 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 018/101] tcg: Generic expansion of tcg_gen_and_* Richard Henderson
` (83 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 21 ++++++---------------
3 files changed, 7 insertions(+), 17 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index bce6be377ca..1ad18b10b5d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -222,7 +221,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index b5ede945115..487ee5936ef 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,3 +9,4 @@ DEF2(movi, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
+DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 37135fcf4b3..07bd0767fe4 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -409,17 +409,17 @@ void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
tcg_gen_addi(type, dst, src1, -src2);
}
-/* 32 bit ops */
-
-void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
+void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
{
- if (arg1 == 0) {
- tcg_gen_neg_i32(ret, arg2);
+ if (src1 == 0) {
+ tcg_gen_neg(type, dst, src2);
} else {
- tcg_gen_sub_i32(ret, tcg_constant_i32(arg1), arg2);
+ tcg_gen_sub(type, dst, tcg_constant_internal(type, src1), src2);
}
}
+/* 32 bit ops */
+
void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
tcg_gen_op3_i32(INDEX_op_and, ret, arg1, arg2);
@@ -1528,15 +1528,6 @@ void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op3_i64(INDEX_op_mul, ret, arg1, arg2);
}
-void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
-{
- if (arg1 == 0) {
- tcg_gen_neg_i64(ret, arg2);
- } else {
- tcg_gen_sub_i64(ret, tcg_constant_i64(arg1), arg2);
- }
-}
-
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 018/101] tcg: Generic expansion of tcg_gen_and_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (16 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 017/101] tcg: Generic expansion of tcg_gen_subfi_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:33 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 019/101] tcg: Generic expansion of tcg_gen_or_* Richard Henderson
` (82 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1ad18b10b5d..0c4513ffb80 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -317,7 +316,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 487ee5936ef..d6b45004a2f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -3,6 +3,7 @@
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
+DEF3(and, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 07bd0767fe4..f76e01310af 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -377,6 +377,11 @@ void tcg_gen_addi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_and(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_and, type, dst, src1, src2);
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -420,11 +425,6 @@ void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
/* 32 bit ops */
-void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_and, ret, arg1, arg2);
-}
-
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_and, ret, arg1, arg2);
-}
-
void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_or, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 019/101] tcg: Generic expansion of tcg_gen_or_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (17 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 018/101] tcg: Generic expansion of tcg_gen_and_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:33 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 020/101] tcg: Generic expansion of tcg_gen_xor_* Richard Henderson
` (81 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 0c4513ffb80..ba333d83958 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -316,7 +315,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index d6b45004a2f..8dd39290609 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -8,6 +8,7 @@ DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
+DEF3(or, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f76e01310af..5fc7f1d02af 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -404,6 +404,11 @@ void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
}
+void tcg_gen_or(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_or, type, dst, src1, src2);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -455,11 +460,6 @@ void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
tcg_gen_and_i32(ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_or, ret, arg1, arg2);
-}
-
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_or, ret, arg1, arg2);
-}
-
void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_xor, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 020/101] tcg: Generic expansion of tcg_gen_xor_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (18 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 019/101] tcg: Generic expansion of tcg_gen_or_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:33 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 021/101] tcg: Generic expansion of tcg_gen_shl_* Richard Henderson
` (80 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ba333d83958..81854b56f93 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -315,7 +314,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 8dd39290609..ad298b7e306 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -12,3 +12,4 @@ DEF3(or, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
+DEF3(xor, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 5fc7f1d02af..8c3f7dce815 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -428,6 +428,11 @@ void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
}
}
+void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_xor, type, dst, src1, src2);
+}
+
/* 32 bit ops */
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
@@ -472,11 +477,6 @@ void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
}
}
-void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_xor, ret, arg1, arg2);
-}
-
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_xor, ret, arg1, arg2);
-}
-
void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_shl, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 021/101] tcg: Generic expansion of tcg_gen_shl_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (19 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 020/101] tcg: Generic expansion of tcg_gen_xor_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:34 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 022/101] tcg: Generic expansion of tcg_gen_shr_* Richard Henderson
` (79 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 81854b56f93..773f1e16c41 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -314,7 +313,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index ad298b7e306..3e6dd1eaf93 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,6 +9,7 @@ DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
+DEF3(shl, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 8c3f7dce815..8d5befb75a6 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -409,6 +409,11 @@ void tcg_gen_or(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_or, type, dst, src1, src2);
}
+void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -500,11 +505,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_shl, ret, arg1, arg2);
-}
-
void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_shl, ret, arg1, arg2);
-}
-
void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_shr, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 022/101] tcg: Generic expansion of tcg_gen_shr_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (20 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 021/101] tcg: Generic expansion of tcg_gen_shl_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:35 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 023/101] tcg: Generic expansion of tcg_gen_sar_* Richard Henderson
` (78 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 773f1e16c41..5d72c92534d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -313,7 +312,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 3e6dd1eaf93..573a4963b4f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -10,6 +10,7 @@ DEF2(movi, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(shl, TCGV, TCGV, TCGV)
+DEF3(shr, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 8d5befb75a6..dc1734b7584 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -414,6 +414,11 @@ void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
}
+void tcg_gen_shr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_shr, type, dst, src1, src2);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -515,11 +520,6 @@ void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
}
}
-void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_shr, ret, arg1, arg2);
-}
-
void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_shr, ret, arg1, arg2);
-}
-
void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_sar, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 023/101] tcg: Generic expansion of tcg_gen_sar_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (21 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 022/101] tcg: Generic expansion of tcg_gen_shr_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:35 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 024/101] tcg: Generic expansion of tcg_gen_mul_* Richard Henderson
` (77 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 5d72c92534d..a78752e0427 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -312,7 +311,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
/* Size changing operations. */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 573a4963b4f..96bd6abd74d 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,6 +9,7 @@ DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
+DEF3(sar, TCGV, TCGV, TCGV)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shr, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index dc1734b7584..065e37b34f7 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -409,6 +409,11 @@ void tcg_gen_or(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_or, type, dst, src1, src2);
}
+void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
+}
+
void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
@@ -530,11 +535,6 @@ void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
}
}
-void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_sar, ret, arg1, arg2);
-}
-
void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_sar, ret, arg1, arg2);
-}
-
void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
tcg_gen_op3_i64(INDEX_op_mul, ret, arg1, arg2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 024/101] tcg: Generic expansion of tcg_gen_mul_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (22 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 023/101] tcg: Generic expansion of tcg_gen_sar_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:35 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 025/101] tcg: Generic expansion of tcg_gen_shli_* Richard Henderson
` (76 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index a78752e0427..fd35307a848 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -210,7 +210,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
@@ -311,7 +310,6 @@ void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
/* Size changing operations. */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 96bd6abd74d..c1273a10197 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -7,6 +7,7 @@ DEF3(and, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
+DEF3(mul, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 065e37b34f7..70591ba503c 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -399,6 +399,11 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
}
+void tcg_gen_mul(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ tcg_gen_op_ttt(INDEX_op_mul, type, dst, src1, src2);
+}
+
void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
{
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
@@ -601,11 +606,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- tcg_gen_op3_i32(INDEX_op_mul, ret, arg1, arg2);
-}
-
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
if (arg2 == 0) {
@@ -1493,11 +1493,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- tcg_gen_op3_i64(INDEX_op_mul, ret, arg1, arg2);
-}
-
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 025/101] tcg: Generic expansion of tcg_gen_shli_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (23 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 024/101] tcg: Generic expansion of tcg_gen_mul_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-28 9:46 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 026/101] tcg: Generic expansion of tcg_gen_shri_* Richard Henderson
` (75 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index fd35307a848..d469f2b42a2 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -126,7 +126,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
-void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -217,7 +216,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
-void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index c1273a10197..c47de1a3a42 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -12,6 +12,7 @@ DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(shl, TCGV, TCGV, TCGV)
+DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 70591ba503c..716417bbfc4 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -424,6 +424,16 @@ void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
}
+void tcg_gen_shli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_debug_assert(src2 >= 0 && src2 < tcg_type_size(type) * 8);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ tcg_gen_shl(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_shr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shr, type, dst, src1, src2);
@@ -520,16 +530,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 32);
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else {
- tcg_gen_shl_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1549,16 +1549,6 @@ void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
}
}
-void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 64);
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else {
- tcg_gen_shl_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 64);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 025/101] tcg: Generic expansion of tcg_gen_shli_*
2026-09-27 8:58 ` [PATCH v5 025/101] tcg: Generic expansion of tcg_gen_shli_* Richard Henderson
@ 2026-09-28 9:46 ` Philippe Mathieu-Daudé
2026-09-28 11:44 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 9:46 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:58, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 30 ++++++++++--------------------
> 3 files changed, 11 insertions(+), 22 deletions(-)
> +void tcg_gen_shli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> +{
> + tcg_debug_assert(src2 >= 0 && src2 < tcg_type_size(type) * 8);
Can we add a tcg_type_bits() helper?
> + if (src2 == 0) {
> + tcg_gen_mov(type, dst, src1);
> + } else {
> + tcg_gen_shl(type, dst, src1, tcg_constant_internal(type, src2));
> + }
> +}
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 026/101] tcg: Generic expansion of tcg_gen_shri_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (24 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 025/101] tcg: Generic expansion of tcg_gen_shli_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-28 9:47 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 027/101] tcg: Generic expansion of tcg_gen_sari_* Richard Henderson
` (74 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index d469f2b42a2..af6b85b6a3f 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -126,7 +126,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
-void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -216,7 +215,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
-void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index c47de1a3a42..ea641158ae0 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -14,6 +14,7 @@ DEF3(sar, TCGV, TCGV, TCGV)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
+DEF3(shri, TCGV, TCGV, TINT)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 716417bbfc4..a72fb4c0aee 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -439,6 +439,16 @@ void tcg_gen_shr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_shr, type, dst, src1, src2);
}
+void tcg_gen_shri(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_debug_assert(src2 >= 0 && src2 < tcg_type_size(type) * 8);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ tcg_gen_shr(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -530,16 +540,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 32);
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else {
- tcg_gen_shr_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1549,16 +1549,6 @@ void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
}
}
-void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 64);
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else {
- tcg_gen_shr_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 64);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 027/101] tcg: Generic expansion of tcg_gen_sari_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (25 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 026/101] tcg: Generic expansion of tcg_gen_shri_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-28 9:48 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 028/101] tcg: Generic expansion of tcg_gen_andi_* Richard Henderson
` (73 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index af6b85b6a3f..6b66f050cab 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -126,7 +126,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
-void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -215,7 +214,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
-void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index ea641158ae0..2108082ce63 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -11,6 +11,7 @@ DEF3(mul, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
+DEF3(sari, TCGV, TCGV, TINT)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a72fb4c0aee..7832e99dccd 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -419,6 +419,16 @@ void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
}
+void tcg_gen_sari(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_debug_assert(src2 >= 0 && src2 < tcg_type_size(type) * 8);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ tcg_gen_sar(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
@@ -540,16 +550,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 32);
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else {
- tcg_gen_sar_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TCGv_i32 arg2, TCGLabel *l)
{
if (cond == TCG_COND_ALWAYS) {
@@ -1549,16 +1549,6 @@ void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
}
}
-void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 64);
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else {
- tcg_gen_sar_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel *l)
{
if (cond == TCG_COND_ALWAYS) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 028/101] tcg: Generic expansion of tcg_gen_andi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (26 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 027/101] tcg: Generic expansion of tcg_gen_sari_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-28 15:41 ` Philippe Mathieu-Daudé
2026-09-27 8:58 ` [PATCH v5 029/101] tcg: Generic expansion of tcg_gen_ori_* Richard Henderson
` (72 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
tcg/tcg-internal.h | 6 +++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 84 +++++++++++-------------------------
4 files changed, 31 insertions(+), 62 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 6b66f050cab..1af9f58df1e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -211,7 +210,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 0da1a9c440c..76c8f026a64 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -114,6 +114,12 @@ static inline void tcg_gen_op_ttt(TCGOpcode opc, TCGType type,
tcg_gen_op3(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2));
}
+static inline TCGOp *tcg_gen_op_ttii(TCGOpcode opc, TCGType type, TCGTemp *t0,
+ TCGTemp *t1, TCGArg a2, TCGArg a3)
+{
+ return tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), a2, a3);
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 2108082ce63..f7e7f4d2a1c 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -4,6 +4,7 @@
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
+DEF3(andi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 7832e99dccd..2baddbcfd38 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -382,6 +382,30 @@ void tcg_gen_and(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_and, type, dst, src1, src2);
}
+void tcg_gen_andi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ if (src2 == 0) {
+ tcg_gen_movi(type, dst, 0);
+ } else if (src2 == -1) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ /*
+ * Canonicalize on extract, if valid. This aids x86 with its
+ * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
+ * which does not require matching operands. Other backends can
+ * trivially expand the extract to AND during code generation.
+ */
+ if (is_power_of_2(src2 + 1)) {
+ unsigned len = cto64(src2);
+ if (TCG_TARGET_extract_valid(type, 0, len)) {
+ tcg_gen_op_ttii(INDEX_op_extract, type, dst, src1, 0, len);
+ return;
+ }
+ }
+ tcg_gen_and(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -485,36 +509,6 @@ void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
/* 32 bit ops */
-void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- /* Some cases can be optimized here. */
- switch (arg2) {
- case 0:
- tcg_gen_movi_i32(ret, 0);
- return;
- case -1:
- tcg_gen_mov_i32(ret, arg1);
- return;
- default:
- /*
- * Canonicalize on extract, if valid. This aids x86 with its
- * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
- * which does not require matching operands. Other backends can
- * trivially expand the extract to AND during code generation.
- */
- if (!(arg2 & (arg2 + 1))) {
- unsigned len = ctz32(~arg2);
- if (TCG_TARGET_extract_valid(TCG_TYPE_I32, 0, len)) {
- tcg_gen_extract_i32(ret, arg1, 0, len);
- return;
- }
- }
- break;
- }
-
- tcg_gen_and_i32(ret, arg1, tcg_constant_i32(arg2));
-}
-
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1493,36 +1487,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- /* Some cases can be optimized here. */
- switch (arg2) {
- case 0:
- tcg_gen_movi_i64(ret, 0);
- return;
- case -1:
- tcg_gen_mov_i64(ret, arg1);
- return;
- default:
- /*
- * Canonicalize on extract, if valid. This aids x86 with its
- * 2 operand MOVZBL and 2 operand AND, selecting the TCGOpcode
- * which does not require matching operands. Other backends can
- * trivially expand the extract to AND during code generation.
- */
- if (!(arg2 & (arg2 + 1))) {
- unsigned len = ctz64(~arg2);
- if (TCG_TARGET_extract_valid(TCG_TYPE_I64, 0, len)) {
- tcg_gen_extract_i64(ret, arg1, 0, len);
- return;
- }
- }
- break;
- }
-
- tcg_gen_and_i64(ret, arg1, tcg_constant_i64(arg2));
-}
-
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 029/101] tcg: Generic expansion of tcg_gen_ori_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (27 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 028/101] tcg: Generic expansion of tcg_gen_andi_* Richard Henderson
@ 2026-09-27 8:58 ` Richard Henderson
2026-09-27 15:39 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 030/101] tcg: Generic expansion of tcg_gen_xori_* Richard Henderson
` (71 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:58 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 35 +++++++++++------------------------
3 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1af9f58df1e..b574a8f4f4f 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -210,7 +209,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index f7e7f4d2a1c..f7a7dc69c9d 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -11,6 +11,7 @@ DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
+DEF3(ori, TCGV, TCGV, TINT)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF3(shl, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2baddbcfd38..90aae9ed4c9 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -438,6 +438,17 @@ void tcg_gen_or(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_or, type, dst, src1, src2);
}
+void tcg_gen_ori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ if (src2 == -1) {
+ tcg_gen_movi(type, dst, -1);
+ } else if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else {
+ tcg_gen_or(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -509,18 +520,6 @@ void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
/* 32 bit ops */
-void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- /* Some cases can be optimized here. */
- if (arg2 == -1) {
- tcg_gen_movi_i32(ret, -1);
- } else if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else {
- tcg_gen_or_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
/* Some cases can be optimized here. */
@@ -1487,18 +1486,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- /* Some cases can be optimized here. */
- if (arg2 == -1) {
- tcg_gen_movi_i64(ret, -1);
- } else if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else {
- tcg_gen_or_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
/* Some cases can be optimized here. */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 030/101] tcg: Generic expansion of tcg_gen_xori_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (28 preceding siblings ...)
2026-09-27 8:58 ` [PATCH v5 029/101] tcg: Generic expansion of tcg_gen_ori_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 15:42 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 031/101] tcg: Generic expansion of tcg_gen_muli_* Richard Henderson
` (70 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 34 +++++++++-------------------------
3 files changed, 10 insertions(+), 27 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index b574a8f4f4f..87aab828112 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -209,7 +208,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index f7a7dc69c9d..b38969478a9 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -22,3 +22,4 @@ DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
DEF3(xor, TCGV, TCGV, TCGV)
+DEF3(xori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 90aae9ed4c9..153a759305e 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -518,22 +518,20 @@ void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_xor, type, dst, src1, src2);
}
-/* 32 bit ops */
-
-void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
+void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
{
- /* Some cases can be optimized here. */
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else if (arg2 == -1 &&
- tcg_op_supported(INDEX_op_not, TCG_TYPE_I32, 0)) {
- /* Don't recurse with tcg_gen_not_i32. */
- tcg_gen_op2_i32(INDEX_op_not, ret, arg1);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else if (src2 == -1 && tcg_op_supported(INDEX_op_not, type, 0)) {
+ /* Do not recurse with gen_not. */
+ tcg_gen_op_tt(INDEX_op_not, type, dst, src1);
} else {
- tcg_gen_xor_i32(ret, arg1, tcg_constant_i32(arg2));
+ tcg_gen_xor(type, dst, src1, tcg_constant_internal(type, src2));
}
}
+/* 32 bit ops */
+
void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
{
if (tcg_op_supported(INDEX_op_not, TCG_TYPE_I32, 0)) {
@@ -1486,20 +1484,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- /* Some cases can be optimized here. */
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else if (arg2 == -1 &&
- tcg_op_supported(INDEX_op_not, TCG_TYPE_I64, 0)) {
- /* Don't recurse with tcg_gen_not_i64. */
- tcg_gen_op2_i64(INDEX_op_not, ret, arg1);
- } else {
- tcg_gen_xor_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel *l)
{
if (cond == TCG_COND_ALWAYS) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 031/101] tcg: Generic expansion of tcg_gen_muli_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (29 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 030/101] tcg: Generic expansion of tcg_gen_xori_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:48 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 032/101] tcg: Generic expansion of tcg_gen_not_* Richard Henderson
` (69 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 33 +++++++++++----------------------
3 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 87aab828112..773dd8db719 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -208,7 +207,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index b38969478a9..abea00e7e0e 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,6 +9,7 @@ DEF1(discard, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
+DEF3(muli, TCGV, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 153a759305e..dacdcc68c52 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -428,6 +428,17 @@ void tcg_gen_mul(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_gen_op_ttt(INDEX_op_mul, type, dst, src1, src2);
}
+void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ if (src2 == 0) {
+ tcg_gen_movi(type, dst, 0);
+ } else if (is_power_of_2(src2)) {
+ tcg_gen_shli(type, dst, src1, ctz64(src2));
+ } else {
+ tcg_gen_mul(type, dst, src1, tcg_constant_internal(type, src2));
+ }
+}
+
void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
{
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
@@ -597,17 +608,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- if (arg2 == 0) {
- tcg_gen_movi_i32(ret, 0);
- } else if (is_power_of_2(arg2)) {
- tcg_gen_shli_i32(ret, arg1, ctz32(arg2));
- } else {
- tcg_gen_mul_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I32, 0)) {
@@ -1536,17 +1536,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
}
}
-void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- if (arg2 == 0) {
- tcg_gen_movi_i64(ret, 0);
- } else if (is_power_of_2(arg2)) {
- tcg_gen_shli_i64(ret, arg1, ctz64(arg2));
- } else {
- tcg_gen_mul_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 032/101] tcg: Generic expansion of tcg_gen_not_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (30 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 031/101] tcg: Generic expansion of tcg_gen_muli_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 15:37 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 033/101] tcg: Drop division helpers Richard Henderson
` (68 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 3 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 28 ++++++++++------------------
3 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 773dd8db719..aa4fe339d8e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -203,8 +203,6 @@ void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg);
-
/* 64 bit ops */
void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
@@ -258,7 +256,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index abea00e7e0e..8c9d3d99c48 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -11,6 +11,7 @@ DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
DEF2(neg, TCGV, TCGV)
+DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
DEF3(sar, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index dacdcc68c52..d1cf0a436ea 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -444,6 +444,16 @@ void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
}
+void tcg_gen_not(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ if (tcg_op_supported(INDEX_op_not, type, 0)) {
+ tcg_gen_op_tt(INDEX_op_not, type, dst, src);
+ } else {
+ /* Do not recurse with gen_xori. */
+ tcg_gen_xor(type, dst, src, tcg_constant_internal(type, -1));
+ }
+}
+
void tcg_gen_or(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_or, type, dst, src1, src2);
@@ -543,15 +553,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- if (tcg_op_supported(INDEX_op_not, TCG_TYPE_I32, 0)) {
- tcg_gen_op2_i32(INDEX_op_not, ret, arg);
- } else {
- tcg_gen_xori_i32(ret, arg, -1);
- }
-}
-
void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TCGv_i32 arg2, TCGLabel *l)
{
if (cond == TCG_COND_ALWAYS) {
@@ -1803,15 +1804,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- if (tcg_op_supported(INDEX_op_not, TCG_TYPE_I64, 0)) {
- tcg_gen_op2_i64(INDEX_op_not, ret, arg);
- } else {
- tcg_gen_xori_i64(ret, arg, -1);
- }
-}
-
void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_andc, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 033/101] tcg: Drop division helpers
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (31 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 032/101] tcg: Generic expansion of tcg_gen_not_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:23 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 034/101] tcg: Generic expansion of tcg_gen_div_* Richard Henderson
` (67 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
All current tcg hosts support division, so the helpers
are no longer used.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
accel/tcg/tcg-runtime.h | 10 ----------
accel/tcg/tcg-runtime.c | 44 -----------------------------------------
tcg/tcg-op.c | 16 +++++++--------
3 files changed, 8 insertions(+), 62 deletions(-)
diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h
index 0b832176b33..003c963bc7d 100644
--- a/accel/tcg/tcg-runtime.h
+++ b/accel/tcg/tcg-runtime.h
@@ -1,13 +1,3 @@
-DEF_HELPER_FLAGS_2(div_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32)
-DEF_HELPER_FLAGS_2(rem_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32)
-DEF_HELPER_FLAGS_2(divu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
-DEF_HELPER_FLAGS_2(remu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
-
-DEF_HELPER_FLAGS_2(div_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
-DEF_HELPER_FLAGS_2(rem_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
-DEF_HELPER_FLAGS_2(divu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
-DEF_HELPER_FLAGS_2(remu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
-
DEF_HELPER_FLAGS_2(mulsh_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
DEF_HELPER_FLAGS_2(muluh_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c
index 7c0aab98a80..77c4024148f 100644
--- a/accel/tcg/tcg-runtime.c
+++ b/accel/tcg/tcg-runtime.c
@@ -32,50 +32,6 @@
#include "exec/helper-info.c.inc"
#undef HELPER_H
-/* 32-bit helpers */
-
-int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2)
-{
- return arg1 / arg2;
-}
-
-int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2)
-{
- return arg1 % arg2;
-}
-
-uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2)
-{
- return arg1 / arg2;
-}
-
-uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2)
-{
- return arg1 % arg2;
-}
-
-/* 64-bit helpers */
-
-int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2)
-{
- return arg1 / arg2;
-}
-
-int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2)
-{
- return arg1 % arg2;
-}
-
-uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2)
-{
- return arg1 / arg2;
-}
-
-uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2)
-{
- return arg1 % arg2;
-}
-
uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2)
{
uint64_t l, h;
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index d1cf0a436ea..67ba4a0307a 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -619,7 +619,7 @@ void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_gen_op5_i32(INDEX_op_divs2, ret, t0, arg1, t0, arg2);
tcg_temp_free_i32(t0);
} else {
- gen_helper_div_i32(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -639,7 +639,7 @@ void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_gen_op5_i32(INDEX_op_divs2, t0, ret, arg1, t0, arg2);
tcg_temp_free_i32(t0);
} else {
- gen_helper_rem_i32(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -653,7 +653,7 @@ void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_gen_op5_i32(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
tcg_temp_free_i32(t0);
} else {
- gen_helper_divu_i32(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -673,7 +673,7 @@ void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_gen_op5_i32(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
tcg_temp_free_i32(t0);
} else {
- gen_helper_remu_i32(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -1547,7 +1547,7 @@ void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op5_i64(INDEX_op_divs2, ret, t0, arg1, t0, arg2);
tcg_temp_free_i64(t0);
} else {
- gen_helper_div_i64(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -1567,7 +1567,7 @@ void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op5_i64(INDEX_op_divs2, t0, ret, arg1, t0, arg2);
tcg_temp_free_i64(t0);
} else {
- gen_helper_rem_i64(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -1581,7 +1581,7 @@ void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op5_i64(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
tcg_temp_free_i64(t0);
} else {
- gen_helper_divu_i64(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
@@ -1601,7 +1601,7 @@ void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_op5_i64(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
tcg_temp_free_i64(t0);
} else {
- gen_helper_remu_i64(ret, arg1, arg2);
+ g_assert_not_reached();
}
}
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 033/101] tcg: Drop division helpers
2026-09-27 8:59 ` [PATCH v5 033/101] tcg: Drop division helpers Richard Henderson
@ 2026-09-28 16:23 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 16:23 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> All current tcg hosts support division, so the helpers
> are no longer used.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> accel/tcg/tcg-runtime.h | 10 ----------
> accel/tcg/tcg-runtime.c | 44 -----------------------------------------
> tcg/tcg-op.c | 16 +++++++--------
> 3 files changed, 8 insertions(+), 62 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 034/101] tcg: Generic expansion of tcg_gen_div_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (32 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 033/101] tcg: Drop division helpers Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 15:43 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 035/101] tcg: Generic expansion of tcg_gen_rem_* Richard Henderson
` (66 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
tcg/tcg-internal.h | 8 +++++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 43 +++++++++++++-----------------------
4 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index aa4fe339d8e..bfda3c1f444 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -205,7 +204,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 76c8f026a64..6b65228241e 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -120,6 +120,14 @@ static inline TCGOp *tcg_gen_op_ttii(TCGOpcode opc, TCGType type, TCGTemp *t0,
return tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), a2, a3);
}
+static inline void tcg_gen_op_ttttt(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
+ TCGTemp *t3, TCGTemp *t4)
+{
+ tcg_gen_op5(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2),
+ temp_arg(t3), temp_arg(t4));
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 8c9d3d99c48..778854286cc 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -6,6 +6,7 @@ DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
+DEF3(div, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 67ba4a0307a..203de8909fa 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -411,6 +411,21 @@ void tcg_gen_discard(TCGType type, TCGTemp *src)
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
}
+void tcg_gen_div(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_divs, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_divs, type, dst, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_divs2, type, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+ int width = tcg_type_size(type) * 8;
+
+ tcg_gen_sari(type, tmp, src1, width - 1);
+ tcg_gen_op_ttttt(INDEX_op_divs2, type, dst, tmp, src1, tmp, src2);
+ } else {
+ g_assert_not_reached();
+ }
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -609,20 +624,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_divs, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divs2, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_sari_i32(t0, arg1, 31);
- tcg_gen_op5_i32(INDEX_op_divs2, ret, t0, arg1, t0, arg2);
- tcg_temp_free_i32(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_rems, TCG_TYPE_I32, 0)) {
@@ -1537,20 +1538,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
}
}
-void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_divs, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divs2, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_sari_i64(t0, arg1, 63);
- tcg_gen_op5_i64(INDEX_op_divs2, ret, t0, arg1, t0, arg2);
- tcg_temp_free_i64(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_rems, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 035/101] tcg: Generic expansion of tcg_gen_rem_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (33 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 034/101] tcg: Generic expansion of tcg_gen_div_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 15:45 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 036/101] tcg: Generic expansion of tcg_gen_divu_* Richard Henderson
` (65 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 61 +++++++++++++-----------------------
3 files changed, 22 insertions(+), 42 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index bfda3c1f444..e1457b3f584 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -204,7 +203,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 778854286cc..50d725b72c5 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -15,6 +15,7 @@ DEF2(neg, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
+DEF3(rem, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF3(shl, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 203de8909fa..0304f8e15cf 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -485,6 +485,27 @@ void tcg_gen_ori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_rem(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_rems, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rems, type, dst, src1, src2);
+ } else {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_divs, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_divs, type, tmp, src1, src2);
+ tcg_gen_mul(type, tmp, tmp, src2);
+ tcg_gen_sub(type, dst, src1, tmp);
+ } else if (tcg_op_supported(INDEX_op_divs2, type, 0)) {
+ int width = tcg_type_size(type) * 8;
+ tcg_gen_sari(type, tmp, src1, width - 1);
+ tcg_gen_op_ttttt(INDEX_op_divs2, type, tmp, dst, src1, tmp, src2);
+ } else {
+ g_assert_not_reached();
+ }
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -624,26 +645,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_rems, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rems, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_divs, t0, arg1, arg2);
- tcg_gen_mul_i32(t0, t0, arg2);
- tcg_gen_sub_i32(ret, arg1, t0);
- tcg_temp_free_i32(t0);
- } else if (tcg_op_supported(INDEX_op_divs2, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_sari_i32(t0, arg1, 31);
- tcg_gen_op5_i32(INDEX_op_divs2, t0, ret, arg1, t0, arg2);
- tcg_temp_free_i32(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I32, 0)) {
@@ -1538,26 +1539,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
}
}
-void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_rems, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rems, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_op3_i64(INDEX_op_divs, t0, arg1, arg2);
- tcg_gen_mul_i64(t0, t0, arg2);
- tcg_gen_sub_i64(ret, arg1, t0);
- tcg_temp_free_i64(t0);
- } else if (tcg_op_supported(INDEX_op_divs2, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_sari_i64(t0, arg1, 63);
- tcg_gen_op5_i64(INDEX_op_divs2, t0, ret, arg1, t0, arg2);
- tcg_temp_free_i64(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 036/101] tcg: Generic expansion of tcg_gen_divu_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (34 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 035/101] tcg: Generic expansion of tcg_gen_rem_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:50 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 037/101] tcg: Generic expansion of tcg_gen_remu_* Richard Henderson
` (64 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 42 ++++++++++++------------------------
3 files changed, 15 insertions(+), 30 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index e1457b3f584..ce31b0d971d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -203,7 +202,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 50d725b72c5..1b108d9f147 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -7,6 +7,7 @@ DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
+DEF3(divu, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 0304f8e15cf..a4bdf1143e6 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -426,6 +426,20 @@ void tcg_gen_div(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_divu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_divu, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_divu, type, dst, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_divu2, type, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_op_ttttt(INDEX_op_divu2, type, dst, tmp, src1,
+ tcg_constant_internal(type, 0), src2);
+ } else {
+ g_assert_not_reached();
+ }
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -645,20 +659,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_divu, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 zero = tcg_constant_i32(0);
- tcg_gen_op5_i32(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
- tcg_temp_free_i32(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_remu, TCG_TYPE_I32, 0)) {
@@ -1539,20 +1539,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
}
}
-void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_divu, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 zero = tcg_constant_i64(0);
- tcg_gen_op5_i64(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
- tcg_temp_free_i64(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_remu, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 037/101] tcg: Generic expansion of tcg_gen_remu_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (35 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 036/101] tcg: Generic expansion of tcg_gen_divu_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:01 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 038/101] tcg: Generic expansion of tcg_gen_andc_* Richard Henderson
` (63 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 74 ++++++++++--------------------------
3 files changed, 21 insertions(+), 56 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ce31b0d971d..0fa534f24d0 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -202,7 +201,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 1b108d9f147..cfa19a0a815 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -17,6 +17,7 @@ DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
DEF3(rem, TCGV, TCGV, TCGV)
+DEF3(remu, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF3(shl, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a4bdf1143e6..39b4bbb659e 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -211,20 +211,6 @@ static TCGOp * DNI tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
tcgv_i64_arg(a1), tcgv_i64_arg(a2), a3, a4);
}
-static void DNI tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGv_i32 a3, TCGv_i32 a4, TCGv_i32 a5)
-{
- tcg_gen_op5(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
- tcgv_i32_arg(a3), tcgv_i32_arg(a4), tcgv_i32_arg(a5));
-}
-
-static void DNI tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGv_i64 a3, TCGv_i64 a4, TCGv_i64 a5)
-{
- tcg_gen_op5(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
- tcgv_i64_arg(a3), tcgv_i64_arg(a4), tcgv_i64_arg(a5));
-}
-
static void DNI tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
TCGv_i32 a3, TCGArg a4, TCGArg a5)
{
@@ -520,6 +506,26 @@ void tcg_gen_rem(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_remu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_remu, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_remu, type, dst, src1, src2);
+ } else {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_divu, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_divu, type, tmp, src1, src2);
+ tcg_gen_mul(type, tmp, tmp, src2);
+ tcg_gen_sub(type, dst, src1, tmp);
+ } else if (tcg_op_supported(INDEX_op_divu2, type, 0)) {
+ tcg_gen_op_ttttt(INDEX_op_divu2, type, tmp, dst, src1,
+ tcg_constant_internal(type, 0), src2);
+ } else {
+ g_assert_not_reached();
+ }
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -659,26 +665,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_remu, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_remu, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_divu, t0, arg1, arg2);
- tcg_gen_mul_i32(t0, t0, arg2);
- tcg_gen_sub_i32(ret, arg1, t0);
- tcg_temp_free_i32(t0);
- } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 zero = tcg_constant_i32(0);
- tcg_gen_op5_i32(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
- tcg_temp_free_i32(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_andc, TCG_TYPE_I32, 0)) {
@@ -1539,26 +1525,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
}
}
-void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_remu, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_remu, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_op3_i64(INDEX_op_divu, t0, arg1, arg2);
- tcg_gen_mul_i64(t0, t0, arg2);
- tcg_gen_sub_i64(ret, arg1, t0);
- tcg_temp_free_i64(t0);
- } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 zero = tcg_constant_i64(0);
- tcg_gen_op5_i64(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
- tcg_temp_free_i64(t0);
- } else {
- g_assert_not_reached();
- }
-}
-
void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 8);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 038/101] tcg: Generic expansion of tcg_gen_andc_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (36 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 037/101] tcg: Generic expansion of tcg_gen_remu_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:51 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 039/101] tcg: Generic expansion of tcg_gen_eqv_* Richard Henderson
` (62 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 36 ++++++++++++------------------------
3 files changed, 13 insertions(+), 26 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 0fa534f24d0..af50c90eb04 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -201,7 +200,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index cfa19a0a815..7386332658c 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -5,6 +5,7 @@ DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
+DEF3(andc, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 39b4bbb659e..e3ae8c2383f 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -392,6 +392,18 @@ void tcg_gen_andi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_andc(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_andc, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_andc, type, dst, src1, src2);
+ } else {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_not(type, tmp, src2);
+ tcg_gen_and(type, dst, src1, tmp);
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -665,18 +677,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_andc, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_andc, ret, arg1, arg2);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_not_i32(t0, arg2);
- tcg_gen_and_i32(ret, arg1, t0);
- tcg_temp_free_i32(t0);
- }
-}
-
void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_eqv, TCG_TYPE_I32, 0)) {
@@ -1724,18 +1724,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_andc, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_andc, ret, arg1, arg2);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_not_i64(t0, arg2);
- tcg_gen_and_i64(ret, arg1, t0);
- tcg_temp_free_i64(t0);
- }
-}
-
void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_eqv, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 039/101] tcg: Generic expansion of tcg_gen_eqv_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (37 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 038/101] tcg: Generic expansion of tcg_gen_andc_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:51 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 040/101] tcg: Generic expansion of tcg_gen_nand_* Richard Henderson
` (61 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index af50c90eb04..cfa94a1f5dc 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -200,7 +199,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 7386332658c..6a4d726b799 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,6 +9,7 @@ DEF3(andc, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
+DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index e3ae8c2383f..f33b25734e0 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -438,6 +438,16 @@ void tcg_gen_divu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_eqv(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_eqv, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_eqv, type, dst, src1, src2);
+ } else {
+ tcg_gen_xor(type, dst, src1, src2);
+ tcg_gen_not(type, dst, dst);
+ }
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -677,16 +687,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_eqv, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_eqv, ret, arg1, arg2);
- } else {
- tcg_gen_xor_i32(ret, arg1, arg2);
- tcg_gen_not_i32(ret, ret);
- }
-}
-
void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_nand, TCG_TYPE_I32, 0)) {
@@ -1724,16 +1724,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_eqv, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_eqv, ret, arg1, arg2);
- } else {
- tcg_gen_xor_i64(ret, arg1, arg2);
- tcg_gen_not_i64(ret, ret);
- }
-}
-
void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_nand, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 040/101] tcg: Generic expansion of tcg_gen_nand_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (38 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 039/101] tcg: Generic expansion of tcg_gen_eqv_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:51 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 041/101] tcg: Generic expansion of tcg_gen_nor_* Richard Henderson
` (60 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index cfa94a1f5dc..04d85e25d68 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -199,7 +198,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 6a4d726b799..fc40bca553f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -14,6 +14,7 @@ DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
+DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f33b25734e0..0e9a1758ed9 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -476,6 +476,16 @@ void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_nand(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_nand, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_nand, type, dst, src1, src2);
+ } else {
+ tcg_gen_and(type, dst, src1, src2);
+ tcg_gen_not(type, dst, dst);
+ }
+}
+
void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
{
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
@@ -687,16 +697,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_nand, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_nand, ret, arg1, arg2);
- } else {
- tcg_gen_and_i32(ret, arg1, arg2);
- tcg_gen_not_i32(ret, ret);
- }
-}
-
void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_nor, TCG_TYPE_I32, 0)) {
@@ -1724,16 +1724,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_nand, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_nand, ret, arg1, arg2);
- } else {
- tcg_gen_and_i64(ret, arg1, arg2);
- tcg_gen_not_i64(ret, ret);
- }
-}
-
void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_nor, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 041/101] tcg: Generic expansion of tcg_gen_nor_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (39 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 040/101] tcg: Generic expansion of tcg_gen_nand_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:52 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 042/101] tcg: Generic expansion of tcg_gen_orc_* Richard Henderson
` (59 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 30 ++++++++++--------------------
3 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 04d85e25d68..f5bb4d8031f 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -198,7 +197,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index fc40bca553f..7d94e0cdfeb 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -16,6 +16,7 @@ DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
+DEF3(nor, TCGV, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 0e9a1758ed9..f06c00f7263 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -491,6 +491,16 @@ void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
}
+void tcg_gen_nor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_nor, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_nor, type, dst, src1, src2);
+ } else {
+ tcg_gen_or(type, dst, src1, src2);
+ tcg_gen_not(type, dst, dst);
+ }
+}
+
void tcg_gen_not(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (tcg_op_supported(INDEX_op_not, type, 0)) {
@@ -697,16 +707,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_nor, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_nor, ret, arg1, arg2);
- } else {
- tcg_gen_or_i32(ret, arg1, arg2);
- tcg_gen_not_i32(ret, ret);
- }
-}
-
void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_orc, TCG_TYPE_I32, 0)) {
@@ -1724,16 +1724,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_nor, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_nor, ret, arg1, arg2);
- } else {
- tcg_gen_or_i64(ret, arg1, arg2);
- tcg_gen_not_i64(ret, ret);
- }
-}
-
void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_orc, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 042/101] tcg: Generic expansion of tcg_gen_orc_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (40 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 041/101] tcg: Generic expansion of tcg_gen_nor_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:52 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 043/101] tcg: Generic expansion of tcg_gen_brcond_* Richard Henderson
` (58 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 36 ++++++++++++------------------------
3 files changed, 13 insertions(+), 26 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index f5bb4d8031f..fadbcbbcde2 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
@@ -197,7 +196,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 7d94e0cdfeb..fa33d41e3df 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -20,6 +20,7 @@ DEF3(nor, TCGV, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
+DEF3(orc, TCGV, TCGV, TCGV)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f06c00f7263..aeac3480754 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -527,6 +527,18 @@ void tcg_gen_ori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_orc(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_orc, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_orc, type, dst, src1, src2);
+ } else {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_not(type, tmp, src2);
+ tcg_gen_or(type, dst, src1, tmp);
+ }
+}
+
void tcg_gen_rem(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_rems, type, 0)) {
@@ -707,18 +719,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
}
-void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_orc, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_orc, ret, arg1, arg2);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_not_i32(t0, arg2);
- tcg_gen_or_i32(ret, arg1, t0);
- tcg_temp_free_i32(t0);
- }
-}
-
void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I32, 0)) {
@@ -1724,18 +1724,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_orc, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_orc, ret, arg1, arg2);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_not_i64(t0, arg2);
- tcg_gen_or_i64(ret, arg1, t0);
- tcg_temp_free_i64(t0);
- }
-}
-
void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 043/101] tcg: Generic expansion of tcg_gen_brcond_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (41 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 042/101] tcg: Generic expansion of tcg_gen_orc_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:02 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 044/101] tcg: Generic expansion of tcg_gen_brcondi_* Richard Henderson
` (57 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 5 ++--
include/tcg/tcg.h | 1 +
tcg/tcg-internal.h | 3 +++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 44 ++++++++++++++++++------------------
5 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index fadbcbbcde2..e1dcd18bf0d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -98,6 +98,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2);
#define DEF3(NAME, T1, T2, T3) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3);
+#define DEF4(NAME, T1, T2, T3, T4) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4);
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -120,6 +122,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef DEF1
#undef DEF2
#undef DEF3
+#undef DEF4
/* 32 bit ops */
@@ -143,7 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TCGv_i32 arg2, TCGLabel *);
void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *);
void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, TCGv_i32 arg2);
@@ -216,7 +218,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel *);
void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel *);
void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 16ac528340a..077a1b37021 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -97,6 +97,7 @@ struct TCGLabelUse {
};
typedef struct TCGLabel TCGLabel;
+typedef struct TCGLabel *TCGLabelPtr;
struct TCGLabel {
bool present;
bool has_value;
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 6b65228241e..cd481dfd27f 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -150,6 +150,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2);
#define DEF3(NAME, T1, T2, T3) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3);
+#define DEF4(NAME, T1, T2, T3, T4) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4);
#define TCGV TCGTemp *
#define TINT int64_t
@@ -162,5 +164,6 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF1
#undef DEF2
#undef DEF3
+#undef DEF4
#endif /* TCG_INTERNAL_H */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index fa33d41e3df..10ed0438fd5 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -6,6 +6,7 @@ DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
+DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index aeac3480754..9a22791be0d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -307,10 +307,17 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c) \
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), glue(C_,T3)(c)); }
+#define DEF4(NAME, T1, T2, T3, T4) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c, T4 d) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), \
+ glue(C_,T3)(c), glue(C_,T4)(d)); }
+
#define C_TCGv_i32 tcgv_i32_temp
#define C_TCGv_i64 tcgv_i64_temp
#define C_int32_t
#define C_int64_t
+#define C_TCGCond
+#define C_TCGLabelPtr
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -338,10 +345,13 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_TCGv_i64
#undef C_int32_t
#undef C_int64_t
+#undef C_TCGCond
+#undef C_TCGLabelPtr
#undef DEF1
#undef DEF2
#undef DEF3
+#undef DEF4
/*
* Generic expansions for templated operations.
@@ -404,6 +414,18 @@ void tcg_gen_andc(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_brcond(TCGType type, TCGCond cond, TCGTemp *src1,
+ TCGTemp *src2, TCGLabel *l)
+{
+ if (cond == TCG_COND_ALWAYS) {
+ tcg_gen_br(l);
+ } else if (cond != TCG_COND_NEVER) {
+ TCGOp *op = tcg_gen_op_ttii(INDEX_op_brcond, type,
+ src1, src2, cond, label_arg(l));
+ add_as_label_use(l, op);
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -663,17 +685,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1, TCGv_i32 arg2, TCGLabel *l)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_br(l);
- } else if (cond != TCG_COND_NEVER) {
- TCGOp *op = tcg_gen_op4ii_i32(INDEX_op_brcond,
- arg1, arg2, cond, label_arg(l));
- add_as_label_use(l, op);
- }
-}
-
void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *l)
{
if (cond == TCG_COND_ALWAYS) {
@@ -1473,17 +1484,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel *l)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_br(l);
- } else if (cond != TCG_COND_NEVER) {
- TCGOp *op = tcg_gen_op4ii_i64(INDEX_op_brcond, arg1, arg2, cond,
- label_arg(l));
- add_as_label_use(l, op);
- }
-}
-
void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel *l)
{
tcg_gen_brcond_i64(cond, arg1, tcg_constant_i64(arg2), l);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 044/101] tcg: Generic expansion of tcg_gen_brcondi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (42 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 043/101] tcg: Generic expansion of tcg_gen_brcond_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:47 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 045/101] tcg: Generic expansion of tcg_gen_setcond_* Richard Henderson
` (56 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 20 ++++++--------------
3 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index e1dcd18bf0d..8540c30a58a 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *);
void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
@@ -218,7 +217,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel *);
void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 10ed0438fd5..a863215ffe3 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -7,6 +7,7 @@ DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
+DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 9a22791be0d..75d965d40ab 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -426,6 +426,12 @@ void tcg_gen_brcond(TCGType type, TCGCond cond, TCGTemp *src1,
}
}
+void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
+ int64_t src2, TCGLabel *l)
+{
+ tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -685,15 +691,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *l)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_br(l);
- } else if (cond != TCG_COND_NEVER) {
- tcg_gen_brcond_i32(cond, arg1, tcg_constant_i32(arg2), l);
- }
-}
-
void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, TCGv_i32 arg2)
{
@@ -1484,11 +1481,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel *l)
-{
- tcg_gen_brcond_i64(cond, arg1, tcg_constant_i64(arg2), l);
-}
-
void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, TCGv_i64 arg2)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 044/101] tcg: Generic expansion of tcg_gen_brcondi_*
2026-09-27 8:59 ` [PATCH v5 044/101] tcg: Generic expansion of tcg_gen_brcondi_* Richard Henderson
@ 2026-09-29 12:47 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:47 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 20 ++++++--------------
> 3 files changed, 7 insertions(+), 16 deletions(-)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 9a22791be0d..75d965d40ab 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -426,6 +426,12 @@ void tcg_gen_brcond(TCGType type, TCGCond cond, TCGTemp *src1,
> }
> }
>
> +void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
> + int64_t src2, TCGLabel *l)
> +{
> + tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
> +}
> +
> void tcg_gen_discard(TCGType type, TCGTemp *src)
> {
> tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
> @@ -685,15 +691,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
>
> /* 32 bit ops */
>
> -void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *l)
> -{
> - if (cond == TCG_COND_ALWAYS) {
> - tcg_gen_br(l);
> - } else if (cond != TCG_COND_NEVER) {
Should we mention "Remove premature optimization" in the commit
description?
> - tcg_gen_brcond_i32(cond, arg1, tcg_constant_i32(arg2), l);
> - }
> -}
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 045/101] tcg: Generic expansion of tcg_gen_setcond_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (43 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 044/101] tcg: Generic expansion of tcg_gen_brcondi_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:04 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 046/101] tcg: Generic expansion of tcg_gen_setcondi_* Richard Henderson
` (55 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ----
tcg/tcg-internal.h | 6 ++++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 36 ++++++++++++------------------------
4 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 8540c30a58a..66b72a498e1 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,8 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, int32_t arg2);
void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret,
@@ -217,8 +215,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, int64_t arg2);
void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index cd481dfd27f..0de8516447f 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -120,6 +120,12 @@ static inline TCGOp *tcg_gen_op_ttii(TCGOpcode opc, TCGType type, TCGTemp *t0,
return tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), a2, a3);
}
+static inline void tcg_gen_op_ttti(TCGOpcode opc, TCGType type, TCGTemp *t0,
+ TCGTemp *t1, TCGTemp *t2, TCGArg a3)
+{
+ tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2), a3);
+}
+
static inline void tcg_gen_op_ttttt(TCGOpcode opc, TCGType type,
TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
TCGTemp *t3, TCGTemp *t4)
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index a863215ffe3..4934f117bbe 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -27,6 +27,7 @@ DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
+DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 75d965d40ab..f8ded81ed84 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -623,6 +623,18 @@ void tcg_gen_sari(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_setcond(TCGType type, TCGCond cond, TCGTemp *dst,
+ TCGTemp *src1, TCGTemp *src2)
+{
+ if (cond == TCG_COND_ALWAYS) {
+ tcg_gen_movi(type, dst, 1);
+ } else if (cond == TCG_COND_NEVER) {
+ tcg_gen_movi(type, dst, 0);
+ } else {
+ tcg_gen_op_ttti(INDEX_op_setcond, type, dst, src1, src2, cond);
+ }
+}
+
void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
@@ -691,18 +703,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_movi_i32(ret, 1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_movi_i32(ret, 0);
- } else {
- tcg_gen_op4i_i32(INDEX_op_setcond, ret, arg1, arg2, cond);
- }
-}
-
void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, int32_t arg2)
{
@@ -1481,18 +1481,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_movi_i64(ret, 1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_movi_i64(ret, 0);
- } else {
- tcg_gen_op4i_i64(INDEX_op_setcond, ret, arg1, arg2, cond);
- }
-}
-
void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, int64_t arg2)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 046/101] tcg: Generic expansion of tcg_gen_setcondi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (44 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 045/101] tcg: Generic expansion of tcg_gen_setcond_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:05 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 047/101] tcg: Generic expansion of tcg_gen_negsetcond_* Richard Henderson
` (54 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ----
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 18 ++++++------------
3 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 66b72a498e1..54c2528b3aa 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,8 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, int32_t arg2);
void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
@@ -215,8 +213,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, int64_t arg2);
void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 4934f117bbe..92a35e83f81 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -28,6 +28,7 @@ DEF3(remu, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
+DEF4(setcondi, TCGCond, TCGV, TCGV, TINT)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f8ded81ed84..069926ce3cb 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -635,6 +635,12 @@ void tcg_gen_setcond(TCGType type, TCGCond cond, TCGTemp *dst,
}
}
+void tcg_gen_setcondi(TCGType type, TCGCond cond, TCGTemp *dst,
+ TCGTemp *src1, int64_t src2)
+{
+ tcg_gen_setcond(type, cond, dst, src1, tcg_constant_internal(type, src2));
+}
+
void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
@@ -703,12 +709,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, int32_t arg2)
-{
- tcg_gen_setcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
-}
-
void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, TCGv_i32 arg2)
{
@@ -1481,12 +1481,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, int64_t arg2)
-{
- tcg_gen_setcond_i64(cond, ret, arg1, tcg_constant_i64(arg2));
-}
-
void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, int64_t arg2)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 047/101] tcg: Generic expansion of tcg_gen_negsetcond_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (45 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 046/101] tcg: Generic expansion of tcg_gen_setcondi_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:06 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 048/101] tcg: Generic expansion of tcg_gen_negsetcondi_* Richard Henderson
` (53 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ----
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 36 ++++++++++++------------------------
3 files changed, 13 insertions(+), 28 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 54c2528b3aa..e752dc977f8 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,8 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, int32_t arg2);
void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1,
@@ -213,8 +211,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
TCGv_i64 arg1, int64_t arg2);
void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 92a35e83f81..1ab2c69cbe1 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -18,6 +18,7 @@ DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
+DEF4(negsetcond, TCGCond, TCGV, TCGV, TCGV)
DEF3(nor, TCGV, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 069926ce3cb..82917d148a3 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -519,6 +519,18 @@ void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_op_tt(INDEX_op_neg, type, dst, src);
}
+void tcg_gen_negsetcond(TCGType type, TCGCond cond, TCGTemp *dst,
+ TCGTemp *src1, TCGTemp *src2)
+{
+ if (cond == TCG_COND_ALWAYS) {
+ tcg_gen_movi(type, dst, -1);
+ } else if (cond == TCG_COND_NEVER) {
+ tcg_gen_movi(type, dst, 0);
+ } else {
+ tcg_gen_op_ttti(INDEX_op_negsetcond, type, dst, src1, src2, cond);
+ }
+}
+
void tcg_gen_nor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_nor, type, 0)) {
@@ -709,18 +721,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_negsetcond_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_movi_i32(ret, -1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_movi_i32(ret, 0);
- } else {
- tcg_gen_op4i_i32(INDEX_op_negsetcond, ret, arg1, arg2, cond);
- }
-}
-
void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
TCGv_i32 arg1, int32_t arg2)
{
@@ -1487,18 +1487,6 @@ void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
tcg_gen_negsetcond_i64(cond, ret, arg1, tcg_constant_i64(arg2));
}
-void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_movi_i64(ret, -1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_movi_i64(ret, 0);
- } else {
- tcg_gen_op4i_i64(INDEX_op_negsetcond, ret, arg1, arg2, cond);
- }
-}
-
void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 8);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 048/101] tcg: Generic expansion of tcg_gen_negsetcondi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (46 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 047/101] tcg: Generic expansion of tcg_gen_negsetcond_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:06 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 049/101] tcg: Generic expansion of tcg_gen_movcond_* Richard Henderson
` (52 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ----
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 19 +++++++------------
3 files changed, 8 insertions(+), 16 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index e752dc977f8..7dd50bfae77 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,8 +146,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, int32_t arg2);
void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1,
TCGv_i32 c2, TCGv_i32 v1, TCGv_i32 v2);
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
@@ -211,8 +209,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, int64_t arg2);
void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1,
TCGv_i64 c2, TCGv_i64 v1, TCGv_i64 v2);
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 1ab2c69cbe1..846b781c836 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -19,6 +19,7 @@ DEF3(muli, TCGV, TCGV, TINT)
DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF4(negsetcond, TCGCond, TCGV, TCGV, TCGV)
+DEF4(negsetcondi, TCGCond, TCGV, TCGV, TINT)
DEF3(nor, TCGV, TCGV, TCGV)
DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 82917d148a3..a12ed17f3da 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -531,6 +531,13 @@ void tcg_gen_negsetcond(TCGType type, TCGCond cond, TCGTemp *dst,
}
}
+void tcg_gen_negsetcondi(TCGType type, TCGCond cond, TCGTemp *dst,
+ TCGTemp *src1, int64_t src2)
+{
+ tcg_gen_negsetcond(type, cond, dst, src1,
+ tcg_constant_internal(type, src2));
+}
+
void tcg_gen_nor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_nor, type, 0)) {
@@ -721,12 +728,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret,
- TCGv_i32 arg1, int32_t arg2)
-{
- tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
-}
-
void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I32, 0)) {
@@ -1481,12 +1482,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_negsetcondi_i64(TCGCond cond, TCGv_i64 ret,
- TCGv_i64 arg1, int64_t arg2)
-{
- tcg_gen_negsetcond_i64(cond, ret, arg1, tcg_constant_i64(arg2));
-}
-
void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 8);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 049/101] tcg: Generic expansion of tcg_gen_movcond_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (47 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 048/101] tcg: Generic expansion of tcg_gen_negsetcondi_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 16:08 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 050/101] tcg: Split out tcg_gen_ext{rl,rh,s,u} Richard Henderson
` (51 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 7 ++---
tcg/tcg-internal.h | 11 +++++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 58 +++++++++++-------------------------
4 files changed, 33 insertions(+), 44 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 7dd50bfae77..c6b8af46de4 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -100,6 +100,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3);
#define DEF4(NAME, T1, T2, T3, T4) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4);
+#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6);
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -123,6 +125,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF6
/* 32 bit ops */
@@ -146,8 +149,6 @@ void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
-void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1,
- TCGv_i32 c2, TCGv_i32 v1, TCGv_i32 v2);
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
@@ -209,8 +210,6 @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
-void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1,
- TCGv_i64 c2, TCGv_i64 v1, TCGv_i64 v2);
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 0de8516447f..cd5028104a8 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -134,6 +134,14 @@ static inline void tcg_gen_op_ttttt(TCGOpcode opc, TCGType type,
temp_arg(t3), temp_arg(t4));
}
+static inline void tcg_gen_op_ttttti(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
+ TCGTemp *t3, TCGTemp *t4, TCGArg a5)
+{
+ tcg_gen_op6(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2),
+ temp_arg(t3), temp_arg(t4), a5);
+}
+
QEMU_RET_ARG_NONNULL
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
TCGOpcode, TCGType, unsigned nargs);
@@ -158,6 +166,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3);
#define DEF4(NAME, T1, T2, T3, T4) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4);
+#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
#define TCGV TCGTemp *
#define TINT int64_t
@@ -171,5 +181,6 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF6
#endif /* TCG_INTERNAL_H */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 846b781c836..a1c1e9b9186 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -14,6 +14,7 @@ DEF3(divu, TCGV, TCGV, TCGV)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
+DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
DEF3(nand, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a12ed17f3da..35cffc6447a 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -225,22 +225,6 @@ static void DNI tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
tcgv_i64_arg(a3), a4, a5);
}
-static void DNI tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGv_i32 a3, TCGv_i32 a4,
- TCGv_i32 a5, TCGArg a6)
-{
- tcg_gen_op6(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
- tcgv_i32_arg(a3), tcgv_i32_arg(a4), tcgv_i32_arg(a5), a6);
-}
-
-static void DNI tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGv_i64 a3, TCGv_i64 a4,
- TCGv_i64 a5, TCGArg a6)
-{
- tcg_gen_op6(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
- tcgv_i64_arg(a3), tcgv_i64_arg(a4), tcgv_i64_arg(a5), a6);
-}
-
/* Generic ops. */
void gen_set_label(TCGLabel *l)
@@ -312,6 +296,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), \
glue(C_,T3)(c), glue(C_,T4)(d)); }
+#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), glue(C_,T3)(c), \
+ glue(C_,T4)(d), glue(C_,T5)(e), glue(C_,T6)(f)); }
+
#define C_TCGv_i32 tcgv_i32_temp
#define C_TCGv_i64 tcgv_i64_temp
#define C_int32_t
@@ -352,6 +341,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF6
/*
* Generic expansions for templated operations.
@@ -488,6 +478,18 @@ void tcg_gen_movi(TCGType type, TCGTemp *dst, int64_t src)
tcg_gen_op_tt(INDEX_op_mov, type, dst, tcg_constant_internal(type, src));
}
+void tcg_gen_movcond(TCGType type, TCGCond cond, TCGTemp *dst,
+ TCGTemp *c1, TCGTemp *c2, TCGTemp *v1, TCGTemp *v2)
+{
+ if (cond == TCG_COND_ALWAYS) {
+ tcg_gen_mov(type, dst, v1);
+ } else if (cond == TCG_COND_NEVER) {
+ tcg_gen_mov(type, dst, v2);
+ } else {
+ tcg_gen_op_ttttti(INDEX_op_movcond, type, dst, c1, c2, v1, v2, cond);
+ }
+}
+
void tcg_gen_mul(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_mul, type, dst, src1, src2);
@@ -1037,18 +1039,6 @@ void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
}
}
-void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1,
- TCGv_i32 c2, TCGv_i32 v1, TCGv_i32 v2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_mov_i32(ret, v1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_mov_i32(ret, v2);
- } else {
- tcg_gen_op6i_i32(INDEX_op_movcond, ret, c1, c2, v1, v2, cond);
- }
-}
-
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
{
@@ -1962,18 +1952,6 @@ void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
}
}
-void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1,
- TCGv_i64 c2, TCGv_i64 v1, TCGv_i64 v2)
-{
- if (cond == TCG_COND_ALWAYS) {
- tcg_gen_mov_i64(ret, v1);
- } else if (cond == TCG_COND_NEVER) {
- tcg_gen_mov_i64(ret, v2);
- } else {
- tcg_gen_op6i_i64(INDEX_op_movcond, ret, c1, c2, v1, v2, cond);
- }
-}
-
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 050/101] tcg: Split out tcg_gen_ext{rl,rh,s,u}
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (48 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 049/101] tcg: Generic expansion of tcg_gen_movcond_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 051/101] tcg: Generic expansion of tcg_gen_clz_* Richard Henderson
` (50 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
We'll need these for other generic expansions.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-internal.h | 20 ++++++++++++++++++++
tcg/tcg-op.c | 12 ++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index cd5028104a8..a0edf112927 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -183,4 +183,24 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF4
#undef DEF6
+static inline void tcg_gen_extrh(TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_op_tt(INDEX_op_extrh_i64_i32, TCG_TYPE_I32, dst, src);
+}
+
+static inline void tcg_gen_extrl(TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_op_tt(INDEX_op_extrl_i64_i32, TCG_TYPE_I32, dst, src);
+}
+
+static inline void tcg_gen_exts(TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_op_tt(INDEX_op_ext_i32_i64, TCG_TYPE_I64, dst, src);
+}
+
+static inline void tcg_gen_extu(TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_op_tt(INDEX_op_extu_i32_i64, TCG_TYPE_I64, dst, src);
+}
+
#endif /* TCG_INTERNAL_H */
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 35cffc6447a..6a5f77e9977 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -2200,26 +2200,22 @@ void tcg_gen_abs_i64(TCGv_i64 ret, TCGv_i64 a)
void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
{
- tcg_gen_op2(INDEX_op_extrl_i64_i32, TCG_TYPE_I32,
- tcgv_i32_arg(ret), tcgv_i64_arg(arg));
+ tcg_gen_extrl(tcgv_i32_temp(ret), tcgv_i64_temp(arg));
}
void tcg_gen_extrh_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
{
- tcg_gen_op2(INDEX_op_extrh_i64_i32, TCG_TYPE_I32,
- tcgv_i32_arg(ret), tcgv_i64_arg(arg));
+ tcg_gen_extrh(tcgv_i32_temp(ret), tcgv_i64_temp(arg));
}
void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
{
- tcg_gen_op2(INDEX_op_extu_i32_i64, TCG_TYPE_I64,
- tcgv_i64_arg(ret), tcgv_i32_arg(arg));
+ tcg_gen_extu(tcgv_i64_temp(ret), tcgv_i32_temp(arg));
}
void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
{
- tcg_gen_op2(INDEX_op_ext_i32_i64, TCG_TYPE_I64,
- tcgv_i64_arg(ret), tcgv_i32_arg(arg));
+ tcg_gen_exts(tcgv_i64_temp(ret), tcgv_i32_temp(arg));
}
void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 051/101] tcg: Generic expansion of tcg_gen_clz_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (49 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 050/101] tcg: Split out tcg_gen_ext{rl,rh,s,u} Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:49 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 052/101] tcg: Use signed integer for tcg_gen_{clz, ctz}i_{i32, i64} Richard Henderson
` (49 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 52 ++++++++++++++++--------------------
3 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index c6b8af46de4..f40c286a831 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
@@ -190,7 +189,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index a1c1e9b9186..74c68f46b76 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -8,6 +8,7 @@ DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
+DEF3(clz, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 6a5f77e9977..74e1e1aae2d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -422,6 +422,29 @@ void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
}
+void tcg_gen_clz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_clz, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_clz, type, dst, src1, src2);
+ } else if (type == TCG_TYPE_I64) {
+ gen_helper_clz_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(TCG_TYPE_I64);
+ g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(TCG_TYPE_I64);
+
+ tcg_gen_extu(t1, src1);
+ tcg_gen_extu(t2, src2);
+ tcg_gen_addi(TCG_TYPE_I64, t2, t2, 32);
+ tcg_gen_op_ttt(INDEX_op_clz, TCG_TYPE_I64, t1, t1, t2);
+ tcg_gen_extrl(dst, t1);
+ tcg_gen_addi(TCG_TYPE_I32, dst, dst, -32);
+ } else {
+ gen_helper_clz_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src1),
+ temp_tcgv_i32(src2));
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -730,26 +753,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_clz, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- TCGv_i64 t2 = tcg_temp_ebb_new_i64();
- tcg_gen_extu_i32_i64(t1, arg1);
- tcg_gen_extu_i32_i64(t2, arg2);
- tcg_gen_addi_i64(t2, t2, 32);
- tcg_gen_clz_i64(t1, t1, t2);
- tcg_gen_extrl_i64_i32(ret, t1);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
- tcg_gen_subi_i32(ret, ret, 32);
- } else {
- gen_helper_clz_i32(ret, arg1, arg2);
- }
-}
-
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
{
tcg_gen_clz_i32(ret, arg1, tcg_constant_i32(arg2));
@@ -1671,15 +1674,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_clz, ret, arg1, arg2);
- } else {
- gen_helper_clz_i64(ret, arg1, arg2);
- }
-}
-
void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
{
tcg_gen_clz_i64(ret, arg1, tcg_constant_i64(arg2));
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 052/101] tcg: Use signed integer for tcg_gen_{clz, ctz}i_{i32, i64}
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (50 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 051/101] tcg: Generic expansion of tcg_gen_clz_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:50 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 053/101] tcg: Generic expansion of tcg_gen_clzi_* Richard Henderson
` (48 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
We use signed integers for all other functions, and the
sign of the second source is not meaningful here.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 8 ++++----
tcg/tcg-op.c | 8 ++++----
target/ppc/translate/fixedpoint-impl.c.inc | 4 ++--
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index f40c286a831..40a7f94040c 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -130,8 +130,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
-void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
+void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
+void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ctpop_i32(TCGv_i32 a1, TCGv_i32 a2);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -190,8 +190,8 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
-void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
+void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
+void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ctpop_i64(TCGv_i64 a1, TCGv_i64 a2);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 74e1e1aae2d..1231cb4ca0e 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -753,7 +753,7 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
+void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_gen_clz_i32(ret, arg1, tcg_constant_i32(arg2));
}
@@ -798,7 +798,7 @@ void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_temp_free_i32(t);
}
-void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
+void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
if (arg2 == 32
&& !tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I32, 0)
@@ -1674,7 +1674,7 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
+void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
tcg_gen_clz_i64(ret, arg1, tcg_constant_i64(arg2));
}
@@ -1708,7 +1708,7 @@ void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_temp_free_i64(t);
}
-void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
+void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
if (arg2 == 64
&& !tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0)
diff --git a/target/ppc/translate/fixedpoint-impl.c.inc b/target/ppc/translate/fixedpoint-impl.c.inc
index c3d8bbf2670..5195db4e9a3 100644
--- a/target/ppc/translate/fixedpoint-impl.c.inc
+++ b/target/ppc/translate/fixedpoint-impl.c.inc
@@ -1551,7 +1551,7 @@ static bool trans_CMPB(DisasContext *ctx, arg_CMPB *a)
}
static bool do_cntzw(DisasContext *ctx, arg_X_sa_rc *a,
- void (*helper)(TCGv_i32, TCGv_i32, uint32_t))
+ void (*helper)(TCGv_i32, TCGv_i32, int32_t))
{
TCGv_i32 t = tcg_temp_new_i32();
@@ -1567,7 +1567,7 @@ static bool do_cntzw(DisasContext *ctx, arg_X_sa_rc *a,
#if defined(TARGET_PPC64)
static bool do_cntzd(DisasContext *ctx, arg_X_sa_rc *a,
- void (*helper)(TCGv_i64, TCGv_i64, uint64_t))
+ void (*helper)(TCGv_i64, TCGv_i64, int64_t))
{
helper(cpu_gpr[a->ra], cpu_gpr[a->rs], 64);
if (unlikely(a->rc)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 052/101] tcg: Use signed integer for tcg_gen_{clz, ctz}i_{i32, i64}
2026-09-27 8:59 ` [PATCH v5 052/101] tcg: Use signed integer for tcg_gen_{clz, ctz}i_{i32, i64} Richard Henderson
@ 2026-09-29 12:50 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:50 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> We use signed integers for all other functions, and the
> sign of the second source is not meaningful here.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 8 ++++----
> tcg/tcg-op.c | 8 ++++----
> target/ppc/translate/fixedpoint-impl.c.inc | 4 ++--
> 3 files changed, 10 insertions(+), 10 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 053/101] tcg: Generic expansion of tcg_gen_clzi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (51 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 052/101] tcg: Use signed integer for tcg_gen_{clz, ctz}i_{i32, i64} Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:54 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_* Richard Henderson
` (47 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 40a7f94040c..acdd31dbeaf 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -130,7 +130,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ctpop_i32(TCGv_i32 a1, TCGv_i32 a2);
@@ -190,7 +189,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ctpop_i64(TCGv_i64 a1, TCGv_i64 a2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 74c68f46b76..cf832a6dc07 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -9,6 +9,7 @@ DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
DEF3(clz, TCGV, TCGV, TCGV)
+DEF3(clzi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 1231cb4ca0e..f168386f46b 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -445,6 +445,11 @@ void tcg_gen_clz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_clzi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_gen_clz(type, dst, src1, tcg_constant_internal(type, src2));
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -753,11 +758,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_gen_clz_i32(ret, arg1, tcg_constant_i32(arg2));
-}
-
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
TCGv_i32 z, t;
@@ -1674,11 +1674,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_gen_clz_i64(ret, arg1, tcg_constant_i64(arg2));
-}
-
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
TCGv_i64 z, t;
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (52 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 053/101] tcg: Generic expansion of tcg_gen_clzi_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:51 ` Philippe Mathieu-Daudé
2026-09-29 23:37 ` Matt Turner
2026-09-27 8:59 ` [PATCH v5 055/101] tcg: Generic expansion of tcg_gen_ctz_* Richard Henderson
` (46 subsequent siblings)
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 41 +++++++++++++++---------------------
3 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index acdd31dbeaf..7f977661b3d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_ctpop_i32(TCGv_i32 a1, TCGv_i32 a2);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -191,7 +190,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ctpop_i64(TCGv_i64 a1, TCGv_i64 a2);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index cf832a6dc07..66977cada1f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -10,6 +10,7 @@ DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
DEF3(clz, TCGV, TCGV, TCGV)
DEF3(clzi, TCGV, TCGV, TINT)
+DEF2(ctpop, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f168386f46b..86dae114859 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -450,6 +450,23 @@ void tcg_gen_clzi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
tcg_gen_clz(type, dst, src1, tcg_constant_internal(type, src2));
}
+void tcg_gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ if (tcg_op_supported(INDEX_op_ctpop, type, 0)) {
+ tcg_gen_op_tt(INDEX_op_ctpop, type, dst, src);
+ } else if (type == TCG_TYPE_I64) {
+ gen_helper_ctpop_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
+ } else if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(TCG_TYPE_I64);
+
+ tcg_gen_extu(tmp, src);
+ tcg_gen_op_tt(INDEX_op_ctpop, TCG_TYPE_I64, tmp, src);
+ tcg_gen_extrl(dst, tmp);
+ } else {
+ gen_helper_ctpop_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -828,21 +845,6 @@ void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_ctpop_i32(TCGv_i32 ret, TCGv_i32 arg1)
-{
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I32, 0)) {
- tcg_gen_op2_i32(INDEX_op_ctpop, ret, arg1);
- } else if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- tcg_gen_extu_i32_i64(t, arg1);
- tcg_gen_ctpop_i64(t, t);
- tcg_gen_extrl_i64_i32(ret, t);
- tcg_temp_free_i64(t);
- } else {
- gen_helper_ctpop_i32(ret, arg1);
- }
-}
-
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
@@ -1733,15 +1735,6 @@ void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_ctpop_i64(TCGv_i64 ret, TCGv_i64 arg1)
-{
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
- tcg_gen_op2_i64(INDEX_op_ctpop, ret, arg1);
- } else {
- gen_helper_ctpop_i64(ret, arg1);
- }
-}
-
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_*
2026-09-27 8:59 ` [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_* Richard Henderson
@ 2026-09-29 12:51 ` Philippe Mathieu-Daudé
2026-09-29 23:37 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:51 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 41 +++++++++++++++---------------------
> 3 files changed, 18 insertions(+), 26 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_*
2026-09-27 8:59 ` [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_* Richard Henderson
2026-09-29 12:51 ` Philippe Mathieu-Daudé
@ 2026-09-29 23:37 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:37 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:04 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 41 +++++++++++++++---------------------
> 3 files changed, 18 insertions(+), 26 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index acdd31dbeaf..7f977661b3d 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
> -void tcg_gen_ctpop_i32(TCGv_i32 a1, TCGv_i32 a2);
> void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
> void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
> @@ -191,7 +190,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
> void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
> -void tcg_gen_ctpop_i64(TCGv_i64 a1, TCGv_i64 a2);
> void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
> void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index cf832a6dc07..66977cada1f 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -10,6 +10,7 @@ DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
> DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
> DEF3(clz, TCGV, TCGV, TCGV)
> DEF3(clzi, TCGV, TCGV, TINT)
> +DEF2(ctpop, TCGV, TCGV)
> DEF1(discard, TCGV)
> DEF3(div, TCGV, TCGV, TCGV)
> DEF3(divu, TCGV, TCGV, TCGV)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index f168386f46b..86dae114859 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -450,6 +450,23 @@ void tcg_gen_clzi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> tcg_gen_clz(type, dst, src1, tcg_constant_internal(type, src2));
> }
>
> +void tcg_gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp *src)
> +{
> + if (tcg_op_supported(INDEX_op_ctpop, type, 0)) {
> + tcg_gen_op_tt(INDEX_op_ctpop, type, dst, src);
> + } else if (type == TCG_TYPE_I64) {
> + gen_helper_ctpop_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
> + } else if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
> + g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(TCG_TYPE_I64);
> +
> + tcg_gen_extu(tmp, src);
> + tcg_gen_op_tt(INDEX_op_ctpop, TCG_TYPE_I64, tmp, src);
ctpop should read tmp instead of src, right? Otherwise the extu
immediately above is dead.
> + tcg_gen_extrl(dst, tmp);
> + } else {
> + gen_helper_ctpop_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
> + }
> +}
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 055/101] tcg: Generic expansion of tcg_gen_ctz_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (53 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 054/101] tcg: Generic expansion of tcg_gen_ctpop_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 056/101] tcg: Generic expansion of tcg_gen_ctzi_* Richard Henderson
` (45 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 115 ++++++++++++++---------------------
3 files changed, 47 insertions(+), 71 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 7f977661b3d..94c2a3d1682 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -187,7 +186,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 66977cada1f..2436fea04dc 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -11,6 +11,7 @@ DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
DEF3(clz, TCGV, TCGV, TCGV)
DEF3(clzi, TCGV, TCGV, TINT)
DEF2(ctpop, TCGV, TCGV)
+DEF3(ctz, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 86dae114859..1c0c1566d92 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -467,6 +467,52 @@ void tcg_gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp *src)
}
}
+void tcg_gen_ctz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ g_autoptr(TCGTemp) t1 = NULL;
+
+ if (tcg_op_supported(INDEX_op_ctz, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_ctz, type, dst, src1, src2);
+ return;
+ }
+ if (tcg_op_supported(INDEX_op_ctpop, type, 0)) {
+ t1 = tcg_temp_new_ebb(type);
+ tcg_gen_addi(type, t1, src1, -1);
+ tcg_gen_andc(type, t1, t1, src1);
+ tcg_gen_ctpop(type, t1, t1);
+ } else if (tcg_op_supported(INDEX_op_clz, type, 0)) {
+ int width = tcg_type_size(type) * 8;
+
+ t1 = tcg_temp_new_ebb(type);
+ tcg_gen_neg(type, t1, src1);
+ tcg_gen_and(type, t1, t1, src1);
+ tcg_gen_clzi(type, t1, t1, width);
+ tcg_gen_xori(type, t1, t1, width - 1);
+ } else if (type == TCG_TYPE_I64) {
+ gen_helper_ctz_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ return;
+ } else if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0) ||
+ tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0) ||
+ tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
+ g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(TCG_TYPE_I64);
+
+ t1 = tcg_temp_new_ebb(TCG_TYPE_I64);
+ tcg_gen_extu(t1, src1);
+ tcg_gen_extu(t2, src2);
+ tcg_gen_ctz(TCG_TYPE_I64, t1, t1, t2);
+ tcg_gen_extrl(dst, t1);
+ return;
+ } else {
+ gen_helper_ctz_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src1),
+ temp_tcgv_i32(src2));
+ return;
+ }
+
+ tcg_gen_movcond(type, TCG_COND_EQ, dst, src1,
+ tcg_constant_internal(type, 0), src2, t1);
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -775,46 +821,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- TCGv_i32 z, t;
-
- if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_ctz, ret, arg1, arg2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0)) {
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- TCGv_i64 t2 = tcg_temp_ebb_new_i64();
- tcg_gen_extu_i32_i64(t1, arg1);
- tcg_gen_extu_i32_i64(t2, arg2);
- tcg_gen_ctz_i64(t1, t1, t2);
- tcg_gen_extrl_i64_i32(ret, t1);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_REG, 0)) {
- t = tcg_temp_ebb_new_i32();
- tcg_gen_subi_i32(t, arg1, 1);
- tcg_gen_andc_i32(t, t, arg1);
- tcg_gen_ctpop_i32(t, t);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
- t = tcg_temp_ebb_new_i32();
- tcg_gen_neg_i32(t, arg1);
- tcg_gen_and_i32(t, t, arg1);
- tcg_gen_clzi_i32(t, t, 32);
- tcg_gen_xori_i32(t, t, 31);
- } else {
- gen_helper_ctz_i32(ret, arg1, arg2);
- return;
- }
-
- z = tcg_constant_i32(0);
- tcg_gen_movcond_i32(TCG_COND_EQ, ret, arg1, z, arg2, t);
- tcg_temp_free_i32(t);
-}
-
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
if (arg2 == 32
@@ -1676,35 +1682,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- TCGv_i64 z, t;
-
- if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_ctz, ret, arg1, arg2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
- t = tcg_temp_ebb_new_i64();
- tcg_gen_subi_i64(t, arg1, 1);
- tcg_gen_andc_i64(t, t, arg1);
- tcg_gen_ctpop_i64(t, t);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- t = tcg_temp_ebb_new_i64();
- tcg_gen_neg_i64(t, arg1);
- tcg_gen_and_i64(t, t, arg1);
- tcg_gen_clzi_i64(t, t, 64);
- tcg_gen_xori_i64(t, t, 63);
- } else {
- gen_helper_ctz_i64(ret, arg1, arg2);
- return;
- }
-
- z = tcg_constant_i64(0);
- tcg_gen_movcond_i64(TCG_COND_EQ, ret, arg1, z, arg2, t);
- tcg_temp_free_i64(t);
-}
-
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
if (arg2 == 64
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 056/101] tcg: Generic expansion of tcg_gen_ctzi_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (54 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 055/101] tcg: Generic expansion of tcg_gen_ctz_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 057/101] tcg: Generic expansion of tcg_gen_clrsb_* Richard Henderson
` (44 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 45 +++++++++---------------------------
3 files changed, 12 insertions(+), 36 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 94c2a3d1682..ede4743b1ae 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -186,7 +185,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 2436fea04dc..7ee00c9d53e 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -12,6 +12,7 @@ DEF3(clz, TCGV, TCGV, TCGV)
DEF3(clzi, TCGV, TCGV, TINT)
DEF2(ctpop, TCGV, TCGV)
DEF3(ctz, TCGV, TCGV, TCGV)
+DEF3(ctzi, TCGV, TCGV, TINT)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 1c0c1566d92..3498be09e70 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -470,6 +470,7 @@ void tcg_gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp *src)
void tcg_gen_ctz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
g_autoptr(TCGTemp) t1 = NULL;
+ int width = tcg_type_size(type) * 8;
if (tcg_op_supported(INDEX_op_ctz, type, 0)) {
tcg_gen_op_ttt(INDEX_op_ctz, type, dst, src1, src2);
@@ -479,10 +480,13 @@ void tcg_gen_ctz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
t1 = tcg_temp_new_ebb(type);
tcg_gen_addi(type, t1, src1, -1);
tcg_gen_andc(type, t1, t1, src1);
+ if (src2->kind == TEMP_CONST && src2->val == width) {
+ /* No fixup required. */
+ tcg_gen_ctpop(type, dst, t1);
+ return;
+ }
tcg_gen_ctpop(type, t1, t1);
} else if (tcg_op_supported(INDEX_op_clz, type, 0)) {
- int width = tcg_type_size(type) * 8;
-
t1 = tcg_temp_new_ebb(type);
tcg_gen_neg(type, t1, src1);
tcg_gen_and(type, t1, t1, src1);
@@ -513,6 +517,11 @@ void tcg_gen_ctz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
tcg_constant_internal(type, 0), src2, t1);
}
+void tcg_gen_ctzi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ tcg_gen_ctz(type, dst, src1, tcg_constant_internal(type, src2));
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -821,22 +830,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- if (arg2 == 32
- && !tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I32, 0)
- && tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_REG, 0)) {
- /* This equivalence has the advantage of not requiring a fixup. */
- TCGv_i32 t = tcg_temp_ebb_new_i32();
- tcg_gen_subi_i32(t, arg1, 1);
- tcg_gen_andc_i32(t, t, arg1);
- tcg_gen_ctpop_i32(ret, t);
- tcg_temp_free_i32(t);
- } else {
- tcg_gen_ctz_i32(ret, arg1, tcg_constant_i32(arg2));
- }
-}
-
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
@@ -1682,22 +1675,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- if (arg2 == 64
- && !tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0)
- && tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
- /* This equivalence has the advantage of not requiring a fixup. */
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- tcg_gen_subi_i64(t, arg1, 1);
- tcg_gen_andc_i64(t, t, arg1);
- tcg_gen_ctpop_i64(ret, t);
- tcg_temp_free_i64(t);
- } else {
- tcg_gen_ctz_i64(ret, arg1, tcg_constant_i64(arg2));
- }
-}
-
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 057/101] tcg: Generic expansion of tcg_gen_clrsb_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (55 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 056/101] tcg: Generic expansion of tcg_gen_ctzi_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:52 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 058/101] tcg: Generic expansion of tcg_gen_rotl_* Richard Henderson
` (43 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 45 ++++++++++++++----------------------
3 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ede4743b1ae..d19feb49cbc 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -185,7 +184,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 7ee00c9d53e..ef0ac5aece3 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -8,6 +8,7 @@ DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
+DEF2(clrsb, TCGV, TCGV)
DEF3(clz, TCGV, TCGV, TCGV)
DEF3(clzi, TCGV, TCGV, TINT)
DEF2(ctpop, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 3498be09e70..5ee49e2553d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -422,6 +422,23 @@ void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
}
+void tcg_gen_clrsb(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+ int width = tcg_type_size(type) * 8;
+
+ tcg_gen_sari(type, tmp, src, width - 1);
+ tcg_gen_xor(type, tmp, tmp, src);
+ tcg_gen_clzi(type, tmp, tmp, width);
+ tcg_gen_addi(type, dst, tmp, -1);
+ } else if (type == TCG_TYPE_I32) {
+ gen_helper_clrsb_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
+ } else {
+ gen_helper_clrsb_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
+ }
+}
+
void tcg_gen_clz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_clz, type, 0)) {
@@ -830,20 +847,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
- TCGv_i32 t = tcg_temp_ebb_new_i32();
- tcg_gen_sari_i32(t, arg, 31);
- tcg_gen_xor_i32(t, t, arg);
- tcg_gen_clzi_i32(t, t, 32);
- tcg_gen_subi_i32(ret, t, 1);
- tcg_temp_free_i32(t);
- } else {
- gen_helper_clrsb_i32(ret, arg);
- }
-}
-
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
@@ -1675,20 +1678,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- tcg_gen_sari_i64(t, arg, 63);
- tcg_gen_xor_i64(t, t, arg);
- tcg_gen_clzi_i64(t, t, 64);
- tcg_gen_subi_i64(ret, t, 1);
- tcg_temp_free_i64(t);
- } else {
- gen_helper_clrsb_i64(ret, arg);
- }
-}
-
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 057/101] tcg: Generic expansion of tcg_gen_clrsb_*
2026-09-27 8:59 ` [PATCH v5 057/101] tcg: Generic expansion of tcg_gen_clrsb_* Richard Henderson
@ 2026-09-29 12:52 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:52 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 45 ++++++++++++++----------------------
> 3 files changed, 18 insertions(+), 30 deletions(-)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 3498be09e70..5ee49e2553d 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -422,6 +422,23 @@ void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
> tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
> }
>
> +void tcg_gen_clrsb(TCGType type, TCGTemp *dst, TCGTemp *src)
> +{
> + if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
> + g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
> + int width = tcg_type_size(type) * 8;
tcg_type_bits()
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> + tcg_gen_sari(type, tmp, src, width - 1);
> + tcg_gen_xor(type, tmp, tmp, src);
> + tcg_gen_clzi(type, tmp, tmp, width);
> + tcg_gen_addi(type, dst, tmp, -1);
> + } else if (type == TCG_TYPE_I32) {
> + gen_helper_clrsb_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
> + } else {
> + gen_helper_clrsb_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
> + }
> +}
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 058/101] tcg: Generic expansion of tcg_gen_rotl_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (56 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 057/101] tcg: Generic expansion of tcg_gen_clrsb_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:53 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 059/101] tcg: Generic expansion of tcg_gen_rotr_* Richard Henderson
` (42 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 62 ++++++++++++------------------------
3 files changed, 21 insertions(+), 44 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index d19feb49cbc..1a028da36b5 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
@@ -184,7 +183,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index ef0ac5aece3..f832e286aba 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -34,6 +34,7 @@ DEF3(ori, TCGV, TCGV, TINT)
DEF3(orc, TCGV, TCGV, TCGV)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
+DEF3(rotl, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 5ee49e2553d..37ee848f24d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -746,6 +746,26 @@ void tcg_gen_remu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_rotl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rotl, type, dst, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_rotr, type, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_neg(type, tmp, src2);
+ tcg_gen_op_ttt(INDEX_op_rotr, type, dst, src1, tmp);
+ } else {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ tcg_gen_shl(type, t0, src1, src2);
+ tcg_gen_neg(type, t1, src2);
+ tcg_gen_shr(type, t1, src1, t1);
+ tcg_gen_or(type, dst, t0, t1);
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -847,27 +867,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_neg_i32(t0, arg2);
- tcg_gen_op3_i32(INDEX_op_rotr, ret, arg1, t0);
- tcg_temp_free_i32(t0);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- tcg_gen_shl_i32(t0, arg1, arg2);
- tcg_gen_neg_i32(t1, arg2);
- tcg_gen_shr_i32(t1, arg1, t1);
- tcg_gen_or_i32(ret, t0, t1);
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1678,27 +1677,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_neg_i64(t0, arg2);
- tcg_gen_op3_i64(INDEX_op_rotr, ret, arg1, t0);
- tcg_temp_free_i64(t0);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_shl_i64(t0, arg1, arg2);
- tcg_gen_neg_i64(t1, arg2);
- tcg_gen_shr_i64(t1, arg1, t1);
- tcg_gen_or_i64(ret, t0, t1);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 64);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 059/101] tcg: Generic expansion of tcg_gen_rotr_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (57 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 058/101] tcg: Generic expansion of tcg_gen_rotl_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:54 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 060/101] tcg: Generic expansion of tcg_gen_rotri_* Richard Henderson
` (41 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 62 ++++++++++++------------------------
3 files changed, 21 insertions(+), 44 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 1a028da36b5..eb860ff8c9e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -130,7 +130,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
-void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
unsigned int ofs, unsigned int len);
@@ -184,7 +183,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
-void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
unsigned int ofs, unsigned int len);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index f832e286aba..84ef1d53782 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -35,6 +35,7 @@ DEF3(orc, TCGV, TCGV, TCGV)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF3(rotl, TCGV, TCGV, TCGV)
+DEF3(rotr, TCGV, TCGV, TCGV)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 37ee848f24d..6414b3b627c 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -766,6 +766,26 @@ void tcg_gen_rotl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_rotr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_rotr, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rotr, type, dst, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_neg(type, tmp, src2);
+ tcg_gen_op_ttt(INDEX_op_rotl, type, dst, src1, tmp);
+ } else {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ tcg_gen_shr(type, t0, src1, src2);
+ tcg_gen_neg(type, t1, src2);
+ tcg_gen_shl(type, t1, src1, t1);
+ tcg_gen_or(type, dst, t0, t1);
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -879,27 +899,6 @@ void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
}
}
-void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rotr, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_neg_i32(t0, arg2);
- tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, t0);
- tcg_temp_free_i32(t0);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- tcg_gen_shr_i32(t0, arg1, arg2);
- tcg_gen_neg_i32(t1, arg2);
- tcg_gen_shl_i32(t1, arg1, t1);
- tcg_gen_or_i32(ret, t0, t1);
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 32);
@@ -1689,27 +1688,6 @@ void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
}
}
-void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rotr, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_neg_i64(t0, arg2);
- tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, t0);
- tcg_temp_free_i64(t0);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_shr_i64(t0, arg1, arg2);
- tcg_gen_neg_i64(t1, arg2);
- tcg_gen_shl_i64(t1, arg1, t1);
- tcg_gen_or_i64(ret, t0, t1);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
tcg_debug_assert(arg2 >= 0 && arg2 < 64);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 060/101] tcg: Generic expansion of tcg_gen_rotri_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (58 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 059/101] tcg: Generic expansion of tcg_gen_rotr_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 12:55 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 061/101] tcg: Generic expansion of tcg_gen_rotli_* Richard Henderson
` (40 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 49 ++++++++++++++----------------------
3 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index eb860ff8c9e..b27d6c7975a 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -130,7 +130,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
-void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
@@ -183,7 +182,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
-void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 84ef1d53782..88a8001601d 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -36,6 +36,7 @@ DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF3(rotl, TCGV, TCGV, TCGV)
DEF3(rotr, TCGV, TCGV, TCGV)
+DEF3(rotri, TCGV, TCGV, TINT)
DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 6414b3b627c..4c51428f935 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -786,6 +786,25 @@ void tcg_gen_rotr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_rotri(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ int width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(src2 >= 0 && src2 < width);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else if (tcg_op_supported(INDEX_op_rotr, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rotr, type, dst, src1,
+ tcg_constant_internal(type, src2));
+ } else if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rotl, type, dst, src1,
+ tcg_constant_internal(type, width - src2));
+ } else {
+ /* Do not recurse with the rotri simplification. */
+ tcg_gen_op_ttti(INDEX_op_extract2, type, dst, src1, src1, src2);
+ }
+}
+
void tcg_gen_sar(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sar, type, dst, src1, src2);
@@ -899,21 +918,6 @@ void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
}
}
-void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 32);
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rotr, ret, arg1, tcg_constant_i32(arg2));
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, tcg_constant_i32(32 - arg2));
- } else {
- /* Do not recurse with the rotri simplification. */
- tcg_gen_op4i_i32(INDEX_op_extract2, ret, arg1, arg1, arg2);
- }
-}
-
void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
unsigned int ofs, unsigned int len)
{
@@ -1688,21 +1692,6 @@ void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
}
}
-void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 64);
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rotr, ret, arg1, tcg_constant_i64(arg2));
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, tcg_constant_i64(64 - arg2));
- } else {
- /* Do not recurse with the rotri simplification. */
- tcg_gen_op4i_i64(INDEX_op_extract2, ret, arg1, arg1, arg2);
- }
-}
-
void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
unsigned int ofs, unsigned int len)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 060/101] tcg: Generic expansion of tcg_gen_rotri_*
2026-09-27 8:59 ` [PATCH v5 060/101] tcg: Generic expansion of tcg_gen_rotri_* Richard Henderson
@ 2026-09-29 12:55 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-29 12:55 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 49 ++++++++++++++----------------------
> 3 files changed, 20 insertions(+), 32 deletions(-)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 6414b3b627c..4c51428f935 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -786,6 +786,25 @@ void tcg_gen_rotr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> }
> }
>
> +void tcg_gen_rotri(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> +{
> + int width = tcg_type_size(type) * 8;
tcg_type_bits()
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> +
> + tcg_debug_assert(src2 >= 0 && src2 < width);
> + if (src2 == 0) {
> + tcg_gen_mov(type, dst, src1);
> + } else if (tcg_op_supported(INDEX_op_rotr, type, 0)) {
> + tcg_gen_op_ttt(INDEX_op_rotr, type, dst, src1,
> + tcg_constant_internal(type, src2));
> + } else if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
> + tcg_gen_op_ttt(INDEX_op_rotl, type, dst, src1,
> + tcg_constant_internal(type, width - src2));
> + } else {
> + /* Do not recurse with the rotri simplification. */
> + tcg_gen_op_ttti(INDEX_op_extract2, type, dst, src1, src1, src2);
> + }
> +}
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 061/101] tcg: Generic expansion of tcg_gen_rotli_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (59 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 060/101] tcg: Generic expansion of tcg_gen_rotri_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 062/101] tcg: Generic expansion of tcg_gen_deposit_* Richard Henderson
` (39 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 39 ++++++++++++++----------------------
3 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index b27d6c7975a..3eed9e6c2ed 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
@@ -181,7 +180,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 88a8001601d..9b88373ff23 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -35,6 +35,7 @@ DEF3(orc, TCGV, TCGV, TCGV)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF3(rotl, TCGV, TCGV, TCGV)
+DEF3(rotli, TCGV, TCGV, TINT)
DEF3(rotr, TCGV, TCGV, TCGV)
DEF3(rotri, TCGV, TCGV, TINT)
DEF3(sar, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 4c51428f935..dc6079a9e45 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -766,6 +766,21 @@ void tcg_gen_rotl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_rotli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
+{
+ int width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(src2 >= 0 && src2 < width);
+ if (src2 == 0) {
+ tcg_gen_mov(type, dst, src1);
+ } else if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_rotl, type, dst, src1,
+ tcg_constant_internal(type, src2));
+ } else {
+ tcg_gen_rotri(type, dst, src1, width - src2);
+ }
+}
+
void tcg_gen_rotr(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_rotr, type, 0)) {
@@ -906,18 +921,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 32);
- if (arg2 == 0) {
- tcg_gen_mov_i32(ret, arg1);
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, tcg_constant_i32(arg2));
- } else {
- tcg_gen_rotri_i32(ret, arg1, -arg2 & 31);
- }
-}
-
void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
unsigned int ofs, unsigned int len)
{
@@ -1680,18 +1683,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
-{
- tcg_debug_assert(arg2 >= 0 && arg2 < 64);
- if (arg2 == 0) {
- tcg_gen_mov_i64(ret, arg1);
- } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, tcg_constant_i64(arg2));
- } else {
- tcg_gen_rotri_i64(ret, arg1, -arg2 & 63);
- }
-}
-
void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
unsigned int ofs, unsigned int len)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 062/101] tcg: Generic expansion of tcg_gen_deposit_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (60 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 061/101] tcg: Generic expansion of tcg_gen_rotli_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 063/101] tcg: Generic expansion of tcg_gen_extract_* Richard Henderson
` (38 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 7 ++---
tcg/tcg-internal.h | 10 +++++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 55 ++++++++++++++++--------------------
4 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 3eed9e6c2ed..e3d6c9bfd8c 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -100,6 +100,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3);
#define DEF4(NAME, T1, T2, T3, T4) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4);
+#define DEF5(NAME, T1, T2, T3, T4, T5) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5);
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6);
@@ -125,12 +127,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF5
#undef DEF6
/* 32 bit ops */
-void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
- unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract_i32(TCGv_i32 ret, TCGv_i32 arg,
@@ -180,8 +181,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
- unsigned int ofs, unsigned int len);
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract_i64(TCGv_i64 ret, TCGv_i64 arg,
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index a0edf112927..13c4be5a5c7 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -126,6 +126,13 @@ static inline void tcg_gen_op_ttti(TCGOpcode opc, TCGType type, TCGTemp *t0,
tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2), a3);
}
+static inline void tcg_gen_op_tttii(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
+ TCGArg a3, TCGArg a4)
+{
+ tcg_gen_op5(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2), a3, a4);
+}
+
static inline void tcg_gen_op_ttttt(TCGOpcode opc, TCGType type,
TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
TCGTemp *t3, TCGTemp *t4)
@@ -166,6 +173,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3);
#define DEF4(NAME, T1, T2, T3, T4) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4);
+#define DEF5(NAME, T1, T2, T3, T4, T5) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5);
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
@@ -181,6 +190,7 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF5
#undef DEF6
static inline void tcg_gen_extrh(TCGTemp *dst, TCGTemp *src)
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 9b88373ff23..95885d28d83 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -14,6 +14,7 @@ DEF3(clzi, TCGV, TCGV, TINT)
DEF2(ctpop, TCGV, TCGV)
DEF3(ctz, TCGV, TCGV, TCGV)
DEF3(ctzi, TCGV, TCGV, TINT)
+DEF5(deposit, TCGV, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index dc6079a9e45..f5771240803 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -296,6 +296,11 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), \
glue(C_,T3)(c), glue(C_,T4)(d)); }
+#define DEF5(NAME, T1, T2, T3, T4, T5) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c, T4 d, T5 e) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), \
+ glue(C_,T3)(c), glue(C_,T4)(d), glue(C_,T5)(e)); }
+
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c, T4 d, T5 e, T6 f) \
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), glue(C_,T3)(c), \
@@ -307,6 +312,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#define C_int64_t
#define C_TCGCond
#define C_TCGLabelPtr
+#define C_unsigned
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -336,11 +342,13 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_int64_t
#undef C_TCGCond
#undef C_TCGLabelPtr
+#undef C_unsigned
#undef DEF1
#undef DEF2
#undef DEF3
#undef DEF4
+#undef DEF5
#undef DEF6
/*
@@ -539,6 +547,23 @@ void tcg_gen_ctzi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
tcg_gen_ctz(type, dst, src1, tcg_constant_internal(type, src2));
}
+void tcg_gen_deposit(TCGType type, TCGTemp *dst, TCGTemp *src1,
+ TCGTemp *src2, unsigned ofs, unsigned len)
+{
+ unsigned width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(ofs < width);
+ tcg_debug_assert(len > 0);
+ tcg_debug_assert(len <= width);
+ tcg_debug_assert(ofs + len <= width);
+
+ if (len == width) {
+ tcg_gen_mov(type, dst, src2);
+ } else {
+ tcg_gen_op_tttii(INDEX_op_deposit, type, dst, src1, src2, ofs, len);
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -921,21 +946,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 32);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 32);
- tcg_debug_assert(ofs + len <= 32);
-
- if (len == 32) {
- tcg_gen_mov_i32(ret, arg2);
- } else {
- tcg_gen_op5ii_i32(INDEX_op_deposit, ret, arg1, arg2, ofs, len);
- }
-}
-
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len)
{
@@ -1683,21 +1693,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 64);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 64);
- tcg_debug_assert(ofs + len <= 64);
-
- if (len == 64) {
- tcg_gen_mov_i64(ret, arg2);
- } else {
- tcg_gen_op5ii_i64(INDEX_op_deposit, ret, arg1, arg2, ofs, len);
- }
-}
-
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 063/101] tcg: Generic expansion of tcg_gen_extract_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (61 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 062/101] tcg: Generic expansion of tcg_gen_deposit_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 064/101] tcg: Generic expansion of tcg_gen_sextract_* Richard Henderson
` (37 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 131 ++++++++++++-----------------------
3 files changed, 46 insertions(+), 90 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index e3d6c9bfd8c..ec4cf775b38 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -134,8 +134,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
-void tcg_gen_extract_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
@@ -183,8 +181,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
-void tcg_gen_extract_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 95885d28d83..69f76f1d232 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -18,6 +18,7 @@ DEF5(deposit, TCGV, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
+DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f5771240803..a7d815b9e16 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -608,6 +608,51 @@ void tcg_gen_eqv(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
+ unsigned int ofs, unsigned int len)
+{
+ unsigned width = tcg_type_size(type) * 8;
+ uint64_t mask;
+
+ tcg_debug_assert(ofs < width);
+ tcg_debug_assert(len > 0);
+ tcg_debug_assert(len <= width);
+ tcg_debug_assert(ofs + len <= width);
+
+ /* Canonicalize certain special cases, even if extract is supported. */
+ if (ofs + len == width) {
+ tcg_gen_shri(type, dst, src, ofs);
+ return;
+ }
+
+ if (TCG_TARGET_extract_valid(type, ofs, len)) {
+ tcg_gen_op_ttii(INDEX_op_extract, type, dst, src, ofs, len);
+ return;
+ }
+
+ /* Assume that zero-extension, if available, is cheaper than a shift. */
+ if (TCG_TARGET_extract_valid(type, 0, ofs + len)) {
+ tcg_gen_op_ttii(INDEX_op_extract, type, dst, src, 0, ofs + len);
+ tcg_gen_shri(type, dst, dst, ofs);
+ return;
+ }
+ if (TCG_TARGET_extract_valid(type, 0, len)) {
+ tcg_gen_shri(type, dst, src, ofs);
+ tcg_gen_op_ttii(INDEX_op_extract, type, dst, dst, 0, len);
+ return;
+ }
+
+ mask = MAKE_64BIT_MASK(0, len);
+ if (tcg_op_imm_match(INDEX_op_and, type, mask)) {
+ tcg_gen_shri(type, dst, src, ofs);
+ /* Do not recurse with gen_andi. */
+ tcg_gen_and(type, dst, dst, tcg_constant_internal(type, mask));
+ } else {
+ tcg_gen_shli(type, dst, src, width - len - ofs);
+ tcg_gen_shri(type, dst, dst, width - len);
+ }
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -964,49 +1009,6 @@ void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
}
}
-void tcg_gen_extract_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len)
-{
- uint32_t mask;
-
- tcg_debug_assert(ofs < 32);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 32);
- tcg_debug_assert(ofs + len <= 32);
-
- /* Canonicalize certain special cases, even if extract is supported. */
- if (ofs + len == 32) {
- tcg_gen_shri_i32(ret, arg, 32 - len);
- return;
- }
-
- if (TCG_TARGET_extract_valid(TCG_TYPE_I32, ofs, len)) {
- tcg_gen_op4ii_i32(INDEX_op_extract, ret, arg, ofs, len);
- return;
- }
-
- mask = (1u << len) - 1;
- if (ofs == 0) {
- tcg_gen_andi_i32(ret, arg, mask);
- return;
- }
-
- /* Assume that zero-extension, if available, is cheaper than a shift. */
- if (TCG_TARGET_extract_valid(TCG_TYPE_I32, 0, ofs + len)) {
- tcg_gen_op4ii_i32(INDEX_op_extract, ret, arg, 0, ofs + len);
- tcg_gen_shri_i32(ret, ret, ofs);
- return;
- }
-
- if (tcg_op_imm_match(INDEX_op_and, TCG_TYPE_I32, mask)) {
- tcg_gen_shri_i32(ret, arg, ofs);
- tcg_gen_andi_i32(ret, ret, mask);
- } else {
- tcg_gen_shli_i32(ret, arg, 32 - len - ofs);
- tcg_gen_shri_i32(ret, ret, 32 - len);
- }
-}
-
void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len)
{
@@ -1711,49 +1713,6 @@ void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
}
}
-void tcg_gen_extract_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len)
-{
- uint64_t mask;
-
- tcg_debug_assert(ofs < 64);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 64);
- tcg_debug_assert(ofs + len <= 64);
-
- /* Canonicalize certain special cases, even if extract is supported. */
- if (ofs + len == 64) {
- tcg_gen_shri_i64(ret, arg, 64 - len);
- return;
- }
-
- if (TCG_TARGET_extract_valid(TCG_TYPE_I64, ofs, len)) {
- tcg_gen_op4ii_i64(INDEX_op_extract, ret, arg, ofs, len);
- return;
- }
-
- mask = (1ull << len) - 1;
- if (ofs == 0) {
- tcg_gen_andi_i64(ret, arg, mask);
- return;
- }
-
- /* Assume that zero-extension, if available, is cheaper than a shift. */
- if (TCG_TARGET_extract_valid(TCG_TYPE_I64, 0, ofs + len)) {
- tcg_gen_op4ii_i64(INDEX_op_extract, ret, arg, 0, ofs + len);
- tcg_gen_shri_i64(ret, ret, ofs);
- return;
- }
-
- if (tcg_op_imm_match(INDEX_op_and, TCG_TYPE_I64, mask)) {
- tcg_gen_shri_i64(ret, arg, ofs);
- tcg_gen_andi_i64(ret, ret, mask);
- } else {
- tcg_gen_shli_i64(ret, arg, 64 - len - ofs);
- tcg_gen_shri_i64(ret, ret, 64 - len);
- }
-}
-
void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 064/101] tcg: Generic expansion of tcg_gen_sextract_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (62 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 063/101] tcg: Generic expansion of tcg_gen_extract_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 065/101] tcg: Generic expansion of tcg_gen_deposit_z_* Richard Henderson
` (36 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 121 +++++++++++------------------------
3 files changed, 38 insertions(+), 88 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ec4cf775b38..ef47b704bc9 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -134,8 +134,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
unsigned int ofs, unsigned int len);
-void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
@@ -181,8 +179,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
unsigned int ofs, unsigned int len);
-void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 69f76f1d232..338ecce6fce 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -44,6 +44,7 @@ DEF3(sar, TCGV, TCGV, TCGV)
DEF3(sari, TCGV, TCGV, TINT)
DEF4(setcond, TCGCond, TCGV, TCGV, TCGV)
DEF4(setcondi, TCGCond, TCGV, TCGV, TINT)
+DEF4(sextract, TCGV, TCGV, unsigned, unsigned)
DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a7d815b9e16..8fbf07d045e 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -197,20 +197,6 @@ static void DNI tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
tcgv_i64_arg(a3), a4);
}
-static TCGOp * DNI tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGArg a3, TCGArg a4)
-{
- return tcg_gen_op4(opc, TCG_TYPE_I32,
- tcgv_i32_arg(a1), tcgv_i32_arg(a2), a3, a4);
-}
-
-static TCGOp * DNI tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGArg a3, TCGArg a4)
-{
- return tcg_gen_op4(opc, TCG_TYPE_I64,
- tcgv_i64_arg(a1), tcgv_i64_arg(a2), a3, a4);
-}
-
static void DNI tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
TCGv_i32 a3, TCGArg a4, TCGArg a5)
{
@@ -923,6 +909,43 @@ void tcg_gen_setcondi(TCGType type, TCGCond cond, TCGTemp *dst,
tcg_gen_setcond(type, cond, dst, src1, tcg_constant_internal(type, src2));
}
+void tcg_gen_sextract(TCGType type, TCGTemp *dst, TCGTemp *src,
+ unsigned int ofs, unsigned int len)
+{
+ unsigned width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(ofs < width);
+ tcg_debug_assert(len > 0);
+ tcg_debug_assert(len <= width);
+ tcg_debug_assert(ofs + len <= width);
+
+ /* Canonicalize certain special cases, even if extract is supported. */
+ if (ofs + len == width) {
+ tcg_gen_sari(type, dst, src, width - len);
+ return;
+ }
+
+ if (TCG_TARGET_sextract_valid(type, ofs, len)) {
+ tcg_gen_op_ttii(INDEX_op_sextract, type, dst, src, ofs, len);
+ return;
+ }
+
+ /* Assume that sign-extension, if available, is cheaper than a shift. */
+ if (TCG_TARGET_sextract_valid(type, 0, ofs + len)) {
+ tcg_gen_op_ttii(INDEX_op_sextract, type, dst, src, 0, ofs + len);
+ tcg_gen_sari(type, dst, dst, ofs);
+ return;
+ }
+ if (TCG_TARGET_sextract_valid(type, 0, len)) {
+ tcg_gen_shri(type, dst, src, ofs);
+ tcg_gen_op_ttii(INDEX_op_sextract, type, dst, dst, 0, len);
+ return;
+ }
+
+ tcg_gen_shli(type, dst, src, width - len - ofs);
+ tcg_gen_sari(type, dst, dst, width - len);
+}
+
void tcg_gen_shl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_shl, type, dst, src1, src2);
@@ -1009,41 +1032,6 @@ void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
}
}
-void tcg_gen_sextract_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 32);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 32);
- tcg_debug_assert(ofs + len <= 32);
-
- /* Canonicalize certain special cases, even if extract is supported. */
- if (ofs + len == 32) {
- tcg_gen_sari_i32(ret, arg, 32 - len);
- return;
- }
-
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I32, ofs, len)) {
- tcg_gen_op4ii_i32(INDEX_op_sextract, ret, arg, ofs, len);
- return;
- }
-
- /* Assume that sign-extension, if available, is cheaper than a shift. */
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I32, 0, ofs + len)) {
- tcg_gen_op4ii_i32(INDEX_op_sextract, ret, arg, 0, ofs + len);
- tcg_gen_sari_i32(ret, ret, ofs);
- return;
- }
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I32, 0, len)) {
- tcg_gen_shri_i32(ret, arg, ofs);
- tcg_gen_op4ii_i32(INDEX_op_sextract, ret, ret, 0, len);
- return;
- }
-
- tcg_gen_shli_i32(ret, arg, 32 - len - ofs);
- tcg_gen_sari_i32(ret, ret, 32 - len);
-}
-
/*
* Extract 32-bits from a 64-bit input, ah:al, starting from ofs.
* Unlike tcg_gen_extract_i32 above, len is fixed at 32.
@@ -1713,41 +1701,6 @@ void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
}
}
-void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 64);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 64);
- tcg_debug_assert(ofs + len <= 64);
-
- /* Canonicalize certain special cases, even if sextract is supported. */
- if (ofs + len == 64) {
- tcg_gen_sari_i64(ret, arg, 64 - len);
- return;
- }
-
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I64, ofs, len)) {
- tcg_gen_op4ii_i64(INDEX_op_sextract, ret, arg, ofs, len);
- return;
- }
-
- /* Assume that sign-extension, if available, is cheaper than a shift. */
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I64, 0, ofs + len)) {
- tcg_gen_op4ii_i64(INDEX_op_sextract, ret, arg, 0, ofs + len);
- tcg_gen_sari_i64(ret, ret, ofs);
- return;
- }
- if (TCG_TARGET_sextract_valid(TCG_TYPE_I64, 0, len)) {
- tcg_gen_shri_i64(ret, arg, ofs);
- tcg_gen_op4ii_i64(INDEX_op_sextract, ret, ret, 0, len);
- return;
- }
-
- tcg_gen_shli_i64(ret, arg, 64 - len - ofs);
- tcg_gen_sari_i64(ret, ret, 64 - len);
-}
-
/*
* Extract 64 bits from a 128-bit input, ah:al, starting from ofs.
* Unlike tcg_gen_extract_i64 above, len is fixed at 64.
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 065/101] tcg: Generic expansion of tcg_gen_deposit_z_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (63 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 064/101] tcg: Generic expansion of tcg_gen_sextract_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 066/101] tcg: Generic expansion of tcg_gen_ext8s_* Richard Henderson
` (35 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 70 +++++++++++-------------------------
3 files changed, 21 insertions(+), 54 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ef47b704bc9..f80e9dc2e29 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,8 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
unsigned int ofs);
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
@@ -177,8 +175,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len);
void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
unsigned int ofs);
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 338ecce6fce..88e87ebc2f6 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -15,6 +15,7 @@ DEF2(ctpop, TCGV, TCGV)
DEF3(ctz, TCGV, TCGV, TCGV)
DEF3(ctzi, TCGV, TCGV, TINT)
DEF5(deposit, TCGV, TCGV, TCGV, unsigned, unsigned)
+DEF4(deposit_z, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 8fbf07d045e..2e5bc1e8200 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -197,20 +197,6 @@ static void DNI tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
tcgv_i64_arg(a3), a4);
}
-static void DNI tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGv_i32 a3, TCGArg a4, TCGArg a5)
-{
- tcg_gen_op5(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
- tcgv_i32_arg(a3), a4, a5);
-}
-
-static void DNI tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGv_i64 a3, TCGArg a4, TCGArg a5)
-{
- tcg_gen_op5(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
- tcgv_i64_arg(a3), a4, a5);
-}
-
/* Generic ops. */
void gen_set_label(TCGLabel *l)
@@ -550,6 +536,26 @@ void tcg_gen_deposit(TCGType type, TCGTemp *dst, TCGTemp *src1,
}
}
+void tcg_gen_deposit_z(TCGType type, TCGTemp *dst, TCGTemp *src,
+ unsigned int ofs, unsigned int len)
+{
+ unsigned width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(ofs < width);
+ tcg_debug_assert(len > 0);
+ tcg_debug_assert(len <= width);
+ tcg_debug_assert(ofs + len <= width);
+
+ if (ofs + len == width) {
+ tcg_gen_shli(type, dst, src, ofs);
+ } else if (ofs == 0) {
+ tcg_gen_extract(type, dst, src, 0, len);
+ } else {
+ TCGTemp *zero = tcg_constant_internal(type, 0);
+ tcg_gen_op_tttii(INDEX_op_deposit, type, dst, zero, src, ofs, len);
+ }
+}
+
void tcg_gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -1014,24 +1020,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 32);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 32);
- tcg_debug_assert(ofs + len <= 32);
-
- if (ofs + len == 32) {
- tcg_gen_shli_i32(ret, arg, ofs);
- } else if (ofs == 0) {
- tcg_gen_extract_i32(ret, arg, 0, len);
- } else {
- TCGv_i32 zero = tcg_constant_i32(0);
- tcg_gen_op5ii_i32(INDEX_op_deposit, ret, zero, arg, ofs, len);
- }
-}
-
/*
* Extract 32-bits from a 64-bit input, ah:al, starting from ofs.
* Unlike tcg_gen_extract_i32 above, len is fixed at 32.
@@ -1683,24 +1671,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
- unsigned int ofs, unsigned int len)
-{
- tcg_debug_assert(ofs < 64);
- tcg_debug_assert(len > 0);
- tcg_debug_assert(len <= 64);
- tcg_debug_assert(ofs + len <= 64);
-
- if (ofs + len == 64) {
- tcg_gen_shli_i64(ret, arg, ofs);
- } else if (ofs == 0) {
- tcg_gen_andi_i64(ret, arg, (1ull << len) - 1);
- } else {
- TCGv_i64 zero = tcg_constant_i64(0);
- tcg_gen_op5ii_i64(INDEX_op_deposit, ret, zero, arg, ofs, len);
- }
-}
-
/*
* Extract 64 bits from a 128-bit input, ah:al, starting from ofs.
* Unlike tcg_gen_extract_i64 above, len is fixed at 64.
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 066/101] tcg: Generic expansion of tcg_gen_ext8s_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (64 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 065/101] tcg: Generic expansion of tcg_gen_deposit_z_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 067/101] tcg: Generic expansion of tcg_gen_ext8u_* Richard Henderson
` (34 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index f80e9dc2e29..52752db2655 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -143,7 +143,6 @@ void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -187,7 +186,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 88e87ebc2f6..a5b2bdcb432 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -19,6 +19,7 @@ DEF4(deposit_z, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
+DEF2(ext8s, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2e5bc1e8200..6dbe396afc1 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -600,6 +600,11 @@ void tcg_gen_eqv(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_ext8s(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_sextract(type, dst, src, 0, 8);
+}
+
void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
unsigned int ofs, unsigned int len)
{
@@ -1166,11 +1171,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_temp_free_i64(t1);
}
-void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- tcg_gen_sextract_i32(ret, arg, 0, 8);
-}
-
void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
{
tcg_gen_sextract_i32(ret, arg, 0, 16);
@@ -1472,11 +1472,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- tcg_gen_sextract_i64(ret, arg, 0, 8);
-}
-
void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 16);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 067/101] tcg: Generic expansion of tcg_gen_ext8u_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (65 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 066/101] tcg: Generic expansion of tcg_gen_ext8s_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 068/101] tcg: Generic expansion of tcg_gen_ext16s_* Richard Henderson
` (33 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 52752db2655..260f65f3305 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -144,7 +144,6 @@ void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
@@ -188,7 +187,6 @@ void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext_i64(TCGv_i64 ret, TCGv_i64 val, MemOp opc);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index a5b2bdcb432..1cdcf3aeeca 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -20,6 +20,7 @@ DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
DEF2(ext8s, TCGV, TCGV)
+DEF2(ext8u, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 6dbe396afc1..60a4f1c196b 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -605,6 +605,11 @@ void tcg_gen_ext8s(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_sextract(type, dst, src, 0, 8);
}
+void tcg_gen_ext8u(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_extract(type, dst, src, 0, 8);
+}
+
void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
unsigned int ofs, unsigned int len)
{
@@ -1176,11 +1181,6 @@ void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
tcg_gen_sextract_i32(ret, arg, 0, 16);
}
-void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- tcg_gen_extract_i32(ret, arg, 0, 8);
-}
-
void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
{
tcg_gen_extract_i32(ret, arg, 0, 16);
@@ -1482,11 +1482,6 @@ void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
tcg_gen_sextract_i64(ret, arg, 0, 32);
}
-void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- tcg_gen_extract_i64(ret, arg, 0, 8);
-}
-
void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_extract_i64(ret, arg, 0, 16);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 068/101] tcg: Generic expansion of tcg_gen_ext16s_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (66 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 067/101] tcg: Generic expansion of tcg_gen_ext8u_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 069/101] tcg: Generic expansion of tcg_gen_ext16u_* Richard Henderson
` (32 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 260f65f3305..d8bd08ff1ec 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -143,7 +143,6 @@ void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
@@ -185,7 +184,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 1cdcf3aeeca..4c1fc9633c1 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -21,6 +21,7 @@ DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
DEF2(ext8s, TCGV, TCGV)
DEF2(ext8u, TCGV, TCGV)
+DEF2(ext16s, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 60a4f1c196b..c4ae16273fc 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -610,6 +610,11 @@ void tcg_gen_ext8u(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_extract(type, dst, src, 0, 8);
}
+void tcg_gen_ext16s(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_sextract(type, dst, src, 0, 16);
+}
+
void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
unsigned int ofs, unsigned int len)
{
@@ -1176,11 +1181,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_temp_free_i64(t1);
}
-void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- tcg_gen_sextract_i32(ret, arg, 0, 16);
-}
-
void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
{
tcg_gen_extract_i32(ret, arg, 0, 16);
@@ -1472,11 +1472,6 @@ void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
}
-void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- tcg_gen_sextract_i64(ret, arg, 0, 16);
-}
-
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 32);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 069/101] tcg: Generic expansion of tcg_gen_ext16u_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (67 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 068/101] tcg: Generic expansion of tcg_gen_ext16s_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 070/101] tcg: Generic expansion of tcg_gen_ext_* Richard Henderson
` (31 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index d8bd08ff1ec..2878701b105 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -143,7 +143,6 @@ void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -185,7 +184,6 @@ void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext_i64(TCGv_i64 ret, TCGv_i64 val, MemOp opc);
void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 4c1fc9633c1..6208a51f536 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -22,6 +22,7 @@ DEF3(divu, TCGV, TCGV, TCGV)
DEF2(ext8s, TCGV, TCGV)
DEF2(ext8u, TCGV, TCGV)
DEF2(ext16s, TCGV, TCGV)
+DEF2(ext16u, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index c4ae16273fc..362eec23f76 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -615,6 +615,11 @@ void tcg_gen_ext16s(TCGType type, TCGTemp *dst, TCGTemp *src)
tcg_gen_sextract(type, dst, src, 0, 16);
}
+void tcg_gen_ext16u(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ tcg_gen_extract(type, dst, src, 0, 16);
+}
+
void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
unsigned int ofs, unsigned int len)
{
@@ -1181,11 +1186,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_temp_free_i64(t1);
}
-void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- tcg_gen_extract_i32(ret, arg, 0, 16);
-}
-
/*
* Internal helper for bit and byte reversal.
* Given a repeating matched block of 1's and 0's, swap the bits within
@@ -1477,11 +1477,6 @@ void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
tcg_gen_sextract_i64(ret, arg, 0, 32);
}
-void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- tcg_gen_extract_i64(ret, arg, 0, 16);
-}
-
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_extract_i64(ret, arg, 0, 32);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 070/101] tcg: Generic expansion of tcg_gen_ext_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (68 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 069/101] tcg: Generic expansion of tcg_gen_ext16u_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 071/101] tcg: Generic expansion of tcg_gen_smin_* Richard Henderson
` (30 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Move from tcg-op-ldst.c and compute the width of the
extract instead of using a switch.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op-ldst.c | 54 ------------------------------------
tcg/tcg-op.c | 13 +++++++++
4 files changed, 14 insertions(+), 56 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 2878701b105..383cd093863 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -143,7 +143,6 @@ void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -185,7 +184,6 @@ void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ext_i64(TCGv_i64 ret, TCGv_i64 val, MemOp opc);
void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 6208a51f536..f9812c1f882 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -19,6 +19,7 @@ DEF4(deposit_z, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
+DEF3(ext, TCGV, TCGV, MemOp)
DEF2(ext8s, TCGV, TCGV)
DEF2(ext8u, TCGV, TCGV)
DEF2(ext16s, TCGV, TCGV)
diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
index 22211ccb452..031c5ce926b 100644
--- a/tcg/tcg-op-ldst.c
+++ b/tcg/tcg-op-ldst.c
@@ -760,60 +760,6 @@ void tcg_gen_qemu_st_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx,
tcg_gen_qemu_st_i128_int(val, addr, idx, memop);
}
-void tcg_gen_ext_i32(TCGv_i32 ret, TCGv_i32 val, MemOp opc)
-{
- switch (opc & MO_SSIZE) {
- case MO_SB:
- tcg_gen_ext8s_i32(ret, val);
- break;
- case MO_UB:
- tcg_gen_ext8u_i32(ret, val);
- break;
- case MO_SW:
- tcg_gen_ext16s_i32(ret, val);
- break;
- case MO_UW:
- tcg_gen_ext16u_i32(ret, val);
- break;
- case MO_UL:
- case MO_SL:
- tcg_gen_mov_i32(ret, val);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
-void tcg_gen_ext_i64(TCGv_i64 ret, TCGv_i64 val, MemOp opc)
-{
- switch (opc & MO_SSIZE) {
- case MO_SB:
- tcg_gen_ext8s_i64(ret, val);
- break;
- case MO_UB:
- tcg_gen_ext8u_i64(ret, val);
- break;
- case MO_SW:
- tcg_gen_ext16s_i64(ret, val);
- break;
- case MO_UW:
- tcg_gen_ext16u_i64(ret, val);
- break;
- case MO_SL:
- tcg_gen_ext32s_i64(ret, val);
- break;
- case MO_UL:
- tcg_gen_ext32u_i64(ret, val);
- break;
- case MO_UQ:
- case MO_SQ:
- tcg_gen_mov_i64(ret, val);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
typedef void (*gen_atomic_cx_i32)(TCGv_i32, TCGv_env, TCGv_i64,
TCGv_i32, TCGv_i32, TCGv_i32);
typedef void (*gen_atomic_cx_i64)(TCGv_i64, TCGv_env, TCGv_i64,
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 362eec23f76..96675ef77b0 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -282,6 +282,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#define C_TCGv_i64 tcgv_i64_temp
#define C_int32_t
#define C_int64_t
+#define C_MemOp
#define C_TCGCond
#define C_TCGLabelPtr
#define C_unsigned
@@ -312,6 +313,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_TCGv_i64
#undef C_int32_t
#undef C_int64_t
+#undef C_MemOp
#undef C_TCGCond
#undef C_TCGLabelPtr
#undef C_unsigned
@@ -600,6 +602,17 @@ void tcg_gen_eqv(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_ext(TCGType type, TCGTemp *dst, TCGTemp *src, MemOp mop)
+{
+ unsigned width = memop_size(mop) * 8;
+
+ if (mop & MO_SIGN) {
+ tcg_gen_sextract(type, dst, src, 0, width);
+ } else {
+ tcg_gen_extract(type, dst, src, 0, width);
+ }
+}
+
void tcg_gen_ext8s(TCGType type, TCGTemp *dst, TCGTemp *src)
{
tcg_gen_sextract(type, dst, src, 0, 8);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 071/101] tcg: Generic expansion of tcg_gen_smin_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (69 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 070/101] tcg: Generic expansion of tcg_gen_ext_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 10:45 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 072/101] tcg: Generic expansion of tcg_gen_smax_* Richard Henderson
` (29 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 27 +++++++++------------------
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 383cd093863..3f463725d68 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_smin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_smax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_umin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_umax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -189,7 +188,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_smin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_smax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_umin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_umax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index f9812c1f882..14860667283 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -55,6 +55,7 @@ DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
DEF3(shri, TCGV, TCGV, TINT)
+DEF3(smin, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 96675ef77b0..207a62450a1 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1015,6 +1015,15 @@ void tcg_gen_shri(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_smin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_smin, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_smin, type, dst, src1, src2);
+ } else {
+ tcg_gen_movcond(type, TCG_COND_LT, dst, src1, src2, src1, src2);
+ }
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -1331,15 +1340,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_smin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
-{
- if (tcg_op_supported(INDEX_op_smin, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_smin, ret, a, b);
- } else {
- tcg_gen_movcond_i32(TCG_COND_LT, ret, a, b, a, b);
- }
-}
-
void tcg_gen_umin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
{
if (tcg_op_supported(INDEX_op_umin, TCG_TYPE_I32, 0)) {
@@ -1871,15 +1871,6 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_temp_free_i64(t2);
}
-void tcg_gen_smin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
-{
- if (tcg_op_supported(INDEX_op_smin, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_smin, ret, a, b);
- } else {
- tcg_gen_movcond_i64(TCG_COND_LT, ret, a, b, a, b);
- }
-}
-
void tcg_gen_umin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
{
if (tcg_op_supported(INDEX_op_umin, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 072/101] tcg: Generic expansion of tcg_gen_smax_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (70 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 071/101] tcg: Generic expansion of tcg_gen_smin_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 073/101] tcg: Generic expansion of tcg_gen_umin_* Richard Henderson
` (28 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 27 +++++++++------------------
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 3f463725d68..c7dafd2773d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_smax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_umin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_umax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ussub_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -188,7 +187,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_smax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_umin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_umax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ussub_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 14860667283..de3feeabdb6 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -55,6 +55,7 @@ DEF3(shl, TCGV, TCGV, TCGV)
DEF3(shli, TCGV, TCGV, TINT)
DEF3(shr, TCGV, TCGV, TCGV)
DEF3(shri, TCGV, TCGV, TINT)
+DEF3(smax, TCGV, TCGV, TCGV)
DEF3(smin, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 207a62450a1..3deaecc7e0b 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1015,6 +1015,15 @@ void tcg_gen_shri(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_smax(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_smax, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_smax, type, dst, src1, src2);
+ } else {
+ tcg_gen_movcond(type, TCG_COND_GT, dst, src1, src2, src1, src2);
+ }
+}
+
void tcg_gen_smin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_smin, type, 0)) {
@@ -1349,15 +1358,6 @@ void tcg_gen_umin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
}
}
-void tcg_gen_smax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
-{
- if (tcg_op_supported(INDEX_op_smax, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_smax, ret, a, b);
- } else {
- tcg_gen_movcond_i32(TCG_COND_LT, ret, a, b, b, a);
- }
-}
-
void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
{
if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I32, 0)) {
@@ -1880,15 +1880,6 @@ void tcg_gen_umin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
}
}
-void tcg_gen_smax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
-{
- if (tcg_op_supported(INDEX_op_smax, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_smax, ret, a, b);
- } else {
- tcg_gen_movcond_i64(TCG_COND_LT, ret, a, b, b, a);
- }
-}
-
void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
{
if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 073/101] tcg: Generic expansion of tcg_gen_umin_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (71 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 072/101] tcg: Generic expansion of tcg_gen_smax_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 10:46 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 074/101] tcg: Generic expansion of tcg_gen_umax_* Richard Henderson
` (27 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 27 +++++++++------------------
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index c7dafd2773d..79a2716e29a 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_umin_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_umax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ussub_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_abs_i32(TCGv_i32, TCGv_i32);
@@ -187,7 +186,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_umin_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_umax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ussub_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_abs_i64(TCGv_i64, TCGv_i64);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index de3feeabdb6..7d1035a8c84 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -60,5 +60,6 @@ DEF3(smin, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
+DEF3(umin, TCGV, TCGV, TCGV)
DEF3(xor, TCGV, TCGV, TCGV)
DEF3(xori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 3deaecc7e0b..904c3ed0e1a 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1052,6 +1052,15 @@ void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
}
}
+void tcg_gen_umin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_umin, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_umin, type, dst, src1, src2);
+ } else {
+ tcg_gen_movcond(type, TCG_COND_LTU, dst, src1, src2, src1, src2);
+ }
+}
+
void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_xor, type, dst, src1, src2);
@@ -1349,15 +1358,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_umin_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
-{
- if (tcg_op_supported(INDEX_op_umin, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_umin, ret, a, b);
- } else {
- tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, a, b);
- }
-}
-
void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
{
if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I32, 0)) {
@@ -1871,15 +1871,6 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_temp_free_i64(t2);
}
-void tcg_gen_umin_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
-{
- if (tcg_op_supported(INDEX_op_umin, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_umin, ret, a, b);
- } else {
- tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, a, b);
- }
-}
-
void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
{
if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 074/101] tcg: Generic expansion of tcg_gen_umax_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (72 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 073/101] tcg: Generic expansion of tcg_gen_umin_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 075/101] tcg: Generic expansion of tcg_gen_abs_* Richard Henderson
` (26 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 27 +++++++++------------------
3 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 79a2716e29a..18130617966 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_umax_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ussub_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_abs_i32(TCGv_i32, TCGv_i32);
void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -186,7 +185,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_umax_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ussub_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_abs_i64(TCGv_i64, TCGv_i64);
void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 7d1035a8c84..3c93c207044 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -60,6 +60,7 @@ DEF3(smin, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
+DEF3(umax, TCGV, TCGV, TCGV)
DEF3(umin, TCGV, TCGV, TCGV)
DEF3(xor, TCGV, TCGV, TCGV)
DEF3(xori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 904c3ed0e1a..d16830c8dca 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1052,6 +1052,15 @@ void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
}
}
+void tcg_gen_umax(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_umax, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_umax, type, dst, src1, src2);
+ } else {
+ tcg_gen_movcond(type, TCG_COND_GTU, dst, src1, src2, src1, src2);
+ }
+}
+
void tcg_gen_umin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_umin, type, 0)) {
@@ -1358,15 +1367,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
-{
- if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_umax, ret, a, b);
- } else {
- tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, b, a);
- }
-}
-
void tcg_gen_ussub_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
{
TCGv_i32 t = tcg_temp_ebb_new_i32();
@@ -1871,15 +1871,6 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_temp_free_i64(t2);
}
-void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
-{
- if (tcg_op_supported(INDEX_op_umax, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_umax, ret, a, b);
- } else {
- tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, b, a);
- }
-}
-
void tcg_gen_ussub_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
{
TCGv_i64 t = tcg_temp_ebb_new_i64();
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 075/101] tcg: Generic expansion of tcg_gen_abs_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (73 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 074/101] tcg: Generic expansion of tcg_gen_umax_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 10:44 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 076/101] tcg: Generic expansion of tcg_gen_ussub_* Richard Henderson
` (25 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 35 +++++++++++++++--------------------
3 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 18130617966..91acfefb1a1 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -147,7 +147,6 @@ void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_ussub_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_abs_i32(TCGv_i32, TCGv_i32);
void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -186,7 +185,6 @@ void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ussub_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_abs_i64(TCGv_i64, TCGv_i64);
void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 3c93c207044..19c6347fa7d 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: MIT */
/* Templated TCGv_i32 and TCGv_i64 operations */
+DEF2(abs, TCGV, TCGV)
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
DEF3(and, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index d16830c8dca..67145b43d12 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -331,6 +331,21 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
* are of the proper type.
*/
+void tcg_gen_abs(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_smax, type, 0)) {
+ tcg_gen_neg(type, tmp, src);
+ tcg_gen_smax(type, dst, tmp, src);
+ } else {
+ int width = tcg_type_size(type) * 8;
+ tcg_gen_sari(type, tmp, src, width - 1);
+ tcg_gen_xor(type, dst, src, tmp);
+ tcg_gen_sub(type, dst, dst, tmp);
+ }
+}
+
void tcg_gen_add(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_add, type, dst, src1, src2);
@@ -1377,16 +1392,6 @@ void tcg_gen_ussub_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
tcg_temp_free_i32(t);
}
-void tcg_gen_abs_i32(TCGv_i32 ret, TCGv_i32 a)
-{
- TCGv_i32 t = tcg_temp_ebb_new_i32();
-
- tcg_gen_sari_i32(t, a, 31);
- tcg_gen_xor_i32(ret, a, t);
- tcg_gen_sub_i32(ret, ret, t);
- tcg_temp_free_i32(t);
-}
-
void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_ld8u, ret, arg2, offset);
@@ -1881,16 +1886,6 @@ void tcg_gen_ussub_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
tcg_temp_free_i64(t);
}
-void tcg_gen_abs_i64(TCGv_i64 ret, TCGv_i64 a)
-{
- TCGv_i64 t = tcg_temp_ebb_new_i64();
-
- tcg_gen_sari_i64(t, a, 63);
- tcg_gen_xor_i64(ret, a, t);
- tcg_gen_sub_i64(ret, ret, t);
- tcg_temp_free_i64(t);
-}
-
/* Size changing operations. */
void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 075/101] tcg: Generic expansion of tcg_gen_abs_*
2026-09-27 8:59 ` [PATCH v5 075/101] tcg: Generic expansion of tcg_gen_abs_* Richard Henderson
@ 2026-09-28 10:44 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 10:44 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 35 +++++++++++++++--------------------
> 3 files changed, 16 insertions(+), 22 deletions(-)
> +void tcg_gen_abs(TCGType type, TCGTemp *dst, TCGTemp *src)
> +{
> + g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
> +
> + if (tcg_op_supported(INDEX_op_smax, type, 0)) {
> + tcg_gen_neg(type, tmp, src);
> + tcg_gen_smax(type, dst, tmp, src);
This patch is doing 2 distinct changes, generic expansion of ABS
and use of SMAX. Can we have the SMAX use in a following patch?
Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> + } else {
> + int width = tcg_type_size(type) * 8;
> + tcg_gen_sari(type, tmp, src, width - 1);
> + tcg_gen_xor(type, dst, src, tmp);
> + tcg_gen_sub(type, dst, dst, tmp);
> + }
> +}
> +
> void tcg_gen_add(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> {
> tcg_gen_op_ttt(INDEX_op_add, type, dst, src1, src2);
> @@ -1377,16 +1392,6 @@ void tcg_gen_ussub_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
> tcg_temp_free_i32(t);
> }
>
> -void tcg_gen_abs_i32(TCGv_i32 ret, TCGv_i32 a)
> -{
> - TCGv_i32 t = tcg_temp_ebb_new_i32();
> -
> - tcg_gen_sari_i32(t, a, 31);
> - tcg_gen_xor_i32(ret, a, t);
> - tcg_gen_sub_i32(ret, ret, t);
> - tcg_temp_free_i32(t);
> -}
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 076/101] tcg: Generic expansion of tcg_gen_ussub_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (74 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 075/101] tcg: Generic expansion of tcg_gen_abs_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 10:44 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 077/101] tcg: Use umax in ussub if available Richard Henderson
` (24 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 29 +++++++++--------------------
3 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 91acfefb1a1..040bdbd24a0 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -146,7 +146,6 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_ussub_i32(TCGv_i32, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -184,7 +183,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ussub_i64(TCGv_i64, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 19c6347fa7d..82dfc90009c 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -63,5 +63,6 @@ DEF3(subi, TCGV, TCGV, TINT)
DEF3(subfi, TCGV, TINT, TCGV)
DEF3(umax, TCGV, TCGV, TCGV)
DEF3(umin, TCGV, TCGV, TCGV)
+DEF3(ussub, TCGV, TCGV, TCGV)
DEF3(xor, TCGV, TCGV, TCGV)
DEF3(xori, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 67145b43d12..a1c1bfc8912 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1085,6 +1085,15 @@ void tcg_gen_umin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_ussub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+
+ tcg_gen_sub(type, tmp, src1, src2);
+ tcg_gen_movcond(type, TCG_COND_LTU, dst, src1, src2,
+ tcg_constant_internal(type, 0), tmp);
+}
+
void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_xor, type, dst, src1, src2);
@@ -1382,16 +1391,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_ussub_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b)
-{
- TCGv_i32 t = tcg_temp_ebb_new_i32();
- TCGv_i32 z = tcg_constant_i32(0);
-
- tcg_gen_sub_i32(t, a, b);
- tcg_gen_movcond_i32(TCG_COND_LTU, ret, a, b, z, t);
- tcg_temp_free_i32(t);
-}
-
void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_ld8u, ret, arg2, offset);
@@ -1876,16 +1875,6 @@ void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_temp_free_i64(t2);
}
-void tcg_gen_ussub_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b)
-{
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- TCGv_i64 z = tcg_constant_i64(0);
-
- tcg_gen_sub_i64(t, a, b);
- tcg_gen_movcond_i64(TCG_COND_LTU, ret, a, b, z, t);
- tcg_temp_free_i64(t);
-}
-
/* Size changing operations. */
void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 077/101] tcg: Use umax in ussub if available
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (75 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 076/101] tcg: Generic expansion of tcg_gen_ussub_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 078/101] tcg: Generic expansion of tcg_gen_extract2_* Richard Henderson
` (23 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-op.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index a1c1bfc8912..b7b3451a4f8 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1089,9 +1089,18 @@ void tcg_gen_ussub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
- tcg_gen_sub(type, tmp, src1, src2);
- tcg_gen_movcond(type, TCG_COND_LTU, dst, src1, src2,
- tcg_constant_internal(type, 0), tmp);
+ if (tcg_op_supported(INDEX_op_umax, type, 0)) {
+ tcg_gen_umax(type, tmp, src1, src2);
+ tcg_gen_sub(type, dst, tmp, src2);
+ } else {
+ /*
+ * While umax can be expanded with movcond, some hosts can
+ * perform movcond with a zero source in fewer insns.
+ */
+ tcg_gen_sub(type, tmp, src1, src2);
+ tcg_gen_movcond(type, TCG_COND_LTU, dst, src1, src2,
+ tcg_constant_internal(type, 0), tmp);
+ }
}
void tcg_gen_xor(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 078/101] tcg: Generic expansion of tcg_gen_extract2_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (76 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 077/101] tcg: Use umax in ussub if available Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 10:41 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 079/101] tcg: Generic expansion of tcg_gen_addcio_* Richard Henderson
` (22 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 69 +++++++++---------------------------
3 files changed, 18 insertions(+), 56 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 040bdbd24a0..9fbf582e413 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,8 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
- unsigned int ofs);
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
@@ -164,8 +162,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
- unsigned int ofs);
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 82dfc90009c..a237ccd0c51 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -26,6 +26,7 @@ DEF2(ext8u, TCGV, TCGV)
DEF2(ext16s, TCGV, TCGV)
DEF2(ext16u, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
+DEF4(extract2, TCGV, TCGV, TCGV, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index b7b3451a4f8..98f21004a84 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -183,20 +183,6 @@ static void DNI tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
tcgv_i64_arg(a3), tcgv_i64_arg(a4));
}
-static void DNI tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGv_i32 a3, TCGArg a4)
-{
- tcg_gen_op4(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
- tcgv_i32_arg(a3), a4);
-}
-
-static void DNI tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGv_i64 a3, TCGArg a4)
-{
- tcg_gen_op4(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
- tcgv_i64_arg(a3), a4);
-}
-
/* Generic ops. */
void gen_set_label(TCGLabel *l)
@@ -693,6 +679,23 @@ void tcg_gen_extract(TCGType type, TCGTemp *dst, TCGTemp *src,
}
}
+void tcg_gen_extract2(TCGType type, TCGTemp *dst, TCGTemp *lo, TCGTemp *hi,
+ unsigned int ofs)
+{
+ unsigned width = tcg_type_size(type) * 8;
+
+ tcg_debug_assert(ofs <= width);
+ if (ofs == 0) {
+ tcg_gen_mov(type, dst, lo);
+ } else if (ofs == width) {
+ tcg_gen_mov(type, dst, hi);
+ } else if (lo == hi) {
+ tcg_gen_rotri(type, dst, lo, ofs);
+ } else {
+ tcg_gen_op_ttti(INDEX_op_extract2, type, dst, lo, hi, ofs);
+ }
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1122,25 +1125,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-/*
- * Extract 32-bits from a 64-bit input, ah:al, starting from ofs.
- * Unlike tcg_gen_extract_i32 above, len is fixed at 32.
- */
-void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah,
- unsigned int ofs)
-{
- tcg_debug_assert(ofs <= 32);
- if (ofs == 0) {
- tcg_gen_mov_i32(ret, al);
- } else if (ofs == 32) {
- tcg_gen_mov_i32(ret, ah);
- } else if (al == ah) {
- tcg_gen_rotri_i32(ret, al, ofs);
- } else {
- tcg_gen_op4i_i32(INDEX_op_extract2, ret, al, ah, ofs);
- }
-}
-
void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
{
@@ -1677,25 +1661,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-/*
- * Extract 64 bits from a 128-bit input, ah:al, starting from ofs.
- * Unlike tcg_gen_extract_i64 above, len is fixed at 64.
- */
-void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah,
- unsigned int ofs)
-{
- tcg_debug_assert(ofs <= 64);
- if (ofs == 0) {
- tcg_gen_mov_i64(ret, al);
- } else if (ofs == 64) {
- tcg_gen_mov_i64(ret, ah);
- } else if (al == ah) {
- tcg_gen_rotri_i64(ret, al, ofs);
- } else {
- tcg_gen_op4i_i64(INDEX_op_extract2, ret, al, ah, ofs);
- }
-}
-
void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
{
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 079/101] tcg: Generic expansion of tcg_gen_addcio_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (77 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 078/101] tcg: Generic expansion of tcg_gen_extract2_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 080/101] tcg: Generic expansion of tcg_gen_add2_* Richard Henderson
` (21 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 77 +++++++++++-------------------------
3 files changed, 24 insertions(+), 58 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 9fbf582e413..9cc941478ba 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -136,8 +136,6 @@ void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
-void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
- TCGv_i32 a, TCGv_i32 b, TCGv_i32 ci);
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -166,8 +164,6 @@ void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
-void tcg_gen_addcio_i64(TCGv_i64 r, TCGv_i64 co,
- TCGv_i64 a, TCGv_i64 b, TCGv_i64 ci);
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index a237ccd0c51..003384b65df 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -4,6 +4,7 @@
DEF2(abs, TCGV, TCGV)
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
+DEF5(addcio, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 98f21004a84..eb59bc37631 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -346,6 +346,29 @@ void tcg_gen_addi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_addcio(TCGType type, TCGTemp *r, TCGTemp *co,
+ TCGTemp *a, TCGTemp *b, TCGTemp *ci)
+{
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_addci, type, 0)) {
+ TCGTemp *zero = tcg_constant_internal(type, 0);
+ TCGTemp *mone = tcg_constant_internal(type, -1);
+
+ tcg_gen_op_ttt(INDEX_op_addco, type, t0, ci, mone);
+ tcg_gen_op_ttt(INDEX_op_addcio, type, r, a, b);
+ tcg_gen_op_ttt(INDEX_op_addci, type, co, zero, zero);
+ } else {
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ tcg_gen_add(type, t0, a, b);
+ tcg_gen_setcond(type, TCG_COND_LTU, t1, t0, a);
+ tcg_gen_add(type, r, t0, ci);
+ tcg_gen_setcond(type, TCG_COND_LTU, t0, r, t0);
+ tcg_gen_or(type, co, t0, t1);
+ }
+}
+
void tcg_gen_and(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_and, type, dst, src1, src2);
@@ -1147,33 +1170,6 @@ void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
}
}
-void tcg_gen_addcio_i32(TCGv_i32 r, TCGv_i32 co,
- TCGv_i32 a, TCGv_i32 b, TCGv_i32 ci)
-{
- if (tcg_op_supported(INDEX_op_addci, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 zero = tcg_constant_i32(0);
- TCGv_i32 mone = tcg_constant_i32(-1);
-
- tcg_gen_op3_i32(INDEX_op_addco, t0, ci, mone);
- tcg_gen_op3_i32(INDEX_op_addcio, r, a, b);
- tcg_gen_op3_i32(INDEX_op_addci, co, zero, zero);
- tcg_temp_free_i32(t0);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
-
- tcg_gen_add_i32(t0, a, b);
- tcg_gen_setcond_i32(TCG_COND_LTU, t1, t0, a);
- tcg_gen_add_i32(r, t0, ci);
- tcg_gen_setcond_i32(TCG_COND_LTU, t0, r, t0);
- tcg_gen_or_i32(co, t0, t1);
-
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
{
@@ -1684,33 +1680,6 @@ void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
}
}
-void tcg_gen_addcio_i64(TCGv_i64 r, TCGv_i64 co,
- TCGv_i64 a, TCGv_i64 b, TCGv_i64 ci)
-{
- if (tcg_op_supported(INDEX_op_addci, TCG_TYPE_I64, 0)) {
- TCGv_i64 discard = tcg_temp_ebb_new_i64();
- TCGv_i64 zero = tcg_constant_i64(0);
- TCGv_i64 mone = tcg_constant_i64(-1);
-
- tcg_gen_op3_i64(INDEX_op_addco, discard, ci, mone);
- tcg_gen_op3_i64(INDEX_op_addcio, r, a, b);
- tcg_gen_op3_i64(INDEX_op_addci, co, zero, zero);
- tcg_temp_free_i64(discard);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
-
- tcg_gen_add_i64(t0, a, b);
- tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, a);
- tcg_gen_add_i64(r, t0, ci);
- tcg_gen_setcond_i64(TCG_COND_LTU, t0, r, t0);
- tcg_gen_or_i64(co, t0, t1);
-
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b)
{
tcg_debug_assert(n > 2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 080/101] tcg: Generic expansion of tcg_gen_add2_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (78 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 079/101] tcg: Generic expansion of tcg_gen_addcio_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 081/101] tcg: Generic expansion of tcg_gen_sub2_* Richard Henderson
` (20 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 64 +++++++++++-------------------------
3 files changed, 20 insertions(+), 49 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 9cc941478ba..0a1ff0c5b19 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,8 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
- TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -160,8 +158,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
- TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 003384b65df..e9f0b971a2b 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -4,6 +4,7 @@
DEF2(abs, TCGV, TCGV)
DEF3(add, TCGV, TCGV, TCGV)
DEF3(addi, TCGV, TCGV, TINT)
+DEF6(add2, TCGV, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF5(addcio, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(and, TCGV, TCGV, TCGV)
DEF3(andi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index eb59bc37631..0f478e65861 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -346,6 +346,25 @@ void tcg_gen_addi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_add2(TCGType type, TCGTemp *rl, TCGTemp *rh, TCGTemp *al,
+ TCGTemp *ah, TCGTemp *bl, TCGTemp *bh)
+{
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_addci, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_addco, type, t0, al, bl);
+ tcg_gen_op_ttt(INDEX_op_addci, type, rh, ah, bh);
+ } else {
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ tcg_gen_add(type, t0, al, bl);
+ tcg_gen_setcond(type, TCG_COND_LTU, t1, t0, al);
+ tcg_gen_add(type, rh, ah, bh);
+ tcg_gen_add(type, rh, rh, t1);
+ }
+ tcg_gen_mov(type, rl, t0);
+}
+
void tcg_gen_addcio(TCGType type, TCGTemp *r, TCGTemp *co,
TCGTemp *a, TCGTemp *b, TCGTemp *ci)
{
@@ -1148,28 +1167,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
- TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
-{
- if (tcg_op_supported(INDEX_op_addci, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_addco, t0, al, bl);
- tcg_gen_op3_i32(INDEX_op_addci, rh, ah, bh);
- tcg_gen_mov_i32(rl, t0);
- tcg_temp_free_i32(t0);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- tcg_gen_add_i32(t0, al, bl);
- tcg_gen_setcond_i32(TCG_COND_LTU, t1, t0, al);
- tcg_gen_add_i32(rh, ah, bh);
- tcg_gen_add_i32(rh, rh, t1);
- tcg_gen_mov_i32(rl, t0);
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
{
@@ -1657,29 +1654,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
- TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
-{
- if (tcg_op_supported(INDEX_op_addci, TCG_TYPE_REG, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
-
- tcg_gen_op3_i64(INDEX_op_addco, t0, al, bl);
- tcg_gen_op3_i64(INDEX_op_addci, rh, ah, bh);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_add_i64(t0, al, bl);
- tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
- tcg_gen_add_i64(rh, ah, bh);
- tcg_gen_add_i64(rh, rh, t1);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b)
{
tcg_debug_assert(n > 2);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 081/101] tcg: Generic expansion of tcg_gen_sub2_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (79 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 080/101] tcg: Generic expansion of tcg_gen_add2_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 082/101] tcg: Generic expansion of tcg_gen_mulu2_* Richard Henderson
` (19 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 64 +++++++++++-------------------------
3 files changed, 20 insertions(+), 49 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 0a1ff0c5b19..267ef111ae3 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,8 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
- TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh);
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -158,8 +156,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
- TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index e9f0b971a2b..14bdabb2f15 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -63,6 +63,7 @@ DEF3(smax, TCGV, TCGV, TCGV)
DEF3(smin, TCGV, TCGV, TCGV)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
+DEF6(sub2, TCGV, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(subfi, TCGV, TINT, TCGV)
DEF3(umax, TCGV, TCGV, TCGV)
DEF3(umin, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 0f478e65861..7b8e158c2e4 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1103,6 +1103,25 @@ void tcg_gen_subi(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
tcg_gen_addi(type, dst, src1, -src2);
}
+void tcg_gen_sub2(TCGType type, TCGTemp *rl, TCGTemp *rh, TCGTemp *al,
+ TCGTemp *ah, TCGTemp *bl, TCGTemp *bh)
+{
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+
+ if (tcg_op_supported(INDEX_op_subbi, type, 0)) {
+ tcg_gen_op_ttt(INDEX_op_subbo, type, t0, al, bl);
+ tcg_gen_op_ttt(INDEX_op_subbi, type, rh, ah, bh);
+ } else {
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ tcg_gen_sub(type, t0, al, bl);
+ tcg_gen_setcond(type, TCG_COND_LTU, t1, al, bl);
+ tcg_gen_sub(type, rh, ah, bh);
+ tcg_gen_sub(type, rh, rh, t1);
+ }
+ tcg_gen_mov(type, rl, t0);
+}
+
void tcg_gen_subfi(TCGType type, TCGTemp *dst, int64_t src1, TCGTemp *src2)
{
if (src1 == 0) {
@@ -1167,28 +1186,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
- TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
-{
- if (tcg_op_supported(INDEX_op_subbi, TCG_TYPE_I32, 0)) {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_subbo, t0, al, bl);
- tcg_gen_op3_i32(INDEX_op_subbi, rh, ah, bh);
- tcg_gen_mov_i32(rl, t0);
- tcg_temp_free_i32(t0);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- tcg_gen_sub_i32(t0, al, bl);
- tcg_gen_setcond_i32(TCG_COND_LTU, t1, al, bl);
- tcg_gen_sub_i32(rh, ah, bh);
- tcg_gen_sub_i32(rh, rh, t1);
- tcg_gen_mov_i32(rl, t0);
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I32, 0)) {
@@ -1696,29 +1693,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b)
}
}
-void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
- TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
-{
- if (tcg_op_supported(INDEX_op_subbi, TCG_TYPE_REG, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
-
- tcg_gen_op3_i64(INDEX_op_subbo, t0, al, bl);
- tcg_gen_op3_i64(INDEX_op_subbi, rh, ah, bh);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_sub_i64(t0, al, bl);
- tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
- tcg_gen_sub_i64(rh, ah, bh);
- tcg_gen_sub_i64(rh, rh, t1);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 082/101] tcg: Generic expansion of tcg_gen_mulu2_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (80 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 081/101] tcg: Generic expansion of tcg_gen_sub2_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_* Richard Henderson
` (18 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
tcg/tcg-internal.h | 7 ++++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 72 ++++++++++++++++--------------------
4 files changed, 39 insertions(+), 43 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 267ef111ae3..41a4d52d497 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
@@ -157,7 +156,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
-void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 13c4be5a5c7..09899cb3091 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -126,6 +126,13 @@ static inline void tcg_gen_op_ttti(TCGOpcode opc, TCGType type, TCGTemp *t0,
tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1), temp_arg(t2), a3);
}
+static inline void tcg_gen_op_tttt(TCGOpcode opc, TCGType type, TCGTemp *t0,
+ TCGTemp *t1, TCGTemp *t2, TCGTemp *t3)
+{
+ tcg_gen_op4(opc, type, temp_arg(t0), temp_arg(t1),
+ temp_arg(t2), temp_arg(t3));
+}
+
static inline void tcg_gen_op_tttii(TCGOpcode opc, TCGType type,
TCGTemp *t0, TCGTemp *t1, TCGTemp *t2,
TCGArg a3, TCGArg a4)
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 14bdabb2f15..b24122173a2 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -35,6 +35,7 @@ DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
+DEF4(mulu2, TCGV, TCGV, TCGV, TCGV)
DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
DEF4(negsetcond, TCGCond, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 7b8e158c2e4..f107e3a85ea 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -778,6 +778,37 @@ void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_mulu2(TCGType type, TCGTemp *rl, TCGTemp *rh,
+ TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_mulu2, type, 0)) {
+ tcg_gen_op_tttt(INDEX_op_mulu2, type, rl, rh, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_muluh, type, 0)) {
+ g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
+
+ tcg_gen_mul(type, t, src1, src2);
+ tcg_gen_op_ttt(INDEX_op_muluh, type, rh, src1, src2);
+ tcg_gen_mov(type, rl, t);
+ } else if (type == TCG_TYPE_I32) {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(TCG_TYPE_I64);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(TCG_TYPE_I64);
+
+ /* Simply extend and use host 64-bit multiply. */
+ tcg_gen_extu(t0, src1);
+ tcg_gen_extu(t1, src2);
+ tcg_gen_mul(TCG_TYPE_I64, t0, t0, t1);
+ tcg_gen_extrl(rl, t0);
+ tcg_gen_extrh(rh, t0);
+ } else {
+ g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
+
+ tcg_gen_mul(TCG_TYPE_I64, t, src1, src2);
+ gen_helper_muluh_i64(temp_tcgv_i64(rh), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ tcg_gen_mov(TCG_TYPE_I64, rl, t);
+ }
+}
+
void tcg_gen_nand(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_nand, type, 0)) {
@@ -1186,28 +1217,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I32, 0)) {
- tcg_gen_op4_i32(INDEX_op_mulu2, rl, rh, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_muluh, TCG_TYPE_I32, 0)) {
- TCGv_i32 t = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_mul, t, arg1, arg2);
- tcg_gen_op3_i32(INDEX_op_muluh, rh, arg1, arg2);
- tcg_gen_mov_i32(rl, t);
- tcg_temp_free_i32(t);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_extu_i32_i64(t0, arg1);
- tcg_gen_extu_i32_i64(t1, arg2);
- tcg_gen_mul_i64(t0, t0, t1);
- tcg_gen_extr_i64_i32(rl, rh, t0);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
{
if (tcg_op_supported(INDEX_op_muls2, TCG_TYPE_I32, 0)) {
@@ -1693,25 +1702,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b)
}
}
-void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I64, 0)) {
- tcg_gen_op4_i64(INDEX_op_mulu2, rl, rh, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_muluh, TCG_TYPE_I64, 0)) {
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- tcg_gen_op3_i64(INDEX_op_mul, t, arg1, arg2);
- tcg_gen_op3_i64(INDEX_op_muluh, rh, arg1, arg2);
- tcg_gen_mov_i64(rl, t);
- tcg_temp_free_i64(t);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_mul_i64(t0, arg1, arg2);
- gen_helper_muluh_i64(rh, arg1, arg2);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- }
-}
-
void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
{
if (tcg_op_supported(INDEX_op_muls2, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (81 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 082/101] tcg: Generic expansion of tcg_gen_mulu2_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 23:40 ` Matt Turner
2026-09-29 23:42 ` Matt Turner
2026-09-27 8:59 ` [PATCH v5 084/101] tcg: Use unsigned for flags for bswap and revbit operations Richard Henderson
` (17 subsequent siblings)
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 131 +++++++++++++----------------------
3 files changed, 51 insertions(+), 83 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 41a4d52d497..5f73601ddf7 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -156,7 +155,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
-void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index b24122173a2..b606aaab128 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -35,6 +35,7 @@ DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
DEF3(mul, TCGV, TCGV, TCGV)
DEF3(muli, TCGV, TCGV, TINT)
+DEF4(muls2, TCGV, TCGV, TCGV, TCGV)
DEF4(mulu2, TCGV, TCGV, TCGV, TCGV)
DEF3(nand, TCGV, TCGV, TCGV)
DEF2(neg, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index f107e3a85ea..61d50294a68 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -129,13 +129,6 @@ static void DNI tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2)
tcg_gen_op2(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2));
}
-static void DNI tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 a1,
- TCGv_i32 a2, TCGv_i32 a3)
-{
- tcg_gen_op3(opc, TCG_TYPE_I32, tcgv_i32_arg(a1),
- tcgv_i32_arg(a2), tcgv_i32_arg(a3));
-}
-
static void DNI tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 a1,
TCGv_i64 a2, TCGv_i64 a3)
{
@@ -169,20 +162,6 @@ static void DNI tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
tcgv_ptr_arg(base), offset);
}
-static void DNI tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
- TCGv_i32 a3, TCGv_i32 a4)
-{
- tcg_gen_op4(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
- tcgv_i32_arg(a3), tcgv_i32_arg(a4));
-}
-
-static void DNI tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
- TCGv_i64 a3, TCGv_i64 a4)
-{
- tcg_gen_op4(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
- tcgv_i64_arg(a3), tcgv_i64_arg(a4));
-}
-
/* Generic ops. */
void gen_set_label(TCGLabel *l)
@@ -778,6 +757,56 @@ void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
}
}
+void tcg_gen_muls2(TCGType type, TCGTemp *rl, TCGTemp *rh,
+ TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_muls2, type, 0)) {
+ tcg_gen_op_tttt(INDEX_op_muls2, type, rl, rh, src1, src2);
+ } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I32, 0)) {
+ g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
+
+ tcg_gen_mul(type, t, src1, src2);
+ tcg_gen_op_ttt(INDEX_op_mulsh, type, rh, src1, src2);
+ tcg_gen_mov(type, rl, t);
+ } else if (type == TCG_TYPE_I32) {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+
+ /* Simply extend and use host 64-bit multiply. */
+ tcg_gen_exts(t0, src1);
+ tcg_gen_exts(t1, src2);
+ tcg_gen_mul(TCG_TYPE_I64, t0, t0, t1);
+ tcg_gen_extrl(rl, t0);
+ tcg_gen_extrh(rh, t0);
+ } else if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I64, 0) ||
+ tcg_op_supported(INDEX_op_muluh, TCG_TYPE_I64, 0)) {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t2 = NULL;
+ g_autoptr(TCGTemp) t3 = NULL;
+
+ tcg_gen_mulu2(TCG_TYPE_I64, t0, t1, src1, src2);
+
+ /* Adjust for negative inputs. */
+ t2 = tcg_temp_new_ebb(type);
+ t3 = tcg_temp_new_ebb(type);
+ tcg_gen_sari(TCG_TYPE_I64, t2, src1, 63);
+ tcg_gen_sari(TCG_TYPE_I64, t3, src2, 63);
+ tcg_gen_and(TCG_TYPE_I64, t2, t2, src2);
+ tcg_gen_and(TCG_TYPE_I64, t3, t3, src1);
+ tcg_gen_sub(TCG_TYPE_I64, rh, t1, t2);
+ tcg_gen_sub(TCG_TYPE_I64, rh, rh, t3);
+ tcg_gen_mov(TCG_TYPE_I64, rl, t0);
+ } else {
+ g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
+
+ tcg_gen_mul(TCG_TYPE_I64, t, src1, src2);
+ gen_helper_mulsh_i64(temp_tcgv_i64(rh), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ tcg_gen_mov(TCG_TYPE_I64, rl, t);
+ }
+}
+
void tcg_gen_mulu2(TCGType type, TCGTemp *rl, TCGTemp *rh,
TCGTemp *src1, TCGTemp *src2)
{
@@ -1217,28 +1246,6 @@ void tcg_gen_xori(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_muls2, TCG_TYPE_I32, 0)) {
- tcg_gen_op4_i32(INDEX_op_muls2, rl, rh, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I32, 0)) {
- TCGv_i32 t = tcg_temp_ebb_new_i32();
- tcg_gen_op3_i32(INDEX_op_mul, t, arg1, arg2);
- tcg_gen_op3_i32(INDEX_op_mulsh, rh, arg1, arg2);
- tcg_gen_mov_i32(rl, t);
- tcg_temp_free_i32(t);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- tcg_gen_ext_i32_i64(t0, arg1);
- tcg_gen_ext_i32_i64(t1, arg2);
- tcg_gen_mul_i64(t0, t0, t1);
- tcg_gen_extr_i64_i32(rl, rh, t0);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
{
TCGv_i64 t0 = tcg_temp_ebb_new_i64();
@@ -1702,44 +1709,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b)
}
}
-void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_muls2, TCG_TYPE_I64, 0)) {
- tcg_gen_op4_i64(INDEX_op_muls2, rl, rh, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I64, 0)) {
- TCGv_i64 t = tcg_temp_ebb_new_i64();
- tcg_gen_op3_i64(INDEX_op_mul, t, arg1, arg2);
- tcg_gen_op3_i64(INDEX_op_mulsh, rh, arg1, arg2);
- tcg_gen_mov_i64(rl, t);
- tcg_temp_free_i64(t);
- } else if (tcg_op_supported(INDEX_op_mulu2, TCG_TYPE_I64, 0) ||
- tcg_op_supported(INDEX_op_muluh, TCG_TYPE_I64, 0)) {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- TCGv_i64 t2 = tcg_temp_ebb_new_i64();
- TCGv_i64 t3 = tcg_temp_ebb_new_i64();
- tcg_gen_mulu2_i64(t0, t1, arg1, arg2);
- /* Adjust for negative inputs. */
- tcg_gen_sari_i64(t2, arg1, 63);
- tcg_gen_sari_i64(t3, arg2, 63);
- tcg_gen_and_i64(t2, t2, arg2);
- tcg_gen_and_i64(t3, t3, arg1);
- tcg_gen_sub_i64(rh, t1, t2);
- tcg_gen_sub_i64(rh, rh, t3);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
- tcg_temp_free_i64(t3);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- tcg_gen_mul_i64(t0, arg1, arg2);
- gen_helper_mulsh_i64(rh, arg1, arg2);
- tcg_gen_mov_i64(rl, t0);
- tcg_temp_free_i64(t0);
- }
-}
-
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2)
{
TCGv_i64 t0 = tcg_temp_ebb_new_i64();
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_*
2026-09-27 8:59 ` [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_* Richard Henderson
@ 2026-09-29 23:40 ` Matt Turner
2026-09-29 23:42 ` Matt Turner
1 sibling, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:40 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:07 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 -
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 131 +++++++++++++----------------------
> 3 files changed, 51 insertions(+), 83 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 41a4d52d497..5f73601ddf7 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
>
> /* 32 bit ops */
>
> -void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
> void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
> @@ -156,7 +155,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
> /* 64 bit ops */
>
> void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
> -void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index b24122173a2..b606aaab128 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -35,6 +35,7 @@ DEF2(movi, TCGV, TINT)
> DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
> DEF3(mul, TCGV, TCGV, TCGV)
> DEF3(muli, TCGV, TCGV, TINT)
> +DEF4(muls2, TCGV, TCGV, TCGV, TCGV)
> DEF4(mulu2, TCGV, TCGV, TCGV, TCGV)
> DEF3(nand, TCGV, TCGV, TCGV)
> DEF2(neg, TCGV, TCGV)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index f107e3a85ea..61d50294a68 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -129,13 +129,6 @@ static void DNI tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2)
> tcg_gen_op2(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2));
> }
>
> -static void DNI tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 a1,
> - TCGv_i32 a2, TCGv_i32 a3)
> -{
> - tcg_gen_op3(opc, TCG_TYPE_I32, tcgv_i32_arg(a1),
> - tcgv_i32_arg(a2), tcgv_i32_arg(a3));
> -}
> -
> static void DNI tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 a1,
> TCGv_i64 a2, TCGv_i64 a3)
> {
> @@ -169,20 +162,6 @@ static void DNI tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
> tcgv_ptr_arg(base), offset);
> }
>
> -static void DNI tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
> - TCGv_i32 a3, TCGv_i32 a4)
> -{
> - tcg_gen_op4(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
> - tcgv_i32_arg(a3), tcgv_i32_arg(a4));
> -}
> -
> -static void DNI tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
> - TCGv_i64 a3, TCGv_i64 a4)
> -{
> - tcg_gen_op4(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
> - tcgv_i64_arg(a3), tcgv_i64_arg(a4));
> -}
> -
> /* Generic ops. */
>
> void gen_set_label(TCGLabel *l)
> @@ -778,6 +757,56 @@ void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> }
> }
>
> +void tcg_gen_muls2(TCGType type, TCGTemp *rl, TCGTemp *rh,
> + TCGTemp *src1, TCGTemp *src2)
> +{
> + if (tcg_op_supported(INDEX_op_muls2, type, 0)) {
> + tcg_gen_op_tttt(INDEX_op_muls2, type, rl, rh, src1, src2);
> + } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I32, 0)) {
s/TCG_TYPE_I32/type/ since that's how mulsh is emitted a couple lines below.
> + g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
> +
> + tcg_gen_mul(type, t, src1, src2);
> + tcg_gen_op_ttt(INDEX_op_mulsh, type, rh, src1, src2);
> + tcg_gen_mov(type, rl, t);
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_*
2026-09-27 8:59 ` [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_* Richard Henderson
2026-09-29 23:40 ` Matt Turner
@ 2026-09-29 23:42 ` Matt Turner
2026-10-02 6:38 ` Richard Henderson
1 sibling, 1 reply; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:42 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:07 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 -
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 131 +++++++++++++----------------------
> 3 files changed, 51 insertions(+), 83 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 41a4d52d497..5f73601ddf7 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
>
> /* 32 bit ops */
>
> -void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
> void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
> @@ -156,7 +155,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
> /* 64 bit ops */
>
> void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
> -void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
> void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index b24122173a2..b606aaab128 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -35,6 +35,7 @@ DEF2(movi, TCGV, TINT)
> DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
> DEF3(mul, TCGV, TCGV, TCGV)
> DEF3(muli, TCGV, TCGV, TINT)
> +DEF4(muls2, TCGV, TCGV, TCGV, TCGV)
> DEF4(mulu2, TCGV, TCGV, TCGV, TCGV)
> DEF3(nand, TCGV, TCGV, TCGV)
> DEF2(neg, TCGV, TCGV)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index f107e3a85ea..61d50294a68 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -129,13 +129,6 @@ static void DNI tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2)
> tcg_gen_op2(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2));
> }
>
> -static void DNI tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 a1,
> - TCGv_i32 a2, TCGv_i32 a3)
> -{
> - tcg_gen_op3(opc, TCG_TYPE_I32, tcgv_i32_arg(a1),
> - tcgv_i32_arg(a2), tcgv_i32_arg(a3));
> -}
> -
> static void DNI tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 a1,
> TCGv_i64 a2, TCGv_i64 a3)
> {
> @@ -169,20 +162,6 @@ static void DNI tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
> tcgv_ptr_arg(base), offset);
> }
>
> -static void DNI tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2,
> - TCGv_i32 a3, TCGv_i32 a4)
> -{
> - tcg_gen_op4(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2),
> - tcgv_i32_arg(a3), tcgv_i32_arg(a4));
> -}
> -
> -static void DNI tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2,
> - TCGv_i64 a3, TCGv_i64 a4)
> -{
> - tcg_gen_op4(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2),
> - tcgv_i64_arg(a3), tcgv_i64_arg(a4));
> -}
> -
> /* Generic ops. */
>
> void gen_set_label(TCGLabel *l)
> @@ -778,6 +757,56 @@ void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2)
> }
> }
>
> +void tcg_gen_muls2(TCGType type, TCGTemp *rl, TCGTemp *rh,
> + TCGTemp *src1, TCGTemp *src2)
> +{
> + if (tcg_op_supported(INDEX_op_muls2, type, 0)) {
> + tcg_gen_op_tttt(INDEX_op_muls2, type, rl, rh, src1, src2);
> + } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I32, 0)) {
> + g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
> +
> + tcg_gen_mul(type, t, src1, src2);
> + tcg_gen_op_ttt(INDEX_op_mulsh, type, rh, src1, src2);
> + tcg_gen_mov(type, rl, t);
> + } else if (type == TCG_TYPE_I32) {
> + g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
> + g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
... and these need to be TCG_TYPE_I64 I think?
> +
> + /* Simply extend and use host 64-bit multiply. */
> + tcg_gen_exts(t0, src1);
> + tcg_gen_exts(t1, src2);
> + tcg_gen_mul(TCG_TYPE_I64, t0, t0, t1);
> + tcg_gen_extrl(rl, t0);
> + tcg_gen_extrh(rh, t0);
^ permalink raw reply [flat|nested] 197+ messages in thread* Re: [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_*
2026-09-29 23:42 ` Matt Turner
@ 2026-10-02 6:38 ` Richard Henderson
0 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-10-02 6:38 UTC (permalink / raw)
To: Matt Turner; +Cc: qemu-devel
On 9/30/26 01:42, Matt Turner wrote:
>> +void tcg_gen_muls2(TCGType type, TCGTemp *rl, TCGTemp *rh,
>> + TCGTemp *src1, TCGTemp *src2)
>> +{
>> + if (tcg_op_supported(INDEX_op_muls2, type, 0)) {
>> + tcg_gen_op_tttt(INDEX_op_muls2, type, rl, rh, src1, src2);
>> + } else if (tcg_op_supported(INDEX_op_mulsh, TCG_TYPE_I32, 0)) {
>> + g_autoptr(TCGTemp) t = tcg_temp_new_ebb(type);
>> +
>> + tcg_gen_mul(type, t, src1, src2);
>> + tcg_gen_op_ttt(INDEX_op_mulsh, type, rh, src1, src2);
>> + tcg_gen_mov(type, rl, t);
>> + } else if (type == TCG_TYPE_I32) {
>> + g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
>> + g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
>
> ... and these need to be TCG_TYPE_I64 I think?
Good eyes.
While we still officially support hosts that require this path, I don't
have one for testing. :-/
r~
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 084/101] tcg: Use unsigned for flags for bswap and revbit operations
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (82 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 083/101] tcg: Generic expansion of tcg_gen_muls2_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 14:56 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 085/101] tcg: Generic expansion of tcg_gen_bswap16_* Richard Henderson
` (16 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 8 ++++----
tcg/tcg-op.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 5f73601ddf7..7971619ba92 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -133,7 +133,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags);
+void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, unsigned flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -158,13 +158,13 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
-void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
+void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
+void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags);
+void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 61d50294a68..e593a4d8758 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1305,7 +1305,7 @@ static void gen_bitswap_i64(TCGv_i64 ret, TCGv_i64 arg, uint64_t mask)
* With TCG_BSWAP_IZ, x == zero, else undefined.
* With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
*/
-void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
+void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, unsigned flags)
{
/* Only one extension flag may be present. */
tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
@@ -1506,7 +1506,7 @@ void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
* With TCG_BSWAP_IZ, x == zero, else undefined.
* With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
*/
-void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
+void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags)
{
/* Only one extension flag may be present. */
tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
@@ -1549,7 +1549,7 @@ void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
* With TCG_BSWAP_IZ, x == zero, else undefined.
* With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
*/
-void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
+void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags)
{
/* Only one extension flag may be present. */
tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
@@ -1616,7 +1616,7 @@ void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg)
tcg_gen_rotli_i64(ret, arg, 32);
}
-void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
+void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags)
{
/* Only one extension flag may be present. */
tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 085/101] tcg: Generic expansion of tcg_gen_bswap16_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (83 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 084/101] tcg: Use unsigned for flags for bswap and revbit operations Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 8:59 ` [PATCH v5 086/101] tcg: Split out gen_bitswap Richard Henderson
` (15 subsequent siblings)
100 siblings, 0 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 -
tcg/tcg-internal.h | 6 ++
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 120 ++++++++++-------------------------
4 files changed, 41 insertions(+), 88 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 7971619ba92..d5915ecc1bb 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -133,7 +133,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, unsigned flags);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
@@ -158,7 +157,6 @@ void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index 09899cb3091..d6ea11d8fcd 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -108,6 +108,12 @@ static inline void tcg_gen_op_tt(TCGOpcode opc, TCGType type,
tcg_gen_op2(opc, type, temp_arg(t0), temp_arg(t1));
}
+static inline void tcg_gen_op_tti(TCGOpcode opc, TCGType type,
+ TCGTemp *t0, TCGTemp *t1, TCGArg a2)
+{
+ tcg_gen_op3(opc, type, temp_arg(t0), temp_arg(t1), a2);
+}
+
static inline void tcg_gen_op_ttt(TCGOpcode opc, TCGType type,
TCGTemp *t0, TCGTemp *t1, TCGTemp *t2)
{
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index b606aaab128..2ebcf4a0665 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -11,6 +11,7 @@ DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
+DEF3(bswap16, TCGV, TCGV, unsigned)
DEF2(clrsb, TCGV, TCGV)
DEF3(clz, TCGV, TCGV, TCGV)
DEF3(clzi, TCGV, TCGV, TINT)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index e593a4d8758..0bf7c2fdff1 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -426,6 +426,40 @@ void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp *src1,
tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
}
+void tcg_gen_bswap16(TCGType type, TCGTemp *dst, TCGTemp *src, unsigned flags)
+{
+ /* Only one extension flag may be present. */
+ tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
+
+ if (tcg_op_supported(INDEX_op_bswap16, type, 0)) {
+ tcg_gen_op_tti(INDEX_op_bswap16, type, dst, src, flags);
+ } else {
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+ int width = tcg_type_size(type) * 8;
+
+ if (flags & TCG_BSWAP_IZ) { /* t0 = ...a */
+ tcg_gen_shri(type, t0, src, 8);
+ } else {
+ tcg_gen_extract(type, t0, src, 8, 8);
+ }
+
+ if (flags & TCG_BSWAP_OS) {
+ tcg_gen_shli(type, t1, src, width - 8); /* t1 = b... */
+ tcg_gen_sari(type, t1, t1, width - 16); /* t1 = ssb. */
+ } else if (flags & TCG_BSWAP_OZ) {
+ tcg_gen_ext8u(type, t1, src); /* t1 = ...b */
+ tcg_gen_shli(type, t1, t1, 8); /* t1 = ..b. */
+ } else {
+ tcg_gen_shli(type, t1, src, 8); /* t1 = xab. */
+ }
+
+ tcg_gen_or(type, dst, t0, t1); /* ret = ..ba (OZ) */
+ /* = ssba (OS) */
+ /* = xaba (0) */
+ }
+}
+
void tcg_gen_clrsb(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
@@ -1297,49 +1331,6 @@ static void gen_bitswap_i64(TCGv_i64 ret, TCGv_i64 arg, uint64_t mask)
tcg_temp_free_i64(t1);
}
-/*
- * bswap16_i32: 16-bit byte swap on the low bits of a 32-bit value.
- *
- * Byte pattern: xxab -> yyba
- *
- * With TCG_BSWAP_IZ, x == zero, else undefined.
- * With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
- */
-void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, unsigned flags)
-{
- /* Only one extension flag may be present. */
- tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
-
- if (tcg_op_supported(INDEX_op_bswap16, TCG_TYPE_I32, 0)) {
- tcg_gen_op3i_i32(INDEX_op_bswap16, ret, arg, flags);
- } else {
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
-
- /* arg = ..ab (IZ) xxab (!IZ) */
- tcg_gen_shri_i32(t0, arg, 8); /* t0 = ...a (IZ) .xxa (!IZ) */
- if (!(flags & TCG_BSWAP_IZ)) {
- tcg_gen_ext8u_i32(t0, t0); /* t0 = ...a */
- }
-
- if (flags & TCG_BSWAP_OS) {
- tcg_gen_shli_i32(t1, arg, 24); /* t1 = b... */
- tcg_gen_sari_i32(t1, t1, 16); /* t1 = ssb. */
- } else if (flags & TCG_BSWAP_OZ) {
- tcg_gen_ext8u_i32(t1, arg); /* t1 = ...b */
- tcg_gen_shli_i32(t1, t1, 8); /* t1 = ..b. */
- } else {
- tcg_gen_shli_i32(t1, arg, 8); /* t1 = xab. */
- }
-
- tcg_gen_or_i32(ret, t0, t1); /* ret = ..ba (OZ) */
- /* = ssba (OS) */
- /* = xaba (no flag) */
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
- }
-}
-
/*
* bswap32_i32: 32-bit byte swap on a 32-bit value.
*
@@ -1498,49 +1489,6 @@ void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
tcg_gen_extract_i64(ret, arg, 0, 32);
}
-/*
- * bswap16_i64: 16-bit byte swap on the low bits of a 64-bit value.
- *
- * Byte pattern: xxxxxxxxab -> yyyyyyyyba
- *
- * With TCG_BSWAP_IZ, x == zero, else undefined.
- * With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
- */
-void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags)
-{
- /* Only one extension flag may be present. */
- tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));
-
- if (tcg_op_supported(INDEX_op_bswap16, TCG_TYPE_I64, 0)) {
- tcg_gen_op3i_i64(INDEX_op_bswap16, ret, arg, flags);
- } else {
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
-
- /* arg = ......ab or xxxxxxab */
- tcg_gen_shri_i64(t0, arg, 8); /* t0 = .......a or .xxxxxxa */
- if (!(flags & TCG_BSWAP_IZ)) {
- tcg_gen_ext8u_i64(t0, t0); /* t0 = .......a */
- }
-
- if (flags & TCG_BSWAP_OS) {
- tcg_gen_shli_i64(t1, arg, 56); /* t1 = b....... */
- tcg_gen_sari_i64(t1, t1, 48); /* t1 = ssssssb. */
- } else if (flags & TCG_BSWAP_OZ) {
- tcg_gen_ext8u_i64(t1, arg); /* t1 = .......b */
- tcg_gen_shli_i64(t1, t1, 8); /* t1 = ......b. */
- } else {
- tcg_gen_shli_i64(t1, arg, 8); /* t1 = xxxxxab. */
- }
-
- tcg_gen_or_i64(ret, t0, t1); /* ret = ......ba (OZ) */
- /* ssssssba (OS) */
- /* xxxxxaba (no flag) */
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
- }
-}
-
/*
* bswap32_i64: 32-bit byte swap on the low bits of a 64-bit value.
*
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 086/101] tcg: Split out gen_bitswap
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (84 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 085/101] tcg: Generic expansion of tcg_gen_bswap16_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-27 14:58 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 087/101] tcg: Generic expansion of tcg_gen_revbit8_* Richard Henderson
` (14 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
We'll need this for other generic expansions.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-op.c | 58 ++++++++++++++++++++++------------------------------
1 file changed, 25 insertions(+), 33 deletions(-)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 0bf7c2fdff1..0c6146cfbe6 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -290,6 +290,27 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef DEF5
#undef DEF6
+/*
+ * Internal helper for bit and byte reversal.
+ * Given a repeating matched block of 1's and 0's, swap the bits within
+ * those two blocks. E.g. mask=00ff00ff, shift the input bits left and
+ * right 8 bits.
+ */
+static void tcg_gen_bitswap(TCGType type, TCGTemp *dst,
+ TCGTemp *src, uint64_t mask)
+{
+ g_autoptr(TCGTemp) t0 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+ TCGTemp *tmask = tcg_constant_internal(type, mask);
+ TCGTemp *tshift = tcg_constant_internal(type, cto64(mask));
+
+ tcg_gen_and(type, t0, src, tmask);
+ tcg_gen_shr(type, t1, src, tshift);
+ tcg_gen_shl(type, t0, t0, tshift);
+ tcg_gen_and(type, t1, t1, tmask);
+ tcg_gen_or(type, dst, t0, t1);
+}
+
/*
* Generic expansions for templated operations.
* We have used compiler type checks to ensure all TCGTemp
@@ -1292,43 +1313,14 @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_temp_free_i64(t1);
}
-/*
- * Internal helper for bit and byte reversal.
- * Given a repeating matched block of 1's and 0's, swap the bits within
- * those two blocks. E.g. mask=00ff00ff, shift the input bits left and
- * right 8 bits.
- */
-static void gen_bitswap_i32(TCGv_i32 ret, TCGv_i32 arg, uint32_t mask)
+static void gen_bitswap_i32(TCGv_i32 dst, TCGv_i32 src, uint32_t mask)
{
- TCGv_i32 t0 = tcg_temp_ebb_new_i32();
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- int sh = cto32(mask);
-
- tcg_gen_andi_i32(t0, arg, mask);
- tcg_gen_shri_i32(t1, arg, sh);
- tcg_gen_shli_i32(t0, t0, sh);
- tcg_gen_andi_i32(t1, t1, mask);
- tcg_gen_or_i32(ret, t0, t1);
-
- tcg_temp_free_i32(t0);
- tcg_temp_free_i32(t1);
+ tcg_gen_bitswap(TCG_TYPE_I32, tcgv_i32_temp(dst), tcgv_i32_temp(src), mask);
}
-/* Similarly for 64-bit operands. */
-static void gen_bitswap_i64(TCGv_i64 ret, TCGv_i64 arg, uint64_t mask)
+static void gen_bitswap_i64(TCGv_i64 dst, TCGv_i64 src, uint64_t mask)
{
- TCGv_i64 t0 = tcg_temp_ebb_new_i64();
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- int sh = cto64(mask);
-
- tcg_gen_andi_i64(t0, arg, mask);
- tcg_gen_shri_i64(t1, arg, sh);
- tcg_gen_shli_i64(t0, t0, sh);
- tcg_gen_andi_i64(t1, t1, mask);
- tcg_gen_or_i64(ret, t0, t1);
-
- tcg_temp_free_i64(t0);
- tcg_temp_free_i64(t1);
+ tcg_gen_bitswap(TCG_TYPE_I64, tcgv_i64_temp(dst), tcgv_i64_temp(src), mask);
}
/*
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 087/101] tcg: Generic expansion of tcg_gen_revbit8_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (85 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 086/101] tcg: Split out gen_bitswap Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-29 23:19 ` Matt Turner
2026-09-27 8:59 ` [PATCH v5 088/101] tcg: Generic expansion of tcg_gen_ld_* Richard Henderson
` (13 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 51 +++++++++++++-----------------------
3 files changed, 19 insertions(+), 35 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index d5915ecc1bb..ed503462a2e 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -135,7 +135,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
@@ -161,7 +160,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 2ebcf4a0665..ab1bf259296 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -49,6 +49,7 @@ DEF3(ori, TCGV, TCGV, TINT)
DEF3(orc, TCGV, TCGV, TCGV)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
+DEF2(revbit8, TCGV, TCGV)
DEF3(rotl, TCGV, TCGV, TCGV)
DEF3(rotli, TCGV, TCGV, TINT)
DEF3(rotr, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 0c6146cfbe6..17f323b1b72 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -119,11 +119,6 @@ static TCGOp * DNI tcg_gen_op1i(TCGOpcode opc, TCGType type, TCGArg a1)
return tcg_gen_op1(opc, type, a1);
}
-static void DNI tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2)
-{
- tcg_gen_op2(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2));
-}
-
static void DNI tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2)
{
tcg_gen_op2(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2));
@@ -1016,6 +1011,24 @@ void tcg_gen_remu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_revbit8(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ static const TCGOpcode revw[2] = { INDEX_op_revbit32, INDEX_op_revbit64 };
+ static const TCGOpcode bswapw[2] = { INDEX_op_bswap32, INDEX_op_bswap64 };
+
+ if (tcg_op_supported(INDEX_op_revbit8, type, 0)) {
+ tcg_gen_op_tt(INDEX_op_revbit8, type, dst, src);
+ } else if (tcg_op_supported(revw[type], type, 0) &&
+ tcg_op_supported(bswapw[type], type, 0)) {
+ tcg_gen_op_tt(revw[type], type, dst, src);
+ tcg_gen_op_tti(bswapw[type], type, dst, dst, 0);
+ } else {
+ tcg_gen_bitswap(type, dst, src, 0x5555555555555555ull);
+ tcg_gen_bitswap(type, dst, dst, 0x3333333333333333ull);
+ tcg_gen_bitswap(type, dst, dst, 0x0f0f0f0f0f0f0f0full);
+ }
+}
+
void tcg_gen_rotl(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_rotl, type, 0)) {
@@ -1349,20 +1362,6 @@ void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg)
tcg_gen_rotli_i32(ret, arg, 16);
}
-void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg)
-{
- if (tcg_op_supported(INDEX_op_revbit8, TCG_TYPE_I32, 0)) {
- tcg_gen_op2_i32(INDEX_op_revbit8, ret, arg);
- } else if (tcg_op_supported(INDEX_op_revbit32, TCG_TYPE_I32, 0)) {
- tcg_gen_op2_i32(INDEX_op_revbit32, ret, arg);
- tcg_gen_bswap32_i32(ret, ret);
- } else {
- gen_bitswap_i32(ret, arg, 0x55555555u);
- gen_bitswap_i32(ret, ret, 0x33333333u);
- gen_bitswap_i32(ret, ret, 0x0f0f0f0fu);
- }
-}
-
void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
{
if (tcg_op_supported(INDEX_op_revbit32, TCG_TYPE_I32, 0)) {
@@ -1583,20 +1582,6 @@ void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags)
}
}
-void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg)
-{
- if (tcg_op_supported(INDEX_op_revbit8, TCG_TYPE_I64, 0)) {
- tcg_gen_op2_i64(INDEX_op_revbit8, ret, arg);
- } else if (tcg_op_supported(INDEX_op_revbit64, TCG_TYPE_I64, 0)) {
- tcg_gen_op2_i64(INDEX_op_revbit64, ret, arg);
- tcg_gen_bswap64_i64(ret, ret);
- } else {
- gen_bitswap_i64(ret, arg, 0x5555555555555555ull);
- gen_bitswap_i64(ret, ret, 0x3333333333333333ull);
- gen_bitswap_i64(ret, ret, 0x0f0f0f0f0f0f0f0full);
- }
-}
-
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
{
if (tcg_op_supported(INDEX_op_revbit64, TCG_TYPE_I64, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 087/101] tcg: Generic expansion of tcg_gen_revbit8_*
2026-09-27 8:59 ` [PATCH v5 087/101] tcg: Generic expansion of tcg_gen_revbit8_* Richard Henderson
@ 2026-09-29 23:19 ` Matt Turner
0 siblings, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:19 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:07 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 51 +++++++++++++-----------------------
> 3 files changed, 19 insertions(+), 35 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index d5915ecc1bb..ed503462a2e 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -135,7 +135,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
> void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
> void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
> -void tcg_gen_revbit8_i32(TCGv_i32 ret, TCGv_i32 arg);
> void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
>
> /* Replicate a value of size @vece from @in to all the lanes in @out */
> @@ -161,7 +160,6 @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
> void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
> -void tcg_gen_revbit8_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
> void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
>
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index 2ebcf4a0665..ab1bf259296 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -49,6 +49,7 @@ DEF3(ori, TCGV, TCGV, TINT)
> DEF3(orc, TCGV, TCGV, TCGV)
> DEF3(rem, TCGV, TCGV, TCGV)
> DEF3(remu, TCGV, TCGV, TCGV)
> +DEF2(revbit8, TCGV, TCGV)
> DEF3(rotl, TCGV, TCGV, TCGV)
> DEF3(rotli, TCGV, TCGV, TINT)
> DEF3(rotr, TCGV, TCGV, TCGV)
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 0c6146cfbe6..17f323b1b72 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -119,11 +119,6 @@ static TCGOp * DNI tcg_gen_op1i(TCGOpcode opc, TCGType type, TCGArg a1)
> return tcg_gen_op1(opc, type, a1);
> }
>
> -static void DNI tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 a1, TCGv_i32 a2)
> -{
> - tcg_gen_op2(opc, TCG_TYPE_I32, tcgv_i32_arg(a1), tcgv_i32_arg(a2));
> -}
> -
> static void DNI tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 a1, TCGv_i64 a2)
> {
> tcg_gen_op2(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2));
> @@ -1016,6 +1011,24 @@ void tcg_gen_remu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> }
> }
>
> +void tcg_gen_revbit8(TCGType type, TCGTemp *dst, TCGTemp *src)
> +{
> + static const TCGOpcode revw[2] = { INDEX_op_revbit32, INDEX_op_revbit64 };
> + static const TCGOpcode bswapw[2] = { INDEX_op_bswap32, INDEX_op_bswap64 };
> +
> + if (tcg_op_supported(INDEX_op_revbit8, type, 0)) {
> + tcg_gen_op_tt(INDEX_op_revbit8, type, dst, src);
> + } else if (tcg_op_supported(revw[type], type, 0) &&
> + tcg_op_supported(bswapw[type], type, 0)) {
> + tcg_gen_op_tt(revw[type], type, dst, src);
> + tcg_gen_op_tti(bswapw[type], type, dst, dst, 0);
> + } else {
> + tcg_gen_bitswap(type, dst, src, 0x5555555555555555ull);
> + tcg_gen_bitswap(type, dst, dst, 0x3333333333333333ull);
> + tcg_gen_bitswap(type, dst, dst, 0x0f0f0f0f0f0f0f0full);
When called with type=I32, src2 won't be in the canonical (i.e.
sign-extended) form.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 088/101] tcg: Generic expansion of tcg_gen_ld_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (86 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 087/101] tcg: Generic expansion of tcg_gen_revbit8_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:57 ` Philippe Mathieu-Daudé
2026-09-27 8:59 ` [PATCH v5 089/101] tcg: Generic expansion of tcg_gen_ld8s_* Richard Henderson
` (12 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
tcg/tcg-internal.h | 6 ++++--
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 19 +++++++++----------
4 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index ed503462a2e..b7c31ad6c8c 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -144,7 +144,6 @@ void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
@@ -176,7 +175,6 @@ void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* Size changing operations. */
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index d6ea11d8fcd..bfd34905ee7 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -191,13 +191,15 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
-#define TCGV TCGTemp *
-#define TINT int64_t
+#define TCGV TCGTemp *
+#define TINT int64_t
+#define TCGv_ptr TCGTemp *
#include "tcg/tcg-op-def.h.inc"
#undef TINT
#undef TCGV
+#undef TCGv_ptr
#undef DEF1
#undef DEF2
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index ab1bf259296..6284358a132 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -31,6 +31,7 @@ DEF2(ext16u, TCGV, TCGV)
DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF4(extract2, TCGV, TCGV, TCGV, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
+DEF3(ld, TCGV, TCGv_ptr, tcg_target_long)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 17f323b1b72..4d6838e8dc3 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -240,11 +240,13 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#define C_TCGv_i32 tcgv_i32_temp
#define C_TCGv_i64 tcgv_i64_temp
+#define C_TCGv_ptr tcgv_ptr_temp
#define C_int32_t
#define C_int64_t
#define C_MemOp
#define C_TCGCond
#define C_TCGLabelPtr
+#define C_tcg_target_long
#define C_unsigned
#define TCGV glue(TCGv,TExt)
@@ -271,11 +273,13 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_TCGv_i32
#undef C_TCGv_i64
+#undef C_TCGv_ptr
#undef C_int32_t
#undef C_int64_t
#undef C_MemOp
#undef C_TCGCond
#undef C_TCGLabelPtr
+#undef C_tcg_target_long
#undef C_unsigned
#undef DEF1
@@ -767,6 +771,11 @@ void tcg_gen_extract2(TCGType type, TCGTemp *dst, TCGTemp *lo, TCGTemp *hi,
}
}
+void tcg_gen_ld(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_ld, type, dst, base, ofs);
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1392,11 +1401,6 @@ void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i32(INDEX_op_ld16s, ret, arg2, offset);
}
-void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_ld, ret, arg2, offset);
-}
-
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
@@ -1445,11 +1449,6 @@ void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_ld32s, ret, arg2, offset);
}
-void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_ld, ret, arg2, offset);
-}
-
void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_st8, arg1, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 088/101] tcg: Generic expansion of tcg_gen_ld_*
2026-09-27 8:59 ` [PATCH v5 088/101] tcg: Generic expansion of tcg_gen_ld_* Richard Henderson
@ 2026-09-28 9:57 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 9:57 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 10:59, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 2 --
> tcg/tcg-internal.h | 6 ++++--
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op.c | 19 +++++++++----------
> 4 files changed, 14 insertions(+), 14 deletions(-)
> diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
> index d6ea11d8fcd..bfd34905ee7 100644
> --- a/tcg/tcg-internal.h
> +++ b/tcg/tcg-internal.h
> @@ -191,13 +191,15 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
> #define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
> QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
>
> -#define TCGV TCGTemp *
> -#define TINT int64_t
> +#define TCGV TCGTemp *
> +#define TINT int64_t
Squash in [PATCH v5 009/101] tcg: Generic expansion of tcg_gen_mov_*.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 089/101] tcg: Generic expansion of tcg_gen_ld8s_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (87 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 088/101] tcg: Generic expansion of tcg_gen_ld_* Richard Henderson
@ 2026-09-27 8:59 ` Richard Henderson
2026-09-28 9:57 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 090/101] tcg: Generic expansion of tcg_gen_ld8u_* Richard Henderson
` (11 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 8:59 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 16 ++++++----------
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index b7c31ad6c8c..981dfb73019 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -141,7 +141,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
@@ -170,7 +169,6 @@ void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 6284358a132..a110e645104 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -32,6 +32,7 @@ DEF4(extract, TCGV, TCGV, unsigned, unsigned)
DEF4(extract2, TCGV, TCGV, TCGV, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF3(ld, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(ld8s, TCGV, TCGv_ptr, tcg_target_long)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 4d6838e8dc3..cbed2ce790f 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -776,6 +776,12 @@ void tcg_gen_ld(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
tcg_gen_op_tti(INDEX_op_ld, type, dst, base, ofs);
}
+void tcg_gen_ld8s(TCGType type, TCGTemp *dst,
+ TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_ld8s, type, dst, base, ofs);
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1386,11 +1392,6 @@ void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i32(INDEX_op_ld8u, ret, arg2, offset);
}
-void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_ld8s, ret, arg2, offset);
-}
-
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_ld16u, ret, arg2, offset);
@@ -1424,11 +1425,6 @@ void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_ld8u, ret, arg2, offset);
}
-void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_ld8s, ret, arg2, offset);
-}
-
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld16u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 090/101] tcg: Generic expansion of tcg_gen_ld8u_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (88 preceding siblings ...)
2026-09-27 8:59 ` [PATCH v5 089/101] tcg: Generic expansion of tcg_gen_ld8s_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:58 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 091/101] tcg: Generic expansion of tcg_gen_ld16s_* Richard Henderson
` (10 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 16 ++++++----------
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 981dfb73019..bf300de4b9f 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -140,7 +140,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
@@ -168,7 +167,6 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index a110e645104..75bb38a07e5 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -33,6 +33,7 @@ DEF4(extract2, TCGV, TCGV, TCGV, unsigned)
DEF3(eqv, TCGV, TCGV, TCGV)
DEF3(ld, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld8s, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(ld8u, TCGV, TCGv_ptr, tcg_target_long)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index cbed2ce790f..608010bb542 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -782,6 +782,12 @@ void tcg_gen_ld8s(TCGType type, TCGTemp *dst,
tcg_gen_op_tti(INDEX_op_ld8s, type, dst, base, ofs);
}
+void tcg_gen_ld8u(TCGType type, TCGTemp *dst,
+ TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_ld8u, type, dst, base, ofs);
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1387,11 +1393,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_ld8u, ret, arg2, offset);
-}
-
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_ld16u, ret, arg2, offset);
@@ -1420,11 +1421,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
/* 64-bit ops */
-void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_ld8u, ret, arg2, offset);
-}
-
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld16u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 091/101] tcg: Generic expansion of tcg_gen_ld16s_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (89 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 090/101] tcg: Generic expansion of tcg_gen_ld8u_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:58 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 092/101] tcg: Generic expansion of tcg_gen_ld16u_* Richard Henderson
` (9 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 16 ++++++----------
3 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index bf300de4b9f..3782d1839fc 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -141,7 +141,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
@@ -168,7 +167,6 @@ void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 75bb38a07e5..785c417a74e 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -34,6 +34,7 @@ DEF3(eqv, TCGV, TCGV, TCGV)
DEF3(ld, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld8s, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld8u, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(ld16s, TCGV, TCGv_ptr, tcg_target_long)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 608010bb542..af28243cb73 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -788,6 +788,12 @@ void tcg_gen_ld8u(TCGType type, TCGTemp *dst,
tcg_gen_op_tti(INDEX_op_ld8u, type, dst, base, ofs);
}
+void tcg_gen_ld16s(TCGType type, TCGTemp *dst,
+ TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_ld16s, type, dst, base, ofs);
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1398,11 +1404,6 @@ void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i32(INDEX_op_ld16u, ret, arg2, offset);
}
-void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_ld16s, ret, arg2, offset);
-}
-
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
@@ -1426,11 +1427,6 @@ void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_ld16u, ret, arg2, offset);
}
-void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_ld16s, ret, arg2, offset);
-}
-
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld32u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 092/101] tcg: Generic expansion of tcg_gen_ld16u_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (90 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 091/101] tcg: Generic expansion of tcg_gen_ld16s_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:58 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 093/101] tcg: Generic expansion of tcg_gen_st_* Richard Henderson
` (8 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 3 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 16 ++++++----------
3 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 3782d1839fc..a2786b8bd55 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -140,8 +140,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset);
-
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
@@ -166,7 +164,6 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 785c417a74e..98a07a70f09 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -35,6 +35,7 @@ DEF3(ld, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld8s, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld8u, TCGV, TCGv_ptr, tcg_target_long)
DEF3(ld16s, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(ld16u, TCGV, TCGv_ptr, tcg_target_long)
DEF2(mov, TCGV, TCGV)
DEF2(movi, TCGV, TINT)
DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index af28243cb73..647c7d1308b 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -794,6 +794,12 @@ void tcg_gen_ld16s(TCGType type, TCGTemp *dst,
tcg_gen_op_tti(INDEX_op_ld16s, type, dst, base, ofs);
}
+void tcg_gen_ld16u(TCGType type, TCGTemp *dst,
+ TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_ld16u, type, dst, base, ofs);
+}
+
void tcg_gen_mov(TCGType type, TCGTemp *dst, TCGTemp *src)
{
if (src != dst) {
@@ -1399,11 +1405,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_ld16u, ret, arg2, offset);
-}
-
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
@@ -1422,11 +1423,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
/* 64-bit ops */
-void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_ld16u, ret, arg2, offset);
-}
-
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_ld32u, ret, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 093/101] tcg: Generic expansion of tcg_gen_st_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (91 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 092/101] tcg: Generic expansion of tcg_gen_ld16u_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:59 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 094/101] tcg: Generic expansion of tcg_gen_st8_* Richard Henderson
` (7 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 16 +++++-----------
3 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index a2786b8bd55..6c10f15167d 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -142,7 +142,6 @@ void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
@@ -166,7 +165,6 @@ void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
-void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* Size changing operations. */
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 98a07a70f09..514967f91db 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -70,6 +70,7 @@ DEF3(shr, TCGV, TCGV, TCGV)
DEF3(shri, TCGV, TCGV, TINT)
DEF3(smax, TCGV, TCGV, TCGV)
DEF3(smin, TCGV, TCGV, TCGV)
+DEF3(st, TCGV, TCGv_ptr, tcg_target_long)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF6(sub2, TCGV, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 647c7d1308b..20622be3daf 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1254,6 +1254,11 @@ void tcg_gen_smin(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_st(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_st, type, dst, base, ofs);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -1415,12 +1420,6 @@ void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i32(INDEX_op_st16, arg1, arg2, offset);
}
-void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_st, arg1, arg2, offset);
-}
-
-
/* 64-bit ops */
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
@@ -1448,11 +1447,6 @@ void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_st32, arg1, arg2, offset);
}
-void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_st, arg1, arg2, offset);
-}
-
void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
{
tcg_gen_sextract_i64(ret, arg, 0, 32);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 094/101] tcg: Generic expansion of tcg_gen_st8_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (92 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 093/101] tcg: Generic expansion of tcg_gen_st_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:59 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 095/101] tcg: Generic expansion of tcg_gen_st16_* Richard Henderson
` (6 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 15 +++++----------
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 6c10f15167d..b04a9a76e00 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -140,7 +140,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
/* 64 bit ops */
@@ -159,7 +158,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in);
-void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 514967f91db..90bcf9e5ab8 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -71,6 +71,7 @@ DEF3(shri, TCGV, TCGV, TINT)
DEF3(smax, TCGV, TCGV, TCGV)
DEF3(smin, TCGV, TCGV, TCGV)
DEF3(st, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(st8, TCGV, TCGv_ptr, tcg_target_long)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF6(sub2, TCGV, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 20622be3daf..257ce2c3e6d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1259,6 +1259,11 @@ void tcg_gen_st(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
tcg_gen_op_tti(INDEX_op_st, type, dst, base, ofs);
}
+void tcg_gen_st8(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_st8, type, dst, base, ofs);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -1410,11 +1415,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
-}
-
void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i32(INDEX_op_st16, arg1, arg2, offset);
@@ -1432,11 +1432,6 @@ void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_ld32s, ret, arg2, offset);
}
-void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_st8, arg1, arg2, offset);
-}
-
void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_st16, arg1, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 095/101] tcg: Generic expansion of tcg_gen_st16_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (93 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 094/101] tcg: Generic expansion of tcg_gen_st8_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 9:59 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 096/101] tcg: Generic expansion of tcg_gen_dup_* Richard Henderson
` (5 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 3 ---
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 23 ++++++-----------------
3 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index b04a9a76e00..65b9d828e38 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -140,8 +140,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset);
-
/* 64 bit ops */
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
@@ -158,7 +156,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
/* Replicate a value of size @vece from @in to all the lanes in @out */
void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in);
-void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 90bcf9e5ab8..f9dab50a911 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -72,6 +72,7 @@ DEF3(smax, TCGV, TCGV, TCGV)
DEF3(smin, TCGV, TCGV, TCGV)
DEF3(st, TCGV, TCGv_ptr, tcg_target_long)
DEF3(st8, TCGV, TCGv_ptr, tcg_target_long)
+DEF3(st16, TCGV, TCGv_ptr, tcg_target_long)
DEF3(sub, TCGV, TCGV, TCGV)
DEF3(subi, TCGV, TCGV, TINT)
DEF6(sub2, TCGV, TCGV, TCGV, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 257ce2c3e6d..2e8087c938c 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -143,13 +143,6 @@ static void DNI tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 a1,
tcg_gen_op3(opc, TCG_TYPE_I64, tcgv_i64_arg(a1), tcgv_i64_arg(a2), a3);
}
-static void DNI tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
- TCGv_ptr base, TCGArg offset)
-{
- tcg_gen_op3(opc, TCG_TYPE_I32, tcgv_i32_arg(val),
- tcgv_ptr_arg(base), offset);
-}
-
static void DNI tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
TCGv_ptr base, TCGArg offset)
{
@@ -1264,6 +1257,12 @@ void tcg_gen_st8(TCGType type, TCGTemp *dst, TCGTemp *base, tcg_target_long ofs)
tcg_gen_op_tti(INDEX_op_st8, type, dst, base, ofs);
}
+void tcg_gen_st16(TCGType type, TCGTemp *dst,
+ TCGTemp *base, tcg_target_long ofs)
+{
+ tcg_gen_op_tti(INDEX_op_st16, type, dst, base, ofs);
+}
+
void tcg_gen_sub(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
tcg_gen_op_ttt(INDEX_op_sub, type, dst, src1, src2);
@@ -1415,11 +1414,6 @@ void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}
-void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i32(INDEX_op_st16, arg1, arg2, offset);
-}
-
/* 64-bit ops */
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
@@ -1432,11 +1426,6 @@ void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
tcg_gen_ldst_op_i64(INDEX_op_ld32s, ret, arg2, offset);
}
-void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
-{
- tcg_gen_ldst_op_i64(INDEX_op_st16, arg1, arg2, offset);
-}
-
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
{
tcg_gen_ldst_op_i64(INDEX_op_st32, arg1, arg2, offset);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* [PATCH v5 096/101] tcg: Generic expansion of tcg_gen_dup_*
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (94 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 095/101] tcg: Generic expansion of tcg_gen_st16_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-29 23:28 ` Matt Turner
2026-09-27 9:00 ` [PATCH v5 097/101] tcg: Generic expansion of tcg_gen_qemu_ld_chk Richard Henderson
` (4 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 6 ------
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op-gvec.c | 41 ------------------------------------
tcg/tcg-op.c | 16 ++++++++++++++
4 files changed, 17 insertions(+), 47 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 65b9d828e38..583f6ebb2f5 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -137,9 +137,6 @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
-/* Replicate a value of size @vece from @in to all the lanes in @out */
-void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
-
/* 64 bit ops */
void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
@@ -153,9 +150,6 @@ void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
-/* Replicate a value of size @vece from @in to all the lanes in @out */
-void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in);
-
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index f9dab50a911..556f7470cd6 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -23,6 +23,7 @@ DEF4(deposit_z, TCGV, TCGV, unsigned, unsigned)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
+DEF3(dup, unsigned, TCGV, TCGV)
DEF3(ext, TCGV, TCGV, MemOp)
DEF2(ext8s, TCGV, TCGV)
DEF2(ext8u, TCGV, TCGV)
diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c
index 0d649cc13b2..72abb0a08ec 100644
--- a/tcg/tcg-op-gvec.c
+++ b/tcg/tcg-op-gvec.c
@@ -434,47 +434,6 @@ uint64_t (dup_const)(unsigned vece, uint64_t c)
}
}
-/* Duplicate IN into OUT as per VECE. */
-void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in)
-{
- switch (vece) {
- case MO_8:
- tcg_gen_ext8u_i32(out, in);
- tcg_gen_muli_i32(out, out, 0x01010101);
- break;
- case MO_16:
- tcg_gen_deposit_i32(out, in, in, 16, 16);
- break;
- case MO_32:
- tcg_gen_mov_i32(out, in);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
-void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in)
-{
- switch (vece) {
- case MO_8:
- tcg_gen_ext8u_i64(out, in);
- tcg_gen_muli_i64(out, out, 0x0101010101010101ull);
- break;
- case MO_16:
- tcg_gen_ext16u_i64(out, in);
- tcg_gen_muli_i64(out, out, 0x0001000100010001ull);
- break;
- case MO_32:
- tcg_gen_deposit_i64(out, in, in, 32, 32);
- break;
- case MO_64:
- tcg_gen_mov_i64(out, in);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
/* Select a supported vector type for implementing an operation on SIZE
* bytes. If OP is 0, assume that the real operation to be performed is
* required by all backends. Otherwise, make sure than OP can be performed
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2e8087c938c..924b94414b7 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -661,6 +661,22 @@ void tcg_gen_divu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
}
}
+void tcg_gen_dup(TCGType type, unsigned vece, TCGTemp *dst, TCGTemp *src)
+{
+ unsigned t_width = tcg_type_size(type) * 8;
+ unsigned e_width = memop_size(vece) * 8;
+
+ tcg_debug_assert(e_width <= t_width);
+ if (t_width == e_width) {
+ tcg_gen_mov(type, dst, src);
+ } else if (t_width == e_width * 2) {
+ tcg_gen_deposit(type, dst, src, src, e_width, e_width);
+ } else {
+ tcg_gen_extract(type, dst, src, 0, e_width);
+ tcg_gen_muli(type, dst, dst, ~0ull / MAKE_64BIT_MASK(0, e_width));
+ }
+}
+
void tcg_gen_eqv(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
{
if (tcg_op_supported(INDEX_op_eqv, type, 0)) {
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 096/101] tcg: Generic expansion of tcg_gen_dup_*
2026-09-27 9:00 ` [PATCH v5 096/101] tcg: Generic expansion of tcg_gen_dup_* Richard Henderson
@ 2026-09-29 23:28 ` Matt Turner
0 siblings, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:28 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:08 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 6 ------
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op-gvec.c | 41 ------------------------------------
> tcg/tcg-op.c | 16 ++++++++++++++
> 4 files changed, 17 insertions(+), 47 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 65b9d828e38..583f6ebb2f5 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -137,9 +137,6 @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
> void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
> void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
>
> -/* Replicate a value of size @vece from @in to all the lanes in @out */
> -void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in);
> -
> /* 64 bit ops */
>
> void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
> @@ -153,9 +150,6 @@ void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
> void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
> void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
>
> -/* Replicate a value of size @vece from @in to all the lanes in @out */
> -void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in);
> -
> void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
>
> void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index f9dab50a911..556f7470cd6 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -23,6 +23,7 @@ DEF4(deposit_z, TCGV, TCGV, unsigned, unsigned)
> DEF1(discard, TCGV)
> DEF3(div, TCGV, TCGV, TCGV)
> DEF3(divu, TCGV, TCGV, TCGV)
> +DEF3(dup, unsigned, TCGV, TCGV)
> DEF3(ext, TCGV, TCGV, MemOp)
> DEF2(ext8s, TCGV, TCGV)
> DEF2(ext8u, TCGV, TCGV)
> diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c
> index 0d649cc13b2..72abb0a08ec 100644
> --- a/tcg/tcg-op-gvec.c
> +++ b/tcg/tcg-op-gvec.c
> @@ -434,47 +434,6 @@ uint64_t (dup_const)(unsigned vece, uint64_t c)
> }
> }
>
> -/* Duplicate IN into OUT as per VECE. */
> -void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in)
> -{
> - switch (vece) {
> - case MO_8:
> - tcg_gen_ext8u_i32(out, in);
> - tcg_gen_muli_i32(out, out, 0x01010101);
> - break;
> - case MO_16:
> - tcg_gen_deposit_i32(out, in, in, 16, 16);
> - break;
> - case MO_32:
> - tcg_gen_mov_i32(out, in);
> - break;
> - default:
> - g_assert_not_reached();
> - }
> -}
> -
> -void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in)
> -{
> - switch (vece) {
> - case MO_8:
> - tcg_gen_ext8u_i64(out, in);
> - tcg_gen_muli_i64(out, out, 0x0101010101010101ull);
> - break;
> - case MO_16:
> - tcg_gen_ext16u_i64(out, in);
> - tcg_gen_muli_i64(out, out, 0x0001000100010001ull);
> - break;
> - case MO_32:
> - tcg_gen_deposit_i64(out, in, in, 32, 32);
> - break;
> - case MO_64:
> - tcg_gen_mov_i64(out, in);
> - break;
> - default:
> - g_assert_not_reached();
> - }
> -}
> -
> /* Select a supported vector type for implementing an operation on SIZE
> * bytes. If OP is 0, assume that the real operation to be performed is
> * required by all backends. Otherwise, make sure than OP can be performed
> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
> index 2e8087c938c..924b94414b7 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -661,6 +661,22 @@ void tcg_gen_divu(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
> }
> }
>
> +void tcg_gen_dup(TCGType type, unsigned vece, TCGTemp *dst, TCGTemp *src)
> +{
> + unsigned t_width = tcg_type_size(type) * 8;
> + unsigned e_width = memop_size(vece) * 8;
> +
> + tcg_debug_assert(e_width <= t_width);
> + if (t_width == e_width) {
> + tcg_gen_mov(type, dst, src);
> + } else if (t_width == e_width * 2) {
> + tcg_gen_deposit(type, dst, src, src, e_width, e_width);
> + } else {
> + tcg_gen_extract(type, dst, src, 0, e_width);
> + tcg_gen_muli(type, dst, dst, ~0ull / MAKE_64BIT_MASK(0, e_width));
For I32 with MO_8 this multiplies by an I32 constant
0x0101010101010101 rather than 0x01010101.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 097/101] tcg: Generic expansion of tcg_gen_qemu_ld_chk
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (95 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 096/101] tcg: Generic expansion of tcg_gen_dup_* Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-29 23:48 ` Matt Turner
2026-09-27 9:00 ` [PATCH v5 098/101] tcg: Generic expansion of tcg_gen_qemu_st_chk Richard Henderson
` (3 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 4 +-
include/tcg/tcg-op-mem.h | 6 +-
include/tcg/tcg.h | 2 +
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op-ldst.c | 164 ++++++++++++++---------------------
tcg/tcg-op.c | 4 +
6 files changed, 75 insertions(+), 106 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 583f6ebb2f5..fcbaae3def5 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -177,11 +177,9 @@ void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
/* Local load/store bit ops */
-void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType);
+void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
void tcg_gen_qemu_st_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType);
-void tcg_gen_qemu_ld_i64_chk(TCGv_i64, TCGTemp *, TCGArg, MemOp, TCGType);
void tcg_gen_qemu_st_i64_chk(TCGv_i64, TCGTemp *, TCGArg, MemOp, TCGType);
-void tcg_gen_qemu_ld_i128_chk(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
void tcg_gen_qemu_st_i128_chk(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
/* Atomic ops */
diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
index 29e7c02f256..76955d27c1f 100644
--- a/include/tcg/tcg-op-mem.h
+++ b/include/tcg/tcg-op-mem.h
@@ -31,7 +31,7 @@ typedef TCGv_i64 TCGv_va;
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_ld_chk_i32(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
QEMU_ARG_NONNULL static inline void
@@ -43,7 +43,7 @@ tcg_gen_qemu_st_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_ld_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_ld_chk_i64(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
QEMU_ARG_NONNULL static inline void
@@ -55,7 +55,7 @@ tcg_gen_qemu_st_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_ld_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_ld_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_ld_chk_i128(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
QEMU_ARG_NONNULL static inline void
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
index 077a1b37021..fd719f9a36a 100644
--- a/include/tcg/tcg.h
+++ b/include/tcg/tcg.h
@@ -293,6 +293,8 @@ typedef struct TCGTemp {
void *state_ptr;
} TCGTemp;
+typedef TCGTemp *TCGTempPtr;
+
typedef struct TCGContext TCGContext;
typedef struct TCGTempSet {
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 556f7470cd6..e2da3ddef66 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -53,6 +53,7 @@ DEF2(not, TCGV, TCGV)
DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
DEF3(orc, TCGV, TCGV, TCGV)
+DEF5(qemu_ld_chk, TCGV, TCGTempPtr, unsigned, MemOp, TCGType)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF2(revbit8, TCGV, TCGV)
diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
index 031c5ce926b..c48b8c0e3d1 100644
--- a/tcg/tcg-op-ldst.c
+++ b/tcg/tcg-op-ldst.c
@@ -191,33 +191,37 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi,
#endif
static void
-plugin_gen_mem_callbacks_i32(TCGv_i32 val,
+plugin_gen_mem_callbacks_tmp(TCGType type, TCGTemp *val,
TCGv_i64 copy_addr, TCGTemp *orig_addr,
MemOpIdx oi, enum qemu_plugin_mem_rw rw)
{
#ifdef CONFIG_PLUGIN
if (tcg_ctx->plugin_insn != NULL) {
- tcg_gen_st_i32(val, tcg_env,
- offsetof(CPUState, neg.plugin_mem_value_low) -
- sizeof(CPUState) + (HOST_BIG_ENDIAN * 4));
+ tcg_gen_st(type, val, tcgv_ptr_temp(tcg_env),
+ offsetof(CPUState, neg.plugin_mem_value_low)
+ - sizeof(CPUState)
+ + (HOST_BIG_ENDIAN && type == TCG_TYPE_I32 ? 4 : 0));
plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw);
}
#endif
}
+static void
+plugin_gen_mem_callbacks_i32(TCGv_i32 val,
+ TCGv_i64 copy_addr, TCGTemp *orig_addr,
+ MemOpIdx oi, enum qemu_plugin_mem_rw rw)
+{
+ plugin_gen_mem_callbacks_tmp(TCG_TYPE_I32, tcgv_i32_temp(val), copy_addr,
+ orig_addr, oi, rw);
+}
+
static void
plugin_gen_mem_callbacks_i64(TCGv_i64 val,
TCGv_i64 copy_addr, TCGTemp *orig_addr,
MemOpIdx oi, enum qemu_plugin_mem_rw rw)
{
-#ifdef CONFIG_PLUGIN
- if (tcg_ctx->plugin_insn != NULL) {
- tcg_gen_st_i64(val, tcg_env,
- offsetof(CPUState, neg.plugin_mem_value_low) -
- sizeof(CPUState));
- plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw);
- }
-#endif
+ plugin_gen_mem_callbacks_tmp(TCG_TYPE_I64, tcgv_i64_temp(val), copy_addr,
+ orig_addr, oi, rw);
}
static void
@@ -238,8 +242,31 @@ plugin_gen_mem_callbacks_i128(TCGv_i128 val,
#endif
}
-static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr,
- TCGArg idx, MemOp memop)
+static void tcg_gen_bswap(TCGType type, TCGTemp *dst,
+ TCGTemp *src, unsigned flags, MemOp memop)
+{
+ switch (memop & MO_SIZE) {
+ case MO_16:
+ tcg_gen_bswap16(type, src, dst, flags);
+ break;
+ case MO_32:
+ if (type == TCG_TYPE_I32) {
+ tcg_gen_bswap32_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
+ } else {
+ tcg_gen_bswap32_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src), flags);
+ }
+ break;
+ case MO_64:
+ tcg_debug_assert(type == TCG_TYPE_I64);
+ tcg_gen_bswap64_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+static void tcg_gen_qemu_ld_int(TCGType type, TCGTemp *val,
+ TCGTemp *addr, TCGArg idx, MemOp memop)
{
MemOp orig_memop;
MemOpIdx orig_oi, oi;
@@ -247,48 +274,40 @@ static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr,
TCGTemp *addr_new;
tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
- orig_memop = memop = tcg_canonicalize_memop(memop, 0, 0);
+ memop = tcg_canonicalize_memop(memop, type != TCG_TYPE_I32, 0);
+ orig_memop = memop;
orig_oi = oi = make_memop_idx(memop, idx);
if ((memop & MO_BSWAP) && !tcg_target_has_memory_bswap(memop)) {
- memop &= ~MO_BSWAP;
/* The bswap primitive benefits from zero-extended input. */
- if ((memop & MO_SSIZE) == MO_SW) {
- memop &= ~MO_SIGN;
- }
+ memop &= ~(MO_BSWAP | MO_SIGN);
oi = make_memop_idx(memop, idx);
}
addr_new = tci_extend_addr(addr);
copy_addr = plugin_maybe_preserve_addr(addr);
- gen_ldst1(INDEX_op_qemu_ld, TCG_TYPE_I32, tcgv_i32_temp(val), addr_new, oi);
+ tcg_gen_op_tti(INDEX_op_qemu_ld, type, val, addr_new, oi);
if ((orig_memop ^ memop) & MO_BSWAP) {
- switch (orig_memop & MO_SIZE) {
- case MO_16:
- tcg_gen_bswap16_i32(val, val, (orig_memop & MO_SIGN
- ? TCG_BSWAP_IZ | TCG_BSWAP_OS
- : TCG_BSWAP_IZ | TCG_BSWAP_OZ));
- break;
- case MO_32:
- tcg_gen_bswap32_i32(val, val);
- break;
- default:
- g_assert_not_reached();
- }
+ int flags = (orig_memop & MO_SIGN
+ ? TCG_BSWAP_IZ | TCG_BSWAP_OS
+ : TCG_BSWAP_IZ | TCG_BSWAP_OZ);
+ tcg_gen_bswap(type, val, val, flags, orig_memop);
}
- plugin_gen_mem_callbacks_i32(val, copy_addr, addr, orig_oi,
- QEMU_PLUGIN_MEM_R);
+ plugin_gen_mem_callbacks_tmp(type, val, copy_addr, addr,
+ orig_oi, QEMU_PLUGIN_MEM_R);
maybe_free_addr(addr, addr_new);
}
-void tcg_gen_qemu_ld_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
- MemOp memop, TCGType addr_type)
+void tcg_gen_qemu_ld_chk(TCGType val_type, TCGTemp *val, TCGTemp *addr,
+ unsigned idx, MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_32);
- tcg_gen_qemu_ld_i32_int(val, addr, idx, memop);
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type));
+ tcg_debug_assert(idx < NB_MMU_MODES);
+
+ tcg_gen_qemu_ld_int(val_type, val, addr, idx, memop);
}
static void tcg_gen_qemu_st_i32_int(TCGv_i32 orig_val, TCGTemp *addr,
@@ -337,63 +356,6 @@ void tcg_gen_qemu_st_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
tcg_gen_qemu_st_i32_int(val, addr, idx, memop);
}
-static void tcg_gen_qemu_ld_i64_int(TCGv_i64 val, TCGTemp *addr,
- TCGArg idx, MemOp memop)
-{
- MemOp orig_memop;
- MemOpIdx orig_oi, oi;
- TCGv_i64 copy_addr;
- TCGTemp *addr_new;
-
- tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD);
- orig_memop = memop = tcg_canonicalize_memop(memop, 1, 0);
- orig_oi = oi = make_memop_idx(memop, idx);
-
- if ((memop & MO_BSWAP) && !tcg_target_has_memory_bswap(memop)) {
- memop &= ~MO_BSWAP;
- /* The bswap primitive benefits from zero-extended input. */
- if ((memop & MO_SIGN) && (memop & MO_SIZE) < MO_64) {
- memop &= ~MO_SIGN;
- }
- oi = make_memop_idx(memop, idx);
- }
-
- addr_new = tci_extend_addr(addr);
- copy_addr = plugin_maybe_preserve_addr(addr);
- gen_ld_i64(val, addr_new, oi);
-
- if ((orig_memop ^ memop) & MO_BSWAP) {
- int flags = (orig_memop & MO_SIGN
- ? TCG_BSWAP_IZ | TCG_BSWAP_OS
- : TCG_BSWAP_IZ | TCG_BSWAP_OZ);
- switch (orig_memop & MO_SIZE) {
- case MO_16:
- tcg_gen_bswap16_i64(val, val, flags);
- break;
- case MO_32:
- tcg_gen_bswap32_i64(val, val, flags);
- break;
- case MO_64:
- tcg_gen_bswap64_i64(val, val);
- break;
- default:
- g_assert_not_reached();
- }
- }
-
- plugin_gen_mem_callbacks_i64(val, copy_addr, addr, orig_oi,
- QEMU_PLUGIN_MEM_R);
- maybe_free_addr(addr, addr_new);
-}
-
-void tcg_gen_qemu_ld_i64_chk(TCGv_i64 val, TCGTemp *addr, TCGArg idx,
- MemOp memop, TCGType addr_type)
-{
- tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_64);
- tcg_gen_qemu_ld_i64_int(val, addr, idx, memop);
-}
-
static void tcg_gen_qemu_st_i64_int(TCGv_i64 orig_val, TCGTemp *addr,
TCGArg idx, MemOp memop)
{
@@ -638,7 +600,7 @@ static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr,
QEMU_PLUGIN_MEM_R);
}
-void tcg_gen_qemu_ld_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx,
+void tcg_gen_qemu_ld_chk_i128(TCGv_i128 val, TCGTemp *addr, TCGArg idx,
MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
@@ -800,7 +762,8 @@ static void tcg_gen_nonatomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
tcg_gen_ext_i32(t2, cmpv, memop & MO_SIZE);
- tcg_gen_qemu_ld_i32_int(t1, addr, idx, memop & ~MO_SIGN);
+ tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1),
+ addr, idx, memop & ~MO_SIGN);
tcg_gen_movcond_i32(TCG_COND_EQ, t2, t1, t2, newv, t1);
tcg_gen_qemu_st_i32_int(t2, addr, idx, memop);
tcg_temp_free_i32(t2);
@@ -871,7 +834,8 @@ static void tcg_gen_nonatomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
tcg_gen_ext_i64(t2, cmpv, memop & MO_SIZE);
- tcg_gen_qemu_ld_i64_int(t1, addr, idx, memop & ~MO_SIGN);
+ tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1),
+ addr, idx, memop & ~MO_SIGN);
tcg_gen_movcond_i64(TCG_COND_EQ, t2, t1, t2, newv, t1);
tcg_gen_qemu_st_i64_int(t2, addr, idx, memop);
tcg_temp_free_i64(t2);
@@ -1047,7 +1011,7 @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
memop = tcg_canonicalize_memop(memop, 0, 0);
- tcg_gen_qemu_ld_i32_int(t1, addr, idx, memop);
+ tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1), addr, idx, memop);
tcg_gen_ext_i32(t2, val, memop);
gen(t2, t1, t2);
tcg_gen_qemu_st_i32_int(t2, addr, idx, memop);
@@ -1088,7 +1052,7 @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
memop = tcg_canonicalize_memop(memop, 1, 0);
- tcg_gen_qemu_ld_i64_int(t1, addr, idx, memop);
+ tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1), addr, idx, memop);
tcg_gen_ext_i64(t2, val, memop);
gen(t2, t1, t2);
tcg_gen_qemu_st_i64_int(t2, addr, idx, memop);
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 924b94414b7..c68e9e10501 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -239,6 +239,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#define C_MemOp
#define C_TCGCond
#define C_TCGLabelPtr
+#define C_TCGTempPtr
+#define C_TCGType
#define C_tcg_target_long
#define C_unsigned
@@ -272,6 +274,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef C_MemOp
#undef C_TCGCond
#undef C_TCGLabelPtr
+#undef C_TCGTempPtr
+#undef C_TCGType
#undef C_tcg_target_long
#undef C_unsigned
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 097/101] tcg: Generic expansion of tcg_gen_qemu_ld_chk
2026-09-27 9:00 ` [PATCH v5 097/101] tcg: Generic expansion of tcg_gen_qemu_ld_chk Richard Henderson
@ 2026-09-29 23:48 ` Matt Turner
0 siblings, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-29 23:48 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:08 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 4 +-
> include/tcg/tcg-op-mem.h | 6 +-
> include/tcg/tcg.h | 2 +
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op-ldst.c | 164 ++++++++++++++---------------------
> tcg/tcg-op.c | 4 +
> 6 files changed, 75 insertions(+), 106 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 583f6ebb2f5..fcbaae3def5 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -177,11 +177,9 @@ void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
>
> /* Local load/store bit ops */
>
> -void tcg_gen_qemu_ld_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType);
> +void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
> void tcg_gen_qemu_st_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType);
> -void tcg_gen_qemu_ld_i64_chk(TCGv_i64, TCGTemp *, TCGArg, MemOp, TCGType);
> void tcg_gen_qemu_st_i64_chk(TCGv_i64, TCGTemp *, TCGArg, MemOp, TCGType);
> -void tcg_gen_qemu_ld_i128_chk(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
> void tcg_gen_qemu_st_i128_chk(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
>
> /* Atomic ops */
> diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
> index 29e7c02f256..76955d27c1f 100644
> --- a/include/tcg/tcg-op-mem.h
> +++ b/include/tcg/tcg-op-mem.h
> @@ -31,7 +31,7 @@ typedef TCGv_i64 TCGv_va;
> QEMU_ARG_NONNULL static inline void
> tcg_gen_qemu_ld_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
> {
> - tcg_gen_qemu_ld_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> + tcg_gen_qemu_ld_chk_i32(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> }
>
> QEMU_ARG_NONNULL static inline void
> @@ -43,7 +43,7 @@ tcg_gen_qemu_st_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
> QEMU_ARG_NONNULL static inline void
> tcg_gen_qemu_ld_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
> {
> - tcg_gen_qemu_ld_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> + tcg_gen_qemu_ld_chk_i64(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> }
>
> QEMU_ARG_NONNULL static inline void
> @@ -55,7 +55,7 @@ tcg_gen_qemu_st_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
> QEMU_ARG_NONNULL static inline void
> tcg_gen_qemu_ld_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
> {
> - tcg_gen_qemu_ld_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> + tcg_gen_qemu_ld_chk_i128(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
> }
>
> QEMU_ARG_NONNULL static inline void
> diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
> index 077a1b37021..fd719f9a36a 100644
> --- a/include/tcg/tcg.h
> +++ b/include/tcg/tcg.h
> @@ -293,6 +293,8 @@ typedef struct TCGTemp {
> void *state_ptr;
> } TCGTemp;
>
> +typedef TCGTemp *TCGTempPtr;
> +
> typedef struct TCGContext TCGContext;
>
> typedef struct TCGTempSet {
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index 556f7470cd6..e2da3ddef66 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -53,6 +53,7 @@ DEF2(not, TCGV, TCGV)
> DEF3(or, TCGV, TCGV, TCGV)
> DEF3(ori, TCGV, TCGV, TINT)
> DEF3(orc, TCGV, TCGV, TCGV)
> +DEF5(qemu_ld_chk, TCGV, TCGTempPtr, unsigned, MemOp, TCGType)
> DEF3(rem, TCGV, TCGV, TCGV)
> DEF3(remu, TCGV, TCGV, TCGV)
> DEF2(revbit8, TCGV, TCGV)
> diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
> index 031c5ce926b..c48b8c0e3d1 100644
> --- a/tcg/tcg-op-ldst.c
> +++ b/tcg/tcg-op-ldst.c
> @@ -191,33 +191,37 @@ plugin_gen_mem_callbacks(TCGv_i64 copy_addr, TCGTemp *orig_addr, MemOpIdx oi,
> #endif
>
> static void
> -plugin_gen_mem_callbacks_i32(TCGv_i32 val,
> +plugin_gen_mem_callbacks_tmp(TCGType type, TCGTemp *val,
> TCGv_i64 copy_addr, TCGTemp *orig_addr,
> MemOpIdx oi, enum qemu_plugin_mem_rw rw)
> {
> #ifdef CONFIG_PLUGIN
> if (tcg_ctx->plugin_insn != NULL) {
> - tcg_gen_st_i32(val, tcg_env,
> - offsetof(CPUState, neg.plugin_mem_value_low) -
> - sizeof(CPUState) + (HOST_BIG_ENDIAN * 4));
> + tcg_gen_st(type, val, tcgv_ptr_temp(tcg_env),
> + offsetof(CPUState, neg.plugin_mem_value_low)
> + - sizeof(CPUState)
> + + (HOST_BIG_ENDIAN && type == TCG_TYPE_I32 ? 4 : 0));
> plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw);
> }
> #endif
> }
>
> +static void
> +plugin_gen_mem_callbacks_i32(TCGv_i32 val,
> + TCGv_i64 copy_addr, TCGTemp *orig_addr,
> + MemOpIdx oi, enum qemu_plugin_mem_rw rw)
> +{
> + plugin_gen_mem_callbacks_tmp(TCG_TYPE_I32, tcgv_i32_temp(val), copy_addr,
> + orig_addr, oi, rw);
> +}
> +
> static void
> plugin_gen_mem_callbacks_i64(TCGv_i64 val,
> TCGv_i64 copy_addr, TCGTemp *orig_addr,
> MemOpIdx oi, enum qemu_plugin_mem_rw rw)
> {
> -#ifdef CONFIG_PLUGIN
> - if (tcg_ctx->plugin_insn != NULL) {
> - tcg_gen_st_i64(val, tcg_env,
> - offsetof(CPUState, neg.plugin_mem_value_low) -
> - sizeof(CPUState));
> - plugin_gen_mem_callbacks(copy_addr, orig_addr, oi, rw);
> - }
> -#endif
> + plugin_gen_mem_callbacks_tmp(TCG_TYPE_I64, tcgv_i64_temp(val), copy_addr,
> + orig_addr, oi, rw);
> }
>
> static void
> @@ -238,8 +242,31 @@ plugin_gen_mem_callbacks_i128(TCGv_i128 val,
> #endif
> }
>
> -static void tcg_gen_qemu_ld_i32_int(TCGv_i32 val, TCGTemp *addr,
> - TCGArg idx, MemOp memop)
> +static void tcg_gen_bswap(TCGType type, TCGTemp *dst,
> + TCGTemp *src, unsigned flags, MemOp memop)
> +{
> + switch (memop & MO_SIZE) {
> + case MO_16:
> + tcg_gen_bswap16(type, src, dst, flags);
src and dst are swapped. The load path in this patch avoids this being
a problem because the same argument is passed for both src and dst,
but 098 has a path that ends up byte swapping an uninitialized value.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 098/101] tcg: Generic expansion of tcg_gen_qemu_st_chk
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (96 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 097/101] tcg: Generic expansion of tcg_gen_qemu_ld_chk Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-28 11:42 ` Philippe Mathieu-Daudé
2026-09-27 9:00 ` [PATCH v5 099/101] tcg: Generic expansion of tcg_gen_{non}atomic_qemu_cmpxchg_chk Richard Henderson
` (2 subsequent siblings)
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 6 +-
include/tcg/tcg-op-mem.h | 6 +-
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op-ldst.c | 114 ++++++-----------------------------
4 files changed, 25 insertions(+), 102 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index fcbaae3def5..4fec1500d56 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -175,12 +175,8 @@ void tcg_gen_mov_i128(TCGv_i128 dst, TCGv_i128 src);
void tcg_gen_ld_i128(TCGv_i128 ret, TCGv_ptr base, tcg_target_long offset);
void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
-/* Local load/store bit ops */
-
void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
-void tcg_gen_qemu_st_i32_chk(TCGv_i32, TCGTemp *, TCGArg, MemOp, TCGType);
-void tcg_gen_qemu_st_i64_chk(TCGv_i64, TCGTemp *, TCGArg, MemOp, TCGType);
-void tcg_gen_qemu_st_i128_chk(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
+void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
/* Atomic ops */
diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
index 76955d27c1f..e8425e10598 100644
--- a/include/tcg/tcg-op-mem.h
+++ b/include/tcg/tcg-op-mem.h
@@ -37,7 +37,7 @@ tcg_gen_qemu_ld_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i32(TCGv_i32 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_st_i32_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_st_chk_i32(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
QEMU_ARG_NONNULL static inline void
@@ -49,7 +49,7 @@ tcg_gen_qemu_ld_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i64(TCGv_i64 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_st_i64_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_st_chk_i64(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
QEMU_ARG_NONNULL static inline void
@@ -61,7 +61,7 @@ tcg_gen_qemu_ld_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
QEMU_ARG_NONNULL static inline void
tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
{
- tcg_gen_qemu_st_i128_chk(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
+ tcg_gen_qemu_st_chk_i128(v, tcgv_va_temp(a), i, m, TCG_TYPE_VA);
}
#define DEF_ATOMIC2(N, S) \
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index e2da3ddef66..552f62b7f4f 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -54,6 +54,7 @@ DEF3(or, TCGV, TCGV, TCGV)
DEF3(ori, TCGV, TCGV, TINT)
DEF3(orc, TCGV, TCGV, TCGV)
DEF5(qemu_ld_chk, TCGV, TCGTempPtr, unsigned, MemOp, TCGType)
+DEF5(qemu_st_chk, TCGV, TCGTempPtr, unsigned, MemOp, TCGType)
DEF3(rem, TCGV, TCGV, TCGV)
DEF3(remu, TCGV, TCGV, TCGV)
DEF2(revbit8, TCGV, TCGV)
diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
index c48b8c0e3d1..7345bdfcc2b 100644
--- a/tcg/tcg-op-ldst.c
+++ b/tcg/tcg-op-ldst.c
@@ -206,24 +206,6 @@ plugin_gen_mem_callbacks_tmp(TCGType type, TCGTemp *val,
#endif
}
-static void
-plugin_gen_mem_callbacks_i32(TCGv_i32 val,
- TCGv_i64 copy_addr, TCGTemp *orig_addr,
- MemOpIdx oi, enum qemu_plugin_mem_rw rw)
-{
- plugin_gen_mem_callbacks_tmp(TCG_TYPE_I32, tcgv_i32_temp(val), copy_addr,
- orig_addr, oi, rw);
-}
-
-static void
-plugin_gen_mem_callbacks_i64(TCGv_i64 val,
- TCGv_i64 copy_addr, TCGTemp *orig_addr,
- MemOpIdx oi, enum qemu_plugin_mem_rw rw)
-{
- plugin_gen_mem_callbacks_tmp(TCG_TYPE_I64, tcgv_i64_temp(val), copy_addr,
- orig_addr, oi, rw);
-}
-
static void
plugin_gen_mem_callbacks_i128(TCGv_i128 val,
TCGv_i64 copy_addr, TCGTemp *orig_addr,
@@ -310,99 +292,43 @@ void tcg_gen_qemu_ld_chk(TCGType val_type, TCGTemp *val, TCGTemp *addr,
tcg_gen_qemu_ld_int(val_type, val, addr, idx, memop);
}
-static void tcg_gen_qemu_st_i32_int(TCGv_i32 orig_val, TCGTemp *addr,
- TCGArg idx, MemOp memop)
+static void tcg_gen_qemu_st_int(TCGType type, TCGTemp *orig_val,
+ TCGTemp *addr, unsigned idx, MemOp memop)
{
- TCGv_i32 val = orig_val;
+ TCGTemp *val = orig_val;
MemOpIdx orig_oi, oi;
TCGTemp *addr_new;
tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST);
- memop = tcg_canonicalize_memop(memop, 0, 1);
+ memop = tcg_canonicalize_memop(memop, type != TCG_TYPE_I32, 1);
orig_oi = oi = make_memop_idx(memop, idx);
if ((memop & MO_BSWAP) && !tcg_target_has_memory_bswap(memop)) {
- val = tcg_temp_ebb_new_i32();
- switch (memop & MO_SIZE) {
- case MO_16:
- tcg_gen_bswap16_i32(val, orig_val, 0);
- break;
- case MO_32:
- tcg_gen_bswap32_i32(val, orig_val);
- break;
- default:
- g_assert_not_reached();
- }
+ val = tcg_temp_new_ebb(type);
+ tcg_gen_bswap(type, val, orig_val, 0, memop);
memop &= ~MO_BSWAP;
oi = make_memop_idx(memop, idx);
}
addr_new = tci_extend_addr(addr);
- gen_ldst1(INDEX_op_qemu_st, TCG_TYPE_I32, tcgv_i32_temp(val), addr_new, oi);
- plugin_gen_mem_callbacks_i32(orig_val, NULL, addr, orig_oi,
- QEMU_PLUGIN_MEM_W);
+ tcg_gen_op_tti(INDEX_op_qemu_st, type, val, addr_new, oi);
+ plugin_gen_mem_callbacks_tmp(type, orig_val, NULL, addr,
+ orig_oi, QEMU_PLUGIN_MEM_W);
maybe_free_addr(addr, addr_new);
if (val != orig_val) {
- tcg_temp_free_i32(val);
+ tcg_temp_free_internal(val);
}
}
-void tcg_gen_qemu_st_i32_chk(TCGv_i32 val, TCGTemp *addr, TCGArg idx,
- MemOp memop, TCGType addr_type)
+void tcg_gen_qemu_st_chk(TCGType val_type, TCGTemp *val, TCGTemp *addr,
+ unsigned idx, MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_32);
- tcg_gen_qemu_st_i32_int(val, addr, idx, memop);
-}
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type));
+ tcg_debug_assert(idx < NB_MMU_MODES);
-static void tcg_gen_qemu_st_i64_int(TCGv_i64 orig_val, TCGTemp *addr,
- TCGArg idx, MemOp memop)
-{
- TCGv_i64 val = orig_val;
- MemOpIdx orig_oi, oi;
- TCGTemp *addr_new;
-
- tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST);
- memop = tcg_canonicalize_memop(memop, 1, 1);
- orig_oi = oi = make_memop_idx(memop, idx);
-
- if ((memop & MO_BSWAP) && !tcg_target_has_memory_bswap(memop)) {
- val = tcg_temp_ebb_new_i64();
- switch (memop & MO_SIZE) {
- case MO_16:
- tcg_gen_bswap16_i64(val, orig_val, 0);
- break;
- case MO_32:
- tcg_gen_bswap32_i64(val, orig_val, 0);
- break;
- case MO_64:
- tcg_gen_bswap64_i64(val, orig_val);
- break;
- default:
- g_assert_not_reached();
- }
- memop &= ~MO_BSWAP;
- oi = make_memop_idx(memop, idx);
- }
-
- addr_new = tci_extend_addr(addr);
- gen_st_i64(val, addr_new, oi);
- plugin_gen_mem_callbacks_i64(orig_val, NULL, addr, orig_oi,
- QEMU_PLUGIN_MEM_W);
- maybe_free_addr(addr, addr_new);
-
- if (val != orig_val) {
- tcg_temp_free_i64(val);
- }
-}
-
-void tcg_gen_qemu_st_i64_chk(TCGv_i64 val, TCGTemp *addr, TCGArg idx,
- MemOp memop, TCGType addr_type)
-{
- tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_64);
- tcg_gen_qemu_st_i64_int(val, addr, idx, memop);
+ tcg_gen_qemu_st_int(val_type, val, addr, idx, memop);
}
/*
@@ -713,7 +639,7 @@ static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCGTemp *addr,
QEMU_PLUGIN_MEM_W);
}
-void tcg_gen_qemu_st_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx,
+void tcg_gen_qemu_st_chk_i128(TCGv_i128 val, TCGTemp *addr, TCGArg idx,
MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
@@ -765,7 +691,7 @@ static void tcg_gen_nonatomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1),
addr, idx, memop & ~MO_SIGN);
tcg_gen_movcond_i32(TCG_COND_EQ, t2, t1, t2, newv, t1);
- tcg_gen_qemu_st_i32_int(t2, addr, idx, memop);
+ tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
tcg_temp_free_i32(t2);
if (memop & MO_SIGN) {
@@ -837,7 +763,7 @@ static void tcg_gen_nonatomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1),
addr, idx, memop & ~MO_SIGN);
tcg_gen_movcond_i64(TCG_COND_EQ, t2, t1, t2, newv, t1);
- tcg_gen_qemu_st_i64_int(t2, addr, idx, memop);
+ tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
tcg_temp_free_i64(t2);
if (memop & MO_SIGN) {
@@ -1014,7 +940,7 @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1), addr, idx, memop);
tcg_gen_ext_i32(t2, val, memop);
gen(t2, t1, t2);
- tcg_gen_qemu_st_i32_int(t2, addr, idx, memop);
+ tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop);
tcg_temp_free_i32(t1);
@@ -1055,7 +981,7 @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1), addr, idx, memop);
tcg_gen_ext_i64(t2, val, memop);
gen(t2, t1, t2);
- tcg_gen_qemu_st_i64_int(t2, addr, idx, memop);
+ tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);
tcg_temp_free_i64(t1);
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 098/101] tcg: Generic expansion of tcg_gen_qemu_st_chk
2026-09-27 9:00 ` [PATCH v5 098/101] tcg: Generic expansion of tcg_gen_qemu_st_chk Richard Henderson
@ 2026-09-28 11:42 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-28 11:42 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 11:00, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 6 +-
> include/tcg/tcg-op-mem.h | 6 +-
> include/tcg/tcg-op-def.h.inc | 1 +
> tcg/tcg-op-ldst.c | 114 ++++++-----------------------------
> 4 files changed, 25 insertions(+), 102 deletions(-)
> -static void tcg_gen_qemu_st_i32_int(TCGv_i32 orig_val, TCGTemp *addr,
> - TCGArg idx, MemOp memop)
> +static void tcg_gen_qemu_st_int(TCGType type, TCGTemp *orig_val,
> + TCGTemp *addr, unsigned idx, MemOp memop)
> {
> - TCGv_i32 val = orig_val;
> + TCGTemp *val = orig_val;
> MemOpIdx orig_oi, oi;
> TCGTemp *addr_new;
>
> tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST);
> - memop = tcg_canonicalize_memop(memop, 0, 1);
> + memop = tcg_canonicalize_memop(memop, type != TCG_TYPE_I32, 1);
> orig_oi = oi = make_memop_idx(memop, idx);
>
> if ((memop & MO_BSWAP) && !tcg_target_has_memory_bswap(memop)) {
> - val = tcg_temp_ebb_new_i32();
> - switch (memop & MO_SIZE) {
> - case MO_16:
> - tcg_gen_bswap16_i32(val, orig_val, 0);
> - break;
> - case MO_32:
> - tcg_gen_bswap32_i32(val, orig_val);
> - break;
> - default:
> - g_assert_not_reached();
> - }
> + val = tcg_temp_new_ebb(type);
> + tcg_gen_bswap(type, val, orig_val, 0, memop);
> memop &= ~MO_BSWAP;
> oi = make_memop_idx(memop, idx);
> }
>
> addr_new = tci_extend_addr(addr);
> - gen_ldst1(INDEX_op_qemu_st, TCG_TYPE_I32, tcgv_i32_temp(val), addr_new, oi);
> - plugin_gen_mem_callbacks_i32(orig_val, NULL, addr, orig_oi,
> - QEMU_PLUGIN_MEM_W);
> + tcg_gen_op_tti(INDEX_op_qemu_st, type, val, addr_new, oi);
> + plugin_gen_mem_callbacks_tmp(type, orig_val, NULL, addr,
> + orig_oi, QEMU_PLUGIN_MEM_W);
> maybe_free_addr(addr, addr_new);
>
> if (val != orig_val) {
> - tcg_temp_free_i32(val);
> + tcg_temp_free_internal(val);
> }
Directly:
maybe_free_addr(val, orig_val);
> }
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 099/101] tcg: Generic expansion of tcg_gen_{non}atomic_qemu_cmpxchg_chk
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (97 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 098/101] tcg: Generic expansion of tcg_gen_qemu_st_chk Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-30 0:19 ` Matt Turner
2026-09-27 9:00 ` [PATCH v5 100/101] tcg: Generic expansion of remaining atomic operations Richard Henderson
2026-09-27 9:00 ` [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL Richard Henderson
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 16 +--
include/tcg/tcg-op-mem.h | 2 +-
tcg/tcg-internal.h | 3 +
include/tcg/tcg-op-def.h.inc | 3 +
tcg/tcg-op-ldst.c | 237 ++++++++++++++---------------------
tcg/tcg-op.c | 8 ++
6 files changed, 113 insertions(+), 156 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 4fec1500d56..9864674f1c2 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -104,6 +104,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5);
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6);
+#define DEF7(NAME, T1, T2, T3, T4, T5, T6, T7) \
+ QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6, T7);
#define TCGV glue(TCGv,TExt)
#define TExt _i32
@@ -129,6 +131,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
#undef DEF4
#undef DEF5
#undef DEF6
+#undef DEF7
/* 32 bit ops */
@@ -180,18 +183,9 @@ void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
/* Atomic ops */
-void tcg_gen_atomic_cmpxchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_cmpxchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_cmpxchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
+void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
-
-void tcg_gen_nonatomic_cmpxchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_nonatomic_cmpxchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_nonatomic_cmpxchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
+void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
void tcg_gen_atomic_xchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
index e8425e10598..935860f1442 100644
--- a/include/tcg/tcg-op-mem.h
+++ b/include/tcg/tcg-op-mem.h
@@ -72,7 +72,7 @@ tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
#define DEF_ATOMIC3(N, S) \
QEMU_ARG_NONNULL static inline void \
N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S o, TCGv_##S n, TCGArg i, MemOp m) \
- { N##_##S##_chk(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
+ { N##_chk_##S(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i32)
DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i64)
diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
index bfd34905ee7..da1b9c9bab3 100644
--- a/tcg/tcg-internal.h
+++ b/tcg/tcg-internal.h
@@ -190,6 +190,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5);
#define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
+#define DEF7(NAME, T1, T2, T3, T4, T5, T6, T7) \
+ QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6, T7);
#define TCGV TCGTemp *
#define TINT int64_t
@@ -207,6 +209,7 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
#undef DEF4
#undef DEF5
#undef DEF6
+#undef DEF7
static inline void tcg_gen_extrh(TCGTemp *dst, TCGTemp *src)
{
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 552f62b7f4f..e0ffd0da678 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -85,3 +85,6 @@ DEF3(umin, TCGV, TCGV, TCGV)
DEF3(ussub, TCGV, TCGV, TCGV)
DEF3(xor, TCGV, TCGV, TCGV)
DEF3(xori, TCGV, TCGV, TINT)
+
+DEF7(atomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
+DEF7(nonatomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
index 7345bdfcc2b..b3143f6311b 100644
--- a/tcg/tcg-op-ldst.c
+++ b/tcg/tcg-op-ldst.c
@@ -667,181 +667,125 @@ typedef void (*gen_atomic_op_i128)(TCGv_i128, TCGv_env, TCGv_i64,
# define WITH_ATOMIC128(X)
#endif
-static void * const table_cmpxchg[(MO_SIZE | MO_BSWAP) + 1] = {
- [MO_8] = gen_helper_atomic_cmpxchgb,
- [MO_16 | MO_LE] = gen_helper_atomic_cmpxchgw_le,
- [MO_16 | MO_BE] = gen_helper_atomic_cmpxchgw_be,
- [MO_32 | MO_LE] = gen_helper_atomic_cmpxchgl_le,
- [MO_32 | MO_BE] = gen_helper_atomic_cmpxchgl_be,
- [MO_64 | MO_LE] = gen_helper_atomic_cmpxchgq_le,
- [MO_64 | MO_BE] = gen_helper_atomic_cmpxchgq_be,
- WITH_ATOMIC128([MO_128 | MO_LE] = gen_helper_atomic_cmpxchgo_le)
- WITH_ATOMIC128([MO_128 | MO_BE] = gen_helper_atomic_cmpxchgo_be)
-};
-
-static void tcg_gen_nonatomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
- TCGv_i32 cmpv, TCGv_i32 newv,
- TCGArg idx, MemOp memop)
+static void tcg_gen_nonatomic_cmpxchg_int(TCGType type, TCGTemp *retv,
+ TCGTemp *addr, TCGTemp *cmpv,
+ TCGTemp *newv, unsigned idx,
+ MemOp memop)
{
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- TCGv_i32 t2 = tcg_temp_ebb_new_i32();
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(type);
- tcg_gen_ext_i32(t2, cmpv, memop & MO_SIZE);
+ tcg_gen_ext(type, t2, cmpv, memop & MO_SIZE);
- tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1),
- addr, idx, memop & ~MO_SIGN);
- tcg_gen_movcond_i32(TCG_COND_EQ, t2, t1, t2, newv, t1);
- tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
- tcg_temp_free_i32(t2);
+ tcg_gen_qemu_ld_int(type, t1, addr, idx, memop & ~MO_SIGN);
+ tcg_gen_movcond(type, TCG_COND_EQ, t2, t1, t2, newv, t1);
+ tcg_gen_qemu_st_int(type, t2, addr, idx, memop);
if (memop & MO_SIGN) {
- tcg_gen_ext_i32(retv, t1, memop);
+ tcg_gen_ext(type, retv, t1, memop);
} else {
- tcg_gen_mov_i32(retv, t1);
+ tcg_gen_mov(type, retv, t1);
}
- tcg_temp_free_i32(t1);
}
-void tcg_gen_nonatomic_cmpxchg_i32_chk(TCGv_i32 retv, TCGTemp *addr,
- TCGv_i32 cmpv, TCGv_i32 newv,
- TCGArg idx, MemOp memop,
- TCGType addr_type)
+void tcg_gen_nonatomic_cmpxchg_chk(TCGType val_type, TCGTemp *retv,
+ TCGTemp *addr, TCGTemp *cmpv, TCGTemp *newv,
+ unsigned idx, MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_32);
- tcg_gen_nonatomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type));
+ tcg_debug_assert(idx < NB_MMU_MODES);
+
+ tcg_gen_nonatomic_cmpxchg_int(val_type, retv, addr, cmpv, newv, idx, memop);
}
-static void tcg_gen_atomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
- TCGv_i32 cmpv, TCGv_i32 newv,
- TCGArg idx, MemOp memop)
+static void tcg_gen_atomic_cmpxchg_int(TCGType type, TCGTemp *retv,
+ TCGTemp *addr, TCGTemp *cmpv,
+ TCGTemp *newv, unsigned idx,
+ MemOp memop)
{
- gen_atomic_cx_i32 gen;
TCGv_i64 a64;
MemOpIdx oi;
if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) {
- tcg_gen_nonatomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
+ tcg_gen_nonatomic_cmpxchg_int(type, retv, addr, cmpv,
+ newv, idx, memop);
return;
}
- memop = tcg_canonicalize_memop(memop, 0, 0);
- gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
- tcg_debug_assert(gen != NULL);
-
- oi = make_memop_idx(memop & ~MO_SIGN, idx);
a64 = maybe_extend_addr64(addr);
- gen(retv, tcg_env, a64, cmpv, newv, tcg_constant_i32(oi));
- maybe_free_addr64(a64);
-
- if (memop & MO_SIGN) {
- tcg_gen_ext_i32(retv, retv, memop);
- }
-}
-
-void tcg_gen_atomic_cmpxchg_i32_chk(TCGv_i32 retv, TCGTemp *addr,
- TCGv_i32 cmpv, TCGv_i32 newv,
- TCGArg idx, MemOp memop,
- TCGType addr_type)
-{
- tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_32);
- tcg_gen_atomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
-}
-
-static void tcg_gen_nonatomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
- TCGv_i64 cmpv, TCGv_i64 newv,
- TCGArg idx, MemOp memop)
-{
- TCGv_i64 t1, t2;
-
- t1 = tcg_temp_ebb_new_i64();
- t2 = tcg_temp_ebb_new_i64();
-
- tcg_gen_ext_i64(t2, cmpv, memop & MO_SIZE);
-
- tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1),
- addr, idx, memop & ~MO_SIGN);
- tcg_gen_movcond_i64(TCG_COND_EQ, t2, t1, t2, newv, t1);
- tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
- tcg_temp_free_i64(t2);
-
- if (memop & MO_SIGN) {
- tcg_gen_ext_i64(retv, t1, memop);
- } else {
- tcg_gen_mov_i64(retv, t1);
- }
- tcg_temp_free_i64(t1);
-}
-
-void tcg_gen_nonatomic_cmpxchg_i64_chk(TCGv_i64 retv, TCGTemp *addr,
- TCGv_i64 cmpv, TCGv_i64 newv,
- TCGArg idx, MemOp memop,
- TCGType addr_type)
-{
- tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_64);
- tcg_gen_nonatomic_cmpxchg_i64_int(retv, addr, cmpv, newv, idx, memop);
-}
-
-static void tcg_gen_atomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
- TCGv_i64 cmpv, TCGv_i64 newv,
- TCGArg idx, MemOp memop)
-{
- if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) {
- tcg_gen_nonatomic_cmpxchg_i64_int(retv, addr, cmpv, newv, idx, memop);
- return;
- }
if ((memop & MO_SIZE) == MO_64) {
- gen_atomic_cx_i64 gen;
+ gen_atomic_cx_i64 gen = ((memop & MO_BSWAP) == MO_LE
+ ? gen_helper_atomic_cmpxchgq_le
+ : gen_helper_atomic_cmpxchgq_be);
+
+ tcg_debug_assert(type == TCG_TYPE_I64);
memop = tcg_canonicalize_memop(memop, 1, 0);
- gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
- if (gen) {
- MemOpIdx oi = make_memop_idx(memop, idx);
- TCGv_i64 a64 = maybe_extend_addr64(addr);
- gen(retv, tcg_env, a64, cmpv, newv, tcg_constant_i32(oi));
- maybe_free_addr64(a64);
- return;
+ oi = make_memop_idx(memop & ~MO_SIGN, idx);
+
+ gen(temp_tcgv_i64(retv), tcg_env, a64, temp_tcgv_i64(cmpv),
+ temp_tcgv_i64(newv), tcg_constant_i32(oi));
+ } else {
+ static gen_atomic_cx_i32 const table_cmpxchg[(MO_SIZE | MO_BSWAP) + 1] = {
+ [MO_8] = gen_helper_atomic_cmpxchgb,
+ [MO_16 | MO_LE] = gen_helper_atomic_cmpxchgw_le,
+ [MO_16 | MO_BE] = gen_helper_atomic_cmpxchgw_be,
+ [MO_32 | MO_LE] = gen_helper_atomic_cmpxchgl_le,
+ [MO_32 | MO_BE] = gen_helper_atomic_cmpxchgl_be,
+ };
+
+ g_autoptr(TCGTemp) c32 = NULL;
+ g_autoptr(TCGTemp) n32 = NULL;
+ g_autoptr(TCGTemp) r32 = NULL;
+ TCGTemp *retv_orig = retv;
+
+ gen_atomic_cx_i32 gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
+ tcg_debug_assert(gen != NULL);
+
+ if (type == TCG_TYPE_I64) {
+ c32 = tcg_temp_new_ebb(TCG_TYPE_I32);
+ n32 = tcg_temp_new_ebb(TCG_TYPE_I32);
+ r32 = tcg_temp_new_ebb(TCG_TYPE_I32);
+
+ tcg_gen_extrl(c32, cmpv);
+ tcg_gen_extrl(n32, newv);
+
+ cmpv = c32;
+ newv = n32;
+ retv = r32;
}
- gen_helper_exit_atomic(tcg_env);
+ memop = tcg_canonicalize_memop(memop, 0, 0);
+ oi = make_memop_idx(memop & ~MO_SIGN, idx);
- /*
- * Produce a result for a well-formed opcode stream. This satisfies
- * liveness for set before used, which happens before this dead code
- * is removed.
- */
- tcg_gen_movi_i64(retv, 0);
- } else {
- TCGv_i32 c32 = tcg_temp_ebb_new_i32();
- TCGv_i32 n32 = tcg_temp_ebb_new_i32();
- TCGv_i32 r32 = tcg_temp_ebb_new_i32();
-
- tcg_gen_extrl_i64_i32(c32, cmpv);
- tcg_gen_extrl_i64_i32(n32, newv);
- tcg_gen_atomic_cmpxchg_i32_int(r32, addr, c32, n32,
- idx, memop & ~MO_SIGN);
- tcg_temp_free_i32(c32);
- tcg_temp_free_i32(n32);
-
- tcg_gen_extu_i32_i64(retv, r32);
- tcg_temp_free_i32(r32);
+ gen(temp_tcgv_i32(retv), tcg_env, a64, temp_tcgv_i32(cmpv),
+ temp_tcgv_i32(newv), tcg_constant_i32(oi));
if (memop & MO_SIGN) {
- tcg_gen_ext_i64(retv, retv, memop);
+ tcg_gen_ext(TCG_TYPE_I32, retv, retv, memop);
+ }
+ if (retv != retv_orig) {
+ if (memop & MO_SIGN) {
+ tcg_gen_exts(retv_orig, retv);
+ } else {
+ tcg_gen_extu(retv_orig, retv);
+ }
}
}
+ maybe_free_addr64(a64);
}
-void tcg_gen_atomic_cmpxchg_i64_chk(TCGv_i64 retv, TCGTemp *addr,
- TCGv_i64 cmpv, TCGv_i64 newv,
- TCGArg idx, MemOp memop, TCGType addr_type)
+void tcg_gen_atomic_cmpxchg_chk(TCGType val_type, TCGTemp *retv, TCGTemp *addr,
+ TCGTemp *cmpv, TCGTemp *newv,
+ unsigned idx, MemOp memop, TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
- tcg_debug_assert((memop & MO_SIZE) <= MO_64);
- tcg_gen_atomic_cmpxchg_i64_int(retv, addr, cmpv, newv, idx, memop);
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type));
+ tcg_debug_assert(idx < NB_MMU_MODES);
+
+ tcg_gen_atomic_cmpxchg_int(val_type, retv, addr, cmpv, newv, idx, memop);
}
static void tcg_gen_nonatomic_cmpxchg_i128_int(TCGv_i128 retv, TCGTemp *addr,
@@ -877,7 +821,7 @@ static void tcg_gen_nonatomic_cmpxchg_i128_int(TCGv_i128 retv, TCGTemp *addr,
tcg_temp_free_i128(oldv);
}
-void tcg_gen_nonatomic_cmpxchg_i128_chk(TCGv_i128 retv, TCGTemp *addr,
+void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128 retv, TCGTemp *addr,
TCGv_i128 cmpv, TCGv_i128 newv,
TCGArg idx, MemOp memop,
TCGType addr_type)
@@ -887,18 +831,23 @@ void tcg_gen_nonatomic_cmpxchg_i128_chk(TCGv_i128 retv, TCGTemp *addr,
tcg_gen_nonatomic_cmpxchg_i128_int(retv, addr, cmpv, newv, idx, memop);
}
-static void tcg_gen_atomic_cmpxchg_i128_int(TCGv_i128 retv, TCGTemp *addr,
+static void tcg_gen_atomic_cmpxchg_int_i128(TCGv_i128 retv, TCGTemp *addr,
TCGv_i128 cmpv, TCGv_i128 newv,
TCGArg idx, MemOp memop)
{
- gen_atomic_cx_i128 gen;
+ gen_atomic_cx_i128 gen = NULL;
if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) {
tcg_gen_nonatomic_cmpxchg_i128_int(retv, addr, cmpv, newv, idx, memop);
return;
}
- gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
+#if HAVE_CMPXCHG128
+ gen = ((memop & MO_BSWAP) == MO_LE
+ ? gen_helper_atomic_cmpxchgo_le
+ : gen_helper_atomic_cmpxchgo_be);
+#endif
+
if (gen) {
MemOpIdx oi = make_memop_idx(memop, idx);
TCGv_i64 a64 = maybe_extend_addr64(addr);
@@ -918,14 +867,14 @@ static void tcg_gen_atomic_cmpxchg_i128_int(TCGv_i128 retv, TCGTemp *addr,
tcg_gen_movi_i64(TCGV128_HIGH(retv), 0);
}
-void tcg_gen_atomic_cmpxchg_i128_chk(TCGv_i128 retv, TCGTemp *addr,
+void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128 retv, TCGTemp *addr,
TCGv_i128 cmpv, TCGv_i128 newv,
TCGArg idx, MemOp memop,
TCGType addr_type)
{
tcg_debug_assert(addr_type == tcg_ctx->addr_type);
tcg_debug_assert((memop & (MO_SIZE | MO_SIGN)) == MO_128);
- tcg_gen_atomic_cmpxchg_i128_int(retv, addr, cmpv, newv, idx, memop);
+ tcg_gen_atomic_cmpxchg_int_i128(retv, addr, cmpv, newv, idx, memop);
}
static void do_nonatomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index c68e9e10501..c8c79356d55 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -231,6 +231,13 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
{ tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), glue(C_,T3)(c), \
glue(C_,T4)(d), glue(C_,T5)(e), glue(C_,T6)(f)); }
+#define DEF7(NAME, T1, T2, T3, T4, T5, T6, T7) \
+ void glue(glue(tcg_gen_,NAME),TExt)(T1 a, T2 b, T3 c, T4 d, T5 e, \
+ T6 f, T7 g) \
+ { tcg_gen_##NAME(TYPE, glue(C_,T1)(a), glue(C_,T2)(b), \
+ glue(C_,T3)(c), glue(C_,T4)(d), glue(C_,T5)(e), \
+ glue(C_,T6)(f), glue(C_,T7)(g)); }
+
#define C_TCGv_i32 tcgv_i32_temp
#define C_TCGv_i64 tcgv_i64_temp
#define C_TCGv_ptr tcgv_ptr_temp
@@ -285,6 +292,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo)
#undef DEF4
#undef DEF5
#undef DEF6
+#undef DEF7
/*
* Internal helper for bit and byte reversal.
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 099/101] tcg: Generic expansion of tcg_gen_{non}atomic_qemu_cmpxchg_chk
2026-09-27 9:00 ` [PATCH v5 099/101] tcg: Generic expansion of tcg_gen_{non}atomic_qemu_cmpxchg_chk Richard Henderson
@ 2026-09-30 0:19 ` Matt Turner
0 siblings, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-30 0:19 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:08 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 16 +--
> include/tcg/tcg-op-mem.h | 2 +-
> tcg/tcg-internal.h | 3 +
> include/tcg/tcg-op-def.h.inc | 3 +
> tcg/tcg-op-ldst.c | 237 ++++++++++++++---------------------
> tcg/tcg-op.c | 8 ++
> 6 files changed, 113 insertions(+), 156 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 4fec1500d56..9864674f1c2 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -104,6 +104,8 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5);
> #define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
> QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6);
> +#define DEF7(NAME, T1, T2, T3, T4, T5, T6, T7) \
> + QEMU_ARG_NONNULL void glue(glue(tcg_gen_,NAME),TExt)(T1, T2, T3, T4, T5, T6, T7);
>
> #define TCGV glue(TCGv,TExt)
> #define TExt _i32
> @@ -129,6 +131,7 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
> #undef DEF4
> #undef DEF5
> #undef DEF6
> +#undef DEF7
>
> /* 32 bit ops */
>
> @@ -180,18 +183,9 @@ void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
>
> /* Atomic ops */
>
> -void tcg_gen_atomic_cmpxchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_cmpxchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_cmpxchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
> +void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
> -
> -void tcg_gen_nonatomic_cmpxchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_nonatomic_cmpxchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_nonatomic_cmpxchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
> +void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
>
> void tcg_gen_atomic_xchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
> index e8425e10598..935860f1442 100644
> --- a/include/tcg/tcg-op-mem.h
> +++ b/include/tcg/tcg-op-mem.h
> @@ -72,7 +72,7 @@ tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
> #define DEF_ATOMIC3(N, S) \
> QEMU_ARG_NONNULL static inline void \
> N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S o, TCGv_##S n, TCGArg i, MemOp m) \
> - { N##_##S##_chk(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
> + { N##_chk_##S(r, tcgv_va_temp(a), o, n, i, m, TCG_TYPE_VA); }
>
> DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i32)
> DEF_ATOMIC3(tcg_gen_atomic_cmpxchg, i64)
> diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h
> index bfd34905ee7..da1b9c9bab3 100644
> --- a/tcg/tcg-internal.h
> +++ b/tcg/tcg-internal.h
> @@ -190,6 +190,8 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
> QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5);
> #define DEF6(NAME, T1, T2, T3, T4, T5, T6) \
> QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6);
> +#define DEF7(NAME, T1, T2, T3, T4, T5, T6, T7) \
> + QEMU_ARG_NONNULL void glue(tcg_gen_,NAME)(TCGType, T1, T2, T3, T4, T5, T6, T7);
>
> #define TCGV TCGTemp *
> #define TINT int64_t
> @@ -207,6 +209,7 @@ bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
> #undef DEF4
> #undef DEF5
> #undef DEF6
> +#undef DEF7
>
> static inline void tcg_gen_extrh(TCGTemp *dst, TCGTemp *src)
> {
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index 552f62b7f4f..e0ffd0da678 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -85,3 +85,6 @@ DEF3(umin, TCGV, TCGV, TCGV)
> DEF3(ussub, TCGV, TCGV, TCGV)
> DEF3(xor, TCGV, TCGV, TCGV)
> DEF3(xori, TCGV, TCGV, TINT)
> +
> +DEF7(atomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
> +DEF7(nonatomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
> diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
> index 7345bdfcc2b..b3143f6311b 100644
> --- a/tcg/tcg-op-ldst.c
> +++ b/tcg/tcg-op-ldst.c
> @@ -667,181 +667,125 @@ typedef void (*gen_atomic_op_i128)(TCGv_i128, TCGv_env, TCGv_i64,
> # define WITH_ATOMIC128(X)
> #endif
>
> -static void * const table_cmpxchg[(MO_SIZE | MO_BSWAP) + 1] = {
> - [MO_8] = gen_helper_atomic_cmpxchgb,
> - [MO_16 | MO_LE] = gen_helper_atomic_cmpxchgw_le,
> - [MO_16 | MO_BE] = gen_helper_atomic_cmpxchgw_be,
> - [MO_32 | MO_LE] = gen_helper_atomic_cmpxchgl_le,
> - [MO_32 | MO_BE] = gen_helper_atomic_cmpxchgl_be,
> - [MO_64 | MO_LE] = gen_helper_atomic_cmpxchgq_le,
> - [MO_64 | MO_BE] = gen_helper_atomic_cmpxchgq_be,
> - WITH_ATOMIC128([MO_128 | MO_LE] = gen_helper_atomic_cmpxchgo_le)
> - WITH_ATOMIC128([MO_128 | MO_BE] = gen_helper_atomic_cmpxchgo_be)
> -};
> -
> -static void tcg_gen_nonatomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
> - TCGv_i32 cmpv, TCGv_i32 newv,
> - TCGArg idx, MemOp memop)
> +static void tcg_gen_nonatomic_cmpxchg_int(TCGType type, TCGTemp *retv,
> + TCGTemp *addr, TCGTemp *cmpv,
> + TCGTemp *newv, unsigned idx,
> + MemOp memop)
> {
> - TCGv_i32 t1 = tcg_temp_ebb_new_i32();
> - TCGv_i32 t2 = tcg_temp_ebb_new_i32();
> + g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
> + g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(type);
>
> - tcg_gen_ext_i32(t2, cmpv, memop & MO_SIZE);
> + tcg_gen_ext(type, t2, cmpv, memop & MO_SIZE);
>
> - tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1),
> - addr, idx, memop & ~MO_SIGN);
> - tcg_gen_movcond_i32(TCG_COND_EQ, t2, t1, t2, newv, t1);
> - tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
> - tcg_temp_free_i32(t2);
> + tcg_gen_qemu_ld_int(type, t1, addr, idx, memop & ~MO_SIGN);
> + tcg_gen_movcond(type, TCG_COND_EQ, t2, t1, t2, newv, t1);
> + tcg_gen_qemu_st_int(type, t2, addr, idx, memop);
>
> if (memop & MO_SIGN) {
> - tcg_gen_ext_i32(retv, t1, memop);
> + tcg_gen_ext(type, retv, t1, memop);
> } else {
> - tcg_gen_mov_i32(retv, t1);
> + tcg_gen_mov(type, retv, t1);
> }
> - tcg_temp_free_i32(t1);
> }
>
> -void tcg_gen_nonatomic_cmpxchg_i32_chk(TCGv_i32 retv, TCGTemp *addr,
> - TCGv_i32 cmpv, TCGv_i32 newv,
> - TCGArg idx, MemOp memop,
> - TCGType addr_type)
> +void tcg_gen_nonatomic_cmpxchg_chk(TCGType val_type, TCGTemp *retv,
> + TCGTemp *addr, TCGTemp *cmpv, TCGTemp *newv,
> + unsigned idx, MemOp memop, TCGType addr_type)
> {
> tcg_debug_assert(addr_type == tcg_ctx->addr_type);
> - tcg_debug_assert((memop & MO_SIZE) <= MO_32);
> - tcg_gen_nonatomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
> + tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type));
> + tcg_debug_assert(idx < NB_MMU_MODES);
> +
> + tcg_gen_nonatomic_cmpxchg_int(val_type, retv, addr, cmpv, newv, idx, memop);
> }
>
> -static void tcg_gen_atomic_cmpxchg_i32_int(TCGv_i32 retv, TCGTemp *addr,
> - TCGv_i32 cmpv, TCGv_i32 newv,
> - TCGArg idx, MemOp memop)
> +static void tcg_gen_atomic_cmpxchg_int(TCGType type, TCGTemp *retv,
> + TCGTemp *addr, TCGTemp *cmpv,
> + TCGTemp *newv, unsigned idx,
> + MemOp memop)
> {
> - gen_atomic_cx_i32 gen;
> TCGv_i64 a64;
> MemOpIdx oi;
>
> if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) {
> - tcg_gen_nonatomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
> + tcg_gen_nonatomic_cmpxchg_int(type, retv, addr, cmpv,
> + newv, idx, memop);
> return;
> }
>
> - memop = tcg_canonicalize_memop(memop, 0, 0);
> - gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
> - tcg_debug_assert(gen != NULL);
> -
> - oi = make_memop_idx(memop & ~MO_SIGN, idx);
> a64 = maybe_extend_addr64(addr);
> - gen(retv, tcg_env, a64, cmpv, newv, tcg_constant_i32(oi));
> - maybe_free_addr64(a64);
> -
> - if (memop & MO_SIGN) {
> - tcg_gen_ext_i32(retv, retv, memop);
> - }
> -}
> -
> -void tcg_gen_atomic_cmpxchg_i32_chk(TCGv_i32 retv, TCGTemp *addr,
> - TCGv_i32 cmpv, TCGv_i32 newv,
> - TCGArg idx, MemOp memop,
> - TCGType addr_type)
> -{
> - tcg_debug_assert(addr_type == tcg_ctx->addr_type);
> - tcg_debug_assert((memop & MO_SIZE) <= MO_32);
> - tcg_gen_atomic_cmpxchg_i32_int(retv, addr, cmpv, newv, idx, memop);
> -}
> -
> -static void tcg_gen_nonatomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
> - TCGv_i64 cmpv, TCGv_i64 newv,
> - TCGArg idx, MemOp memop)
> -{
> - TCGv_i64 t1, t2;
> -
> - t1 = tcg_temp_ebb_new_i64();
> - t2 = tcg_temp_ebb_new_i64();
> -
> - tcg_gen_ext_i64(t2, cmpv, memop & MO_SIZE);
> -
> - tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1),
> - addr, idx, memop & ~MO_SIGN);
> - tcg_gen_movcond_i64(TCG_COND_EQ, t2, t1, t2, newv, t1);
> - tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
> - tcg_temp_free_i64(t2);
> -
> - if (memop & MO_SIGN) {
> - tcg_gen_ext_i64(retv, t1, memop);
> - } else {
> - tcg_gen_mov_i64(retv, t1);
> - }
> - tcg_temp_free_i64(t1);
> -}
> -
> -void tcg_gen_nonatomic_cmpxchg_i64_chk(TCGv_i64 retv, TCGTemp *addr,
> - TCGv_i64 cmpv, TCGv_i64 newv,
> - TCGArg idx, MemOp memop,
> - TCGType addr_type)
> -{
> - tcg_debug_assert(addr_type == tcg_ctx->addr_type);
> - tcg_debug_assert((memop & MO_SIZE) <= MO_64);
> - tcg_gen_nonatomic_cmpxchg_i64_int(retv, addr, cmpv, newv, idx, memop);
> -}
> -
> -static void tcg_gen_atomic_cmpxchg_i64_int(TCGv_i64 retv, TCGTemp *addr,
> - TCGv_i64 cmpv, TCGv_i64 newv,
> - TCGArg idx, MemOp memop)
> -{
> - if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) {
> - tcg_gen_nonatomic_cmpxchg_i64_int(retv, addr, cmpv, newv, idx, memop);
> - return;
> - }
>
> if ((memop & MO_SIZE) == MO_64) {
> - gen_atomic_cx_i64 gen;
> + gen_atomic_cx_i64 gen = ((memop & MO_BSWAP) == MO_LE
> + ? gen_helper_atomic_cmpxchgq_le
> + : gen_helper_atomic_cmpxchgq_be);
> +
> + tcg_debug_assert(type == TCG_TYPE_I64);
>
> memop = tcg_canonicalize_memop(memop, 1, 0);
> - gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
> - if (gen) {
> - MemOpIdx oi = make_memop_idx(memop, idx);
> - TCGv_i64 a64 = maybe_extend_addr64(addr);
> - gen(retv, tcg_env, a64, cmpv, newv, tcg_constant_i32(oi));
> - maybe_free_addr64(a64);
> - return;
> + oi = make_memop_idx(memop & ~MO_SIGN, idx);
> +
> + gen(temp_tcgv_i64(retv), tcg_env, a64, temp_tcgv_i64(cmpv),
> + temp_tcgv_i64(newv), tcg_constant_i32(oi));
> + } else {
> + static gen_atomic_cx_i32 const table_cmpxchg[(MO_SIZE | MO_BSWAP) + 1] = {
> + [MO_8] = gen_helper_atomic_cmpxchgb,
> + [MO_16 | MO_LE] = gen_helper_atomic_cmpxchgw_le,
> + [MO_16 | MO_BE] = gen_helper_atomic_cmpxchgw_be,
> + [MO_32 | MO_LE] = gen_helper_atomic_cmpxchgl_le,
> + [MO_32 | MO_BE] = gen_helper_atomic_cmpxchgl_be,
> + };
> +
> + g_autoptr(TCGTemp) c32 = NULL;
> + g_autoptr(TCGTemp) n32 = NULL;
> + g_autoptr(TCGTemp) r32 = NULL;
> + TCGTemp *retv_orig = retv;
> +
> + gen_atomic_cx_i32 gen = table_cmpxchg[memop & (MO_SIZE | MO_BSWAP)];
This now happens before tcg_canonicalize_memop(), so I think that can
lead to indexing into an empty entry.
> + tcg_debug_assert(gen != NULL);
> +
> + if (type == TCG_TYPE_I64) {
> + c32 = tcg_temp_new_ebb(TCG_TYPE_I32);
> + n32 = tcg_temp_new_ebb(TCG_TYPE_I32);
> + r32 = tcg_temp_new_ebb(TCG_TYPE_I32);
> +
> + tcg_gen_extrl(c32, cmpv);
> + tcg_gen_extrl(n32, newv);
> +
> + cmpv = c32;
> + newv = n32;
> + retv = r32;
> }
>
> - gen_helper_exit_atomic(tcg_env);
> + memop = tcg_canonicalize_memop(memop, 0, 0);
> + oi = make_memop_idx(memop & ~MO_SIGN, idx);
>
> - /*
> - * Produce a result for a well-formed opcode stream. This satisfies
> - * liveness for set before used, which happens before this dead code
> - * is removed.
> - */
> - tcg_gen_movi_i64(retv, 0);
> - } else {
> - TCGv_i32 c32 = tcg_temp_ebb_new_i32();
> - TCGv_i32 n32 = tcg_temp_ebb_new_i32();
> - TCGv_i32 r32 = tcg_temp_ebb_new_i32();
> -
> - tcg_gen_extrl_i64_i32(c32, cmpv);
> - tcg_gen_extrl_i64_i32(n32, newv);
> - tcg_gen_atomic_cmpxchg_i32_int(r32, addr, c32, n32,
> - idx, memop & ~MO_SIGN);
> - tcg_temp_free_i32(c32);
> - tcg_temp_free_i32(n32);
> -
> - tcg_gen_extu_i32_i64(retv, r32);
> - tcg_temp_free_i32(r32);
> + gen(temp_tcgv_i32(retv), tcg_env, a64, temp_tcgv_i32(cmpv),
> + temp_tcgv_i32(newv), tcg_constant_i32(oi));
>
> if (memop & MO_SIGN) {
> - tcg_gen_ext_i64(retv, retv, memop);
> + tcg_gen_ext(TCG_TYPE_I32, retv, retv, memop);
> + }
> + if (retv != retv_orig) {
> + if (memop & MO_SIGN) {
> + tcg_gen_exts(retv_orig, retv);
For MO_32, tcg_canonicalize_memop(memop, is64=false, ...) clears
MO_SIGN, so the i64 result is always zero-extended. Looks like the old
code tested the caller's memop. Maybe I'm misreading.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 100/101] tcg: Generic expansion of remaining atomic operations
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (98 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 099/101] tcg: Generic expansion of tcg_gen_{non}atomic_qemu_cmpxchg_chk Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-30 0:22 ` Matt Turner
2026-09-27 9:00 ` [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL Richard Henderson
100 siblings, 1 reply; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
These are done in bulk because of existing macro magic.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 80 +-------------
include/tcg/tcg-op-mem.h | 2 +-
include/tcg/tcg-op-def.h.inc | 20 ++++
tcg/tcg-op-ldst.c | 206 +++++++++++++----------------------
4 files changed, 102 insertions(+), 206 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 9864674f1c2..bc96c02aaea 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -181,89 +181,15 @@ void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
-/* Atomic ops */
-
void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
-
-void tcg_gen_atomic_xchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_xchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_xchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
+void tcg_gen_atomic_xchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
-
-void tcg_gen_atomic_fetch_add_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_add_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_and_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_and_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_or_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_or_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_xor_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_xor_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_smin_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
+void tcg_gen_atomic_fetch_and_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_smin_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_umin_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_umin_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_smax_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_smax_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_umax_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_umax_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-
-void tcg_gen_atomic_add_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_add_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_and_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_and_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_or_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_or_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_xor_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_xor_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_smin_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_smin_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_umin_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_umin_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_smax_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_smax_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_umax_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_umax_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
- TCGArg, MemOp, TCGType);
-
-void tcg_gen_atomic_fetch_and_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
- TCGArg, MemOp, TCGType);
-void tcg_gen_atomic_fetch_or_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
+void tcg_gen_atomic_fetch_or_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
/* Vector ops */
diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
index 935860f1442..6533704082e 100644
--- a/include/tcg/tcg-op-mem.h
+++ b/include/tcg/tcg-op-mem.h
@@ -67,7 +67,7 @@ tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
#define DEF_ATOMIC2(N, S) \
QEMU_ARG_NONNULL static inline void \
N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S v, TCGArg i, MemOp m) \
- { N##_##S##_chk(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
+ { N##_chk_##S(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
#define DEF_ATOMIC3(N, S) \
QEMU_ARG_NONNULL static inline void \
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index e0ffd0da678..e694f0e38c4 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -88,3 +88,23 @@ DEF3(xori, TCGV, TCGV, TINT)
DEF7(atomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
DEF7(nonatomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
+
+DEF6(atomic_xchg_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+
+DEF6(atomic_fetch_add_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_and_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_or_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_smax_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_smin_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_umax_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_umin_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_fetch_xor_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+
+DEF6(atomic_add_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_and_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_or_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_smax_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_smin_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_umax_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_umin_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
+DEF6(atomic_xor_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
index b3143f6311b..77679634cbf 100644
--- a/tcg/tcg-op-ldst.c
+++ b/tcg/tcg-op-ldst.c
@@ -877,113 +877,92 @@ void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128 retv, TCGTemp *addr,
tcg_gen_atomic_cmpxchg_int_i128(retv, addr, cmpv, newv, idx, memop);
}
-static void do_nonatomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
- TCGArg idx, MemOp memop, bool new_val,
- void (*gen)(TCGv_i32, TCGv_i32, TCGv_i32))
+static void do_nonatomic_op(TCGType type, TCGTemp *ret, TCGTemp *addr,
+ TCGTemp *val, unsigned idx, MemOp memop,
+ bool new_val,
+ void (*gen)(TCGType, TCGTemp *,
+ TCGTemp *, TCGTemp *))
{
- TCGv_i32 t1 = tcg_temp_ebb_new_i32();
- TCGv_i32 t2 = tcg_temp_ebb_new_i32();
+ g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
+ g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(type);
- memop = tcg_canonicalize_memop(memop, 0, 0);
+ memop = tcg_canonicalize_memop(memop, type != TCG_TYPE_I32, 0);
- tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1), addr, idx, memop);
- tcg_gen_ext_i32(t2, val, memop);
- gen(t2, t1, t2);
- tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
+ tcg_gen_qemu_ld_int(type, t1, addr, idx, memop);
+ tcg_gen_ext(type, t2, val, memop);
+ gen(type, t2, t1, t2);
+ tcg_gen_qemu_st_int(type, t2, addr, idx, memop);
- tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop);
- tcg_temp_free_i32(t1);
- tcg_temp_free_i32(t2);
+ tcg_gen_ext(type, ret, (new_val ? t2 : t1), memop);
}
-static void do_atomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
- TCGArg idx, MemOp memop, void * const table[])
+static void do_atomic_op(TCGType type, TCGTemp *ret, TCGTemp *addr,
+ TCGTemp *val, unsigned idx, MemOp memop,
+ void * const table[])
{
- gen_atomic_op_i32 gen;
- TCGv_i64 a64;
+ TCGv_i64 a64 = maybe_extend_addr64(addr);
MemOpIdx oi;
- memop = tcg_canonicalize_memop(memop, 0, 0);
-
- gen = table[memop & (MO_SIZE | MO_BSWAP)];
- tcg_debug_assert(gen != NULL);
-
- oi = make_memop_idx(memop & ~MO_SIGN, idx);
- a64 = maybe_extend_addr64(addr);
- gen(ret, tcg_env, a64, val, tcg_constant_i32(oi));
- maybe_free_addr64(a64);
-
- if (memop & MO_SIGN) {
- tcg_gen_ext_i32(ret, ret, memop);
- }
-}
-
-static void do_nonatomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
- TCGArg idx, MemOp memop, bool new_val,
- void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64))
-{
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- TCGv_i64 t2 = tcg_temp_ebb_new_i64();
-
- memop = tcg_canonicalize_memop(memop, 1, 0);
-
- tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1), addr, idx, memop);
- tcg_gen_ext_i64(t2, val, memop);
- gen(t2, t1, t2);
- tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
-
- tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
-}
-
-static void do_atomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
- TCGArg idx, MemOp memop, void * const table[])
-{
- memop = tcg_canonicalize_memop(memop, 1, 0);
-
if ((memop & MO_SIZE) == MO_64) {
gen_atomic_op_i64 gen = table[memop & (MO_SIZE | MO_BSWAP)];
+ tcg_debug_assert(gen != NULL);
+ tcg_debug_assert(type == TCG_TYPE_I64);
- if (gen) {
- MemOpIdx oi = make_memop_idx(memop & ~MO_SIGN, idx);
- TCGv_i64 a64 = maybe_extend_addr64(addr);
- gen(ret, tcg_env, a64, val, tcg_constant_i32(oi));
- maybe_free_addr64(a64);
- return;
+ memop = tcg_canonicalize_memop(memop, 1, 0);
+ oi = make_memop_idx(memop & ~MO_SIGN, idx);
+
+ gen(temp_tcgv_i64(ret), tcg_env, a64,
+ temp_tcgv_i64(val), tcg_constant_i32(oi));
+ } else {
+ g_autoptr(TCGTemp) v32 = NULL;
+ g_autoptr(TCGTemp) r32 = NULL;
+ TCGTemp *ret_orig = ret;
+
+ gen_atomic_op_i32 gen = table[memop & (MO_SIZE | MO_BSWAP)];
+ tcg_debug_assert(gen != NULL);
+
+ if (type == TCG_TYPE_I64) {
+ v32 = tcg_temp_new_ebb(TCG_TYPE_I32);
+ r32 = tcg_temp_new_ebb(TCG_TYPE_I32);
+
+ tcg_gen_extrl(v32, val);
+ val = v32;
+ ret = r32;
}
- gen_helper_exit_atomic(tcg_env);
- /* Produce a result, so that we have a well-formed opcode stream
- with respect to uses of the result in the (dead) code following. */
- tcg_gen_movi_i64(ret, 0);
- } else {
- TCGv_i32 v32 = tcg_temp_ebb_new_i32();
- TCGv_i32 r32 = tcg_temp_ebb_new_i32();
+ memop = tcg_canonicalize_memop(memop, 0, 0);
+ oi = make_memop_idx(memop & ~MO_SIGN, idx);
- tcg_gen_extrl_i64_i32(v32, val);
- do_atomic_op_i32(r32, addr, v32, idx, memop & ~MO_SIGN, table);
- tcg_temp_free_i32(v32);
-
- tcg_gen_extu_i32_i64(ret, r32);
- tcg_temp_free_i32(r32);
+ gen(temp_tcgv_i32(ret), tcg_env, a64,
+ temp_tcgv_i32(val), tcg_constant_i32(oi));
if (memop & MO_SIGN) {
- tcg_gen_ext_i64(ret, ret, memop);
+ tcg_gen_ext(TCG_TYPE_I32, ret, ret, memop);
+ }
+ if (ret != ret_orig) {
+ if (memop & MO_SIGN) {
+ tcg_gen_exts(ret_orig, ret);
+ } else {
+ tcg_gen_extu(ret_orig, ret);
+ }
}
}
+ maybe_free_addr64(a64);
}
static void do_nonatomic_op_i128(TCGv_i128 ret, TCGTemp *addr, TCGv_i128 val,
TCGArg idx, MemOp memop, bool new_val,
- void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64))
+ void (*gen)(TCGType, TCGTemp *,
+ TCGTemp *, TCGTemp *))
{
TCGv_i128 t = tcg_temp_ebb_new_i128();
TCGv_i128 r = tcg_temp_ebb_new_i128();
tcg_gen_qemu_ld_i128_int(r, addr, idx, memop);
- gen(TCGV128_LOW(t), TCGV128_LOW(r), TCGV128_LOW(val));
- gen(TCGV128_HIGH(t), TCGV128_HIGH(r), TCGV128_HIGH(val));
+ gen(TCG_TYPE_I64, tcgv_i64_temp(TCGV128_LOW(t)),
+ tcgv_i64_temp(TCGV128_LOW(r)), tcgv_i64_temp(TCGV128_LOW(val)));
+ gen(TCG_TYPE_I64, tcgv_i64_temp(TCGV128_HIGH(t)),
+ tcgv_i64_temp(TCGV128_HIGH(r)), tcgv_i64_temp(TCGV128_HIGH(val)));
tcg_gen_qemu_st_i128_int(t, addr, idx, memop);
tcg_gen_mov_i128(ret, r);
@@ -1022,33 +1001,21 @@ static void * const table_##NAME[(MO_SIZE | MO_BSWAP) + 1] = { \
WITH_ATOMIC128([MO_128 | MO_LE] = gen_helper_atomic_##NAME##o_le) \
WITH_ATOMIC128([MO_128 | MO_BE] = gen_helper_atomic_##NAME##o_be) \
}; \
-void tcg_gen_atomic_##NAME##_i32_chk(TCGv_i32 ret, TCGTemp *addr, \
- TCGv_i32 val, TCGArg idx, \
- MemOp memop, TCGType addr_type) \
+void tcg_gen_atomic_##NAME##_chk(TCGType val_type, TCGTemp *ret, \
+ TCGTemp *addr, TCGTemp *val, unsigned idx, \
+ MemOp memop, TCGType addr_type) \
{ \
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
- tcg_debug_assert((memop & MO_SIZE) <= MO_32); \
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type)); \
+ tcg_debug_assert(idx < NB_MMU_MODES); \
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
- do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \
+ do_atomic_op(val_type, ret, addr, val, idx, memop, table_##NAME); \
} else { \
- do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
- tcg_gen_##OP##_i32); \
+ do_nonatomic_op(val_type, ret, addr, val, idx, memop, NEW, \
+ tcg_gen_##OP); \
} \
} \
-void tcg_gen_atomic_##NAME##_i64_chk(TCGv_i64 ret, TCGTemp *addr, \
- TCGv_i64 val, TCGArg idx, \
- MemOp memop, TCGType addr_type) \
-{ \
- tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
- tcg_debug_assert((memop & MO_SIZE) <= MO_64); \
- if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
- do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \
- } else { \
- do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
- tcg_gen_##OP##_i64); \
- } \
-} \
-void tcg_gen_atomic_##NAME##_i128_chk(TCGv_i128 ret, TCGTemp *addr, \
+void tcg_gen_atomic_##NAME##_chk_i128(TCGv_i128 ret, TCGTemp *addr, \
TCGv_i128 val, TCGArg idx, \
MemOp memop, TCGType addr_type) \
{ \
@@ -1058,7 +1025,7 @@ void tcg_gen_atomic_##NAME##_i128_chk(TCGv_i128 ret, TCGTemp *addr, \
do_atomic_op_i128(ret, addr, val, idx, memop, table_##NAME); \
} else { \
do_nonatomic_op_i128(ret, addr, val, idx, memop, NEW, \
- tcg_gen_##OP##_i64); \
+ tcg_gen_##OP); \
} \
}
@@ -1072,30 +1039,18 @@ static void * const table_##NAME[(MO_SIZE | MO_BSWAP) + 1] = { \
[MO_64 | MO_LE] = gen_helper_atomic_##NAME##q_le, \
[MO_64 | MO_BE] = gen_helper_atomic_##NAME##q_be, \
}; \
-void tcg_gen_atomic_##NAME##_i32_chk(TCGv_i32 ret, TCGTemp *addr, \
- TCGv_i32 val, TCGArg idx, \
- MemOp memop, TCGType addr_type) \
+void tcg_gen_atomic_##NAME##_chk(TCGType val_type, TCGTemp *ret, \
+ TCGTemp *addr, TCGTemp *val, unsigned idx, \
+ MemOp memop, TCGType addr_type) \
{ \
tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
- tcg_debug_assert((memop & MO_SIZE) <= MO_32); \
+ tcg_debug_assert(memop_size(memop) <= tcg_type_size(val_type)); \
+ tcg_debug_assert(idx < NB_MMU_MODES); \
if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
- do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \
+ do_atomic_op(val_type, ret, addr, val, idx, memop, table_##NAME); \
} else { \
- do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \
- tcg_gen_##OP##_i32); \
- } \
-} \
-void tcg_gen_atomic_##NAME##_i64_chk(TCGv_i64 ret, TCGTemp *addr, \
- TCGv_i64 val, TCGArg idx, \
- MemOp memop, TCGType addr_type) \
-{ \
- tcg_debug_assert(addr_type == tcg_ctx->addr_type); \
- tcg_debug_assert((memop & MO_SIZE) <= MO_64); \
- if (tcg_ctx->gen_tb->cflags & CF_PARALLEL) { \
- do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \
- } else { \
- do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \
- tcg_gen_##OP##_i64); \
+ do_nonatomic_op(val_type, ret, addr, val, idx, memop, NEW, \
+ tcg_gen_##OP); \
} \
}
@@ -1117,14 +1072,9 @@ GEN_ATOMIC_HELPER(umin_fetch, umin, 1)
GEN_ATOMIC_HELPER(smax_fetch, smax, 1)
GEN_ATOMIC_HELPER(umax_fetch, umax, 1)
-static void tcg_gen_mov2_i32(TCGv_i32 r, TCGv_i32 a, TCGv_i32 b)
+static void tcg_gen_mov2(TCGType type, TCGTemp *r, TCGTemp *a, TCGTemp *b)
{
- tcg_gen_mov_i32(r, b);
-}
-
-static void tcg_gen_mov2_i64(TCGv_i64 r, TCGv_i64 a, TCGv_i64 b)
-{
- tcg_gen_mov_i64(r, b);
+ tcg_gen_mov(type, r, b);
}
GEN_ATOMIC_HELPER128(xchg, mov2, 0)
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 100/101] tcg: Generic expansion of remaining atomic operations
2026-09-27 9:00 ` [PATCH v5 100/101] tcg: Generic expansion of remaining atomic operations Richard Henderson
@ 2026-09-30 0:22 ` Matt Turner
0 siblings, 0 replies; 197+ messages in thread
From: Matt Turner @ 2026-09-30 0:22 UTC (permalink / raw)
To: Richard Henderson; +Cc: qemu-devel
On Sun, Sep 27, 2026 at 5:08 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> These are done in bulk because of existing macro magic.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 80 +-------------
> include/tcg/tcg-op-mem.h | 2 +-
> include/tcg/tcg-op-def.h.inc | 20 ++++
> tcg/tcg-op-ldst.c | 206 +++++++++++++----------------------
> 4 files changed, 102 insertions(+), 206 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index 9864674f1c2..bc96c02aaea 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -181,89 +181,15 @@ void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
> void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
> void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
>
> -/* Atomic ops */
> -
> void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
> void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
> -
> -void tcg_gen_atomic_xchg_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_xchg_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_xchg_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
> +void tcg_gen_atomic_xchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGArg, MemOp, TCGType);
> -
> -void tcg_gen_atomic_fetch_add_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_add_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_and_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_and_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_or_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_or_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_xor_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_xor_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_smin_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> +void tcg_gen_atomic_fetch_and_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_smin_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_umin_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_umin_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_smax_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_smax_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_umax_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_umax_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -
> -void tcg_gen_atomic_add_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_add_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_and_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_and_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_or_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_or_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_xor_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_xor_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_smin_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_smin_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_umin_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_umin_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_smax_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_smax_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_umax_fetch_i32_chk(TCGv_i32, TCGTemp *, TCGv_i32,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_umax_fetch_i64_chk(TCGv_i64, TCGTemp *, TCGv_i64,
> - TCGArg, MemOp, TCGType);
> -
> -void tcg_gen_atomic_fetch_and_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
> - TCGArg, MemOp, TCGType);
> -void tcg_gen_atomic_fetch_or_i128_chk(TCGv_i128, TCGTemp *, TCGv_i128,
> +void tcg_gen_atomic_fetch_or_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGArg, MemOp, TCGType);
>
> /* Vector ops */
> diff --git a/include/tcg/tcg-op-mem.h b/include/tcg/tcg-op-mem.h
> index 935860f1442..6533704082e 100644
> --- a/include/tcg/tcg-op-mem.h
> +++ b/include/tcg/tcg-op-mem.h
> @@ -67,7 +67,7 @@ tcg_gen_qemu_st_i128(TCGv_i128 v, TCGv_va a, TCGArg i, MemOp m)
> #define DEF_ATOMIC2(N, S) \
> QEMU_ARG_NONNULL static inline void \
> N##_##S(TCGv_##S r, TCGv_va a, TCGv_##S v, TCGArg i, MemOp m) \
> - { N##_##S##_chk(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
> + { N##_chk_##S(r, tcgv_va_temp(a), v, i, m, TCG_TYPE_VA); }
>
> #define DEF_ATOMIC3(N, S) \
> QEMU_ARG_NONNULL static inline void \
> diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
> index e0ffd0da678..e694f0e38c4 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -88,3 +88,23 @@ DEF3(xori, TCGV, TCGV, TINT)
>
> DEF7(atomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
> DEF7(nonatomic_cmpxchg_chk, TCGV, TCGTempPtr, TCGV, TCGV, unsigned, MemOp, TCGType)
> +
> +DEF6(atomic_xchg_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +
> +DEF6(atomic_fetch_add_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_and_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_or_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_smax_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_smin_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_umax_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_umin_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_fetch_xor_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +
> +DEF6(atomic_add_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_and_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_or_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_smax_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_smin_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_umax_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_umin_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> +DEF6(atomic_xor_fetch_chk, TCGV, TCGTempPtr, TCGV, unsigned, MemOp, TCGType)
> diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c
> index b3143f6311b..77679634cbf 100644
> --- a/tcg/tcg-op-ldst.c
> +++ b/tcg/tcg-op-ldst.c
> @@ -877,113 +877,92 @@ void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128 retv, TCGTemp *addr,
> tcg_gen_atomic_cmpxchg_int_i128(retv, addr, cmpv, newv, idx, memop);
> }
>
> -static void do_nonatomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
> - TCGArg idx, MemOp memop, bool new_val,
> - void (*gen)(TCGv_i32, TCGv_i32, TCGv_i32))
> +static void do_nonatomic_op(TCGType type, TCGTemp *ret, TCGTemp *addr,
> + TCGTemp *val, unsigned idx, MemOp memop,
> + bool new_val,
> + void (*gen)(TCGType, TCGTemp *,
> + TCGTemp *, TCGTemp *))
> {
> - TCGv_i32 t1 = tcg_temp_ebb_new_i32();
> - TCGv_i32 t2 = tcg_temp_ebb_new_i32();
> + g_autoptr(TCGTemp) t1 = tcg_temp_new_ebb(type);
> + g_autoptr(TCGTemp) t2 = tcg_temp_new_ebb(type);
>
> - memop = tcg_canonicalize_memop(memop, 0, 0);
> + memop = tcg_canonicalize_memop(memop, type != TCG_TYPE_I32, 0);
>
> - tcg_gen_qemu_ld_int(TCG_TYPE_I32, tcgv_i32_temp(t1), addr, idx, memop);
> - tcg_gen_ext_i32(t2, val, memop);
> - gen(t2, t1, t2);
> - tcg_gen_qemu_st_int(TCG_TYPE_I32, tcgv_i32_temp(t2), addr, idx, memop);
> + tcg_gen_qemu_ld_int(type, t1, addr, idx, memop);
> + tcg_gen_ext(type, t2, val, memop);
> + gen(type, t2, t1, t2);
> + tcg_gen_qemu_st_int(type, t2, addr, idx, memop);
>
> - tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop);
> - tcg_temp_free_i32(t1);
> - tcg_temp_free_i32(t2);
> + tcg_gen_ext(type, ret, (new_val ? t2 : t1), memop);
> }
>
> -static void do_atomic_op_i32(TCGv_i32 ret, TCGTemp *addr, TCGv_i32 val,
> - TCGArg idx, MemOp memop, void * const table[])
> +static void do_atomic_op(TCGType type, TCGTemp *ret, TCGTemp *addr,
> + TCGTemp *val, unsigned idx, MemOp memop,
> + void * const table[])
> {
> - gen_atomic_op_i32 gen;
> - TCGv_i64 a64;
> + TCGv_i64 a64 = maybe_extend_addr64(addr);
> MemOpIdx oi;
>
> - memop = tcg_canonicalize_memop(memop, 0, 0);
> -
> - gen = table[memop & (MO_SIZE | MO_BSWAP)];
> - tcg_debug_assert(gen != NULL);
> -
> - oi = make_memop_idx(memop & ~MO_SIGN, idx);
> - a64 = maybe_extend_addr64(addr);
> - gen(ret, tcg_env, a64, val, tcg_constant_i32(oi));
> - maybe_free_addr64(a64);
> -
> - if (memop & MO_SIGN) {
> - tcg_gen_ext_i32(ret, ret, memop);
> - }
> -}
> -
> -static void do_nonatomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
> - TCGArg idx, MemOp memop, bool new_val,
> - void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64))
> -{
> - TCGv_i64 t1 = tcg_temp_ebb_new_i64();
> - TCGv_i64 t2 = tcg_temp_ebb_new_i64();
> -
> - memop = tcg_canonicalize_memop(memop, 1, 0);
> -
> - tcg_gen_qemu_ld_int(TCG_TYPE_I64, tcgv_i64_temp(t1), addr, idx, memop);
> - tcg_gen_ext_i64(t2, val, memop);
> - gen(t2, t1, t2);
> - tcg_gen_qemu_st_int(TCG_TYPE_I64, tcgv_i64_temp(t2), addr, idx, memop);
> -
> - tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);
> - tcg_temp_free_i64(t1);
> - tcg_temp_free_i64(t2);
> -}
> -
> -static void do_atomic_op_i64(TCGv_i64 ret, TCGTemp *addr, TCGv_i64 val,
> - TCGArg idx, MemOp memop, void * const table[])
> -{
> - memop = tcg_canonicalize_memop(memop, 1, 0);
> -
> if ((memop & MO_SIZE) == MO_64) {
> gen_atomic_op_i64 gen = table[memop & (MO_SIZE | MO_BSWAP)];
> + tcg_debug_assert(gen != NULL);
> + tcg_debug_assert(type == TCG_TYPE_I64);
>
> - if (gen) {
> - MemOpIdx oi = make_memop_idx(memop & ~MO_SIGN, idx);
> - TCGv_i64 a64 = maybe_extend_addr64(addr);
> - gen(ret, tcg_env, a64, val, tcg_constant_i32(oi));
> - maybe_free_addr64(a64);
> - return;
> + memop = tcg_canonicalize_memop(memop, 1, 0);
> + oi = make_memop_idx(memop & ~MO_SIGN, idx);
> +
> + gen(temp_tcgv_i64(ret), tcg_env, a64,
> + temp_tcgv_i64(val), tcg_constant_i32(oi));
> + } else {
> + g_autoptr(TCGTemp) v32 = NULL;
> + g_autoptr(TCGTemp) r32 = NULL;
> + TCGTemp *ret_orig = ret;
> +
> + gen_atomic_op_i32 gen = table[memop & (MO_SIZE | MO_BSWAP)];
> + tcg_debug_assert(gen != NULL);
> +
> + if (type == TCG_TYPE_I64) {
> + v32 = tcg_temp_new_ebb(TCG_TYPE_I32);
> + r32 = tcg_temp_new_ebb(TCG_TYPE_I32);
> +
> + tcg_gen_extrl(v32, val);
> + val = v32;
> + ret = r32;
> }
>
> - gen_helper_exit_atomic(tcg_env);
> - /* Produce a result, so that we have a well-formed opcode stream
> - with respect to uses of the result in the (dead) code following. */
> - tcg_gen_movi_i64(ret, 0);
> - } else {
> - TCGv_i32 v32 = tcg_temp_ebb_new_i32();
> - TCGv_i32 r32 = tcg_temp_ebb_new_i32();
> + memop = tcg_canonicalize_memop(memop, 0, 0);
> + oi = make_memop_idx(memop & ~MO_SIGN, idx);
>
> - tcg_gen_extrl_i64_i32(v32, val);
> - do_atomic_op_i32(r32, addr, v32, idx, memop & ~MO_SIGN, table);
> - tcg_temp_free_i32(v32);
> -
> - tcg_gen_extu_i32_i64(ret, r32);
> - tcg_temp_free_i32(r32);
> + gen(temp_tcgv_i32(ret), tcg_env, a64,
> + temp_tcgv_i32(val), tcg_constant_i32(oi));
>
> if (memop & MO_SIGN) {
> - tcg_gen_ext_i64(ret, ret, memop);
> + tcg_gen_ext(TCG_TYPE_I32, ret, ret, memop);
> + }
> + if (ret != ret_orig) {
> + if (memop & MO_SIGN) {
> + tcg_gen_exts(ret_orig, ret);
Same two comments from 099/101 apply to this patch.
^ permalink raw reply [flat|nested] 197+ messages in thread
* [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL
2026-09-27 8:58 [PATCH v5 000/101] tcg: Generic expansion of most operations Richard Henderson
` (99 preceding siblings ...)
2026-09-27 9:00 ` [PATCH v5 100/101] tcg: Generic expansion of remaining atomic operations Richard Henderson
@ 2026-09-27 9:00 ` Richard Henderson
2026-09-27 14:57 ` Philippe Mathieu-Daudé
2026-09-27 15:14 ` Philippe Mathieu-Daudé
100 siblings, 2 replies; 197+ messages in thread
From: Richard Henderson @ 2026-09-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: mattst88
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
include/tcg/tcg-op-common.h | 188 +++++++++++++++++++-----------------
1 file changed, 99 insertions(+), 89 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index bc96c02aaea..ec0b7d37684 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -12,24 +12,24 @@
#include "exec/helper-proto-common.h"
#include "exec/helper-gen-common.h"
-TCGv_i32 tcg_constant_i32(int32_t val);
-TCGv_i64 tcg_constant_i64(int64_t val);
-TCGv_vaddr tcg_constant_vaddr(uintptr_t val);
-TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val);
-TCGv_vec tcg_constant_vec_matching(TCGv_vec match, unsigned vece, int64_t val);
+QEMU_RET_NONNULL TCGv_i32 tcg_constant_i32(int32_t val);
+QEMU_RET_NONNULL TCGv_i64 tcg_constant_i64(int64_t val);
+QEMU_RET_NONNULL TCGv_vaddr tcg_constant_vaddr(uintptr_t val);
+QEMU_RET_NONNULL TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val);
+QEMU_RET_NONNULL TCGv_vec tcg_constant_vec_matching(TCGv_vec match, unsigned vece, int64_t val);
-TCGv_i128 tcg_zero_i128(void);
+QEMU_RET_NONNULL TCGv_i128 tcg_zero_i128(void);
-TCGv_i32 tcg_temp_new_i32(void);
-TCGv_i64 tcg_temp_new_i64(void);
-TCGv_ptr tcg_temp_new_ptr(void);
-TCGv_i128 tcg_temp_new_i128(void);
-TCGv_vec tcg_temp_new_vec(TCGType type);
-TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match);
+QEMU_RET_NONNULL TCGv_i32 tcg_temp_new_i32(void);
+QEMU_RET_NONNULL TCGv_i64 tcg_temp_new_i64(void);
+QEMU_RET_NONNULL TCGv_ptr tcg_temp_new_ptr(void);
+QEMU_RET_NONNULL TCGv_i128 tcg_temp_new_i128(void);
+QEMU_RET_NONNULL TCGv_vec tcg_temp_new_vec(TCGType type);
+QEMU_RET_NONNULL TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match);
-TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t off, const char *name);
-TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t off, const char *name);
-TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t off, const char *name);
+QEMU_RET_NONNULL TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t off, const char *name);
+QEMU_RET_NONNULL TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t off, const char *name);
+QEMU_RET_NONNULL TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t off, const char *name);
/* Generic ops. */
static inline void tcg_gen_insn_start(uint64_t pc, uint64_t a1,
@@ -41,8 +41,8 @@ static inline void tcg_gen_insn_start(uint64_t pc, uint64_t a1,
tcg_set_insn_start_param(op, 2, a2);
}
-void gen_set_label(TCGLabel *l);
-void tcg_gen_br(TCGLabel *l);
+QEMU_ARG_NONNULL void gen_set_label(TCGLabel *l);
+QEMU_ARG_NONNULL void tcg_gen_br(TCGLabel *l);
void tcg_gen_mb(TCGBar);
/**
@@ -86,7 +86,7 @@ void tcg_gen_goto_tb(unsigned idx);
void tcg_gen_lookup_and_goto_ptr(void);
void tcg_gen_plugin_cb(unsigned from);
-void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
+QEMU_ARG_NONNULL void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/*
* Construct operations from templates.
@@ -135,23 +135,23 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
-void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
-void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
+QEMU_ARG_NONNULL void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2);
+QEMU_ARG_NONNULL void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg);
+QEMU_ARG_NONNULL void tcg_gen_hswap_i32(TCGv_i32 ret, TCGv_i32 arg);
+QEMU_ARG_NONNULL void tcg_gen_revbit32_i32(TCGv_i32 ret, TCGv_i32 arg);
/* 64 bit ops */
-void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
-void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
-void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
-void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
-void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
-void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_addN_i64(int n, TCGv_i64 *r, TCGv_i64 *a, TCGv_i64 *b);
+QEMU_ARG_NONNULL void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2);
+QEMU_ARG_NONNULL void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
+QEMU_ARG_NONNULL void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_wswap_i64(TCGv_i64 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_revbit32_i64(TCGv_i64 ret, TCGv_i64 arg, unsigned flags);
+QEMU_ARG_NONNULL void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset);
@@ -160,96 +160,106 @@ void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
/* Size changing operations. */
-void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg);
-void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg);
-void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high);
-void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg);
-void tcg_gen_extrh_i64_i32(TCGv_i32 ret, TCGv_i64 arg);
-void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg);
-void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg);
-void tcg_gen_concat32_i64(TCGv_i64 ret, TCGv_i64 lo, TCGv_i64 hi);
+QEMU_ARG_NONNULL void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg);
+QEMU_ARG_NONNULL void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg);
+QEMU_ARG_NONNULL void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high);
+QEMU_ARG_NONNULL void tcg_gen_extrl_i64_i32(TCGv_i32 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_extrh_i64_i32(TCGv_i32 ret, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg);
+QEMU_ARG_NONNULL void tcg_gen_concat32_i64(TCGv_i64 ret, TCGv_i64 lo, TCGv_i64 hi);
-void tcg_gen_extr_i128_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i128 arg);
-void tcg_gen_concat_i64_i128(TCGv_i128 ret, TCGv_i64 lo, TCGv_i64 hi);
+QEMU_ARG_NONNULL void tcg_gen_extr_i128_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i128 arg);
+QEMU_ARG_NONNULL void tcg_gen_concat_i64_i128(TCGv_i128 ret, TCGv_i64 lo, TCGv_i64 hi);
/* 128 bit ops */
-void tcg_gen_mov_i128(TCGv_i128 dst, TCGv_i128 src);
-void tcg_gen_ld_i128(TCGv_i128 ret, TCGv_ptr base, tcg_target_long offset);
-void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
+QEMU_ARG_NONNULL void tcg_gen_mov_i128(TCGv_i128 dst, TCGv_i128 src);
+QEMU_ARG_NONNULL void tcg_gen_ld_i128(TCGv_i128 ret, TCGv_ptr base, tcg_target_long offset);
+QEMU_ARG_NONNULL void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
+QEMU_ARG_NONNULL
void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGv_i128, TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_atomic_xchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_atomic_fetch_and_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
+QEMU_ARG_NONNULL
void tcg_gen_atomic_fetch_or_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
TCGArg, MemOp, TCGType);
/* Vector ops */
-void tcg_gen_mov_vec(TCGv_vec, TCGv_vec);
-void tcg_gen_dup_i32_vec(unsigned vece, TCGv_vec, TCGv_i32);
-void tcg_gen_dup_i64_vec(unsigned vece, TCGv_vec, TCGv_i64);
-void tcg_gen_dup_mem_vec(unsigned vece, TCGv_vec, TCGv_ptr, tcg_target_long);
-void tcg_gen_dupi_vec(unsigned vece, TCGv_vec, uint64_t);
-void tcg_gen_add_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_sub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_mul_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_and_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_or_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_xor_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_andc_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_orc_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_nand_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_nor_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_eqv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_not_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
-void tcg_gen_neg_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
-void tcg_gen_abs_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
-void tcg_gen_ssadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_usadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_sssub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_ussub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_smin_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_umin_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_smax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_umax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_mov_vec(TCGv_vec, TCGv_vec);
+QEMU_ARG_NONNULL void tcg_gen_dup_i32_vec(unsigned vece, TCGv_vec, TCGv_i32);
+QEMU_ARG_NONNULL void tcg_gen_dup_i64_vec(unsigned vece, TCGv_vec, TCGv_i64);
+QEMU_ARG_NONNULL void tcg_gen_dup_mem_vec(unsigned vece, TCGv_vec, TCGv_ptr, tcg_target_long);
+QEMU_ARG_NONNULL void tcg_gen_dupi_vec(unsigned vece, TCGv_vec, uint64_t);
+QEMU_ARG_NONNULL void tcg_gen_add_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_sub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_mul_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_and_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_or_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_xor_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_andc_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_orc_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_nand_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_nor_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_eqv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_not_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
+QEMU_ARG_NONNULL void tcg_gen_neg_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
+QEMU_ARG_NONNULL void tcg_gen_abs_vec(unsigned vece, TCGv_vec r, TCGv_vec a);
+QEMU_ARG_NONNULL void tcg_gen_ssadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_usadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_sssub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_ussub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_smin_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_umin_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_smax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL void tcg_gen_umax_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
-void tcg_gen_shli_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
-void tcg_gen_shri_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
-void tcg_gen_sari_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
-void tcg_gen_rotli_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
-void tcg_gen_rotri_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
+QEMU_ARG_NONNULL void tcg_gen_shli_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
+QEMU_ARG_NONNULL void tcg_gen_shri_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
+QEMU_ARG_NONNULL void tcg_gen_sari_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
+QEMU_ARG_NONNULL void tcg_gen_rotli_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
+QEMU_ARG_NONNULL void tcg_gen_rotri_vec(unsigned vece, TCGv_vec r, TCGv_vec a, int64_t i);
-void tcg_gen_shls_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
-void tcg_gen_shrs_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
-void tcg_gen_sars_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
-void tcg_gen_rotls_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
+QEMU_ARG_NONNULL void tcg_gen_shls_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
+QEMU_ARG_NONNULL void tcg_gen_shrs_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
+QEMU_ARG_NONNULL void tcg_gen_sars_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
+QEMU_ARG_NONNULL void tcg_gen_rotls_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_i32 s);
-void tcg_gen_shlv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
-void tcg_gen_shrv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
-void tcg_gen_sarv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
-void tcg_gen_rotlv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
-void tcg_gen_rotrv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL void tcg_gen_shlv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL void tcg_gen_shrv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL void tcg_gen_sarv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL void tcg_gen_rotlv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL void tcg_gen_rotrv_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec s);
+QEMU_ARG_NONNULL
void tcg_gen_cmp_vec(TCGCond cond, unsigned vece, TCGv_vec r,
TCGv_vec a, TCGv_vec b);
+QEMU_ARG_NONNULL
void tcg_gen_bitsel_vec(unsigned vece, TCGv_vec r, TCGv_vec a,
TCGv_vec b, TCGv_vec c);
+QEMU_ARG_NONNULL
void tcg_gen_cmpsel_vec(TCGCond cond, unsigned vece, TCGv_vec r,
TCGv_vec a, TCGv_vec b, TCGv_vec c, TCGv_vec d);
-void tcg_gen_ld_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset);
-void tcg_gen_st_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset);
-void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t);
+QEMU_ARG_NONNULL void tcg_gen_ld_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset);
+QEMU_ARG_NONNULL void tcg_gen_st_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset);
+QEMU_ARG_NONNULL void tcg_gen_stl_vec(TCGv_vec r, TCGv_ptr base, TCGArg offset, TCGType t);
/* Host pointer ops */
--
2.53.0
^ permalink raw reply related [flat|nested] 197+ messages in thread* Re: [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL
2026-09-27 9:00 ` [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL Richard Henderson
@ 2026-09-27 14:57 ` Philippe Mathieu-Daudé
2026-09-27 15:14 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 14:57 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 11:00, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 188 +++++++++++++++++++-----------------
> 1 file changed, 99 insertions(+), 89 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 197+ messages in thread
* Re: [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL
2026-09-27 9:00 ` [PATCH v5 101/101] tcg: Annontate functions in tcg-op-common.h with QEMU_*_NONNULL Richard Henderson
2026-09-27 14:57 ` Philippe Mathieu-Daudé
@ 2026-09-27 15:14 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 197+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-27 15:14 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: mattst88
On 27/9/26 11:00, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/tcg/tcg-op-common.h | 188 +++++++++++++++++++-----------------
> 1 file changed, 99 insertions(+), 89 deletions(-)
> /* 128 bit ops */
>
> -void tcg_gen_mov_i128(TCGv_i128 dst, TCGv_i128 src);
> -void tcg_gen_ld_i128(TCGv_i128 ret, TCGv_ptr base, tcg_target_long offset);
> -void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
> +QEMU_ARG_NONNULL void tcg_gen_mov_i128(TCGv_i128 dst, TCGv_i128 src);
> +QEMU_ARG_NONNULL void tcg_gen_ld_i128(TCGv_i128 ret, TCGv_ptr base, tcg_target_long offset);
> +QEMU_ARG_NONNULL void tcg_gen_st_i128(TCGv_i128 val, TCGv_ptr base, tcg_target_long offset);
>
> +QEMU_ARG_NONNULL
> void tcg_gen_qemu_ld_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
> +QEMU_ARG_NONNULL
> void tcg_gen_qemu_st_chk_i128(TCGv_i128, TCGTemp *, TCGArg, MemOp, TCGType);
>
> +QEMU_ARG_NONNULL
> void tcg_gen_atomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
> +QEMU_ARG_NONNULL
> void tcg_gen_nonatomic_cmpxchg_chk_i128(TCGv_i128, TCGTemp *, TCGv_i128,
> TCGv_i128, TCGArg, MemOp, TCGType);
Could we unify style and prepend the QEMU_ARG_NONNULL attribute always
in its own line? That'd reduce churn and keep declarations at our
coding style line limit.
^ permalink raw reply [flat|nested] 197+ messages in thread