Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/*	$NetBSD: rf_nwayxor.c,v 1.11 2006/11/16 01:33:23 christos Exp $	*/
/*
 * Copyright (c) 1995 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Mark Holland, Daniel Stodolsky
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

/************************************************************
 *
 * nwayxor.c -- code to do N-way xors for reconstruction
 *
 * nWayXorN xors N input buffers into the destination buffer.
 * adapted from danner's longword_bxor code.
 *
 ************************************************************/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rf_nwayxor.c,v 1.11 2006/11/16 01:33:23 christos Exp $");

#include "rf_nwayxor.h"
#include "rf_shutdown.h"

static int callcount[10];
static void rf_ShutdownNWayXor(void *);

static void
rf_ShutdownNWayXor(void *ignored)
{
	int     i;

	if (rf_showXorCallCounts == 0)
		return;
	printf("Call counts for n-way xor routines:  ");
	for (i = 0; i < 10; i++)
		printf("%d ", callcount[i]);
	printf("\n");
}

int
rf_ConfigureNWayXor(RF_ShutdownList_t **listp)
{
	int     i;

	for (i = 0; i < 10; i++)
		callcount[i] = 0;
	rf_ShutdownCreate(listp, rf_ShutdownNWayXor, NULL);
	return (0);
}

void
rf_nWayXor1(RF_ReconBuffer_t **src_rbs,	RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *src = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *dest = (unsigned long *) dest_rb->buffer;
	unsigned long *end = src + len;
	unsigned long d0, d1, d2, d3, s0, s1, s2, s3;

	callcount[1]++;
	while (len >= 4) {
		d0 = dest[0];
		d1 = dest[1];
		d2 = dest[2];
		d3 = dest[3];
		s0 = src[0];
		s1 = src[1];
		s2 = src[2];
		s3 = src[3];
		dest[0] = d0 ^ s0;
		dest[1] = d1 ^ s1;
		dest[2] = d2 ^ s2;
		dest[3] = d3 ^ s3;
		src += 4;
		dest += 4;
		len -= 4;
	}
	while (src < end) {
		*dest++ ^= *src++;
	}
}

void
rf_nWayXor2(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *a = dst;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[2]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ = *a++ ^ *b++ ^ *c++;
		len--;
	}
	while (len > 4) {
		a0 = a[0];
		len -= 4;

		a1 = a[1];
		a2 = a[2];

		a3 = a[3];
		a += 4;

		b0 = b[0];
		b1 = b[1];

		b2 = b[2];
		b3 = b[3];
		/* start dual issue */
		a0 ^= b0;
		b0 = c[0];

		b += 4;
		a1 ^= b1;

		a2 ^= b2;
		a3 ^= b3;

		b1 = c[1];
		a0 ^= b0;

		b2 = c[2];
		a1 ^= b1;

		b3 = c[3];
		a2 ^= b2;

		dst[0] = a0;
		a3 ^= b3;
		dst[1] = a1;
		c += 4;
		dst[2] = a2;
		dst[3] = a3;
		dst += 4;
	}
	while (len) {
		*dst++ = *a++ ^ *b++ ^ *c++;
		len--;
	}
}
/* note that first arg is not incremented but 2nd arg is */
#define LOAD_FIRST(_dst,_b) \
  a0 = _dst[0]; len -= 4;   \
  a1 = _dst[1];             \
  a2 = _dst[2];             \
  a3 = _dst[3];             \
  b0 = _b[0];               \
  b1 = _b[1];               \
  b2 = _b[2];               \
  b3 = _b[3];  _b += 4;

/* note: arg is incremented */
#define XOR_AND_LOAD_NEXT(_n) \
  a0 ^= b0; b0 = _n[0];       \
  a1 ^= b1; b1 = _n[1];       \
  a2 ^= b2; b2 = _n[2];       \
  a3 ^= b3; b3 = _n[3];       \
  _n += 4;

