math/mpx.c: Fix two's-complement storing.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 22 Jun 2017 08:33:20 +0000 (09:33 +0100)
commit850dc2722b8ca17302d89c483b63693fa2fe9ef5
tree8135b17751b22f3ef402d3d4a03a54cb63606465
parent8851fe49eb5c9112f3bd00e285f9c502dfd0deb3
math/mpx.c: Fix two's-complement storing.

Oh, dear.  This was a bit wrong.

  * The internal representation, in terms of `mpw' vectors, is always
    nonnegative.  Remove the bogus sign-extension machinery for
    `mpx_load*2cn'.

  * The logic for sign-extending octet vectors in `mpx_store*2cn' was
    the wrong way round.  Fix it.

  * Rather than sign-extending `mpw' vectors, it's necessary to apply a
    correction when we reach the end of an octet vector in
    `mpx_load*2cn'.  Introduce a new argument to `MPX_LOADSTORE' to
    carry the necessary correction logic, and use it.

  * The test functions used a single `mpw' vector length for both
    positive and negative values, which meant that the logic for sign-
    extending octet strings on output wasn't exercised.  Fix the test:
    so that it now does two passes, forcing both sign-extension on
    output and zero-extension on input.
math/mpx.c
math/t/mpx