Skip to content

Add support for __fp16 where appropriate #8323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ansi-c/ansi_c_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ bool ansi_c_languaget::parse(
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
ansi_c_parser.float16_type = config.ansi_c.float16_type;
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;
ansi_c_parser.cpp98=false; // it's not C++
ansi_c_parser.cpp11=false; // it's not C++
ansi_c_parser.mode=config.ansi_c.mode;
Expand Down Expand Up @@ -202,6 +203,7 @@ bool ansi_c_languaget::to_expr(
ansi_c_parser.ts_18661_3_Floatn_types=config.ansi_c.ts_18661_3_Floatn_types;
ansi_c_parser.float16_type = config.ansi_c.float16_type;
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;
ansi_c_parser.cpp98 = false; // it's not C++
ansi_c_parser.cpp11 = false; // it's not C++
ansi_c_parser.mode = config.ansi_c.mode;
Expand Down
4 changes: 3 additions & 1 deletion src/ansi-c/ansi_c_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class ansi_c_parsert:public parsert
for_has_scope(false),
ts_18661_3_Floatn_types(false),
float16_type(false),
bf16_type(false)
bf16_type(false),
fp16_type(false)
{
// set up global scope
scopes.clear();
Expand Down Expand Up @@ -69,6 +70,7 @@ class ansi_c_parsert:public parsert
bool ts_18661_3_Floatn_types;
bool float16_type;
bool bf16_type;
bool fp16_type;

typedef ansi_c_identifiert identifiert;
typedef ansi_c_scopet scopet;
Expand Down
1 change: 1 addition & 0 deletions src/ansi-c/builtin_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static bool convert(
ansi_c_parser.ts_18661_3_Floatn_types = config.ansi_c.ts_18661_3_Floatn_types;
ansi_c_parser.float16_type = config.ansi_c.float16_type;
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;
ansi_c_parser.cpp98=false; // it's not C++
ansi_c_parser.cpp11=false; // it's not C++
ansi_c_parser.mode=config.ansi_c.mode;
Expand Down
7 changes: 7 additions & 0 deletions src/ansi-c/gcc_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,11 @@ void configure_gcc(const gcc_versiont &gcc_version)
gcc_version.is_at_least(13u)) ||
(gcc_version.flavor == gcc_versiont::flavort::CLANG &&
gcc_version.is_at_least(15u));

config.ansi_c.fp16_type =
(gcc_version.flavor == gcc_versiont::flavort::GCC &&
gcc_version.is_at_least(4u, 5u) &&
(config.ansi_c.arch == "arm" || config.ansi_c.arch == "arm64")) ||
(gcc_version.flavor == gcc_versiont::flavort::CLANG &&
gcc_version.is_at_least(6u));
}
6 changes: 6 additions & 0 deletions src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ enable_or_disable ("enable"|"disable")
return make_identifier();
}

"__fp16" { if(PARSER.fp16_type)
{ loc(); return TOK_GCC_FLOAT16; }
else
return make_identifier();
}

"_Float32" { if(PARSER.ts_18661_3_Floatn_types)
{ loc(); return TOK_GCC_FLOAT32; }
else
Expand Down
1 change: 1 addition & 0 deletions src/cpp/cpp_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool cpp_parsert::parse()
false; // these are still typedefs
token_buffer.ansi_c_parser.float16_type = *support_float16;
token_buffer.ansi_c_parser.bf16_type = *support_float16;
token_buffer.ansi_c_parser.fp16_type = *support_float16;
token_buffer.ansi_c_parser.in = in;
token_buffer.ansi_c_parser.mode = mode;
token_buffer.ansi_c_parser.set_file(get_file());
Expand Down
1 change: 1 addition & 0 deletions src/goto-instrument/contracts/contracts_wrangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void contracts_wranglert::mangle(
ansi_c_parser.ts_18661_3_Floatn_types = config.ansi_c.ts_18661_3_Floatn_types;
ansi_c_parser.float16_type = config.ansi_c.float16_type;
ansi_c_parser.bf16_type = config.ansi_c.bf16_type;
ansi_c_parser.fp16_type = config.ansi_c.fp16_type;
ansi_c_parser.cpp98 = false; // it's not C++
ansi_c_parser.cpp11 = false; // it's not C++
ansi_c_parser.mode = config.ansi_c.mode;
Expand Down
5 changes: 3 additions & 2 deletions src/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ bool configt::set(const cmdlinet &cmdline)
ansi_c.ts_18661_3_Floatn_types=false;
ansi_c.float16_type = false;
ansi_c.bf16_type = false;
ansi_c.fp16_type = false;
ansi_c.c_standard=ansi_ct::default_c_standard();
ansi_c.endianness=ansi_ct::endiannesst::NO_ENDIANNESS;
ansi_c.os=ansi_ct::ost::NO_OS;
Expand Down Expand Up @@ -1328,8 +1329,8 @@ void configt::set_from_symbol_table(const symbol_table_baset &symbol_table)
ansi_c.char_is_unsigned=unsigned_from_ns(ns, "char_is_unsigned")!=0;
ansi_c.wchar_t_is_unsigned=unsigned_from_ns(ns, "wchar_t_is_unsigned")!=0;
// for_has_scope, single_precision_constant, rounding_mode,
// ts_18661_3_Floatn_types, float16_type, bf16_type are not architectural
// features, and thus not stored in namespace
// ts_18661_3_Floatn_types, float16_type, bf16_type, fp16_type are not
// architectural features, and thus not stored in namespace

ansi_c.alignment=unsigned_from_ns(ns, "alignment");

Expand Down
1 change: 1 addition & 0 deletions src/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class configt
bool gcc__float128_type; // __float128, a gcc extension since 4.3/4.5
bool float16_type; // _Float16 (Clang >= 15, GCC >= 12)
bool bf16_type; // __bf16 (Clang >= 15, GCC >= 13)
bool fp16_type; // __fp16 (GCC >= 4.5 on ARM, Clang >= 6)
bool single_precision_constant;
enum class c_standardt
{
Expand Down
1 change: 1 addition & 0 deletions unit/cpp_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int main(int argc, const char *argv[])
ansi_c_parser.ts_18661_3_Floatn_types = false;
ansi_c_parser.float16_type = false;
ansi_c_parser.bf16_type = false;
ansi_c_parser.fp16_type = false;
ansi_c_parser.in=∈
cpp_parser.in=∈

Expand Down
Loading