From a2645b5d639c03f54c2e84f4972462dd23606dca Mon Sep 17 00:00:00 2001 From: Radomir Djogo <159184120+rdjogoTT@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:39:30 -0500 Subject: [PATCH] Add binary sfpu div init (#50) * Add binary sfpu div init * Add enum classes for op type template param --- common/inc/sfpu/ckernel_sfpu_binary.h | 38 +++++++++++-------- common/inc/sfpu/ckernel_sfpu_binary_bitwise.h | 18 ++++----- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/common/inc/sfpu/ckernel_sfpu_binary.h b/common/inc/sfpu/ckernel_sfpu_binary.h index f0c7d7d..e6466ca 100644 --- a/common/inc/sfpu/ckernel_sfpu_binary.h +++ b/common/inc/sfpu/ckernel_sfpu_binary.h @@ -17,14 +17,14 @@ namespace ckernel namespace sfpu { -enum { - ADD_BINARY = 0, - SUB_BINARY = 1, - MUL_BINARY = 2, - DIV_BINARY = 3, - RSUB_BINARY = 4, - POW_BINARY = 5 -}; // BINOP_MODE +enum class BinaryOp : uint8_t { + ADD = 0, + SUB = 1, + MUL = 2, + DIV = 3, + RSUB = 4, + POW = 5 +}; sfpi_inline vFloat _calculate_sfpu_binary_power_(vFloat base, vFloat pow) { @@ -93,7 +93,7 @@ sfpi_inline vFloat _calculate_sfpu_binary_power_(vFloat base, vFloat pow) return result; } -template +template inline void _calculate_sfpu_binary_(const uint dst_offset) { // SFPU microcode @@ -103,13 +103,13 @@ inline void _calculate_sfpu_binary_(const uint dst_offset) vFloat in1 = dst_reg[dst_offset * dst_tile_size]; vFloat result = 0.0f; - if constexpr (BINOP_MODE == ADD_BINARY) { + if constexpr (BINOP == BinaryOp::ADD) { result = in0 + in1; - } else if constexpr (BINOP_MODE == SUB_BINARY) { + } else if constexpr (BINOP == BinaryOp::SUB) { result = in0 - in1; - } else if constexpr (BINOP_MODE == MUL_BINARY) { + } else if constexpr (BINOP == BinaryOp::MUL) { result = in0 * in1; - } else if constexpr (BINOP_MODE == DIV_BINARY) { + } else if constexpr (BINOP == BinaryOp::DIV) { v_if (in1 == 0) { v_if (in0 == 0) { result = std::numeric_limits::quiet_NaN(); @@ -124,9 +124,9 @@ inline void _calculate_sfpu_binary_(const uint dst_offset) result = in0 * setsgn(_sfpu_reciprocal_<4>(in1), in1); } v_endif; - } else if constexpr (BINOP_MODE == RSUB_BINARY) { + } else if constexpr (BINOP == BinaryOp::RSUB) { result = in1 - in0; - } else if constexpr (BINOP_MODE == POW_BINARY) { + } else if constexpr (BINOP == BinaryOp::POW) { result = _calculate_sfpu_binary_power_(in0, in1); } @@ -135,5 +135,13 @@ inline void _calculate_sfpu_binary_(const uint dst_offset) } } +template +inline void _sfpu_binary_init_() +{ + if constexpr (BINOP == BinaryOp::DIV) { + _init_reciprocal_(); + } +} + } // namespace sfpu } // namespace ckernel diff --git a/common/inc/sfpu/ckernel_sfpu_binary_bitwise.h b/common/inc/sfpu/ckernel_sfpu_binary_bitwise.h index c0df40c..d7d56d4 100644 --- a/common/inc/sfpu/ckernel_sfpu_binary_bitwise.h +++ b/common/inc/sfpu/ckernel_sfpu_binary_bitwise.h @@ -17,13 +17,13 @@ namespace ckernel namespace sfpu { -enum { - AND_BINARY = 0, - OR_BINARY = 1, - XOR_BINARY = 2, -}; // BITWISE_MODE +enum class BinaryBitwiseOp : uint8_t { + AND = 0, + OR = 1, + XOR = 2, +}; -template +template inline void _calculate_sfpu_binary_bitwise_(const uint dst_offset) { // SFPU microcode @@ -33,11 +33,11 @@ inline void _calculate_sfpu_binary_bitwise_(const uint dst_offset) TTI_SFPLOAD(0,4,3,0); TT_SFPLOAD(1,4,3,dst_offset*dst_tile_size); - if constexpr (BITWISE_MODE == AND_BINARY) { + if constexpr (BITWISE_OP == BinaryBitwiseOp::AND) { TTI_SFPAND(0,1,0,0); - } else if constexpr (BITWISE_MODE == OR_BINARY) { + } else if constexpr (BITWISE_OP == BinaryBitwiseOp::OR) { TTI_SFPOR(0,1,0,0); - } else if constexpr (BITWISE_MODE == XOR_BINARY) { + } else if constexpr (BITWISE_OP == BinaryBitwiseOp::XOR) { TTI_SFPXOR(0,1,0,0); }