public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Patch to eliminate FOO_INSN_MAX from sim
@ 2001-04-01 20:15 Ben Elliston
  2001-04-01 22:27 ` [RFA] Patch to eliminate FOO_INSN_MAX from sid Ben Elliston
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Elliston @ 2001-04-01 20:15 UTC (permalink / raw)
  To: cgen

Currently, cgen breaks when handling instruction sets with a "max"
instruction mnemonic.  I've already fixed it properly in opcodes.
This patch extends the fix into the sim application.

The code to produce the C symbol in sim-{decode,model}.scm is quite
long-winded.  Is there a better way?

Tested on two ports with expected results.  Okay to commit?


2001-04-02  Ben Elliston  <bje@redhat.com>

	* sim-decode.scm (@prefix@_init_idesc_table): Compute tabsize
	using the size of the table and its elements.
	(-gen-decode-insn-globals): Define the idesc table's size to be
	the last instruction enum plus one, not @PREFIX@_INSN_MAX.
	* sim-model.scm (-gen-mach-defns): Define CPU_MAX_INSNS as the
	last instruction enum plus one, not @CPU@_INSN_MAX.

Index: sim-decode.scm
===================================================================
RCS file: /cvs/src/src/cgen/sim-decode.scm,v
retrieving revision 1.5
diff -u -w -r1.5 sim-decode.scm
--- sim-decode.scm	2001/03/05 15:43:38	1.5
+++ sim-decode.scm	2001/04/02 03:03:56
@@ -32,7 +32,9 @@
    teensy bit of cpu in the decoder.  Moving it to malloc space is trivial
    but won't be done until necessary (we don't currently support the runtime
    addition of instructions nor an SMP machine with different cpus).  */
-static IDESC " IDESC-TABLE-VAR "[@PREFIX@_INSN_MAX];
+static IDESC " IDESC-TABLE-VAR "[@PREFIX@_INSN_"
+   (string-upcase (gen-c-symbol (caar (list-take -1
+       (gen-obj-list-enums (non-multi-insns (current-insn-list))))))) " + 1];
 
 /* Commas between elements are contained in the macros.
    Some of these are conditionally compiled out.  */
@@ -145,7 +147,7 @@
 {
   IDESC *id,*tabend;
   const struct insn_sem *t,*tend;
-  int tabsize = @PREFIX@_INSN_MAX;
+  int tabsize = sizeof (" IDESC-TABLE-VAR ") / sizeof (IDESC);
   IDESC *table = " IDESC-TABLE-VAR ";
 
   memset (table, 0, tabsize * sizeof (IDESC));
Index: sim-model.scm
===================================================================
RCS file: /cvs/src/src/cgen/sim-model.scm,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 sim-model.scm
--- sim-model.scm	2000/07/28 04:11:52	1.1.1.1
+++ sim-model.scm	2001/04/02 03:03:57
@@ -313,6 +313,8 @@
 ; Return C code to define the machine data.
 
 (define (-gen-mach-defns)
+  (let* ((insns (gen-obj-list-enums (non-multi-insns (current-insn-list))))
+	 (last-insn (string-upcase (gen-c-symbol (caar (list-take -1 insns))))))
   (string-list-map
    (lambda (mach)
      (gen-obj-sanitize
@@ -326,7 +328,7 @@
   CPU_PC_FETCH (cpu) = " (gen-sym (mach-cpu mach)) "_h_pc_get;
   CPU_PC_STORE (cpu) = " (gen-sym (mach-cpu mach)) "_h_pc_set;
   CPU_GET_IDATA (cpu) = @cpu@_get_idata;
-  CPU_MAX_INSNS (cpu) = @CPU@_INSN_MAX;
+  CPU_MAX_INSNS (cpu) = @CPU@_INSN_" last-insn " + 1;
   CPU_INSN_NAME (cpu) = cgen_insn_name;
   CPU_FULL_ENGINE_FN (cpu) = @cpu@_engine_run_full;
 #if WITH_FAST
@@ -352,7 +354,7 @@
 
 ")))
 
-   (current-mach-list))
+   (current-mach-list)))
 )
 \f
 ; Top level file generators.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [RFA] Patch to eliminate FOO_INSN_MAX from sid
  2001-04-01 20:15 [RFA] Patch to eliminate FOO_INSN_MAX from sim Ben Elliston
@ 2001-04-01 22:27 ` Ben Elliston
  0 siblings, 0 replies; 2+ messages in thread
From: Ben Elliston @ 2001-04-01 22:27 UTC (permalink / raw)
  To: cgen

>>>>> "Ben" == Ben Elliston <bje@redhat.com> writes:

  Ben> Currently, cgen breaks when handling instruction sets with a "max"
  Ben> instruction mnemonic.  I've already fixed it properly in opcodes.
  Ben> This patch extends the fix into the sim application.

And, likewise, here is the fix for the sid application.  Tested on a
few ports, including "the hulk" (ARM7T).  Okay to to commit?


