x86: fix helper function that displaces address by a given amount.

Change the function from a non-const method to a static member to avoid
giving an impression that it modifies the old address.

Add a gtest that constructs addresses with some initial displacement and
checks that they are equal to addresses constructed in the same way only
without displacement, and then displaced.

The added gtest reveals errors in the displace function. Some of the
added test cases crashed on checks, others failed test assertions. This
shouldn't affect real world as the use of the helper function in the
compiler is limited to a few working cases.

Checks failed because some of the address constructors do not expect ESP
as base register. It is possible to construct such addresses with
another constructor like `x86::Address(x86::ESP, 0))`, but an attempt to
displace this address would try to reassemble it using a forbidden
constructor and hit the check.

Some of the failed test assertions were for Address::Absolute, such as:

  Expected equality of these values:
    x86::Address::displace(x86::Address::Absolute(0), 42)
      Which is: 42(%ebp)
    x86::Address::Absolute(42)
      Which is: (%ebp)

Other failed test assertions were due to the fact that one and the same
address can be encoded in more than one way, e.g. 32-bit displacement
normally requires mod 11b, but can also be achieved with mod 00b if EBP
is used as r/m or base. Example of a test failure:

  Expected equality of these values:
    x86::Address::displace(x86::Address(EAX, TIMES_1, 42), -42)
      Which is: 0(%ebp,%eax,1)
    x86::Address(EAX, TIMES_1, 0)
      Which is: 0(,%eax,1)

Bug: 65872996
Test: m test-art-host-gtest  # changes covered by the new test
Test: art/test.py --host -r
Change-Id: I8dcdc968d7bd9da2c0a16ef0afeb13cf9a168359
3 files changed