1 /* This file is part of the program psim.
3 Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "ld-decode.h"
33 sub_val (insn_uint val,
34 insn_field_entry *field,
38 return ((val >> (field->last - last_pos))
39 & (((insn_uint)1 << (last_pos - first_pos + 1)) - 1));
43 update_depth (lf *file,
48 int *max_depth = (int*)data;
49 if (*max_depth < depth)
55 gen_entry_depth (gen_entry *table)
58 gen_entry_traverse_tree (NULL,
70 print_gen_entry_path (line_ref *line,
74 if (table->parent == NULL)
76 if (table->top->processor != NULL)
77 print (line, "%s", table->top->processor);
83 print_gen_entry_path (line, table->parent, print);
84 print (NULL, ".%d", table->opcode_nr);
89 print_gen_entry_insns (gen_entry *table,
96 message = first_message;
97 for (i = table->insns; i != NULL; i = i->next)
99 insn_entry *insn = i->insn;
100 print_gen_entry_path (insn->line, table, print);
101 print (NULL, ": %s.%s %s\n",
105 if (next_message != NULL)
106 message = next_message;
113 insn_word_cmp (insn_word_entry *l, insn_word_entry *r)
118 if (l == NULL && r == NULL)
119 return 0; /* all previous fields the same */
121 return -1; /* left shorter than right */
123 return +1; /* left longer than right */
125 bit_nr < options.insn_bit_size;
128 if (l->bit[bit_nr]->mask < r->bit[bit_nr]->mask)
130 if (l->bit[bit_nr]->mask > r->bit[bit_nr]->mask)
132 if (l->bit[bit_nr]->value < r->bit[bit_nr]->value)
134 if (l->bit[bit_nr]->value > r->bit[bit_nr]->value)
143 opcode_bit_cmp (opcode_bits *l,
146 if (l == NULL && r == NULL)
147 return 0; /* all previous bits the same */
149 return -1; /* left shorter than right */
151 return +1; /* left longer than right */
152 /* most significant word */
153 if (l->field->word_nr < r->field->word_nr)
154 return +1; /* left has more significant word */
155 if (l->field->word_nr > r->field->word_nr)
156 return -1; /* right has more significant word */
157 /* most significant bit? */
158 if (l->first < r->first)
159 return +1; /* left as more significant bit */
160 if (l->first > r->first)
161 return -1; /* right as more significant bit */
163 if (l->last < r->last)
164 return +1; /* left as less bits */
165 if (l->last > r->last)
166 return -1; /* right as less bits */
168 if (l->value < r->value)
170 if (l->value > r->value)
176 opcode_bits_cmp (opcode_bits *l,
182 if (l == NULL && r == NULL)
183 return 0; /* all previous bits the same */
184 cmp = opcode_bit_cmp (l, r);
193 new_opcode_bits (opcode_bits *old_bits,
197 insn_field_entry *field,
198 opcode_field *opcode)
200 opcode_bits *new_bits = ZALLOC (opcode_bits);
201 new_bits->field = field;
202 new_bits->value = value;
203 new_bits->first = first;
204 new_bits->last = last;
205 new_bits->opcode = opcode;
207 if (old_bits != NULL)
209 opcode_bits *new_list;
210 opcode_bits **last = &new_list;
211 new_list = new_opcode_bits (old_bits->next,
217 while (*last != NULL)
219 int cmp = opcode_bit_cmp (new_bits, *last);
220 if (cmp < 0) /* new < new_list */
226 ERROR ("Duplicated insn bits in list");
228 last = &(*last)->next;
230 new_bits->next = *last;
244 merge_duplicate_insns,
245 report_duplicate_insns,
246 } duplicate_insn_actions;
249 insn_list_insert (insn_list **cur_insn_ptr,
252 opcode_bits *expanded_bits,
253 opcode_field *opcodes,
254 int nr_prefetched_words,
255 duplicate_insn_actions duplicate_action)
257 /* insert it according to the order of the fields & bits */
258 while ((*cur_insn_ptr) != NULL)
260 int word_cmp = insn_word_cmp (insn->words,
261 (*cur_insn_ptr)->insn->words);
264 /* found insertion point - new_insn < cur_insn->next */
267 else if (word_cmp == 0)
269 /* words same, try for bit fields */
270 int bit_cmp = opcode_bits_cmp (expanded_bits,
271 (*cur_insn_ptr)->expanded_bits);
274 /* found insertion point - new_insn < cur_insn->next */
277 else if (bit_cmp == 0)
279 switch (duplicate_action)
281 case report_duplicate_insns:
282 /* two instructions with the same constant field
283 values across all words and bits */
285 "Location of second (duplicated?) instruction");
286 error ((*cur_insn_ptr)->insn->line,
287 "Two instructions with identical constant fields\n");
288 case merge_duplicate_insns:
289 /* Add the opcode path to the instructions list */
292 insn_opcodes **last = &(*cur_insn_ptr)->opcodes;
293 while (*last != NULL)
295 last = &(*last)->next;
297 (*last) = ZALLOC (insn_opcodes);
298 (*last)->opcode = opcodes;
300 /* Use the larger nr_prefetched_words */
301 if ((*cur_insn_ptr)->nr_prefetched_words < nr_prefetched_words)
302 (*cur_insn_ptr)->nr_prefetched_words = nr_prefetched_words;
303 return (*cur_insn_ptr);
307 /* keep looking - new_insn > cur_insn->next */
308 cur_insn_ptr = &(*cur_insn_ptr)->next;
311 /* create a new list entry and insert it */
313 insn_list *new_insn = ZALLOC (insn_list);
314 new_insn->insn = insn;
315 new_insn->expanded_bits = expanded_bits;
316 new_insn->next = (*cur_insn_ptr);
317 new_insn->nr_prefetched_words = nr_prefetched_words;
320 new_insn->opcodes = ZALLOC (insn_opcodes);
321 new_insn->opcodes->opcode = opcodes;
323 (*cur_insn_ptr) = new_insn;
328 return (*cur_insn_ptr);
333 gen_entry_traverse_tree (lf *file,
336 gen_entry_handler *start,
337 gen_entry_handler *leaf,
338 gen_entry_handler *end,
343 ASSERT (table != NULL);
344 ASSERT (table->opcode != NULL);
345 ASSERT (table->nr_entries > 0);
346 ASSERT (table->entries != 0);
349 if (start != NULL && depth >= 0)
351 start (file, table, depth, data);
354 for (entry = table->entries;
356 entry = entry->sibling)
358 if (entry->entries != NULL && depth != 0)
360 gen_entry_traverse_tree (file, entry, depth + 1,
361 start, leaf, end, data);
367 leaf (file, entry, depth, data);
372 if (end != NULL && depth >= 0)
374 end (file, table, depth, data);
380 /* create a list element containing a single gen_table entry */
383 make_table (insn_table *isa,
388 gen_list *entry = ZALLOC (gen_list);
389 entry->table = ZALLOC (gen_entry);
390 entry->table->top = entry;
391 entry->processor = processor;
393 for (insn = isa->insns; insn != NULL; insn = insn->next)
395 if (processor == NULL
396 || insn->processors == NULL
397 || filter_is_member (insn->processors, processor))
399 insn_list_insert (&entry->table->insns,
400 &entry->table->nr_insns,
402 NULL, /* expanded_bits - none yet */
403 NULL, /* opcodes - none yet */
404 0, /* nr_prefetched_words - none yet */
405 report_duplicate_insns);
408 entry->table->opcode_rule = rules;
414 make_gen_tables (insn_table *isa,
417 gen_table *gen = ZALLOC (gen_table);
420 if (options.gen.multi_sim)
422 gen_list **last = &gen->tables;
425 if (options.model_filter != NULL)
426 processors = options.model_filter;
428 processors = isa->model->processors;
429 for (processor = filter_next (processors, "");
431 processor = filter_next (processors, processor))
433 *last = make_table (isa, rules, processor);
434 last = &(*last)->next;
439 gen->tables = make_table (isa, rules, NULL);
445 /****************************************************************/
449 field_is_not_constant = 0,
450 field_constant_int = 1,
451 field_constant_reserved = 2,
452 field_constant_string = 3
453 } constant_field_types;
455 static constant_field_types
456 insn_field_is_constant (insn_field *field,
462 /* field is an integer */
463 return field_constant_int;
464 case insn_field_reserved:
465 /* field is `/' and treating that as a constant */
466 if (rule->with_zero_reserved)
467 return field_constant_reserved;
469 return field_is_not_constant;
470 case insn_field_wild:
471 return field_is_not_constant; /* never constant */
472 case insn_field_string:
473 /* field, though variable, is on the list of forced constants */
474 if (filter_is_member (rule->constant_field_names, field->val_string))
475 return field_constant_string;
477 return field_is_not_constant;
479 ERROR ("Internal error");
480 return field_is_not_constant;
485 /****************************************************************/
488 /* Is the bit, according to the decode rule, identical across all the
491 insns_bit_useless (insn_list *insns,
497 int is_useless = 1; /* cleared if something actually found */
498 for (entry = insns; entry != NULL; entry = entry->next)
500 insn_word_entry *word = entry->insn->word[rule->word_nr];
501 insn_bit_entry *bit = word->bit[bit_nr];
502 switch (bit->field->type)
504 case insn_field_wild:
505 case insn_field_reserved:
506 /* neither useless or useful - ignore */
509 switch (rule->search)
511 case decode_find_strings:
512 /* an integer isn't a string */
514 case decode_find_constants:
515 case decode_find_mixed:
516 /* an integer is useful if its value isn't the same
517 between all instructions? */
520 else if (value != bit->value)
525 case insn_field_string:
526 switch (rule->search)
528 case decode_find_strings:
529 /* at least one string, keep checking */
532 case decode_find_constants:
533 case decode_find_mixed:
534 /* a string field forced to constant */
535 if (filter_is_member (rule->constant_field_names,
536 bit->field->val_string))
538 else if (rule->search == decode_find_constants)
539 /* the string field isn't constant */
549 /* go through a gen-table's list of instruction formats looking for a
550 range of bits that meet the decode table RULEs requirements */
552 static opcode_field *
553 gen_entry_find_opcode_field (insn_list *insns,
557 opcode_field curr_opcode;
558 ASSERT (rule != NULL);
560 memset (&curr_opcode, 0, sizeof (curr_opcode));
561 curr_opcode.word_nr = rule->word_nr;
562 curr_opcode.first = rule->first;
563 curr_opcode.last = rule->last;
565 /* Try to reduce the size of first..last in accordance with the
568 while (curr_opcode.first <= rule->last)
570 if (insns_bit_useless (insns, rule, curr_opcode.first))
571 curr_opcode.first ++;
575 while (curr_opcode.last >= rule->first)
577 if (insns_bit_useless (insns, rule, curr_opcode.last))
585 for (entry = insns; entry != NULL; entry = entry->next)
587 insn_word_entry *fields = entry->insn->word[rule->word_nr];
588 opcode_field new_opcode;
590 ASSERT (fields != NULL);
592 /* find a start point for the opcode field */
593 new_opcode.first = rule->first;
594 while (new_opcode.first <= rule->last
596 || (insn_field_is_constant(fields->bit[new_opcode.first], rule)
597 != field_constant_string))
599 || (insn_field_is_constant(fields->bit[new_opcode.first], rule)
600 == field_is_not_constant)))
602 int new_first = fields->bit[new_opcode.first]->last + 1;
603 ASSERT (new_first > new_opcode.first);
604 new_opcode.first = new_first;
606 ASSERT(new_opcode.first > rule->last
608 && insn_field_is_constant(fields->bit[new_opcode.first],
609 rule) == field_constant_string)
611 && insn_field_is_constant(fields->bit[new_opcode.first],
614 /* find the end point for the opcode field */
615 new_opcode.last = rule->last;
616 while (new_opcode.last >= rule->first
618 || insn_field_is_constant(fields->bit[new_opcode.last],
619 rule) != field_constant_string)
621 || !insn_field_is_constant(fields->bit[new_opcode.last],
624 int new_last = fields->bit[new_opcode.last]->first - 1;
625 ASSERT (new_last < new_opcode.last);
626 new_opcode.last = new_last;
628 ASSERT(new_opcode.last < rule->first
630 && insn_field_is_constant(fields->bit[new_opcode.last],
631 rule) == field_constant_string)
633 && insn_field_is_constant(fields->bit[new_opcode.last],
636 /* now see if our current opcode needs expanding to include the
637 interesting fields within this instruction */
638 if (new_opcode.first <= rule->last
639 && curr_opcode.first > new_opcode.first)
640 curr_opcode.first = new_opcode.first;
641 if (new_opcode.last >= rule->first
642 && curr_opcode.last < new_opcode.last)
643 curr_opcode.last = new_opcode.last;
648 /* did the final opcode field end up being empty? */
649 if (curr_opcode.first > curr_opcode.last)
653 ASSERT (curr_opcode.last >= rule->first);
654 ASSERT (curr_opcode.first <= rule->last);
655 ASSERT (curr_opcode.first <= curr_opcode.last);
657 /* Ensure that, for the non string only case, the opcode includes
658 the range forced_first .. forced_last */
660 && curr_opcode.first > rule->force_first)
662 curr_opcode.first = rule->force_first;
665 && curr_opcode.last < rule->force_last)
667 curr_opcode.last = rule->force_last;
670 /* For the string only case, force just the lower bound (so that the
671 shift can be eliminated) */
673 && rule->force_last == options.insn_bit_size - 1)
675 curr_opcode.last = options.insn_bit_size - 1;
678 /* handle any special cases */
681 case normal_decode_rule:
682 /* let the above apply */
683 curr_opcode.nr_opcodes =
684 (1 << (curr_opcode.last - curr_opcode.first + 1));
687 curr_opcode.is_boolean = 1;
688 curr_opcode.boolean_constant = rule->constant;
689 curr_opcode.nr_opcodes = 2;
694 opcode_field *new_field = ZALLOC (opcode_field);
695 memcpy (new_field, &curr_opcode, sizeof (opcode_field));
702 gen_entry_insert_insn (gen_entry *table,
703 insn_entry *old_insn,
705 int new_nr_prefetched_words,
707 opcode_bits *new_bits)
709 gen_entry **entry = &table->entries;
711 /* find the new table for this entry */
712 while ((*entry) != NULL && (*entry)->opcode_nr < new_opcode_nr)
714 entry = &(*entry)->sibling;
717 if ((*entry) == NULL || (*entry)->opcode_nr != new_opcode_nr)
719 /* insert the missing entry */
720 gen_entry *new_entry = ZALLOC (gen_entry);
721 new_entry->sibling = (*entry);
722 (*entry) = new_entry;
725 new_entry->top = table->top;
726 new_entry->opcode_nr = new_opcode_nr;
727 new_entry->word_nr = new_word_nr;
728 new_entry->expanded_bits = new_bits;
729 new_entry->opcode_rule = table->opcode_rule->next;
730 new_entry->parent = table;
731 new_entry->nr_prefetched_words = new_nr_prefetched_words;
733 /* ASSERT new_bits == cur_entry bits */
734 ASSERT ((*entry) != NULL && (*entry)->opcode_nr == new_opcode_nr);
735 insn_list_insert (&(*entry)->insns,
738 NULL, /* expanded_bits - only in final list */
739 NULL, /* opcodes - only in final list */
740 new_nr_prefetched_words, /* for this table */
741 report_duplicate_insns);
746 gen_entry_expand_opcode (gen_entry *table,
747 insn_entry *instruction,
752 if (bit_nr > table->opcode->last)
754 /* Only include the hardwired bit information with an entry IF
755 that entry (and hence its functions) are being duplicated. */
756 if (table->opcode_rule->with_duplicates)
758 gen_entry_insert_insn (table, instruction,
759 table->opcode->word_nr,
760 table->nr_prefetched_words,
765 gen_entry_insert_insn (table, instruction,
766 table->opcode->word_nr,
767 table->nr_prefetched_words,
773 insn_word_entry *word = instruction->word[table->opcode->word_nr];
774 insn_field_entry *field = word->bit[bit_nr]->field;
775 int last_pos = ((field->last < table->opcode->last)
776 ? field->last : table->opcode->last);
777 int first_pos = ((field->first > table->opcode->first)
778 ? field->first : table->opcode->first);
779 int width = last_pos - first_pos + 1;
785 val = sub_val (field->val_int, field, first_pos, last_pos);
786 gen_entry_expand_opcode (table, instruction,
788 ((opcode_nr << width) | val),
794 if (field->type == insn_field_reserved)
795 gen_entry_expand_opcode (table, instruction,
797 ((opcode_nr << width)),
802 int last_val = (table->opcode->is_boolean
804 for (val = 0; val < last_val; val++)
806 /* check to see if the value has been limited */
807 insn_field_exclusion *exclusion;
808 for (exclusion = field->exclusions;
810 exclusion = exclusion->next)
812 int value = sub_val (exclusion->value, field,
813 first_pos, last_pos);
817 if (exclusion == NULL)
819 /* Only add additional hardwired bit
820 information if the entry is not going to
822 if (table->opcode_rule->with_combine)
824 gen_entry_expand_opcode (table, instruction,
826 ((opcode_nr << width) | val),
831 opcode_bits *new_bits = new_opcode_bits (bits, val,
835 gen_entry_expand_opcode (table, instruction,
837 ((opcode_nr << width) | val),
849 gen_entry_insert_expanding (gen_entry *table,
850 insn_entry *instruction)
852 gen_entry_expand_opcode (table,
854 table->opcode->first,
856 table->expanded_bits);
861 insns_match_format_names (insn_list *insns,
862 filter *format_names)
864 if (format_names != NULL)
867 for (i = insns; i != NULL; i = i->next)
869 if ( i->insn->format_name != NULL
870 && !filter_is_member (format_names, i->insn->format_name))
878 table_matches_path (gen_entry *table,
879 decode_path_list *paths)
883 while (paths != NULL)
885 gen_entry *entry = table;
886 decode_path *path = paths->path;
889 if (entry == NULL && path == NULL)
891 if (entry == NULL || path == NULL)
893 if (entry->opcode_nr != path->opcode_nr)
895 entry = entry->parent;
905 insns_match_conditions (insn_list *insns,
906 decode_cond *conditions)
908 if (conditions != NULL)
911 for (i = insns; i != NULL; i = i->next)
914 for (cond = conditions; cond != NULL; cond = cond->next)
917 if (i->insn->nr_words <= cond->word_nr)
919 for (bit_nr = 0; bit_nr < options.insn_bit_size; bit_nr++)
921 if (!cond->mask[bit_nr])
923 if (!i->insn->word[cond->word_nr]->bit[bit_nr]->mask)
925 if ((i->insn->word[cond->word_nr]->bit[bit_nr]->value
926 == cond->value[bit_nr])
937 insns_match_nr_words (insn_list *insns,
941 for (i = insns; i != NULL; i = i->next)
943 if (i->insn->nr_words < nr_words)
950 insn_list_cmp (insn_list *l,
956 if (l == NULL && r == NULL)
962 if (l->insn != r->insn)
963 return -1; /* somewhat arbitrary at present */
966 while (l != NULL && l->insn == insn)
968 while (r != NULL && r->insn == insn)
976 gen_entry_expand_insns (gen_entry *table)
978 decode_table *opcode_rule;
980 ASSERT(table->nr_insns >= 1);
982 /* determine a valid opcode */
983 for (opcode_rule = table->opcode_rule;
985 opcode_rule = opcode_rule->next)
987 char *discard_reason;
988 if (table->top->processor != NULL
989 && opcode_rule->model_names != NULL
990 && !filter_is_member (opcode_rule->model_names,
991 table->top->processor))
993 /* the rule isn't applicable to this processor */
994 discard_reason = "wrong model";
996 else if (table->nr_insns == 1 && opcode_rule->conditions == NULL)
998 /* for safety, require a pre-codition when attempting to
999 apply a rule to a single instruction */
1000 discard_reason = "need pre-condition when nr-insn == 1";
1002 else if (table->nr_insns == 1 && !opcode_rule->with_duplicates)
1004 /* Little point in expanding a single instruction when we're
1005 not duplicating the semantic functions that this table
1007 discard_reason = "need duplication with nr-insns == 1";
1009 else if (!insns_match_format_names (table->insns, opcode_rule->format_names))
1011 discard_reason = "wrong format name";
1013 else if (!insns_match_nr_words (table->insns, opcode_rule->word_nr + 1))
1015 discard_reason = "wrong nr words";
1017 else if (!table_matches_path (table, opcode_rule->paths))
1019 discard_reason = "path failed";
1021 else if (!insns_match_conditions (table->insns, opcode_rule->conditions))
1023 discard_reason = "condition failed";
1027 discard_reason = "no opcode field";
1029 gen_entry_find_opcode_field (table->insns,
1031 table->nr_insns == 1/*string-only*/
1033 if (table->opcode != NULL)
1035 table->opcode_rule = opcode_rule;
1040 if (options.trace.rule_rejection)
1042 print_gen_entry_path (opcode_rule->line, table, notify);
1043 notify (NULL, ": rule discarded - %s\n", discard_reason);
1047 /* did we find anything */
1048 if (opcode_rule == NULL)
1050 /* the decode table failed, this set of instructions haven't
1051 been uniquely identified */
1052 if (table->nr_insns > 1)
1054 print_gen_entry_insns (table, warning,
1055 "was not uniquely decoded",
1056 "decodes to the same entry");
1062 /* Determine the number of words that must have been prefetched for
1063 this table to function */
1064 if (table->parent == NULL)
1065 table->nr_prefetched_words = table->opcode_rule->word_nr + 1;
1066 else if (table->opcode_rule->word_nr + 1 > table->parent->nr_prefetched_words)
1067 table->nr_prefetched_words = table->opcode_rule->word_nr + 1;
1069 table->nr_prefetched_words = table->parent->nr_prefetched_words;
1071 /* back link what we found to its parent */
1072 if (table->parent != NULL)
1074 ASSERT(table->parent->opcode != NULL);
1075 table->opcode->parent = table->parent->opcode;
1078 /* expand the raw instructions according to the opcode */
1081 for (entry = table->insns; entry != NULL; entry = entry->next)
1083 gen_entry_insert_expanding (table, entry->insn);
1087 if (options.trace.rule_selection)
1089 print_gen_entry_path (table->opcode_rule->line, table, notify);
1091 ": decode - word %d, bits [%d..%d] in [%d..%d], opcodes %d, entries %d\n",
1092 table->opcode->word_nr,
1093 i2target (options.hi_bit_nr, table->opcode->first),
1094 i2target (options.hi_bit_nr, table->opcode->last),
1095 i2target (options.hi_bit_nr, table->opcode_rule->first),
1096 i2target (options.hi_bit_nr, table->opcode_rule->last),
1097 table->opcode->nr_opcodes,
1101 /* dump the results */
1102 if (options.trace.entries)
1105 for (entry = table->entries; entry != NULL; entry = entry->sibling)
1108 print_gen_entry_path (table->opcode_rule->line, entry, notify);
1109 notify (NULL, ": %d - entries %d -",
1112 for (l = entry->insns; l != NULL; l = l->next)
1113 notify (NULL, " %s.%s", l->insn->format_name, l->insn->name);
1114 notify (NULL, "\n");
1118 /* perform a combine pass if needed */
1119 if (table->opcode_rule->with_combine)
1122 for (entry = table->entries; entry != NULL; entry = entry->sibling)
1124 if (entry->combined_parent == NULL)
1126 gen_entry **last = &entry->combined_next;
1128 for (alt = entry->sibling; alt != NULL; alt = alt->sibling)
1130 if (alt->combined_parent == NULL
1131 && insn_list_cmp (entry->insns, alt->insns) == 0)
1133 alt->combined_parent = entry;
1135 last = &alt->combined_next;
1140 if (options.trace.combine)
1144 for (entry = table->entries; entry != NULL; entry = entry->sibling)
1146 if (entry->combined_parent == NULL)
1149 gen_entry *duplicate;
1151 print_gen_entry_path (table->opcode_rule->line, entry, notify);
1152 for (duplicate = entry->combined_next;
1154 duplicate = duplicate->combined_next)
1156 notify (NULL, "+%d", duplicate->opcode_nr);
1158 notify (NULL, ": entries %d -", entry->nr_insns);
1159 for (l = entry->insns; l != NULL; l = l->next)
1161 notify (NULL, " %s.%s",
1162 l->insn->format_name,
1165 notify (NULL, "\n");
1168 print_gen_entry_path (table->opcode_rule->line, table, notify);
1169 notify (NULL, ": combine - word %d, bits [%d..%d] in [%d..%d], opcodes %d, entries %d, unique %d\n",
1170 table->opcode->word_nr,
1171 i2target (options.hi_bit_nr, table->opcode->first),
1172 i2target (options.hi_bit_nr, table->opcode->last),
1173 i2target (options.hi_bit_nr, table->opcode_rule->first),
1174 i2target (options.hi_bit_nr, table->opcode_rule->last),
1175 table->opcode->nr_opcodes,
1181 /* Check that the rule did more than re-arange the order of the
1185 for (entry = table->entries; entry != NULL; entry = entry->sibling)
1187 if (entry->combined_parent == NULL)
1189 if (insn_list_cmp (table->insns, entry->insns) == 0)
1191 print_gen_entry_path (table->opcode_rule->line, table, warning);
1192 warning (NULL, ": Applying rule just copied all instructions\n");
1193 print_gen_entry_insns (entry, warning, "Copied", NULL);
1200 /* if some form of expanded table, fill in the missing dots */
1201 switch (table->opcode_rule->gen)
1203 case padded_switch_gen:
1205 case goto_switch_gen:
1206 if (!table->opcode->is_boolean)
1208 gen_entry **entry = &table->entries;
1209 gen_entry *illegals = NULL;
1210 gen_entry **last_illegal = &illegals;
1212 while (opcode_nr < table->opcode->nr_opcodes)
1214 if ((*entry) == NULL || (*entry)->opcode_nr != opcode_nr)
1216 /* missing - insert it under our feet at *entry */
1217 gen_entry_insert_insn (table,
1218 table->top->isa->illegal_insn,
1219 table->opcode->word_nr,
1220 0, /* nr_prefetched_words == 0 for invalid */
1222 ASSERT ((*entry) != NULL);
1223 ASSERT ((*entry)->opcode_nr == opcode_nr);
1224 (*last_illegal) = *entry;
1225 (*last_illegal)->combined_parent = illegals;
1226 last_illegal = &(*last_illegal)->combined_next;
1228 entry = &(*entry)->sibling;
1231 /* oops, will have pointed the first illegal insn back to
1232 its self. Fix this */
1233 if (illegals != NULL)
1234 illegals->combined_parent = NULL;
1243 /* and do the same for the newly created sub entries but *only*
1244 expand entries that haven't been combined. */
1247 for (entry = table->entries; entry != NULL; entry = entry->sibling)
1249 if (entry->combined_parent == NULL)
1251 gen_entry_expand_insns (entry);
1258 gen_tables_expand_insns (gen_table *gen)
1261 for (entry = gen->tables; entry != NULL; entry = entry->next)
1263 gen_entry_expand_insns (entry->table);
1268 /* create a list of all the semantic functions that need to be
1269 generated. Eliminate any duplicates. Verify that the decode stage
1273 make_gen_semantics_list (lf *file,
1278 gen_table *gen = (gen_table*) data;
1280 /* Not interested in an entrie that have been combined into some
1281 other entry at the same level */
1282 if (entry->combined_parent != NULL)
1285 /* a leaf should contain exactly one instruction. If not the decode
1287 ASSERT (entry->nr_insns == 1);
1289 /* Enter this instruction into the list of semantic functions. */
1290 insn = insn_list_insert (&gen->semantics, &gen->nr_semantics,
1292 entry->expanded_bits,
1293 entry->parent->opcode,
1294 entry->insns->nr_prefetched_words,
1295 merge_duplicate_insns);
1296 /* point the table entry at the real semantic function */
1297 ASSERT (insn != NULL);
1298 entry->insns->semantic = insn;
1303 gen_tables_expand_semantics (gen_table *gen)
1306 for (entry = gen->tables; entry != NULL; entry = entry->next)
1308 gen_entry_traverse_tree (NULL,
1311 NULL, /* start-handler */
1312 make_gen_semantics_list, /* leaf-handler */
1313 NULL, /* end-handler */
1324 dump_opcode_field (lf *file,
1326 opcode_field *field,
1330 lf_printf (file, "%s(opcode_field *) 0x%lx", prefix, (long) field);
1331 if (levels && field != NULL) {
1332 lf_indent (file, +1);
1333 lf_printf (file, "\n(first %d)", field->first);
1334 lf_printf (file, "\n(last %d)", field->last);
1335 lf_printf (file, "\n(nr_opcodes %d)", field->nr_opcodes);
1336 lf_printf (file, "\n(is_boolean %d)", field->is_boolean);
1337 lf_printf (file, "\n(boolean_constant %d)", field->boolean_constant);
1338 dump_opcode_field(file, "\n(parent ", field->parent, ")", levels - 1);
1339 lf_indent (file, -1);
1341 lf_printf (file, "%s", suffix);
1346 dump_opcode_bits (lf *file,
1352 lf_printf (file, "%s(opcode_bits *) 0x%lx", prefix, (long) bits);
1354 if (levels && bits != NULL)
1356 lf_indent (file, +1);
1357 lf_printf (file, "\n(value %d)", bits->value);
1358 dump_opcode_field (file, "\n(opcode ", bits->opcode, ")", 0);
1359 dump_insn_field (file, "\n(field ", bits->field, ")");
1360 dump_opcode_bits (file, "\n(next ", bits->next, ")", levels - 1);
1361 lf_indent (file, -1);
1363 lf_printf (file, "%s", suffix);
1369 dump_insn_list (lf *file,
1374 lf_printf (file, "%s(insn_list *) 0x%lx", prefix, (long) entry);
1376 if (entry != NULL) {
1377 lf_indent (file, +1);
1378 dump_insn_entry (file, "\n(insn ", entry->insn, ")");
1379 lf_printf (file, "\n(next 0x%lx)", (long) entry->next);
1380 lf_indent (file, -1);
1382 lf_printf (file, "%s", suffix);
1387 dump_insn_word_entry_list_entries (lf *file,
1392 lf_printf (file, "%s", prefix);
1393 while (entry != NULL)
1395 dump_insn_list (file, "\n(", entry, ")");
1396 entry = entry->next;
1398 lf_printf (file, "%s", suffix);
1403 dump_gen_entry (lf *file,
1410 lf_printf (file, "%s(gen_entry *) 0x%lx", prefix, (long) table);
1412 if (levels && table != NULL) {
1414 lf_indent (file, +1);
1415 lf_printf (file, "\n(opcode_nr %d)", table->opcode_nr);
1416 lf_printf (file, "\n(word_nr %d)", table->word_nr);
1417 dump_opcode_bits (file, "\n(expanded_bits ", table->expanded_bits, ")", -1);
1418 lf_printf (file, "\n(nr_insns %d)", table->nr_insns);
1419 dump_insn_word_entry_list_entries (file, "\n(insns ", table->insns, ")");
1420 dump_decode_rule (file, "\n(opcode_rule ", table->opcode_rule, ")");
1421 dump_opcode_field (file, "\n(opcode ", table->opcode, ")", 0);
1422 lf_printf (file, "\n(nr_entries %d)", table->nr_entries);
1423 dump_gen_entry (file, "\n(entries ", table->entries, ")", table->nr_entries);
1424 dump_gen_entry (file, "\n(sibling ", table->sibling, ")", levels - 1);
1425 dump_gen_entry (file, "\n(parent ", table->parent, ")", 0);
1426 lf_indent (file, -1);
1428 lf_printf (file, "%s", suffix);
1432 dump_gen_list (lf *file,
1438 while (entry != NULL)
1440 lf_printf (file, "%s(gen_list *) 0x%lx", prefix, (long) entry);
1441 dump_gen_entry (file, "\n(", entry->table, ")", levels);
1442 lf_printf (file, "\n(next (gen_list *) 0x%lx)", (long) entry->next);
1443 lf_printf (file, "%s", suffix);
1449 dump_gen_table (lf *file,
1455 lf_printf (file, "%s(gen_table *) 0x%lx", prefix, (long) gen);
1456 lf_printf (file, "\n(isa (insn_table *) 0x%lx)", (long) gen->isa);
1457 lf_printf (file, "\n(rules (decode_table *) 0x%lx)", (long) gen->rules);
1458 dump_gen_list (file, "\n(", gen->tables, ")", levels);
1459 lf_printf (file, "%s", suffix);
1463 igen_options options;
1469 decode_table *decode_rules;
1470 insn_table *instructions;
1475 error (NULL, "Usage: insn <filter-in> <hi-bit-nr> <insn-bit-size> <widths> <decode-table> <insn-table>\n");
1477 INIT_OPTIONS (options);
1479 filter_parse (&options.flags_filter, argv[1]);
1481 options.hi_bit_nr = a2i(argv[2]);
1482 options.insn_bit_size = a2i(argv[3]);
1483 options.insn_specifying_widths = a2i(argv[4]);
1484 ASSERT(options.hi_bit_nr < options.insn_bit_size);
1486 instructions = load_insn_table (argv[6], NULL);
1487 decode_rules = load_decode_table (argv[5]);
1488 gen = make_gen_tables (instructions, decode_rules);
1490 gen_tables_expand_insns (gen);
1492 l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-ld-insn");
1494 dump_gen_table (l, "(", gen, ")\n", -1);