From d537d7c2fb18a2694a31b815a5e82ea69e102599 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Tue, 2 Mar 2021 18:20:39 +0000 Subject: make the tricky stuff private --- vespalib/src/vespa/vespalib/util/bfloat16.h | 40 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/vespalib/src/vespa/vespalib/util/bfloat16.h b/vespalib/src/vespa/vespalib/util/bfloat16.h index f5066d2f8e5..81c1bc5bcba 100644 --- a/vespalib/src/vespa/vespalib/util/bfloat16.h +++ b/vespalib/src/vespa/vespalib/util/bfloat16.h @@ -25,26 +25,6 @@ private: uint16_t u1; uint16_t u2; }; -public: - constexpr BFloat16(float value) noexcept : _bits(float_to_bits(value)) {} - BFloat16() noexcept = default; - ~BFloat16() noexcept = default; - constexpr BFloat16(const BFloat16 &other) noexcept = default; - constexpr BFloat16(BFloat16 &&other) noexcept = default; - constexpr BFloat16& operator=(const BFloat16 &other) noexcept = default; - constexpr BFloat16& operator=(BFloat16 &&other) noexcept = default; - constexpr BFloat16& operator=(float value) noexcept { - _bits = float_to_bits(value); - return *this; - } - - constexpr operator float () const noexcept { return bits_to_float(_bits); } - - constexpr float to_float() const noexcept { return bits_to_float(_bits); } - constexpr void assign(float value) noexcept { _bits = float_to_bits(value); } - - constexpr uint16_t get_bits() const { return _bits; } - constexpr void assign_bits(uint16_t value) noexcept { _bits = value; } template static constexpr uint16_t float_to_bits(float value) noexcept { @@ -75,6 +55,26 @@ public: memcpy(&result, &both, sizeof(float)); return result; } +public: + constexpr BFloat16(float value) noexcept : _bits(float_to_bits(value)) {} + BFloat16() noexcept = default; + ~BFloat16() noexcept = default; + constexpr BFloat16(const BFloat16 &other) noexcept = default; + constexpr BFloat16(BFloat16 &&other) noexcept = default; + constexpr BFloat16& operator=(const BFloat16 &other) noexcept = default; + constexpr BFloat16& operator=(BFloat16 &&other) noexcept = default; + constexpr BFloat16& operator=(float value) noexcept { + _bits = float_to_bits(value); + return *this; + } + + constexpr operator float () const noexcept { return bits_to_float(_bits); } + + constexpr float to_float() const noexcept { return bits_to_float(_bits); } + constexpr void assign(float value) noexcept { _bits = float_to_bits(value); } + + constexpr uint16_t get_bits() const { return _bits; } + constexpr void assign_bits(uint16_t value) noexcept { _bits = value; } }; } -- cgit v1.2.3