From mboxrd@z Thu Jan 1 00:00:00 1970 From: mjn3@codepoet.org (Manuel Novoa III) Subject: Re: Small-C revisited Date: Wed, 5 Jun 2002 12:56:25 -0600 Sender: linux-8086-owner@vger.kernel.org Message-ID: <20020605185625.GA22247@codepoet.org> References: <1023298283.2443.11.camel@irongate.swansea.linux.org.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ReaqsoxgOBHFXBhH" Return-path: Content-Disposition: inline In-Reply-To: <1023298283.2443.11.camel@irongate.swansea.linux.org.uk> List-Id: To: Alan Cox Cc: Ken Martwick , linux-8086@vger.kernel.org --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, On Wed, Jun 05, 2002 at 06:31:23PM +0100, Alan Cox wrote: > I've been pondering the question of how to make bcc fit. One way is a > better optimiser, but the other approach that might be easier to > implement would be an optional 'size before speed' piece of code. > > Take the entire existing tree, scan it for identical sequences of asm > instructions where the stack is balanced (ie equal push/pop and never > pops below the level on entry) generate a library of them and then > replace those sequences with calls if bcc is called with some suitable > option to run the replacer. We'd trade a few clock cycles for bytes each > time the substitution occurred. > > That way bcc would probably actually fit > As an interim approach, you could try just #ifdef-ing out the floating point support. I just ran a quick test of simply removing floatop.c from the dependencies and #ifdef'ing out the necessary code blocks in genloads.c, glogcode.c, softop.c, hardop.c, and assign.c. It buids, and at least the preprocessor works with elksemu. I'm not sure what compiler misbehavior might result if any floating point code is encountered though. [mjn3@mars bcc]$ file bcc bcc-cc1 bcc: Linux-8086 executable bcc-cc1: Linux-8086 executable [mjn3@mars bcc]$ size86 bcc bcc-cc1 text data bss dec hex filename 11776 1328 744 13848 3618 bcc 65424 5896 8848 80168 13928 bcc-cc1 This is for bcc from dev86-0.16.3, but with some additional tweaks to the preprocessor to support "#elif" and non-ansi token pasting macros, as well as enabling the "asm" statement outside of a function so that I could do things like the following (bcc patch for this is attached). I meant to post the patch sometime before this, but I've been pretty busy with some uClibc projects. Manuel /* Put this immediately before the function being aliased. */ #define __BCC_ALIAS(X,Y) asm("export _" "X" "\n_" "X" " = _" "Y") #ifdef __AS386_16__ #define __BCC_CTOR(X) asm( \ " loc 1\n" /* Make sure the pointer is in the correct segment */ \ "auto_func:\n" /* Label for bcc -M to work. */ \ ".word _" "X" "\n" /* Pointer to the autorun function */ \ ".word no_op\n" /* Space filler cause segs are padded to 4 bytes. */ \ ".text\n" /* So the function after is also in the correct seg. */ \ ) #endif #ifdef __AS386_32__ #define __BCC_CTOR(X) asm( \ " loc 1\n" /* Make sure the pointer is in the correct segment */ \ "auto_func:\n" /* Label for bcc -M to work. */ \ ".long _" "X" "\n" /* Pointer to the autorun function */ \ ".text\n" /* So the function after is also in the correct seg. */ \ ) #endif --ReaqsoxgOBHFXBhH Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bcc.diff" --- declare.c-dist Fri Dec 17 11:51:13 1999 +++ declare.c Sun Apr 21 18:55:33 2002 @@ -36,6 +36,7 @@ FORWARD void declselt P((struct typestruct *structype, offset_T *psoffset, struct typelist ** ptypelist)); FORWARD bool_pt declspec P((void)); +FORWARD void doasm2 P((void)); FORWARD struct typestruct *declsu P((void)); FORWARD void idecllist P((void)); FORWARD void initarray P((struct typestruct *type)); @@ -47,6 +48,23 @@ FORWARD void rdeclarator P((void)); FORWARD bool_pt regdecl P((void)); +PRIVATE void doasm2() +{ + lparen(); + if (sym!=STRINGCONST) + error("string const expected"); + else { + nextsym(); + constant.value.s[charptr-constant.value.s]='\0'; + outnstr("!BCC_ASM"); + outbyte('\t'); + outnstr(constant.value.s); + outnstr("!BCC_ENDASM"); + rparen(); + semicolon(); + } +} + PRIVATE struct typestruct *chainprefix(pretype, sufftype) struct typestruct *pretype; struct typestruct *sufftype; @@ -487,6 +505,10 @@ case UNSIGNDECL: ++nunsigned; nextsym(); + break; + case ASMSYM: + nextsym(); + doasm2(); break; default: goto break2; --- preproc.c-dist Sat Jan 12 12:02:18 2002 +++ preproc.c Sun Apr 21 18:55:43 2002 @@ -53,6 +53,7 @@ FORWARD void asmcontrol P((void)); FORWARD void control P((void)); FORWARD void defineorundefinestring P((char *str, bool_pt defineflag)); +FORWARD void elifcontrol P((void)); FORWARD void elsecontrol P((void)); FORWARD void endif P((void)); FORWARD fastin_pt getparnames P((void)); @@ -193,7 +194,7 @@ } ctlcase = symptr->offset.offsym; if (ifstate.ifflag == FALSE && - (ctlcase < ELSECNTL || ctlcase > IFNDEFCNTL)) + (ctlcase < ELIFCNTL || ctlcase > IFNDEFCNTL)) return; switch (ctlcase) { @@ -209,6 +210,9 @@ case DEFINECNTL: define(); break; + case ELIFCNTL: + elifcontrol(); + break; case ELSECNTL: elsecontrol(); break; @@ -345,7 +349,14 @@ gch1(); skipcomment(); /* comment is space in modern cpp's but they have '##' too */ +#if 0 ch = *--lineptr = ' '; +#else + /* With this, we can define a paste macro. */ + --lineptr; + gch1(); + continue; +#endif } } #ifdef TS @@ -495,6 +506,29 @@ } skipline(); } + } +} + +/* elifcontrol() - process #elif */ + +PRIVATE void elifcontrol() +{ + if (iflevel == 0) + { + error("elif without if"); + return; + } + if (ifstate.elseflag) { + register struct ifstruct *ifptr; + + ifptr = &ifstack[(int)--iflevel]; + ifstate.elseflag = ifptr->elseflag; + ifstate.ifflag = ifptr->ifflag; + + ifcontrol(IFCNTL); + } else { + ifstate.ifflag = ifstate.elseflag; + ifstate.elseflag = FALSE; } } --- table.c-dist Sat Mar 16 04:28:26 2002 +++ table.c Sun Apr 21 18:55:58 2002 @@ -30,7 +30,7 @@ #define MAXEXPR 500 #endif #define MAXLOCAL 100 -#define NKEYWORDS 35 +#define NKEYWORDS 36 #ifdef NOFLOAT #define NSCALTYPES 10 #else @@ -116,6 +116,7 @@ { "#asm", ASMCNTL, }, { "#define", DEFINECNTL, }, + { "#elif", ELIFCNTL, }, { "#else", ELSECNTL, }, { "#endasm", ENDASMCNTL, }, { "#endif", ENDIFCNTL, }, --ReaqsoxgOBHFXBhH--