1 /* $MirOS: contrib/code/jupp/blocks.c,v 1.4 2012/06/08 16:55:27 tg Exp $ */
3 * Fast block move/copy subroutines
5 * (C) 1992 Joseph H. Allen
7 * This file is part of JOE (Joe's Own Editor)
11 /* This module requires ALIGNED and SIZEOF_INT to be defined correctly */
25 /* Set 'sz' 'int's beginning at 'd' to the value 'c' */
26 /* Returns address of block. Does nothing if 'sz' equals zero */
28 int *msetI(void *dest, int c, int sz)
69 case 0: /* do nothing */;
74 /* Set 'sz' 'int's beginning at 'd' to the value 'c' */
75 /* Returns address of block. Does nothing if 'sz' equals zero */
77 void **msetP(void **d, void *c, int sz)
117 case 0: /* do nothing */;
122 /* Set 'sz' 'char's beginning at 'd' to the value 'c' */
123 /* Returns address of block. Does nothing if 'sz' equals zero */
125 unsigned char *mset(void *dest, unsigned char c, int sz)
127 unsigned char *d = dest;
128 unsigned char *orgd = dest;
147 case 0: /* do nothing */;
150 unsigned z = SIZEOF_INT - ((unsigned long)d & (SIZEOF_INT - 1));
152 if (z != SIZEOF_INT) {
161 case 0: /* do nothing */;
168 (c << (BITS * 7)) + (c << (BITS * 6)) + (c << (BITS * 5)) + (c << (BITS * 4)) +
171 (c << (BITS * 3)) + (c << (BITS * 2)) +
177 d += sz & ~(SIZEOF_INT - 1);
178 switch (sz & (SIZEOF_INT - 1)) {
186 case 0: /* do nothing */;
192 /* Copy a block of integers */
193 /* Copy from highest address to lowest */
195 static int *mbkwdI(void *dest, const void *src, int sz)
228 case 15: d[14] = s[14];
229 case 14: d[13] = s[13];
230 case 13: d[12] = s[12];
231 case 12: d[11] = s[11];
232 case 11: d[10] = s[10];
233 case 10: d[9] = s[9];
243 case 0: /* do nothing */;
248 /* Copy a block of 'int's. Copy from lowest address to highest */
250 static int *mfwrdI(void *dest, const void *src, int sz)
282 case 15: d[0] = s[0];
283 case 14: d[1] = s[1];
284 case 13: d[2] = s[2];
285 case 12: d[3] = s[3];
286 case 11: d[4] = s[4];
287 case 10: d[5] = s[5];
292 case 5: d[10] = s[10];
293 case 4: d[11] = s[11];
294 case 3: d[12] = s[12];
295 case 2: d[13] = s[13];
296 case 1: d[14] = s[14];
297 case 0: /* do nothing */;
302 /* Copy the block of 'sz' bytes beginning at 's' to 'd'. If 'sz' is zero or
303 * if 's'=='d', nothing happens. The bytes at the highest address ('s'+'sz'-1)
304 * are copied before the ones at the lowest ('s') are.
307 static unsigned char *mbkwd(register unsigned char *d, register const unsigned char *s, register int sz)
316 if (((unsigned long)s & (SIZEOF_INT - 1)) == ((unsigned long)d & (SIZEOF_INT - 1)) && sz >= 16)
319 unsigned z = ((unsigned long) s & (SIZEOF_INT - 1));
331 case 0: /* do nothing */;
334 mbkwdI(d - (sz & ~(SIZEOF_INT - 1)), s - (sz & ~(SIZEOF_INT - 1)), sz >> SHFT);
337 switch (sz & (SIZEOF_INT - 1)) {
345 case 0: /* do nothing */;
372 case 15: d[14] = s[14];
373 case 14: d[13] = s[13];
374 case 13: d[12] = s[12];
375 case 12: d[11] = s[11];
376 case 11: d[10] = s[10];
377 case 10: d[9] = s[9];
387 case 0: /* do nothing */;
393 /* Copy the block of 'sz' bytes beginning at 's' to 'd'. If 'sz' is zero or
394 * if 's'=='d', nothing happens. The bytes at the lowest address ('s')
395 * are copied before the ones at the highest ('s'+'sz'-1) are.
398 static unsigned char *mfwrd(register unsigned char *d, register const unsigned char *s, register int sz)
400 unsigned char *od = d;
407 if (((unsigned long)d & (SIZEOF_INT - 1)) == ((unsigned long)s & (SIZEOF_INT - 1)) && sz >= 16)
410 unsigned z = ((unsigned long)s & (SIZEOF_INT - 1));
415 switch (SIZEOF_INT - z) {
424 case 0: /* do nothing */;
430 case 0: /* do nothing */;
434 case 0: /* do nothing */;
441 sz -= SIZEOF_INT - z;
443 mfwrdI(d, s, sz >> SHFT);
444 s += sz - (SIZEOF_INT - 1);
445 d += sz - (SIZEOF_INT - 1);
446 switch (sz & (SIZEOF_INT - 1)) {
455 case 0: /* do nothing */;
461 case 0: /* do nothing */;
465 case 0: /* do nothing */;
495 case 15: d[0] = s[0];
496 case 14: d[1] = s[1];
497 case 13: d[2] = s[2];
498 case 12: d[3] = s[3];
499 case 11: d[4] = s[4];
500 case 10: d[5] = s[5];
505 case 5: d[10] = s[10];
506 case 4: d[11] = s[11];
507 case 3: d[12] = s[12];
508 case 2: d[13] = s[13];
509 case 1: d[14] = s[14];
510 case 0: /* do nothing */;
516 void *mmove(void *d, const void *s, int sz)
525 /* Utility to count number of lines within a segment */
527 int mcnt(register unsigned char *blk, register unsigned char c, int size)
529 register int nlines = 0;
532 if (blk[0] == c) ++nlines;
533 if (blk[1] == c) ++nlines;
534 if (blk[2] == c) ++nlines;
535 if (blk[3] == c) ++nlines;
536 if (blk[4] == c) ++nlines;
537 if (blk[5] == c) ++nlines;
538 if (blk[6] == c) ++nlines;
539 if (blk[7] == c) ++nlines;
540 if (blk[8] == c) ++nlines;
541 if (blk[9] == c) ++nlines;
542 if (blk[10] == c) ++nlines;
543 if (blk[11] == c) ++nlines;
544 if (blk[12] == c) ++nlines;
545 if (blk[13] == c) ++nlines;
546 if (blk[14] == c) ++nlines;
547 if (blk[15] == c) ++nlines;
552 case 15: if (blk[14] == c) ++nlines;
553 case 14: if (blk[13] == c) ++nlines;
554 case 13: if (blk[12] == c) ++nlines;
555 case 12: if (blk[11] == c) ++nlines;
556 case 11: if (blk[10] == c) ++nlines;
557 case 10: if (blk[9] == c) ++nlines;
558 case 9: if (blk[8] == c) ++nlines;
559 case 8: if (blk[7] == c) ++nlines;
560 case 7: if (blk[6] == c) ++nlines;
561 case 6: if (blk[5] == c) ++nlines;
562 case 5: if (blk[4] == c) ++nlines;
563 case 4: if (blk[3] == c) ++nlines;
564 case 3: if (blk[2] == c) ++nlines;
565 case 2: if (blk[1] == c) ++nlines;
566 case 1: if (blk[0] == c) ++nlines;
567 case 0: /* do nothing */;