Skip to content

tcg: Handle clz, ctz, and clrsb generically

Richard Henderson qemu-arm qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest25 patches 14 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/25tcg: Add clz and ctz opcodestcg-runtime.c tcg/README tcg/aarch64/tcg-target.h +14 more+209 -02 replies
2/25target-alpha: Use the ctz and clz opcodestarget-alpha/helper.h target-alpha/int_helper.c target-alpha/translate.c+2 -140 replies
3/25target-cris: Use clz opcodetarget-cris/helper.h target-cris/op_helper.c target-cris/translate.c+1 -70 replies
4/25target-microblaze: Use clz opcodetarget-microblaze/helper.h target-microblaze/op_helper.c target-microblaze/translate.c+1 -70 replies
5/25target-mips: Use clz opcodetarget-mips/helper.h target-mips/op_helper.c target-mips/translate.c+16 -360 replies
6/25target-openrisc: Use clz and ctz opcodestarget-openrisc/helper.h target-openrisc/int_helper.c target-openrisc/translate.c+4 -230 replies
7/25target-ppc: Use clz and ctz opcodestarget-ppc/helper.h target-ppc/int_helper.c target-ppc/translate.c+16 -281 reply
8/25target-s390x: Use clz opcodetarget-s390x/helper.h target-s390x/int_helper.c target-s390x/translate.c+1 -80 replies
9/25target-tilegx: Use clz and ctz opcodestarget-tilegx/helper.c target-tilegx/helper.h target-tilegx/translate.c+2 -140 replies
10/25target-tricore: Use clz opcodetarget-tricore/helper.h target-tricore/op_helper.c target-tricore/translate.c+3 -142 replies
11/25target-unicore32: Use clz opcodetarget-unicore32/helper.c target-unicore32/helper.h target-unicore32/translate.c+3 -160 replies
12/25target-xtensa: Use clz opcodetarget-xtensa/helper.h target-xtensa/op_helper.c target-xtensa/translate.c+11 -170 replies
13/25target-arm: Use clz opcodetarget-arm/helper-a64.c target-arm/helper-a64.h target-arm/helper.c +3 more+7 -250 replies
14/25target-i386: Use clz and ctz opcodestarget-i386/helper.h target-i386/int_helper.c target-i386/translate.c+14 -300 replies
15/25disas/i386.c: Handle tzcntdisas/i386.c+10 -20 replies
16/25tcg/i386: Handle ctz and clz opcodestcg/i386/tcg-target.h tcg/i386/tcg-target.inc.c+78 -137 replies
17/25tcg/ppc: Handle ctz and clz opcodestcg/ppc/tcg-target.h tcg/ppc/tcg-target.inc.c+61 -40 replies
18/25tcg/aarch64: Handle ctz and clz opcodestcg/aarch64/tcg-target.h tcg/aarch64/tcg-target.inc.c+51 -42 replies
19/25tcg/arm: Handle ctz and clz opcodestcg/arm/tcg-target.h tcg/arm/tcg-target.inc.c+29 -20 replies
20/25tcg/mips: Handle clz opcodetcg/mips/tcg-target.h tcg/mips/tcg-target.inc.c+36 -20 replies
21/25tcg/s390: Handle clz opcodetcg/s390/tcg-target.h tcg/s390/tcg-target.inc.c+36 -20 replies
22/25tcg: Add helpers for clrsbtcg-runtime.c tcg/tcg-op.c tcg/tcg-op.h +1 more+44 -00 replies
23/25target-arm: Use clrsb helpertarget-arm/helper-a64.c target-arm/helper-a64.h target-arm/translate-a64.c+4 -160 replies
24/25target-tricore: Use clrsb helpertarget-tricore/helper.h target-tricore/op_helper.c target-tricore/translate.c+1 -70 replies
25/25target-xtensa: Use clrsb helpertarget-xtensa/translate.c+1 -100 replies

Reviews trailers per patch

1 of 25 patches has a Reviewed-by or Acked-by.

PatchDavid Gibson
1/25
2/25
3/25
4/25
5/25
6/25
7/25R-b
8/25
9/25
10/25
11/25
12/25
13/25
14/25
15/25
16/25
17/25
18/25
19/25
20/25
21/25
22/25
23/25
24/25
25/25

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

Read the v1 thread

Cover letter [Qemu-devel] [PATCH 00/25] tcg: Handle clz, ctz, and clrsb generically

As you can see from the diffstat below, almost every target was defining its own helpers for these common bit manipulation ops.

In the case of ctz and clz, they are often central to string search routines such as strlen, so it does benefit us to make them fast. So I do go ahead and add those as tcg opcodes, that can be handled by the tcg backends.

One perhaps surprising thing about my definition of these opcodes is that they take an explicit argument for the value to return when the input is zero.

In the vast majority of cases this we simply pass a constant that is the width of the argument. But it turns out to have a number of uses when implementing target-i386 (bsf does not change the register), target-openrisc (ff1 = ffs(3)), decomposing 64-bit clz/ctz for a 32-bit host, and actually implementing tcg/i386 (forcing the value into a register for input to cmov).

