sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libast / common / string / swapmem.c
blob72027dcb613b869b4bc8c2121fd93ba2061927a5
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * Glenn Fowler
25 * AT&T Research
27 * internal representation conversion support
30 #include <ast.h>
31 #include <swap.h>
34 * swap n bytes according to op
35 * from==to is ok
38 void*
39 swapmem(int op, const void* from, void* to, register size_t n)
41 register char* f = (char*)from;
42 register char* t = (char*)to;
43 register int c;
45 switch (op & (n - 1))
47 case 0:
48 if (t != f)
49 memcpy(t, f, n);
50 break;
51 case 1:
52 for (n >>= 1; n--; f += 2, t += 2)
54 c = f[0]; t[0] = f[1]; t[1] = c;
56 break;
57 case 2:
58 for (n >>= 2; n--; f += 4, t += 4)
60 c = f[0]; t[0] = f[2]; t[2] = c;
61 c = f[1]; t[1] = f[3]; t[3] = c;
63 break;
64 case 3:
65 for (n >>= 2; n--; f += 4, t += 4)
67 c = f[0]; t[0] = f[3]; t[3] = c;
68 c = f[1]; t[1] = f[2]; t[2] = c;
70 break;
71 case 4:
72 for (n >>= 3; n--; f += 8, t += 8)
74 c = f[0]; t[0] = f[4]; t[4] = c;
75 c = f[1]; t[1] = f[5]; t[5] = c;
76 c = f[2]; t[2] = f[6]; t[6] = c;
77 c = f[3]; t[3] = f[7]; t[7] = c;
79 break;
80 case 5:
81 for (n >>= 3; n--; f += 8, t += 8)
83 c = f[0]; t[0] = f[5]; t[5] = c;
84 c = f[1]; t[1] = f[4]; t[4] = c;
85 c = f[2]; t[2] = f[7]; t[7] = c;
86 c = f[3]; t[3] = f[6]; t[6] = c;
88 break;
89 case 6:
90 for (n >>= 3; n--; f += 8, t += 8)
92 c = f[0]; t[0] = f[6]; t[6] = c;
93 c = f[1]; t[1] = f[7]; t[7] = c;
94 c = f[2]; t[2] = f[4]; t[4] = c;
95 c = f[3]; t[3] = f[5]; t[5] = c;
97 break;
98 case 7:
99 for (n >>= 3; n--; f += 8, t += 8)
101 c = f[0]; t[0] = f[7]; t[7] = c;
102 c = f[1]; t[1] = f[6]; t[6] = c;
103 c = f[2]; t[2] = f[5]; t[5] = c;
104 c = f[3]; t[3] = f[4]; t[4] = c;
106 break;
108 return to;