for discussion: Proposed change to label handling

Tyson Dowd trd at cs.mu.oz.au
Mon Dec 15 18:56:17 AEDT 1997


Hi,

I'm considering making some changes to the default compilation model.

At the moment, internal labels only have local scope, and so are not
accessible for stack traces, tracing, accurate gc, etc. So if you want
to use any one of those features, you need to have a different grade.
And to keep code duplication and complexity down, you'll need a shared
grade that does things like make labels available, as well as an
individual grade for each feature. This makes for a complex design when
handling options and defining grades.

Rather than have the default grade be the "odd one out", it would be
much easier to develop and support these features if they were only a
slight variation on the standard compilation model.  So I did some
measurements to see how feasible this would be.

I switched the internal labels to global (by simply defining internal 
labels as entry labels), turned off the more complex call mechanism 
(which does an ASM_FIXUP_REGS on return from the call, but before
proceeding to the continuation) and did some measurements in
asm_fast.gc on murlibobo:

current setup:
   -rwx------   1 trd      mercury  4800512 Dec 15 15:14 mercury_compile*
   text    data    bss     dec     hex
   4046848 753664  81904   4882416 4a7ff0

   compiling make_hlds.m:
   42.327u 2.236s 0:48.93 91.0%    6+285k 534+172io 0pf+0w
   41.714u 2.083s 0:45.02 97.2%    6+286k 30+168io 0pf+0w
   41.756u 2.134s 0:44.62 98.3%    6+285k 31+168io 0pf+0w


alternate setup:
   -rwx------   1 trd      mercury  7979008 Dec 15 13:46 mercury_compile*
   text    data    bss     dec     hex
   7249920 729088  81248   8060256 7afd60

   compiling make_hlds.m:
   42.513u 2.257s 0:49.27 90.8%    6+286k 637+172io 0pf+0w
   42.465u 2.148s 0:44.99 99.1%    6+286k 31+164io 0pf+0w
   42.264u 2.075s 0:44.49 99.6%    6+287k 0+165io 0pf+0w

So this costs quite a bit of space (all in code size), and has a small
slowdown.

One way of improving that space problem is to use local labels instead.
This requires a bit more work -- you need to initialize variables
for the "entry" point of each local label much the same way that non-asm
labels work (static Code * label = &&entry(label)). All other uses
of the labels stay exactly the same.

You need only pay the cost of doing all the initialization if you
need the label addresses (e.g. you can do it lazily whenever a stack
trace is required, or on your first gc). Any static references to the
label address instead reference the variable, and you need to make sure
the variables get initialized before you use the static references.

improved alternate setup:
   -rwx------   1 trd      mercury  5644288 Dec 15 17:36 mercury_compile*
   text    data    bss     dec     hex
   4497408 1146880 369664  6013952 5bc400

   compiling make_hlds.m:
   41.084u 1.033s 0:46.38 90.7%    9+308k 649+167io 0pf+0w
   40.921u 0.702s 0:41.76 99.6%    9+310k 0+164io 0pf+0w
   40.564u 0.586s 0:41.27 99.6%    9+310k 0+160io 0pf+0w

So this is a moderate size increase (and in better places - only
40k more code, 400k more data). And a speedup. My guess is that
the simpler call-return sequence is less expensive (fewer pipeline
bubbles?). 

I propose this change as the new "default". Here's the diff I used
for the measurements (but not what I'm proposing actually committing).
Any comments or concerns would be appreciated.

Index: mercury_calls.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_calls.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_calls.h
--- mercury_calls.h	1997/12/03 07:26:11	1.3
+++ mercury_calls.h	1997/12/15 01:34:20
@@ -34,7 +34,7 @@
 ** label.
 */
 #if defined(USE_GCC_NONLOCAL_GOTOS) && defined(NEED_ASM_FIXUP_REGS) &&	\
-	!defined(NATIVE_GC)
+	!defined(NATIVE_GC) && !defined(ALTERNATE_LABEL)
   #define	noprof_call(proc, succ_cont)			\
 		({						\
 			__label__ fixup_gp;			\
Index: mercury_goto.h
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/mercury_goto.h,v
retrieving revision 1.3
diff -u -r1.3 mercury_goto.h
--- mercury_goto.h	1997/12/03 07:26:14	1.3
+++ mercury_goto.h	1997/12/15 06:21:44
@@ -513,14 +513,17 @@
 	label:	\
 	{
   #define init_local(label)	make_local(stringify(label), &&label, label)
-  #ifdef NATIVE_GC
-   #define Declare_label(label)	Define_extern_entry(label)
-   #define Define_label(label)	Define_entry(label)
+  #if defined(NATIVE_GC) || defined(ALTERNATE_LABEL)
+   #define Declare_label(label)		static Code * (label)
+   #define Define_label(label)		Define_local(label)
+   #define init_label(label)   		\
+   	(label) = &&entry(label);       \
+   	make_label(stringify(label), &&entry(label), label)
   #else
    #define Declare_label(label)	/* no declaration required */
    #define Define_label(label)	Define_local(label)
+   #define init_label(label)	make_label(stringify(label), &&label, label)
   #endif
-  #define init_label(label)	make_label(stringify(label), &&label, label)
 
   #define LOCAL(label)		(&&entry(label))
   #define LABEL(label)		(&&entry(label))

-- 
       Tyson Dowd           # 
                            #         Linux versus Windows is a 
     trd at cs.mu.oz.au        #            Win lose situation.
http://www.cs.mu.oz.au/~trd #



More information about the developers mailing list