iio: tools: Use proper macro to detect _Float16 support
PATCH 1/1 iio: tools: Use proper macro to detect _Float16 support
__FLT16_MAX__ is an internal compiler macro. GCC defines it if _Float16 is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'
141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale);
| ^~~~~~To fix that, use the public macro without double underscores.
--- tools/iio/iio_generic_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/iio/iio_generic_buffer.c +1 -1
@@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)printf ("%05f " , ((float )input + info->offset) * info->scale);break ;case 'f' : { -#if defined(__FLT16_MAX__) +#if defined(FLT16_MAX) union { uint16_t u; _Float16 f;
Signature · 1 line
2.50.1
Quoted 23 lines · On Fri, 18 Sep 2026 20:13:02 +0400 "Ivan A. Melnikov" <[email protected]> wrote:
__FLT16_MAX__is an internal compiler macro. GCC defines it if_Float16is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale); | ^~~~~~To fix that, use the public macro without double underscores.
Fixes cdd445d4b2a9 ("iio: tools: Add support for floating-point types in buffer scan elements")Signed-off-by Ivan A. Melnikov <[email protected]>--- tools/iio/iio_generic_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/iio/iio_generic_buffer.c +0
-0
tools/iio/iio_generic_buffer.c static void print2byte(uint16_t input, struct iio_channel_info *info) · line 137
Quoted 8 lines
tools/iio/iio_generic_buffer.c +1
-1@@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)printf ("%05f " , ((float )input + info->offset) * info->scale);break ;case 'f' : { -#if defined(__FLT16_MAX__) +#if defined(FLT16_MAX) union { uint16_t u; _Float16 f;
One Sashiko issue:
Does this unintentionally disable _Float16 support for all architectures?
Since the tools build environment uses gnu11 compilation flags without explicitly defining __STDC_WANT_IEC_60559_TYPES_EXT__, FLT16_MAX is undefined across all architectures. This causes the preprocessor to skip this block entirely, causing the tool to always print <unsupported 2-byte float> for 16-bit float data, even on platforms where native support previously worked.
If FLT16_MAX were actually defined, the compiler would still parse the _Float16 block and throw the same missing -msse2 compilation error mentioned in the commit message. Is there an alternative way to check for hardware support without completely disabling the feature?
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 37 lines · Joshua Crofts
Quoted 23 lines · On Fri, 18 Sep 2026 20:13:02 +0400 "Ivan A. Melnikov" <[email protected]> wrote:
__FLT16_MAX__is an internal compiler macro. GCC defines it if_Float16is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale); | ^~~~~~To fix that, use the public macro without double underscores.
Fixes cdd445d4b2a9 ("iio: tools: Add support for floating-point types in buffer scan elements")Signed-off-by Ivan A. Melnikov <[email protected]>--- tools/iio/iio_generic_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/iio/iio_generic_buffer.c +0
-0tools/iio/iio_generic_buffer.c static void print2byte(uint16_t input, struct iio_channel_info *info) · line 137
Quoted 8 lines
tools/iio/iio_generic_buffer.c +1
-1@@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)printf ("%05f " , ((float )input + info->offset) * info->scale);break ;case 'f' : { -#if defined(__FLT16_MAX__) +#if defined(FLT16_MAX) union { uint16_t u; _Float16 f;One Sashiko issue:
Quoted 1 line
Does this unintentionally disable
_Float16support for all architectures?
Indeed, it does. Sorry, my patch is incorrect. I must have completely messed up all my checks on Friday.
Quoted 11 lines
Since the tools build environment uses gnu11 compilation flags without explicitly defining
__STDC_WANT_IEC_60559_TYPES_EXT__,FLT16_MAXis undefined across all architectures. This causes the preprocessor to skip this block entirely, causing the tool to always print <unsupported 2-byte float> for 16-bit float data, even on platforms where native support previously worked.If
FLT16_MAXwere actually defined, the compiler would still parse the_Float16block and throw the same missing -msse2 compilation error mentioned in the commit message. Is there an alternative way to check for hardware support without completely disabling the feature?
Apparently, the only correct way to detect _Float16 is to try compiling some code that uses it. For that, a feature can be added to tools/build.
On other hand, x86 without SSE2 is the only platform I could find where __FLT16_MAX__ is defined, but _Float16 does not work, so a simple platform-specific workaround would also work and would be much less elaborate.
WDYT?
Signature · 2 lines
wbr,
iv m.Jonathan Cameron
maintainerQuoted 58 lines · On Mon, 21 Sep 2026 15:33:55 +0400 "Ivan A. Melnikov" <[email protected]> wrote:
Quoted 37 lines · Joshua Crofts
Quoted 23 lines · On Fri, 18 Sep 2026 20:13:02 +0400 "Ivan A. Melnikov" <[email protected]> wrote:
__FLT16_MAX__is an internal compiler macro. GCC defines it if_Float16is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale); | ^~~~~~To fix that, use the public macro without double underscores.
Fixes cdd445d4b2a9 ("iio: tools: Add support for floating-point types in buffer scan elements")Signed-off-by Ivan A. Melnikov <[email protected]>--- tools/iio/iio_generic_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/iio/iio_generic_buffer.c +0
-0tools/iio/iio_generic_buffer.c static void print2byte(uint16_t input, struct iio_channel_info *info) · line 137
Quoted 8 lines
tools/iio/iio_generic_buffer.c +1
-1@@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)printf ("%05f " , ((float )input + info->offset) * info->scale);break ;case 'f' : { -#if defined(__FLT16_MAX__) +#if defined(FLT16_MAX) union { uint16_t u; _Float16 f;One Sashiko issue:
Quoted 1 line
Does this unintentionally disable
_Float16support for all architectures?Indeed, it does. Sorry, my patch is incorrect. I must have completely messed up all my checks on Friday.
Quoted 11 lines
Since the tools build environment uses gnu11 compilation flags without explicitly defining
__STDC_WANT_IEC_60559_TYPES_EXT__,FLT16_MAXis undefined across all architectures. This causes the preprocessor to skip this block entirely, causing the tool to always print <unsupported 2-byte float> for 16-bit float data, even on platforms where native support previously worked.If
FLT16_MAXwere actually defined, the compiler would still parse the_Float16block and throw the same missing -msse2 compilation error mentioned in the commit message. Is there an alternative way to check for hardware support without completely disabling the feature?Apparently, the only correct way to detect
_Float16is to try compiling some code that uses it. For that, a feature can be added totools/build.
Quoted 6 lines
On other hand, x86 without SSE2 is the only platform I could find where
__FLT16_MAX__is defined, but_Float16does not work, so a simple platform-specific workaround would also work and would be much less elaborate.WDYT?
I would do it properly. Avoids problems with what is defined for architectures changing in the future.
Thanks,
Jonathan
Quoted 1 line
Quoted 11 lines · Ivan A. Melnikov
__FLT16_MAX__is an internal compiler macro. GCC defines it if_Float16is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale); | ^~~~~~To fix that, use the public macro without double underscores.
What about clang?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · On Fri, 18 Sep 2026 20:13:02 +0400 "Ivan A. Melnikov" <[email protected]> wrote:
__FLT16_MAX__is an internal compiler macro. GCC defines it if_Float16is supported by the target in general, but the support may depend on the exact target options. For example, on i586 without -msse2 I get the following error from GCC15:
iio_generic_buffer.c: In function 'print2byte':
iio_generic_buffer.c:141:17: error: invalid conversion from type '_Float16' without option '-msse2'141 | printf("%05f ", ((float)converter.f + info->offset) * info->scale); | ^~~~~~To fix that, use the public macro without double underscores.
Assuming float and _Float16 are both IEEE 754 you can directly convert them. If I've typed it correctly:
union {
uint32_t u;
float f;
} converter;
converter.u = (input & 0x8000) << 16 | (input & 0x7fff) << 13;
printf(... converter.f * 0x1p112 ...)That handles denormalised values (near zero) but not infinity and NaN.
David
Quoted 20 lines
Fixes cdd445d4b2a9 ("iio: tools: Add support for floating-point types in buffer scan elements")Signed-off-by Ivan A. Melnikov <[email protected]>--- tools/iio/iio_generic_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/iio/iio_generic_buffer.c +1
-1@@ -131,7 +131,7 @@ static void print2byte(uint16_t input, struct iio_channel_info *info)printf ("%05f " , ((float )input + info->offset) * info->scale);break ;case 'f' : { -#if defined(__FLT16_MAX__) +#if defined(FLT16_MAX) union { uint16_t u; _Float16 f;