Commit 9bc18287 authored by Umang Yadav's avatar Umang Yadav
Browse files

cppcheck fixes

parent df7f8a35
...@@ -22,12 +22,8 @@ ...@@ -22,12 +22,8 @@
#ifndef MIGRAPHX_FP8_IMPL_HPP #ifndef MIGRAPHX_FP8_IMPL_HPP
#define MIGRAPHX_FP8_IMPL_HPP #define MIGRAPHX_FP8_IMPL_HPP
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-identifier"
#endif
#define CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x)) #define MIGRAPHX_CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
namespace migraphx_f8_impl { namespace migraphx_f8_impl {
namespace detail { namespace detail {
template <bool B, class T, class F> template <bool B, class T, class F>
...@@ -47,11 +43,10 @@ inline constexpr To bit_cast(From fr) noexcept ...@@ -47,11 +43,10 @@ inline constexpr To bit_cast(From fr) noexcept
{ {
static_assert(sizeof(To) == sizeof(From)); static_assert(sizeof(To) == sizeof(From));
#if defined(__GNUC__) and !defined(__clang__) #if defined(__GNUC__) and !defined(__clang__)
To x = CONST_FOLD(*reinterpret_cast<To*>(&fr)); return MIGRAPHX_CONST_FOLD(*reinterpret_cast<To*>(&fr));
#else #else
To x = __builtin_bit_cast(To, fr); return __builtin_bit_cast(To, fr);
#endif #endif
return x;
} }
} // namespace detail } // namespace detail
...@@ -102,7 +97,6 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng) ...@@ -102,7 +97,6 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng)
} }
else else
{ {
// if(__hisinf(x) || __hisnan(x))
if((x & 0x7C00) == 0x7C00) if((x & 0x7C00) == 0x7C00)
return 0x80; return 0x80;
} }
...@@ -112,12 +106,12 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng) ...@@ -112,12 +106,12 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng)
if(sizeof(T) == 4) if(sizeof(T) == 4)
{ {
if((x & 0x7F800000) == 0x7F800000) if((x & 0x7F800000) == 0x7F800000)
return signed_inf + (mantissa != 0 ? 1 : 0); return signed_inf + (mantissa != 0 ? 1 : 0); // cppcheck-suppress InvertedLogic
} }
else else
{ {
if((x & 0x7C00) == 0x7C00) if((x & 0x7C00) == 0x7C00)
return signed_inf + (mantissa != 0 ? 1 : 0); return signed_inf + (mantissa != 0 ? 1 : 0); // cppcheck-suppress InvertedLogic
} }
} }
// handle positive zero // handle positive zero
...@@ -241,7 +235,7 @@ this case, the fp16 mantissa should be shift left by 1 */ ...@@ -241,7 +235,7 @@ this case, the fp16 mantissa should be shift left by 1 */
} }
} }
if(f8_exponent == 0 && mantissa == 0) if(f8_exponent == 0 and mantissa == 0)
return negative_zero_nan ? 0 : (sign << 7); return negative_zero_nan ? 0 : (sign << 7);
mantissa &= (1 << wm) - 1; mantissa &= (1 << wm) - 1;
return (sign << 7) | (f8_exponent << wm) | mantissa; return (sign << 7) | (f8_exponent << wm) | mantissa;
...@@ -314,7 +308,4 @@ constexpr T cast_from_f8(uint8_t x) ...@@ -314,7 +308,4 @@ constexpr T cast_from_f8(uint8_t x)
} }
} // namespace migraphx_f8_impl } // namespace migraphx_f8_impl
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // MIGRAPHX_FP8_IMPL_HPP #endif // MIGRAPHX_FP8_IMPL_HPP
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast" #pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wfloat-equal" #pragma clang diagnostic ignored "-Wfloat-equal"
#pragma clang diagnostic ignored "-Wmacro-redefined"
#pragma clang diagnostic ignored "-Wc++20-extensions" #pragma clang diagnostic ignored "-Wc++20-extensions"
#endif // __clang__ #endif // __clang__
...@@ -36,6 +35,7 @@ ...@@ -36,6 +35,7 @@
// We are clipping in down conversion by default // We are clipping in down conversion by default
#define MIGRAPHX_F8_DOWNCAST_CLIPPING 1 #define MIGRAPHX_F8_DOWNCAST_CLIPPING 1
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <climits> #include <climits>
...@@ -79,7 +79,7 @@ class numeric_limits; ...@@ -79,7 +79,7 @@ class numeric_limits;
template <migraphx_fp8::f8_type T = migraphx_fp8::f8_type::fp8> template <migraphx_fp8::f8_type T = migraphx_fp8::f8_type::fp8>
struct float8 struct float8
{ {
uint8_t data; uint8_t data = 0x00;
// default constructor // default constructor
constexpr float8() = default; constexpr float8() = default;
// default copy constructor // default copy constructor
...@@ -141,7 +141,7 @@ struct float8 ...@@ -141,7 +141,7 @@ struct float8
} }
else else
{ {
return (data == 0x00) || (data == 0x80); return (data == 0x00) or (data == 0x80);
} }
} }
...@@ -155,15 +155,15 @@ struct float8 ...@@ -155,15 +155,15 @@ struct float8
{ {
if(T == migraphx_fp8::f8_type::bf8) if(T == migraphx_fp8::f8_type::bf8)
{ {
return (data == 0x7d) || (data == 0x7e) || (data == 0x7f) || (data == 0xfd) || return (data == 0x7d) or (data == 0x7e) or (data == 0x7f) or (data == 0xfd) or
(data == 0xfe) || (data == 0xff); (data == 0xfe) or (data == 0xff);
} }
else else
{ {
return (data == 0x79) || (data == 0x7a) || (data == 0x7b) || (data == 0x7c) || return (data == 0x79) or (data == 0x7a) or (data == 0x7b) or (data == 0x7c) or
(data == 0x7d) || (data == 0x7e) || (data == 0x7f) || (data == 0xf9) || (data == 0x7d) or (data == 0x7e) or (data == 0x7f) or (data == 0xf9) or
(data == 0xfa) || (data == 0xfb) || (data == 0xfc) || (data == 0xfd) || (data == 0xfa) or (data == 0xfb) or (data == 0xfc) or (data == 0xfd) or
(data == 0xfe) || (data == 0xff); (data == 0xfe) or (data == 0xff);
} }
} }
} }
...@@ -178,11 +178,11 @@ struct float8 ...@@ -178,11 +178,11 @@ struct float8
{ {
if(T == migraphx_fp8::f8_type::bf8) if(T == migraphx_fp8::f8_type::bf8)
{ {
return (data == 0x7c) || (data == 0xfc); return (data == 0x7c) or (data == 0xfc);
} }
else else
{ {
return (data == 0x78) || (data == 0xf8); return (data == 0x78) or (data == 0xf8);
} }
} }
} }
...@@ -217,10 +217,10 @@ struct float8 ...@@ -217,10 +217,10 @@ struct float8
inline constexpr bool operator==(const float8& rhs) const inline constexpr bool operator==(const float8& rhs) const
{ {
if((rhs.is_zero() && this->is_zero()) || if((rhs.is_zero() and this->is_zero()) or
(fabs(rhs - *this) < migraphx_fp8::numeric_limits<float8<T>>::epsilon())) (fabs(rhs - *this) < migraphx_fp8::numeric_limits<float8<T>>::epsilon()))
return true; return true;
else if(rhs.is_nan() || rhs.is_inf() || this->is_nan() || this->is_inf()) else if(rhs.is_nan() or rhs.is_inf() or this->is_nan() or this->is_inf())
return false; return false;
return false; return false;
...@@ -373,6 +373,8 @@ class numeric_limits<migraphx_fp8::float8<migraphx_fp8::f8_type::bf8>> ...@@ -373,6 +373,8 @@ class numeric_limits<migraphx_fp8::float8<migraphx_fp8::f8_type::bf8>>
} }
}; };
} // namespace migraphx_fp8 } // namespace migraphx_fp8
// =================================================================================================
// define numeric limits for the new data type // define numeric limits for the new data type
namespace std { namespace std {
inline bool isfinite(migraphx_fp8::float8<migraphx_fp8::f8_type::fp8> x) // NOLINT inline bool isfinite(migraphx_fp8::float8<migraphx_fp8::f8_type::fp8> x) // NOLINT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment