Skip to content

Commit

Permalink
Fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amirbawab committed Jul 8, 2019
1 parent 478c60d commit 19311b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Binary file modified docs/demo/nnb_js.wasm
Binary file not shown.
28 changes: 14 additions & 14 deletions src/nn-builder/src/snippet/matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1217,15 +1217,15 @@ ExprList* MatrixSnippetSimd::MatrixAddRightSignScale(ds::NDArray *lhs, ds::NDArr
auto lhs_addr = MakeBinary(Opcode::I32Add, MakeI32Const(lhs->Memory()->Begin()), MakeLocalGet(addr));
auto rhs_addr = MakeBinary(Opcode::I32Add, MakeI32Const(rhs->Memory()->Begin()), MakeLocalGet(addr));
// Compute right sign scale
// 1) [-1, 2, -3, 4] >= [0, 0, 0, 0] = [0, -1, 0, -1]
// 2) [0, -1, 0, -1] to-float = [0.0, -1.0. 0.0, -1.0]
// 3) [0.0, -1.0, 0.0, 1.0] * [2s, 2s, 2s, 2s] = [0, -2s, 0, -2s]
// 4) [0, -2s, 0, -2s] + [s, s, s, s] = [-s, s, -s, s]
// 1) [-1, 2, -3, 4] >= [0, 0, 0, 0] = [0, -1, 0, -1]
// 2) [0, -1, 0, -1] to-float = [0.0, -1.0. 0.0, -1.0]
// 3) [0.0, -1.0, 0.0, 1.0] * [-2s, -2s, -2s, -2s] = [0, 2s, 0, 2s]
// 4) [0, 2s, 0, 2s] - [s, s, s, s] = [-s, s, -s, s]
auto rhs_ge = MakeBinary(Opcode::F32X4Ge, MakeV128Load(rhs_addr), MakeUnary(Opcode::F32X4Splat, MakeF32Const(0)));
auto rhs_cnvt = MakeUnary(Opcode::F32X4ConvertI32X4S, rhs_ge);
auto rhs_mul = MakeBinary(Opcode::F32X4Mul, rhs_cnvt, MakeUnary(Opcode::F32X4Splat, MakeF32Const(2*scale)));
auto rhs_add = MakeBinary(Opcode::F32X4Add, rhs_mul, MakeUnary(Opcode::F32X4Splat, MakeF32Const(scale)));
b->Insert(MakeV128Store(MakeLocalGet(dst_addr), MakeBinary(Opcode::F32X4Add, MakeV128Load(lhs_addr), rhs_add)));
auto rhs_mul = MakeBinary(Opcode::F32X4Mul, rhs_cnvt, MakeUnary(Opcode::F32X4Splat, MakeF32Const(-2*scale)));
auto rhs_sub = MakeBinary(Opcode::F32X4Sub, rhs_mul, MakeUnary(Opcode::F32X4Splat, MakeF32Const(scale)));
b->Insert(MakeV128Store(MakeLocalGet(dst_addr), MakeBinary(Opcode::F32X4Add, MakeV128Load(lhs_addr), rhs_sub)));
// Move to next elements
b->Insert(GenerateCompoundAssignment(addr, Opcode::I32Add, MakeI32Const(simd_type_size)));
}));
Expand Down Expand Up @@ -1280,16 +1280,16 @@ ExprList* MatrixSnippetSimd::MatrixAddRightSignScaleAddRightScale(nn::ds::NDArra
// Cache rhs val
b->Insert(MakeLocalSet(rhs_v128_cache, MakeV128Load(rhs_addr)));
// Compute right sign scale
// 1) [-1, 2, -3, 4] >= [0, 0, 0, 0] = [0, -1, 0, -1]
// 2) [0, -1, 0, -1] to-float = [0.0, -1.0. 0.0, -1.0]
// 3) [0.0, -1.0, 0.0, 1.0] * [2s, 2s, 2s, 2s] = [0, -2s, 0, -2s]
// 4) [0, -2s, 0, -2s] + [s, s, s, s] = [-s, s, -s, s]
// 1) [-1, 2, -3, 4] >= [0, 0, 0, 0] = [0, -1, 0, -1]
// 2) [0, -1, 0, -1] to-float = [0.0, -1.0. 0.0, -1.0]
// 3) [0.0, -1.0, 0.0, 1.0] * [-2s, -2s, -2s, -2s] = [0, 2s, 0, 2s]
// 4) [0, 2s, 0, 2s] - [s, s, s, s] = [-s, s, -s, s]
auto rhs_ge = MakeBinary(Opcode::F32X4Ge, MakeLocalGet(rhs_v128_cache), MakeUnary(Opcode::F32X4Splat, MakeF32Const(0)));
auto rhs_cnvt = MakeUnary(Opcode::F32X4ConvertI32X4S, rhs_ge);
auto rhs_mul = MakeBinary(Opcode::F32X4Mul, rhs_cnvt, MakeUnary(Opcode::F32X4Splat, MakeF32Const(2*scale1)));
auto rhs_add = MakeBinary(Opcode::F32X4Add, rhs_mul, MakeUnary(Opcode::F32X4Splat, MakeF32Const(scale1)));
auto rhs_mul = MakeBinary(Opcode::F32X4Mul, rhs_cnvt, MakeUnary(Opcode::F32X4Splat, MakeF32Const(-2*scale1)));
auto rhs_sub = MakeBinary(Opcode::F32X4Sub, rhs_mul, MakeUnary(Opcode::F32X4Splat, MakeF32Const(scale1)));
auto rhs_scale2 = MakeBinary(Opcode::F32X4Mul, MakeLocalGet(rhs_v128_cache), MakeUnary(Opcode::F32X4Splat, MakeF32Const(scale2)));
auto rhs_val = MakeBinary(Opcode::F32X4Add, rhs_add, rhs_scale2);
auto rhs_val = MakeBinary(Opcode::F32X4Add, rhs_sub, rhs_scale2);
b->Insert(MakeV128Store(MakeLocalGet(dst_addr), MakeBinary(Opcode::F32X4Add, MakeV128Load(lhs_addr), rhs_val)));
// Move to next elements
b->Insert(GenerateCompoundAssignment(addr, Opcode::I32Add, MakeI32Const(simd_type_size)));
Expand Down

0 comments on commit 19311b4

Please sign in to comment.