tesseract/arch/intsimdmatrixsse.cpp

45 lines
1.6 KiB
C++
Raw Normal View History

///////////////////////////////////////////////////////////////////////
// File: intsindmatrixsse.cpp
// Description: SSE implementation of 8-bit int SIMD matrix multiply.
// Author: Ray Smith
// Created: Tue Aug 23 13:58:49 PST 2017
//
// (C) Copyright 2017, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////
#include "intsimdmatrixsse.h"
#include <stdint.h>
#include <vector>
#include "dotproductsse.h"
namespace tesseract {
#ifdef __SSE4_1__
// Computes part of matrix.vector v = Wu. Computes 1 result.
static void PartialMatrixDotVector1(const int8_t* wi, const double* scales,
const int8_t* u, int num_in, int num_out,
double* v) {
int total = IntDotProductSSE(u, wi, num_in);
// Add in the bias and correct for integer values.
*v = (static_cast<double>(total) / MAX_INT8 + wi[num_in]) * *scales;
}
#endif // __SSE4_1__
IntSimdMatrixSSE::IntSimdMatrixSSE() {
#ifdef __SSE4_1__
partial_funcs_ = {PartialMatrixDotVector1};
#endif // __SSE4_1__
}
} // namespace tesseract.