Skip to content

target/i386: miscellaneous flags improvements

Paolo Bonzini qemu-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest14 patches 5 repliesIn review
  2. v114 patches 8 repliesSuperseded

Changes in v2 from the cover letter

- use MAKE_64BIT_MASK in helper_cc_compute_nz
- get rid completely of parity_table

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14target/i386: use tcg_gen_ext_tl when applicabletarget/i386/tcg/translate.c+8 -80 replies
2/14target/i386: Tidy cc_op_str usagetarget/i386/cpu-dump.c+11 -60 replies
3/14target/i386: remove CC_OP_CLRtarget/i386/cpu-dump.c target/i386/cpu.h target/i386/tcg/cc_helper.c +2 more+4 -260 replies
4/14target/i386: Rearrange CCOptarget/i386/cpu.h+8 -60 replies
5/14target/i386: Introduce cc_op_sizetarget/i386/cpu.h target/i386/tcg/emit.c.inc target/i386/tcg/translate.c+26 -130 replies
6/14target/i386: Wrap cc_op_live with a validity checktarget/i386/cpu.h target/i386/tcg/decode-new.c.inc target/i386/tcg/emit.c.inc +1 more+21 -70 replies
7/14target/i386: optimize computation of ZF from CC_OP_DYNAMICtarget/i386/helper.h target/i386/tcg/cc_helper.c target/i386/tcg/translate.c+21 -31 reply
8/14target/i386: optimize TEST+Jxx sequencestarget/i386/tcg/translate.c+22 -00 replies
9/14target/i386: add a few more trivial CCPrepare casestarget/i386/tcg/translate.c+3 -00 replies
10/14target/i386: add a note about gen_jcc1target/i386/tcg/translate.c+4 -01 reply
11/14target/i386: make flag variables unsignedtarget/i386/tcg/cc_helper_template.h.inc+23 -230 replies
12/14target/i386: use compiler builtin to compute PFinclude/qemu/host-utils.h target/i386/tcg/cc_helper.c target/i386/tcg/cc_helper_template.h.inc +2 more+26 -481 reply
13/14target/i386: use higher-precision arithmetic to compute CFtarget/i386/tcg/cc_helper_template.h.inc+37 -01 reply
14/14target/i386: use + to put flags togethertarget/i386/tcg/cc_helper_template.h.inc+12 -121 reply

Reviews trailers per patch

11 of 14 patches have a Reviewed-by or Acked-by.

PatchRichard Henderson
1/14R-b
2/14
3/14R-b
4/14
5/14
6/14R-b
7/14R-b
8/14R-b
9/14R-b
10/14R-b
11/14R-b
12/14R-b
13/14R-b
14/14R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/14] target/i386: miscellaneous flags improvements

This includes improved translation of checks, microoptimization of the helpers, and improvements to the cc_op_* functions from Richard.

Unlike his original patches[1] I didn't convert cc_op_live() to a switch statement, instead keeping the array but making sure that all of its entries are nonzero. The only zero entry was CC_OP_CLR, which is now changed to spill the constant value of EFLAGS to cc_op_src. While this has a 0.2% cost in number of TCG ops, getting rid of the special case for CC_OP_CLR makes it even easier to optimize computation of ZF from CC_OP_DYNAMIC; this is quite common, for example in switch statements that have CMP/JG/JE sequences (JE followed JL/JG/JA/JB seems less common than the opposite, though that's not universal).

On a quick-and-dirty run of "ls -lR", the changes add ~750 spills of 0x44 to cc_op_src; but it also reduces to one half the calls to cc_compute_all (most of them are completely eliminated), and that is a lot more expensive.

One thing I noticed is that those spills are really huge (11 bytes). It might help to move cc_* at the very beginning of CPUX86State, because the number of accesses to cc_* is comparable to the number of accesses to registers (despite cc_* being mostly written, while registers are both read and written).

Thanks,

Paolo

[1] https://patchew.org/QEMU/[email protected]/

v1->v2:
- use MAKE_64BIT_MASK in helper_cc_compute_nz
- get rid completely of parity_table

Paolo Bonzini (10):
target/i386: use tcg_gen_ext_tl when applicable target/i386: remove CC_OP_CLR
target/i386: optimize computation of ZF from CC_OP_DYNAMIC target/i386: optimize TEST+Jxx sequences target/i386: add a few more trivial CCPrepare cases target/i386: add a note about gen_jcc1 target/i386: make flag variables unsigned target/i386: use compiler builtin to compute PF target/i386: use higher-precision arithmetic to compute CF target/i386: use + to put flags together

Richard Henderson (4):
target/i386: Tidy cc_op_str usage target/i386: Rearrange CCOp
target/i386: Introduce cc_op_size target/i386: Wrap cc_op_live with a validity check

 include/qemu/host-utils.h                |   9 ++
 target/i386/cpu.h                        |  33 ++++--
 target/i386/helper.h                     |   1 +
 target/i386/tcg/helper-tcg.h             |   6 +-
 target/i386/tcg/cc_helper_template.h.inc | 127 +++++++++++++++--------
 target/i386/cpu-dump.c                   |  18 ++--
 target/i386/tcg/cc_helper.c              |  51 +++------
 target/i386/tcg/int_helper.c             |   4 +-
 target/i386/tcg/translate.c              | 103 ++++++++++++------
 target/i386/tcg/decode-new.c.inc         |   2 +-
 target/i386/tcg/emit.c.inc               |  24 ++---
 11 files changed, 226 insertions(+), 152 deletions(-)
Signature · 1 line
2.47.0