diff --git a/internal/allocator.h b/internal/allocator.h index 3a6f077..e71df15 100644 --- a/internal/allocator.h +++ b/internal/allocator.h @@ -86,11 +86,11 @@ class Allocator { } // Alignment of allocated blocks. - static const std::size_t kAlignment = kDefaultCacheLineSize; + static constexpr std::size_t kAlignment = kDefaultCacheLineSize; // This is all we need so far, and since the usage pattern is fixed, // there is no point in allowing more until we need to. - static const std::size_t kMaxBlocks = 5; + static constexpr std::size_t kMaxBlocks = 5; void Commit() { assert(!committed_); diff --git a/internal/common.h b/internal/common.h index 332ad07..708cc40 100644 --- a/internal/common.h +++ b/internal/common.h @@ -165,7 +165,7 @@ Integer RoundUpToPowerOfTwo(Integer n) { template struct IsPowerOfTwo { - static const bool value = !(N & (N - 1)); + static constexpr bool value = !(N & (N - 1)); }; template diff --git a/internal/dispatch_gemm_shape.h b/internal/dispatch_gemm_shape.h index ba4f341..b844f78 100644 --- a/internal/dispatch_gemm_shape.h +++ b/internal/dispatch_gemm_shape.h @@ -74,7 +74,8 @@ struct TransposeImpl> { template struct TransposeImpl> { typedef OutputStageQuantizeDownInt32ToUint8ScalePC SrcType; - static const VectorShape TransposedShape = TransposeVectorShape::Value; + static constexpr VectorShape TransposedShape = + TransposeVectorShape::Value; typedef OutputStageQuantizeDownInt32ToUint8ScalePC DstType; static DstType Run(const SrcType& src) { DstType dst; @@ -88,7 +89,8 @@ struct TransposeImpl> { template struct TransposeImpl> { typedef OutputStageScaleInt32ByFixedPointAndExponentPC SrcType; - static const VectorShape TransposedShape = TransposeVectorShape::Value; + static constexpr VectorShape TransposedShape = + TransposeVectorShape::Value; typedef OutputStageScaleInt32ByFixedPointAndExponentPC DstType; static DstType Run(const SrcType& src) { diff --git a/internal/kernel.h b/internal/kernel.h index 3120216..f1a3fd8 100644 --- a/internal/kernel.h +++ b/internal/kernel.h @@ -126,11 +126,11 @@ enum class CellOrder { DepthMajor, WidthMajor, Diagonal }; // out in a cell. That is, a CellOrder together with actual dimensions. template struct CellFormat { - static const int kWidth = tWidth; - static const int kDepth = tDepth; - static const CellOrder kOrder = tOrder; + static constexpr int kWidth = tWidth; + static constexpr int kDepth = tDepth; + static constexpr CellOrder kOrder = tOrder; - static const int kSize = kWidth * kDepth; + static constexpr int kSize = kWidth * kDepth; }; // KernelSideFormat describes how data is laid out in a kernel side @@ -142,9 +142,9 @@ struct CellFormat { template struct KernelSideFormat { typedef tCellFormat Cell; - static const int kCells = tCells; - static const int kWidth = kCells * Cell::kWidth; - static const int kDepth = Cell::kDepth; + static constexpr int kCells = tCells; + static constexpr int kWidth = kCells * Cell::kWidth; + static constexpr int kDepth = Cell::kDepth; typedef std::uint8_t Scalar; // The scalar type of the Format. typedef std::uint8_t InputScalar; // The scalar type of the original input. }; @@ -173,9 +173,9 @@ struct KernelFormat { typedef tRhs Rhs; static_assert(Lhs::Cell::kDepth == Rhs::Cell::kDepth, ""); - static const int kDepth = Lhs::Cell::kDepth; - static const int kRows = Lhs::Cell::kWidth * Lhs::kCells; - static const int kCols = Rhs::Cell::kWidth * Rhs::kCells; + static constexpr int kDepth = Lhs::Cell::kDepth; + static constexpr int kRows = Lhs::Cell::kWidth * Lhs::kCells; + static constexpr int kCols = Rhs::Cell::kWidth * Rhs::kCells; }; inline const char* CellOrderName(CellOrder o) { diff --git a/internal/pack.h b/internal/pack.h index 7c43d6e..82f0dd1 100644 --- a/internal/pack.h +++ b/internal/pack.h @@ -143,7 +143,7 @@ template class SideMap { public: typedef tScalar Scalar; - static const SideMapOrder kOrder = tOrder; + static constexpr SideMapOrder kOrder = tOrder; SideMap(Scalar* data, int width, int depth, int stride) : data_(data), width_(width), depth_(depth), stride_(stride) {} @@ -214,13 +214,13 @@ class PackingRegisterBlockBase { typedef typename KernelSideFormat::Cell CellFormat; typedef typename KernelSideFormat::InputScalar KernelInputScalar; typedef typename KernelSideFormat::Scalar KernelScalar; - static const int kCells = KernelSideFormat::kCells; - static const int kCellWidth = CellFormat::kWidth; - static const int kKernelWidth = CellFormat::kWidth * kCells; - static const int kCellDepth = CellFormat::kDepth; - static const int kCellSize = CellFormat::kSize; - static const SideMapOrder kSrcOrder = SrcMapType::kOrder; - static const int kZeroPointInputValue = + static constexpr int kCells = KernelSideFormat::kCells; + static constexpr int kCellWidth = CellFormat::kWidth; + static constexpr int kKernelWidth = CellFormat::kWidth * kCells; + static constexpr int kCellDepth = CellFormat::kDepth; + static constexpr int kCellSize = CellFormat::kSize; + static constexpr SideMapOrder kSrcOrder = SrcMapType::kOrder; + static constexpr int kZeroPointInputValue = ZeroPointInputValue::kValue; PackingRegisterBlockBase() : complete_src_(nullptr, 0, 0, 0) {} @@ -302,10 +302,10 @@ class PackSideBlockImpl { public: typedef typename PackedSideBlock::KernelSideFormat KernelSideFormat; typedef typename KernelSideFormat::Cell CellFormat; - static const int kCells = KernelSideFormat::kCells; - static const int kCellWidth = CellFormat::kWidth; - static const int kKernelWidth = CellFormat::kWidth * kCells; - static const int kCellDepth = CellFormat::kDepth; + static constexpr int kCells = KernelSideFormat::kCells; + static constexpr int kCellWidth = CellFormat::kWidth; + static constexpr int kKernelWidth = CellFormat::kWidth * kCells; + static constexpr int kCellDepth = CellFormat::kDepth; typedef PackingRegisterBlock PackingRegisterBlockType; diff --git a/internal/pack_sse.h b/internal/pack_sse.h index 52163c4..b729014 100644 --- a/internal/pack_sse.h +++ b/internal/pack_sse.h @@ -41,11 +41,11 @@ class PackingRegisterBlock< public: typedef WidthMajorSideFormatNCells4x2 KernelSideFormat; typedef typename KernelSideFormat::Cell CellFormat; - static const int kCells = KernelSideFormat::kCells; - static const int kCellWidth = CellFormat::kWidth; - static const int kKernelWidth = CellFormat::kWidth * kCells; - static const int kCellDepth = CellFormat::kDepth; - static const int kCellSize = CellFormat::kSize; + static constexpr int kCells = KernelSideFormat::kCells; + static constexpr int kCellWidth = CellFormat::kWidth; + static constexpr int kKernelWidth = CellFormat::kWidth * kCells; + static constexpr int kCellDepth = CellFormat::kDepth; + static constexpr int kCellSize = CellFormat::kSize; void Pack(PackedSideBlock* dst, int start_width) { std::uint8_t* dst_ptr = dst->current_data(); diff --git a/public/bit_depth.h b/public/bit_depth.h index 412944e..5b19430 100644 --- a/public/bit_depth.h +++ b/public/bit_depth.h @@ -22,8 +22,8 @@ namespace gemmlowp { // The range of allowed values for an operand. template struct OperandRange { - static const int kMinValue = tMinValue; - static const int kMaxValue = tMaxValue; + static constexpr int kMinValue = tMinValue; + static constexpr int kMaxValue = tMaxValue; static_assert(kMinValue < kMaxValue, ""); }; diff --git a/public/map.h b/public/map.h index fe6bc5c..1b71f9e 100644 --- a/public/map.h +++ b/public/map.h @@ -32,7 +32,7 @@ template class MatrixMap { public: typedef tScalar Scalar; - static const MapOrder kOrder = tOrder; + static constexpr MapOrder kOrder = tOrder; protected: Scalar* data_; // not owned. @@ -84,7 +84,7 @@ template class VectorMap { public: typedef tScalar Scalar; - static const VectorShape kShape = tShape; + static constexpr VectorShape kShape = tShape; protected: Scalar* data_; // not owned. @@ -113,7 +113,7 @@ template class VectorDup { public: typedef tScalar Scalar; - static const VectorShape kShape = tShape; + static constexpr VectorShape kShape = tShape; protected: Scalar data_; diff --git a/test/test.h b/test/test.h index ca8314d..b381bad 100644 --- a/test/test.h +++ b/test/test.h @@ -49,7 +49,7 @@ class Matrix : public MatrixMap { typedef MatrixMap Map; typedef MatrixMap ConstMap; typedef typename Map::Scalar Scalar; - static const MapOrder Order = tOrder; + static constexpr MapOrder Order = tOrder; using Map::kOrder; using Map::rows_; using Map::cols_; diff --git a/test/test_blocking_counter.cc b/test/test_blocking_counter.cc index f082e3c..34d963d 100644 --- a/test/test_blocking_counter.cc +++ b/test/test_blocking_counter.cc @@ -78,7 +78,7 @@ class Thread { return nullptr; } - static const size_t max_stack_size_ = 256 * 1024; + static constexpr size_t max_stack_size_ = 256 * 1024; BlockingCounter* const blocking_counter_; const int number_of_times_to_decrement_; pthread_t thread_;