diff mbox series

[6/8] qemu/bswap: Add const_le64()

Message ID 20230111142440.24771-7-Jonathan.Cameron@huawei.com
State Superseded
Headers show
Series hw/cxl: CXL emulation cleanups and minor fixes for upstream | expand

Commit Message

Jonathan Cameron Jan. 11, 2023, 2:24 p.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

Gcc requires constant versions of cpu_to_le* calls.

Add a 64 bit version.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 include/qemu/bswap.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Philippe Mathieu-Daudé Jan. 11, 2023, 3:49 p.m. UTC | #1
On 11/1/23 15:24, Jonathan Cameron via wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> Gcc requires constant versions of cpu_to_le* calls.
> 
> Add a 64 bit version.
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>   include/qemu/bswap.h | 10 ++++++++++
>   1 file changed, 10 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Philippe Mathieu-Daudé Jan. 11, 2023, 4:07 p.m. UTC | #2
On 11/1/23 16:49, Philippe Mathieu-Daudé wrote:
> On 11/1/23 15:24, Jonathan Cameron via wrote:
>> From: Ira Weiny <ira.weiny@intel.com>
>>
>> Gcc requires constant versions of cpu_to_le* calls.
>>
>> Add a 64 bit version.
>>
>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>> ---
>>   include/qemu/bswap.h | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Actually I thought this was already merged but apparently
this never got in:
https://lore.kernel.org/qemu-devel/20200928131934.739451-1-philmd@redhat.com/
Philippe Mathieu-Daudé Jan. 11, 2023, 4:33 p.m. UTC | #3
On 11/1/23 17:07, Philippe Mathieu-Daudé wrote:
> On 11/1/23 16:49, Philippe Mathieu-Daudé wrote:
>> On 11/1/23 15:24, Jonathan Cameron via wrote:
>>> From: Ira Weiny <ira.weiny@intel.com>
>>>
>>> Gcc requires constant versions of cpu_to_le* calls.
>>>
>>> Add a 64 bit version.
>>>
>>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>>> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
>>> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>>> ---
>>>   include/qemu/bswap.h | 10 ++++++++++
>>>   1 file changed, 10 insertions(+)
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> Actually I thought this was already merged but apparently
> this never got in:
> https://lore.kernel.org/qemu-devel/20200928131934.739451-1-philmd@redhat.com/

Oops unrelated, I meant:
https://lore.kernel.org/qemu-devel/20200917163106.49351-1-philmd@redhat.com/

But thank for the reminder, good opportunity to respin the
other one ;)
Philippe Mathieu-Daudé Jan. 11, 2023, 4:40 p.m. UTC | #4
On 11/1/23 15:24, Jonathan Cameron via wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> Gcc requires constant versions of cpu_to_le* calls.
> 
> Add a 64 bit version.
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>   include/qemu/bswap.h | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
> index 346d05f2aa..e1eca22f25 100644
> --- a/include/qemu/bswap.h
> +++ b/include/qemu/bswap.h
> @@ -187,6 +187,15 @@ CPU_CONVERT(le, 64, uint64_t)
>    * used to initialize static variables.
>    */
>   #if HOST_BIG_ENDIAN
> +# define const_le64(_x)                          \
> +    ((((_x) & 0x00000000000000ffU) << 56) |      \
> +     (((_x) & 0x000000000000ff00U) << 40) |      \
> +     (((_x) & 0x0000000000ff0000U) << 24) |      \
> +     (((_x) & 0x00000000ff000000U) <<  8) |      \
> +     (((_x) & 0x000000ff00000000U) >>  8) |      \
> +     (((_x) & 0x0000ff0000000000U) >> 24) |      \
> +     (((_x) & 0x00ff000000000000U) >> 40) |      \
> +     (((_x) & 0xff00000000000000U) >> 56))

