[Mesa-dev] [PATCH 2/3] mesa: move _mesa_half_is_negative() to half_float.h

Roland Scheidegger sroland at vmware.com
Mon Oct 9 23:08:52 UTC 2017


Am 09.10.2017 um 23:33 schrieb Brian Paul:
> On 10/09/2017 03:24 PM, Ilia Mirkin wrote:
>> On Mon, Oct 9, 2017 at 5:07 PM, Roland Scheidegger
>> <sroland at vmware.com> wrote:
>>> Am 09.10.2017 um 22:56 schrieb Brian Paul:
>>>> ---
>>>>   src/mesa/main/imports.h | 6 ------
>>>>   src/util/half_float.h   | 8 ++++++++
>>>>   2 files changed, 8 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
>>>> index a4964a3..51fa72c 100644
>>>> --- a/src/mesa/main/imports.h
>>>> +++ b/src/mesa/main/imports.h
>>>> @@ -333,12 +333,6 @@ _mesa_bitcount_64(uint64_t n);
>>>>   #endif
>>>>
>>>>
>>>> -static inline bool
>>>> -_mesa_half_is_negative(GLhalfARB h)
>>>> -{
>>>> -   return h & 0x8000;
>>>> -}
>>>> -
>>>>   extern int
>>>>   _mesa_snprintf( char *str, size_t size, const char *fmt, ... )
>>>> PRINTFLIKE(3, 4);
>>>>
>>>> diff --git a/src/util/half_float.h b/src/util/half_float.h
>>>> index 64f2042..35f27c8 100644
>>>> --- a/src/util/half_float.h
>>>> +++ b/src/util/half_float.h
>>>> @@ -25,6 +25,7 @@
>>>>   #ifndef _HALF_FLOAT_H_
>>>>   #define _HALF_FLOAT_H_
>>>>
>>>> +#include <stdbool.h>
>>>>   #include <stdint.h>
>>>>
>>>>   #ifdef __cplusplus
>>>> @@ -34,6 +35,13 @@ extern "C" {
>>>>   uint16_t _mesa_float_to_half(float val);
>>>>   float _mesa_half_to_float(uint16_t val);
>>>>
>>>> +static inline bool
>>>> +_mesa_half_is_negative(uint16_t h)
>>>> +{
>>>> +   return h & 0x8000;
>>>> +}
>>> Not that this is a new issue, but isn't this pretty problematic and
>>> should
>>> rather be return !!(h & 0x8000) or something like that?
>>
>> That should be implied by the C99 _Bool return type (hopefully bool is
>> typecast to that and not something horrible like char).
> 
> Hmm, yeah, with gcc -O3 at least, the same asm code is generated
> with/without !!(h & 0x8000).
> 

Ah yes I wasn't thinking about c99 _Bool but pre-c99 fake bool types
(where things like that tended to be problematic). So implicit
conversion should be just fine (albeit imho explicit "conversion" can't
hurt).

Reviewed-by: Roland Scheidegger <sroland at vmware.com>




More information about the mesa-dev mailing list