Il 02/07/2013 14:46, Jay Foad ha scritto:
>> static inline Int128 int128_neg(Int128 a)
>> {
>> -a.lo = ~a.lo;
>> -a.hi = ~a.hi;
>> -return int128_add(a, int128_one());
>> +uint64_t lo = -a.lo;
>> +return (Int128) { lo, ~a.hi + !lo };
>> }
>
> This leaves int128_one unused. (
> static inline Int128 int128_neg(Int128 a)
> {
> -a.lo = ~a.lo;
> -a.hi = ~a.hi;
> -return int128_add(a, int128_one());
> +uint64_t lo = -a.lo;
> +return (Int128) { lo, ~a.hi + !lo };
> }
This leaves int128_one unused. (Also the temporary lo seems a bit
pointless, since you
Il 20/06/2013 18:46, Richard Henderson ha scritto:
> On 06/20/2013 08:00 AM, Paolo Bonzini wrote:
>> static inline Int128 int128_sub(Int128 a, Int128 b)
>> {
>> -return int128_add(a, int128_neg(b));
>> +uint64_t lo = a.lo - b.lo;
>> +return (Int128) { lo, (lo < a.lo) + a.hi - b.hi };
On 06/20/2013 08:00 AM, Paolo Bonzini wrote:
> static inline Int128 int128_sub(Int128 a, Int128 b)
> {
> -return int128_add(a, int128_neg(b));
> +uint64_t lo = a.lo - b.lo;
> +return (Int128) { lo, (lo < a.lo) + a.hi - b.hi };
This one isn't right. Consider { 2, 0 } - { 2, 0 }
lo
For add and sub, carry computation only requires checking one of the
arguments (any for add, the LHS for sub because the RHS is negated).
For neg, we can similarly optimize computation of the carry.
For ge, we can just do lexicographic order.
Signed-off-by: Paolo Bonzini
---
Will post un