Mercurial > hg > CbC > CbC_gcc
annotate gcc/genmodes.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 1830386684a0 |
children |
rev | line source |
---|---|
0 | 1 /* Generate the machine mode enumeration and associated tables. |
145 | 2 Copyright (C) 2003-2020 Free Software Foundation, Inc. |
0 | 3 |
4 This file is part of GCC. | |
5 | |
6 GCC is free software; you can redistribute it and/or modify it under | |
7 the terms of the GNU General Public License as published by the Free | |
8 Software Foundation; either version 3, or (at your option) any later | |
9 version. | |
10 | |
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GCC; see the file COPYING3. If not see | |
18 <http://www.gnu.org/licenses/>. */ | |
19 | |
20 #include "bconfig.h" | |
21 #include "system.h" | |
22 #include "errors.h" | |
23 | |
24 /* enum mode_class is normally defined by machmode.h but we can't | |
25 include that header here. */ | |
26 #include "mode-classes.def" | |
27 | |
28 #define DEF_MODE_CLASS(M) M | |
29 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS }; | |
30 #undef DEF_MODE_CLASS | |
31 | |
32 /* Text names of mode classes, for output. */ | |
33 #define DEF_MODE_CLASS(M) #M | |
34 static const char *const mode_class_names[MAX_MODE_CLASS] = | |
35 { | |
36 MODE_CLASSES | |
37 }; | |
38 #undef DEF_MODE_CLASS | |
39 #undef MODE_CLASSES | |
40 | |
41 #ifdef EXTRA_MODES_FILE | |
42 # define HAVE_EXTRA_MODES 1 | |
43 #else | |
44 # define HAVE_EXTRA_MODES 0 | |
45 # define EXTRA_MODES_FILE "" | |
46 #endif | |
47 | |
48 /* Data structure for building up what we know about a mode. | |
49 They're clustered by mode class. */ | |
50 struct mode_data | |
51 { | |
52 struct mode_data *next; /* next this class - arbitrary order */ | |
53 | |
54 const char *name; /* printable mode name -- SI, not SImode */ | |
55 enum mode_class cl; /* this mode class */ | |
145 | 56 unsigned int order; /* top-level sorting order */ |
0 | 57 unsigned int precision; /* size in bits, equiv to TYPE_PRECISION */ |
58 unsigned int bytesize; /* storage size in addressable units */ | |
59 unsigned int ncomponents; /* number of subunits */ | |
60 unsigned int alignment; /* mode alignment */ | |
61 const char *format; /* floating point format - float modes only */ | |
62 | |
63 struct mode_data *component; /* mode of components */ | |
64 struct mode_data *wider; /* next wider mode */ | |
65 | |
66 struct mode_data *contained; /* Pointer to list of modes that have | |
67 this mode as a component. */ | |
68 struct mode_data *next_cont; /* Next mode in that list. */ | |
69 | |
111 | 70 struct mode_data *complex; /* complex type with mode as component. */ |
0 | 71 const char *file; /* file and line of definition, */ |
72 unsigned int line; /* for error reporting */ | |
73 unsigned int counter; /* Rank ordering of modes */ | |
74 unsigned int ibit; /* the number of integral bits */ | |
75 unsigned int fbit; /* the number of fractional bits */ | |
131 | 76 bool need_nunits_adj; /* true if this mode needs dynamic nunits |
77 adjustment */ | |
78 bool need_bytesize_adj; /* true if this mode needs dynamic size | |
111 | 79 adjustment */ |
80 unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */ | |
0 | 81 }; |
82 | |
83 static struct mode_data *modes[MAX_MODE_CLASS]; | |
84 static unsigned int n_modes[MAX_MODE_CLASS]; | |
85 static struct mode_data *void_mode; | |
86 | |
87 static const struct mode_data blank_mode = { | |
88 0, "<unknown>", MAX_MODE_CLASS, | |
145 | 89 0, -1U, -1U, -1U, -1U, |
0 | 90 0, 0, 0, 0, 0, 0, |
131 | 91 "<unknown>", 0, 0, 0, 0, false, false, 0 |
0 | 92 }; |
93 | |
94 static htab_t modes_by_name; | |
95 | |
96 /* Data structure for recording target-specified runtime adjustments | |
97 to a particular mode. We support varying the byte size, the | |
98 alignment, and the floating point format. */ | |
99 struct mode_adjust | |
100 { | |
101 struct mode_adjust *next; | |
102 struct mode_data *mode; | |
103 const char *adjustment; | |
104 | |
105 const char *file; | |
106 unsigned int line; | |
107 }; | |
108 | |
131 | 109 static struct mode_adjust *adj_nunits; |
0 | 110 static struct mode_adjust *adj_bytesize; |
111 static struct mode_adjust *adj_alignment; | |
112 static struct mode_adjust *adj_format; | |
113 static struct mode_adjust *adj_ibit; | |
114 static struct mode_adjust *adj_fbit; | |
115 | |
116 /* Mode class operations. */ | |
117 static enum mode_class | |
118 complex_class (enum mode_class c) | |
119 { | |
120 switch (c) | |
121 { | |
122 case MODE_INT: return MODE_COMPLEX_INT; | |
131 | 123 case MODE_PARTIAL_INT: return MODE_COMPLEX_INT; |
0 | 124 case MODE_FLOAT: return MODE_COMPLEX_FLOAT; |
125 default: | |
126 error ("no complex class for class %s", mode_class_names[c]); | |
127 return MODE_RANDOM; | |
128 } | |
129 } | |
130 | |
131 static enum mode_class | |
132 vector_class (enum mode_class cl) | |
133 { | |
134 switch (cl) | |
135 { | |
136 case MODE_INT: return MODE_VECTOR_INT; | |
137 case MODE_FLOAT: return MODE_VECTOR_FLOAT; | |
138 case MODE_FRACT: return MODE_VECTOR_FRACT; | |
139 case MODE_UFRACT: return MODE_VECTOR_UFRACT; | |
140 case MODE_ACCUM: return MODE_VECTOR_ACCUM; | |
141 case MODE_UACCUM: return MODE_VECTOR_UACCUM; | |
142 default: | |
143 error ("no vector class for class %s", mode_class_names[cl]); | |
144 return MODE_RANDOM; | |
145 } | |
146 } | |
147 | |
148 /* Utility routines. */ | |
149 static inline struct mode_data * | |
150 find_mode (const char *name) | |
151 { | |
152 struct mode_data key; | |
153 | |
154 key.name = name; | |
155 return (struct mode_data *) htab_find (modes_by_name, &key); | |
156 } | |
157 | |
158 static struct mode_data * | |
159 new_mode (enum mode_class cl, const char *name, | |
160 const char *file, unsigned int line) | |
161 { | |
162 struct mode_data *m; | |
163 static unsigned int count = 0; | |
164 | |
165 m = find_mode (name); | |
166 if (m) | |
167 { | |
168 error ("%s:%d: duplicate definition of mode \"%s\"", | |
169 trim_filename (file), line, name); | |
170 error ("%s:%d: previous definition here", m->file, m->line); | |
171 return m; | |
172 } | |
173 | |
174 m = XNEW (struct mode_data); | |
175 memcpy (m, &blank_mode, sizeof (struct mode_data)); | |
176 m->cl = cl; | |
177 m->name = name; | |
178 if (file) | |
179 m->file = trim_filename (file); | |
180 m->line = line; | |
181 m->counter = count++; | |
182 | |
183 m->next = modes[cl]; | |
184 modes[cl] = m; | |
185 n_modes[cl]++; | |
186 | |
187 *htab_find_slot (modes_by_name, m, INSERT) = m; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
188 |
0 | 189 return m; |
190 } | |
191 | |
192 static hashval_t | |
193 hash_mode (const void *p) | |
194 { | |
195 const struct mode_data *m = (const struct mode_data *)p; | |
196 return htab_hash_string (m->name); | |
197 } | |
198 | |
199 static int | |
200 eq_mode (const void *p, const void *q) | |
201 { | |
202 const struct mode_data *a = (const struct mode_data *)p; | |
203 const struct mode_data *b = (const struct mode_data *)q; | |
204 | |
205 return !strcmp (a->name, b->name); | |
206 } | |
207 | |
208 #define for_all_modes(C, M) \ | |
209 for (C = 0; C < MAX_MODE_CLASS; C++) \ | |
210 for (M = modes[C]; M; M = M->next) | |
211 | |
212 static void ATTRIBUTE_UNUSED | |
213 new_adjust (const char *name, | |
214 struct mode_adjust **category, const char *catname, | |
215 const char *adjustment, | |
216 enum mode_class required_class_from, | |
217 enum mode_class required_class_to, | |
218 const char *file, unsigned int line) | |
219 { | |
220 struct mode_data *mode = find_mode (name); | |
221 struct mode_adjust *a; | |
222 | |
223 file = trim_filename (file); | |
224 | |
225 if (!mode) | |
226 { | |
227 error ("%s:%d: no mode \"%s\"", file, line, name); | |
228 return; | |
229 } | |
230 | |
231 if (required_class_from != MODE_RANDOM | |
232 && (mode->cl < required_class_from || mode->cl > required_class_to)) | |
233 { | |
234 error ("%s:%d: mode \"%s\" is not among class {%s, %s}", | |
235 file, line, name, mode_class_names[required_class_from] + 5, | |
236 mode_class_names[required_class_to] + 5); | |
237 return; | |
238 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
239 |
0 | 240 for (a = *category; a; a = a->next) |
241 if (a->mode == mode) | |
242 { | |
243 error ("%s:%d: mode \"%s\" already has a %s adjustment", | |
244 file, line, name, catname); | |
245 error ("%s:%d: previous adjustment here", a->file, a->line); | |
246 return; | |
247 } | |
248 | |
249 a = XNEW (struct mode_adjust); | |
250 a->mode = mode; | |
251 a->adjustment = adjustment; | |
252 a->file = file; | |
253 a->line = line; | |
254 | |
255 a->next = *category; | |
256 *category = a; | |
257 } | |
258 | |
259 /* Diagnose failure to meet expectations in a partially filled out | |
260 mode structure. */ | |
261 enum requirement { SET, UNSET, OPTIONAL }; | |
262 | |
263 #define validate_field_(mname, fname, req, val, unset, file, line) do { \ | |
264 switch (req) \ | |
265 { \ | |
266 case SET: \ | |
267 if (val == unset) \ | |
268 error ("%s:%d: (%s) field %s must be set", \ | |
269 file, line, mname, fname); \ | |
270 break; \ | |
271 case UNSET: \ | |
272 if (val != unset) \ | |
273 error ("%s:%d: (%s) field %s must not be set", \ | |
274 file, line, mname, fname); \ | |
275 case OPTIONAL: \ | |
276 break; \ | |
277 } \ | |
278 } while (0) | |
279 | |
280 #define validate_field(M, F) \ | |
281 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line) | |
282 | |
283 static void | |
284 validate_mode (struct mode_data *m, | |
285 enum requirement r_precision, | |
286 enum requirement r_bytesize, | |
287 enum requirement r_component, | |
288 enum requirement r_ncomponents, | |
289 enum requirement r_format) | |
290 { | |
291 validate_field (m, precision); | |
292 validate_field (m, bytesize); | |
293 validate_field (m, component); | |
294 validate_field (m, ncomponents); | |
295 validate_field (m, format); | |
296 } | |
297 #undef validate_field | |
298 #undef validate_field_ | |
299 | |
300 /* Given a partially-filled-out mode structure, figure out what we can | |
301 and fill the rest of it in; die if it isn't enough. */ | |
302 static void | |
303 complete_mode (struct mode_data *m) | |
304 { | |
305 unsigned int alignment; | |
306 | |
307 if (!m->name) | |
308 { | |
309 error ("%s:%d: mode with no name", m->file, m->line); | |
310 return; | |
311 } | |
312 if (m->cl == MAX_MODE_CLASS) | |
313 { | |
314 error ("%s:%d: %smode has no mode class", m->file, m->line, m->name); | |
315 return; | |
316 } | |
317 | |
318 switch (m->cl) | |
319 { | |
320 case MODE_RANDOM: | |
321 /* Nothing more need be said. */ | |
322 if (!strcmp (m->name, "VOID")) | |
323 void_mode = m; | |
324 | |
325 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET); | |
326 | |
327 m->precision = 0; | |
328 m->bytesize = 0; | |
329 m->ncomponents = 0; | |
330 m->component = 0; | |
331 break; | |
332 | |
333 case MODE_CC: | |
334 /* Again, nothing more need be said. For historical reasons, | |
335 the size of a CC mode is four units. */ | |
336 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET); | |
337 | |
338 m->bytesize = 4; | |
339 m->ncomponents = 1; | |
340 m->component = 0; | |
341 break; | |
342 | |
343 case MODE_INT: | |
344 case MODE_FLOAT: | |
345 case MODE_DECIMAL_FLOAT: | |
346 case MODE_FRACT: | |
347 case MODE_UFRACT: | |
348 case MODE_ACCUM: | |
349 case MODE_UACCUM: | |
350 /* A scalar mode must have a byte size, may have a bit size, | |
351 and must not have components. A float mode must have a | |
352 format. */ | |
353 validate_mode (m, OPTIONAL, SET, UNSET, UNSET, | |
354 (m->cl == MODE_FLOAT || m->cl == MODE_DECIMAL_FLOAT) | |
355 ? SET : UNSET); | |
356 | |
357 m->ncomponents = 1; | |
358 m->component = 0; | |
359 break; | |
360 | |
361 case MODE_PARTIAL_INT: | |
362 /* A partial integer mode uses ->component to say what the | |
363 corresponding full-size integer mode is, and may also | |
364 specify a bit size. */ | |
365 validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET); | |
366 | |
367 m->bytesize = m->component->bytesize; | |
368 | |
369 m->ncomponents = 1; | |
370 break; | |
371 | |
372 case MODE_COMPLEX_INT: | |
373 case MODE_COMPLEX_FLOAT: | |
374 /* Complex modes should have a component indicated, but no more. */ | |
375 validate_mode (m, UNSET, UNSET, SET, UNSET, UNSET); | |
376 m->ncomponents = 2; | |
377 if (m->component->precision != (unsigned int)-1) | |
378 m->precision = 2 * m->component->precision; | |
379 m->bytesize = 2 * m->component->bytesize; | |
380 break; | |
381 | |
131 | 382 case MODE_VECTOR_BOOL: |
383 validate_mode (m, UNSET, SET, SET, SET, UNSET); | |
384 break; | |
385 | |
0 | 386 case MODE_VECTOR_INT: |
387 case MODE_VECTOR_FLOAT: | |
388 case MODE_VECTOR_FRACT: | |
389 case MODE_VECTOR_UFRACT: | |
390 case MODE_VECTOR_ACCUM: | |
391 case MODE_VECTOR_UACCUM: | |
392 /* Vector modes should have a component and a number of components. */ | |
393 validate_mode (m, UNSET, UNSET, SET, SET, UNSET); | |
394 if (m->component->precision != (unsigned int)-1) | |
395 m->precision = m->ncomponents * m->component->precision; | |
396 m->bytesize = m->ncomponents * m->component->bytesize; | |
397 break; | |
398 | |
399 default: | |
400 gcc_unreachable (); | |
401 } | |
402 | |
403 /* If not already specified, the mode alignment defaults to the largest | |
404 power of two that divides the size of the object. Complex types are | |
405 not more aligned than their contents. */ | |
406 if (m->cl == MODE_COMPLEX_INT || m->cl == MODE_COMPLEX_FLOAT) | |
407 alignment = m->component->bytesize; | |
408 else | |
409 alignment = m->bytesize; | |
410 | |
411 m->alignment = alignment & (~alignment + 1); | |
412 | |
413 /* If this mode has components, make the component mode point back | |
414 to this mode, for the sake of adjustments. */ | |
415 if (m->component) | |
416 { | |
417 m->next_cont = m->component->contained; | |
418 m->component->contained = m; | |
419 } | |
420 } | |
421 | |
422 static void | |
423 complete_all_modes (void) | |
424 { | |
425 struct mode_data *m; | |
426 int cl; | |
427 | |
428 for_all_modes (cl, m) | |
429 complete_mode (m); | |
430 } | |
431 | |
432 /* For each mode in class CLASS, construct a corresponding complex mode. */ | |
111 | 433 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__) |
0 | 434 static void |
435 make_complex_modes (enum mode_class cl, | |
436 const char *file, unsigned int line) | |
437 { | |
438 struct mode_data *m; | |
439 struct mode_data *c; | |
440 enum mode_class cclass = complex_class (cl); | |
441 | |
442 if (cclass == MODE_RANDOM) | |
443 return; | |
444 | |
445 for (m = modes[cl]; m; m = m->next) | |
446 { | |
111 | 447 char *p, *buf; |
448 size_t m_len; | |
449 | |
0 | 450 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */ |
451 if (m->precision == 1) | |
452 continue; | |
453 | |
111 | 454 m_len = strlen (m->name); |
455 /* The leading "1 +" is in case we prepend a "C" below. */ | |
456 buf = (char *) xmalloc (1 + m_len + 1); | |
0 | 457 |
458 /* Float complex modes are named SCmode, etc. | |
459 Int complex modes are named CSImode, etc. | |
460 This inconsistency should be eliminated. */ | |
111 | 461 p = 0; |
0 | 462 if (cl == MODE_FLOAT) |
463 { | |
111 | 464 memcpy (buf, m->name, m_len + 1); |
0 | 465 p = strchr (buf, 'F'); |
111 | 466 if (p == 0 && strchr (buf, 'D') == 0) |
0 | 467 { |
468 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'", | |
469 m->file, m->line, m->name); | |
111 | 470 free (buf); |
0 | 471 continue; |
472 } | |
473 } | |
111 | 474 if (p != 0) |
475 *p = 'C'; | |
0 | 476 else |
111 | 477 { |
478 buf[0] = 'C'; | |
479 memcpy (buf + 1, m->name, m_len + 1); | |
480 } | |
0 | 481 |
111 | 482 c = new_mode (cclass, buf, file, line); |
0 | 483 c->component = m; |
111 | 484 m->complex = c; |
0 | 485 } |
486 } | |
487 | |
145 | 488 /* For all modes in class CL, construct vector modes of width WIDTH, |
489 having as many components as necessary. ORDER is the sorting order | |
490 of the mode, with smaller numbers indicating a higher priority. */ | |
491 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \ | |
492 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__) | |
493 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0) | |
0 | 494 static void ATTRIBUTE_UNUSED |
131 | 495 make_vector_modes (enum mode_class cl, const char *prefix, unsigned int width, |
145 | 496 unsigned int order, const char *file, unsigned int line) |
0 | 497 { |
498 struct mode_data *m; | |
499 struct mode_data *v; | |
111 | 500 /* Big enough for a 32-bit UINT_MAX plus the text. */ |
501 char buf[12]; | |
0 | 502 unsigned int ncomponents; |
503 enum mode_class vclass = vector_class (cl); | |
504 | |
505 if (vclass == MODE_RANDOM) | |
506 return; | |
507 | |
508 for (m = modes[cl]; m; m = m->next) | |
509 { | |
510 /* Do not construct vector modes with only one element, or | |
511 vector modes where the element size doesn't divide the full | |
512 size evenly. */ | |
513 ncomponents = width / m->bytesize; | |
514 if (ncomponents < 2) | |
515 continue; | |
516 if (width % m->bytesize) | |
517 continue; | |
518 | |
519 /* Skip QFmode and BImode. FIXME: this special case should | |
520 not be necessary. */ | |
521 if (cl == MODE_FLOAT && m->bytesize == 1) | |
522 continue; | |
523 if (cl == MODE_INT && m->precision == 1) | |
524 continue; | |
525 | |
131 | 526 if ((size_t) snprintf (buf, sizeof buf, "%s%u%s", prefix, |
527 ncomponents, m->name) >= sizeof buf) | |
0 | 528 { |
529 error ("%s:%d: mode name \"%s\" is too long", | |
530 m->file, m->line, m->name); | |
531 continue; | |
532 } | |
533 | |
534 v = new_mode (vclass, xstrdup (buf), file, line); | |
145 | 535 v->order = order; |
0 | 536 v->component = m; |
537 v->ncomponents = ncomponents; | |
538 } | |
539 } | |
540 | |
131 | 541 /* Create a vector of booleans called NAME with COUNT elements and |
542 BYTESIZE bytes in total. */ | |
543 #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \ | |
544 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__) | |
545 static void ATTRIBUTE_UNUSED | |
546 make_vector_bool_mode (const char *name, unsigned int count, | |
547 unsigned int bytesize, const char *file, | |
548 unsigned int line) | |
549 { | |
550 struct mode_data *m = find_mode ("BI"); | |
551 if (!m) | |
552 { | |
553 error ("%s:%d: no mode \"BI\"", file, line); | |
554 return; | |
555 } | |
556 | |
557 struct mode_data *v = new_mode (MODE_VECTOR_BOOL, name, file, line); | |
558 v->component = m; | |
559 v->ncomponents = count; | |
560 v->bytesize = bytesize; | |
561 } | |
562 | |
0 | 563 /* Input. */ |
564 | |
111 | 565 #define _SPECIAL_MODE(C, N) \ |
566 make_special_mode (MODE_##C, #N, __FILE__, __LINE__) | |
0 | 567 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N) |
568 #define CC_MODE(N) _SPECIAL_MODE (CC, N) | |
569 | |
570 static void | |
571 make_special_mode (enum mode_class cl, const char *name, | |
572 const char *file, unsigned int line) | |
573 { | |
574 new_mode (cl, name, file, line); | |
575 } | |
576 | |
577 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y) | |
578 #define FRACTIONAL_INT_MODE(N, B, Y) \ | |
579 make_int_mode (#N, B, Y, __FILE__, __LINE__) | |
580 | |
581 static void | |
582 make_int_mode (const char *name, | |
583 unsigned int precision, unsigned int bytesize, | |
584 const char *file, unsigned int line) | |
585 { | |
586 struct mode_data *m = new_mode (MODE_INT, name, file, line); | |
587 m->bytesize = bytesize; | |
588 m->precision = precision; | |
589 } | |
590 | |
591 #define FRACT_MODE(N, Y, F) \ | |
592 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__) | |
593 | |
594 #define UFRACT_MODE(N, Y, F) \ | |
595 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__) | |
596 | |
597 #define ACCUM_MODE(N, Y, I, F) \ | |
598 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__) | |
599 | |
600 #define UACCUM_MODE(N, Y, I, F) \ | |
601 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__) | |
602 | |
603 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT, | |
604 FILE, and LINE. */ | |
605 | |
606 static void | |
607 make_fixed_point_mode (enum mode_class cl, | |
608 const char *name, | |
609 unsigned int bytesize, | |
610 unsigned int ibit, | |
611 unsigned int fbit, | |
612 const char *file, unsigned int line) | |
613 { | |
614 struct mode_data *m = new_mode (cl, name, file, line); | |
615 m->bytesize = bytesize; | |
616 m->ibit = ibit; | |
617 m->fbit = fbit; | |
618 } | |
619 | |
620 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F) | |
621 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \ | |
622 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__) | |
623 | |
624 static void | |
625 make_float_mode (const char *name, | |
626 unsigned int precision, unsigned int bytesize, | |
627 const char *format, | |
628 const char *file, unsigned int line) | |
629 { | |
630 struct mode_data *m = new_mode (MODE_FLOAT, name, file, line); | |
631 m->bytesize = bytesize; | |
632 m->precision = precision; | |
633 m->format = format; | |
634 } | |
635 | |
636 #define DECIMAL_FLOAT_MODE(N, Y, F) \ | |
637 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F) | |
638 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \ | |
639 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__) | |
640 | |
641 static void | |
642 make_decimal_float_mode (const char *name, | |
643 unsigned int precision, unsigned int bytesize, | |
644 const char *format, | |
645 const char *file, unsigned int line) | |
646 { | |
647 struct mode_data *m = new_mode (MODE_DECIMAL_FLOAT, name, file, line); | |
648 m->bytesize = bytesize; | |
649 m->precision = precision; | |
650 m->format = format; | |
651 } | |
652 | |
653 #define RESET_FLOAT_FORMAT(N, F) \ | |
654 reset_float_format (#N, #F, __FILE__, __LINE__) | |
655 static void ATTRIBUTE_UNUSED | |
656 reset_float_format (const char *name, const char *format, | |
657 const char *file, unsigned int line) | |
658 { | |
659 struct mode_data *m = find_mode (name); | |
660 if (!m) | |
661 { | |
662 error ("%s:%d: no mode \"%s\"", file, line, name); | |
663 return; | |
664 } | |
665 if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT) | |
666 { | |
667 error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name); | |
668 return; | |
669 } | |
670 m->format = format; | |
671 } | |
672 | |
111 | 673 /* __intN support. */ |
674 #define INT_N(M,PREC) \ | |
675 make_int_n (#M, PREC, __FILE__, __LINE__) | |
676 static void ATTRIBUTE_UNUSED | |
677 make_int_n (const char *m, int bitsize, | |
678 const char *file, unsigned int line) | |
679 { | |
680 struct mode_data *component = find_mode (m); | |
681 if (!component) | |
682 { | |
683 error ("%s:%d: no mode \"%s\"", file, line, m); | |
684 return; | |
685 } | |
686 if (component->cl != MODE_INT | |
687 && component->cl != MODE_PARTIAL_INT) | |
688 { | |
689 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m); | |
690 return; | |
691 } | |
692 if (component->int_n != 0) | |
693 { | |
694 error ("%s:%d: mode \"%s\" already has an intN", file, line, m); | |
695 return; | |
696 } | |
697 | |
698 component->int_n = bitsize; | |
699 } | |
700 | |
701 /* Partial integer modes are specified by relation to a full integer | |
702 mode. */ | |
703 #define PARTIAL_INT_MODE(M,PREC,NAME) \ | |
704 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__) | |
0 | 705 static void ATTRIBUTE_UNUSED |
706 make_partial_integer_mode (const char *base, const char *name, | |
707 unsigned int precision, | |
708 const char *file, unsigned int line) | |
709 { | |
710 struct mode_data *m; | |
711 struct mode_data *component = find_mode (base); | |
712 if (!component) | |
713 { | |
714 error ("%s:%d: no mode \"%s\"", file, line, name); | |
715 return; | |
716 } | |
717 if (component->cl != MODE_INT) | |
718 { | |
719 error ("%s:%d: mode \"%s\" is not class INT", file, line, name); | |
720 return; | |
721 } | |
722 | |
723 m = new_mode (MODE_PARTIAL_INT, name, file, line); | |
724 m->precision = precision; | |
725 m->component = component; | |
726 } | |
727 | |
728 /* A single vector mode can be specified by naming its component | |
729 mode and the number of components. */ | |
730 #define VECTOR_MODE(C, M, N) \ | |
731 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__); | |
732 static void ATTRIBUTE_UNUSED | |
733 make_vector_mode (enum mode_class bclass, | |
734 const char *base, | |
735 unsigned int ncomponents, | |
736 const char *file, unsigned int line) | |
737 { | |
738 struct mode_data *v; | |
739 enum mode_class vclass = vector_class (bclass); | |
740 struct mode_data *component = find_mode (base); | |
111 | 741 char namebuf[16]; |
0 | 742 |
743 if (vclass == MODE_RANDOM) | |
744 return; | |
745 if (component == 0) | |
746 { | |
747 error ("%s:%d: no mode \"%s\"", file, line, base); | |
748 return; | |
749 } | |
750 if (component->cl != bclass | |
751 && (component->cl != MODE_PARTIAL_INT | |
752 || bclass != MODE_INT)) | |
753 { | |
754 error ("%s:%d: mode \"%s\" is not class %s", | |
755 file, line, base, mode_class_names[bclass] + 5); | |
756 return; | |
757 } | |
758 | |
759 if ((size_t)snprintf (namebuf, sizeof namebuf, "V%u%s", | |
760 ncomponents, base) >= sizeof namebuf) | |
761 { | |
762 error ("%s:%d: mode name \"%s\" is too long", | |
763 file, line, base); | |
764 return; | |
765 } | |
766 | |
767 v = new_mode (vclass, xstrdup (namebuf), file, line); | |
768 v->ncomponents = ncomponents; | |
769 v->component = component; | |
770 } | |
771 | |
772 /* Adjustability. */ | |
773 #define _ADD_ADJUST(A, M, X, C1, C2) \ | |
774 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__) | |
775 | |
131 | 776 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM) |
111 | 777 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM) |
778 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM) | |
779 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT) | |
780 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM) | |
781 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM) | |
782 | |
783 static int bits_per_unit; | |
784 static int max_bitsize_mode_any_int; | |
131 | 785 static int max_bitsize_mode_any_mode; |
0 | 786 |
787 static void | |
788 create_modes (void) | |
789 { | |
790 #include "machmode.def" | |
111 | 791 |
792 /* So put the default value unless the target needs a non standard | |
793 value. */ | |
794 #ifdef BITS_PER_UNIT | |
795 bits_per_unit = BITS_PER_UNIT; | |
796 #else | |
797 bits_per_unit = 8; | |
798 #endif | |
799 | |
800 #ifdef MAX_BITSIZE_MODE_ANY_INT | |
801 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT; | |
802 #else | |
803 max_bitsize_mode_any_int = 0; | |
804 #endif | |
131 | 805 |
806 #ifdef MAX_BITSIZE_MODE_ANY_MODE | |
807 max_bitsize_mode_any_mode = MAX_BITSIZE_MODE_ANY_MODE; | |
808 #else | |
809 max_bitsize_mode_any_mode = 0; | |
810 #endif | |
0 | 811 } |
812 | |
131 | 813 #ifndef NUM_POLY_INT_COEFFS |
814 #define NUM_POLY_INT_COEFFS 1 | |
815 #endif | |
816 | |
0 | 817 /* Processing. */ |
818 | |
819 /* Sort a list of modes into the order needed for the WIDER field: | |
820 major sort by precision, minor sort by component precision. | |
821 | |
822 For instance: | |
823 QI < HI < SI < DI < TI | |
824 V4QI < V2HI < V8QI < V4HI < V2SI. | |
825 | |
826 If the precision is not set, sort by the bytesize. A mode with | |
827 precision set gets sorted before a mode without precision set, if | |
828 they have the same bytesize; this is the right thing because | |
829 the precision must always be smaller than the bytesize * BITS_PER_UNIT. | |
830 We don't have to do anything special to get this done -- an unset | |
831 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */ | |
832 static int | |
833 cmp_modes (const void *a, const void *b) | |
834 { | |
835 const struct mode_data *const m = *(const struct mode_data *const*)a; | |
836 const struct mode_data *const n = *(const struct mode_data *const*)b; | |
837 | |
145 | 838 if (m->order > n->order) |
839 return 1; | |
840 else if (m->order < n->order) | |
841 return -1; | |
842 | |
0 | 843 if (m->bytesize > n->bytesize) |
844 return 1; | |
845 else if (m->bytesize < n->bytesize) | |
846 return -1; | |
847 | |
848 if (m->precision > n->precision) | |
849 return 1; | |
850 else if (m->precision < n->precision) | |
851 return -1; | |
852 | |
853 if (!m->component && !n->component) | |
854 { | |
855 if (m->counter < n->counter) | |
856 return -1; | |
857 else | |
858 return 1; | |
859 } | |
860 | |
861 if (m->component->bytesize > n->component->bytesize) | |
862 return 1; | |
863 else if (m->component->bytesize < n->component->bytesize) | |
864 return -1; | |
865 | |
866 if (m->component->precision > n->component->precision) | |
867 return 1; | |
868 else if (m->component->precision < n->component->precision) | |
869 return -1; | |
870 | |
871 if (m->counter < n->counter) | |
872 return -1; | |
873 else | |
874 return 1; | |
875 } | |
876 | |
877 static void | |
878 calc_wider_mode (void) | |
879 { | |
880 int c; | |
881 struct mode_data *m; | |
882 struct mode_data **sortbuf; | |
883 unsigned int max_n_modes = 0; | |
884 unsigned int i, j; | |
885 | |
886 for (c = 0; c < MAX_MODE_CLASS; c++) | |
887 max_n_modes = MAX (max_n_modes, n_modes[c]); | |
888 | |
889 /* Allocate max_n_modes + 1 entries to leave room for the extra null | |
890 pointer assigned after the qsort call below. */ | |
111 | 891 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1); |
0 | 892 |
893 for (c = 0; c < MAX_MODE_CLASS; c++) | |
894 { | |
895 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC. | |
896 However, we want these in textual order, and we have | |
897 precisely the reverse. */ | |
898 if (c == MODE_RANDOM || c == MODE_CC) | |
899 { | |
900 struct mode_data *prev, *next; | |
901 | |
902 for (prev = 0, m = modes[c]; m; m = next) | |
903 { | |
904 m->wider = void_mode; | |
905 | |
906 /* this is nreverse */ | |
907 next = m->next; | |
908 m->next = prev; | |
909 prev = m; | |
910 } | |
911 modes[c] = prev; | |
912 } | |
913 else | |
914 { | |
915 if (!modes[c]) | |
916 continue; | |
917 | |
918 for (i = 0, m = modes[c]; m; i++, m = m->next) | |
919 sortbuf[i] = m; | |
920 | |
111 | 921 (qsort) (sortbuf, i, sizeof (struct mode_data *), cmp_modes); |
0 | 922 |
923 sortbuf[i] = 0; | |
924 for (j = 0; j < i; j++) | |
111 | 925 { |
926 sortbuf[j]->next = sortbuf[j + 1]; | |
927 if (c == MODE_PARTIAL_INT) | |
928 sortbuf[j]->wider = sortbuf[j]->component; | |
929 else | |
930 sortbuf[j]->wider = sortbuf[j]->next; | |
931 } | |
0 | 932 |
933 modes[c] = sortbuf[0]; | |
934 } | |
935 } | |
936 } | |
937 | |
131 | 938 /* Text to add to the constant part of a poly_int_pod initializer in |
939 order to fill out te whole structure. */ | |
940 #if NUM_POLY_INT_COEFFS == 1 | |
941 #define ZERO_COEFFS "" | |
942 #elif NUM_POLY_INT_COEFFS == 2 | |
943 #define ZERO_COEFFS ", 0" | |
944 #else | |
945 #error "Unknown value of NUM_POLY_INT_COEFFS" | |
946 #endif | |
947 | |
0 | 948 /* Output routines. */ |
949 | |
950 #define tagged_printf(FMT, ARG, TAG) do { \ | |
951 int count_ = printf (" " FMT ",", ARG); \ | |
952 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \ | |
953 } while (0) | |
954 | |
955 #define print_decl(TYPE, NAME, ASIZE) \ | |
956 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{"); | |
957 | |
131 | 958 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \ |
0 | 959 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \ |
131 | 960 NEEDS_ADJ ? "" : "const ") |
0 | 961 |
962 #define print_closer() puts ("};") | |
963 | |
111 | 964 /* Compute the max bitsize of some of the classes of integers. It may |
965 be that there are needs for the other integer classes, and this | |
966 code is easy to extend. */ | |
967 static void | |
968 emit_max_int (void) | |
969 { | |
970 unsigned int max, mmax; | |
971 struct mode_data *i; | |
972 int j; | |
973 | |
974 puts (""); | |
975 | |
976 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit); | |
977 | |
978 if (max_bitsize_mode_any_int == 0) | |
979 { | |
980 for (max = 1, i = modes[MODE_INT]; i; i = i->next) | |
981 if (max < i->bytesize) | |
982 max = i->bytesize; | |
983 mmax = max; | |
984 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next) | |
985 if (max < i->bytesize) | |
986 max = i->bytesize; | |
987 if (max > mmax) | |
988 mmax = max; | |
989 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax); | |
990 } | |
991 else | |
992 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int); | |
993 | |
131 | 994 if (max_bitsize_mode_any_mode == 0) |
995 { | |
996 mmax = 0; | |
997 for (j = 0; j < MAX_MODE_CLASS; j++) | |
998 for (i = modes[j]; i; i = i->next) | |
999 if (mmax < i->bytesize) | |
1000 mmax = i->bytesize; | |
1001 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax); | |
1002 } | |
1003 else | |
1004 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n", | |
1005 max_bitsize_mode_any_mode); | |
111 | 1006 } |
1007 | |
1008 /* Emit mode_size_inline routine into insn-modes.h header. */ | |
1009 static void | |
1010 emit_mode_size_inline (void) | |
1011 { | |
1012 int c; | |
1013 struct mode_adjust *a; | |
1014 struct mode_data *m; | |
1015 | |
1016 /* Size adjustments must be propagated to all containing modes. */ | |
1017 for (a = adj_bytesize; a; a = a->next) | |
1018 { | |
1019 a->mode->need_bytesize_adj = true; | |
1020 for (m = a->mode->contained; m; m = m->next_cont) | |
1021 m->need_bytesize_adj = true; | |
1022 } | |
1023 | |
131 | 1024 /* Changing the number of units by a factor of X also changes the size |
1025 by a factor of X. */ | |
1026 for (mode_adjust *a = adj_nunits; a; a = a->next) | |
1027 a->mode->need_bytesize_adj = true; | |
1028 | |
111 | 1029 printf ("\ |
1030 #ifdef __cplusplus\n\ | |
1031 inline __attribute__((__always_inline__))\n\ | |
1032 #else\n\ | |
1033 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1034 #endif\n\ | |
131 | 1035 poly_uint16\n\ |
111 | 1036 mode_size_inline (machine_mode mode)\n\ |
1037 {\n\ | |
131 | 1038 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\ |
111 | 1039 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ |
1040 switch (mode)\n\ | |
131 | 1041 {\n", adj_nunits || adj_bytesize ? "" : "const "); |
111 | 1042 |
1043 for_all_modes (c, m) | |
1044 if (!m->need_bytesize_adj) | |
1045 printf (" case E_%smode: return %u;\n", m->name, m->bytesize); | |
1046 | |
1047 puts ("\ | |
1048 default: return mode_size[mode];\n\ | |
1049 }\n\ | |
1050 }\n"); | |
1051 } | |
1052 | |
1053 /* Emit mode_nunits_inline routine into insn-modes.h header. */ | |
1054 static void | |
1055 emit_mode_nunits_inline (void) | |
1056 { | |
1057 int c; | |
1058 struct mode_data *m; | |
1059 | |
131 | 1060 for (mode_adjust *a = adj_nunits; a; a = a->next) |
1061 a->mode->need_nunits_adj = true; | |
1062 | |
1063 printf ("\ | |
111 | 1064 #ifdef __cplusplus\n\ |
1065 inline __attribute__((__always_inline__))\n\ | |
1066 #else\n\ | |
1067 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1068 #endif\n\ | |
131 | 1069 poly_uint16\n\ |
111 | 1070 mode_nunits_inline (machine_mode mode)\n\ |
1071 {\n\ | |
131 | 1072 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\ |
111 | 1073 switch (mode)\n\ |
131 | 1074 {\n", adj_nunits ? "" : "const "); |
111 | 1075 |
1076 for_all_modes (c, m) | |
131 | 1077 if (!m->need_nunits_adj) |
1078 printf (" case E_%smode: return %u;\n", m->name, m->ncomponents); | |
111 | 1079 |
1080 puts ("\ | |
1081 default: return mode_nunits[mode];\n\ | |
1082 }\n\ | |
1083 }\n"); | |
1084 } | |
1085 | |
1086 /* Emit mode_inner_inline routine into insn-modes.h header. */ | |
1087 static void | |
1088 emit_mode_inner_inline (void) | |
1089 { | |
1090 int c; | |
1091 struct mode_data *m; | |
1092 | |
1093 puts ("\ | |
1094 #ifdef __cplusplus\n\ | |
1095 inline __attribute__((__always_inline__))\n\ | |
1096 #else\n\ | |
1097 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1098 #endif\n\ | |
1099 unsigned char\n\ | |
1100 mode_inner_inline (machine_mode mode)\n\ | |
1101 {\n\ | |
1102 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\ | |
1103 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ | |
1104 switch (mode)\n\ | |
1105 {"); | |
1106 | |
1107 for_all_modes (c, m) | |
1108 printf (" case E_%smode: return E_%smode;\n", m->name, | |
1109 c != MODE_PARTIAL_INT && m->component | |
1110 ? m->component->name : m->name); | |
1111 | |
1112 puts ("\ | |
1113 default: return mode_inner[mode];\n\ | |
1114 }\n\ | |
1115 }\n"); | |
1116 } | |
1117 | |
1118 /* Emit mode_unit_size_inline routine into insn-modes.h header. */ | |
1119 static void | |
1120 emit_mode_unit_size_inline (void) | |
1121 { | |
1122 int c; | |
1123 struct mode_data *m; | |
1124 | |
1125 puts ("\ | |
1126 #ifdef __cplusplus\n\ | |
1127 inline __attribute__((__always_inline__))\n\ | |
1128 #else\n\ | |
1129 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1130 #endif\n\ | |
1131 unsigned char\n\ | |
1132 mode_unit_size_inline (machine_mode mode)\n\ | |
1133 {\n\ | |
1134 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\ | |
1135 \n\ | |
1136 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ | |
1137 switch (mode)\n\ | |
1138 {"); | |
1139 | |
1140 for_all_modes (c, m) | |
1141 { | |
1142 const char *name = m->name; | |
1143 struct mode_data *m2 = m; | |
1144 if (c != MODE_PARTIAL_INT && m2->component) | |
1145 m2 = m2->component; | |
1146 if (!m2->need_bytesize_adj) | |
1147 printf (" case E_%smode: return %u;\n", name, m2->bytesize); | |
1148 } | |
1149 | |
1150 puts ("\ | |
1151 default: return mode_unit_size[mode];\n\ | |
1152 }\n\ | |
1153 }\n"); | |
1154 } | |
1155 | |
1156 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */ | |
1157 static void | |
1158 emit_mode_unit_precision_inline (void) | |
1159 { | |
1160 int c; | |
1161 struct mode_data *m; | |
1162 | |
1163 puts ("\ | |
1164 #ifdef __cplusplus\n\ | |
1165 inline __attribute__((__always_inline__))\n\ | |
1166 #else\n\ | |
1167 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\ | |
1168 #endif\n\ | |
1169 unsigned short\n\ | |
1170 mode_unit_precision_inline (machine_mode mode)\n\ | |
1171 {\n\ | |
1172 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\ | |
1173 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\ | |
1174 switch (mode)\n\ | |
1175 {"); | |
1176 | |
1177 for_all_modes (c, m) | |
1178 { | |
1179 struct mode_data *m2 | |
1180 = (c != MODE_PARTIAL_INT && m->component) ? m->component : m; | |
1181 if (m2->precision != (unsigned int)-1) | |
1182 printf (" case E_%smode: return %u;\n", m->name, m2->precision); | |
1183 else | |
1184 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n", | |
1185 m->name, m2->bytesize); | |
1186 } | |
1187 | |
1188 puts ("\ | |
1189 default: return mode_unit_precision[mode];\n\ | |
1190 }\n\ | |
1191 }\n"); | |
1192 } | |
1193 | |
1194 /* Return the best machine mode class for MODE, or null if machine_mode | |
1195 should be used. */ | |
1196 | |
1197 static const char * | |
1198 get_mode_class (struct mode_data *mode) | |
1199 { | |
1200 switch (mode->cl) | |
1201 { | |
1202 case MODE_INT: | |
1203 case MODE_PARTIAL_INT: | |
1204 return "scalar_int_mode"; | |
1205 | |
1206 case MODE_FRACT: | |
1207 case MODE_UFRACT: | |
1208 case MODE_ACCUM: | |
1209 case MODE_UACCUM: | |
1210 return "scalar_mode"; | |
1211 | |
1212 case MODE_FLOAT: | |
1213 case MODE_DECIMAL_FLOAT: | |
1214 return "scalar_float_mode"; | |
1215 | |
1216 case MODE_COMPLEX_INT: | |
1217 case MODE_COMPLEX_FLOAT: | |
1218 return "complex_mode"; | |
1219 | |
1220 default: | |
1221 return NULL; | |
1222 } | |
1223 } | |
1224 | |
0 | 1225 static void |
1226 emit_insn_modes_h (void) | |
1227 { | |
1228 int c; | |
1229 struct mode_data *m, *first, *last; | |
111 | 1230 int n_int_n_ents = 0; |
0 | 1231 |
1232 printf ("/* Generated automatically from machmode.def%s%s\n", | |
1233 HAVE_EXTRA_MODES ? " and " : "", | |
1234 EXTRA_MODES_FILE); | |
1235 | |
1236 puts ("\ | |
1237 by genmodes. */\n\ | |
1238 \n\ | |
1239 #ifndef GCC_INSN_MODES_H\n\ | |
1240 #define GCC_INSN_MODES_H\n\ | |
1241 \n\ | |
1242 enum machine_mode\n{"); | |
1243 | |
1244 for (c = 0; c < MAX_MODE_CLASS; c++) | |
1245 for (m = modes[c]; m; m = m->next) | |
1246 { | |
111 | 1247 int count_ = printf (" E_%smode,", m->name); |
0 | 1248 printf ("%*s/* %s:%d */\n", 27 - count_, "", |
1249 trim_filename (m->file), m->line); | |
111 | 1250 printf ("#define HAVE_%smode\n", m->name); |
1251 printf ("#ifdef USE_ENUM_MODES\n"); | |
1252 printf ("#define %smode E_%smode\n", m->name, m->name); | |
1253 printf ("#else\n"); | |
1254 if (const char *mode_class = get_mode_class (m)) | |
1255 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n", | |
1256 m->name, mode_class, mode_class, m->name); | |
1257 else | |
1258 printf ("#define %smode ((void) 0, E_%smode)\n", | |
1259 m->name, m->name); | |
1260 printf ("#endif\n"); | |
0 | 1261 } |
1262 | |
1263 puts (" MAX_MACHINE_MODE,\n"); | |
1264 | |
1265 for (c = 0; c < MAX_MODE_CLASS; c++) | |
1266 { | |
1267 first = modes[c]; | |
1268 last = 0; | |
1269 for (m = first; m; last = m, m = m->next) | |
1270 ; | |
1271 | |
1272 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle | |
1273 end will try to use it for bitfields in structures and the | |
1274 like, which we do not want. Only the target md file should | |
1275 generate BImode widgets. */ | |
111 | 1276 if (first && first->precision == 1 && c == MODE_INT) |
0 | 1277 first = first->next; |
1278 | |
1279 if (first && last) | |
111 | 1280 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n", |
0 | 1281 mode_class_names[c], first->name, |
1282 mode_class_names[c], last->name); | |
1283 else | |
111 | 1284 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n", |
0 | 1285 mode_class_names[c], void_mode->name, |
1286 mode_class_names[c], void_mode->name); | |
1287 } | |
1288 | |
1289 puts ("\ | |
1290 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\ | |
1291 };\n"); | |
1292 | |
1293 /* I can't think of a better idea, can you? */ | |
131 | 1294 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const"); |
1295 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const"); | |
1296 printf ("#define CONST_MODE_SIZE%s\n", | |
1297 adj_bytesize || adj_nunits ? "" : " const"); | |
111 | 1298 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const"); |
0 | 1299 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const"); |
1300 #if 0 /* disabled for backward compatibility, temporary */ | |
1301 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const"); | |
1302 #endif | |
1303 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const"); | |
1304 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const"); | |
111 | 1305 emit_max_int (); |
1306 | |
1307 for_all_modes (c, m) | |
1308 if (m->int_n) | |
1309 n_int_n_ents ++; | |
1310 | |
1311 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents); | |
1312 | |
131 | 1313 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS); |
1314 | |
0 | 1315 puts ("\ |
1316 \n\ | |
1317 #endif /* insn-modes.h */"); | |
1318 } | |
1319 | |
1320 static void | |
111 | 1321 emit_insn_modes_inline_h (void) |
1322 { | |
1323 printf ("/* Generated automatically from machmode.def%s%s\n", | |
1324 HAVE_EXTRA_MODES ? " and " : "", | |
1325 EXTRA_MODES_FILE); | |
1326 | |
1327 puts ("\ | |
1328 by genmodes. */\n\ | |
1329 \n\ | |
1330 #ifndef GCC_INSN_MODES_INLINE_H\n\ | |
1331 #define GCC_INSN_MODES_INLINE_H"); | |
1332 | |
1333 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n"); | |
1334 emit_mode_size_inline (); | |
1335 emit_mode_nunits_inline (); | |
1336 emit_mode_inner_inline (); | |
1337 emit_mode_unit_size_inline (); | |
1338 emit_mode_unit_precision_inline (); | |
1339 puts ("#endif /* GCC_VERSION >= 4001 */"); | |
1340 | |
1341 puts ("\ | |
1342 \n\ | |
1343 #endif /* insn-modes-inline.h */"); | |
1344 } | |
1345 | |
1346 static void | |
0 | 1347 emit_insn_modes_c_header (void) |
1348 { | |
1349 printf ("/* Generated automatically from machmode.def%s%s\n", | |
1350 HAVE_EXTRA_MODES ? " and " : "", | |
1351 EXTRA_MODES_FILE); | |
1352 | |
1353 puts ("\ | |
1354 by genmodes. */\n\ | |
1355 \n\ | |
1356 #include \"config.h\"\n\ | |
1357 #include \"system.h\"\n\ | |
1358 #include \"coretypes.h\"\n\ | |
1359 #include \"tm.h\"\n\ | |
1360 #include \"real.h\""); | |
1361 } | |
1362 | |
1363 static void | |
1364 emit_min_insn_modes_c_header (void) | |
1365 { | |
1366 printf ("/* Generated automatically from machmode.def%s%s\n", | |
1367 HAVE_EXTRA_MODES ? " and " : "", | |
1368 EXTRA_MODES_FILE); | |
1369 | |
1370 puts ("\ | |
1371 by genmodes. */\n\ | |
1372 \n\ | |
1373 #include \"bconfig.h\"\n\ | |
1374 #include \"system.h\"\n\ | |
111 | 1375 #include \"coretypes.h\""); |
0 | 1376 } |
1377 | |
1378 static void | |
1379 emit_mode_name (void) | |
1380 { | |
1381 int c; | |
1382 struct mode_data *m; | |
1383 | |
1384 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES"); | |
1385 | |
1386 for_all_modes (c, m) | |
1387 printf (" \"%s\",\n", m->name); | |
1388 | |
1389 print_closer (); | |
1390 } | |
1391 | |
1392 static void | |
1393 emit_mode_class (void) | |
1394 { | |
1395 int c; | |
1396 struct mode_data *m; | |
1397 | |
1398 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES"); | |
1399 | |
1400 for_all_modes (c, m) | |
1401 tagged_printf ("%s", mode_class_names[m->cl], m->name); | |
1402 | |
1403 print_closer (); | |
1404 } | |
1405 | |
1406 static void | |
1407 emit_mode_precision (void) | |
1408 { | |
1409 int c; | |
1410 struct mode_data *m; | |
1411 | |
131 | 1412 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision", |
1413 "NUM_MACHINE_MODES", adj_nunits); | |
0 | 1414 |
1415 for_all_modes (c, m) | |
1416 if (m->precision != (unsigned int)-1) | |
131 | 1417 tagged_printf ("{ %u" ZERO_COEFFS " }", m->precision, m->name); |
0 | 1418 else |
131 | 1419 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS " }", |
1420 m->bytesize, m->name); | |
0 | 1421 |
1422 print_closer (); | |
1423 } | |
1424 | |
1425 static void | |
1426 emit_mode_size (void) | |
1427 { | |
1428 int c; | |
1429 struct mode_data *m; | |
1430 | |
131 | 1431 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size", |
1432 "NUM_MACHINE_MODES", adj_nunits || adj_bytesize); | |
0 | 1433 |
1434 for_all_modes (c, m) | |
131 | 1435 tagged_printf ("{ %u" ZERO_COEFFS " }", m->bytesize, m->name); |
0 | 1436 |
1437 print_closer (); | |
1438 } | |
1439 | |
1440 static void | |
1441 emit_mode_nunits (void) | |
1442 { | |
1443 int c; | |
1444 struct mode_data *m; | |
1445 | |
131 | 1446 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits", |
1447 "NUM_MACHINE_MODES", adj_nunits); | |
0 | 1448 |
1449 for_all_modes (c, m) | |
131 | 1450 tagged_printf ("{ %u" ZERO_COEFFS " }", m->ncomponents, m->name); |
0 | 1451 |
1452 print_closer (); | |
1453 } | |
1454 | |
1455 static void | |
1456 emit_mode_wider (void) | |
1457 { | |
1458 int c; | |
1459 struct mode_data *m; | |
1460 | |
1461 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES"); | |
1462 | |
1463 for_all_modes (c, m) | |
111 | 1464 tagged_printf ("E_%smode", |
0 | 1465 m->wider ? m->wider->name : void_mode->name, |
1466 m->name); | |
1467 | |
1468 print_closer (); | |
1469 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES"); | |
1470 | |
1471 for_all_modes (c, m) | |
1472 { | |
1473 struct mode_data * m2; | |
1474 | |
1475 for (m2 = m; | |
1476 m2 && m2 != void_mode; | |
1477 m2 = m2->wider) | |
1478 { | |
1479 if (m2->bytesize < 2 * m->bytesize) | |
1480 continue; | |
1481 if (m->precision != (unsigned int) -1) | |
1482 { | |
1483 if (m2->precision != 2 * m->precision) | |
1484 continue; | |
1485 } | |
1486 else | |
1487 { | |
1488 if (m2->precision != (unsigned int) -1) | |
1489 continue; | |
1490 } | |
1491 | |
111 | 1492 /* For vectors we want twice the number of components, |
1493 with the same element type. */ | |
131 | 1494 if (m->cl == MODE_VECTOR_BOOL |
1495 || m->cl == MODE_VECTOR_INT | |
111 | 1496 || m->cl == MODE_VECTOR_FLOAT |
1497 || m->cl == MODE_VECTOR_FRACT | |
1498 || m->cl == MODE_VECTOR_UFRACT | |
1499 || m->cl == MODE_VECTOR_ACCUM | |
1500 || m->cl == MODE_VECTOR_UACCUM) | |
1501 { | |
1502 if (m2->ncomponents != 2 * m->ncomponents) | |
1503 continue; | |
1504 if (m->component != m2->component) | |
1505 continue; | |
1506 } | |
1507 | |
0 | 1508 break; |
1509 } | |
1510 if (m2 == void_mode) | |
1511 m2 = 0; | |
111 | 1512 tagged_printf ("E_%smode", |
0 | 1513 m2 ? m2->name : void_mode->name, |
1514 m->name); | |
1515 } | |
1516 | |
1517 print_closer (); | |
1518 } | |
1519 | |
1520 static void | |
111 | 1521 emit_mode_complex (void) |
1522 { | |
1523 int c; | |
1524 struct mode_data *m; | |
1525 | |
1526 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES"); | |
1527 | |
1528 for_all_modes (c, m) | |
1529 tagged_printf ("E_%smode", | |
1530 m->complex ? m->complex->name : void_mode->name, | |
1531 m->name); | |
1532 | |
1533 print_closer (); | |
1534 } | |
1535 | |
1536 static void | |
0 | 1537 emit_mode_mask (void) |
1538 { | |
1539 int c; | |
1540 struct mode_data *m; | |
1541 | |
1542 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array", | |
1543 "NUM_MACHINE_MODES"); | |
1544 puts ("\ | |
1545 #define MODE_MASK(m) \\\n\ | |
1546 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\ | |
111 | 1547 ? HOST_WIDE_INT_M1U \\\n\ |
1548 : (HOST_WIDE_INT_1U << (m)) - 1\n"); | |
0 | 1549 |
1550 for_all_modes (c, m) | |
1551 if (m->precision != (unsigned int)-1) | |
1552 tagged_printf ("MODE_MASK (%u)", m->precision, m->name); | |
1553 else | |
1554 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name); | |
1555 | |
1556 puts ("#undef MODE_MASK"); | |
1557 print_closer (); | |
1558 } | |
1559 | |
1560 static void | |
1561 emit_mode_inner (void) | |
1562 { | |
1563 int c; | |
1564 struct mode_data *m; | |
1565 | |
1566 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES"); | |
1567 | |
1568 for_all_modes (c, m) | |
111 | 1569 tagged_printf ("E_%smode", |
1570 c != MODE_PARTIAL_INT && m->component | |
1571 ? m->component->name : m->name, | |
0 | 1572 m->name); |
1573 | |
1574 print_closer (); | |
1575 } | |
1576 | |
111 | 1577 /* Emit mode_unit_size array into insn-modes.c file. */ |
1578 static void | |
1579 emit_mode_unit_size (void) | |
1580 { | |
1581 int c; | |
1582 struct mode_data *m; | |
1583 | |
1584 print_maybe_const_decl ("%sunsigned char", "mode_unit_size", | |
131 | 1585 "NUM_MACHINE_MODES", adj_bytesize); |
111 | 1586 |
1587 for_all_modes (c, m) | |
1588 tagged_printf ("%u", | |
1589 c != MODE_PARTIAL_INT && m->component | |
1590 ? m->component->bytesize : m->bytesize, m->name); | |
1591 | |
1592 print_closer (); | |
1593 } | |
1594 | |
1595 /* Emit mode_unit_precision array into insn-modes.c file. */ | |
1596 static void | |
1597 emit_mode_unit_precision (void) | |
1598 { | |
1599 int c; | |
1600 struct mode_data *m; | |
1601 | |
1602 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES"); | |
1603 | |
1604 for_all_modes (c, m) | |
1605 { | |
1606 struct mode_data *m2 = (c != MODE_PARTIAL_INT && m->component) ? | |
1607 m->component : m; | |
1608 if (m2->precision != (unsigned int)-1) | |
1609 tagged_printf ("%u", m2->precision, m->name); | |
1610 else | |
1611 tagged_printf ("%u*BITS_PER_UNIT", m2->bytesize, m->name); | |
1612 } | |
1613 | |
1614 print_closer (); | |
1615 } | |
1616 | |
1617 | |
0 | 1618 static void |
1619 emit_mode_base_align (void) | |
1620 { | |
1621 int c; | |
1622 struct mode_data *m; | |
1623 | |
111 | 1624 print_maybe_const_decl ("%sunsigned short", |
0 | 1625 "mode_base_align", "NUM_MACHINE_MODES", |
131 | 1626 adj_alignment); |
0 | 1627 |
1628 for_all_modes (c, m) | |
1629 tagged_printf ("%u", m->alignment, m->name); | |
1630 | |
1631 print_closer (); | |
1632 } | |
1633 | |
1634 static void | |
1635 emit_class_narrowest_mode (void) | |
1636 { | |
1637 int c; | |
1638 | |
1639 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS"); | |
1640 | |
1641 for (c = 0; c < MAX_MODE_CLASS; c++) | |
1642 /* Bleah, all this to get the comment right for MIN_MODE_INT. */ | |
1643 tagged_printf ("MIN_%s", mode_class_names[c], | |
1644 modes[c] | |
111 | 1645 ? ((c != MODE_INT || modes[c]->precision != 1) |
0 | 1646 ? modes[c]->name |
1647 : (modes[c]->next | |
1648 ? modes[c]->next->name | |
1649 : void_mode->name)) | |
1650 : void_mode->name); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1651 |
0 | 1652 print_closer (); |
1653 } | |
1654 | |
1655 static void | |
1656 emit_real_format_for_mode (void) | |
1657 { | |
1658 struct mode_data *m; | |
1659 | |
1660 /* The entities pointed to by this table are constant, whether | |
1661 or not the table itself is constant. | |
1662 | |
1663 For backward compatibility this table is always writable | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1664 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME: |
0 | 1665 convert all said targets to use ADJUST_FORMAT instead. */ |
1666 #if 0 | |
1667 print_maybe_const_decl ("const struct real_format *%s", | |
1668 "real_format_for_mode", | |
1669 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1", | |
1670 format); | |
1671 #else | |
1672 print_decl ("struct real_format *\n", "real_format_for_mode", | |
1673 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 " | |
1674 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1"); | |
1675 #endif | |
1676 | |
1677 /* The beginning of the table is entries for float modes. */ | |
1678 for (m = modes[MODE_FLOAT]; m; m = m->next) | |
1679 if (!strcmp (m->format, "0")) | |
1680 tagged_printf ("%s", m->format, m->name); | |
1681 else | |
1682 tagged_printf ("&%s", m->format, m->name); | |
1683 | |
1684 /* The end of the table is entries for decimal float modes. */ | |
1685 for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next) | |
1686 if (!strcmp (m->format, "0")) | |
1687 tagged_printf ("%s", m->format, m->name); | |
1688 else | |
1689 tagged_printf ("&%s", m->format, m->name); | |
1690 | |
1691 print_closer (); | |
1692 } | |
1693 | |
1694 static void | |
1695 emit_mode_adjustments (void) | |
1696 { | |
1697 struct mode_adjust *a; | |
1698 struct mode_data *m; | |
1699 | |
1700 puts ("\ | |
1701 \nvoid\ | |
1702 \ninit_adjust_machine_modes (void)\ | |
1703 \n{\ | |
131 | 1704 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\ |
1705 size_t s ATTRIBUTE_UNUSED;"); | |
1706 | |
1707 for (a = adj_nunits; a; a = a->next) | |
1708 { | |
1709 m = a->mode; | |
1710 printf ("\n" | |
1711 " {\n" | |
1712 " /* %s:%d */\n ps = %s;\n", | |
1713 a->file, a->line, a->adjustment); | |
1714 printf (" int old_factor = vector_element_size" | |
1715 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n", | |
1716 m->name, m->name); | |
1717 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m->name); | |
1718 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode]," | |
1719 " BITS_PER_UNIT);\n", m->name, m->name); | |
1720 printf (" mode_nunits[E_%smode] = ps;\n", m->name); | |
1721 printf (" }\n"); | |
1722 } | |
0 | 1723 |
1724 /* Size adjustments must be propagated to all containing modes. | |
1725 A size adjustment forces us to recalculate the alignment too. */ | |
1726 for (a = adj_bytesize; a; a = a->next) | |
1727 { | |
131 | 1728 printf ("\n /* %s:%d */\n", a->file, a->line); |
1729 switch (a->mode->cl) | |
1730 { | |
1731 case MODE_VECTOR_BOOL: | |
1732 case MODE_VECTOR_INT: | |
1733 case MODE_VECTOR_FLOAT: | |
1734 case MODE_VECTOR_FRACT: | |
1735 case MODE_VECTOR_UFRACT: | |
1736 case MODE_VECTOR_ACCUM: | |
1737 case MODE_VECTOR_UACCUM: | |
1738 printf (" ps = %s;\n", a->adjustment); | |
1739 printf (" s = mode_unit_size[E_%smode];\n", a->mode->name); | |
1740 break; | |
1741 | |
1742 default: | |
1743 printf (" ps = s = %s;\n", a->adjustment); | |
1744 printf (" mode_unit_size[E_%smode] = s;\n", a->mode->name); | |
1745 break; | |
1746 } | |
1747 printf (" mode_size[E_%smode] = ps;\n", a->mode->name); | |
1748 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n", | |
0 | 1749 a->mode->name); |
1750 | |
1751 for (m = a->mode->contained; m; m = m->next_cont) | |
1752 { | |
1753 switch (m->cl) | |
1754 { | |
1755 case MODE_COMPLEX_INT: | |
1756 case MODE_COMPLEX_FLOAT: | |
111 | 1757 printf (" mode_size[E_%smode] = 2*s;\n", m->name); |
1758 printf (" mode_unit_size[E_%smode] = s;\n", m->name); | |
1759 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n", | |
0 | 1760 m->name); |
1761 break; | |
1762 | |
131 | 1763 case MODE_VECTOR_BOOL: |
1764 /* Changes to BImode should not affect vector booleans. */ | |
1765 break; | |
1766 | |
0 | 1767 case MODE_VECTOR_INT: |
1768 case MODE_VECTOR_FLOAT: | |
1769 case MODE_VECTOR_FRACT: | |
1770 case MODE_VECTOR_UFRACT: | |
1771 case MODE_VECTOR_ACCUM: | |
1772 case MODE_VECTOR_UACCUM: | |
131 | 1773 printf (" mode_size[E_%smode] = %d * ps;\n", |
0 | 1774 m->name, m->ncomponents); |
111 | 1775 printf (" mode_unit_size[E_%smode] = s;\n", m->name); |
131 | 1776 printf (" mode_base_align[E_%smode]" |
1777 " = known_alignment (%d * ps);\n", | |
1778 m->name, m->ncomponents); | |
0 | 1779 break; |
1780 | |
1781 default: | |
1782 internal_error ( | |
1783 "mode %s is neither vector nor complex but contains %s", | |
1784 m->name, a->mode->name); | |
1785 /* NOTREACHED */ | |
1786 } | |
1787 } | |
1788 } | |
1789 | |
1790 /* Alignment adjustments propagate too. | |
1791 ??? This may not be the right thing for vector modes. */ | |
1792 for (a = adj_alignment; a; a = a->next) | |
1793 { | |
1794 printf ("\n /* %s:%d */\n s = %s;\n", | |
1795 a->file, a->line, a->adjustment); | |
111 | 1796 printf (" mode_base_align[E_%smode] = s;\n", a->mode->name); |
0 | 1797 |
1798 for (m = a->mode->contained; m; m = m->next_cont) | |
1799 { | |
1800 switch (m->cl) | |
1801 { | |
1802 case MODE_COMPLEX_INT: | |
1803 case MODE_COMPLEX_FLOAT: | |
111 | 1804 printf (" mode_base_align[E_%smode] = s;\n", m->name); |
0 | 1805 break; |
1806 | |
131 | 1807 case MODE_VECTOR_BOOL: |
1808 /* Changes to BImode should not affect vector booleans. */ | |
1809 break; | |
1810 | |
0 | 1811 case MODE_VECTOR_INT: |
1812 case MODE_VECTOR_FLOAT: | |
1813 case MODE_VECTOR_FRACT: | |
1814 case MODE_VECTOR_UFRACT: | |
1815 case MODE_VECTOR_ACCUM: | |
1816 case MODE_VECTOR_UACCUM: | |
111 | 1817 printf (" mode_base_align[E_%smode] = %d*s;\n", |
0 | 1818 m->name, m->ncomponents); |
1819 break; | |
1820 | |
1821 default: | |
1822 internal_error ( | |
1823 "mode %s is neither vector nor complex but contains %s", | |
1824 m->name, a->mode->name); | |
1825 /* NOTREACHED */ | |
1826 } | |
1827 } | |
1828 } | |
1829 | |
1830 /* Ibit adjustments don't have to propagate. */ | |
1831 for (a = adj_ibit; a; a = a->next) | |
1832 { | |
1833 printf ("\n /* %s:%d */\n s = %s;\n", | |
1834 a->file, a->line, a->adjustment); | |
111 | 1835 printf (" mode_ibit[E_%smode] = s;\n", a->mode->name); |
0 | 1836 } |
1837 | |
1838 /* Fbit adjustments don't have to propagate. */ | |
1839 for (a = adj_fbit; a; a = a->next) | |
1840 { | |
1841 printf ("\n /* %s:%d */\n s = %s;\n", | |
1842 a->file, a->line, a->adjustment); | |
111 | 1843 printf (" mode_fbit[E_%smode] = s;\n", a->mode->name); |
0 | 1844 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1845 |
0 | 1846 /* Real mode formats don't have to propagate anywhere. */ |
1847 for (a = adj_format; a; a = a->next) | |
111 | 1848 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n", |
0 | 1849 a->file, a->line, a->mode->name, a->adjustment); |
1850 | |
1851 puts ("}"); | |
1852 } | |
1853 | |
1854 /* Emit ibit for all modes. */ | |
1855 | |
1856 static void | |
1857 emit_mode_ibit (void) | |
1858 { | |
1859 int c; | |
1860 struct mode_data *m; | |
1861 | |
1862 print_maybe_const_decl ("%sunsigned char", | |
1863 "mode_ibit", "NUM_MACHINE_MODES", | |
131 | 1864 adj_ibit); |
0 | 1865 |
1866 for_all_modes (c, m) | |
1867 tagged_printf ("%u", m->ibit, m->name); | |
1868 | |
1869 print_closer (); | |
1870 } | |
1871 | |
1872 /* Emit fbit for all modes. */ | |
1873 | |
1874 static void | |
1875 emit_mode_fbit (void) | |
1876 { | |
1877 int c; | |
1878 struct mode_data *m; | |
1879 | |
1880 print_maybe_const_decl ("%sunsigned char", | |
1881 "mode_fbit", "NUM_MACHINE_MODES", | |
131 | 1882 adj_fbit); |
0 | 1883 |
1884 for_all_modes (c, m) | |
1885 tagged_printf ("%u", m->fbit, m->name); | |
1886 | |
1887 print_closer (); | |
1888 } | |
1889 | |
111 | 1890 /* Emit __intN for all modes. */ |
1891 | |
1892 static void | |
1893 emit_mode_int_n (void) | |
1894 { | |
1895 int c; | |
1896 struct mode_data *m; | |
1897 struct mode_data **mode_sort; | |
1898 int n_modes = 0; | |
1899 int i, j; | |
1900 | |
1901 print_decl ("int_n_data_t", "int_n_data", ""); | |
1902 | |
1903 n_modes = 0; | |
1904 for_all_modes (c, m) | |
1905 if (m->int_n) | |
1906 n_modes ++; | |
1907 mode_sort = XALLOCAVEC (struct mode_data *, n_modes); | |
1908 | |
1909 n_modes = 0; | |
1910 for_all_modes (c, m) | |
1911 if (m->int_n) | |
1912 mode_sort[n_modes++] = m; | |
1913 | |
1914 /* Yes, this is a bubblesort, but there are at most four (and | |
1915 usually only 1-2) entries to sort. */ | |
1916 for (i = 0; i<n_modes - 1; i++) | |
1917 for (j = i + 1; j < n_modes; j++) | |
1918 if (mode_sort[i]->int_n > mode_sort[j]->int_n) | |
1919 std::swap (mode_sort[i], mode_sort[j]); | |
1920 | |
1921 for (i = 0; i < n_modes; i ++) | |
1922 { | |
1923 m = mode_sort[i]; | |
1924 printf(" {\n"); | |
1925 tagged_printf ("%u", m->int_n, m->name); | |
1926 printf ("{ E_%smode },", m->name); | |
1927 printf(" },\n"); | |
1928 } | |
1929 | |
1930 print_closer (); | |
1931 } | |
1932 | |
0 | 1933 |
1934 static void | |
1935 emit_insn_modes_c (void) | |
1936 { | |
1937 emit_insn_modes_c_header (); | |
1938 emit_mode_name (); | |
1939 emit_mode_class (); | |
1940 emit_mode_precision (); | |
1941 emit_mode_size (); | |
1942 emit_mode_nunits (); | |
1943 emit_mode_wider (); | |
111 | 1944 emit_mode_complex (); |
0 | 1945 emit_mode_mask (); |
1946 emit_mode_inner (); | |
111 | 1947 emit_mode_unit_size (); |
1948 emit_mode_unit_precision (); | |
0 | 1949 emit_mode_base_align (); |
1950 emit_class_narrowest_mode (); | |
1951 emit_real_format_for_mode (); | |
1952 emit_mode_adjustments (); | |
1953 emit_mode_ibit (); | |
1954 emit_mode_fbit (); | |
111 | 1955 emit_mode_int_n (); |
0 | 1956 } |
1957 | |
1958 static void | |
1959 emit_min_insn_modes_c (void) | |
1960 { | |
1961 emit_min_insn_modes_c_header (); | |
1962 emit_mode_name (); | |
1963 emit_mode_class (); | |
111 | 1964 emit_mode_nunits (); |
0 | 1965 emit_mode_wider (); |
111 | 1966 emit_mode_inner (); |
0 | 1967 emit_class_narrowest_mode (); |
1968 } | |
1969 | |
1970 /* Master control. */ | |
1971 int | |
1972 main (int argc, char **argv) | |
1973 { | |
111 | 1974 bool gen_header = false, gen_inlines = false, gen_min = false; |
0 | 1975 progname = argv[0]; |
1976 | |
1977 if (argc == 1) | |
1978 ; | |
1979 else if (argc == 2 && !strcmp (argv[1], "-h")) | |
1980 gen_header = true; | |
111 | 1981 else if (argc == 2 && !strcmp (argv[1], "-i")) |
1982 gen_inlines = true; | |
0 | 1983 else if (argc == 2 && !strcmp (argv[1], "-m")) |
1984 gen_min = true; | |
1985 else | |
1986 { | |
111 | 1987 error ("usage: %s [-h|-i|-m] > file", progname); |
0 | 1988 return FATAL_EXIT_CODE; |
1989 } | |
1990 | |
1991 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free); | |
1992 | |
1993 create_modes (); | |
1994 complete_all_modes (); | |
1995 | |
1996 if (have_error) | |
1997 return FATAL_EXIT_CODE; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1998 |
0 | 1999 calc_wider_mode (); |
2000 | |
2001 if (gen_header) | |
2002 emit_insn_modes_h (); | |
111 | 2003 else if (gen_inlines) |
2004 emit_insn_modes_inline_h (); | |
0 | 2005 else if (gen_min) |
2006 emit_min_insn_modes_c (); | |
2007 else | |
2008 emit_insn_modes_c (); | |
2009 | |
2010 if (fflush (stdout) || fclose (stdout)) | |
2011 return FATAL_EXIT_CODE; | |
2012 return SUCCESS_EXIT_CODE; | |
2013 } |