From 7851ff900f4e5d10d246edde9e6d0eff75f66e4e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 31 Oct 1988 15:42:15 +0000 Subject: [PATCH] many modyfications in search for more speed --- util/ceg/ce_back/obj_back/back.h | 9 +++-- util/ceg/ce_back/obj_back/common.c | 6 +-- util/ceg/ce_back/obj_back/con2.c | 4 +- util/ceg/ce_back/obj_back/con4.c | 16 ++++++-- util/ceg/ce_back/obj_back/data.c | 55 +++++++------------------- util/ceg/ce_back/obj_back/data.h | 3 ++ util/ceg/ce_back/obj_back/gen2.c | 29 ++++++++++---- util/ceg/ce_back/obj_back/gen4.c | 38 ++++++++++++++---- util/ceg/ce_back/obj_back/mysprint.c | 7 +++- util/ceg/ce_back/obj_back/reloc1.c | 34 ++++++++++------ util/ceg/ce_back/obj_back/reloc2.c | 34 ++++++++++------ util/ceg/ce_back/obj_back/reloc4.c | 37 +++++++++++------ util/ceg/ce_back/obj_back/relocation.c | 4 +- util/ceg/ce_back/obj_back/rom2.c | 4 +- util/ceg/ce_back/obj_back/rom4.c | 16 ++++++-- util/ceg/ce_back/obj_back/switchseg.c | 4 +- util/ceg/ce_back/obj_back/symtable.c | 22 +++++++---- util/ceg/ce_back/obj_back/text2.c | 4 +- util/ceg/ce_back/obj_back/text4.c | 16 ++++++-- 19 files changed, 208 insertions(+), 134 deletions(-) diff --git a/util/ceg/ce_back/obj_back/back.h b/util/ceg/ce_back/obj_back/back.h index 621695bee..301c5e3f8 100644 --- a/util/ceg/ce_back/obj_back/back.h +++ b/util/ceg/ce_back/obj_back/back.h @@ -26,6 +26,8 @@ extern holno, procno; #define swtxt() switchseg( SEGTXT) +#define switchseg(seg) if ((seg) != cur_seg) swtchsg(seg); else + #define PC_REL 1 #define ABSOLUTE !PC_REL @@ -34,8 +36,7 @@ extern holno, procno; #define MAXTEXT 4096 #define MAXDATA 2048 -#define MAXRELO 100 -#define MAXNAME 100 -#define MAXSTRING 2048 -#define MAXHASH 256 +#define MAXRELO 512 +#define MAXNAME 512 +#define MAXSTRING 4096 diff --git a/util/ceg/ce_back/obj_back/common.c b/util/ceg/ce_back/obj_back/common.c index 0db096c6c..c6579f859 100644 --- a/util/ceg/ce_back/obj_back/common.c +++ b/util/ceg/ce_back/obj_back/common.c @@ -9,9 +9,9 @@ arith n; register struct outname *nm = &symbol_table[Label]; if (label_waiting && (nm->on_type & S_EXT)) { - symbol_table[Label].on_type |= S_COM | (S_MIN+SEGBSS); - if (n > symbol_table[Label].on_valu) { - symbol_table[Label].on_valu = n; + nm->on_type |= S_COM | (S_MIN+SEGBSS); + if (n > nm->on_valu) { + nm->on_valu = n; } label_waiting = 0; return; diff --git a/util/ceg/ce_back/obj_back/con2.c b/util/ceg/ce_back/obj_back/con2.c index 0adb5968a..0fd6e6a04 100644 --- a/util/ceg/ce_back/obj_back/con2.c +++ b/util/ceg/ce_back/obj_back/con2.c @@ -6,11 +6,11 @@ TWO_BYTES w; { if ((_data_cnt -= 2) < 0) mem_data(); #ifdef BYTES_REVERSED - *data++ = ( unsigned short)w>>8; + *data++ = w>>8; *data++ = w; #else *data++ = w; - *data++ = ( unsigned short)w>>8; + *data++ = w>>8; #endif } diff --git a/util/ceg/ce_back/obj_back/con4.c b/util/ceg/ce_back/obj_back/con4.c index af590e679..2027e5e93 100644 --- a/util/ceg/ce_back/obj_back/con4.c +++ b/util/ceg/ce_back/obj_back/con4.c @@ -1,14 +1,22 @@ #include "mach.h" +#include "back.h" + +#ifdef BYTES_REVERSED +#define con2(w) { *data++ = ((w) >> 8); *data++ = (w);} +#else +#define con2(w) { *data++ = (w); *data++ = ((w)>>8);} +#endif con4( l) FOUR_BYTES l; { + if ((_data_cnt -= 4) < 0) mem_data(); #ifdef WORDS_REVERSED - con2( (short) ((unsigned long)l>>16)); - con2( (short) l); + con2( (int)(l>>16)); + con2( (int) l); #else - con2( (short) l); - con2( (short) ((unsigned long)l>>16)); + con2( (int) l); + con2( (int) (l>>16)); #endif } diff --git a/util/ceg/ce_back/obj_back/data.c b/util/ceg/ce_back/obj_back/data.c index d3c87b810..5963a84a2 100644 --- a/util/ceg/ce_back/obj_back/data.c +++ b/util/ceg/ce_back/obj_back/data.c @@ -1,5 +1,6 @@ #include #include +#include "data.h" #include "mach.h" /* Global datastructures : @@ -36,26 +37,17 @@ long nbss = 0, size_text, size_data, size_reloc, size_symbol, size_string, _text_cnt, _data_cnt; -put1(sect,addr,b) -char *sect; -long addr; -char b; -{ - sect[addr] = b; -} - - put2(sect,addr,w) char *sect; long addr; int w; { #ifdef BYTES_REVERSED - put1(sect,addr,(char) (w>>8)); - put1(sect,addr+1,(char) w); + put1(sect, addr, (w>>8)); + put1(sect, addr+1, w); #else - put1(sect,addr,(char) w); - put1(sect,addr+1,(char) (w>>8)); + put1(sect, addr, w); + put1(sect, addr+1, (w>>8)); #endif } @@ -66,37 +58,23 @@ long addr; long l; { #ifdef WORDS_REVERSED - put2(sect,addr,(short) (l>>16)); - put2(sect,addr+2,(short) l); + put2(sect,addr,(int) (l>>16)); + put2(sect,addr+2,(int) l); #else - put2(sect,addr,(short) l); - put2(sect,addr+2,(short) (l>>16)); + put2(sect,addr,(int) l); + put2(sect,addr+2,(int) (l>>16)); #endif } - -char get1( sect, addr) +int get2(sect,addr) char *sect; long addr; { - return( sect[addr]); -} - - -short get2(sect,addr) -char *sect; -long addr; -{ - short h,l; - #ifdef BYTES_REVERSED - h = sect[addr]; - l = sect[addr+1]; + return (get1(sect,addr) << 8) | (get1(sect,addr+1) & 255); #else - l = sect[addr]; - h = sect[addr+1]; + return (get1(sect,addr+1) << 8) | (get1(sect,addr) & 255); #endif - return( ( h << 8) | ( l & 255)); } @@ -104,14 +82,9 @@ long get4(sect,addr) char *sect; long addr; { - long l,h; - #ifdef WORDS_REVERSED - h = get2(sect,addr); - l = get2(sect,addr+2); + return ((long)get2(sect,addr) << 16) | get2(sect, addr+2); #else - l = get2(sect,addr); - h = get2(sect,addr+2); + return ((long)get2(sect,addr+2) << 16) | get2(sect, addr); #endif - return( ( h << 16) | ( l & 65535L)); } diff --git a/util/ceg/ce_back/obj_back/data.h b/util/ceg/ce_back/obj_back/data.h index 1c9bb35f5..ee17d90a6 100644 --- a/util/ceg/ce_back/obj_back/data.h +++ b/util/ceg/ce_back/obj_back/data.h @@ -1,6 +1,7 @@ /* The global datastructures (see "data.c"). */ extern long cur_value(); +extern long get4(); extern int cur_seg; @@ -13,3 +14,5 @@ extern char *text_area, *data_area, *string_area; extern struct outrelo *reloc_info, *relo; extern struct outname *symbol_table; +#define put1(buf, off, w) ((buf)[off] = (w)) +#define get1(buf, off) ((buf)[off]) diff --git a/util/ceg/ce_back/obj_back/gen2.c b/util/ceg/ce_back/obj_back/gen2.c index 2de971541..390368558 100644 --- a/util/ceg/ce_back/obj_back/gen2.c +++ b/util/ceg/ce_back/obj_back/gen2.c @@ -2,15 +2,30 @@ #include "mach.h" #include "back.h" -gen2( c) -TWO_BYTES c; +gen2( w) +TWO_BYTES w; { switch ( cur_seg) { - case SEGTXT : text2( c); - return; - case SEGCON : con2( c); - return; - case SEGROM : rom2( c); + case SEGTXT : + if ((_text_cnt -= 2) < 0) mem_text(); +#ifdef BYTES_REVERSED + *text++ = w>>8; + *text++ = w; +#else + *text++ = w; + *text++ = w>>8; +#endif + return; + case SEGCON : + case SEGROM : + if ((_data_cnt -= 2) < 0) mem_data(); +#ifdef BYTES_REVERSED + *data++ = w>>8; + *data++ = w; +#else + *data++ = w; + *data++ = w>>8; +#endif return; case SEGBSS : bss( 2); return; diff --git a/util/ceg/ce_back/obj_back/gen4.c b/util/ceg/ce_back/obj_back/gen4.c index 218e0eb85..98cb08ca3 100644 --- a/util/ceg/ce_back/obj_back/gen4.c +++ b/util/ceg/ce_back/obj_back/gen4.c @@ -1,17 +1,39 @@ #include #include "mach.h" #include "back.h" +#ifdef BYTES_REVERSED +#define text2(w) { *text++ = ((w) >> 8); *text++ = (w);} +#define con2(w) { *data++ = ((w) >> 8); *data++ = (w);} +#else +#define text2(w) { *text++ = (w); *text++ = ((w)>>8);} +#define con2(w) { *data++ = (w); *data++ = ((w)>>8);} +#endif -gen4( c) -FOUR_BYTES c; +gen4( l) +FOUR_BYTES l; { switch ( cur_seg) { - case SEGTXT : text4( c); - return; - case SEGCON : con4( c); - return; - case SEGROM : rom4( c); - return; + case SEGTXT : + if ((_text_cnt -= 4) < 0) mem_text(); +#ifdef WORDS_REVERSED + text2( (int) (l>>16)); + text2( (int) l); +#else + text2( (int) l); + text2( (int) (l>>16)); +#endif + return; + case SEGCON : + case SEGROM : + if ((_data_cnt -= 4) < 0) mem_data(); +#ifdef WORDS_REVERSED + con2( (int)(l>>16)); + con2( (int) l); +#else + con2( (int) l); + con2( (int) (l>>16)); +#endif + return; case SEGBSS : bss( 4); return; default : fprint( STDERR, "gen4() : bad seg number\n"); diff --git a/util/ceg/ce_back/obj_back/mysprint.c b/util/ceg/ce_back/obj_back/mysprint.c index bc33ea573..44281a661 100644 --- a/util/ceg/ce_back/obj_back/mysprint.c +++ b/util/ceg/ce_back/obj_back/mysprint.c @@ -3,9 +3,12 @@ #include /* Mysprint() stores the string directly in the string_arae. This saves - * a copy action. + * a copy action. It is assumed that the strings stored in the string-table + * are never longer than MAXSTRLEN bytes. */ +#define MAXSTRLEN 1024 + /*VARARGS*/ int mysprint(va_alist) va_dcl @@ -16,7 +19,7 @@ int mysprint(va_alist) va_start(args); fmt = va_arg(args, char *); - while (string + 1024 - string_area > size_string) + while (string + MAXSTRLEN - string_area > size_string) mem_string(); retval = _format(string, fmt, args); string[retval] = '\0'; diff --git a/util/ceg/ce_back/obj_back/reloc1.c b/util/ceg/ce_back/obj_back/reloc1.c index fbf7fb679..af5747146 100644 --- a/util/ceg/ce_back/obj_back/reloc1.c +++ b/util/ceg/ce_back/obj_back/reloc1.c @@ -8,26 +8,36 @@ * absolute. */ +#ifdef WORDS_REVERSED +#ifdef BYTES_REVERSED +#define RRR (RELO1|RELBR|RELWR) +#else +#define RRR (RELO1|RELWR) +#endif +#else +#ifdef BYTES_REVERSED +#define RRR (RELO1|RELBR) +#else +#define RRR (RELO1) +#endif +#endif + reloc1( sym, off, pcrel) char *sym; arith off; int pcrel; { + register struct outrelo *r; + if ( relo - reloc_info >= size_reloc) mem_relo(); - relo->or_type = RELO1; -#ifdef BYTES_REVERSED - relo->or_type |= RELBR; -#endif -#ifdef WORDS_REVERSED - relo->or_type |= RELWR; -#endif - relo->or_type |= ( pcrel) ? RELPC : S_UND; - relo->or_sect = S_MIN + conv_seg( cur_seg); - relo->or_nami = find_sym(sym, REFERENCE); - relo->or_addr = cur_value(); - gen1( (pcrel) ? off - ( cur_value() + 1) : off); + r = relo; + r->or_type |= ( pcrel) ? RELPC|RRR : RRR; + r->or_sect = S_MIN + conv_seg( cur_seg); + r->or_nami = find_sym(sym, REFERENCE); + r->or_addr = cur_value(); + gen1( (pcrel) ? off - ( r->or_addr + 1) : off); relo++; } diff --git a/util/ceg/ce_back/obj_back/reloc2.c b/util/ceg/ce_back/obj_back/reloc2.c index 9f27776bb..938c8684f 100644 --- a/util/ceg/ce_back/obj_back/reloc2.c +++ b/util/ceg/ce_back/obj_back/reloc2.c @@ -8,26 +8,36 @@ * absolute. */ +#ifdef WORDS_REVERSED +#ifdef BYTES_REVERSED +#define RRR (RELO2|RELBR|RELWR) +#else +#define RRR (RELO2|RELWR) +#endif +#else +#ifdef BYTES_REVERSED +#define RRR (RELO2|RELBR) +#else +#define RRR (RELO2) +#endif +#endif + reloc2( sym, off, pcrel) char *sym; arith off; int pcrel; { + register struct outrelo *r; + if ( relo - reloc_info >= size_reloc) mem_relo(); - relo->or_type = RELO2; -#ifdef BYTES_REVERSED - relo->or_type |= RELBR; -#endif -#ifdef WORDS_REVERSED - relo->or_type |= RELWR; -#endif - relo->or_type |= ( pcrel) ? RELPC : S_UND; - relo->or_sect = S_MIN + conv_seg( cur_seg); - relo->or_nami = find_sym(sym, REFERENCE); - relo->or_addr = cur_value(); - gen2( (pcrel) ? off - ( cur_value() + 2) : off); + r = relo; + r->or_type = ( pcrel) ? RELPC|RRR : RRR; + r->or_sect = S_MIN + conv_seg( cur_seg); + r->or_nami = find_sym(sym, REFERENCE); + r->or_addr = cur_value(); + gen2( (pcrel) ? off - ( r->or_addr + 2) : off); relo++; } diff --git a/util/ceg/ce_back/obj_back/reloc4.c b/util/ceg/ce_back/obj_back/reloc4.c index 72a27bb2f..009a553cc 100644 --- a/util/ceg/ce_back/obj_back/reloc4.c +++ b/util/ceg/ce_back/obj_back/reloc4.c @@ -9,29 +9,40 @@ * absolute. */ +#ifdef WORDS_REVERSED +#ifdef BYTES_REVERSED +#define RRR (RELO4|RELBR|RELWR) +#else +#define RRR (RELO4|RELWR) +#endif +#else +#ifdef BYTES_REVERSED +#define RRR (RELO4|RELBR) +#else +#define RRR (RELO4) +#endif +#endif + reloc4( sym, off, pcrel) char *sym; arith off; int pcrel; { + register struct outrelo *r; + if ( relo - reloc_info >= size_reloc) mem_relo(); - relo->or_type = RELO4; -#ifdef BYTES_REVERSED - relo->or_type |= RELBR; -#endif -#ifdef WORDS_REVERSED - relo->or_type |= RELWR; -#endif - relo->or_type |= ( pcrel) ? RELPC : S_UND; - relo->or_sect = S_MIN + conv_seg( cur_seg); - relo->or_nami = find_sym(sym, REFERENCE); - relo->or_addr = cur_value(); - gen4( (pcrel) ? off - ( cur_value() + 4) : off); + r = relo; + + r->or_type = ( pcrel) ? RELPC|RRR : RRR; + r->or_sect = S_MIN + conv_seg( cur_seg); + r->or_nami = find_sym(sym, REFERENCE); + r->or_addr = cur_value(); + gen4( (pcrel) ? off - ( r->or_addr + 4) : off); /* print( "r %s r %ld s %d in %d adrr %ld off %ld\n", - sym, pcrel, cur_seg, relo->or_nami, relo->or_addr, + sym, pcrel, cur_seg, r->or_nami, r->or_addr, (pcrel) ? off-cur_value() : off); */ diff --git a/util/ceg/ce_back/obj_back/relocation.c b/util/ceg/ce_back/obj_back/relocation.c index 6990107dd..6aa198eb3 100644 --- a/util/ceg/ce_back/obj_back/relocation.c +++ b/util/ceg/ce_back/obj_back/relocation.c @@ -1,6 +1,7 @@ #include #include #include "back.h" +#include "data.h" /* Solve the local references. */ @@ -8,9 +9,6 @@ #define seg_index( s) ( nname - SEGBSS - 1 + s) long get4(); -extern short get2(); -extern char get1(); - do_local_relocation() diff --git a/util/ceg/ce_back/obj_back/rom2.c b/util/ceg/ce_back/obj_back/rom2.c index 698d43948..216decd1d 100644 --- a/util/ceg/ce_back/obj_back/rom2.c +++ b/util/ceg/ce_back/obj_back/rom2.c @@ -6,10 +6,10 @@ TWO_BYTES w; { if ((_data_cnt -= 2) < 0) mem_data(); #ifdef BYTES_REVERSED - *data++ = ( unsigned short)w>>8; + *data++ = w>>8; *data++ = w; #else *data++ = w; - *data++ = ( unsigned short)w>>8; + *data++ = w>>8; #endif } diff --git a/util/ceg/ce_back/obj_back/rom4.c b/util/ceg/ce_back/obj_back/rom4.c index 1a6150b1a..351ec7d67 100644 --- a/util/ceg/ce_back/obj_back/rom4.c +++ b/util/ceg/ce_back/obj_back/rom4.c @@ -1,14 +1,22 @@ #include "mach.h" +#include "back.h" + +#ifdef BYTES_REVERSED +#define rom2(w) { *data++ = ((w) >> 8); *data++ = (w);} +#else +#define rom2(w) { *data++ = (w); *data++ = ((w)>>8);} +#endif rom4( l) FOUR_BYTES l; { + if ((_data_cnt -= 4) < 0) mem_data(); #ifdef WORDS_REVERSED - rom2( (short) ((unsigned long)l>>16)); - rom2( (short) l); + rom2( (int)(l>>16)); + rom2( (int) l); #else - rom2( (short) l); - rom2( (short) ((unsigned long)l>>16)); + rom2( (int) l); + rom2( (int) (l>>16)); #endif } diff --git a/util/ceg/ce_back/obj_back/switchseg.c b/util/ceg/ce_back/obj_back/switchseg.c index 0c1b8f6c8..b7752673e 100644 --- a/util/ceg/ce_back/obj_back/switchseg.c +++ b/util/ceg/ce_back/obj_back/switchseg.c @@ -1,14 +1,12 @@ #include "data.h" -switchseg( seg) +swtchsg( seg) int seg; /* The EM definition demands that pseudo instructions are aligned * at word boundaries. */ { - if ( seg == cur_seg) - return; cur_seg = seg; align_word(); } diff --git a/util/ceg/ce_back/obj_back/symtable.c b/util/ceg/ce_back/obj_back/symtable.c index 0dab30dd3..db324a96e 100644 --- a/util/ceg/ce_back/obj_back/symtable.c +++ b/util/ceg/ce_back/obj_back/symtable.c @@ -30,6 +30,9 @@ int string_lengte = 0, index_symbol_table = -1; struct Hashitem *Hashitems ; + +/* MAXHASH must be a power of two ... */ +#define MAXHASH 512 static int Hashtab[ MAXHASH]; static int Hash(); @@ -38,7 +41,6 @@ int find_sym( sym, isdef) char *sym; int isdef; { - register char *p; register struct outname *s; register struct Hashitem *ip; register int h; @@ -57,8 +59,11 @@ int isdef; h = Hash(sym); for ( ip = Hashtab[h] + Hashitems ; ip != Hashitems; ip = (ip->hs_next) + Hashitems) { + register char *p = sym, *q; + s = symbol_table + ip->hs_nami; - if (strcmp(sym, (s->on_foff) + string_area) == 0) { + q = string_area + s->on_foff; + while (*p == *q++) if (*p++ == '\0') { if ( (s->on_valu == -2) && (isdef == REFERENCE)) { s->on_type = S_EXT; s->on_valu = -1; @@ -89,6 +94,8 @@ int isdef; if ( sym == string) string += string_lengte; else { /* zie C_fil, C_lin, C_lni */ + register char *p; + string_lengte = 0; for( p=sym; *p != '\0' ; p++) { string_lengte++; @@ -111,15 +118,14 @@ int isdef; static int Hash(sym) -register char *sym; + char *sym; { register unsigned h; - register c; + register char *s = sym; h = 0; - while (c = *sym++) { - h <<= 2; - h += c; + while (*s) { + h = (h << 2) + *s++; } - return (h % MAXHASH); + return (h & (MAXHASH - 1)); } diff --git a/util/ceg/ce_back/obj_back/text2.c b/util/ceg/ce_back/obj_back/text2.c index 040d72b35..f93389aaa 100644 --- a/util/ceg/ce_back/obj_back/text2.c +++ b/util/ceg/ce_back/obj_back/text2.c @@ -6,10 +6,10 @@ TWO_BYTES w; { if ((_text_cnt -= 2) < 0) mem_text(); #ifdef BYTES_REVERSED - *text++ = ( unsigned short)w>>8; + *text++ = w>>8; *text++ = w; #else *text++ = w; - *text++ = ( unsigned short)w>>8; + *text++ = w>>8; #endif } diff --git a/util/ceg/ce_back/obj_back/text4.c b/util/ceg/ce_back/obj_back/text4.c index 6b318f3da..81167f4b8 100644 --- a/util/ceg/ce_back/obj_back/text4.c +++ b/util/ceg/ce_back/obj_back/text4.c @@ -1,13 +1,21 @@ #include "mach.h" +#include "back.h" + +#ifdef BYTES_REVERSED +#define text2(w) { *text++ = ((w) >> 8); *text++ = (w);} +#else +#define text2(w) { *text++ = (w); *text++ = ((w)>>8);} +#endif text4( l) FOUR_BYTES l; { + if ((_text_cnt -= 4) < 0) mem_text(); #ifdef WORDS_REVERSED - text2( (short) ((unsigned long)l>>16)); - text2( (short) l); + text2( (int) (l>>16)); + text2( (int) l); #else - text2( (short) l); - text2( (short) ((unsigned long)l>>16)); + text2( (int) l); + text2( (int) (l>>16)); #endif }