Lightly tested with x86_64 and ppc64 hosts.

r~

Richard Henderson (25):
tcg: Add clz and ctz opcodes
target-alpha: Use the ctz and clz opcodes
target-cris: Use clz opcode
target-microblaze: Use clz opcode
target-mips: Use clz opcode
target-openrisc: Use clz and ctz opcodes
target-ppc: Use clz and ctz opcodes
target-s390x: Use clz opcode
target-tilegx: Use clz and ctz opcodes
target-tricore: Use clz opcode
target-unicore32: Use clz opcode
target-xtensa: Use clz opcode
target-arm: Use clz opcode
target-i386: Use clz and ctz opcodes
disas/i386.c: Handle tzcnt
tcg/i386: Handle ctz and clz opcodes
tcg/ppc: Handle ctz and clz opcodes
tcg/aarch64: Handle ctz and clz opcodes
tcg/arm: Handle ctz and clz opcodes
tcg/mips: Handle clz opcode
tcg/s390: Handle clz opcode
tcg: Add helpers for clrsb
target-arm: Use clrsb helper
target-tricore: Use clrsb helper
target-xtensa: Use clrsb helper

 disas/i386.c                  |  12 ++++-
 target-alpha/helper.h         |   2 -
 target-alpha/int_helper.c     |  10 ----
 target-alpha/translate.c      |   4 +-
 target-arm/helper-a64.c       |  20 --------
 target-arm/helper-a64.h       |   4 --
 target-arm/helper.c           |   5 --
 target-arm/helper.h           |   1 -
 target-arm/translate-a64.c    |  16 +++---
 target-arm/translate.c        |   6 +--
 target-cris/helper.h          |   1 -
 target-cris/op_helper.c       |   5 --
 target-cris/translate.c       |   2 +-
 target-i386/helper.h          |   2 -
 target-i386/int_helper.c      |  11 ----
 target-i386/translate.c       |  31 ++++++------
 target-microblaze/helper.h    |   1 -
 target-microblaze/op_helper.c |   5 --
 target-microblaze/translate.c |   2 +-
 target-mips/helper.h          |   7 ---
 target-mips/op_helper.c       |  22 --------
 target-mips/translate.c       |  23 ++++++---
 target-openrisc/helper.h      |   2 -
 target-openrisc/int_helper.c  |  19 -------
 target-openrisc/translate.c   |   6 ++-
 target-ppc/helper.h           |   4 --
 target-ppc/int_helper.c       |  20 --------
 target-ppc/translate.c        |  20 ++++++--
 target-s390x/helper.h         |   1 -
 target-s390x/int_helper.c     |   6 ---
 target-s390x/translate.c      |   2 +-
 target-tilegx/helper.c        |  10 ----
 target-tilegx/helper.h        |   2 -
 target-tilegx/translate.c     |   4 +-
 target-tricore/helper.h       |   3 --
 target-tricore/op_helper.c    |  15 ------
 target-tricore/translate.c    |   7 +--
 target-unicore32/helper.c     |  10 ----
 target-unicore32/helper.h     |   3 --
 target-unicore32/translate.c  |   6 +--
 target-xtensa/helper.h        |   2 -
 target-xtensa/op_helper.c     |  13 -----
 target-xtensa/translate.c     |   4 +-
 tcg-runtime.c                 |  30 +++++++++++
 tcg/README                    |   8 +++
 tcg/aarch64/tcg-target.h      |   4 ++
 tcg/aarch64/tcg-target.inc.c  |  47 +++++++++++++++++
 tcg/arm/tcg-target.h          |   2 +
 tcg/arm/tcg-target.inc.c      |  27 ++++++++++
 tcg/i386/tcg-target.h         |   4 ++
 tcg/i386/tcg-target.inc.c     |  83 ++++++++++++++++++++++++++----
 tcg/ia64/tcg-target.h         |   4 ++
 tcg/mips/tcg-target.h         |   2 +
 tcg/mips/tcg-target.inc.c     |  34 +++++++++++++
 tcg/optimize.c                |  36 +++++++++++++
 tcg/ppc/tcg-target.h          |   4 ++
 tcg/ppc/tcg-target.inc.c      |  57 +++++++++++++++++++++
 tcg/s390/tcg-target.h         |   4 ++
 tcg/s390/tcg-target.inc.c     |  36 ++++++++++++-
 tcg/sparc/tcg-target.h        |   4 ++
 tcg/tcg-op.c                  | 114 ++++++++++++++++++++++++++++++++++++++++++
 tcg/tcg-op.h                  |  20 ++++++++
 tcg/tcg-opc.h                 |   4 ++
 tcg/tcg-runtime.h             |   7 +++
 tcg/tcg.h                     |   2 +
 tcg/tci/tcg-target.h          |   4 ++
 66 files changed, 614 insertions(+), 274 deletions(-)
Signature · 1 line
2.7.4