/* arg is incremented */
#define XOR_AND_STORE(_dst)       \
  a0 ^= b0; _dst[0] = a0;         \
  a1 ^= b1; _dst[1] = a1;         \
  a2 ^= b2; _dst[2] = a2;         \
  a3 ^= b3; _dst[3] = a3;         \
  _dst += 4;


void
rf_nWayXor3(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[3]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++;
		len--;
	}
}

void
rf_nWayXor4(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[4]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++;
		len--;
	}
}

void
rf_nWayXor5(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long *f = (unsigned long *) src_rbs[4]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[5]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_LOAD_NEXT(f);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++;
		len--;
	}
}

void
rf_nWayXor6(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long *f = (unsigned long *) src_rbs[4]->buffer;
	unsigned long *g = (unsigned long *) src_rbs[5]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[6]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_LOAD_NEXT(f);
		XOR_AND_LOAD_NEXT(g);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++;
		len--;
	}
}

void
rf_nWayXor7(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long *f = (unsigned long *) src_rbs[4]->buffer;
	unsigned long *g = (unsigned long *) src_rbs[5]->buffer;
	unsigned long *h = (unsigned long *) src_rbs[6]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[7]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_LOAD_NEXT(f);
		XOR_AND_LOAD_NEXT(g);
		XOR_AND_LOAD_NEXT(h);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++;
		len--;
	}
}

void
rf_nWayXor8(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long *f = (unsigned long *) src_rbs[4]->buffer;
	unsigned long *g = (unsigned long *) src_rbs[5]->buffer;
	unsigned long *h = (unsigned long *) src_rbs[6]->buffer;
	unsigned long *i = (unsigned long *) src_rbs[7]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[8]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++ ^ *i++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_LOAD_NEXT(f);
		XOR_AND_LOAD_NEXT(g);
		XOR_AND_LOAD_NEXT(h);
		XOR_AND_LOAD_NEXT(i);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++ ^ *i++;
		len--;
	}
}


void
rf_nWayXor9(RF_ReconBuffer_t **src_rbs, RF_ReconBuffer_t *dest_rb, int len)
{
	unsigned long *dst = (unsigned long *) dest_rb->buffer;
	unsigned long *b = (unsigned long *) src_rbs[0]->buffer;
	unsigned long *c = (unsigned long *) src_rbs[1]->buffer;
	unsigned long *d = (unsigned long *) src_rbs[2]->buffer;
	unsigned long *e = (unsigned long *) src_rbs[3]->buffer;
	unsigned long *f = (unsigned long *) src_rbs[4]->buffer;
	unsigned long *g = (unsigned long *) src_rbs[5]->buffer;
	unsigned long *h = (unsigned long *) src_rbs[6]->buffer;
	unsigned long *i = (unsigned long *) src_rbs[7]->buffer;
	unsigned long *j = (unsigned long *) src_rbs[8]->buffer;
	unsigned long a0, a1, a2, a3, b0, b1, b2, b3;

	callcount[9]++;
	/* align dest to cache line */
	while ((((unsigned long) dst) & 0x1f)) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++ ^ *i++ ^ *j++;
		len--;
	}
	while (len > 4) {
		LOAD_FIRST(dst, b);
		XOR_AND_LOAD_NEXT(c);
		XOR_AND_LOAD_NEXT(d);
		XOR_AND_LOAD_NEXT(e);
		XOR_AND_LOAD_NEXT(f);
		XOR_AND_LOAD_NEXT(g);
		XOR_AND_LOAD_NEXT(h);
		XOR_AND_LOAD_NEXT(i);
		XOR_AND_LOAD_NEXT(j);
		XOR_AND_STORE(dst);
	}
	while (len) {
		*dst++ ^= *b++ ^ *c++ ^ *d++ ^ *e++ ^ *f++ ^ *g++ ^ *h++ ^ *i++ ^ *j++;
		len--;
	}
}