13ce311afSJiri Olsa /* SPDX-License-Identifier: GPL-2.0 */
23ce311afSJiri Olsa #ifndef __LIBPERF_INTERNAL_XYARRAY_H
33ce311afSJiri Olsa #define __LIBPERF_INTERNAL_XYARRAY_H
43ce311afSJiri Olsa
53ce311afSJiri Olsa #include <linux/compiler.h>
63ce311afSJiri Olsa #include <sys/types.h>
73ce311afSJiri Olsa
83ce311afSJiri Olsa struct xyarray {
93ce311afSJiri Olsa size_t row_size;
103ce311afSJiri Olsa size_t entry_size;
113ce311afSJiri Olsa size_t entries;
123ce311afSJiri Olsa size_t max_x;
133ce311afSJiri Olsa size_t max_y;
143ce311afSJiri Olsa char contents[] __aligned(8);
153ce311afSJiri Olsa };
163ce311afSJiri Olsa
173ce311afSJiri Olsa struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size);
183ce311afSJiri Olsa void xyarray__delete(struct xyarray *xy);
193ce311afSJiri Olsa void xyarray__reset(struct xyarray *xy);
203ce311afSJiri Olsa
__xyarray__entry(struct xyarray * xy,int x,int y)21*81886948SRob Herring static inline void *__xyarray__entry(struct xyarray *xy, int x, int y)
223ce311afSJiri Olsa {
233ce311afSJiri Olsa return &xy->contents[x * xy->row_size + y * xy->entry_size];
243ce311afSJiri Olsa }
253ce311afSJiri Olsa
xyarray__entry(struct xyarray * xy,size_t x,size_t y)26*81886948SRob Herring static inline void *xyarray__entry(struct xyarray *xy, size_t x, size_t y)
27*81886948SRob Herring {
28*81886948SRob Herring if (x >= xy->max_x || y >= xy->max_y)
29*81886948SRob Herring return NULL;
30*81886948SRob Herring return __xyarray__entry(xy, x, y);
31*81886948SRob Herring }
32*81886948SRob Herring
xyarray__max_y(struct xyarray * xy)333ce311afSJiri Olsa static inline int xyarray__max_y(struct xyarray *xy)
343ce311afSJiri Olsa {
353ce311afSJiri Olsa return xy->max_y;
363ce311afSJiri Olsa }
373ce311afSJiri Olsa
xyarray__max_x(struct xyarray * xy)383ce311afSJiri Olsa static inline int xyarray__max_x(struct xyarray *xy)
393ce311afSJiri Olsa {
403ce311afSJiri Olsa return xy->max_x;
413ce311afSJiri Olsa }
423ce311afSJiri Olsa
433ce311afSJiri Olsa #endif /* __LIBPERF_INTERNAL_XYARRAY_H */
44