Skip to content

Commit

Permalink
Add SFPU binary bitwise, int32 add, div
Browse files Browse the repository at this point in the history
  • Loading branch information
rdjogoTT committed Dec 4, 2024
1 parent a7620d0 commit ed52a73
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/inc/ckernel_sfpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "sfpu/ckernel_sfpu_abs.h"
#include "sfpu/ckernel_sfpu_add_int32.h"
#include "sfpu/ckernel_sfpu_binary.h"
#include "sfpu/ckernel_sfpu_binary_bitwise.h"
#include "sfpu/ckernel_sfpu_cast_fp32_to_fp16a.h"
#include "sfpu/ckernel_sfpu_clamp.h"
#include "sfpu/ckernel_sfpu_comp.h"
Expand Down
2 changes: 1 addition & 1 deletion common/inc/sfpu/ckernel_sfpu_add_int32.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace sfpu
{

template <bool APPROXIMATION_MODE, int ITERATIONS>
inline void _add_int32_(const int iterations, const uint dst_offset) {
inline void _add_int32_(const uint dst_offset) {
// Operand A is input1 (int32)
// Operand B is input2 (int32)
// Output is int32
Expand Down
13 changes: 10 additions & 3 deletions common/inc/sfpu/ckernel_sfpu_binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,17 @@ inline void _calculate_sfpu_binary_(const uint dst_offset)
result = in0 * in1;
} else if constexpr (BINOP_MODE == DIV_BINARY) {
v_if (in1 == 0) {
result = std::numeric_limits<float>::infinity();
result = setsgn(result, in0);
v_if (in0 == 0) {
result = std::numeric_limits<float>::quiet_NaN();
} v_else {
result = std::numeric_limits<float>::infinity();
result = setsgn(result, in0);
}
v_endif;
} v_elseif (in0 == in1) {
result = vConst1;
} v_else {
result = in0 * setsgn(_sfpu_reciprocal_(in1), in1);
result = in0 * setsgn(_sfpu_reciprocal_<4>(in1), in1);
}
v_endif;
} else if constexpr (BINOP_MODE == RSUB_BINARY) {
Expand Down
50 changes: 50 additions & 0 deletions common/inc/sfpu/ckernel_sfpu_binary_bitwise.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: © 2024 Tenstorrent AI ULC
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "ckernel.h"
#include "ckernel_defs.h"
#include "noc_nonblocking_api.h"
#include "sfpi.h"
#include <limits.h>

using namespace sfpi;

namespace ckernel
{
namespace sfpu
{

enum {
AND_BINARY = 0,
OR_BINARY = 1,
XOR_BINARY = 2,
}; // BITWISE_MODE

template <bool APPROXIMATION_MODE, int BITWISE_MODE, int ITERATIONS = 8>
inline void _calculate_sfpu_binary_bitwise_(const uint dst_offset)
{
// SFPU microcode
for (int d = 0; d < ITERATIONS; d++) {
constexpr uint dst_tile_size = 64;

TTI_SFPLOAD(0,12,ADDR_MOD_7,0);
TT_SFPLOAD(1,12,ADDR_MOD_7,dst_offset*dst_tile_size);

if constexpr (BITWISE_MODE == AND_BINARY) {
TTI_SFPAND(0,1,0,0);
} else if constexpr (BITWISE_MODE == OR_BINARY) {
TTI_SFPOR(0,1,0,0);
} else if constexpr (BITWISE_MODE == XOR_BINARY) {
TTI_SFPXOR(0,1,0,0);
}

TTI_SFPSTORE(0,12,ADDR_MOD_7,0);
dst_reg++;
}
}

} // namespace sfpu
} // namespace ckernel

0 comments on commit ed52a73

Please sign in to comment.