Skip to content

Commit ecdc4c9

Browse files
committed
Add _Float16 availability check
1 parent 4773707 commit ecdc4c9

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

src/machdep-ml.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ typedef int bool;
8686
#define UNDERSCORE_NAME "false"
8787
#endif
8888

89+
#ifdef HAVE_FLOAT16_DEF
90+
#define HAVE_FLOAT16 "true"
91+
#else
92+
#define HAVE_FLOAT16 "false"
93+
#endif
94+
8995
#endif
9096

9197

@@ -231,6 +237,7 @@ int main(int argc, char **argv)
231237
alignof_float128 = (intptr_t)(&((struct s1*)0)->ld);
232238
}
233239

240+
#ifdef HAVE_FLOAT16_DEF
234241
// The alignment of float16
235242
{
236243
struct s1 {
@@ -239,6 +246,9 @@ int main(int argc, char **argv)
239246
};
240247
alignof_float16 = (intptr_t)(&((struct s1*)0)->ld);
241248
}
249+
#else
250+
alignof_float16 = 0;
251+
#endif
242252

243253
// The alignment of a float complex
244254
{
@@ -276,14 +286,18 @@ int main(int argc, char **argv)
276286
alignof_float128complex = (intptr_t)(&((struct s1*)0)->ld);
277287
}
278288

279-
// The alignment of float128 complex
289+
#ifdef HAVE_FLOAT16_DEF
290+
// The alignment of float16 complex
280291
{
281292
struct s1 {
282293
char c;
283294
_Float16 _Complex ld;
284295
};
285296
alignof_float16complex = (intptr_t)(&((struct s1*)0)->ld);
286297
}
298+
#else
299+
alignof_float16complex = 0;
300+
#endif
287301

288302

289303
alignof_str = __alignof("a string");
@@ -326,7 +340,7 @@ int main(int argc, char **argv)
326340
"bool=%d,%d fun=%d,%d alignof_string=%d max_alignment=%d size_t=%s "
327341
"wchar_t=%s char16_t=%s char32_t=%s char_signed=%s "
328342
"big_endian=%s __thread_is_keyword=%s __builtin_va_list=%s "
329-
"underscore_name=%s\n",
343+
"underscore_name=%s have_float16=%s\n",
330344
(int)sizeof(short), alignof_short, (int)sizeof(int), alignof_int,
331345
(int)sizeof(long), alignof_long, (int)sizeof(long long), alignof_longlong,
332346
(int)sizeof(int *), alignof_ptr,
@@ -340,18 +354,26 @@ int main(int argc, char **argv)
340354
(int)sizeof(float), alignof_float, (int)sizeof(double), alignof_double,
341355
(int)sizeof(long double), alignof_longdouble,
342356
(int)sizeof(_Float128), alignof_float128,
357+
#ifdef HAVE_FLOAT16_DEF
343358
(int)sizeof(_Float16), alignof_float16,
359+
#else
360+
0, 0,
361+
#endif
344362
(int)sizeof(float _Complex), alignof_floatcomplex, (int)sizeof(double _Complex), alignof_doublecomplex,
345363
(int)sizeof(long double _Complex), alignof_longdoublecomplex,
346364
(int)sizeof(_Float128 _Complex), alignof_float128complex,
365+
#ifdef HAVE_FLOAT16_DEF
347366
(int)sizeof(_Float16 _Complex), alignof_float16complex,
367+
#else
368+
0, 0,
369+
#endif
348370
(int)sizeof(void),
349371
(int)sizeof(bool), alignof_bool,
350372
sizeof_fun, alignof_fun, alignof_str, alignof_aligned,
351373
underscore(TYPE_SIZE_T), underscore(TYPE_WCHAR_T), underscore(TYPE_CHAR16_T), underscore(TYPE_CHAR32_T),
352374
char_is_unsigned ? "false" : "true",
353375
little_endian ? "false" : "true",
354-
THREAD_IS_KEYWORD, HAVE_BUILTIN_VA_LIST, UNDERSCORE_NAME);
376+
THREAD_IS_KEYWORD, HAVE_BUILTIN_VA_LIST, UNDERSCORE_NAME, HAVE_FLOAT16);
355377
}
356378
else
357379
{
@@ -379,12 +401,20 @@ int main(int argc, char **argv)
379401
printf("\t sizeof_double = %d;\n", (int)sizeof(double));
380402
printf("\t sizeof_longdouble = %d;\n", (int)sizeof(long double));
381403
printf("\t sizeof_float128 = %d;\n", (int)sizeof(_Float128));
404+
#ifdef HAVE_FLOAT16_DEF
382405
printf("\t sizeof_float16 = %d;\n", (int)sizeof(_Float16));
406+
#else
407+
printf("\t sizeof_float16 = %d;\n", 0);
408+
#endif
383409
printf("\t sizeof_floatcomplex = %d;\n", (int)sizeof(float _Complex));
384410
printf("\t sizeof_doublecomplex = %d;\n", (int)sizeof(double _Complex));
385411
printf("\t sizeof_longdoublecomplex = %d;\n", (int)sizeof(long double _Complex));
386412
printf("\t sizeof_float128complex = %d;\n", (int)sizeof(_Float128 _Complex));
413+
#ifdef HAVE_FLOAT16_DEF
387414
printf("\t sizeof_float16complex = %d;\n", (int)sizeof(_Float16 _Complex));
415+
#else
416+
printf("\t sizeof_float16complex = %d;\n", 0);
417+
#endif
388418
printf("\t sizeof_void = %d;\n", (int)sizeof(void));
389419
printf("\t sizeof_fun = %d;\n", (int)sizeof_fun);
390420
printf("\t size_t = \"%s\";\n", TYPE_SIZE_T);
@@ -408,12 +438,20 @@ int main(int argc, char **argv)
408438
printf("\t alignof_double = %d;\n", alignof_double);
409439
printf("\t alignof_longdouble = %d;\n", alignof_longdouble);
410440
printf("\t alignof_float128 = %d;\n", alignof_float128);
441+
#ifdef HAVE_FLOAT16_DEF
411442
printf("\t alignof_float16 = %d;\n", alignof_float16);
443+
#else
444+
printf("\t alignof_float16 = %d;\n", 0);
445+
#endif
412446
printf("\t alignof_floatcomplex = %d;\n", alignof_floatcomplex);
413447
printf("\t alignof_doublecomplex = %d;\n", alignof_doublecomplex);
414448
printf("\t alignof_longdoublecomplex = %d;\n", alignof_longdoublecomplex);
415449
printf("\t alignof_float128complex = %d;\n", alignof_float128complex);
450+
#ifdef HAVE_FLOAT16_DEF
416451
printf("\t alignof_float16complex = %d;\n", alignof_float16complex);
452+
#else
453+
printf("\t alignof_float16complex = %d;\n", alignof_float16complex);
454+
#endif
417455
printf("\t alignof_str = %d;\n", alignof_str);
418456
printf("\t alignof_fun = %d;\n", alignof_fun);
419457
printf("\t alignof_aligned = %d;\n", alignof_aligned);
@@ -422,6 +460,7 @@ int main(int argc, char **argv)
422460
printf("\t __builtin_va_list = %s;\n", HAVE_BUILTIN_VA_LIST);
423461
printf("\t __thread_is_keyword = %s;\n", THREAD_IS_KEYWORD);
424462
printf("\t little_endian = %s;\n", little_endian ? "true" : "false");
463+
printf("\t have_float16 = %s;\n", HAVE_FLOAT16);
425464
}
426465
return 0;
427466
}

