Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix, avoid undefined behavior

2015-11-06 Thread Mark Cave-Ayland
On 06/11/15 15:50, Paolo Bonzini wrote: > This is reported by Coverity. The algorithm description at > ftp://ftp.icm.edu.pl/packages/ggi/doc/hw/sparc/Sparc.pdf suggests > that the 32-bit parts of rs2, after the left shift, is treated > as a 64-bit integer. Bits 32 and above are used to do the >

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix, avoid undefined behavior

2015-11-06 Thread Richard Henderson
On 11/06/2015 04:50 PM, Paolo Bonzini wrote: This is reported by Coverity. The algorithm description at ftp://ftp.icm.edu.pl/packages/ggi/doc/hw/sparc/Sparc.pdf suggests that the 32-bit parts of rs2, after the left shift, is treated as a 64-bit integer. Bits 32 and above are used to do the sat

[Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix, avoid undefined behavior

2015-11-06 Thread Paolo Bonzini
This is reported by Coverity. The algorithm description at ftp://ftp.icm.edu.pl/packages/ggi/doc/hw/sparc/Sparc.pdf suggests that the 32-bit parts of rs2, after the left shift, is treated as a 64-bit integer. Bits 32 and above are used to do the saturating truncation. Use a cast to unsigned in o

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-06 Thread Paolo Bonzini
On 06/11/2015 16:33, Mark Cave-Ayland wrote: >>> >> >>> /* Ugly code */ >>> int64_t scaled = (uint64_t)(int64_t)src << scale; >>> >> >>> >> You mean >>> >> >>> >> int64_t scaled = (int64_t)((uint64_t)src << scale); >> > >> > No, that also looks like a typo. >> > >> > I mean:

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-06 Thread Mark Cave-Ayland
On 05/11/15 09:25, Paolo Bonzini wrote: > On 05/11/2015 10:20, Richard Henderson wrote: >> >>> /* Ugly code */ >>> int64_t scaled = (uint64_t)(int64_t)src << scale; >> >> You mean >> >> int64_t scaled = (int64_t)((uint64_t)src << scale); > > No, that also looks like a typo. > > I mean:

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Paolo Bonzini
On 05/11/2015 10:28, Richard Henderson wrote: > On 11/05/2015 10:25 AM, Paolo Bonzini wrote: >> >> >> On 05/11/2015 10:20, Richard Henderson wrote: >>> /* Ugly code */ int64_t scaled = (uint64_t)(int64_t)src << scale; >>> >>> You mean >>> >>>int64_t scaled = (int64_t)((uin

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Richard Henderson
On 11/05/2015 10:25 AM, Paolo Bonzini wrote: On 05/11/2015 10:20, Richard Henderson wrote: /* Ugly code */ int64_t scaled = (uint64_t)(int64_t)src << scale; You mean int64_t scaled = (int64_t)((uint64_t)src << scale); No, that also looks like a typo. I mean: - unnecessary

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Paolo Bonzini
On 05/11/2015 10:20, Richard Henderson wrote: > >> /* Ugly code */ >> int64_t scaled = (uint64_t)(int64_t)src << scale; > > You mean > > int64_t scaled = (int64_t)((uint64_t)src << scale); No, that also looks like a typo. I mean: - unnecessary cast to int64_t to get the sign exten

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Richard Henderson
On 11/05/2015 10:12 AM, Paolo Bonzini wrote: /* Ugly code */ int64_t scaled = (uint64_t)(int64_t)src << scale; You mean int64_t scaled = (int64_t)((uint64_t)src << scale); r~

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Paolo Bonzini
On 05/11/2015 00:36, Mark Cave-Ayland wrote: > On 04/11/15 11:05, Richard Henderson wrote: > >> On 11/04/2015 11:45 AM, Paolo Bonzini wrote: >int32_t src = rs2 >> (word * 32); > -int64_t scaled = src << scale; > +int64_t scaled = (int64_t)src <

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-05 Thread Paolo Bonzini
On 04/11/2015 18:53, Markus Armbruster wrote: > Paolo Bonzini writes: > >> On 04/11/2015 15:07, Markus Armbruster wrote: >>> Paolo Bonzini writes: >>> On 04/11/2015 12:05, Richard Henderson wrote: > On 11/04/2015 11:45 AM, Paolo Bonzini wrote: int32_t src = rs2

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Mark Cave-Ayland
On 04/11/15 11:05, Richard Henderson wrote: > On 11/04/2015 11:45 AM, Paolo Bonzini wrote: int32_t src = rs2 >> (word * 32); -int64_t scaled = src << scale; +int64_t scaled = (int64_t)src << scale; int64_t from_fixed = scale

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Markus Armbruster
Paolo Bonzini writes: > On 04/11/2015 15:07, Markus Armbruster wrote: >> Paolo Bonzini writes: >> >>> On 04/11/2015 12:05, Richard Henderson wrote: On 11/04/2015 11:45 AM, Paolo Bonzini wrote: >>>int32_t src = rs2 >> (word * 32); >>> -int64_t scaled = sr

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Paolo Bonzini
On 04/11/2015 15:07, Markus Armbruster wrote: > Paolo Bonzini writes: > >> On 04/11/2015 12:05, Richard Henderson wrote: >>> On 11/04/2015 11:45 AM, Paolo Bonzini wrote: >>int32_t src = rs2 >> (word * 32); >> -int64_t scaled = src << scale; >> +

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Markus Armbruster
Paolo Bonzini writes: > On 04/11/2015 12:05, Richard Henderson wrote: >> On 11/04/2015 11:45 AM, Paolo Bonzini wrote: >int32_t src = rs2 >> (word * 32); > -int64_t scaled = src << scale; > +int64_t scaled = (int64_t)src << scale; >

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Paolo Bonzini
On 04/11/2015 12:05, Richard Henderson wrote: > On 11/04/2015 11:45 AM, Paolo Bonzini wrote: int32_t src = rs2 >> (word * 32); -int64_t scaled = src << scale; +int64_t scaled = (int64_t)src << scale; int64_t from_fixed = sc

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Richard Henderson
On 11/04/2015 11:45 AM, Paolo Bonzini wrote: int32_t src = rs2 >> (word * 32); -int64_t scaled = src << scale; +int64_t scaled = (int64_t)src << scale; int64_t from_fixed = scaled >> 16; ... I do think we'd be better served by casting to uint64_t on that l

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Paolo Bonzini
On 04/11/2015 11:12, Richard Henderson wrote: > On 11/02/2015 04:13 PM, Peter Maydell wrote: >> On 2 November 2015 at 14:48, Paolo Bonzini wrote: >>> >>> >>> On 02/11/2015 15:09, Peter Maydell wrote: >> diff --git a/target-sparc/vis_helper.c b/target-sparc/vis_helper.c >> index 383cc8b..

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-04 Thread Richard Henderson
On 11/02/2015 04:13 PM, Peter Maydell wrote: On 2 November 2015 at 14:48, Paolo Bonzini wrote: On 02/11/2015 15:09, Peter Maydell wrote: diff --git a/target-sparc/vis_helper.c b/target-sparc/vis_helper.c index 383cc8b..45fc7db 100644 --- a/target-sparc/vis_helper.c +++ b/target-sparc/vis_hel

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-02 Thread Paolo Bonzini
On 02/11/2015 16:13, Peter Maydell wrote: > On 2 November 2015 at 14:48, Paolo Bonzini wrote: >> >> >> On 02/11/2015 15:09, Peter Maydell wrote: > diff --git a/target-sparc/vis_helper.c b/target-sparc/vis_helper.c > index 383cc8b..45fc7db 100644 > --- a/target-sparc/vis_helper.c

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-02 Thread Peter Maydell
On 2 November 2015 at 14:48, Paolo Bonzini wrote: > > > On 02/11/2015 15:09, Peter Maydell wrote: >>> > diff --git a/target-sparc/vis_helper.c b/target-sparc/vis_helper.c >>> > index 383cc8b..45fc7db 100644 >>> > --- a/target-sparc/vis_helper.c >>> > +++ b/target-sparc/vis_helper.c >>> > @@ -447,7

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-02 Thread Paolo Bonzini
On 02/11/2015 15:09, Peter Maydell wrote: >> > diff --git a/target-sparc/vis_helper.c b/target-sparc/vis_helper.c >> > index 383cc8b..45fc7db 100644 >> > --- a/target-sparc/vis_helper.c >> > +++ b/target-sparc/vis_helper.c >> > @@ -447,7 +447,7 @@ uint32_t helper_fpackfix(uint64_t gsr, uint64_t r

Re: [Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-02 Thread Peter Maydell
On 2 November 2015 at 14:05, Paolo Bonzini wrote: > This is reported by Coverity. The algorithm description at > ftp://ftp.icm.edu.pl/packages/ggi/doc/hw/sparc/Sparc.pdf suggests > that the 32-bit parts of rs2, after the left shift, is treated > as a 64-bit integer. Bits 32 and above are used to

[Qemu-devel] [PATCH] target-sparc: fix 32-bit truncation in fpackfix

2015-11-02 Thread Paolo Bonzini
This is reported by Coverity. The algorithm description at ftp://ftp.icm.edu.pl/packages/ggi/doc/hw/sparc/Sparc.pdf suggests that the 32-bit parts of rs2, after the left shift, is treated as a 64-bit integer. Bits 32 and above are used to do the saturating truncation. Signed-off-by: Paolo Bonzin