Skip to content

Commit

Permalink
Modernize and format code
Browse files Browse the repository at this point in the history
The code was modernized using clang-tidy with "modernize-use-using".

The modified files were then formatted using clang-tidy with
"google-readability-braces-around-statements", then clang-format
was applied.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Apr 3, 2019
1 parent e76d81a commit 98346c2
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 506 deletions.
18 changes: 11 additions & 7 deletions src/arch/intsimdmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include <cstdint>
#include <vector>

template <class T> class GENERIC_2D_ARRAY;
template <typename T> class GenericVector;
template <class T>
class GENERIC_2D_ARRAY;
template <typename T>
class GenericVector;

namespace tesseract {

Expand Down Expand Up @@ -60,7 +62,8 @@ namespace tesseract {
// is required to allow the base class implementation to do all the work.
struct IntSimdMatrix {
// Computes a reshaped copy of the weight matrix w.
void Init(const GENERIC_2D_ARRAY<int8_t>& w, std::vector<int8_t>& shaped_w) const;
void Init(const GENERIC_2D_ARRAY<int8_t>& w,
std::vector<int8_t>& shaped_w) const;

// Rounds the size up to a multiple of the input register size (in int8_t).
int RoundInputs(int size) const {
Expand All @@ -77,8 +80,8 @@ struct IntSimdMatrix {
// implement the bias, but it doesn't actually have it.
// Computes the base C++ implementation.
static void MatrixDotVector(const GENERIC_2D_ARRAY<int8_t>& w,
const GenericVector<double>& scales, const int8_t* u,
double* v);
const GenericVector<double>& scales,
const int8_t* u, double* v);

// Rounds the input up to a multiple of the given factor.
static int Roundup(int input, int factor) {
Expand All @@ -94,8 +97,9 @@ struct IntSimdMatrix {
// RoundInputs above.
// The input will be over-read to the extent of the padding. There are no
// alignment requirements.
typedef void (*MatrixDotVectorFunction)(int dim1, int dim2,
const int8_t* wi, const double* scales, const int8_t* u, double* v);
using MatrixDotVectorFunction = void (*)(int, int, const int8_t*,
const double*, const int8_t*,
double*);
MatrixDotVectorFunction matrixDotVectorFunction;

// Number of 32 bit outputs held in each register.
Expand Down
14 changes: 10 additions & 4 deletions src/arch/simddetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace tesseract {

// Function pointer for best calculation of dot product.
typedef double (*DotProductFunction)(const double* u, const double* v, int n);
using DotProductFunction = double (*)(const double*, const double*, int);
extern DotProductFunction DotProduct;

// Architecture detector. Add code here to detect any other architectures for
Expand All @@ -31,9 +31,13 @@ extern DotProductFunction DotProduct;
class SIMDDetect {
public:
// Returns true if AVX is available on this system.
static inline bool IsAVXAvailable() { return detector.avx_available_; }
static inline bool IsAVXAvailable() {
return detector.avx_available_;
}
// Returns true if AVX2 (integer support) is available on this system.
static inline bool IsAVX2Available() { return detector.avx2_available_; }
static inline bool IsAVX2Available() {
return detector.avx2_available_;
}
// Returns true if AVX512 Foundation (float) is available on this system.
static inline bool IsAVX512FAvailable() {
return detector.avx512F_available_;
Expand All @@ -43,7 +47,9 @@ class SIMDDetect {
return detector.avx512BW_available_;
}
// Returns true if SSE4.1 is available on this system.
static inline bool IsSSEAvailable() { return detector.sse_available_; }
static inline bool IsSSEAvailable() {
return detector.sse_available_;
}

// Update settings after config variable was set.
static void Update();
Expand Down
Loading

0 comments on commit 98346c2

Please sign in to comment.