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 ***********************************************************************/
25 * AT&T Bell Laboratories
27 * generate align features
29 * NOTE: two's complement binary integral representation assumed
32 #include "FEATURE/common"
56 #define roundof(x,y) (((x)+((y)-1))&~((y)-1))
82 align0
= sizeof(struct _s_
) - sizeof(union _u_
);
85 for (j
= 0; j
< align0
; j
++)
89 for (i
= 0; i
< align0
; i
++)
94 if (!bits0
|| bits1
< bits0
)
100 align1
= roundof(align0
, 2);
102 for (bits1
= bits0
; i
< align1
; i
++)
105 bits1
|= u
.u1
^ v
.u1
;
107 align2
= roundof(align0
, 4);
108 for (bits2
= bits1
; i
< align2
; i
++)
111 bits2
|= u
.u1
^ v
.u1
;
113 printf("typedef unsigned %s ALIGN_INTEGRAL;\n", sizeof(char*) >= sizeof(long) ? "long" : sizeof(char*) >= sizeof(int) ? "int" : "short");
115 printf("#define ALIGN_CHUNK %d\n", sizeof(char*) >= 4 ? 8192 : 1024);
116 printf("#define ALIGN_INTEGRAL %s\n", sizeof(char*) >= sizeof(long) ? "long" : sizeof(char*) >= sizeof(int) ? "int" : "short");
117 printf("#define ALIGN_INTEGER(x) ((ALIGN_INTEGRAL)(x))\n");
118 printf("#define ALIGN_POINTER(x) ((char*)(x))\n");
119 if (bits2
== (align2
- 1)) printf("#define ALIGN_ROUND(x,y) ALIGN_POINTER(ALIGN_INTEGER((x)+(y)-1)&~((y)-1))\n");
120 else printf("#define ALIGN_ROUND(x,y) ALIGN_POINTER(ALIGN_INTEGER(ALIGN_ALIGN(x)+(((y)+%d)/%d)-1)&~((((y)+%d)/%d)-1))\n", align0
, align0
, align0
, align0
);
122 if (align0
== align2
)
124 printf("#define ALIGN_BOUND ALIGN_BOUND2\n");
125 printf("#define ALIGN_ALIGN(x) ALIGN_ALIGN2(x)\n");
126 printf("#define ALIGN_TRUNC(x) ALIGN_TRUNC2(x)\n");
128 else if (align0
== align1
)
130 printf("#define ALIGN_BOUND ALIGN_BOUND1\n");
131 printf("#define ALIGN_ALIGN(x) ALIGN_ALIGN1(x)\n");
132 printf("#define ALIGN_TRUNC(x) ALIGN_TRUNC1(x)\n");
136 printf("#define ALIGN_BOUND 1\n");
137 printf("#define ALIGN_ALIGN(x) ALIGN_POINTER(x)\n");
138 printf("#define ALIGN_TRUNC(x) ALIGN_POINTER(x)\n");
141 printf("#define ALIGN_BIT1 0x%lx\n", bit1
);
142 if (align1
== align2
)
144 printf("#define ALIGN_BOUND1 ALIGN_BOUND2\n");
145 printf("#define ALIGN_ALIGN1(x) ALIGN_ALIGN2(x)\n");
146 printf("#define ALIGN_TRUNC1(x) ALIGN_TRUNC2(x)\n");
150 printf("#define ALIGN_BOUND1 %d\n", align1
);
151 printf("#define ALIGN_ALIGN1(x) ALIGN_TRUNC1((x)+%d)\n", align1
- 1);
152 printf("#define ALIGN_TRUNC1(x) ALIGN_POINTER(ALIGN_INTEGER((x)+%d)&0x%lx)\n", align1
- 1, ~(bits0
|bits1
));
154 printf("#define ALIGN_CLRBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~bit1
);
155 printf("#define ALIGN_SETBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)|0x%lx)\n", bit1
);
156 printf("#define ALIGN_TSTBIT1(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", bit1
);
158 printf("#define ALIGN_BIT2 0x%lx\n", bit2
);
159 printf("#define ALIGN_BOUND2 %d\n", align2
);
160 printf("#define ALIGN_ALIGN2(x) ALIGN_TRUNC2((x)+%d)\n", align2
- 1);
161 printf("#define ALIGN_TRUNC2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~(bits0
|bits1
|bits2
));
162 printf("#define ALIGN_CLRBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", ~bit2
);
163 printf("#define ALIGN_SETBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)|0x%lx)\n", bit2
);
164 printf("#define ALIGN_TSTBIT2(x) ALIGN_POINTER(ALIGN_INTEGER(x)&0x%lx)\n", bit2
);