From b99e54e05a4e9fed3bae1172c874af87e712526b Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Wed, 5 Jan 2022 12:18:03 +0000 Subject: Add signbit support for f16 type Resolves COMPMID-5037 Change-Id: I648e8810dfd86e2ebcc16554f3f4cc58a5fd8c32 Signed-off-by: SiCongLi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6899 Reviewed-by: Giorgio Arena Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- LICENSE | 2 +- support/ToolchainSupport.h | 19 ++++++++++++++++++- tests/validation/Validation.h | 5 +++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 1bb90563e9..953432d89e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2021 Arm Limited +Copyright (c) 2017-2022 Arm Limited Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h index f19a8da627..cddcd542c8 100644 --- a/support/ToolchainSupport.h +++ b/support/ToolchainSupport.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021 Arm Limited. + * Copyright (c) 2017-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -309,6 +309,23 @@ inline bool isfinite(bfloat16 value) { return std::isfinite(float(value)); } + +// std::signbit +template ::value>::type> +inline bool signbit(T value) +{ + return std::signbit(value); +} + +inline bool signbit(half_float::half value) +{ + return half_float::signbit(value); +} + +inline bool signbit(bfloat16 value) +{ + return std::signbit(float(value)); +} } // namespace cpp11 } // namespace support } // namespace arm_compute diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h index 7bad1a2286..289aca4d08 100644 --- a/tests/validation/Validation.h +++ b/tests/validation/Validation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021 Arm Limited. + * Copyright (c) 2017-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -51,7 +51,8 @@ namespace template inline bool are_equal_infs(T val0, T val1) { - return (!support::cpp11::isfinite(val0)) && (!support::cpp11::isfinite(val1)) && (std::signbit(val0) == std::signbit(val1)); + const auto same_sign = support::cpp11::signbit(val0) == support::cpp11::signbit(val1); + return (!support::cpp11::isfinite(val0)) && (!support::cpp11::isfinite(val1)) && same_sign; } } // namespace -- cgit v1.2.1