So looking back at 
https://lore.kernel.org/qemu-devel/20200917163106.49351-4-philmd@redhat.com/
this patch missed to update the function description:

  /*
- * Same as cpu_to_{be,le}{16,32} described below, except that gcc will
+ * Same as cpu_to_{be,le}{16,32,64} described below, except that gcc will
   * figure the result is a compile-time constant if you pass in a constant.
   * So this can be used to initialize static variables.
   */
Jonathan Cameron Jan. 11, 2023, 4:59 p.m. UTC | #5
On Wed, 11 Jan 2023 17:40:46 +0100
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> On 11/1/23 15:24, Jonathan Cameron via wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > Gcc requires constant versions of cpu_to_le* calls.
> > 
> > Add a 64 bit version.
> > 
> > Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---
> >   include/qemu/bswap.h | 10 ++++++++++
> >   1 file changed, 10 insertions(+)
> > 
> > diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
> > index 346d05f2aa..e1eca22f25 100644
> > --- a/include/qemu/bswap.h
> > +++ b/include/qemu/bswap.h
> > @@ -187,6 +187,15 @@ CPU_CONVERT(le, 64, uint64_t)
> >    * used to initialize static variables.
> >    */
> >   #if HOST_BIG_ENDIAN
> > +# define const_le64(_x)                          \
> > +    ((((_x) & 0x00000000000000ffU) << 56) |      \
> > +     (((_x) & 0x000000000000ff00U) << 40) |      \
> > +     (((_x) & 0x0000000000ff0000U) << 24) |      \
> > +     (((_x) & 0x00000000ff000000U) <<  8) |      \
> > +     (((_x) & 0x000000ff00000000U) >>  8) |      \
> > +     (((_x) & 0x0000ff0000000000U) >> 24) |      \
> > +     (((_x) & 0x00ff000000000000U) >> 40) |      \
> > +     (((_x) & 0xff00000000000000U) >> 56))  
> 
> So looking back at 
> https://lore.kernel.org/qemu-devel/20200917163106.49351-4-philmd@redhat.com/
> this patch missed to update the function description:
> 
>   /*
> - * Same as cpu_to_{be,le}{16,32} described below, except that gcc will
> + * Same as cpu_to_{be,le}{16,32,64} described below, except that gcc will
>    * figure the result is a compile-time constant if you pass in a constant.
>    * So this can be used to initialize static variables.
>    */

Good point.  The context is a little difference as your series had combined
several comments into one, but I've put in a similar update.

Obviously if your series lands first we can drop this one, but I'll carry
it forwards for now.

Thanks,

Jonathan

> 
>
diff mbox series

Patch

diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 346d05f2aa..e1eca22f25 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -187,6 +187,15 @@  CPU_CONVERT(le, 64, uint64_t)
  * used to initialize static variables.
  */
 #if HOST_BIG_ENDIAN
+# define const_le64(_x)                          \
+    ((((_x) & 0x00000000000000ffU) << 56) |      \
+     (((_x) & 0x000000000000ff00U) << 40) |      \
+     (((_x) & 0x0000000000ff0000U) << 24) |      \
+     (((_x) & 0x00000000ff000000U) <<  8) |      \
+     (((_x) & 0x000000ff00000000U) >>  8) |      \
+     (((_x) & 0x0000ff0000000000U) >> 24) |      \
+     (((_x) & 0x00ff000000000000U) >> 40) |      \
+     (((_x) & 0xff00000000000000U) >> 56))
 # define const_le32(_x)                          \
     ((((_x) & 0x000000ffU) << 24) |              \
      (((_x) & 0x0000ff00U) <<  8) |              \
@@ -196,6 +205,7 @@  CPU_CONVERT(le, 64, uint64_t)
     ((((_x) & 0x00ff) << 8) |                    \
      (((_x) & 0xff00) >> 8))
 #else
+# define const_le64(_x) (_x)
 # define const_le32(_x) (_x)
 # define const_le16(_x) (_x)
 #endif