2001-04-02  Ben Elliston  <bje@redhat.com>

	* sid-cpu.scm (-last-insn): New function.
	(-gen-sem-switch-engine): Loop through idesc while less than or
	equal to the last instruction enum, not less than the MAX enum.
	(-gen-sfrag-engine-fn): Clean up frag_label_table initialisation.
	* sid-decode.scm (-gen-decode-insn-globals): Define the idesc
	table's size to be the last instruction enum plus one, not
	@PREFIX@_INSN_MAX.
	* sid.scm (gen-cpu-insn-enum-decl): Do not append a dummy `max'
	instruction onto the instruction list.
	
Index: sid-cpu.scm
===================================================================
RCS file: /cvs/src/src/cgen/sid-cpu.scm,v
retrieving revision 1.2
diff -u -r1.2 sid-cpu.scm
--- sid-cpu.scm	2001/01/29 18:56:26	1.2
+++ sid-cpu.scm	2001/04/02 05:25:25
@@ -5,6 +5,10 @@
 ; ***********
 ; cgen-desc.h
 
+(define (-last-insn)
+  (string-upcase (gen-c-symbol (caar (list-take -1
+       (gen-obj-list-enums (non-multi-insns (current-insn-list))))))))
+
 ; Declare the attributes.
 
 (define (-gen-attr-decls)
@@ -807,7 +811,7 @@
 	@prefix@_idesc::idesc_table[labels[i].insn].cgoto.label = labels[i].label; 
 
       // confirm that table is all filled up
-      for (int i=0; i<@PREFIX@_INSN_MAX; i++)
+      for (int i = 0; i <= @PREFIX@_INSN_" (-last-insn) "; i++)
         assert (@prefix@_idesc::idesc_table[i].cgoto.label != 0);
 
       // Initialize the compiler virtual insn.
@@ -1049,12 +1053,7 @@
 			       ", @PREFIX@_FRAG_LIST_END },\n"))
 	       insn-list frag-usage)
      "")
-
-   "\
-  { @PREFIX@_INSN_MAX }
-};
-\n"
-   )
+   "};\n\n")
 )
 
 ; Return sfrag computed-goto engine.
@@ -1112,20 +1111,18 @@
       // Allocate frag label table and point idesc table entries at it.
       // FIXME: Temporary hack, to be redone.
       static void** frag_label_table;
-      frag_label_table = new (void*) [@PREFIX@_INSN_MAX * 4];
-      memset (frag_label_table, 0, sizeof (void*) * @PREFIX@_INSN_MAX * 4);
+      int max_insns = @PREFIX@_INSN_" (-last-insn) " + 1;
+      int tabsize = max_insns * 4;
+      frag_label_table = new (void*) [tabsize];
+      memset (frag_label_table, 0, sizeof (void*) * tabsize);
       int i;
       void** v;
-      for (i = 0, v = frag_label_table; i < @PREFIX@_INSN_MAX; ++i)
+      for (i = 0, v = frag_label_table; i < max_insns; ++i)
 	{
 	  @prefix@_idesc::idesc_table[@prefix@_frag_usage[i].itype].cgoto.frags = v;
 	  for (int j = 0; @prefix@_frag_usage[i].ftype[j] != @PREFIX@_FRAG_LIST_END; ++j)
 	    *v++ = labels[@prefix@_frag_usage[i].ftype[j]].label;
 	}
-
-      // Record frags used by each insn.
-      //for (int i = 0; @prefix@_frag_usage[i].itype != @PREFIX@_INSN_MAX; ++i)
-      //  @prefix@_idesc::idesc_table[@prefix@_frag_usage[i].itype].frags = & @prefix@_frag_usage[i];
 
       // Initialize the compiler virtual insn.
       // FIXME: Also needed if !gnuc.
Index: sid-decode.scm
===================================================================
RCS file: /cvs/src/src/cgen/sid-decode.scm,v
retrieving revision 1.3
diff -u -r1.3 sid-decode.scm
--- sid-decode.scm	2001/03/01 19:15:30	1.3
+++ sid-decode.scm	2001/04/02 05:25:25
@@ -11,7 +11,9 @@
   ; Print the higher detailed stuff at higher verbosity.
   (logit 2 "Processing decode insn globals ...\n")
 
-  (let* ((all-attrs (current-insn-attr-list)))
+  (let* ((all-attrs (current-insn-attr-list))
+	 (last-insn (string-upcase (gen-c-symbol (caar (list-take -1
+                      (gen-obj-list-enums (non-multi-insns (current-insn-list)))))))))
 
     (string-write
      "
@@ -27,7 +29,7 @@
 	 "")
 
      "\
-@prefix@_idesc @prefix@_idesc::idesc_table[@PREFIX@_INSN_MAX] =
+@prefix@_idesc @prefix@_idesc::idesc_table[@PREFIX@_INSN_" last-insn " + 1] =
 {\n"
 
      (string-map
Index: sid.scm
===================================================================
RCS file: /cvs/src/src/cgen/sid.scm,v
retrieving revision 1.3
diff -u -r1.3 sid.scm
--- sid.scm	2001/03/01 19:15:30	1.3
+++ sid.scm	2001/04/02 05:25:27
@@ -1320,8 +1320,7 @@
 						  (cons '-
 							(atlist-attrs (obj-atlist i))))))
 					 (parallel-insns insn-list)))
-			     nil)
-			 '((max))))
+			     nil)))
 )
 
 ; Return the enum of INSN in cpu family CPU.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-04-01 22:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-01 20:15 [RFA] Patch to eliminate FOO_INSN_MAX from sim Ben Elliston
2001-04-01 22:27 ` [RFA] Patch to eliminate FOO_INSN_MAX from sid Ben Elliston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).