• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // iterator.h: Const forward iterators for VectorMap and VectorDup that help
16 // access data in architecture specific way, e.g. 4 elements at a time for NEON.
17 
18 #ifndef GEMMLOWP_INTERNAL_ITERATOR_H_
19 #define GEMMLOWP_INTERNAL_ITERATOR_H_
20 
21 namespace gemmlowp {
22 
23 enum class VectorShape;
24 
25 // ConstIterator is a forward only constant iterator that can be made
26 // architecture specific e.g. to return 4 values at once for NEON.
27 template <typename VectorType> class ConstIterator {
28   // Unused default case.
29 };
30 
31 template <typename tScalar, VectorShape tShape> class VectorMap;
32 
33 template <typename tScalar, VectorShape tShape>
34 class ConstIterator<VectorMap<tScalar, tShape>> {
35  public:
36   typedef tScalar Scalar;
ConstIterator(const VectorMap<tScalar,tShape> & vector_map)37   ConstIterator(const VectorMap<tScalar, tShape>& vector_map)
38       : pointer_(vector_map.data()) {}
39   const Scalar operator*() const { return *pointer_; }
get()40   const Scalar* get() const { return pointer_; }
41   ConstIterator& operator+=(int inc) { pointer_ += inc; return *this; }
42  private:
43   const Scalar* pointer_;
44 };
45 
46 template <typename tScalar, VectorShape tShape>
const_iterator(const VectorMap<tScalar,tShape> & vector_map)47 ConstIterator<VectorMap<tScalar, tShape>> const_iterator(
48     const VectorMap<tScalar, tShape>& vector_map) {
49   return ConstIterator<VectorMap<tScalar, tShape>>(vector_map);
50 }
51 
52 template <typename tScalar, VectorShape tShape> class VectorDup;
53 
54 template <typename tScalar, VectorShape tShape>
55 class ConstIterator<VectorDup<tScalar, tShape>> {
56  public:
57   typedef tScalar Scalar;
ConstIterator(const VectorDup<tScalar,tShape> & vector_dup)58   ConstIterator(const VectorDup<tScalar, tShape>& vector_dup)
59       : data_(vector_dup(0)) {}
60   const Scalar operator*() const { return data_; }
get()61   const Scalar* get() const { return &data_; }
62   ConstIterator& operator+=(int inc) { return *this; }
63  private:
64   Scalar data_;
65 };
66 
67 template <typename tScalar, VectorShape tShape>
const_iterator(const VectorDup<tScalar,tShape> & vector_map)68 ConstIterator<VectorDup<tScalar, tShape>> const_iterator(
69     const VectorDup<tScalar, tShape>& vector_map) {
70   return ConstIterator<VectorDup<tScalar, tShape>>(vector_map);
71 }
72 
73 }  // namespace gemmlowp
74 
75 #endif  // GEMMLOWP_INTERNAL_ITERATOR_H_
76