Skip to content

Commit

Permalink
Add binary sfpu div init (#50)
Browse files Browse the repository at this point in the history
* Add binary sfpu div init

* Add enum classes for op type template param
  • Loading branch information
rdjogoTT authored Jan 2, 2025
1 parent 33a7f6a commit a2645b5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
38 changes: 23 additions & 15 deletions common/inc/sfpu/ckernel_sfpu_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ sfpi_inline vFloat _calculate_sfpu_binary_power_(vFloat base, vFloat pow)
return result;
}

template <bool APPROXIMATION_MODE, int BINOP_MODE, int ITERATIONS = 8>
template <bool APPROXIMATION_MODE, BinaryOp BINOP, int ITERATIONS = 8>
inline void _calculate_sfpu_binary_(const uint dst_offset)
{
// SFPU microcode
Expand All @@ -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<float>::quiet_NaN();
Expand All @@ -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);
}

Expand All @@ -135,5 +135,13 @@ inline void _calculate_sfpu_binary_(const uint dst_offset)
}
}

template <bool APPROXIMATION_MODE /*unused*/, BinaryOp BINOP>
inline void _sfpu_binary_init_()
{
if constexpr (BINOP == BinaryOp::DIV) {
_init_reciprocal_<APPROXIMATION_MODE>();
}
}

} // namespace sfpu
} // namespace ckernel
18 changes: 9 additions & 9 deletions common/inc/sfpu/ckernel_sfpu_binary_bitwise.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bool APPROXIMATION_MODE, int BITWISE_MODE, int ITERATIONS = 8>
template <bool APPROXIMATION_MODE, BinaryBitwiseOp BITWISE_OP, int ITERATIONS = 8>
inline void _calculate_sfpu_binary_bitwise_(const uint dst_offset)
{
// SFPU microcode
Expand All @@ -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);
}

Expand Down

0 comments on commit a2645b5

Please sign in to comment.