tcg-ppc: fix qemu_ld/qemu_st for AIX ABI

For the AIX ABI, the function pointer and small area pointer need
to be loaded in the trampoline.  The trampoline instead is called
with a normal BL instruction.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: use new return-argument ld/st helpers

These use a 32-bit load-of-immediate to save a mflr+addi+mtlr sequence.
The immediate must be adjusted by 1; we could actually do that in the
helper instead, since it's common to all targets or almost all targets.
If we did that, stores could use mtlr+b (instead of bl+b) to return from
the trampoline straight to the caller.

Tested with a Windows 98 guest (pretty much the most recent thing I
could run on my PPC machine).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: do not pass r0 to tcg_out_tlb_check, rename arguments

r0 is special in PowerPC and cannot always be used.  Hardcode it in
tcg_out_tlb_check instead of passing it as an argument.

Rename remaining arguments to t1 and t2 to avoid confusion between
register and argument names.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: put pseudo-code before instruction, not after

This is more consistent with other code in the file.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: schedule addend load and computation earlier

Use r0 instead of t1 for the addend, and do the load between the
compare and the branch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: extract code to generate XOR

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: extract code to generate AND

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: extract code to generate shifts

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: improve eq/ne sequences with large constants

Use XORIS if possible.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: use carry-based sequences for unsigned setcond

For constants we could also use a trick similar to the one in the next
commit:

    x > y (unsigned)         sign bit of x | (y - x), if y sign bit is 0
    x > y (unsigned)         sign bit of x & (y - x), if y sign bit is 1

x <= y can then be computed with NAND and NOR, while x < y and x >= y are
obtained by adjusting y.  However, the sequences produced by this patch
are three instructions long, so leave this for later.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tcg-ppc: use magic sequences for signed comparison with positive constants

This is a generalization of a well-known trick:

   x <= 0        sign bit of x | (x - 1)

which can be seen as

   x < 1         sign bit of x | (x - 1)

and generalized to x < y for positive y:

   x < y         sign bit of x | (x - y), y > 0

This basically means "x < y if either x or x-y are negative", and a
similar identity holds negative y ("x < y if both x and x-y are negative",
remember that x-y > x if you disregard overflow!):

   x < y         sign bit of x & (x - y), y < 0

x >= y can then be computed easily as well on PowerPC, since it has NAND
and NOR.  x <= y and x > y can of course be computed too by adjusting
y and reducing to < and >=.

On some benchmarks (e.g. ppc-on-ppc "dc -e 4000k10v") this gives a
5% speedup.  On others (including almost everything i386) it's a wash.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
optimize: store mask for optimization of subsequent instructions

This will help propagating the mask from setcond to deposit
after the following patch.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
optimize: optimize deposit to a previous movi destination

With x86 a common pattern is to zero a register and then do a setCC
operation into it.  In this case, a TCG setcond operation is enough
and there is no need for a deposit operation.  With this patch, the
optimizer notices this and makes the previous store of zero dead.
This gives a ~0.5% improvement for various i386-on-PPC benchmarks,
and a ~1% reduction in executed instructions.

The optimization hits in other cases, such as moving a constant
to %bx where the high bits of %ebx are known to be zero.  This
requires the special handling of deposit operations that become
a movi.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: fix monitor access to CR

This was off-by-one.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: use ARRAY_SIZE in gdbstub.c

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: use CRF_* in fpu_helper.c

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: introduce helpers for mfocrf/mtocrf

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: reorganize gen_compute_fprf

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: introduce gen_op_mfcr/gen_op_mtcr

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ppc: use movcond for isel

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>