swar-array_ops.c
3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
////A: --has-swar
//C: -daiteq-swar-enable
//typedef unsigned int s10x3b __attribute__((subword(3)));
//typedef unsigned int s1x3b __attribute__((subword(3,1)));
typedef unsigned int swpack __attribute__((subword(8)));
typedef unsigned int swelm __attribute__((subword(8,1)));
#define NUMELMS 50
#define BITSZ 8
#define ELMMASK ((1<<BITSZ)-1)
#define PACKING (32/BITSZ)
#define NUMFULLSW (NUMELMS/PACKING)
#define ARRAY_SIZE (NUMFULLSW + ((NUMELMS-(NUMFULLSW*PACKING)) ? 1 : 0))
#define MAXVAL ((1<<BITSZ)-2)
swpack arr[ARRAY_SIZE]; /* pole swarovych slov se zapakovanymi elementy */
swelm elms[NUMELMS]; /* pole elementu */
volatile int gbuf[PACKING];
int main(void)
{
volatile int sz;
volatile swpack swp;
volatile swelm se;// = {3};
volatile unsigned top = 199;
unsigned i, j;
#if 0
sz = ARRAY_SIZE; /* = 5 */
sz = NUMELMS; /* = 50 */
sz = sizeof(arr); /* = 20 */
sz = sizeof(elms); /* = 200 */
sz = sizeof(swp); /* = 4 = velikost pakovaneho slova v bytech */
sz = sizeof(se); /* = 4 */
sz = sizeofswar(arr); /* = 0 */
sz = sizeofswar(elms); /* = 0 */
sz = sizeofswar(swp); /* = 3 */
sz = sizeofswar(se); /* = 3 */
#endif
#if 1
//swp = 0;
//swp = (swpack)0;
//swp = 01234567123; // oct
//swp = (swpack)0x12345;
//// swp = (swpack){1,2,3,4,5,6,7,0,1,2};
////swp = (swpack){se,0,se,se,se,0,0,0,se,se};
//*((unsigned *)&swp) = 05647301234;
//for (int i=0;i<PACKING;++i)
//swp[i] = 4;
//for (int i=0;i<PACKING;++i)
//swp[i] = i & ELMMASK;
// sz = swp[2];
// {
for (int i=0;i<PACKING;++i) {
// sz = swp[i];
sz = swp[i];
// sz = se[0];
}
#endif
#if 1
// se = 0;
// se = (swelm)0;
// se = 2;
// se = (swelm)3
// *((unsigned *)&se) = 7;
// *((unsigned *)&se) = 0;
#endif
#if 0
swp[1] = 0;
// swp[2] = (swelm)2;
swp[3] = 3;
// swp[4] = (swelm)0;
#endif
#if 1
arr[0] = swp;
arr[1] = 0;
arr[2] = 0x1234567;
arr[3][1] =0;
arr[4][1] =2;
for (i=0;i<PACKING;++i)
arr[1][i] = 4;
for (i=0;i<PACKING;++i)
arr[1][i] = i & ELMMASK;
for (int a=0;a<ARRAY_SIZE;++a) {
for (int e=0;e<PACKING;++e)
arr[a][e] = 6;
}
for (int a=0;a<ARRAY_SIZE;++a) {
for (int e=0;e<PACKING;++e)
arr[a][e] = a;
}
for (i=0;i<PACKING;++i)
sz = arr[2][i];
for (int a=0;a<ARRAY_SIZE;++a) {
for (int e=0;e<PACKING;++e)
sz = arr[a][e];
}
for (i=0;i<((top-1)/PACKING)+1;i++) {
for (j=0;j<PACKING;j++) {
arr[i][j]=1;
}
}
for (i=0;i<NUMELMS;++i) {
sz = arr[i/PACKING][i%PACKING];
}
#endif
#if 0
// if (swp) sz = 1;
//if (swp[5])
//sz = 1;
//else
//sz = 0;
if (swp[sz]) sz = 1;
if ( arr[sz][4] == 4) sz = 1;
if ( arr[sz][sz]>sz ) sz = 1;
#endif
#if 0
unsigned sqr, k, val;
top = NUMELMS;
k=0;
for (i=0;i<(top-1)/PACKING+1;i++) {
arr[i]=0;
val=0;
for (j=0;j<PACKING;j++) {
sqr=k*k;
if (sqr<MAXVAL) {
val |= (sqr<<(j*BITSZ));
arr[i][j]=sqr;
} else {
val |= (MAXVAL<<(j*BITSZ));
// c[i][j]=MAXVAL;
}
// m_print("k "); i_print(k); m_print(" sqr "); i_print(sqr); m_print(" val "); i_hexprint(val); NL;
k++;
}
}
#endif
return 0;
}