@samitouri / QOSamiQemu / commits / 7f9ce196f7

tcg/aarch64: Use tgen_brcondi in tcg_out_qemu_ldst_i128

Allow tgen_brcondi to choose between TBNZ and TST+B.cond for implementing a particular mask. Suggested-by: yujun <yujun@kylinos.cn> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed Jul 24, 2026 at 19:51 UTC 7f9ce196f71ffded121f26ae6df5e6036eda5e1f
1 file changed +10 -15
tcg/aarch64/tcg-target.c.inc
+10 -15
@@ -1916,23 +1916,18 @@ static void tcg_out_qemu_ldst_i128(TCGContext *s, TCGReg datalo, TCGReg datahi,
1916 use_pair = h.aa.atom < MO_128 || have_lse2;
1917
1918 if (!use_pair) {
1919 - tcg_insn_unit *branch = NULL;
1919 + TCGLabel *label = NULL;
1920 TCGReg ll, lh, sl, sh;
1921 -
1921 /*
1923 - * If we have already checked for 16-byte alignment, that's all
1924 - * we need. Otherwise we have determined that misaligned atomicity
1925 - * may be handled with two 8-byte loads.
1922 + * Check for 16-byte alignment, taking into consideration the
1923 + * alignment that has already been checked.
1924 */
1927 - if (h.aa.align < MO_128) {
1928 - /*
1929 - * TODO: align should be MO_64, so we only need test bit 3,
1930 - * which means we could use TBNZ instead of ANDS+B_C.
1931 - */
1932 - tcg_out_logicali(s, Ilogic_imm_ANDSI, 0, TCG_REG_XZR, addr_reg,
1933 - 15);
1934 - branch = s->code_ptr;
1935 - tcg_out_insn(s, bcond_imm, B_C, TCG_COND_NE, 0);
1925 + int a_mask = 16 - (1 << h.aa.align);
1926 +
1927 + if (a_mask > 0) {
1928 + label = gen_new_label();
1929 + tgen_brcondi(s, TCG_TYPE_I32, TCG_COND_TSTNE,
1930 + addr_reg, a_mask, label);
1931 use_pair = true;
1932 }
1933
@@ -1971,7 +1966,7 @@ static void tcg_out_qemu_ldst_i128(TCGContext *s, TCGReg datalo, TCGReg datahi,
1966 if (use_pair) {
1967 /* "b .+8", branching across the one insn of use_pair. */
1968 tcg_out_insn(s, branch, B, 2);
1974 - reloc_pc19(branch, tcg_splitwx_to_rx(s->code_ptr));
1969 + tcg_out_label(s, label);
1970 }
1971 }
1972