aboutsummaryrefslogtreecommitdiff
path: root/public/bit_depth.h
blob: 5b1943067e26dcc4931553c94179416e96737265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2015 The Gemmlowp Authors. All Rights Reserved.
//
// 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.

// bit_depth.h: defines the settins controlling LHS/RHS bit depth

#ifndef GEMMLOWP_PUBLIC_BIT_DEPTH_H_
#define GEMMLOWP_PUBLIC_BIT_DEPTH_H_

namespace gemmlowp {

// The range of allowed values for an operand.
template <int tMinValue, int tMaxValue>
struct OperandRange {
  static constexpr int kMinValue = tMinValue;
  static constexpr int kMaxValue = tMaxValue;
  static_assert(kMinValue < kMaxValue, "");
};

using Uint8Range = OperandRange<0, 255>;
using Uint8RangeExcludingZero = OperandRange<1, 255>;

using Int8Range = OperandRange<-128, 127>;
using Int8RangeExcludingLow = OperandRange<-127, 127>;

template <typename tLhsRange, typename tRhsRange>
struct BitDepthParams {
  using LhsRange = tLhsRange;
  using RhsRange = tRhsRange;
};

// Default: LHS and RHS are 8bit.
using DefaultL8R8BitDepthParams = BitDepthParams<Uint8Range, Uint8Range>;

// Variant: LHS may not take the value 0. This allows using
// faster kernels using signed arithmetic, see
// NEON_64bit_GEMM_Int8Operands_Int32Accumulators_AccumTwoWithin16Bits
using L8R8WithLhsNonzeroBitDepthParams =
    BitDepthParams<Uint8RangeExcludingZero, Uint8Range>;

// Signed Variant: This allows using faster kernels using signed arithmetic, see
// NEON_64bit_GEMM_Int8Operands_Int32Accumulators_AccumTwoWithin16Bits
using SignedL8R8WithLhsNonzeroBitDepthParams =
    BitDepthParams<Int8RangeExcludingLow, Int8Range>;

// Deprecated: when gemmlowp used to allow requantizing 8bit
// inputs to less-than-8-bit depths, the public setting allowing
// that was DefaultL7R5BitDepthParams. That requantization
// feature has been removed, but as the whole point of that
// requantization was to make less-than-8-bit an internal
// optimization without any impact on the API (other than lowering
// accuracy), we can temporarily support users who were using it
// by mapping it to the default 8bit behavior.
using DefaultL7R5BitDepthParams = DefaultL8R8BitDepthParams;

}  // namespace gemmlowp

#endif  // GEMMLOWP_PUBLIC_BIT_DEPTH_H_