1#ifndef HEX_DUMP_H
2#define HEX_DUMP_H
3
4#include <HAP_farf.h>
5
6static inline void hex_dump_int8_line(char * pref, const int8_t * x, int n) {
7 char str[1024], *p = str, *p_end = str + sizeof(str);
8 p += snprintf(p, p_end - p, "%s: ", pref);
9 for (int i = 0; i < n && p < p_end; i++) {
10 p += snprintf(p, p_end - p, "%d, ", x[i]);
11 }
12 FARF(HIGH, "%s\n", str);
13}
14
15static inline void hex_dump_uint8_line(char * pref, const uint8_t * x, uint32_t n) {
16 char str[1024], *p = str, *p_end = str + sizeof(str);
17 p += snprintf(p, p_end - p, "%s: ", pref);
18 for (int i = 0; i < n && p < p_end; i++) {
19 p += snprintf(p, p_end - p, "%d, ", x[i]);
20 }
21 FARF(HIGH, "%s\n", str);
22}
23
24static inline void hex_dump_int32_line(char * pref, const int32_t * x, uint32_t n) {
25 char str[1024], *p = str, *p_end = str + sizeof(str);
26 p += snprintf(p, p_end - p, "%s: ", pref);
27 for (int i = 0; i < n; i++) {
28 p += snprintf(p, p_end - p, "%d, ", (int) x[i]);
29 }
30 FARF(HIGH, "%s\n", str);
31}
32
33static inline void hex_dump_f16_line(char * pref, const __fp16 * x, uint32_t n) {
34 char str[1024], *p = str, *p_end = str + sizeof(str);
35 p += snprintf(p, p_end - p, "%s: ", pref);
36 for (int i = 0; i < n; i++) {
37 p += snprintf(p, p_end - p, "%.6f, ", (float) x[i]);
38 }
39 FARF(HIGH, "%s\n", str);
40}
41
42static inline void hex_dump_f32_line(char * pref, const float * x, uint32_t n) {
43 char str[1024], *p = str, *p_end = str + sizeof(str);
44 p += snprintf(p, p_end - p, "%s: ", pref);
45 for (int i = 0; i < n; i++) {
46 p += snprintf(p, p_end - p, "%.6f, ", x[i]);
47 }
48 FARF(HIGH, "%s\n", str);
49}
50
51static inline void hex_dump_f32(char * pref, const float * x, uint32_t n) {
52 uint32_t n0 = n / 16;
53 uint32_t n1 = n % 16;
54
55 uint32_t i = 0;
56 for (; i < n0; i++) {
57 hex_dump_f32_line(pref, x + (16 * i), 16);
58 }
59 if (n1) {
60 hex_dump_f32_line(pref, x + (16 * i), n1);
61 }
62}
63
64static inline void hex_dump_f16(char * pref, const __fp16 * x, uint32_t n) {
65 uint32_t n0 = n / 16;
66 uint32_t n1 = n % 16;
67
68 uint32_t i = 0;
69 for (; i < n0; i++) {
70 hex_dump_f16_line(pref, x + (16 * i), 16);
71 }
72 if (n1) {
73 hex_dump_f16_line(pref, x + (16 * i), n1);
74 }
75}
76
77#endif /* HEX_DUMP_H */