Il 02/06/2013 16:18, Peter Maydell ha scritto: > On 31 May 2013 23:18, Richard Henderson <r...@twiddle.net> wrote: >> On 05/30/2013 02:16 PM, Paolo Bonzini wrote: >>> +static inline Int128 int128_rshift(Int128 a, int n) >>> +{ >>> + return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), (a.hi >> n) }; >>> +} >> >> Produces wrong results for n == 0, since (a.hi << 64) is undefined. > > It produces wrong results for shifts by more than 64, > for that matter.
This should work: int64_t h; if (!n) { return a; } h = a.hi >> n; if (n >= 64) { return (Int128) { h, h >> 63 }; } else { return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), h }; } Paolo