1 /***********************************************************************
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 *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * internal representation conversion support
34 * swap n bytes according to op
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
;
52 for (n
>>= 1; n
--; f
+= 2, t
+= 2)
54 c
= f
[0]; t
[0] = f
[1]; t
[1] = c
;
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
;
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
;
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
;
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
;
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
;
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
;