1 /* ************************************************************************
2  * Copyright 2013 Advanced Micro Devices, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * ************************************************************************/
16 
17 #ifndef TILE_ITER_H
18 #define TILE_ITER_H
19 
20 #include "blas_kgen.h"
21 
22 typedef enum TileIterFlags {
23     // iterate in the backward direction along logical rows
24     TILE_ITER_BACKWARD_ROWS = 0x01,
25     // iterate in the backward direction along logical columns
26     TILE_ITER_BACKWARD_COLS = 0x02
27 } TileIterFlags;
28 
29 typedef enum PhyIterFlags {
30     PHY_ITER_BACKWARD_LINES = 0x01,
31     PHY_ITER_BACKWARD_VECS = 0x02,
32 } PhyIterFlags;
33 
34 typedef struct PhysTileIterator {
35     int row;   // logical tile row
36     int col;   // logical tile column
37 
38     int phyIterFlags;
39     int isLogRowMaj;
40 
41     int vecLen;
42 
43     int line;     // physical line
44     int vec;      // vector in physical line
45 
46     int nrLines;   // physical line number
47     int nrVecs;    // physical vec number
48 
49 } PhysTileIterator;
50 
51 //-----------------------------------------------------------------------------
52 
53 int
54 iterInit(PhysTileIterator *iter,
55     const Tile *tile,
56     int vecLen,
57     unsigned int tileIterFlags);
58 
59 int
60 iterIterate(PhysTileIterator *iter);
61 
62 /*
63  * Check if the entire tile has been iterated. Return true if the iterator is
64  * at the next element beyond the last.
65  */
66 int
67 iterIsEnd(const PhysTileIterator *iter);
68 
69 int
70 iterSeek( PhysTileIterator *iter,
71     int row,
72     int col );
73 
74 int
75 iterSeekPhys( PhysTileIterator *iter,
76     int line,
77     int vec );
78 
79 #endif
80