Use ADD/SUB instructions on x86 and x86-64 atomics instead of INC/DEC
authorThiago Macieira <thiago.macieira@intel.com>
Sun, 25 Dec 2011 21:30:15 +0000 (19:30 -0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Mar 2012 12:54:29 +0000 (14:54 +0200)
commit7db5f0dd6a3a876279a32cf060dfbc929c615de4
tree2139a5ce7c44198cd59d0f4940917c1db1597fa1
parent99802f0c1498b0630949e75f69afe1cc0c89c4d4
Use ADD/SUB instructions on x86 and x86-64 atomics instead of INC/DEC

According to the Intel Optimization Manual section 3.5.1.1 Use of INC
and DEC Instructions, those instructions modify only part of the flags
register, so they mey introduce unnecessary data dependencies on
previous flag-setting operations so that the resulting flags are
computed. Preferring ADD and SUB (rule 33) is recommended.

However, we don't do it for 16-bit integers. The reason is that the
presence of the 0x66 prefix may trigger a slower decoding codepath in
the processor (up to 6 cycles, as opposed to 1). The same Intel manual
talks about Length-Changing Prefix, which applies in particular to
instructions with 16-bit immediates. The assembler generally produces
uses the 8-bit immediate variant of the ADD and SUB instructions, but
to be on the safe side, we prefer to use INC and DEC here.

Change-Id: Ic03236ac600a5b4e087614d21df5d3c666ae064e
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
src/corelib/arch/qatomic_i386.h
src/corelib/arch/qatomic_x86_64.h