diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-07-19 19:56:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 19:56:41 +0800 |
commit | 3415a8a8065ee25cf9a644281a67eda777cbcdeb (patch) | |
tree | f82e5c3990665ec7238bf585e30576d402c8d3c2 | |
parent | 185a3cb1050f00acee61dd9b2d0d0f817c5e8776 (diff) | |
parent | 10ba5ab9e33ea100b3d7a87fb555f501e5fa8c32 (diff) |
Merge pull request #27823 from vespa-engine/balder/prefer-helper-to-inheritance-and-add-noexcept
- Add noexcept and some constexpr.
12 files changed, 126 insertions, 127 deletions
diff --git a/searchlib/src/vespa/searchlib/common/bitword.h b/searchlib/src/vespa/searchlib/common/bitword.h index cba6cf7723f..06071e4cae8 100644 --- a/searchlib/src/vespa/searchlib/common/bitword.h +++ b/searchlib/src/vespa/searchlib/common/bitword.h @@ -12,16 +12,16 @@ class BitWord { public: using Word = uint64_t; using Index = uint32_t; - static Word checkTab(Index index) { return _checkTab[bitNum(index)]; } - static Word startBits(Index index) { return (std::numeric_limits<Word>::max() >> 1) >> (WordLen - 1 - bitNum(index)); } + static Word checkTab(Index index) noexcept { return _checkTab[bitNum(index)]; } + static constexpr Word startBits(Index index) noexcept { return (std::numeric_limits<Word>::max() >> 1) >> (WordLen - 1 - bitNum(index)); } static constexpr size_t WordLen = sizeof(Word)*8; - static uint8_t bitNum(Index idx) { return (idx % WordLen); } - static Word endBits(Index index) { return (std::numeric_limits<Word>::max() - 1) << bitNum(index); } - static Word allBits() { return std::numeric_limits<Word>::max(); } - static Index wordNum(Index idx) { return idx >> numWordBits(); } - static Word mask(Index idx) { return Word(1) << bitNum(idx); } - static constexpr uint8_t size_bits(uint8_t n) { return (n > 1) ? (1 + size_bits(n >> 1)) : 0; } - static uint8_t numWordBits() { return size_bits(WordLen); } + static constexpr uint8_t bitNum(Index idx) noexcept { return (idx % WordLen); } + static constexpr Word endBits(Index index) noexcept { return (std::numeric_limits<Word>::max() - 1) << bitNum(index); } + static constexpr Word allBits() noexcept { return std::numeric_limits<Word>::max(); } + static constexpr Index wordNum(Index idx) noexcept { return idx >> numWordBits(); } + static constexpr Word mask(Index idx) noexcept { return Word(1) << bitNum(idx); } + static constexpr uint8_t size_bits(uint8_t n) noexcept { return (n > 1) ? (1 + size_bits(n >> 1)) : 0; } + static constexpr uint8_t numWordBits() noexcept { return size_bits(WordLen); } private: static Word _checkTab[WordLen]; diff --git a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp index 4203a6361b2..8b8db0f293a 100644 --- a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.cpp @@ -29,12 +29,12 @@ public: memset(_lastWords, 0, sizeof(_lastWords)); } protected: - void updateLastValue(uint32_t docId); - void strictSeek(uint32_t docId); + void updateLastValue(uint32_t docId) noexcept; + void strictSeek(uint32_t docId) noexcept; private: void doSeek(uint32_t docId) override; Trinary is_strict() const override { return Trinary::False; } - bool acceptExtraFilter() const override { return Update::isAnd(); } + bool acceptExtraFilter() const noexcept final { return Update::isAnd(); } Update _update; const IAccelrated & _accel; alignas(64) Word _lastWords[8]; @@ -42,7 +42,7 @@ private: }; template<typename Update> -class MultiBitVectorIteratorStrict : public MultiBitVectorIterator<Update> +class MultiBitVectorIteratorStrict final : public MultiBitVectorIterator<Update> { public: explicit MultiBitVectorIteratorStrict(MultiSearch::Children children) @@ -55,36 +55,36 @@ private: struct And { using Word = BitWord::Word; - void operator () (const IAccelrated & accel, size_t offset, const std::vector<std::pair<const void *, bool>> & src, void *dest) { + void operator () (const IAccelrated & accel, size_t offset, const std::vector<std::pair<const void *, bool>> & src, void *dest) noexcept { accel.and64(offset, src, dest); } - static bool isAnd() { return true; } + static bool isAnd() noexcept { return true; } }; struct Or { using Word = BitWord::Word; - void operator () (const IAccelrated & accel, size_t offset, const std::vector<std::pair<const void *, bool>> & src, void *dest) { + void operator () (const IAccelrated & accel, size_t offset, const std::vector<std::pair<const void *, bool>> & src, void *dest) noexcept { accel.or64(offset, src, dest); } - static bool isAnd() { return false; } + static bool isAnd() noexcept { return false; } }; template<typename Update> -void MultiBitVectorIterator<Update>::updateLastValue(uint32_t docId) +void MultiBitVectorIterator<Update>::updateLastValue(uint32_t docId) noexcept { if (docId >= _lastMaxDocIdLimit) { if (__builtin_expect(docId >= _numDocs, false)) { setAtEnd(); return; } - const uint32_t index(wordNum(docId)); + const uint32_t index(BitWord::wordNum(docId)); if (docId >= _lastMaxDocIdLimitRequireFetch) { uint32_t baseIndex = index & ~(NumWordsInBatch - 1); _update(_accel, baseIndex*sizeof(Word), _bvs, _lastWords); - _lastMaxDocIdLimitRequireFetch = (baseIndex + NumWordsInBatch) * WordLen; + _lastMaxDocIdLimitRequireFetch = (baseIndex + NumWordsInBatch) * BitWord::WordLen; } _lastValue = _lastWords[index % NumWordsInBatch]; - _lastMaxDocIdLimit = (index + 1) * WordLen; + _lastMaxDocIdLimit = (index + 1) * BitWord::WordLen; } } @@ -94,7 +94,7 @@ MultiBitVectorIterator<Update>::doSeek(uint32_t docId) { updateLastValue(docId); if (__builtin_expect( ! isAtEnd(), true)) { - if (_lastValue & mask(docId)) { + if (_lastValue & BitWord::mask(docId)) { setDocId(docId); } } @@ -102,13 +102,13 @@ MultiBitVectorIterator<Update>::doSeek(uint32_t docId) template<typename Update> void -MultiBitVectorIterator<Update>::strictSeek(uint32_t docId) +MultiBitVectorIterator<Update>::strictSeek(uint32_t docId) noexcept { - for (updateLastValue(docId), _lastValue = _lastValue & checkTab(docId); + for (updateLastValue(docId), _lastValue = _lastValue & BitWord::checkTab(docId); (_lastValue == 0) && __builtin_expect(! isAtEnd(), true); updateLastValue(_lastMaxDocIdLimit)); if (__builtin_expect(!isAtEnd(), true)) { - docId = _lastMaxDocIdLimit - WordLen + vespalib::Optimized::lsbIdx(_lastValue); + docId = _lastMaxDocIdLimit - BitWord::WordLen + vespalib::Optimized::lsbIdx(_lastValue); if (__builtin_expect(docId >= _numDocs, false)) { setAtEnd(); } else { diff --git a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.h b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.h index d75a9ddd357..d99e439af0b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.h +++ b/searchlib/src/vespa/searchlib/queryeval/multibitvectoriterator.h @@ -8,7 +8,7 @@ namespace search::queryeval { -class MultiBitVectorIteratorBase : public MultiSearch, protected BitWord +class MultiBitVectorIteratorBase : public MultiSearch { public: ~MultiBitVectorIteratorBase() override; @@ -20,7 +20,8 @@ public: */ static SearchIterator::UP optimize(SearchIterator::UP parent); protected: - MultiBitVectorIteratorBase(Children hildren); + using Word = BitWord::Word; + MultiBitVectorIteratorBase(Children children); using MetaWord = std::pair<const void *, bool>; uint32_t _numDocs; @@ -29,7 +30,7 @@ protected: Word _lastValue; // Last value computed std::vector<MetaWord> _bvs; private: - virtual bool acceptExtraFilter() const = 0; + virtual bool acceptExtraFilter() const noexcept = 0; UP andWith(UP filter, uint32_t estimate) override; void doUnpack(uint32_t docid) override; static SearchIterator::UP optimizeMultiSearch(SearchIterator::UP parent); diff --git a/searchlib/src/vespa/searchlib/queryeval/searchiterator.h b/searchlib/src/vespa/searchlib/queryeval/searchiterator.h index b58d7ceed43..4ab066727af 100644 --- a/searchlib/src/vespa/searchlib/queryeval/searchiterator.h +++ b/searchlib/src/vespa/searchlib/queryeval/searchiterator.h @@ -56,7 +56,7 @@ protected: * * @param id docid for hit **/ - void setDocId(uint32_t id) { _docid = id; } + void setDocId(uint32_t id) noexcept { _docid = id; } /** * Used to adjust the end of the legal docid range. @@ -64,13 +64,13 @@ protected: * * @param end_id the first docid outside the legal iterator range */ - void setEndId(uint32_t end_id) { _endid = end_id; } + void setEndId(uint32_t end_id) noexcept { _endid = end_id; } /** * Will terminate the iterator by setting it past the end. * Further calls to isAtEnd() will then return true. */ - void setAtEnd() { _docid = search::endDocId; } + void setAtEnd() noexcept { _docid = search::endDocId; } public: using Trinary=vespalib::Trinary; @@ -180,7 +180,7 @@ public: /** * The constructor sets the current document id to @ref beginId. **/ - SearchIterator() : _docid(0), _endid(0) { } + SearchIterator() noexcept : _docid(0), _endid(0) { } SearchIterator(const SearchIterator &) = delete; SearchIterator &operator=(const SearchIterator &) = delete; @@ -192,15 +192,15 @@ public: * * @return constant **/ - static uint32_t beginId() { return beginDocId; } + static uint32_t beginId() noexcept { return beginDocId; } /** * Tell if the iterator has reached the end. * * @return true if the iterator has reached its end. **/ - bool isAtEnd() const { return isAtEnd(_docid); } - bool isAtEnd(uint32_t docid) const { + bool isAtEnd() const noexcept { return isAtEnd(_docid); } + bool isAtEnd(uint32_t docid) const noexcept { if (__builtin_expect(docid >= _endid, false)) { return true; } @@ -214,9 +214,9 @@ public: * * @return current document id **/ - uint32_t getDocId() const { return _docid; } + uint32_t getDocId() const noexcept { return _docid; } - uint32_t getEndId() const { return _endid; } + uint32_t getEndId() const noexcept { return _endid; } /** * Check if the given document id is a hit. If it is a hit, the diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp index 590223ed13a..1f3b2d29744 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.cpp @@ -6,32 +6,32 @@ namespace vespalib::hwaccelrated { size_t -Avx2Accelrator::populationCount(const uint64_t *a, size_t sz) const { +Avx2Accelrator::populationCount(const uint64_t *a, size_t sz) const noexcept { return helper::populationCount(a, sz); } double -Avx2Accelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const { +Avx2Accelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept { return helper::squaredEuclideanDistance(a, b, sz); } double -Avx2Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { +Avx2Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept { return avx::euclideanDistanceSelectAlignment<float, 32>(a, b, sz); } double -Avx2Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { +Avx2Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept { return avx::euclideanDistanceSelectAlignment<double, 32>(a, b, sz); } void -Avx2Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +Avx2Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::andChunks<32u, 2u>(offset, src, dest); } void -Avx2Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +Avx2Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::orChunks<32u, 2u>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h index 2949e81fd36..1166282fbe8 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx2.h @@ -12,12 +12,12 @@ namespace vespalib::hwaccelrated { class Avx2Accelrator : public GenericAccelrator { public: - size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const override; - double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; - void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + size_t populationCount(const uint64_t *a, size_t sz) const noexcept override; + double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp index 5878165bb6d..1648f80c9e9 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.cpp @@ -6,44 +6,42 @@ namespace vespalib:: hwaccelrated { float -Avx512Accelrator::dotProduct(const float * af, const float * bf, size_t sz) const -{ +Avx512Accelrator::dotProduct(const float * af, const float * bf, size_t sz) const noexcept { return avx::dotProductSelectAlignment<float, 64>(af, bf, sz); } double -Avx512Accelrator::dotProduct(const double * af, const double * bf, size_t sz) const -{ +Avx512Accelrator::dotProduct(const double * af, const double * bf, size_t sz) const noexcept { return avx::dotProductSelectAlignment<double, 64>(af, bf, sz); } size_t -Avx512Accelrator::populationCount(const uint64_t *a, size_t sz) const { +Avx512Accelrator::populationCount(const uint64_t *a, size_t sz) const noexcept { return helper::populationCount(a, sz); } double -Avx512Accelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const { +Avx512Accelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept { return helper::squaredEuclideanDistance(a, b, sz); } double -Avx512Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { +Avx512Accelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept { return avx::euclideanDistanceSelectAlignment<float, 64>(a, b, sz); } double -Avx512Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { +Avx512Accelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept { return avx::euclideanDistanceSelectAlignment<double, 64>(a, b, sz); } void -Avx512Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +Avx512Accelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::andChunks<64, 1>(offset, src, dest); } void -Avx512Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +Avx512Accelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::orChunks<64, 1>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h index 4989f72e698..3dc207e8ade 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avx512.h @@ -12,14 +12,14 @@ namespace vespalib::hwaccelrated { class Avx512Accelrator : public Avx2Accelrator { public: - float dotProduct(const float * a, const float * b, size_t sz) const override; - double dotProduct(const double * a, const double * b, size_t sz) const override; - size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const override; - double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; - void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + float dotProduct(const float * a, const float * b, size_t sz) const noexcept override; + double dotProduct(const double * a, const double * b, size_t sz) const noexcept override; + size_t populationCount(const uint64_t *a, size_t sz) const noexcept override; + double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp b/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp index 3bdbb7a81ff..e1cea280d0c 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/avxprivate.hpp @@ -8,12 +8,12 @@ namespace vespalib::hwaccelrated::avx { namespace { -inline bool validAlignment(const void * p, const size_t align) { +inline bool validAlignment(const void * p, const size_t align) noexcept { return (reinterpret_cast<uint64_t>(p) & (align-1)) == 0; } template <typename T, typename V> -T sumT(const V & v) { +T sumT(const V & v) noexcept { T sum(0); for (size_t i(0); i < (sizeof(V)/sizeof(T)); i++) { sum += v[i]; @@ -22,7 +22,7 @@ T sumT(const V & v) { } template <typename T, size_t C> -T sumR(const T * v) { +T sumR(const T * v) noexcept { if (C == 1) { return v[0]; } else if (C == 2) { @@ -33,10 +33,10 @@ T sumR(const T * v) { } template <typename T, size_t VLEN, unsigned AlignA, unsigned AlignB, size_t VectorsPerChunk> -static T computeDotProduct(const T * af, const T * bf, size_t sz) __attribute__((noinline)); +static T computeDotProduct(const T * af, const T * bf, size_t sz) noexcept __attribute__((noinline)); template <typename T, size_t VLEN, unsigned AlignA, unsigned AlignB, size_t VectorsPerChunk> -T computeDotProduct(const T * af, const T * bf, size_t sz) +T computeDotProduct(const T * af, const T * bf, size_t sz) noexcept { constexpr const size_t ChunkSize = VLEN*VectorsPerChunk/sizeof(T); typedef T V __attribute__ ((vector_size (VLEN))); @@ -65,10 +65,10 @@ T computeDotProduct(const T * af, const T * bf, size_t sz) } template <typename T, size_t VLEN, size_t VectorsPerChunk=4> -VESPA_DLL_LOCAL T dotProductSelectAlignment(const T * af, const T * bf, size_t sz); +VESPA_DLL_LOCAL T dotProductSelectAlignment(const T * af, const T * bf, size_t sz) noexcept; template <typename T, size_t VLEN, size_t VectorsPerChunk> -T dotProductSelectAlignment(const T * af, const T * bf, size_t sz) +T dotProductSelectAlignment(const T * af, const T * bf, size_t sz) noexcept { if (validAlignment(af, VLEN)) { if (validAlignment(bf, VLEN)) { @@ -87,7 +87,7 @@ T dotProductSelectAlignment(const T * af, const T * bf, size_t sz) template <typename T, unsigned VLEN, unsigned AlignA, unsigned AlignB> double -euclideanDistanceT(const T * af, const T * bf, size_t sz) +euclideanDistanceT(const T * af, const T * bf, size_t sz) noexcept { constexpr unsigned VectorsPerChunk = 4; constexpr unsigned ChunkSize = VLEN*VectorsPerChunk/sizeof(T); @@ -115,7 +115,7 @@ euclideanDistanceT(const T * af, const T * bf, size_t sz) } template <typename T, unsigned VLEN> -double euclideanDistanceSelectAlignment(const T * af, const T * bf, size_t sz) +double euclideanDistanceSelectAlignment(const T * af, const T * bf, size_t sz) noexcept { constexpr unsigned ALIGN = 32; if (validAlignment(af, ALIGN)) { diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp index 13946fa3398..dcc1189e35d 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.cpp @@ -10,7 +10,7 @@ namespace { template <typename ACCUM, typename T, size_t UNROLL> ACCUM -multiplyAdd(const T * a, const T * b, size_t sz) +multiplyAdd(const T * a, const T * b, size_t sz) noexcept { ACCUM partial[UNROLL]; for (size_t i(0); i < UNROLL; i++) { @@ -34,7 +34,7 @@ multiplyAdd(const T * a, const T * b, size_t sz) template <typename T, size_t UNROLL> double -squaredEuclideanDistanceT(const T * a, const T * b, size_t sz) +squaredEuclideanDistanceT(const T * a, const T * b, size_t sz) noexcept { T partial[UNROLL]; for (size_t i(0); i < UNROLL; i++) { @@ -60,7 +60,7 @@ squaredEuclideanDistanceT(const T * a, const T * b, size_t sz) template<size_t UNROLL, typename Operation> void -bitOperation(Operation operation, void * aOrg, const void * bOrg, size_t bytes) { +bitOperation(Operation operation, void * aOrg, const void * bOrg, size_t bytes) noexcept { const size_t sz(bytes/sizeof(uint64_t)); { @@ -87,59 +87,59 @@ bitOperation(Operation operation, void * aOrg, const void * bOrg, size_t bytes) } float -GenericAccelrator::dotProduct(const float * a, const float * b, size_t sz) const +GenericAccelrator::dotProduct(const float * a, const float * b, size_t sz) const noexcept { return cblas_sdot(sz, a, 1, b, 1); } double -GenericAccelrator::dotProduct(const double * a, const double * b, size_t sz) const +GenericAccelrator::dotProduct(const double * a, const double * b, size_t sz) const noexcept { return cblas_ddot(sz, a, 1, b, 1); } int64_t -GenericAccelrator::dotProduct(const int8_t * a, const int8_t * b, size_t sz) const +GenericAccelrator::dotProduct(const int8_t * a, const int8_t * b, size_t sz) const noexcept { return multiplyAdd<int64_t, int8_t, 8>(a, b, sz); } int64_t -GenericAccelrator::dotProduct(const int16_t * a, const int16_t * b, size_t sz) const +GenericAccelrator::dotProduct(const int16_t * a, const int16_t * b, size_t sz) const noexcept { return multiplyAdd<int64_t, int16_t, 8>(a, b, sz); } int64_t -GenericAccelrator::dotProduct(const int32_t * a, const int32_t * b, size_t sz) const +GenericAccelrator::dotProduct(const int32_t * a, const int32_t * b, size_t sz) const noexcept { return multiplyAdd<int64_t, int32_t, 8>(a, b, sz); } long long -GenericAccelrator::dotProduct(const int64_t * a, const int64_t * b, size_t sz) const +GenericAccelrator::dotProduct(const int64_t * a, const int64_t * b, size_t sz) const noexcept { return multiplyAdd<long long, int64_t, 8>(a, b, sz); } void -GenericAccelrator::orBit(void * aOrg, const void * bOrg, size_t bytes) const +GenericAccelrator::orBit(void * aOrg, const void * bOrg, size_t bytes) const noexcept { bitOperation<8>([](uint64_t a, uint64_t b) { return a | b; }, aOrg, bOrg, bytes); } void -GenericAccelrator::andBit(void * aOrg, const void * bOrg, size_t bytes) const +GenericAccelrator::andBit(void * aOrg, const void * bOrg, size_t bytes) const noexcept { bitOperation<8>([](uint64_t a, uint64_t b) { return a & b; }, aOrg, bOrg, bytes); } void -GenericAccelrator::andNotBit(void * aOrg, const void * bOrg, size_t bytes) const +GenericAccelrator::andNotBit(void * aOrg, const void * bOrg, size_t bytes) const noexcept { bitOperation<8>([](uint64_t a, uint64_t b) { return a & ~b; }, aOrg, bOrg, bytes); } void -GenericAccelrator::notBit(void * aOrg, size_t bytes) const +GenericAccelrator::notBit(void * aOrg, size_t bytes) const noexcept { auto a(static_cast<uint64_t *>(aOrg)); const size_t sz(bytes/sizeof(uint64_t)); @@ -153,32 +153,32 @@ GenericAccelrator::notBit(void * aOrg, size_t bytes) const } size_t -GenericAccelrator::populationCount(const uint64_t *a, size_t sz) const { +GenericAccelrator::populationCount(const uint64_t *a, size_t sz) const noexcept { return helper::populationCount(a, sz); } double -GenericAccelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const { +GenericAccelrator::squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept { return helper::squaredEuclideanDistance(a, b, sz); } double -GenericAccelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const { +GenericAccelrator::squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept { return squaredEuclideanDistanceT<float, 2>(a, b, sz); } double -GenericAccelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const { +GenericAccelrator::squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept { return squaredEuclideanDistanceT<double, 2>(a, b, sz); } void -GenericAccelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +GenericAccelrator::and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::andChunks<16, 4>(offset, src, dest); } void -GenericAccelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const { +GenericAccelrator::or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept { helper::orChunks<16,4>(offset, src, dest); } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h index 315e807da07..13c347df80f 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/generic.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/generic.h @@ -12,22 +12,22 @@ namespace vespalib::hwaccelrated { class GenericAccelrator : public IAccelrated { public: - float dotProduct(const float * a, const float * b, size_t sz) const override; - double dotProduct(const double * a, const double * b, size_t sz) const override; - int64_t dotProduct(const int8_t * a, const int8_t * b, size_t sz) const override; - int64_t dotProduct(const int16_t * a, const int16_t * b, size_t sz) const override; - int64_t dotProduct(const int32_t * a, const int32_t * b, size_t sz) const override; - long long dotProduct(const int64_t * a, const int64_t * b, size_t sz) const override; - void orBit(void * a, const void * b, size_t bytes) const override; - void andBit(void * a, const void * b, size_t bytes) const override; - void andNotBit(void * a, const void * b, size_t bytes) const override; - void notBit(void * a, size_t bytes) const override; - size_t populationCount(const uint64_t *a, size_t sz) const override; - double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const override; - double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const override; - double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const override; - void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; - void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const override; + float dotProduct(const float * a, const float * b, size_t sz) const noexcept override; + double dotProduct(const double * a, const double * b, size_t sz) const noexcept override; + int64_t dotProduct(const int8_t * a, const int8_t * b, size_t sz) const noexcept override; + int64_t dotProduct(const int16_t * a, const int16_t * b, size_t sz) const noexcept override; + int64_t dotProduct(const int32_t * a, const int32_t * b, size_t sz) const noexcept override; + long long dotProduct(const int64_t * a, const int64_t * b, size_t sz) const noexcept override; + void orBit(void * a, const void * b, size_t bytes) const noexcept override; + void andBit(void * a, const void * b, size_t bytes) const noexcept override; + void andNotBit(void * a, const void * b, size_t bytes) const noexcept override; + void notBit(void * a, size_t bytes) const noexcept override; + size_t populationCount(const uint64_t *a, size_t sz) const noexcept override; + double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept override; + double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept override; + void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; + void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept override; }; } diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h index 73740858a41..c9b1f7cd45c 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.h @@ -17,24 +17,24 @@ class IAccelrated public: virtual ~IAccelrated() = default; using UP = std::unique_ptr<IAccelrated>; - virtual float dotProduct(const float * a, const float * b, size_t sz) const = 0; - virtual double dotProduct(const double * a, const double * b, size_t sz) const = 0; - virtual int64_t dotProduct(const int8_t * a, const int8_t * b, size_t sz) const = 0; - virtual int64_t dotProduct(const int16_t * a, const int16_t * b, size_t sz) const = 0; - virtual int64_t dotProduct(const int32_t * a, const int32_t * b, size_t sz) const = 0; - virtual long long dotProduct(const int64_t * a, const int64_t * b, size_t sz) const = 0; - virtual void orBit(void * a, const void * b, size_t bytes) const = 0; - virtual void andBit(void * a, const void * b, size_t bytes) const = 0; - virtual void andNotBit(void * a, const void * b, size_t bytes) const = 0; - virtual void notBit(void * a, size_t bytes) const = 0; - virtual size_t populationCount(const uint64_t *a, size_t sz) const = 0; - virtual double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const = 0; - virtual double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const = 0; - virtual double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const = 0; + virtual float dotProduct(const float * a, const float * b, size_t sz) const noexcept = 0; + virtual double dotProduct(const double * a, const double * b, size_t sz) const noexcept = 0; + virtual int64_t dotProduct(const int8_t * a, const int8_t * b, size_t sz) const noexcept = 0; + virtual int64_t dotProduct(const int16_t * a, const int16_t * b, size_t sz) const noexcept = 0; + virtual int64_t dotProduct(const int32_t * a, const int32_t * b, size_t sz) const noexcept = 0; + virtual long long dotProduct(const int64_t * a, const int64_t * b, size_t sz) const noexcept = 0; + virtual void orBit(void * a, const void * b, size_t bytes) const noexcept = 0; + virtual void andBit(void * a, const void * b, size_t bytes) const noexcept = 0; + virtual void andNotBit(void * a, const void * b, size_t bytes) const noexcept = 0; + virtual void notBit(void * a, size_t bytes) const noexcept = 0; + virtual size_t populationCount(const uint64_t *a, size_t sz) const noexcept = 0; + virtual double squaredEuclideanDistance(const int8_t * a, const int8_t * b, size_t sz) const noexcept = 0; + virtual double squaredEuclideanDistance(const float * a, const float * b, size_t sz) const noexcept = 0; + virtual double squaredEuclideanDistance(const double * a, const double * b, size_t sz) const noexcept = 0; // AND 64 bytes from multiple, optionally inverted sources - virtual void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const = 0; + virtual void and64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept = 0; // OR 64 bytes from multiple, optionally inverted sources - virtual void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const = 0; + virtual void or64(size_t offset, const std::vector<std::pair<const void *, bool>> &src, void *dest) const noexcept = 0; static const IAccelrated & getAccelerator() __attribute__((noinline)); }; |