src/machdep.cppo.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type mach = {
5454
little_endian: bool; (* whether the machine is little endian *)
5555
__thread_is_keyword: bool; (* whether __thread is a keyword *)
5656
__builtin_va_list: bool; (* whether __builtin_va_list is builtin (gccism) *)
57+
have_float16: bool; (* Whether _Float16 is supported. *)
5758
}
5859

5960
let gcc = {

src/machdepConfigure.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ let underscore_name_code = {|
2828
int main() { __asm__("jmp _main"); }
2929
|}
3030

31+
let have_float16_code = {|
32+
_Float16 x;
33+
int main() { return 0; }
34+
|}
35+
3136
let cil_check_integer_type_type_code t1 t2 =
3237
Format.sprintf {|
3338
#include <stddef.h>
@@ -77,6 +82,7 @@ let () =
7782
let have_builtin_va_list = C.c_test c builtin_va_list_code in
7883
let thread_is_keyword = not @@ C.c_test c thread_is_keyword_code in
7984
let underscore_name = C.c_test c underscore_name_code in
85+
let have_float16 = C.c_test c have_float16_code in
8086

8187
C.C_define.gen_header_file c ~fname:"machdep-config.h" [
8288
("HAVE_STDLIB_H", Switch (has_header c "stdlib.h"));
@@ -88,6 +94,7 @@ let () =
8894
("HAVE_BUILTIN_VA_LIST_DEF", Switch have_builtin_va_list);
8995
("THREAD_IS_KEYWORD_DEF", Switch thread_is_keyword);
9096
("UNDERSCORE_NAME_DEF", Switch underscore_name);
97+
("HAVE_FLOAT16_DEF", Switch have_float16);
9198

9299
("TYPE_SIZE_T", String (cil_check_integer_type c "size_t"));
93100
("TYPE_WCHAR_T", String (cil_check_integer_type c "wchar_t"));

src/machdepenv.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ let modelParse (s:string) : mach =
106106
little_endian = not (getBool entries "big_endian");
107107
__thread_is_keyword = getBool entries "__thread_is_keyword";
108108
__builtin_va_list = getBool entries "__builtin_va_list";
109+
have_float16 = getBool entries "have_float16";
109110
}

0 commit comments

Comments
 (0)