qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
@ 2020-12-11 13:13 Philippe Mathieu-Daudé
  2020-12-11 13:28 ` Claudio Fontana
  2020-12-11 13:33 ` Peter Maydell
  0 siblings, 2 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-12-11 13:13 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Philippe Mathieu-Daudé, Peter Maydell

Since commit efc6c07 ("configure: Add a test for the minimum compiler
version"), QEMU explicitely depends on GCC >= 4.8.

(clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
__builtin_expect too)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
[PMD: #error if likely/unlikely already defined]
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
---
 include/qemu/compiler.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index c76281f3540..ae1aee79c8d 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -43,14 +43,11 @@
 #define tostring(s)	#s
 #endif
 
-#ifndef likely
-#if __GNUC__ < 3
-#define __builtin_expect(x, n) (x)
+#if defined(likely) || defined(unlikely)
+#error building with likely/unlikely is not supported
 #endif
-
 #define likely(x)   __builtin_expect(!!(x), 1)
 #define unlikely(x)   __builtin_expect(!!(x), 0)
-#endif
 
 #ifndef container_of
 #define container_of(ptr, type, member) ({                      \
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
  2020-12-11 13:13 [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback Philippe Mathieu-Daudé
@ 2020-12-11 13:28 ` Claudio Fontana
  2020-12-11 13:35   ` Philippe Mathieu-Daudé
  2020-12-11 13:33 ` Peter Maydell
  1 sibling, 1 reply; 6+ messages in thread
From: Claudio Fontana @ 2020-12-11 13:28 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marc-André Lureau, Peter Maydell

On 12/11/20 2:13 PM, Philippe Mathieu-Daudé wrote:
> Since commit efc6c07 ("configure: Add a test for the minimum compiler
> version"), QEMU explicitely depends on GCC >= 4.8.
> 
> (clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
> __builtin_expect too)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> [PMD: #error if likely/unlikely already defined]
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
> ---
>  include/qemu/compiler.h | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index c76281f3540..ae1aee79c8d 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -43,14 +43,11 @@
>  #define tostring(s)	#s
>  #endif
>  
> -#ifndef likely
> -#if __GNUC__ < 3
> -#define __builtin_expect(x, n) (x)
> +#if defined(likely) || defined(unlikely)
> +#error building with likely/unlikely is not supported

I'd put the argument of #error as a single string constant delimited by quotes ",
doesn't matter in this case though as there are no problem characters in the string.

>  #endif
> -
>  #define likely(x)   __builtin_expect(!!(x), 1)
>  #define unlikely(x)   __builtin_expect(!!(x), 0)
> -#endif
>  
>  #ifndef container_of
>  #define container_of(ptr, type, member) ({                      \
> 

Reviewed-by: Claudio Fontana <cfontana@suse.de>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
  2020-12-11 13:13 [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback Philippe Mathieu-Daudé
  2020-12-11 13:28 ` Claudio Fontana
@ 2020-12-11 13:33 ` Peter Maydell
  2020-12-11 13:40   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2020-12-11 13:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Marc-André Lureau, QEMU Developers

On Fri, 11 Dec 2020 at 13:13, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> Since commit efc6c07 ("configure: Add a test for the minimum compiler
> version"), QEMU explicitely depends on GCC >= 4.8.
>
> (clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
> __builtin_expect too)
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> [PMD: #error if likely/unlikely already defined]
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
> ---
>  include/qemu/compiler.h | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index c76281f3540..ae1aee79c8d 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -43,14 +43,11 @@
>  #define tostring(s)    #s
>  #endif
>
> -#ifndef likely
> -#if __GNUC__ < 3
> -#define __builtin_expect(x, n) (x)
> +#if defined(likely) || defined(unlikely)
> +#error building with likely/unlikely is not supported

When exactly will the system headers have 'likely' defined,
and when would they define it to something other than the
obvious __builtin_expect() definition the way we do?

likely() and unlikely() in my view fall into a category of
macros like "container_of()" which aren't defined by a system
header but which do have a standard known set of semantics.

I think there are two reasonable approaches:
 (1) just define the macro, on the assumption that the
system headers won't have done (because these aren't standard
macros)
 (2) as we do with container_of() currently, wrap our
definitions in #ifndef whatever, so that we assume that
whatever version we might have got from the system is fine

I don't think there's any point in explicitly #error-ing here:
in fact, it makes the diagnostic to the user less useful,
because instead of the compiler complaining about the macro
being defined twice and giving both locations where it was
defined, now it won't tell the user where the other definition
was...

I think my preference would be "just drop the ifdef", but
there isn't much in it really.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
  2020-12-11 13:28 ` Claudio Fontana
@ 2020-12-11 13:35   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-12-11 13:35 UTC (permalink / raw)
  To: Claudio Fontana, qemu-devel; +Cc: Marc-André Lureau, Peter Maydell

On 12/11/20 2:28 PM, Claudio Fontana wrote:
> On 12/11/20 2:13 PM, Philippe Mathieu-Daudé wrote:
>> Since commit efc6c07 ("configure: Add a test for the minimum compiler
>> version"), QEMU explicitely depends on GCC >= 4.8.
>>
>> (clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
>> __builtin_expect too)
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> [PMD: #error if likely/unlikely already defined]
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
>> ---
>>  include/qemu/compiler.h | 7 ++-----
>>  1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
>> index c76281f3540..ae1aee79c8d 100644
>> --- a/include/qemu/compiler.h
>> +++ b/include/qemu/compiler.h
>> @@ -43,14 +43,11 @@
>>  #define tostring(s)	#s
>>  #endif
>>  
>> -#ifndef likely
>> -#if __GNUC__ < 3
>> -#define __builtin_expect(x, n) (x)
>> +#if defined(likely) || defined(unlikely)
>> +#error building with likely/unlikely is not supported
> 
> I'd put the argument of #error as a single string constant delimited by quotes ",
> doesn't matter in this case though as there are no problem characters in the string.

This is the style I prefer too, but I this seems the QEMU style...:

$ git grep -E \#\s*error|wc -l
82
$ git grep -E \#\s*error|fgrep \"|wc -l
11

> 
>>  #endif
>> -
>>  #define likely(x)   __builtin_expect(!!(x), 1)
>>  #define unlikely(x)   __builtin_expect(!!(x), 0)
>> -#endif
>>  
>>  #ifndef container_of
>>  #define container_of(ptr, type, member) ({                      \
>>
> 
> Reviewed-by: Claudio Fontana <cfontana@suse.de>
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
  2020-12-11 13:33 ` Peter Maydell
@ 2020-12-11 13:40   ` Philippe Mathieu-Daudé
  2020-12-12 13:51     ` Marc-André Lureau
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-12-11 13:40 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Marc-André Lureau, QEMU Developers

On 12/11/20 2:33 PM, Peter Maydell wrote:
> On Fri, 11 Dec 2020 at 13:13, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>>
>> Since commit efc6c07 ("configure: Add a test for the minimum compiler
>> version"), QEMU explicitely depends on GCC >= 4.8.
>>
>> (clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
>> __builtin_expect too)
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> [PMD: #error if likely/unlikely already defined]
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
>> ---
>>  include/qemu/compiler.h | 7 ++-----
>>  1 file changed, 2 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
>> index c76281f3540..ae1aee79c8d 100644
>> --- a/include/qemu/compiler.h
>> +++ b/include/qemu/compiler.h
>> @@ -43,14 +43,11 @@
>>  #define tostring(s)    #s
>>  #endif
>>
>> -#ifndef likely
>> -#if __GNUC__ < 3
>> -#define __builtin_expect(x, n) (x)
>> +#if defined(likely) || defined(unlikely)
>> +#error building with likely/unlikely is not supported
> 
> When exactly will the system headers have 'likely' defined,
> and when would they define it to something other than the
> obvious __builtin_expect() definition the way we do?

Since there was a check, I tried to be extra-cautious
(better safe than sorry).

> likely() and unlikely() in my view fall into a category of
> macros like "container_of()" which aren't defined by a system
> header but which do have a standard known set of semantics.
> 
> I think there are two reasonable approaches:
>  (1) just define the macro, on the assumption that the
> system headers won't have done (because these aren't standard
> macros)
>  (2) as we do with container_of() currently, wrap our
> definitions in #ifndef whatever, so that we assume that
> whatever version we might have got from the system is fine
> 
> I don't think there's any point in explicitly #error-ing here:
> in fact, it makes the diagnostic to the user less useful,
> because instead of the compiler complaining about the macro
> being defined twice and giving both locations where it was
> defined, now it won't tell the user where the other definition
> was...

"diagnostic less useful" is a good reason (to invalidate this
patch).

> I think my preference would be "just drop the ifdef", but
> there isn't much in it really.

Yes, let's stick to Marc-André v3.

Thanks for your review!

Phil.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback
  2020-12-11 13:40   ` Philippe Mathieu-Daudé
@ 2020-12-12 13:51     ` Marc-André Lureau
  0 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2020-12-12 13:51 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: Peter Maydell, QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 2849 bytes --]

Hi

On Fri, Dec 11, 2020 at 5:41 PM Philippe Mathieu-Daudé <philmd@redhat.com>
wrote:

> On 12/11/20 2:33 PM, Peter Maydell wrote:
> > On Fri, 11 Dec 2020 at 13:13, Philippe Mathieu-Daudé <philmd@redhat.com>
> wrote:
> >>
> >> Since commit efc6c07 ("configure: Add a test for the minimum compiler
> >> version"), QEMU explicitely depends on GCC >= 4.8.
> >>
> >> (clang >= 3.4 advertizes itself as GCC >= 4.2 compatible and supports
> >> __builtin_expect too)
> >>
> >> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> >> [PMD: #error if likely/unlikely already defined]
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >> ---
> >> Supersedes: <20201210134752.780923-4-marcandre.lureau@redhat.com>
> >> ---
> >>  include/qemu/compiler.h | 7 ++-----
> >>  1 file changed, 2 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> >> index c76281f3540..ae1aee79c8d 100644
> >> --- a/include/qemu/compiler.h
> >> +++ b/include/qemu/compiler.h
> >> @@ -43,14 +43,11 @@
> >>  #define tostring(s)    #s
> >>  #endif
> >>
> >> -#ifndef likely
> >> -#if __GNUC__ < 3
> >> -#define __builtin_expect(x, n) (x)
> >> +#if defined(likely) || defined(unlikely)
> >> +#error building with likely/unlikely is not supported
> >
> > When exactly will the system headers have 'likely' defined,
> > and when would they define it to something other than the
> > obvious __builtin_expect() definition the way we do?
>
> Since there was a check, I tried to be extra-cautious
> (better safe than sorry).
>
> > likely() and unlikely() in my view fall into a category of
> > macros like "container_of()" which aren't defined by a system
> > header but which do have a standard known set of semantics.
> >
> > I think there are two reasonable approaches:
> >  (1) just define the macro, on the assumption that the
> > system headers won't have done (because these aren't standard
> > macros)
> >  (2) as we do with container_of() currently, wrap our
> > definitions in #ifndef whatever, so that we assume that
> > whatever version we might have got from the system is fine
> >
> > I don't think there's any point in explicitly #error-ing here:
> > in fact, it makes the diagnostic to the user less useful,
> > because instead of the compiler complaining about the macro
> > being defined twice and giving both locations where it was
> > defined, now it won't tell the user where the other definition
> > was...
>
> "diagnostic less useful" is a good reason (to invalidate this
> patch).
>
> > I think my preference would be "just drop the ifdef", but
> > there isn't much in it really.
>
> Yes, let's stick to Marc-André v3.
>
> Thanks for your review!
>

Ok to r-b v3 then?
thanks



-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 4021 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-12 19:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 13:13 [RFC PATCH v4] compiler.h: remove GCC < 3 __builtin_expect fallback Philippe Mathieu-Daudé
2020-12-11 13:28 ` Claudio Fontana
2020-12-11 13:35   ` Philippe Mathieu-Daudé
2020-12-11 13:33 ` Peter Maydell
2020-12-11 13:40   ` Philippe Mathieu-Daudé
2020-12-12 13:51     ` Marc-André Lureau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).