summaryrefslogtreecommitdiff
path: root/sys/src/cmd
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-05-04 16:11:48 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-05-04 16:11:48 +0200
commit986886f2b8ab4a7e1b3d66e99934d8fdab537be9 (patch)
treec49e9711e7229a8d12f5b5b0ab38b5bd6c27b711 /sys/src/cmd
parentf7703d6971383c39f981f5676a4e28a6371c3997 (diff)
retire the dec alpha port
Diffstat (limited to 'sys/src/cmd')
-rw-r--r--sys/src/cmd/7a/a.h208
-rw-r--r--sys/src/cmd/7a/a.y537
-rw-r--r--sys/src/cmd/7a/lex.c694
-rw-r--r--sys/src/cmd/7a/mkfile19
-rw-r--r--sys/src/cmd/7c/7.out.h265
-rw-r--r--sys/src/cmd/7c/cgen.c1067
-rw-r--r--sys/src/cmd/7c/enam.c165
-rw-r--r--sys/src/cmd/7c/gc.h343
-rw-r--r--sys/src/cmd/7c/list.c231
-rw-r--r--sys/src/cmd/7c/machcap.c9
-rw-r--r--sys/src/cmd/7c/mkenam15
-rw-r--r--sys/src/cmd/7c/mkfile39
-rw-r--r--sys/src/cmd/7c/mul.c608
-rw-r--r--sys/src/cmd/7c/peep.c759
-rw-r--r--sys/src/cmd/7c/reg.c1164
-rw-r--r--sys/src/cmd/7c/sgen.c235
-rw-r--r--sys/src/cmd/7c/swt.c578
-rw-r--r--sys/src/cmd/7c/txt.c1306
-rw-r--r--sys/src/cmd/7l/asm.c1220
-rw-r--r--sys/src/cmd/7l/compat.c56
-rw-r--r--sys/src/cmd/7l/l.h316
-rw-r--r--sys/src/cmd/7l/list.c246
-rw-r--r--sys/src/cmd/7l/mkfile33
-rw-r--r--sys/src/cmd/7l/noop.c947
-rw-r--r--sys/src/cmd/7l/obj.c1350
-rw-r--r--sys/src/cmd/7l/optab.c141
-rw-r--r--sys/src/cmd/7l/pass.c495
-rw-r--r--sys/src/cmd/7l/sched.c18
-rw-r--r--sys/src/cmd/7l/span.c584
-rw-r--r--sys/src/cmd/gs/alpha.h44
-rw-r--r--sys/src/cmd/gs/arch.h2
-rw-r--r--sys/src/cmd/gs/default.alpha.h44
-rw-r--r--sys/src/cmd/pcc.c1
-rw-r--r--sys/src/cmd/prof.c1
-rw-r--r--sys/src/cmd/python/pyconfig.h2
35 files changed, 1 insertions, 13741 deletions
diff --git a/sys/src/cmd/7a/a.h b/sys/src/cmd/7a/a.h
deleted file mode 100644
index bb44001a2..000000000
--- a/sys/src/cmd/7a/a.h
+++ /dev/null
@@ -1,208 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../7c/7.out.h"
-
-#ifndef EXTERN
-#define EXTERN extern
-#endif
-
-#define MAXALIGN 7
-
-typedef struct Sym Sym;
-typedef struct Ref Ref;
-typedef struct Gen Gen;
-typedef struct Io Io;
-typedef struct Hist Hist;
-
-#define FPCHIP 1
-#define NSYMB 500
-#define BUFSIZ 8192
-#define HISTSZ 20
-#define NINCLUDE 10
-#define NHUNK 10000
-#define EOF (-1)
-#define IGN (-2)
-#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
-#define NHASH 503
-#define STRINGSZ 200
-#define NMACRO 10
-
-#define ALLOC(lhs, type)\
- while(nhunk < sizeof(type))\
- gethunk();\
- lhs = (type*)hunk;\
- nhunk -= sizeof(type);\
- hunk += sizeof(type);
-
-#define ALLOCN(lhs, len, n)\
- if(lhs+len != hunk || nhunk < n) {\
- while(nhunk <= len)\
- gethunk();\
- memmove(hunk, lhs, len);\
- lhs = hunk;\
- hunk += len;\
- nhunk -= len;\
- }\
- hunk += n;\
- nhunk -= n;
-
-struct Sym
-{
- Sym* link;
- Ref* ref;
- char* macro;
- vlong value;
- long dummy_pad;
- ushort type;
- char *name;
- char sym;
-};
-#define S ((Sym*)0)
-
-struct Ref
-{
- int class;
-};
-
-struct
-{
- char* p;
- int c;
-} fi;
-
-struct Io
-{
- Io* link;
- char b[BUFSIZ];
- char* p;
- short c;
- short f;
-};
-#define I ((Io*)0)
-
-struct
-{
- Sym* sym;
- short type;
-} h[NSYM];
-
-struct Gen
-{
- Sym* sym;
- vlong offset;
- long dummy_pad;
- short type;
- short reg;
- short name;
- double dval;
- char sval[8];
-};
-
-struct Hist
-{
- Hist* link;
- char* name;
- long line;
- vlong offset;
-};
-#define H ((Hist*)0)
-
-enum
-{
- CLAST,
- CMACARG,
- CMACRO,
- CPREPROC,
-};
-
-char debug[256];
-Sym* hash[NHASH];
-char* Dlist[30];
-int nDlist;
-Hist* ehist;
-int newflag;
-Hist* hist;
-char* hunk;
-char* include[NINCLUDE];
-Io* iofree;
-Io* ionext;
-Io* iostack;
-long lineno;
-int nerrors;
-long nhunk;
-int ninclude;
-Gen nullgen;
-char* outfile;
-int pass;
-char* pathname;
-vlong pc;
-int peekc;
-int sym;
-char symb[NSYMB];
-int thechar;
-char* thestring;
-long thunk;
-Biobuf obuf;
-
-void errorexit(void);
-void pushio(void);
-void newio(void);
-void newfile(char*, int);
-Sym* slookup(char*);
-Sym* lookup(void);
-void syminit(Sym*);
-long yylex(void);
-int getc(void);
-int getnsc(void);
-void unget(int);
-int escchar(int);
-void cinit(void);
-void pinit(char*);
-void cclean(void);
-int isreg(Gen*);
-void outcode(int, Gen*, int, Gen*);
-void zname(char*, int, int);
-void zaddr(Gen*, int);
-void ieeedtod(Ieee*, double);
-int filbuf(void);
-Sym* getsym(void);
-void domacro(void);
-void macund(void);
-void macdef(void);
-void macexpand(Sym*, char*);
-void macinc(void);
-void maclin(void);
-void macprag(void);
-void macif(int);
-void macend(void);
-void outhist(void);
-void dodefine(char*);
-void prfile(long);
-void linehist(char*, int);
-void gethunk(void);
-void yyerror(char*, ...);
-int yyparse(void);
-void setinclude(char*);
-int assemble(char*);
-
-/*
- * system-dependent stuff from ../cc/compat.c
- */
-
-enum /* keep in synch with ../cc/cc.h */
-{
- Plan9 = 1<<0,
- Unix = 1<<1,
- Windows = 1<<2,
-};
-int mywait(int*);
-int mycreat(char*, int);
-int systemtype(int);
-int pathchar(void);
-char* mygetwd(char*, int);
-int myexec(char*, char*[]);
-int mydup(int, int);
-int myfork(void);
-int mypipe(int*);
-void* mysbrk(ulong);
diff --git a/sys/src/cmd/7a/a.y b/sys/src/cmd/7a/a.y
deleted file mode 100644
index 8e0565032..000000000
--- a/sys/src/cmd/7a/a.y
+++ /dev/null
@@ -1,537 +0,0 @@
-%{
-#include "a.h"
-%}
-%union
-{
- Sym *sym;
- vlong lval;
- double dval;
- char sval[8];
- Gen gen;
-}
-%left '|'
-%left '^'
-%left '&'
-%left '<' '>'
-%left '+' '-'
-%left '*' '/' '%'
-%token <lval> LTYPE1 LTYPE2 LTYPE3 LTYPE4 LTYPE5
-%token <lval> LTYPE6 LTYPE7 LTYPE8 LTYPE9 LTYPEA
-%token <lval> LTYPEB LTYPEC LTYPED LTYPEE LTYPEF
-%token <lval> LTYPEG LTYPEH LTYPEI LTYPEJ LTYPEK
-%token <lval> LCONST LSP LSB LFP LPC LPREG LPCC
-%token <lval> LTYPEX LREG LFREG LFPCR LR LP LF
-%token <dval> LFCONST
-%token <sval> LSCONST
-%token <sym> LNAME LLAB LVAR
-%type <lval> con expr pointer offset sreg
-%type <gen> gen vgen lgen vlgen flgen rel reg freg preg fcreg
-%type <gen> imm ximm ireg name oreg imr nireg fgen pcc
-%%
-prog:
-| prog line
-
-line:
- LLAB ':'
- {
- if($1->value != pc)
- yyerror("redeclaration of %s", $1->name);
- $1->value = pc;
- }
- line
-| LNAME ':'
- {
- $1->type = LLAB;
- $1->value = pc;
- }
- line
-| LNAME '=' expr ';'
- {
- $1->type = LVAR;
- $1->value = $3;
- }
-| LVAR '=' expr ';'
- {
- if($1->value != $3)
- yyerror("redeclaration of %s", $1->name);
- $1->value = $3;
- }
-| ';'
-| inst ';'
-| error ';'
-
-inst:
-/*
- * Integer operates
- */
- LTYPE1 imr ',' sreg ',' reg
- {
- outcode($1, &$2, $4, &$6);
- }
-| LTYPE1 imr ',' reg
- {
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * floating-type
- */
-| LTYPE2 freg ',' freg
- {
- outcode($1, &$2, NREG, &$4);
- }
-| LTYPE3 freg ',' freg
- {
- outcode($1, &$2, NREG, &$4);
- }
-| LTYPE3 freg ',' LFREG ',' freg
- {
- outcode($1, &$2, $4, &$6);
- }
-/*
- * MOVQ
- */
-| LTYPE4 vlgen ',' vgen
- {
- if(!isreg(&$2) && !isreg(&$4))
- print("one side must be register\n");
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * integer LOAD/STORE, but not MOVQ
- */
-| LTYPE5 lgen ',' gen
- {
- if(!isreg(&$2) && !isreg(&$4))
- print("one side must be register\n");
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * integer LOAD/STORE (only)
- */
-| LTYPE6 oreg ',' reg
- {
- outcode($1, &$2, NREG, &$4);
- }
-| LTYPEK reg ',' oreg
- {
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * floating LOAD/STORE
- */
-| LTYPE7 flgen ',' fgen
- {
- if(!isreg(&$2) && !isreg(&$4))
- print("one side must be register\n");
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * JMP/JSR/RET
- */
-| LTYPE8 comma rel
- {
- outcode($1, &nullgen, NREG, &$3);
- }
-| LTYPE8 comma nireg
- {
- outcode($1, &nullgen, NREG, &$3);
- }
-| LTYPE8 sreg ',' nireg
- {
- outcode($1, &nullgen, $2, &$4);
- }
-| LTYPE9 comma
- {
- outcode($1, &nullgen, NREG, &nullgen);
- }
-/*
- * integer conditional branches
- */
-| LTYPEA gen ',' rel
- {
- if(!isreg(&$2))
- print("left side must be register\n");
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * floating conditional branches
- */
-| LTYPEB fgen ',' rel
- {
- if(!isreg(&$2))
- print("left side must be register\n");
- outcode($1, &$2, NREG, &$4);
- }
-/*
- * TRAPB/MB/REI
- */
-| LTYPEC comma
- {
- outcode($1, &nullgen, NREG, &nullgen);
- }
-/*
- * FETCH/FETCHM
- */
-| LTYPED ireg comma
- {
- outcode($1, &$2, NREG, &nullgen);
- }
-/*
- * Call-pal
- */
-| LTYPEE imm
- {
- outcode($1, &$2, NREG, &nullgen);
- }
-/*
- * TEXT/GLOBL
- */
-| LTYPEF name ',' imm
- {
- outcode($1, &$2, NREG, &$4);
- }
-| LTYPEF name ',' con ',' imm
- {
- outcode($1, &$2, $4, &$6);
- }
-/*
- * DATA
- */
-| LTYPEG name '/' con ',' ximm
- {
- outcode($1, &$2, $4, &$6);
- }
-/*
- * word
- */
-| LTYPEH comma ximm
- {
- outcode($1, &nullgen, NREG, &$3);
- }
-/*
- * NOP
- */
-| LTYPEI comma
- {
- outcode($1, &nullgen, NREG, &nullgen);
- }
-| LTYPEI ',' vgen
- {
- outcode($1, &nullgen, NREG, &$3);
- }
-| LTYPEI vgen comma
- {
- outcode($1, &$2, NREG, &nullgen);
- }
-
-comma:
-| ','
-
-rel:
- con '(' LPC ')'
- {
- $$ = nullgen;
- $$.type = D_BRANCH;
- $$.offset = $1 + pc;
- }
-| LNAME offset
- {
- $$ = nullgen;
- if(pass == 2)
- yyerror("undefined label: %s", $1->name);
- $$.type = D_BRANCH;
- $$.sym = $1;
- $$.offset = $2;
- }
-| LLAB offset
- {
- $$ = nullgen;
- $$.type = D_BRANCH;
- $$.sym = $1;
- $$.offset = $1->value + $2;
- }
-
-vlgen:
- lgen
-| preg
-| pcc
-
-vgen:
- gen
-| preg
-
-lgen:
- gen
-| ximm
-
-flgen:
- fgen
-| ximm
-
-fgen:
- gen
-| freg
-| fcreg
-
-preg:
- LPREG
- {
- $$ = nullgen;
- $$.type = D_PREG;
- $$.reg = $1;
- }
-| LP '(' con ')'
- {
- $$ = nullgen;
- $$.type = D_PREG;
- $$.reg = $1+$3;
- }
-
-fcreg:
- LFPCR
- {
- $$ = nullgen;
- $$.type = D_FCREG;
- $$.reg = $1;
- }
-
-freg:
- LFREG
- {
- $$ = nullgen;
- $$.type = D_FREG;
- $$.reg = $1;
- }
-| LF '(' con ')'
- {
- $$ = nullgen;
- $$.type = D_FREG;
- $$.reg = $3;
- }
-
-pcc:
- LPCC
- {
- $$ = nullgen;
- $$.type = D_PCC;
- $$.reg = $1;
- }
-
-ximm: '$' con
- {
- $$ = nullgen;
- $$.type = D_CONST;
- $$.offset = $2;
- }
-| '$' oreg
- {
- $$ = $2;
- $$.type = D_CONST;
- }
-| '$' LSCONST
- {
- $$ = nullgen;
- $$.type = D_SCONST;
- memcpy($$.sval, $2, sizeof($$.sval));
- }
-| '$' LFCONST
- {
- $$ = nullgen;
- $$.type = D_FCONST;
- $$.dval = $2;
- }
-| '$' '-' LFCONST
- {
- $$ = nullgen;
- $$.type = D_FCONST;
- $$.dval = -$3;
- }
-
-nireg:
- ireg
-| name
- {
- $$ = $1;
- if($1.name != D_EXTERN && $1.name != D_STATIC) {
- }
- }
-
-ireg:
- '(' sreg ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.reg = $2;
- $$.offset = 0;
- }
-
-gen:
- reg
-| con
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.offset = $1;
- }
-| oreg
-
-oreg:
- name
-| name '(' sreg ')'
- {
- $$ = $1;
- $$.type = D_OREG;
- $$.reg = $3;
- }
-| '(' sreg ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.reg = $2;
- $$.offset = 0;
- }
-| con '(' sreg ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.reg = $3;
- $$.offset = $1;
- }
-
-imr:
- reg
-| imm
-
-imm: '$' con
- {
- $$ = nullgen;
- $$.type = D_CONST;
- $$.offset = $2;
- }
-
-reg:
- sreg
- {
- $$ = nullgen;
- $$.type = D_REG;
- $$.reg = $1;
- }
-
-sreg:
- LREG
-| LR '(' con ')'
- {
- if($$ < 0 || $$ >= NREG)
- print("register value out of range\n");
- $$ = $3;
- }
-
-name:
- con '(' pointer ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.name = $3;
- $$.sym = S;
- $$.offset = $1;
- }
-| LNAME offset '(' pointer ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.name = $4;
- $$.sym = $1;
- $$.offset = $2;
- }
-| LNAME '<' '>' offset '(' LSB ')'
- {
- $$ = nullgen;
- $$.type = D_OREG;
- $$.name = D_STATIC;
- $$.sym = $1;
- $$.offset = $4;
- }
-
-offset:
- {
- $$ = 0;
- }
-| '+' con
- {
- $$ = $2;
- }
-| '-' con
- {
- $$ = -$2;
- }
-
-pointer:
- LSB
-| LSP
-| LFP
-
-con:
- LCONST
-| LVAR
- {
- $$ = $1->value;
- }
-| '-' con
- {
- $$ = -$2;
- }
-| '+' con
- {
- $$ = $2;
- }
-| '~' con
- {
- $$ = ~$2;
- }
-| '(' expr ')'
- {
- $$ = $2;
- }
-
-expr:
- con
-| expr '+' expr
- {
- $$ = $1 + $3;
- }
-| expr '-' expr
- {
- $$ = $1 - $3;
- }
-| expr '*' expr
- {
- $$ = $1 * $3;
- }
-| expr '/' expr
- {
- $$ = $1 / $3;
- }
-| expr '%' expr
- {
- $$ = $1 % $3;
- }
-| expr '<' '<' expr
- {
- $$ = $1 << $4;
- }
-| expr '>' '>' expr
- {
- $$ = $1 >> $4;
- }
-| expr '&' expr
- {
- $$ = $1 & $3;
- }
-| expr '^' expr
- {
- $$ = $1 ^ $3;
- }
-| expr '|' expr
- {
- $$ = $1 | $3;
- }
diff --git a/sys/src/cmd/7a/lex.c b/sys/src/cmd/7a/lex.c
deleted file mode 100644
index 30cfd2417..000000000
--- a/sys/src/cmd/7a/lex.c
+++ /dev/null
@@ -1,694 +0,0 @@
-#include <ctype.h>
-#define EXTERN
-#include "a.h"
-#include "y.tab.h"
-
-void
-main(int argc, char *argv[])
-{
- char ofile[100], incfile[20], *p;
- int nout, nproc, status, i, c, of;
-
- thechar = '7'; /* of 9 */
- thestring = "alpha";
- memset(debug, 0, sizeof(debug));
- cinit();
- outfile = 0;
- include[ninclude++] = ".";
- ARGBEGIN {
- default:
- c = ARGC();
- if(c >= 0 || c < sizeof(debug))
- debug[c] = 1;
- break;
-
- case 'o':
- outfile = ARGF();
- break;
-
- case 'D':
- p = ARGF();
- if(p)
- Dlist[nDlist++] = p;
- break;
-
- case 'I':
- p = ARGF();
- if(p)
- include[ninclude++] = p;
- break;
- } ARGEND
- if(*argv == 0) {
- print("usage: %ca [-options] file.s\n", thechar);
- errorexit();
- }
- nproc = 3;
- if(p = getenv("NPROC"))
- nproc = atol(p);
- if(argc > 1) {
- c = 0;
- nout = 0;
- for(;;) {
- while(nout < nproc && argc > 0) {
- i = fork();
- if(i < 0) {
- i = mywait(&status);
- if(i < 0)
- errorexit();
- if(status)
- c++;
- nout--;
- continue;
- }
- if(i == 0) {
- print("%s:\n", *argv);
- goto child;
- }
- nout++;
- argc--;
- argv++;
- }
- i = mywait(&status);
- if(i < 0) {
- if(c)
- errorexit();
- exits(0);
- }
- if(status)
- c++;
- nout--;
- }
- }
-
-child:
- strecpy(ofile, ofile+sizeof ofile, *argv);
- if(p = strrchr(ofile, '/')) {
- include[0] = ofile;
- *p++ = 0;
- } else
- p = ofile;
- if(outfile == 0) {
- outfile = p;
- if(p = strrchr(outfile, '.'))
- if(p[1] == 's' && p[2] == 0)
- p[0] = 0;
- p = strrchr(outfile, 0);
- p[0] = '.';
- p[1] = thechar;
- p[2] = 0;
- }
- if(0) {
- strcpy(incfile, "/usr/%include");
- p = strrchr(incfile, '%');
- if(p)
- *p = thechar;
- } else {
- strcpy(incfile, "/");
- strcat(incfile, thestring);
- strcat(incfile, "/include");
- }
- include[ninclude++] = incfile;
- if(p = getenv("INCLUDE"))
- include[ninclude-1] = p; /* */
- of = mycreat(outfile, 0664);
- if(of < 0) {
- yyerror("%ca: cannot create %s", thechar, outfile);
- errorexit();
- }
- Binit(&obuf, of, OWRITE);
-
- pass = 1;
- pinit(*argv);
- for(i=0; i<nDlist; i++)
- dodefine(Dlist[i]);
- yyparse();
- if(nerrors) {
- cclean();
- errorexit();
- }
-
- pass = 2;
- outhist();
- pinit(*argv);
- for(i=0; i<nDlist; i++)
- dodefine(Dlist[i]);
- yyparse();
- cclean();
- if(nerrors)
- errorexit();
- exits(0);
-}
-
-struct
-{
- char *name;
- ushort type;
- ushort value;
-} itab[] =
-{
- "SP", LSP, D_AUTO,
- "SB", LSB, D_EXTERN,
- "FP", LFP, D_PARAM,
- "PC", LPC, D_BRANCH,
-
- "R", LR, 0,
- "R0", LREG, 0,
- "R1", LREG, 1,
- "R2", LREG, 2,
- "R3", LREG, 3,
- "R4", LREG, 4,
- "R5", LREG, 5,
- "R6", LREG, 6,
- "R7", LREG, 7,
- "R8", LREG, 8,
- "R9", LREG, 9,
- "R10", LREG, 10,
- "R11", LREG, 11,
- "R12", LREG, 12,
- "R13", LREG, 13,
- "R14", LREG, 14,
- "R15", LREG, 15,
- "R16", LREG, 16,
- "R17", LREG, 17,
- "R18", LREG, 18,
- "R19", LREG, 19,
- "R20", LREG, 20,
- "R21", LREG, 21,
- "R22", LREG, 22,
- "R23", LREG, 23,
- "R24", LREG, 24,
- "R25", LREG, 25,
- "R26", LREG, 26,
- "R27", LREG, 27,
- "R28", LREG, 28,
- "R29", LREG, 29,
- "R30", LREG, 30,
- "R31", LREG, 31,
-
- "P", LP, 0,
- "I", LP, 32,
- "A", LP, 64,
- "IA", LP, 96,
- "T", LP, 128,
- "IT", LP, 32+128,
- "AT", LP, 64+128,
- "IAT", LP, 96+128,
- "T0", LPREG, 0+128,
- "T1", LPREG, 1+128,
- "T2", LPREG, 2+128,
- "T3", LPREG, 3+128,
- "T4", LPREG, 4+128,
- "T5", LPREG, 5+128,
- "T6", LPREG, 6+128,
- "T7", LPREG, 7+128,
- "T8", LPREG, 8+128,
- "T9", LPREG, 9+128,
- "T10", LPREG, 10+128,
- "T11", LPREG, 11+128,
- "T12", LPREG, 12+128,
- "T13", LPREG, 13+128,
- "T14", LPREG, 14+128,
- "T15", LPREG, 15+128,
- "T16", LPREG, 16+128,
- "T17", LPREG, 17+128,
- "T18", LPREG, 18+128,
- "T19", LPREG, 19+128,
- "T20", LPREG, 20+128,
- "T21", LPREG, 21+128,
- "T22", LPREG, 22+128,
- "T23", LPREG, 23+128,
- "T24", LPREG, 24+128,
- "T25", LPREG, 25+128,
- "T26", LPREG, 26+128,
- "T27", LPREG, 27+128,
- "T28", LPREG, 28+128,
- "T29", LPREG, 29+128,
- "T30", LPREG, 30+128,
- "T31", LPREG, 31+128,
-
- "F", LF, 0,
-
- "F0", LFREG, 0,
- "F1", LFREG, 1,
- "F2", LFREG, 2,
- "F3", LFREG, 3,
- "F4", LFREG, 4,
- "F5", LFREG, 5,
- "F6", LFREG, 6,
- "F7", LFREG, 7,
- "F8", LFREG, 8,
- "F9", LFREG, 9,
- "F10", LFREG, 10,
- "F11", LFREG, 11,
- "F12", LFREG, 12,
- "F13", LFREG, 13,
- "F14", LFREG, 14,
- "F15", LFREG, 15,
- "F16", LFREG, 16,
- "F17", LFREG, 17,
- "F18", LFREG, 18,
- "F19", LFREG, 19,
- "F20", LFREG, 20,
- "F21", LFREG, 21,
- "F22", LFREG, 22,
- "F23", LFREG, 23,
- "F24", LFREG, 24,
- "F25", LFREG, 25,
- "F26", LFREG, 26,
- "F27", LFREG, 27,
- "F28", LFREG, 28,
- "F29", LFREG, 29,
- "F30", LFREG, 30,
- "F31", LFREG, 31,
-
- "FPCR", LFPCR, 0,
- "PCC", LPCC, 0,
-
- /* 1: integer operates */
- "ADDQ", LTYPE1, AADDQ,
- "ADDL", LTYPE1, AADDL,
- "SUBL", LTYPE1, ASUBL,
- "SUBQ", LTYPE1, ASUBQ,
- "CMPEQ", LTYPE1, ACMPEQ,
- "CMPGT", LTYPE1, ACMPGT,
- "CMPGE", LTYPE1, ACMPGE,
- "CMPUGT", LTYPE1, ACMPUGT,
- "CMPUGE", LTYPE1, ACMPUGE,
- "CMPBLE", LTYPE1, ACMPBLE,
-
- "AND", LTYPE1, AAND,
- "ANDNOT", LTYPE1, AANDNOT,
- "OR", LTYPE1, AOR,
- "ORNOT", LTYPE1, AORNOT,
- "XOR", LTYPE1, AXOR,
- "XORNOT", LTYPE1, AXORNOT,
-
- "CMOVEQ", LTYPE1, ACMOVEQ,
- "CMOVNE", LTYPE1, ACMOVNE,
- "CMOVLT", LTYPE1, ACMOVLT,
- "CMOVGE", LTYPE1, ACMOVGE,
- "CMOVLE", LTYPE1, ACMOVLE,
- "CMOVGT", LTYPE1, ACMOVGT,
- "CMOVLBS", LTYPE1, ACMOVLBS,
- "CMOVLBC", LTYPE1, ACMOVLBC,
-
- "MULL", LTYPE1, AMULL,
- "MULQ", LTYPE1, AMULQ,
- "UMULH", LTYPE1, AUMULH,
- "DIVQ", LTYPE1, ADIVQ,
- "MODQ", LTYPE1, AMODQ,
- "DIVQU", LTYPE1, ADIVQU,
- "MODQU", LTYPE1, AMODQU,
- "DIVL", LTYPE1, ADIVL,
- "MODL", LTYPE1, AMODL,
- "DIVLU", LTYPE1, ADIVLU,
- "MODLU", LTYPE1, AMODLU,
-
- "SLLQ", LTYPE1, ASLLQ,
- "SRLQ", LTYPE1, ASRLQ,
- "SRAQ", LTYPE1, ASRAQ,
-
- "SLLL", LTYPE1, ASLLL,
- "SRLL", LTYPE1, ASRLL,
- "SRAL", LTYPE1, ASRAL,
-
- "EXTBL", LTYPE1, AEXTBL,
- "EXTWL", LTYPE1, AEXTWL,
- "EXTLL", LTYPE1, AEXTLL,
- "EXTQL", LTYPE1, AEXTQL,
- "EXTWH", LTYPE1, AEXTWH,
- "EXTLH", LTYPE1, AEXTLH,
- "EXTQH", LTYPE1, AEXTQH,
-
- "INSBL", LTYPE1, AINSBL,
- "INSWL", LTYPE1, AINSWL,
- "INSLL", LTYPE1, AINSLL,
- "INSQL", LTYPE1, AINSQL,
- "INSWH", LTYPE1, AINSWH,
- "INSLH", LTYPE1, AINSLH,
- "INSQH", LTYPE1, AINSQH,
-
- "MSKBL", LTYPE1, AMSKBL,
- "MSKWL", LTYPE1, AMSKWL,
- "MSKLL", LTYPE1, AMSKLL,
- "MSKQL", LTYPE1, AMSKQL,
- "MSKWH", LTYPE1, AMSKWH,
- "MSKLH", LTYPE1, AMSKLH,
- "MSKQH", LTYPE1, AMSKQH,
-
- "ZAP", LTYPE1, AZAP,
- "ZAPNOT", LTYPE1, AZAPNOT,
-
- /* 2: floating operates with 2 operands */
- "CVTQS", LTYPE2, ACVTQS,
- "CVTQT", LTYPE2, ACVTQT,
- "CVTTS", LTYPE2, ACVTTS,
- "CVTTQ", LTYPE2, ACVTTQ,
- "CVTLQ", LTYPE2, ACVTLQ,
- "CVTQL", LTYPE2, ACVTQL,
-
- /* 3: floating operates with 2 or 3 operands */
- "CPYS", LTYPE3, ACPYS,
- "CPYSN", LTYPE3, ACPYSN,
- "CPYSE", LTYPE3, ACPYSE,
- "ADDS", LTYPE3, AADDS,
- "ADDT", LTYPE3, AADDT,
- "CMPTEQ", LTYPE3, ACMPTEQ,
- "CMPTGT", LTYPE3, ACMPTGT,
- "CMPTGE", LTYPE3, ACMPTGE,
- "CMPTUN", LTYPE3, ACMPTUN,
- "DIVS", LTYPE3, ADIVS,
- "DIVT", LTYPE3, ADIVT,
- "MULS", LTYPE3, AMULS,
- "MULT", LTYPE3, AMULT,
- "SUBS", LTYPE3, ASUBS,
- "SUBT", LTYPE3, ASUBT,
- "FCMOVEQ", LTYPE3, AFCMOVEQ,
- "FCMOVNE", LTYPE3, AFCMOVNE,
- "FCMOVLT", LTYPE3, AFCMOVLT,
- "FCMOVGE", LTYPE3, AFCMOVGE,
- "FCMOVLE", LTYPE3, AFCMOVLE,
- "FCMOVGT", LTYPE3, AFCMOVGT,
-
- /* 4: integer load/store and reg->reg (incl special regs) */
- "MOVQ", LTYPE4, AMOVQ,
-
- /* 5: integer load/store and reg->reg */
- "MOVL", LTYPE5, AMOVL,
- "MOVQU", LTYPE5, AMOVQU,
- "MOVB", LTYPE5, AMOVB,
- "MOVBU", LTYPE5, AMOVBU,
- "MOVW", LTYPE5, AMOVW,
- "MOVWU", LTYPE5, AMOVWU,
- "MOVLP", LTYPE5, AMOVLP,
- "MOVQP", LTYPE5, AMOVQP,
-
- /* 6: integer load/store (only) */
- "MOVA", LTYPE6, AMOVA,
- "MOVAH", LTYPE6, AMOVAH,
- "MOVLL", LTYPE6, AMOVLL,
- "MOVQL", LTYPE6, AMOVQL,
- "MOVLC", LTYPEK, AMOVLC,
- "MOVQC", LTYPEK, AMOVQC,
-
- /* 7: floating load/store and reg->reg */
- "MOVS", LTYPE7, AMOVS,
- "MOVT", LTYPE7, AMOVT,
-
- /* 8,9: jumps */
- "JMP", LTYPE8, AJMP,
- "JSR", LTYPE8, AJSR,
- "RET", LTYPE9, ARET,
-
- /* A: integer conditional branches */
- "BEQ", LTYPEA, ABEQ,
- "BNE", LTYPEA, ABNE,
- "BLT", LTYPEA, ABLT,
- "BGE", LTYPEA, ABGE,
- "BLE", LTYPEA, ABLE,
- "BGT", LTYPEA, ABGT,
- "BLBC", LTYPEA, ABLBC,
- "BLBS", LTYPEA, ABLBS,
-
- /* B: floating conditional branches */
- "FBEQ", LTYPEB, AFBEQ,
- "FBNE", LTYPEB, AFBNE,
- "FBLT", LTYPEB, AFBLT,
- "FBGE", LTYPEB, AFBGE,
- "FBLE", LTYPEB, AFBLE,
- "FBGT", LTYPEB, AFBGT,
-
- /* C-J: miscellaneous */
- "TRAPB", LTYPEC, ATRAPB,
- "MB", LTYPEC, AMB,
- "REI", LTYPEC, AREI,
- "END", LTYPEC, AEND,
- "FETCH", LTYPED, AFETCH,
- "FETCHM", LTYPED, AFETCHM,
- "CALL_PAL", LTYPEE, ACALL_PAL,
- "TEXT", LTYPEF, ATEXT,
- "GLOBL", LTYPEF, AGLOBL,
- "DATA", LTYPEG, ADATA,
- "WORD", LTYPEH, AWORD,
- "NOP", LTYPEI, ANOP,
- 0
-};
-
-void
-cinit(void)
-{
- Sym *s;
- int i;
-
- nullgen.sym = S;
- nullgen.offset = 0;
- nullgen.type = D_NONE;
- nullgen.name = D_NONE;
- nullgen.reg = NREG;
- if(FPCHIP)
- nullgen.dval = 0;
- for(i=0; i<sizeof(nullgen.sval); i++)
- nullgen.sval[i] = 0;
-
- nerrors = 0;
- iostack = I;
- iofree = I;
- peekc = IGN;
- nhunk = 0;
- for(i=0; i<NHASH; i++)
- hash[i] = S;
- for(i=0; itab[i].name; i++) {
- s = slookup(itab[i].name);
- s->type = itab[i].type;
- s->value = itab[i].value;
- }
-
- ALLOCN(pathname, 0, 100);
- if(getwd(pathname, 99) == 0) {
- ALLOCN(pathname, 100, 900);
- if(getwd(pathname, 999) == 0)
- strcpy(pathname, "/???");
- }
-}
-
-void
-syminit(Sym *s)
-{
-
- s->type = LNAME;
- s->value = 0;
-}
-
-int
-isreg(Gen *g)
-{
-
- USED(g);
- return 1;
-}
-
-void
-cclean(void)
-{
-
- outcode(AEND, &nullgen, NREG, &nullgen);
- Bflush(&obuf);
-}
-
-void
-zname(char *n, int t, int s)
-{
-
- Bputc(&obuf, ANAME);
- Bputc(&obuf, t); /* type */
- Bputc(&obuf, s); /* sym */
- while(*n) {
- Bputc(&obuf, *n);
- n++;
- }
- Bputc(&obuf, 0);
-}
-
-void
-zaddr(Gen *a, int s)
-{
- vlong l;
- int i;
- char *n;
- Ieee e;
-
- Bputc(&obuf, a->type);
- Bputc(&obuf, a->reg);
- Bputc(&obuf, s);
- Bputc(&obuf, a->name);
- switch(a->type) {
- default:
- print("unknown type %d\n", a->type);
- exits("arg");
-
- case D_NONE:
- case D_REG:
- case D_FREG:
- case D_PREG:
- case D_FCREG:
- case D_PCC:
- break;
-
- case D_OREG:
- case D_CONST:
- case D_BRANCH:
- l = a->offset;
- Bputc(&obuf, l);
- Bputc(&obuf, l>>8);
- Bputc(&obuf, l>>16);
- Bputc(&obuf, l>>24);
- Bputc(&obuf, l>>32);
- Bputc(&obuf, l>>40);
- Bputc(&obuf, l>>48);
- Bputc(&obuf, l>>56);
- break;
-
- case D_SCONST:
- n = a->sval;
- for(i=0; i<NSNAME; i++) {
- Bputc(&obuf, *n);
- n++;
- }
- break;
-
- case D_FCONST:
- ieeedtod(&e, a->dval);
- Bputc(&obuf, e.l);
- Bputc(&obuf, e.l>>8);
- Bputc(&obuf, e.l>>16);
- Bputc(&obuf, e.l>>24);
- Bputc(&obuf, e.h);
- Bputc(&obuf, e.h>>8);
- Bputc(&obuf, e.h>>16);
- Bputc(&obuf, e.h>>24);
- break;
- }
-}
-
-void
-outcode(int a, Gen *g1, int reg, Gen *g2)
-{
- int sf, st, t;
- Sym *s;
-
- if(pass == 1)
- goto out;
-jackpot:
- sf = 0;
- s = g1->sym;
- while(s != S) {
- sf = s->sym;
- if(sf < 0 || sf >= NSYM)
- sf = 0;
- t = g1->name;
- if(h[sf].type == t)
- if(h[sf].sym == s)
- break;
- zname(s->name, t, sym);
- s->sym = sym;
- h[sym].sym = s;
- h[sym].type = t;
- sf = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- break;
- }
- st = 0;
- s = g2->sym;
- while(s != S) {
- st = s->sym;
- if(st < 0 || st >= NSYM)
- st = 0;
- t = g2->name;
- if(h[st].type == t)
- if(h[st].sym == s)
- break;
- zname(s->name, t, sym);
- s->sym = sym;
- h[sym].sym = s;
- h[sym].type = t;
- st = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- if(st == sf)
- goto jackpot;
- break;
- }
- Bputc(&obuf, a);
- Bputc(&obuf, reg);
- Bputc(&obuf, lineno);
- Bputc(&obuf, lineno>>8);
- Bputc(&obuf, lineno>>16);
- Bputc(&obuf, lineno>>24);
- zaddr(g1, sf);
- zaddr(g2, st);
-
-out:
- if(a != AGLOBL && a != ADATA)
- pc++;
-}
-
-void
-outhist(void)
-{
- Gen g;
- Hist *h;
- char *p, *q, *op;
- int n;
-
- g = nullgen;
- for(h = hist; h != H; h = h->link) {
- p = h->name;
- op = 0;
- if(p && p[0] != '/' && h->offset == 0 && pathname && pathname[0] == '/') {
- op = p;
- p = pathname;
- }
- while(p) {
- q = strchr(p, '/');
- if(q) {
- n = q-p;
- if(n == 0)
- n = 1; /* leading "/" */
- q++;
- } else {
- n = strlen(p);
- q = 0;
- }
- if(n) {
- Bputc(&obuf, ANAME);
- Bputc(&obuf, D_FILE); /* type */
- Bputc(&obuf, 1); /* sym */
- Bputc(&obuf, '<');
- Bwrite(&obuf, p, n);
- Bputc(&obuf, 0);
- }
- p = q;
- if(p == 0 && op) {
- p = op;
- op = 0;
- }
- }
- g.offset = h->offset;
-
- Bputc(&obuf, AHISTORY);
- Bputc(&obuf, 0);
- Bputc(&obuf, h->line);
- Bputc(&obuf, h->line>>8);
- Bputc(&obuf, h->line>>16);
- Bputc(&obuf, h->line>>24);
- zaddr(&nullgen, 0);
- zaddr(&g, 0);
- }
-}
-
-#include "../cc/lexbody"
-#include "../cc/macbody"
-#include "../cc/compat"
diff --git a/sys/src/cmd/7a/mkfile b/sys/src/cmd/7a/mkfile
deleted file mode 100644
index e48fbea48..000000000
--- a/sys/src/cmd/7a/mkfile
+++ /dev/null
@@ -1,19 +0,0 @@
-</$objtype/mkfile
-
-TARG=7a
-OFILES=\
- y.tab.$O\
- lex.$O\
-
-HFILES=\
- ../7c/7.out.h\
- y.tab.h\
- a.h\
-
-YFILES=a.y\
-
-BIN=/$objtype/bin
-< /sys/src/cmd/mkone
-YFLAGS=-D1 -d
-
-lex.$O: ../cc/macbody ../cc/lexbody
diff --git a/sys/src/cmd/7c/7.out.h b/sys/src/cmd/7c/7.out.h
deleted file mode 100644
index 061890206..000000000
--- a/sys/src/cmd/7c/7.out.h
+++ /dev/null
@@ -1,265 +0,0 @@
-#define NSNAME 8
-#define NSYM 50
-#define NREG 32
-#define NOPROF (1<<0)
-#define DUPOK (1<<1)
-
-enum
-{
- REGRET = 0, /* return register and first temp, grows++ */
- REGARG = 0, /* first arg passed in */
- REGEXT = 15, /* first external register, grows-- */
-
- REGLINK = 26, /* subroutine linkage */
- REGTMP = 27, /* used by the loader */
- REGTMP2 = 28, /* used by the loader */
- REGSB = 29, /* static pointer */
- REGSP = 30, /* stack pointer */
- REGZERO = 31, /* always zero */
-
- FREGRET = 0,
- FREGEXT = 27, /* first external register */
- FREGHALF = 28, /* double */
- FREGONE = 29, /* double */
- FREGTWO = 30, /* double */
- FREGZERO = 31, /* both float and double */
-};
-
-enum as
-{
- AXXX,
- AGOK,
- ATEXT,
- ADATA,
- AGLOBL,
- AHISTORY,
- ANAME,
- AWORD,
-
- ANOP,
-
- AMOVL,
- AMOVLU,
- AMOVQ,
- AMOVQU,
- AMOVS,
- AMOVT,
-
- AMOVB,
- AMOVBU,
- AMOVW,
- AMOVWU,
-
- AMOVA,
- AMOVAH,
-
- AMOVLL,
- AMOVQL,
- AMOVLC,
- AMOVQC,
-
- AMOVQP,
- AMOVLP,
-
- AADDL,
- AADDLV,
- AADDQ,
- AADDQV,
- AS4ADDL,
- AS4ADDQ,
- AS8ADDL,
- AS8ADDQ,
- AS4SUBL,
- AS4SUBQ,
- AS8SUBL,
- AS8SUBQ,
- ASUBL,
- ASUBLV,
- ASUBQ,
- ASUBQV,
-
- ACMPEQ,
- ACMPGT,
- ACMPGE,
- ACMPUGT,
- ACMPUGE,
- ACMPBLE,
-
- AAND,
- AANDNOT,
- AOR,
- AORNOT,
- AXOR,
- AXORNOT,
-
- ACMOVEQ,
- ACMOVNE,
- ACMOVLT,
- ACMOVGE,
- ACMOVLE,
- ACMOVGT,
- ACMOVLBC,
- ACMOVLBS,
-
- AMULL,
- AMULQ,
- AMULLV,
- AMULQV,
- AUMULH,
- ADIVQ,
- AMODQ,
- ADIVQU,
- AMODQU,
- ADIVL,
- AMODL,
- ADIVLU,
- AMODLU,
-
- ASLLQ,
- ASRLQ,
- ASRAQ,
- ASLLL,
- ASRLL,
- ASRAL,
-
- AEXTBL,
- AEXTWL,
- AEXTLL,
- AEXTQL,
- AEXTWH,
- AEXTLH,
- AEXTQH,
-
- AINSBL,
- AINSWL,
- AINSLL,
- AINSQL,
- AINSWH,
- AINSLH,
- AINSQH,
-
- AMSKBL,
- AMSKWL,
- AMSKLL,
- AMSKQL,
- AMSKWH,
- AMSKLH,
- AMSKQH,
-
- AZAP,
- AZAPNOT,
-
- AJMP,
- AJSR,
- ARET,
-
- ABR,
- ABSR,
-
- ABEQ,
- ABNE,
- ABLT,
- ABGE,
- ABLE,
- ABGT,
- ABLBC,
- ABLBS,
-
- AFBEQ,
- AFBNE,
- AFBLT,
- AFBGE,
- AFBLE,
- AFBGT,
-
- ATRAPB,
- AMB,
- AFETCH,
- AFETCHM,
- ARPCC,
-
- ACPYS,
- ACPYSN,
- ACPYSE,
- ACVTLQ,
- ACVTQL,
- AFCMOVEQ,
- AFCMOVNE,
- AFCMOVLT,
- AFCMOVGE,
- AFCMOVLE,
- AFCMOVGT,
-
- AADDS,
- AADDT,
- ACMPTEQ,
- ACMPTGT,
- ACMPTGE,
- ACMPTUN,
- ACVTQS,
- ACVTQT,
- ACVTTS,
- ACVTTQ,
- ADIVS,
- ADIVT,
- AMULS,
- AMULT,
- ASUBS,
- ASUBT,
-
- ACALL_PAL,
- AREI,
-
- AEND,
-
- ADYNT,
- AINIT,
-
- ASIGNAME,
-
- ALAST,
-};
-
-/* type/name */
-enum
-{
- D_GOK = 0,
- D_NONE,
-
-/* name */
- D_EXTERN,
- D_STATIC,
- D_AUTO,
- D_PARAM,
-
-/* type */
- D_BRANCH,
- D_OREG,
- D_CONST,
- D_FCONST,
- D_SCONST,
- D_REG,
- D_FREG,
- D_FCREG,
- D_PREG,
- D_PCC,
- D_FILE,
- D_FILE1,
-};
-
-/*
- * this is the ranlib header
- */
-#define SYMDEF "__.SYMDEF"
-
-/*
- * this is the simulated IEEE floating point
- */
-typedef struct ieee Ieee;
-struct ieee
-{
- long l; /* contains ls-man 0xffffffff */
- long h; /* contains sign 0x80000000
- exp 0x7ff00000
- ms-man 0x000fffff */
-};
diff --git a/sys/src/cmd/7c/cgen.c b/sys/src/cmd/7c/cgen.c
deleted file mode 100644
index f2733a8aa..000000000
--- a/sys/src/cmd/7c/cgen.c
+++ /dev/null
@@ -1,1067 +0,0 @@
-#include "gc.h"
-
-void
-cgen(Node *n, Node *nn)
-{
- Node *l, *r;
- Prog *p1;
- Node nod, nod1, nod2, nod3, nod4;
- int o;
- long v, curs;
-
- if(debug['g']) {
- prtree(nn, "cgen lhs");
- prtree(n, "cgen");
- }
- if(n == Z || n->type == T)
- return;
- if(typesu[n->type->etype]) {
- sugen(n, nn, n->type->width);
- return;
- }
- l = n->left;
- r = n->right;
- o = n->op;
- if(n->addable >= INDEXED) {
- if(nn == Z) {
- switch(o) {
- default:
- nullwarn(Z, Z);
- break;
- case OINDEX:
- nullwarn(l, r);
- break;
- }
- return;
- }
- gmove(n, nn);
- return;
- }
- curs = cursafe;
-
- if(n->complex >= FNX)
- if(l->complex >= FNX)
- if(r != Z && r->complex >= FNX)
- switch(o) {
- default:
- regret(&nod, r);
- cgen(r, &nod);
-
- regsalloc(&nod1, r);
- gopcode(OAS, &nod, Z, &nod1);
-
- regfree(&nod);
- nod = *n;
- nod.right = &nod1;
- cgen(&nod, nn);
- return;
-
- case OFUNC:
- case OCOMMA:
- case OANDAND:
- case OOROR:
- case OCOND:
- case ODOT:
- break;
- }
-
- switch(o) {
- default:
- diag(n, "unknown op in cgen: %O", o);
- break;
-
- case OAS:
- if(l->op == OBIT)
- goto bitas;
- if(l->addable >= INDEXED && l->complex < FNX) {
- if(nn != Z || r->addable < INDEXED) {
- regalloc(&nod, r, nn);
- cgen(r, &nod);
- gmove(&nod, l);
- regfree(&nod);
- } else
- gmove(r, l);
- break;
- }
- if(l->complex >= r->complex) {
- reglcgen(&nod1, l, Z);
- if(r->addable >= INDEXED) {
- gmove(r, &nod1);
- if(nn != Z)
- gmove(r, nn);
- regfree(&nod1);
- break;
- }
- regalloc(&nod, r, nn);
- cgen(r, &nod);
- } else {
- regalloc(&nod, r, nn);
- cgen(r, &nod);
- reglcgen(&nod1, l, Z);
- }
- gmove(&nod, &nod1);
- regfree(&nod);
- regfree(&nod1);
- break;
-
- bitas:
- n = l->left;
- regalloc(&nod, r, nn);
- if(l->complex >= r->complex) {
- reglcgen(&nod1, n, Z);
- cgen(r, &nod);
- } else {
- cgen(r, &nod);
- reglcgen(&nod1, n, Z);
- }
- regalloc(&nod2, n, Z);
- gopcode(OAS, &nod1, Z, &nod2);
- bitstore(l, &nod, &nod1, &nod2, nn);
- break;
-
- case OBIT:
- if(nn == Z) {
- nullwarn(l, Z);
- break;
- }
- bitload(n, &nod, Z, Z, nn);
- gopcode(OAS, &nod, Z, nn);
- regfree(&nod);
- break;
-
- case OADD:
- case OSUB:
- case OAND:
- case OOR:
- case OXOR:
- case OLSHR:
- case OASHL:
- case OASHR:
- case OLDIV:
- case OLMOD:
- case ODIV:
- case OMOD:
- case OMUL:
- case OLMUL:
- /*
- * immediate operands
- */
- if(nn != Z)
- if(r->op == OCONST)
- if(!typefd[n->type->etype]) {
- cgen(l, nn);
- if(r->vconst == 0)
- if(o != OAND)
- break;
- if(nn != Z)
- gopcode(o, r, Z, nn);
- break;
- }
-
- if(nn == Z) {
- nullwarn(l, r);
- break;
- }
-/* if(o == OMUL || o == OLMUL) {
- if(mulcon(n, nn))
- break;
- } */
- if(l->complex >= r->complex) {
- regalloc(&nod, l, nn);
- cgen(l, &nod);
- regalloc(&nod1, l, Z); /* note: l used for type, so shifts work! */
- cgen(r, &nod1);
- gopcode(o, &nod1, Z, &nod);
- } else {
- regalloc(&nod, l, nn); /* note: l used for type, so shifts work! */
- cgen(r, &nod);
- regalloc(&nod1, l, Z);
- cgen(l, &nod1);
- gopcode(o, &nod, &nod1, &nod);
- }
- gopcode(OAS, &nod, Z, nn);
- regfree(&nod);
- regfree(&nod1);
- break;
-
- case OASLSHR:
- case OASASHL:
- case OASASHR:
- case OASAND:
- case OASADD:
- case OASSUB:
- case OASXOR:
- case OASOR:
- case OASLDIV:
- case OASLMOD:
- case OASDIV:
- case OASMOD:
- case OASLMUL:
- case OASMUL:
- if(l->op == OBIT)
- goto asbitop;
- if(r->op == OCONST)
- if(!typefd[r->type->etype])
- if(!typefd[n->type->etype]) {
- if(l->addable < INDEXED)
- reglcgen(&nod2, l, Z);
- else
- nod2 = *l;
- regalloc(&nod, l, nn); /* note: l used for type, so shifts work! */
- gopcode(OAS, &nod2, Z, &nod);
- gopcode(o, r, Z, &nod);
- gopcode(OAS, &nod, Z, &nod2);
-
- regfree(&nod);
- if(l->addable < INDEXED)
- regfree(&nod2);
- break;
- }
-
- if(l->complex >= r->complex) {
- if(l->addable < INDEXED)
- reglcgen(&nod2, l, Z);
- else
- nod2 = *l;
- regalloc(&nod1, r, Z);
- cgen(r, &nod1);
- } else {
- regalloc(&nod1, r, Z);
- cgen(r, &nod1);
- if(l->addable < INDEXED)
- reglcgen(&nod2, l, Z);
- else
- nod2 = *l;
- }
-
- regalloc(&nod, n, nn);
- gmove(&nod2, &nod);
- if(nod1.type->etype != nod.type->etype){
- regalloc(&nod3, &nod, Z);
- gmove(&nod1, &nod3);
- regfree(&nod1);
- nod1 = nod3;
- }
- gopcode(o, &nod1, Z, &nod);
- gmove(&nod, &nod2);
- if(nn != Z)
- gopcode(OAS, &nod, Z, nn);
- regfree(&nod);
- regfree(&nod1);
- if(l->addable < INDEXED)
- regfree(&nod2);
- break;
-
- asbitop:
- regalloc(&nod4, n, nn);
- if(l->complex >= r->complex) {
- bitload(l, &nod, &nod1, &nod2, &nod4);
- regalloc(&nod3, r, Z);
- cgen(r, &nod3);
- } else {
- regalloc(&nod3, r, Z);
- cgen(r, &nod3);
- bitload(l, &nod, &nod1, &nod2, &nod4);
- }
- gmove(&nod, &nod4);
- gopcode(o, &nod3, Z, &nod4);
- regfree(&nod3);
- gmove(&nod4, &nod);
- regfree(&nod4);
- bitstore(l, &nod, &nod1, &nod2, nn);
- break;
-
- case OADDR:
- if(nn == Z) {
- nullwarn(l, Z);
- break;
- }
- lcgen(l, nn);
- break;
-
- case OFUNC:
- if(l->complex >= FNX) {
- if(l->op != OIND)
- diag(n, "bad function call");
-
- regret(&nod, l->left);
- cgen(l->left, &nod);
- regsalloc(&nod1, l->left);
- gopcode(OAS, &nod, Z, &nod1);
- regfree(&nod);
-
- nod = *n;
- nod.left = &nod2;
- nod2 = *l;
- nod2.left = &nod1;
- nod2.complex = 1;
- cgen(&nod, nn);
-
- return;
- }
- if(REGARG != NREG)
- o = reg[REGARG];
- gargs(r, &nod, &nod1);
- if(l->addable < INDEXED) {
- reglcgen(&nod, l, Z);
- gopcode(OFUNC, Z, Z, &nod);
- regfree(&nod);
- } else
- gopcode(OFUNC, Z, Z, l);
- if(REGARG != NREG)
- if(o != reg[REGARG])
- reg[REGARG]--;
- if(nn != Z) {
- regret(&nod, n);
- gopcode(OAS, &nod, Z, nn);
- regfree(&nod);
- }
- break;
-
- case OIND:
- if(nn == Z) {
- nullwarn(l, Z);
- break;
- }
- regialloc(&nod, n, nn);
- r = l;
- while(r->op == OADD)
- r = r->right;
- if(sconst(r)) {
- v = r->vconst;
- r->vconst = 0;
- cgen(l, &nod);
- nod.xoffset += v;
- r->vconst = v;
- } else
- cgen(l, &nod);
- regind(&nod, n);
- gopcode(OAS, &nod, Z, nn);
- regfree(&nod);
- break;
-
- case OEQ:
- case ONE:
- case OLE:
- case OLT:
- case OGE:
- case OGT:
- case OLO:
- case OLS:
- case OHI:
- case OHS:
- if(nn == Z) {
- nullwarn(l, r);
- break;
- }
- boolgen(n, 1, nn);
- break;
-
- case OANDAND:
- case OOROR:
- boolgen(n, 1, nn);
- if(nn == Z)
- patch(p, pc);
- break;
-
- case ONOT:
- if(nn == Z) {
- nullwarn(l, Z);
- break;
- }
- boolgen(n, 1, nn);
- break;
-
- case OCOMMA:
- cgen(l, Z);
- cgen(r, nn);
- break;
-
- case OCAST:
- if(nn == Z) {
- nullwarn(l, Z);
- break;
- }
- /*
- * convert from types l->n->nn
- */
- if(nocast(l->type, n->type)) {
- if(nocast(n->type, nn->type)) {
- cgen(l, nn);
- break;
- }
- }
- regalloc(&nod, l, nn);
- cgen(l, &nod);
- regalloc(&nod1, n, &nod);
- gopcode(OAS, &nod, Z, &nod1);
- gopcode(OAS, &nod1, Z, nn);
- regfree(&nod1);
- regfree(&nod);
- break;
-
- case ODOT:
- sugen(l, nodrat, l->type->width);
- if(nn != Z) {
- warn(n, "non-interruptable temporary");
- nod = *nodrat;
- if(!r || r->op != OCONST) {
- diag(n, "DOT and no offset");
- break;
- }
- nod.xoffset += (long)r->vconst;
- nod.type = n->type;
- cgen(&nod, nn);
- }
- break;
-
- case OCOND:
- bcgen(l, 1);
- p1 = p;
- cgen(r->left, nn);
- gbranch(OGOTO);
- patch(p1, pc);
- p1 = p;
- cgen(r->right, nn);
- patch(p1, pc);
- break;
-
- case OPOSTINC:
- case OPOSTDEC:
- v = 1;
- if(l->type->etype == TIND)
- v = l->type->link->width;
- if(o == OPOSTDEC)
- v = -v;
- if(l->op == OBIT)
- goto bitinc;
- if(nn == Z)
- goto pre;
-
- if(l->addable < INDEXED)
- reglcgen(&nod2, l, Z);
- else
- nod2 = *l;
-
- regalloc(&nod, l, nn);
- gopcode(OAS, &nod2, Z, &nod);
- regalloc(&nod1, l, Z);
- if(typefd[l->type->etype]) {
- regalloc(&nod3, l, Z);
- if(v < 0) {
- gopcode(OAS, nodfconst(-v), Z, &nod3);
- gopcode(OSUB, &nod3, &nod, &nod1);
- } else {
- gopcode(OAS, nodfconst(v), Z, &nod3);
- gopcode(OADD, &nod3, &nod, &nod1);
- }
- regfree(&nod3);
- } else
- gopcode(OADD, nodconst(v), &nod, &nod1);
- gopcode(OAS, &nod1, Z, &nod2);
-
- regfree(&nod);
- regfree(&nod1);
- if(l->addable < INDEXED)
- regfree(&nod2);
- break;
-
- case OPREINC:
- case OPREDEC:
- v = 1;
- if(l->type->etype == TIND)
- v = l->type->link->width;
- if(o == OPREDEC)
- v = -v;
- if(l->op == OBIT)
- goto bitinc;
-
- pre:
- if(l->addable < INDEXED)
- reglcgen(&nod2, l, Z);
- else
- nod2 = *l;
-
- regalloc(&nod, l, nn);
- gopcode(OAS, &nod2, Z, &nod);
- if(typefd[l->type->etype]) {
- regalloc(&nod3, l, Z);
- if(v < 0) {
- gopcode(OAS, nodfconst(-v), Z, &nod3);
- gopcode(OSUB, &nod3, Z, &nod);
- } else {
- gopcode(OAS, nodfconst(v), Z, &nod3);
- gopcode(OADD, &nod3, Z, &nod);
- }
- regfree(&nod3);
- } else
- gopcode(OADD, nodconst(v), Z, &nod);
- gopcode(OAS, &nod, Z, &nod2);
- if(nn && l->op == ONAME) /* in x=++i, emit USED(i) */
- gins(ANOP, l, Z);
-
- regfree(&nod);
- if(l->addable < INDEXED)
- regfree(&nod2);
- break;
-
- bitinc:
- if(nn != Z && (o == OPOSTINC || o == OPOSTDEC)) {
- bitload(l, &nod, &nod1, &nod2, Z);
- gopcode(OAS, &nod, Z, nn);
- gopcode(OADD, nodconst(v), Z, &nod);
- bitstore(l, &nod, &nod1, &nod2, Z);
- break;
- }
- bitload(l, &nod, &nod1, &nod2, nn);
- gopcode(OADD, nodconst(v), Z, &nod);
- bitstore(l, &nod, &nod1, &nod2, nn);
- break;
- }
- cursafe = curs;
- return;
-}
-
-void
-reglcgen(Node *t, Node *n, Node *nn)
-{
- Node *r;
- long v;
-
- regialloc(t, n, nn);
- if(n->op == OIND) {
- r = n->left;
- while(r->op == OADD)
- r = r->right;
- if(sconst(r)) {
- v = r->vconst;
- r->vconst = 0;
- lcgen(n, t);
- t->xoffset += v;
- r->vconst = v;
- regind(t, n);
- return;
- }
- }
- lcgen(n, t);
- regind(t, n);
-}
-
-void
-lcgen(Node *n, Node *nn)
-{
- Prog *p1;
- Node nod;
-
- if(debug['g']) {
- prtree(nn, "lcgen lhs");
- prtree(n, "lcgen");
- }
- if(n == Z || n->type == T)
- return;
- if(nn == Z) {
- nn = &nod;
- regalloc(&nod, n, Z);
- }
- switch(n->op) {
- default:
- if(n->addable < INDEXED) {
- diag(n, "unknown op in lcgen: %O", n->op);
- break;
- }
- nod = *n;
- nod.op = OADDR;
- nod.left = n;
- nod.right = Z;
- nod.type = types[TIND];
- gopcode(OAS, &nod, Z, nn);
- break;
-
- case OCOMMA:
- cgen(n->left, n->left);
- lcgen(n->right, nn);
- break;
-
- case OIND:
- cgen(n->left, nn);
- break;
-
- case OCOND:
- bcgen(n->left, 1);
- p1 = p;
- lcgen(n->right->left, nn);
- gbranch(OGOTO);
- patch(p1, pc);
- p1 = p;
- lcgen(n->right->right, nn);
- patch(p1, pc);
- break;
- }
-}
-
-void
-bcgen(Node *n, int true)
-{
-
- if(n->type == T)
- gbranch(OGOTO);
- else
- boolgen(n, true, Z);
-}
-
-void
-boolgen(Node *n, int true, Node *nn)
-{
- int o;
- Prog *p1, *p2;
- Node *l, *r, nod, nod1;
- long curs;
-
- if(debug['g']) {
- prtree(nn, "boolgen lhs");
- prtree(n, "boolgen");
- }
- curs = cursafe;
- l = n->left;
- r = n->right;
- switch(n->op) {
-
- default:
- regalloc(&nod, n, nn);
- cgen(n, &nod);
- o = ONE;
- if(true)
- o = comrel[relindex(o)];
- if(typefd[n->type->etype]) {
- nodreg(&nod1, n, NREG+FREGZERO);
- gopcode(o, &nod, Z, &nod1);
- } else
- gopcode(o, &nod, Z, nodconst(0));
- regfree(&nod);
- goto com;
-
- case OCONST:
- o = vconst(n);
- if(!true)
- o = !o;
- gbranch(OGOTO);
- if(o) {
- p1 = p;
- gbranch(OGOTO);
- patch(p1, pc);
- }
- goto com;
-
- case OCOMMA:
- cgen(l, Z);
- boolgen(r, true, nn);
- break;
-
- case ONOT:
- boolgen(l, !true, nn);
- break;
-
- case OCOND:
- bcgen(l, 1);
- p1 = p;
- bcgen(r->left, true);
- p2 = p;
- gbranch(OGOTO);
- patch(p1, pc);
- p1 = p;
- bcgen(r->right, !true);
- patch(p2, pc);
- p2 = p;
- gbranch(OGOTO);
- patch(p1, pc);
- patch(p2, pc);
- goto com;
-
- case OANDAND:
- if(!true)
- goto caseor;
-
- caseand:
- bcgen(l, true);
- p1 = p;
- bcgen(r, !true);
- p2 = p;
- patch(p1, pc);
- gbranch(OGOTO);
- patch(p2, pc);
- goto com;
-
- case OOROR:
- if(!true)
- goto caseand;
-
- caseor:
- bcgen(l, !true);
- p1 = p;
- bcgen(r, !true);
- p2 = p;
- gbranch(OGOTO);
- patch(p1, pc);
- patch(p2, pc);
- goto com;
-
- case OEQ:
- case ONE:
- case OLE:
- case OLT:
- case OGE:
- case OGT:
- case OHI:
- case OHS:
- case OLO:
- case OLS:
- o = n->op;
- if(true)
- o = comrel[relindex(o)];
- if(l->complex >= FNX && r->complex >= FNX) {
- regret(&nod, r);
- cgen(r, &nod);
- regsalloc(&nod1, r);
- gopcode(OAS, &nod, Z, &nod1);
- regfree(&nod);
- nod = *n;
- nod.right = &nod1;
- boolgen(&nod, true, nn);
- break;
- }
- if(bconst(r)) {
- regalloc(&nod, l, nn);
- cgen(l, &nod);
- gopcode(o, &nod, Z, r);
- regfree(&nod);
- goto com;
- }
- if(l->complex >= r->complex) {
- regalloc(&nod1, l, nn);
- cgen(l, &nod1);
- regalloc(&nod, r, Z);
- cgen(r, &nod);
- } else {
- regalloc(&nod, r, nn);
- cgen(r, &nod);
- regalloc(&nod1, l, Z);
- cgen(l, &nod1);
- }
- gopcode(o, &nod1, Z, &nod);
- regfree(&nod);
- regfree(&nod1);
-
- com:
- if(nn != Z) {
- p1 = p;
- gopcode(OAS, nodconst(1), Z, nn);
- gbranch(OGOTO);
- p2 = p;
- patch(p1, pc);
- gopcode(OAS, nodconst(0), Z, nn);
- patch(p2, pc);
- }
- break;
- }
- cursafe = curs;
-}
-
-void
-sugen(Node *n, Node *nn, long w)
-{
- Prog *p1;
- Node nod0, nod1, nod2, nod3, nod4, *l, *r;
- Type *t;
- long pc1;
- int i, m, c;
-
- if(n == Z || n->type == T)
- return;
- if(debug['g']) {
- prtree(nn, "sugen lhs");
- prtree(n, "sugen");
- }
- if(nn == nodrat)
- if(w > nrathole)
- nrathole = w;
- switch(n->op) {
- case OIND:
- if(nn == Z) {
- nullwarn(n->left, Z);
- break;
- }
-
- default:
- goto copy;
-
- case ODOT:
- l = n->left;
- sugen(l, nodrat, l->type->width);
- if(nn != Z) {
- warn(n, "non-interruptable temporary");
- nod1 = *nodrat;
- r = n->right;
- if(!r || r->op != OCONST) {
- diag(n, "DOT and no offset");
- break;
- }
- nod1.xoffset += (long)r->vconst;
- nod1.type = n->type;
- sugen(&nod1, nn, w);
- }
- break;
-
- case OSTRUCT:
- /*
- * rewrite so lhs has no fn call
- */
- if(nn != Z && nn->complex >= FNX) {
- nod1 = *n;
- nod1.type = typ(TIND, n->type);
- regret(&nod2, &nod1);
- lcgen(nn, &nod2);
- regsalloc(&nod0, &nod1);
- gopcode(OAS, &nod2, Z, &nod0);
- regfree(&nod2);
-
- nod1 = *n;
- nod1.op = OIND;
- nod1.left = &nod0;
- nod1.right = Z;
- nod1.complex = 1;
-
- sugen(n, &nod1, w);
- return;
- }
-
- r = n->left;
- for(t = n->type->link; t != T; t = t->down) {
- l = r;
- if(r->op == OLIST) {
- l = r->left;
- r = r->right;
- }
- if(nn == Z) {
- cgen(l, nn);
- continue;
- }
- /*
- * hand craft *(&nn + o) = l
- */
- nod0 = znode;
- nod0.op = OAS;
- nod0.type = t;
- nod0.left = &nod1;
- nod0.right = l;
-
- nod1 = znode;
- nod1.op = OIND;
- nod1.type = t;
- nod1.left = &nod2;
-
- nod2 = znode;
- nod2.op = OADD;
- nod2.type = typ(TIND, t);
- nod2.left = &nod3;
- nod2.right = &nod4;
-
- nod3 = znode;
- nod3.op = OADDR;
- nod3.type = nod2.type;
- nod3.left = nn;
-
- nod4 = znode;
- nod4.op = OCONST;
- nod4.type = nod2.type;
- nod4.vconst = t->offset;
-
- ccom(&nod0);
- acom(&nod0);
- xcom(&nod0);
- nod0.addable = 0;
-
- /* prtree(&nod0, "hand craft"); /* */
- cgen(&nod0, Z);
- }
- break;
-
- case OAS:
- if(nn == Z) {
- if(n->addable < INDEXED)
- sugen(n->right, n->left, w);
- break;
- }
- sugen(n->right, nodrat, w);
- warn(n, "non-interruptable temporary");
- sugen(nodrat, n->left, w);
- sugen(nodrat, nn, w);
- break;
-
- case OFUNC:
- if(nn == Z) {
- sugen(n, nodrat, w);
- break;
- }
- if(nn->op != OIND) {
- nn = new1(OADDR, nn, Z);
- nn->type = types[TIND];
- nn->addable = 0;
- } else
- nn = nn->left;
- n = new(OFUNC, n->left, new(OLIST, nn, n->right));
- n->type = types[TVOID];
- n->left->type = types[TVOID];
- cgen(n, Z);
- break;
-
- case OCOND:
- bcgen(n->left, 1);
- p1 = p;
- sugen(n->right->left, nn, w);
- gbranch(OGOTO);
- patch(p1, pc);
- p1 = p;
- sugen(n->right->right, nn, w);
- patch(p1, pc);
- break;
-
- case OCOMMA:
- cgen(n->left, Z);
- sugen(n->right, nn, w);
- break;
- }
- return;
-
-copy:
- if(nn == Z)
- return;
- if(n->complex >= FNX && nn->complex >= FNX) {
- t = nn->type;
- nn->type = types[TLONG];
- regialloc(&nod1, nn, Z);
- lcgen(nn, &nod1);
- regsalloc(&nod2, nn);
- nn->type = t;
-
- gopcode(OAS, &nod1, Z, &nod2);
- regfree(&nod1);
-
- nod2.type = typ(TIND, t);
-
- nod1 = nod2;
- nod1.op = OIND;
- nod1.left = &nod2;
- nod1.right = Z;
- nod1.complex = 1;
- nod1.type = t;
-
- sugen(n, &nod1, w);
- return;
- }
-
- if(n->complex > nn->complex) {
- t = n->type;
- n->type = types[TLONG];
- reglcgen(&nod1, n, Z);
- n->type = t;
-
- t = nn->type;
- nn->type = types[TLONG];
- reglcgen(&nod2, nn, Z);
- nn->type = t;
- } else {
- t = nn->type;
- nn->type = types[TLONG];
- reglcgen(&nod2, nn, Z);
- nn->type = t;
-
- t = n->type;
- n->type = types[TLONG];
- reglcgen(&nod1, n, Z);
- n->type = t;
- }
-
- w /= SZ_LONG;
- if(w <= 5) {
- layout(&nod1, &nod2, w, 0, Z);
- goto out;
- }
-
- /*
- * minimize space for unrolling loop
- * 3,4,5 times. (6 or more is never minimum)
- * if small structure, try 2 also.
- */
- c = 0; /* set */
- m = 100;
- i = 3;
- if(w <= 15)
- i = 2;
- for(; i<=5; i++)
- if(i + w%i <= m) {
- c = i;
- m = c + w%c;
- }
-
- regalloc(&nod3, &regnode, Z);
- layout(&nod1, &nod2, w%c, w/c, &nod3);
-
- pc1 = pc;
- layout(&nod1, &nod2, c, 0, Z);
-
- gopcode(OSUB, nodconst(1), Z, &nod3);
- nod1.op = OREGISTER;
- gopcode(OADD, nodconst(c*SZ_LONG), Z, &nod1);
- nod2.op = OREGISTER;
- gopcode(OADD, nodconst(c*SZ_LONG), Z, &nod2);
-
- gopcode(OGT, &nod3, Z, nodconst(0));
- patch(p, pc1);
-
- regfree(&nod3);
-out:
- regfree(&nod1);
- regfree(&nod2);
-}
-
-void
-layout(Node *f, Node *t, int c, int cv, Node *cn)
-{
- Node t1, t2;
-
- while(c > 3) {
- layout(f, t, 2, 0, Z);
- c -= 2;
- }
-
- regalloc(&t1, &regnode, Z);
- regalloc(&t2, &regnode, Z);
- if(c > 0) {
- gopcode(OAS, f, Z, &t1);
- f->xoffset += SZ_LONG;
- }
- if(cn != Z)
- gopcode(OAS, nodconst(cv), Z, cn);
- if(c > 1) {
- gopcode(OAS, f, Z, &t2);
- f->xoffset += SZ_LONG;
- }
- if(c > 0) {
- gopcode(OAS, &t1, Z, t);
- t->xoffset += SZ_LONG;
- }
- if(c > 2) {
- gopcode(OAS, f, Z, &t1);
- f->xoffset += SZ_LONG;
- }
- if(c > 1) {
- gopcode(OAS, &t2, Z, t);
- t->xoffset += SZ_LONG;
- }
- if(c > 2) {
- gopcode(OAS, &t1, Z, t);
- t->xoffset += SZ_LONG;
- }
- regfree(&t1);
- regfree(&t2);
-}
diff --git a/sys/src/cmd/7c/enam.c b/sys/src/cmd/7c/enam.c
deleted file mode 100644
index 1e4c6a06d..000000000
--- a/sys/src/cmd/7c/enam.c
+++ /dev/null
@@ -1,165 +0,0 @@
-char* anames[] =
-{
- "XXX",
- "GOK",
- "TEXT",
- "DATA",
- "GLOBL",
- "HISTORY",
- "NAME",
- "WORD",
- "NOP",
- "MOVL",
- "MOVLU",
- "MOVQ",
- "MOVQU",
- "MOVS",
- "MOVT",
- "MOVB",
- "MOVBU",
- "MOVW",
- "MOVWU",
- "MOVA",
- "MOVAH",
- "MOVLL",
- "MOVQL",
- "MOVLC",
- "MOVQC",
- "MOVQP",
- "MOVLP",
- "ADDL",
- "ADDLV",
- "ADDQ",
- "ADDQV",
- "S4ADDL",
- "S4ADDQ",
- "S8ADDL",
- "S8ADDQ",
- "S4SUBL",
- "S4SUBQ",
- "S8SUBL",
- "S8SUBQ",
- "SUBL",
- "SUBLV",
- "SUBQ",
- "SUBQV",
- "CMPEQ",
- "CMPGT",
- "CMPGE",
- "CMPUGT",
- "CMPUGE",
- "CMPBLE",
- "AND",
- "ANDNOT",
- "OR",
- "ORNOT",
- "XOR",
- "XORNOT",
- "CMOVEQ",
- "CMOVNE",
- "CMOVLT",
- "CMOVGE",
- "CMOVLE",
- "CMOVGT",
- "CMOVLBC",
- "CMOVLBS",
- "MULL",
- "MULQ",
- "MULLV",
- "MULQV",
- "UMULH",
- "DIVQ",
- "MODQ",
- "DIVQU",
- "MODQU",
- "DIVL",
- "MODL",
- "DIVLU",
- "MODLU",
- "SLLQ",
- "SRLQ",
- "SRAQ",
- "SLLL",
- "SRLL",
- "SRAL",
- "EXTBL",
- "EXTWL",
- "EXTLL",
- "EXTQL",
- "EXTWH",
- "EXTLH",
- "EXTQH",
- "INSBL",
- "INSWL",
- "INSLL",
- "INSQL",
- "INSWH",
- "INSLH",
- "INSQH",
- "MSKBL",
- "MSKWL",
- "MSKLL",
- "MSKQL",
- "MSKWH",
- "MSKLH",
- "MSKQH",
- "ZAP",
- "ZAPNOT",
- "JMP",
- "JSR",
- "RET",
- "BR",
- "BSR",
- "BEQ",
- "BNE",
- "BLT",
- "BGE",
- "BLE",
- "BGT",
- "BLBC",
- "BLBS",
- "FBEQ",
- "FBNE",
- "FBLT",
- "FBGE",
- "FBLE",
- "FBGT",
- "TRAPB",
- "MB",
- "FETCH",
- "FETCHM",
- "RPCC",
- "CPYS",
- "CPYSN",
- "CPYSE",
- "CVTLQ",
- "CVTQL",
- "FCMOVEQ",
- "FCMOVNE",
- "FCMOVLT",
- "FCMOVGE",
- "FCMOVLE",
- "FCMOVGT",
- "ADDS",
- "ADDT",
- "CMPTEQ",
- "CMPTGT",
- "CMPTGE",
- "CMPTUN",
- "CVTQS",
- "CVTQT",
- "CVTTS",
- "CVTTQ",
- "DIVS",
- "DIVT",
- "MULS",
- "MULT",
- "SUBS",
- "SUBT",
- "CALL_PAL",
- "REI",
- "END",
- "DYNT",
- "INIT",
- "LAST",
-};
diff --git a/sys/src/cmd/7c/gc.h b/sys/src/cmd/7c/gc.h
deleted file mode 100644
index f41384bd4..000000000
--- a/sys/src/cmd/7c/gc.h
+++ /dev/null
@@ -1,343 +0,0 @@
-#include "../cc/cc.h"
-#include "../7c/7.out.h"
-
-/*
- * 7c/alpha
- * DEC Alpha
- */
-#define SZ_CHAR 1
-#define SZ_SHORT 2
-#define SZ_INT 4
-#define SZ_LONG 4
-#define SZ_IND 4
-#define SZ_FLOAT 4
-#define SZ_VLONG 8
-#define SZ_DOUBLE 8
-#define FNX 100
-
-typedef struct Adr Adr;
-typedef struct Prog Prog;
-typedef struct Case Case;
-typedef struct C1 C1;
-typedef struct Multab Multab;
-typedef struct Hintab Hintab;
-typedef struct Bits Bits;
-typedef struct Var Var;
-typedef struct Reg Reg;
-typedef struct Rgn Rgn;
-
-struct Adr
-{
- union
- {
- vlong offset;
- double dval;
- char sval[NSNAME];
- Ieee ieee;
- };
- Sym* sym;
- char type;
- char reg;
- char name;
- char etype;
-};
-#define A ((Adr*)0)
-
-#define INDEXED 9
-struct Prog
-{
- Adr from;
- Adr to;
- Prog* link;
- long lineno;
- uchar as;
- char reg;
-};
-#define P ((Prog*)0)
-
-struct Case
-{
- Case* link;
- vlong val;
- long label;
- char def;
- char isv;
-};
-#define C ((Case*)0)
-
-struct C1
-{
- vlong val;
- long label;
-};
-
-struct Multab
-{
- long val;
- char code[20];
-};
-
-struct Hintab
-{
- ushort val;
- char hint[10];
-};
-
-struct Var
-{
- vlong offset;
- Sym* sym;
- char name;
- char etype;
-};
-
-struct Reg
-{
- long pc;
- long rpo; /* reverse post ordering */
-
- Bits set;
- Bits use1;
- Bits use2;
-
- Bits refbehind;
- Bits refahead;
- Bits calbehind;
- Bits calahead;
- Bits regdiff;
- Bits act;
-
- long regu;
- long loop; /* could be shorter */
-
- union
- {
- Reg* log5;
- long active;
- };
- Reg* p1;
- Reg* p2;
- Reg* p2link;
- Reg* s1;
- Reg* s2;
- Reg* link;
- Prog* prog;
-};
-#define R ((Reg*)0)
-
-#define NRGN 600
-struct Rgn
-{
- Reg* enter;
- short cost;
- short varno;
- short regno;
-};
-
-EXTERN long breakpc;
-EXTERN long nbreak;
-EXTERN Case* cases;
-EXTERN Node constnode;
-EXTERN Node fconstnode;
-EXTERN long continpc;
-EXTERN long curarg;
-EXTERN long cursafe;
-EXTERN Prog* firstp;
-EXTERN Prog* lastp;
-EXTERN long maxargsafe;
-EXTERN int mnstring;
-EXTERN Multab multab[20];
-EXTERN int hintabsize;
-EXTERN Node* nodrat;
-EXTERN Node* nodret;
-EXTERN Node* nodsafe;
-EXTERN long nrathole;
-EXTERN long nstring;
-EXTERN Prog* p;
-EXTERN long pc;
-EXTERN Node regnode;
-EXTERN char string[NSNAME];
-EXTERN Sym* symrathole;
-EXTERN Node znode;
-EXTERN Prog zprog;
-EXTERN char reg[NREG+NREG];
-EXTERN long exregoffset;
-EXTERN long exfregoffset;
-
-#define BLOAD(r) band(bnot(r->refbehind), r->refahead)
-#define BSTORE(r) band(bnot(r->calbehind), r->calahead)
-#define LOAD(r) (~r->refbehind.b[z] & r->refahead.b[z])
-#define STORE(r) (~r->calbehind.b[z] & r->calahead.b[z])
-
-#define bset(a,n) ((a).b[(n)/32]&(1L<<(n)%32))
-
-#define CLOAD 4
-#define CREF 5
-#define CINF 1000
-#define LOOP 3
-
-EXTERN Rgn region[NRGN];
-EXTERN Rgn* rgp;
-EXTERN int nregion;
-EXTERN int nvar;
-
-EXTERN Bits externs;
-EXTERN Bits params;
-EXTERN Bits consts;
-EXTERN Bits addrs;
-EXTERN Bits zbits;
-
-EXTERN long regbits;
-EXTERN long exregbits;
-
-EXTERN int change;
-EXTERN int suppress;
-
-EXTERN Reg* firstr;
-EXTERN Reg* lastr;
-EXTERN Reg zreg;
-EXTERN Reg* freer;
-EXTERN Var var[NVAR];
-EXTERN long* idom;
-EXTERN Reg** rpo2r;
-EXTERN long maxnr;
-
-extern char* anames[];
-extern Hintab hintab[];
-
-/*
- * sgen.c
- */
-void codgen(Node*, Node*);
-void gen(Node*);
-void usedset(Node*, int);
-void noretval(int);
-void xcom(Node*);
-int bcomplex(Node*, Node*);
-
-/*
- * cgen.c
- */
-void cgen(Node*, Node*);
-void reglcgen(Node*, Node*, Node*);
-void lcgen(Node*, Node*);
-void bcgen(Node*, int);
-void boolgen(Node*, int, Node*);
-void sugen(Node*, Node*, long);
-void layout(Node*, Node*, int, int, Node*);
-
-/*
- * txt.c
- */
-void ginit(void);
-void gclean(void);
-void nextpc(void);
-void gargs(Node*, Node*, Node*);
-void garg1(Node*, Node*, Node*, int, Node**);
-Node* nodconst(long);
-Node* nod32const(vlong);
-Node* nodfconst(double);
-void nodreg(Node*, Node*, int);
-void regret(Node*, Node*);
-void regalloc(Node*, Node*, Node*);
-void regfree(Node*);
-void regialloc(Node*, Node*, Node*);
-void regsalloc(Node*, Node*);
-void regaalloc1(Node*, Node*);
-void regaalloc(Node*, Node*);
-void regind(Node*, Node*);
-void gprep(Node*, Node*);
-void raddr(Node*, Prog*);
-void naddr(Node*, Adr*);
-void gmove(Node*, Node*);
-void gins(int a, Node*, Node*);
-void gopcode(int, Node*, Node*, Node*);
-int samaddr(Node*, Node*);
-void gbranch(int);
-void patch(Prog*, long);
-int bconst(Node*);
-int sconst(Node*);
-int bval(vlong);
-int sval(long);
-void gpseudo(int, Sym*, Node*);
-
-/*
- * swt.c
- */
-int swcmp(void*, void*);
-void doswit(Node*);
-void swit1(C1*, int, long, Node*);
-void swit2(C1*, int, long, Node*, Node*);
-void casf(void);
-void bitload(Node*, Node*, Node*, Node*, Node*);
-void bitstore(Node*, Node*, Node*, Node*, Node*);
-long outstring(char*, long);
-int vlog(Node*);
-int mulcon(Node*, Node*);
-Multab* mulcon0(long);
-void nullwarn(Node*, Node*);
-void sextern(Sym*, Node*, long, long);
-void gextern(Sym*, Node*, long, long);
-void outcode(void);
-void ieeedtod(Ieee*, double);
-
-/*
- * list
- */
-void listinit(void);
-int Pconv(Fmt*);
-int Aconv(Fmt*);
-int Dconv(Fmt*);
-int Sconv(Fmt*);
-int Nconv(Fmt*);
-int Bconv(Fmt*);
-
-/*
- * reg.c
- */
-Reg* rega(void);
-int rcmp(void*, void*);
-void regopt(Prog*);
-void addmove(Reg*, int, int, int);
-Bits mkvar(Adr*, int);
-void prop(Reg*, Bits, Bits);
-void loopit(Reg*, long);
-void synch(Reg*, Bits);
-ulong allreg(ulong, Rgn*);
-void paint1(Reg*, int);
-ulong paint2(Reg*, int);
-void paint3(Reg*, int, long, int);
-void addreg(Adr*, int);
-
-/*
- * peep.c
- */
-void peep(void);
-void excise(Reg*);
-Reg* uniqp(Reg*);
-Reg* uniqs(Reg*);
-int regtyp(Adr*);
-int regzer(Adr*);
-int anyvar(Adr*);
-int subprop(Reg*);
-int copyprop(Reg*);
-int copy1(Adr*, Adr*, Reg*, int);
-int copyu(Prog*, Adr*, Adr*);
-
-int copyas(Adr*, Adr*);
-int copyau(Adr*, Adr*);
-int copyau1(Prog*, Adr*);
-int copysub(Adr*, Adr*, Adr*, int);
-int copysub1(Prog*, Adr*, Adr*, int);
-
-long RtoB(int);
-long FtoB(int);
-int BtoR(long);
-int BtoF(long);
-
-#pragma varargck type "A" int
-#pragma varargck type "B" Bits
-#pragma varargck type "D" Adr*
-#pragma varargck type "N" Adr*
-#pragma varargck type "P" Prog*
-#pragma varargck type "S" char*
diff --git a/sys/src/cmd/7c/list.c b/sys/src/cmd/7c/list.c
deleted file mode 100644
index c2ebdbf1f..000000000
--- a/sys/src/cmd/7c/list.c
+++ /dev/null
@@ -1,231 +0,0 @@
-#define EXTERN
-#include "gc.h"
-
-void
-listinit(void)
-{
-
- fmtinstall('A', Aconv);
- fmtinstall('P', Pconv);
- fmtinstall('S', Sconv);
- fmtinstall('N', Nconv);
- fmtinstall('B', Bconv);
- fmtinstall('D', Dconv);
-}
-
-int
-Bconv(Fmt *fp)
-{
- char str[STRINGSZ], ss[STRINGSZ], *s;
- Bits bits;
- int i;
-
- memset(str, 0, sizeof str);
- bits = va_arg(fp->args, Bits);
- while(bany(&bits)) {
- i = bnum(bits);
- if(str[0])
- strncat(str, " ", sizeof str - 1);
- if(var[i].sym == S) {
- snprint(ss, sizeof ss, "$%lld", var[i].offset);
- s = ss;
- } else
- s = var[i].sym->name;
- strncat(str, s, sizeof str - 1);
- bits.b[i/32] &= ~(1L << (i%32));
- }
- return fmtstrcpy(fp, str);
-}
-
-int
-Pconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Prog *p;
- int a;
-
- p = va_arg(fp->args, Prog*);
- a = p->as;
- if(a == ADATA)
- snprint(str, sizeof str, " %A %D/%d,%D", a, &p->from, p->reg, &p->to);
- else
- if(p->as == ATEXT)
- snprint(str, sizeof str, " %A %D,%d,%D", a, &p->from, p->reg, &p->to);
- else
- if(p->reg == NREG)
- snprint(str, sizeof str, " %A %D,%D", a, &p->from, &p->to);
- else
- if(p->from.type != D_FREG)
- snprint(str, sizeof str, " %A %D,R%d,%D", a, &p->from, p->reg, &p->to);
- else
- snprint(str, sizeof str, " %A %D,F%d,%D", a, &p->from, p->reg, &p->to);
- return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
- char *s;
- int a;
-
- a = va_arg(fp->args, int);
- s = "???";
- if(a >= AXXX && a < ALAST)
- s = anames[a];
- return fmtstrcpy(fp, s);
-}
-
-int
-Dconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
-
- a = va_arg(fp->args, Adr*);
- switch(a->type) {
-
- default:
- snprint(str, sizeof str, "GOK-type(%d)", a->type);
- break;
-
- case D_NONE:
- str[0] = 0;
- if(a->name != D_NONE || a->reg != NREG || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(NONE)", a, a->reg);
- break;
-
- case D_CONST:
- if(a->reg != NREG)
- snprint(str, sizeof str, "$%N(R%d)", a, a->reg);
- else
- snprint(str, sizeof str, "$%N", a);
- break;
-
- case D_OREG:
- if(a->reg != NREG)
- snprint(str, sizeof str, "%N(R%d)", a, a->reg);
- else
- snprint(str, sizeof str, "%N", a);
- break;
-
- case D_REG:
- snprint(str, sizeof str, "R%d", a->reg);
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
- break;
-
- case D_FREG:
- snprint(str, sizeof str, "F%d", a->reg);
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
- break;
-
- case D_FCREG:
- snprint(str, sizeof str, "FPCR");
- if(a->reg != 0 || a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(FPCR%d)(REG)", a, a->reg);
- break;
-
- case D_BRANCH:
- snprint(str, sizeof str, "%lld(PC)", a->offset-pc);
- break;
-
- case D_FCONST:
- snprint(str, sizeof str, "$%.17e", a->dval);
- break;
-
- case D_SCONST:
- snprint(str, sizeof str, "$\"%S\"", a->sval);
- break;
- }
- return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
- int i, c;
- char str[STRINGSZ], *p, *a;
-
- a = va_arg(fp->args, char*);
- p = str;
- for(i=0; i<NSNAME; i++) {
- c = a[i] & 0xff;
- if(c >= 'a' && c <= 'z' ||
- c >= 'A' && c <= 'Z' ||
- c >= '0' && c <= '9' ||
- c == ' ' || c == '%') {
- *p++ = c;
- continue;
- }
- *p++ = '\\';
- switch(c) {
- case 0:
- *p++ = 'z';
- continue;
- case '\\':
- case '"':
- *p++ = c;
- continue;
- case '\n':
- *p++ = 'n';
- continue;
- case '\t':
- *p++ = 't';
- continue;
- case '\r':
- *p++ = 'r';
- continue;
- case '\f':
- *p++ = 'f';
- continue;
- }
- *p++ = (c>>6) + '0';
- *p++ = ((c>>3) & 7) + '0';
- *p++ = (c & 7) + '0';
- }
- *p = 0;
- return fmtstrcpy(fp, str);
-}
-
-int
-Nconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- Sym *s;
-
- a = va_arg(fp->args, Adr*);
- s = a->sym;
- if(s == S) {
- snprint(str, sizeof str, "%lld", a->offset);
- goto out;
- }
- switch(a->name) {
- default:
- snprint(str, sizeof str, "GOK-name(%d)", a->name);
- break;
-
- case D_NONE:
- snprint(str, sizeof str, "%lld", a->offset);
- break;
-
- case D_EXTERN:
- snprint(str, sizeof str, "%s+%lld(SB)", s->name, a->offset);
- break;
-
- case D_STATIC:
- snprint(str, sizeof str, "%s<>+%lld(SB)", s->name, a->offset);
- break;
-
- case D_AUTO:
- snprint(str, sizeof str, "%s-%lld(SP)", s->name, -a->offset);
- break;
-
- case D_PARAM:
- snprint(str, sizeof str, "%s+%lld(FP)", s->name, a->offset);
- break;
- }
-out:
- return fmtstrcpy(fp, str);
-}
diff --git a/sys/src/cmd/7c/machcap.c b/sys/src/cmd/7c/machcap.c
deleted file mode 100644
index 79f4d67d7..000000000
--- a/sys/src/cmd/7c/machcap.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "gc.h"
-
-int
-machcap(Node *n)
-{
- if(n == Z) /* test */
- return 1;
- return 0;
-}
diff --git a/sys/src/cmd/7c/mkenam b/sys/src/cmd/7c/mkenam
deleted file mode 100644
index a1eca4316..000000000
--- a/sys/src/cmd/7c/mkenam
+++ /dev/null
@@ -1,15 +0,0 @@
-ed - ../7c/7.out.h <<'!'
-v/^ A/d
-,s/^ A/ "/
-g/ .*$/s///
-,s/,*$/",/
-1i
-char* anames[] =
-{
-.
-$a
-};
-.
-w enam.c
-Q
-!
diff --git a/sys/src/cmd/7c/mkfile b/sys/src/cmd/7c/mkfile
deleted file mode 100644
index f749eef90..000000000
--- a/sys/src/cmd/7c/mkfile
+++ /dev/null
@@ -1,39 +0,0 @@
-</$objtype/mkfile
-
-TARG=7c
-OFILES=\
- cgen.$O\
- enam.$O\
- list.$O\
- machcap.$O\
- peep.$O\
- pgen.$O\
- pswt.$O\
- reg.$O\
- sgen.$O\
- swt.$O\
- txt.$O\
- mul.$O\
-
-HFILES=\
- gc.h\
- 7.out.h\
- ../cc/cc.h\
-
-LIB=../cc/cc.a$O
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-$LIB:
- cd ../cc
- mk install
- mk clean
-
-%.$O: ../cc/%.c
- $CC $CFLAGS ../cc/$stem.c
-
-t:V: $O.out
- $O.out -S t
- $LD -o t.out t.$O
- t.out
diff --git a/sys/src/cmd/7c/mul.c b/sys/src/cmd/7c/mul.c
deleted file mode 100644
index 3ef56cd56..000000000
--- a/sys/src/cmd/7c/mul.c
+++ /dev/null
@@ -1,608 +0,0 @@
-#include "gc.h"
-
-/*
- * code sequences for multiply by constant.
- * [a-l][0-3]
- * lsl $(A-'a'),r0,r1
- * [+][0-7]
- * add r0,r1,r2
- * [-][0-7]
- * sub r0,r1,r2
- */
-
-static int multabp;
-static long mulval;
-static char* mulcp;
-static long valmax;
-static int shmax;
-
-static int docode(char *hp, char *cp, int r0, int r1);
-static int gen1(int len);
-static int gen2(int len, long r1);
-static int gen3(int len, long r0, long r1, int flag);
-enum
-{
- SR1 = 1<<0, /* r1 has been shifted */
- SR0 = 1<<1, /* r0 has been shifted */
- UR1 = 1<<2, /* r1 has not been used */
- UR0 = 1<<3, /* r0 has not been used */
-};
-
-Multab*
-mulcon0(long v)
-{
- int a1, a2, g;
- Multab *m, *m1;
- char hint[10];
-
- if(v < 0)
- v = -v;
-
- /*
- * look in cache
- */
- m = multab;
- for(g=0; g<nelem(multab); g++) {
- if(m->val == v) {
- if(m->code[0] == 0)
- return 0;
- return m;
- }
- m++;
- }
-
- /*
- * select a spot in cache to overwrite
- */
- multabp++;
- if(multabp < 0 || multabp >= nelem(multab))
- multabp = 0;
- m = multab+multabp;
- m->val = v;
- mulval = v;
-
- /*
- * look in execption hint table
- */
- a1 = 0;
- a2 = hintabsize;
- for(;;) {
- if(a1 >= a2)
- goto no;
- g = (a2 + a1)/2;
- if(v < hintab[g].val) {
- a2 = g;
- continue;
- }
- if(v > hintab[g].val) {
- a1 = g+1;
- continue;
- }
- break;
- }
-
- if(docode(hintab[g].hint, m->code, 1, 0))
- return m;
- print("multiply table failure %ld\n", v);
- m->code[0] = 0;
- return 0;
-
-no:
- /*
- * try to search
- */
- hint[0] = 0;
- for(g=1; g<=6; g++) {
- if(g >= 6 && v >= 65535)
- break;
- mulcp = hint+g;
- *mulcp = 0;
- if(gen1(g)) {
- if(docode(hint, m->code, 1, 0))
- return m;
- print("multiply table failure %ld\n", v);
- break;
- }
- }
-
- /*
- * try a recur followed by a shift
- */
- g = 0;
- while(!(v & 1)) {
- g++;
- v >>= 1;
- }
- if(g) {
- m1 = mulcon0(v);
- if(m1) {
- strcpy(m->code, m1->code);
- sprint(strchr(m->code, 0), "%c0", g+'a');
- return m;
- }
- }
- m->code[0] = 0;
- return 0;
-}
-
-static int
-docode(char *hp, char *cp, int r0, int r1)
-{
- int c, i;
-
- c = *hp++;
- *cp = c;
- cp += 2;
- switch(c) {
- default:
- c -= 'a';
- if(c < 1 || c >= 30)
- break;
- for(i=0; i<4; i++) {
- switch(i) {
- case 0:
- if(docode(hp, cp, r0<<c, r1))
- goto out;
- break;
- case 1:
- if(docode(hp, cp, r1<<c, r1))
- goto out;
- break;
- case 2:
- if(docode(hp, cp, r0, r0<<c))
- goto out;
- break;
- case 3:
- if(docode(hp, cp, r0, r1<<c))
- goto out;
- break;
- }
- }
- break;
-
- case '+':
- for(i=0; i<8; i++) {
- cp[-1] = i+'0';
- switch(i) {
- case 1:
- if(docode(hp, cp, r0+r1, r1))
- goto out;
- break;
- case 5:
- if(docode(hp, cp, r0, r0+r1))
- goto out;
- break;
- }
- }
- break;
-
- case '-':
- for(i=0; i<8; i++) {
- cp[-1] = i+'0';
- switch(i) {
- case 1:
- if(docode(hp, cp, r0-r1, r1))
- goto out;
- break;
- case 2:
- if(docode(hp, cp, r1-r0, r1))
- goto out;
- break;
- case 5:
- if(docode(hp, cp, r0, r0-r1))
- goto out;
- break;
- case 6:
- if(docode(hp, cp, r0, r1-r0))
- goto out;
- break;
- }
- }
- break;
-
- case 0:
- if(r0 == mulval)
- return 1;
- }
- return 0;
-
-out:
- cp[-1] = i+'0';
- return 1;
-}
-
-static int
-gen1(int len)
-{
- int i;
-
- for(shmax=1; shmax<30; shmax++) {
- valmax = 1<<shmax;
- if(valmax >= mulval)
- break;
- }
- if(mulval == 1)
- return 1;
-
- len--;
- for(i=1; i<=shmax; i++)
- if(gen2(len, 1<<i)) {
- *--mulcp = 'a'+i;
- return 1;
- }
- return 0;
-}
-
-static int
-gen2(int len, long r1)
-{
- int i;
-
- if(len <= 0) {
- if(r1 == mulval)
- return 1;
- return 0;
- }
-
- len--;
- if(len == 0)
- goto calcr0;
-
- if(gen3(len, r1, r1+1, UR1)) {
- i = '+';
- goto out;
- }
- if(gen3(len, r1-1, r1, UR0)) {
- i = '-';
- goto out;
- }
- if(gen3(len, 1, r1+1, UR1)) {
- i = '+';
- goto out;
- }
- if(gen3(len, 1, r1-1, UR1)) {
- i = '-';
- goto out;
- }
-
- return 0;
-
-calcr0:
- if(mulval == r1+1) {
- i = '+';
- goto out;
- }
- if(mulval == r1-1) {
- i = '-';
- goto out;
- }
- return 0;
-
-out:
- *--mulcp = i;
- return 1;
-}
-
-static int
-gen3(int len, long r0, long r1, int flag)
-{
- int i, f1, f2;
- long x;
-
- if(r0 <= 0 ||
- r0 >= r1 ||
- r1 > valmax)
- return 0;
-
- len--;
- if(len == 0)
- goto calcr0;
-
- if(!(flag & UR1)) {
- f1 = UR1|SR1;
- for(i=1; i<=shmax; i++) {
- x = r0<<i;
- if(x > valmax)
- break;
- if(gen3(len, r0, x, f1)) {
- i += 'a';
- goto out;
- }
- }
- }
-
- if(!(flag & UR0)) {
- f1 = UR1|SR1;
- for(i=1; i<=shmax; i++) {
- x = r1<<i;
- if(x > valmax)
- break;
- if(gen3(len, r1, x, f1)) {
- i += 'a';
- goto out;
- }
- }
- }
-
- if(!(flag & SR1)) {
- f1 = UR1|SR1|(flag&UR0);
- for(i=1; i<=shmax; i++) {
- x = r1<<i;
- if(x > valmax)
- break;
- if(gen3(len, r0, x, f1)) {
- i += 'a';
- goto out;
- }
- }
- }
-
- if(!(flag & SR0)) {
- f1 = UR0|SR0|(flag&(SR1|UR1));
-
- f2 = UR1|SR1;
- if(flag & UR1)
- f2 |= UR0;
- if(flag & SR1)
- f2 |= SR0;
-
- for(i=1; i<=shmax; i++) {
- x = r0<<i;
- if(x > valmax)
- break;
- if(x > r1) {
- if(gen3(len, r1, x, f2)) {
- i += 'a';
- goto out;
- }
- } else
- if(gen3(len, x, r1, f1)) {
- i += 'a';
- goto out;
- }
- }
- }
-
- x = r1+r0;
- if(gen3(len, r0, x, UR1)) {
- i = '+';
- goto out;
- }
-
- if(gen3(len, r1, x, UR1)) {
- i = '+';
- goto out;
- }
-
- x = r1-r0;
- if(gen3(len, x, r1, UR0)) {
- i = '-';
- goto out;
- }
-
- if(x > r0) {
- if(gen3(len, r0, x, UR1)) {
- i = '-';
- goto out;
- }
- } else
- if(gen3(len, x, r0, UR0)) {
- i = '-';
- goto out;
- }
-
- return 0;
-
-calcr0:
- f1 = flag & (UR0|UR1);
- if(f1 == UR1) {
- for(i=1; i<=shmax; i++) {
- x = r1<<i;
- if(x >= mulval) {
- if(x == mulval) {
- i += 'a';
- goto out;
- }
- break;
- }
- }
- }
-
- if(mulval == r1+r0) {
- i = '+';
- goto out;
- }
- if(mulval == r1-r0) {
- i = '-';
- goto out;
- }
-
- return 0;
-
-out:
- *--mulcp = i;
- return 1;
-}
-
-/*
- * hint table has numbers that
- * the search algorithm fails on.
- * <1000:
- * all numbers
- * <5000:
- * ÷ by 5
- * <10000:
- * ÷ by 50
- * <65536:
- * ÷ by 250
- */
-Hintab hintab[] =
-{
- 683, "b++d+e+",
- 687, "b+e++e-",
- 691, "b++d+e+",
- 731, "b++d+e+",
- 811, "b++d+i+",
- 821, "b++e+e+",
- 843, "b+d++e+",
- 851, "b+f-+e-",
- 853, "b++e+e+",
- 877, "c++++g-",
- 933, "b+c++g-",
- 981, "c-+e-d+",
- 1375, "b+c+b+h-",
- 1675, "d+b++h+",
- 2425, "c++f-e+",
- 2675, "c+d++f-",
- 2750, "b+d-b+h-",
- 2775, "c-+g-e-",
- 3125, "b++e+g+",
- 3275, "b+c+g+e+",
- 3350, "c++++i+",
- 3475, "c-+e-f-",
- 3525, "c-+d+g-",
- 3625, "c-+e-j+",
- 3675, "b+d+d+e+",
- 3725, "b+d-+h+",
- 3925, "b+d+f-d-",
- 4275, "b+g++e+",
- 4325, "b+h-+d+",
- 4425, "b+b+g-j-",
- 4525, "b+d-d+f+",
- 4675, "c++d-g+",
- 4775, "b+d+b+g-",
- 4825, "c+c-+i-",
- 4850, "c++++i-",
- 4925, "b++e-g-",
- 4975, "c+f++e-",
- 5500, "b+g-c+d+",
- 6700, "d+b++i+",
- 9700, "d++++j-",
- 11000, "b+f-c-h-",
- 11750, "b+d+g+j-",
- 12500, "b+c+e-k+",
- 13250, "b+d+e-f+",
- 13750, "b+h-c-d+",
- 14250, "b+g-c+e-",
- 14500, "c+f+j-d-",
- 14750, "d-g--f+",
- 16750, "b+e-d-n+",
- 17750, "c+h-b+e+",
- 18250, "d+b+h-d+",
- 18750, "b+g-++f+",
- 19250, "b+e+b+h+",
- 19750, "b++h--f-",
- 20250, "b+e-l-c+",
- 20750, "c++bi+e-",
- 21250, "b+i+l+c+",
- 22000, "b+e+d-g-",
- 22250, "b+d-h+k-",
- 22750, "b+d-e-g+",
- 23250, "b+c+h+e-",
- 23500, "b+g-c-g-",
- 23750, "b+g-b+h-",
- 24250, "c++g+m-",
- 24750, "b+e+e+j-",
- 25000, "b++dh+g+",
- 25250, "b+e+d-g-",
- 25750, "b+e+b+j+",
- 26250, "b+h+c+e+",
- 26500, "b+h+c+g+",
- 26750, "b+d+e+g-",
- 27250, "b+e+e+f+",
- 27500, "c-i-c-d+",
- 27750, "b+bd++j+",
- 28250, "d-d-++i-",
- 28500, "c+c-h-e-",
- 29000, "b+g-d-f+",
- 29500, "c+h+++e-",
- 29750, "b+g+f-c+",
- 30250, "b+f-g-c+",
- 33500, "c-f-d-n+",
- 33750, "b+d-b+j-",
- 34250, "c+e+++i+",
- 35250, "e+b+d+k+",
- 35500, "c+e+d-g-",
- 35750, "c+i-++e+",
- 36250, "b+bh-d+e+",
- 36500, "c+c-h-e-",
- 36750, "d+e--i+",
- 37250, "b+g+g+b+",
- 37500, "b+h-b+f+",
- 37750, "c+be++j-",
- 38500, "b+e+b+i+",
- 38750, "d+i-b+d+",
- 39250, "b+g-l-+d+",
- 39500, "b+g-c+g-",
- 39750, "b+bh-c+f-",
- 40250, "b+bf+d+g-",
- 40500, "b+g-c+g+",
- 40750, "c+b+i-e+",
- 41250, "d++bf+h+",
- 41500, "b+j+c+d-",
- 41750, "c+f+b+h-",
- 42500, "c+h++g+",
- 42750, "b+g+d-f-",
- 43250, "b+l-e+d-",
- 43750, "c+bd+h+f-",
- 44000, "b+f+g-d-",
- 44250, "b+d-g--f+",
- 44500, "c+e+c+h+",
- 44750, "b+e+d-h-",
- 45250, "b++g+j-g+",
- 45500, "c+d+e-g+",
- 45750, "b+d-h-e-",
- 46250, "c+bd++j+",
- 46500, "b+d-c-j-",
- 46750, "e-e-b+g-",
- 47000, "b+c+d-j-",
- 47250, "b+e+e-g-",
- 47500, "b+g-c-h-",
- 47750, "b+f-c+h-",
- 48250, "d--h+n-",
- 48500, "b+c-g+m-",
- 48750, "b+e+e-g+",
- 49500, "c-f+e+j-",
- 49750, "c+c+g++f-",
- 50000, "b+e+e+k+",
- 50250, "b++i++g+",
- 50500, "c+g+f-i+",
- 50750, "b+e+d+k-",
- 51500, "b+i+c-f+",
- 51750, "b+bd+g-e-",
- 52250, "b+d+g-j+",
- 52500, "c+c+f+g+",
- 52750, "b+c+e+i+",
- 53000, "b+i+c+g+",
- 53500, "c+g+g-n+",
- 53750, "b+j+d-c+",
- 54250, "b+d-g-j-",
- 54500, "c-f+e+f+",
- 54750, "b+f-+c+g+",
- 55000, "b+g-d-g-",
- 55250, "b+e+e+g+",
- 55500, "b+cd++j+",
- 55750, "b+bh-d-f-",
- 56250, "c+d-b+j-",
- 56500, "c+d+c+i+",
- 56750, "b+e+d++h-",
- 57000, "b+d+g-f+",
- 57250, "b+f-m+d-",
- 57750, "b+i+c+e-",
- 58000, "b+e+d+h+",
- 58250, "c+b+g+g+",
- 58750, "d-e-j--e+",
- 59000, "d-i-+e+",
- 59250, "e--h-m+",
- 59500, "c+c-h+f-",
- 59750, "b+bh-e+i-",
- 60250, "b+bh-e-e-",
- 60500, "c+c-g-g-",
- 60750, "b+e-l-e-",
- 61250, "b+g-g-c+",
- 61750, "b+g-c+g+",
- 62250, "f--+c-i-",
- 62750, "e+f--+g+",
- 64750, "b+f+d+p-",
-};
-int hintabsize = nelem(hintab);
diff --git a/sys/src/cmd/7c/peep.c b/sys/src/cmd/7c/peep.c
deleted file mode 100644
index e5d5f240b..000000000
--- a/sys/src/cmd/7c/peep.c
+++ /dev/null
@@ -1,759 +0,0 @@
-#include "gc.h"
-
-void
-peep(void)
-{
- Reg *r, *r1, *r2;
- Prog *p, *p1;
- int t;
-/*
- * complete R structure
- */
- t = 0;
- for(r=firstr; r!=R; r=r1) {
- r1 = r->link;
- if(r1 == R)
- break;
- p = r->prog->link;
- while(p != r1->prog)
- switch(p->as) {
- default:
- r2 = rega();
- r->link = r2;
- r2->link = r1;
-
- r2->prog = p;
- r2->p1 = r;
- r->s1 = r2;
- r2->s1 = r1;
- r1->p1 = r2;
-
- r = r2;
- t++;
-
- case ADATA:
- case AGLOBL:
- case ANAME:
- p = p->link;
- }
- }
-
-loop1:
- t = 0;
- for(r=firstr; r!=R; r=r->link) {
- p = r->prog;
- if(p->as == AMOVQ || /*p->as == AMOVL ||*/ p->as == AMOVS || p->as == AMOVT)
- if(regtyp(&p->to)) {
- if(regtyp(&p->from))
- if(p->from.type == p->to.type) {
- if(copyprop(r)) {
- excise(r);
- t++;
- } else
- if(subprop(r) && copyprop(r)) {
- excise(r);
- t++;
- }
- }
- if(regzer(&p->from))
- if(p->to.type == D_REG) {
- p->from.type = D_REG;
- p->from.reg = REGZERO;
- if(copyprop(r)) {
- excise(r);
- t++;
- } else
- if(subprop(r) && copyprop(r)) {
- excise(r);
- t++;
- }
- }
- }
-/* if(p->as == AMOVL)
- if(regtyp(&p->to)) {
- if(regzer(&p->from))
- if(p->to.type == D_REG) {
- p->from.type = D_REG;
- p->from.reg = REGZERO;
- if(copyprop(r)) {
- excise(r);
- t++;
- } else
- if(subprop(r) && copyprop(r)) {
- excise(r);
- t++;
- }
- }
- } */
- }
- if(t)
- goto loop1;
- /*
- * look for MOVB x,R; MOVB R,R
- */
- for(r=firstr; r!=R; r=r->link) {
- p = r->prog;
- switch(p->as) {
- default:
- continue;
- case AMOVW:
- case AMOVWU:
- case AMOVB:
- case AMOVBU:
- if(p->to.type != D_REG)
- continue;
- break;
- }
- r1 = r->link;
- if(r1 == R)
- continue;
- p1 = r1->prog;
- if(p1->as != p->as)
- continue;
- if(p1->from.type != D_REG || p1->from.reg != p->to.reg)
- continue;
- if(p1->to.type != D_REG || p1->to.reg != p->to.reg)
- continue;
- excise(r1);
- }
-}
-
-void
-excise(Reg *r)
-{
- Prog *p;
-
- p = r->prog;
- p->as = ANOP;
- p->from = zprog.from;
- p->to = zprog.to;
- p->reg = zprog.reg; /**/
-}
-
-Reg*
-uniqp(Reg *r)
-{
- Reg *r1;
-
- r1 = r->p1;
- if(r1 == R) {
- r1 = r->p2;
- if(r1 == R || r1->p2link != R)
- return R;
- } else
- if(r->p2 != R)
- return R;
- return r1;
-}
-
-Reg*
-uniqs(Reg *r)
-{
- Reg *r1;
-
- r1 = r->s1;
- if(r1 == R) {
- r1 = r->s2;
- if(r1 == R)
- return R;
- } else
- if(r->s2 != R)
- return R;
- return r1;
-}
-
-int
-regzer(Adr *a)
-{
-
- if(a->type == D_CONST)
- if(a->sym == S)
- if(a->offset == 0)
- return 1;
- if(a->type == D_REG)
- if(a->reg == REGZERO)
- return 1;
- return 0;
-}
-
-int
-regtyp(Adr *a)
-{
-
- if(a->type == D_REG) {
- if(a->reg != REGZERO)
- return 1;
- return 0;
- }
- if(a->type == D_FREG)
- return 1;
- return 0;
-}
-
-/*
- * the idea is to substitute
- * one register for another
- * from one MOV to another
- * MOV a, R0
- * ADD b, R0 / no use of R1
- * MOV R0, R1
- * would be converted to
- * MOV a, R1
- * ADD b, R1
- * MOV R1, R0
- * hopefully, then the former or latter MOV
- * will be eliminated by copy propagation.
- */
-int
-subprop(Reg *r0)
-{
- Prog *p;
- Adr *v1, *v2;
- Reg *r;
- int t;
-
- p = r0->prog;
- v1 = &p->from;
- if(!regtyp(v1))
- return 0;
- v2 = &p->to;
- if(!regtyp(v2))
- return 0;
- for(r=uniqp(r0); r!=R; r=uniqp(r)) {
- if(uniqs(r) == R)
- break;
- p = r->prog;
- switch(p->as) {
- case AJSR:
- return 0;
-
- case AADDQ:
- case ASUBQ:
- case AADDL:
- case ASUBL:
- case ASLLQ:
- case ASRLQ:
- case ASRAQ:
- case ASLLL:
- case ASRLL:
- case ASRAL:
- case AOR:
- case AAND:
- case AXOR:
- case AMULQ:
- case ADIVQ:
- case ADIVQU:
- case AMODQ:
- case AMODQU:
- case ADIVL:
- case ADIVLU:
- case AMODL:
- case AMODLU:
- case ACMPEQ:
- case ACMPGT:
- case ACMPGE:
- case ACMPUGT:
- case ACMPUGE:
- case ACMPBLE:
- case AMULL:
- case AUMULH:
-
- case AADDT:
- case AADDS:
- case ASUBT:
- case ASUBS:
- case AMULT:
- case AMULS:
- case ADIVT:
- case ADIVS:
- case ACMPTEQ:
- case ACMPTGT:
- case ACMPTGE:
- if(p->to.type == v1->type)
- if(p->to.reg == v1->reg) {
- if(p->reg == NREG)
- p->reg = p->to.reg;
- goto gotit;
- }
- break;
-
- case AMOVS:
- case AMOVT:
- case AMOVQ:
- case ACVTQT:
- case ACVTTQ:
- if(p->to.type == v1->type)
- if(p->to.reg == v1->reg)
- goto gotit;
- break;
- }
- if(copyau(&p->from, v2) ||
- copyau1(p, v2) ||
- copyau(&p->to, v2))
- break;
- if(copysub(&p->from, v1, v2, 0) ||
- copysub1(p, v1, v2, 0) ||
- copysub(&p->to, v1, v2, 0))
- break;
- }
- return 0;
-
-gotit:
- copysub(&p->to, v1, v2, 1);
- if(debug['P']) {
- print("gotit: %D->%D\n%P", v1, v2, r->prog);
- if(p->from.type == v2->type)
- print(" excise");
- print("\n");
- }
- for(r=uniqs(r); r!=r0; r=uniqs(r)) {
- p = r->prog;
- copysub(&p->from, v1, v2, 1);
- copysub1(p, v1, v2, 1);
- copysub(&p->to, v1, v2, 1);
- if(debug['P'])
- print("%P\n", r->prog);
- }
- t = v1->reg;
- v1->reg = v2->reg;
- v2->reg = t;
- if(debug['P'])
- print("%P last\n", r->prog);
- return 1;
-}
-
-/*
- * The idea is to remove redundant copies.
- * v1->v2 F=0
- * (use v2 s/v2/v1/)*
- * set v1 F=1
- * use v2 return fail
- * -----------------
- * v1->v2 F=0
- * (use v2 s/v2/v1/)*
- * set v1 F=1
- * set v2 return success
- */
-int
-copyprop(Reg *r0)
-{
- Prog *p;
- Adr *v1, *v2;
- Reg *r;
-
- p = r0->prog;
- v1 = &p->from;
- v2 = &p->to;
- if(copyas(v1, v2))
- return 1;
- for(r=firstr; r!=R; r=r->link)
- r->active = 0;
- return copy1(v1, v2, r0->s1, 0);
-}
-
-int
-copy1(Adr *v1, Adr *v2, Reg *r, int f)
-{
- int t;
- Prog *p;
-
- if(r->active) {
- if(debug['P'])
- print("act set; return 1\n");
- return 1;
- }
- r->active = 1;
- if(debug['P'])
- print("copy %D->%D f=%d\n", v1, v2, f);
- for(; r != R; r = r->s1) {
- p = r->prog;
- if(debug['P'])
- print("%P", p);
- if(!f && uniqp(r) == R) {
- f = 1;
- if(debug['P'])
- print("; merge; f=%d", f);
- }
- t = copyu(p, v2, A);
- switch(t) {
- case 2: /* rar, cant split */
- if(debug['P'])
- print("; %Drar; return 0\n", v2);
- return 0;
-
- case 3: /* set */
- if(debug['P'])
- print("; %Dset; return 1\n", v2);
- return 1;
-
- case 1: /* used, substitute */
- case 4: /* use and set */
- if(f) {
- if(!debug['P'])
- return 0;
- if(t == 4)
- print("; %Dused+set and f=%d; return 0\n", v2, f);
- else
- print("; %Dused and f=%d; return 0\n", v2, f);
- return 0;
- }
- if(copyu(p, v2, v1)) {
- if(debug['P'])
- print("; sub fail; return 0\n");
- return 0;
- }
- if(debug['P'])
- print("; sub%D/%D", v2, v1);
- if(t == 4) {
- if(debug['P'])
- print("; %Dused+set; return 1\n", v2);
- return 1;
- }
- break;
- }
- if(!f) {
- t = copyu(p, v1, A);
- if(!f && (t == 2 || t == 3 || t == 4)) {
- f = 1;
- if(debug['P'])
- print("; %Dset and !f; f=%d", v1, f);
- }
- }
- if(debug['P'])
- print("\n");
- if(r->s2)
- if(!copy1(v1, v2, r->s2, f))
- return 0;
- }
- return 1;
-}
-
-/*
- * return
- * 1 if v only used (and substitute),
- * 2 if read-alter-rewrite
- * 3 if set
- * 4 if set and used
- * 0 otherwise (not touched)
- */
-copyu(Prog *p, Adr *v, Adr *s)
-{
-
- switch(p->as) {
-
- default:
- if(debug['P'])
- print(" (???)");
- diag(Z, "copyu: unknown op %P", p);
- return 2;
-
-
- case ANOP: /* read, write */
- case AMOVQ:
- case AMOVL:
- case AMOVLU:
- case AMOVW:
- case AMOVWU:
- case AMOVB:
- case AMOVBU:
-
- case AMOVS:
- case AMOVT:
- case ACVTTQ:
- case ACVTQT:
- case ACVTQS:
- case ACVTTS:
- if(s != A) {
- if(copysub(&p->from, v, s, 1))
- return 1;
- if(!copyas(&p->to, v))
- if(copysub(&p->to, v, s, 1))
- return 1;
- return 0;
- }
- if(copyas(&p->to, v)) {
- if(copyau(&p->from, v))
- return 4;
- return 3;
- }
- if(copyau(&p->from, v))
- return 1;
- if(copyau(&p->to, v))
- return 1;
- return 0;
-
- case AADDQ: /* read read write */
- case ASUBQ:
- case AADDL:
- case ASUBL:
- case ACMPEQ:
- case ACMPGT:
- case ACMPGE:
- case ACMPUGT:
- case ACMPUGE:
- case ACMPBLE:
- case ASLLQ:
- case ASRLQ:
- case ASRAQ:
- case ASLLL:
- case ASRLL:
- case ASRAL:
- case AOR:
- case AAND:
- case AXOR:
- case AMULQ:
- case AMULL:
- case AUMULH:
- case ADIVQ:
- case ADIVQU:
- case AMODQ:
- case AMODQU:
- case ADIVL:
- case ADIVLU:
- case AMODL:
- case AMODLU:
-
- case AADDS:
- case AADDT:
- case ASUBS:
- case ASUBT:
- case AMULS:
- case AMULT:
- case ADIVS:
- case ADIVT:
- case ACMPTEQ:
- case ACMPTGT:
- case ACMPTGE:
- if(s != A) {
- if(copysub(&p->from, v, s, 1))
- return 1;
- if(copysub1(p, v, s, 1))
- return 1;
- if(!copyas(&p->to, v))
- if(copysub(&p->to, v, s, 1))
- return 1;
- return 0;
- }
- if(copyas(&p->to, v)) {
- if(p->reg == NREG)
- p->reg = p->to.reg;
- if(copyau(&p->from, v))
- return 4;
- if(copyau1(p, v))
- return 4;
- return 3;
- }
- if(copyau(&p->from, v))
- return 1;
- if(copyau1(p, v))
- return 1;
- if(copyau(&p->to, v))
- return 1;
- return 0;
-
- case ABEQ: /* read */
- case ABNE:
- case ABLT:
- case ABGE:
- case ABLE:
- case ABGT:
- case ABLBC:
- case ABLBS:
-
- case AFBEQ:
- case AFBNE:
- case AFBLT:
- case AFBGE:
- case AFBLE:
- case AFBGT:
- if(s != A)
- return copysub(&p->from, v, s, 1);
- if(copyau(&p->from, v))
- return 1;
- return 0;
-
-#ifdef NOPE
- case ???: /* read read */
- if(s != A) {
- if(copysub(&p->from, v, s, 1))
- return 1;
- return copysub(&p->to, v, s, 1);
- }
- if(copyau(&p->from, v))
- return 1;
- if(copyau(&p->to, v))
- return 1;
- break;
-#endif
-
- case AJMP: /* funny */
- if(s != A) {
- if(copysub(&p->to, v, s, 1))
- return 1;
- return 0;
- }
- if(copyau(&p->to, v))
- return 1;
- return 0;
-
- case ARET: /* funny */
- if(v->type == D_REG)
- if(v->reg == REGRET)
- return 2;
- if(v->type == D_FREG)
- if(v->reg == FREGRET)
- return 2;
-
- case AJSR: /* funny */
- if(v->type == D_REG) {
- if(v->reg <= REGEXT && v->reg > exregoffset)
- return 2;
- if(REGARG != NREG && v->reg == REGARG)
- return 2;
- }
- if(v->type == D_FREG)
- if(v->reg <= FREGEXT && v->reg > exfregoffset)
- return 2;
-
- if(s != A) {
- if(copysub(&p->to, v, s, 1))
- return 1;
- return 0;
- }
- if(copyau(&p->to, v))
- return 4;
- return 3;
-
- case ATEXT: /* funny */
- if(v->type == D_REG)
- if(v->reg == REGARG)
- return 3;
- return 0;
- }
-}
-
-int
-a2type(Prog *p)
-{
-
- switch(p->as) {
- case AADDQ:
- case ASUBQ:
- case ASLLQ:
- case ASRLQ:
- case ASRAQ:
- case ASLLL:
- case ASRLL:
- case ASRAL:
- case AOR:
- case AAND:
- case AXOR:
- case AMULQ:
- case ADIVQ:
- case ADIVQU:
- case AMODQ:
- case AMODQU:
- case ADIVL:
- case ADIVLU:
- case AMODL:
- case AMODLU:
- case AADDL:
- case ASUBL:
- case AEXTLL:
- case ACMPEQ:
- case ACMPGT:
- case ACMPGE:
- case ACMPUGT:
- case ACMPUGE:
- case ACMPBLE:
- case AMULL:
- case AUMULH:
- return D_REG;
-
- case AADDS:
- case AADDT:
- case ASUBS:
- case ASUBT:
- case AMULS:
- case AMULT:
- case ADIVS:
- case ADIVT:
- case ACMPTEQ:
- case ACMPTGT:
- case ACMPTGE:
- case ACVTTQ:
- case ACVTQT:
- return D_FREG;
- }
- return D_NONE;
-}
-
-/*
- * direct reference,
- * could be set/use depending on
- * semantics
- */
-int
-copyas(Adr *a, Adr *v)
-{
-
- if(regtyp(v))
- if(a->type == v->type)
- if(a->reg == v->reg)
- return 1;
- return 0;
-}
-
-/*
- * either direct or indirect
- */
-int
-copyau(Adr *a, Adr *v)
-{
-
- if(copyas(a, v))
- return 1;
- if(v->type == D_REG)
- if(a->type == D_OREG)
- if(v->reg == a->reg)
- return 1;
- return 0;
-}
-
-int
-copyau1(Prog *p, Adr *v)
-{
-
- if(regtyp(v))
- if(p->from.type == v->type || p->to.type == v->type)
- if(p->reg == v->reg) {
- if(a2type(p) != v->type)
- print("botch a2type %P\n", p);
- return 1;
- }
- return 0;
-}
-
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-int
-copysub(Adr *a, Adr *v, Adr *s, int f)
-{
-
- if(f)
- if(copyau(a, v))
- a->reg = s->reg;
- return 0;
-}
-
-int
-copysub1(Prog *p1, Adr *v, Adr *s, int f)
-{
-
- if(f)
- if(copyau1(p1, v))
- p1->reg = s->reg;
- return 0;
-}
diff --git a/sys/src/cmd/7c/reg.c b/sys/src/cmd/7c/reg.c
deleted file mode 100644
index 802bc75dc..000000000
--- a/sys/src/cmd/7c/reg.c
+++ /dev/null
@@ -1,1164 +0,0 @@
-#include "gc.h"
-
-void addsplits(void);
-
-Reg*
-rega(void)
-{
- Reg *r;
-
- r = freer;
- if(r == R) {
- r = alloc(sizeof(*r));
- } else
- freer = r->link;
-
- *r = zreg;
- return r;
-}
-
-int
-rcmp(void *a1, void *a2)
-{
- Rgn *p1, *p2;
- int c1, c2;
-
- p1 = a1;
- p2 = a2;
- c1 = p2->cost;
- c2 = p1->cost;
- if(c1 -= c2)
- return c1;
- return p2->varno - p1->varno;
-}
-
-void
-regopt(Prog *p)
-{
- Reg *r, *r1, *r2;
- Prog *p1;
- int i, z;
- long initpc, val, npc;
- ulong vreg;
- Bits bit;
- struct
- {
- long m;
- long c;
- Reg* p;
- } log5[6], *lp;
-
- firstr = R;
- lastr = R;
- nvar = 0;
- regbits = 0;
- for(z=0; z<BITS; z++) {
- externs.b[z] = 0;
- params.b[z] = 0;
- consts.b[z] = 0;
- addrs.b[z] = 0;
- }
-
- /*
- * pass 1
- * build aux data structure
- * allocate pcs
- * find use and set of variables
- */
- val = 5L * 5L * 5L * 5L * 5L;
- lp = log5;
- for(i=0; i<5; i++) {
- lp->m = val;
- lp->c = 0;
- lp->p = R;
- val /= 5L;
- lp++;
- }
- val = 0;
- for(; p != P; p = p->link) {
- switch(p->as) {
- case ADATA:
- case AGLOBL:
- case ANAME:
- continue;
- }
- r = rega();
- if(firstr == R) {
- firstr = r;
- lastr = r;
- } else {
- lastr->link = r;
- r->p1 = lastr;
- lastr->s1 = r;
- lastr = r;
- }
- r->prog = p;
- r->pc = val;
- val++;
-
- lp = log5;
- for(i=0; i<5; i++) {
- lp->c--;
- if(lp->c <= 0) {
- lp->c = lp->m;
- if(lp->p != R)
- lp->p->log5 = r;
- lp->p = r;
- (lp+1)->c = 0;
- break;
- }
- lp++;
- }
-
- r1 = r->p1;
- if(r1 != R)
- switch(r1->prog->as) {
- case ARET:
- case AJMP:
- case AREI:
- r->p1 = R;
- r1->s1 = R;
- }
-
- /*
- * left side always read
- */
- bit = mkvar(&p->from, p->as==AMOVQ || p->as==AMOVL);
- for(z=0; z<BITS; z++)
- r->use1.b[z] |= bit.b[z];
-
- /*
- * right side depends on opcode
- */
- bit = mkvar(&p->to, 0);
- if(bany(&bit))
- switch(p->as) {
- default:
- diag(Z, "reg: unknown asop: %ud", p->as);
- break;
-
- /*
- * right side write
- */
- case ANOP:
- case AMOVB:
- case AMOVBU:
- case AMOVW:
- case AMOVWU:
- case AMOVL:
- case AMOVQ:
- case AMOVS:
- case AMOVT:
- for(z=0; z<BITS; z++)
- r->set.b[z] |= bit.b[z];
- break;
-
- /*
- * funny
- */
- case AJSR:
- for(z=0; z<BITS; z++)
- addrs.b[z] |= bit.b[z];
- break;
- }
- }
- if(firstr == R)
- return;
- initpc = pc - val;
- npc = val;
-
- /*
- * pass 2
- * turn branch references to pointers
- * build back pointers
- */
- for(r = firstr; r != R; r = r->link) {
- p = r->prog;
- if(p->to.type == D_BRANCH) {
- val = p->to.offset - initpc;
- r1 = firstr;
- while(r1 != R) {
- r2 = r1->log5;
- if(r2 != R && val >= r2->pc) {
- r1 = r2;
- continue;
- }
- if(r1->pc == val)
- break;
- r1 = r1->link;
- }
- if(r1 == R) {
- nearln = p->lineno;
- diag(Z, "ref not found\n%P", p);
- continue;
- }
- if(r1 == r) {
- nearln = p->lineno;
- diag(Z, "ref to self\n%P", p);
- continue;
- }
- r->s2 = r1;
- r->p2link = r1->p2;
- r1->p2 = r;
- }
- }
- if(debug['R']) {
- p = firstr->prog;
- print("\n%L %D\n", p->lineno, &p->from);
- }
-
- /*
- * pass 2.5
- * find looping structure
- */
- for(r = firstr; r != R; r = r->link)
- r->active = 0;
- change = 0;
- loopit(firstr, npc);
-
- /*
- * pass 3
- * iterate propagating usage
- * back until flow graph is complete
- */
-loop1:
- change = 0;
- for(r = firstr; r != R; r = r->link)
- r->active = 0;
- for(r = firstr; r != R; r = r->link)
- if(r->prog->as == ARET)
- prop(r, zbits, zbits);
-loop11:
- /* pick up unreachable code */
- i = 0;
- for(r = firstr; r != R; r = r1) {
- r1 = r->link;
- if(r1 && r1->active && !r->active) {
- prop(r, zbits, zbits);
- i = 1;
- }
- }
- if(i)
- goto loop11;
- if(change)
- goto loop1;
-
-
- /*
- * pass 4
- * iterate propagating register/variable synchrony
- * forward until graph is complete
- */
-loop2:
- change = 0;
- for(r = firstr; r != R; r = r->link)
- r->active = 0;
- synch(firstr, zbits);
- if(change)
- goto loop2;
-
- addsplits();
-
- if(debug['R'] && debug['v']) {
- print("\nprop structure:\n");
- for(r = firstr; r != R; r = r->link) {
- print("%ld:%P", r->loop, r->prog);
- for(z=0; z<BITS; z++)
- bit.b[z] = r->set.b[z] |
- r->refahead.b[z] | r->calahead.b[z] |
- r->refbehind.b[z] | r->calbehind.b[z] |
- r->use1.b[z] | r->use2.b[z];
- if(bany(&bit)) {
- print("\t");
- if(bany(&r->use1))
- print(" u1=%B", r->use1);
- if(bany(&r->use2))
- print(" u2=%B", r->use2);
- if(bany(&r->set))
- print(" st=%B", r->set);
- if(bany(&r->refahead))
- print(" ra=%B", r->refahead);
- if(bany(&r->calahead))
- print(" ca=%B", r->calahead);
- if(bany(&r->refbehind))
- print(" rb=%B", r->refbehind);
- if(bany(&r->calbehind))
- print(" cb=%B", r->calbehind);
- }
- print("\n");
- }
- }
-
- /*
- * pass 5
- * isolate regions
- * calculate costs (paint1)
- */
- r = firstr;
- if(r) {
- for(z=0; z<BITS; z++)
- bit.b[z] = (r->refahead.b[z] | r->calahead.b[z]) &
- ~(externs.b[z] | params.b[z] | addrs.b[z] | consts.b[z]);
- if(bany(&bit)) {
- nearln = r->prog->lineno;
- warn(Z, "used and not set: %B", bit);
- if(debug['R'] && !debug['w'])
- print("used and not set: %B\n", bit);
- }
- }
-
- for(r = firstr; r != R; r = r->link)
- r->act = zbits;
- rgp = region;
- nregion = 0;
- for(r = firstr; r != R; r = r->link) {
- for(z=0; z<BITS; z++)
- bit.b[z] = r->set.b[z] &
- ~(r->refahead.b[z] | r->calahead.b[z] | addrs.b[z]);
- if(bany(&bit)) {
- nearln = r->prog->lineno;
- warn(Z, "set and not used: %B", bit);
- if(debug['R'])
- print("set and not used: %B\n", bit);
- excise(r);
- }
- for(z=0; z<BITS; z++)
- bit.b[z] = LOAD(r) & ~(r->act.b[z] | addrs.b[z]);
- while(bany(&bit)) {
- i = bnum(bit);
- rgp->enter = r;
- rgp->varno = i;
- change = 0;
- if(debug['R'] && debug['v'])
- print("\n");
- paint1(r, i);
- bit.b[i/32] &= ~(1L<<(i%32));
- if(change <= 0) {
- if(debug['R'])
- print("%L $%d: %B\n",
- r->prog->lineno, change, blsh(i));
- continue;
- }
- rgp->cost = change;
- nregion++;
- if(nregion >= NRGN) {
- warn(Z, "too many regions");
- goto brk;
- }
- rgp++;
- }
- }
-brk:
- qsort(region, nregion, sizeof(region[0]), rcmp);
-
- /*
- * pass 6
- * determine used registers (paint2)
- * replace code (paint3)
- */
- rgp = region;
- for(i=0; i<nregion; i++) {
- bit = blsh(rgp->varno);
- vreg = paint2(rgp->enter, rgp->varno);
- vreg = allreg(vreg, rgp);
- if(debug['R']) {
- if(rgp->regno >= NREG)
- print("%L $%d F%d: %B\n",
- rgp->enter->prog->lineno,
- rgp->cost,
- rgp->regno-NREG,
- bit);
- else
- print("%L $%d R%d: %B\n",
- rgp->enter->prog->lineno,
- rgp->cost,
- rgp->regno,
- bit);
- }
- if(rgp->regno != 0)
- paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
- rgp++;
- }
- /*
- * pass 7
- * peep-hole on basic block
- */
- if(!debug['R'] || debug['P'])
- peep();
-
- /*
- * pass 8
- * recalculate pc
- */
- val = initpc;
- for(r = firstr; r != R; r = r1) {
- r->pc = val;
- p = r->prog;
- p1 = P;
- r1 = r->link;
- if(r1 != R)
- p1 = r1->prog;
- for(; p != p1; p = p->link) {
- switch(p->as) {
- default:
- val++;
- break;
-
- case ANOP:
- case ADATA:
- case AGLOBL:
- case ANAME:
- break;
- }
- }
- }
- pc = val;
-
- /*
- * fix up branches
- */
- if(debug['R'])
- if(bany(&addrs))
- print("addrs: %B\n", addrs);
-
- r1 = 0; /* set */
- for(r = firstr; r != R; r = r->link) {
- p = r->prog;
- if(p->to.type == D_BRANCH)
- p->to.offset = r->s2->pc;
- r1 = r;
- }
-
- /*
- * last pass
- * eliminate nops
- * free aux structures
- */
- for(p = firstr->prog; p != P; p = p->link){
- while(p->link && p->link->as == ANOP)
- p->link = p->link->link;
- }
- if(r1 != R) {
- r1->link = freer;
- freer = firstr;
- }
-}
-
-void
-addsplits(void)
-{
- Reg *r, *r1;
- int z, i;
- Bits bit;
-
- for(r = firstr; r != R; r = r->link) {
- if(r->loop > 1)
- continue;
- if(r->prog->as == AJSR)
- continue;
- for(r1 = r->p2; r1 != R; r1 = r1->p2link) {
- if(r1->loop <= 1)
- continue;
- for(z=0; z<BITS; z++)
- bit.b[z] = r1->calbehind.b[z] &
- (r->refahead.b[z] | r->use1.b[z] | r->use2.b[z]) &
- ~(r->calahead.b[z] & addrs.b[z]);
- while(bany(&bit)) {
- i = bnum(bit);
- bit.b[i/32] &= ~(1L << (i%32));
- }
- }
- }
-}
-
-/*
- * add mov b,rn
- * just after r
- */
-void
-addmove(Reg *r, int bn, int rn, int f)
-{
- Prog *p, *p1;
- Adr *a;
- Var *v;
-
- p1 = alloc(sizeof(*p1));
- *p1 = zprog;
- p = r->prog;
-
- p1->link = p->link;
- p->link = p1;
- p1->lineno = p->lineno;
-
- v = var + bn;
-
- a = &p1->to;
- a->sym = v->sym;
- a->name = v->name;
- a->offset = v->offset;
- a->etype = v->etype;
- a->type = D_OREG;
- if(a->etype == TARRAY || a->sym == S)
- a->type = D_CONST;
-
- p1->as = AMOVL;
- if(v->etype == TCHAR || v->etype == TUCHAR) /* TODO: optimise locals? */
- p1->as = AMOVB;
- if(v->etype == TSHORT || v->etype == TUSHORT)
- p1->as = AMOVW;
- if(v->etype == TVLONG || v->etype == TUVLONG)
- p1->as = AMOVQ;
- if(v->etype == TFLOAT)
- p1->as = AMOVS;
- if(v->etype == TDOUBLE)
- p1->as = AMOVT;
-
- p1->from.type = D_REG;
- p1->from.reg = rn;
- if(rn >= NREG) {
- p1->from.type = D_FREG;
- p1->from.reg = rn-NREG;
- }
- if(!f) {
- p1->from = *a;
- *a = zprog.from;
- a->type = D_REG;
- a->reg = rn;
- if(rn >= NREG) {
- a->type = D_FREG;
- a->reg = rn-NREG;
- }
- if(v->etype == TUCHAR)
- p1->as = AMOVBU;
- if(v->etype == TUSHORT)
- p1->as = AMOVWU;
- }
- if(debug['R'])
- print("%P\t.a%P\n", p, p1);
-}
-
-Bits
-mkvar(Adr *a, int docon)
-{
- Var *v;
- int i, t, n, et, z;
- vlong o;
- Bits bit;
- Sym *s;
-
- t = a->type;
- if(t == D_REG && a->reg != NREG)
- regbits |= RtoB(a->reg);
- if(t == D_FREG && a->reg != NREG)
- regbits |= FtoB(a->reg);
- s = a->sym;
- o = a->offset;
- et = a->etype;
- if(s == S) {
- if(t != D_CONST || !docon || a->reg != NREG)
- goto none;
- et = TLONG;
- if (o > 0x7FFFFFFFLL || o < -0x80000000LL)
- et = TVLONG;
- }
- if(t == D_CONST) {
- if(s == S && sval(o))
- goto none;
- }
-
- n = a->name;
- v = var;
- for(i=0; i<nvar; i++) {
- if(s == v->sym)
- if(n == v->name)
- if(o == v->offset)
- goto out;
- v++;
- }
- if(s)
- if(s->name[0] == '.')
- goto none;
- if(nvar >= NVAR) {
- if(debug['w'] > 1 && s)
- warn(Z, "variable not optimized: %s", s->name);
- goto none;
- }
- i = nvar;
- nvar++;
- v = &var[i];
- v->sym = s;
- v->offset = o;
- v->etype = et;
- v->name = n;
- if(debug['R'])
- print("bit=%2d et=%2d %D\n", i, et, a);
-out:
- bit = blsh(i);
- if(n == D_EXTERN || n == D_STATIC)
- for(z=0; z<BITS; z++)
- externs.b[z] |= bit.b[z];
- if(n == D_PARAM)
- for(z=0; z<BITS; z++)
- params.b[z] |= bit.b[z];
- if(v->etype != et || (!typechlpfd[et] && !typev[et])) /* funny punning? */
- for(z=0; z<BITS; z++)
- addrs.b[z] |= bit.b[z];
- if(t == D_CONST) {
- if(s == S) {
- for(z=0; z<BITS; z++)
- consts.b[z] |= bit.b[z];
- return bit;
- }
- if(et != TARRAY)
- for(z=0; z<BITS; z++)
- addrs.b[z] |= bit.b[z];
- for(z=0; z<BITS; z++)
- params.b[z] |= bit.b[z];
- return bit;
- }
- if(t == D_OREG)
- return bit;
-
-none:
- return zbits;
-}
-
-void
-prop(Reg *r, Bits ref, Bits cal)
-{
- Reg *r1, *r2;
- int z;
-
- for(r1 = r; r1 != R; r1 = r1->p1) {
- for(z=0; z<BITS; z++) {
- ref.b[z] |= r1->refahead.b[z];
- if(ref.b[z] != r1->refahead.b[z]) {
- r1->refahead.b[z] = ref.b[z];
- change++;
- }
- cal.b[z] |= r1->calahead.b[z];
- if(cal.b[z] != r1->calahead.b[z]) {
- r1->calahead.b[z] = cal.b[z];
- change++;
- }
- }
- switch(r1->prog->as) {
- case AJSR:
- for(z=0; z<BITS; z++) {
- cal.b[z] |= ref.b[z] | externs.b[z];
- ref.b[z] = 0;
- }
- break;
-
- case ATEXT:
- for(z=0; z<BITS; z++) {
- cal.b[z] = 0;
- ref.b[z] = 0;
- }
- break;
-
- case ARET:
- for(z=0; z<BITS; z++) {
- cal.b[z] = externs.b[z];
- ref.b[z] = 0;
- }
- }
- for(z=0; z<BITS; z++) {
- ref.b[z] = (ref.b[z] & ~r1->set.b[z]) |
- r1->use1.b[z] | r1->use2.b[z];
- cal.b[z] &= ~(r1->set.b[z] | r1->use1.b[z] | r1->use2.b[z]);
- r1->refbehind.b[z] = ref.b[z];
- r1->calbehind.b[z] = cal.b[z];
- }
- if(r1->active)
- break;
- r1->active = 1;
- }
- for(; r != r1; r = r->p1)
- for(r2 = r->p2; r2 != R; r2 = r2->p2link)
- prop(r2, r->refbehind, r->calbehind);
-}
-
-/*
- * find looping structure
- *
- * 1) find reverse postordering
- * 2) find approximate dominators,
- * the actual dominators if the flow graph is reducible
- * otherwise, dominators plus some other non-dominators.
- * See Matthew S. Hecht and Jeffrey D. Ullman,
- * "Analysis of a Simple Algorithm for Global Data Flow Problems",
- * Conf. Record of ACM Symp. on Principles of Prog. Langs, Boston, Massachusetts,
- * Oct. 1-3, 1973, pp. 207-217.
- * 3) find all nodes with a predecessor dominated by the current node.
- * such a node is a loop head.
- * recursively, all preds with a greater rpo number are in the loop
- */
-long
-postorder(Reg *r, Reg **rpo2r, long n)
-{
- Reg *r1;
-
- r->rpo = 1;
- r1 = r->s1;
- if(r1 && !r1->rpo)
- n = postorder(r1, rpo2r, n);
- r1 = r->s2;
- if(r1 && !r1->rpo)
- n = postorder(r1, rpo2r, n);
- rpo2r[n] = r;
- n++;
- return n;
-}
-
-long
-rpolca(long *idom, long rpo1, long rpo2)
-{
- long t;
-
- if(rpo1 == -1)
- return rpo2;
- while(rpo1 != rpo2){
- if(rpo1 > rpo2){
- t = rpo2;
- rpo2 = rpo1;
- rpo1 = t;
- }
- while(rpo1 < rpo2){
- t = idom[rpo2];
- if(t >= rpo2)
- fatal(Z, "bad idom");
- rpo2 = t;
- }
- }
- return rpo1;
-}
-
-int
-doms(long *idom, long r, long s)
-{
- while(s > r)
- s = idom[s];
- return s == r;
-}
-
-int
-loophead(long *idom, Reg *r)
-{
- long src;
-
- src = r->rpo;
- if(r->p1 != R && doms(idom, src, r->p1->rpo))
- return 1;
- for(r = r->p2; r != R; r = r->p2link)
- if(doms(idom, src, r->rpo))
- return 1;
- return 0;
-}
-
-void
-loopmark(Reg **rpo2r, long head, Reg *r)
-{
- if(r->rpo < head || r->active == head)
- return;
- r->active = head;
- r->loop += LOOP;
- if(r->p1 != R)
- loopmark(rpo2r, head, r->p1);
- for(r = r->p2; r != R; r = r->p2link)
- loopmark(rpo2r, head, r);
-}
-
-void
-loopit(Reg *r, long nr)
-{
- Reg *r1;
- long i, d, me;
-
- if(nr > maxnr) {
- rpo2r = alloc(nr * sizeof(Reg*));
- idom = alloc(nr * sizeof(long));
- maxnr = nr;
- }
-
- d = postorder(r, rpo2r, 0);
- if(d > nr)
- fatal(Z, "too many reg nodes");
- nr = d;
- for(i = 0; i < nr / 2; i++){
- r1 = rpo2r[i];
- rpo2r[i] = rpo2r[nr - 1 - i];
- rpo2r[nr - 1 - i] = r1;
- }
- for(i = 0; i < nr; i++)
- rpo2r[i]->rpo = i;
-
- idom[0] = 0;
- for(i = 0; i < nr; i++){
- r1 = rpo2r[i];
- me = r1->rpo;
- d = -1;
- if(r1->p1 != R && r1->p1->rpo < me)
- d = r1->p1->rpo;
- for(r1 = r1->p2; r1 != nil; r1 = r1->p2link)
- if(r1->rpo < me)
- d = rpolca(idom, d, r1->rpo);
- idom[i] = d;
- }
-
- for(i = 0; i < nr; i++){
- r1 = rpo2r[i];
- r1->loop++;
- if(r1->p2 != R && loophead(idom, r1))
- loopmark(rpo2r, i, r1);
- }
-}
-
-void
-synch(Reg *r, Bits dif)
-{
- Reg *r1;
- int z;
-
- for(r1 = r; r1 != R; r1 = r1->s1) {
- for(z=0; z<BITS; z++) {
- dif.b[z] = (dif.b[z] &
- ~(~r1->refbehind.b[z] & r1->refahead.b[z])) |
- r1->set.b[z] | r1->regdiff.b[z];
- if(dif.b[z] != r1->regdiff.b[z]) {
- r1->regdiff.b[z] = dif.b[z];
- change++;
- }
- }
- if(r1->active)
- break;
- r1->active = 1;
- for(z=0; z<BITS; z++)
- dif.b[z] &= ~(~r1->calbehind.b[z] & r1->calahead.b[z]);
- if(r1->s2 != R)
- synch(r1->s2, dif);
- }
-}
-
-ulong
-allreg(ulong b, Rgn *r)
-{
- Var *v;
- int i;
-
- v = var + r->varno;
- r->regno = 0;
- switch(v->etype) {
-
- default:
- diag(Z, "unknown etype %d/%d", bitno(b), v->etype);
- break;
-
- case TCHAR:
- case TUCHAR:
- case TSHORT:
- case TUSHORT:
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TVLONG:
- case TUVLONG:
- case TIND:
- case TARRAY:
- i = BtoR(~b);
- if(i && r->cost >= 0) {
- r->regno = i;
- return RtoB(i);
- }
- break;
-
- case TDOUBLE:
- case TFLOAT:
- i = BtoF(~b);
- if(i && r->cost >= 0) {
- r->regno = i+NREG;
- return FtoB(i);
- }
- break;
- }
- return 0;
-}
-
-void
-paint1(Reg *r, int bn)
-{
- Reg *r1;
- Prog *p;
- int z;
- ulong bb;
-
- z = bn/32;
- bb = 1L<<(bn%32);
- if(r->act.b[z] & bb)
- return;
- for(;;) {
- if(!(r->refbehind.b[z] & bb))
- break;
- r1 = r->p1;
- if(r1 == R)
- break;
- if(!(r1->refahead.b[z] & bb))
- break;
- if(r1->act.b[z] & bb)
- break;
- r = r1;
- }
-
- if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb) {
- change -= CLOAD * r->loop;
- if(debug['R'] && debug['v'])
- print("%ld%P\tld %B $%d\n", r->loop,
- r->prog, blsh(bn), change);
- }
- for(;;) {
- r->act.b[z] |= bb;
- p = r->prog;
-
- if(r->use1.b[z] & bb) {
- change += CREF * r->loop;
- if(debug['R'] && debug['v'])
- print("%ld%P\tu1 %B $%d\n", r->loop,
- p, blsh(bn), change);
- }
-
- if((r->use2.b[z]|r->set.b[z]) & bb) {
- change += CREF * r->loop;
- if(debug['R'] && debug['v'])
- print("%ld%P\tu2 %B $%d\n", r->loop,
- p, blsh(bn), change);
- }
-
- if(STORE(r) & r->regdiff.b[z] & bb) {
- change -= CLOAD * r->loop;
- if(debug['R'] && debug['v'])
- print("%ld%P\tst %B $%d\n", r->loop,
- p, blsh(bn), change);
- }
-
- if(r->refbehind.b[z] & bb)
- for(r1 = r->p2; r1 != R; r1 = r1->p2link)
- if(r1->refahead.b[z] & bb)
- paint1(r1, bn);
-
- if(!(r->refahead.b[z] & bb))
- break;
- r1 = r->s2;
- if(r1 != R)
- if(r1->refbehind.b[z] & bb)
- paint1(r1, bn);
- r = r->s1;
- if(r == R)
- break;
- if(r->act.b[z] & bb)
- break;
- if(!(r->refbehind.b[z] & bb))
- break;
- }
-}
-
-ulong
-paint2(Reg *r, int bn)
-{
- Reg *r1;
- int z;
- ulong bb, vreg;
-
- z = bn/32;
- bb = 1L << (bn%32);
- vreg = regbits;
- if(!(r->act.b[z] & bb))
- return vreg;
- for(;;) {
- if(!(r->refbehind.b[z] & bb))
- break;
- r1 = r->p1;
- if(r1 == R)
- break;
- if(!(r1->refahead.b[z] & bb))
- break;
- if(!(r1->act.b[z] & bb))
- break;
- r = r1;
- }
- for(;;) {
- r->act.b[z] &= ~bb;
-
- vreg |= r->regu;
-
- if(r->refbehind.b[z] & bb)
- for(r1 = r->p2; r1 != R; r1 = r1->p2link)
- if(r1->refahead.b[z] & bb)
- vreg |= paint2(r1, bn);
-
- if(!(r->refahead.b[z] & bb))
- break;
- r1 = r->s2;
- if(r1 != R)
- if(r1->refbehind.b[z] & bb)
- vreg |= paint2(r1, bn);
- r = r->s1;
- if(r == R)
- break;
- if(!(r->act.b[z] & bb))
- break;
- if(!(r->refbehind.b[z] & bb))
- break;
- }
- return vreg;
-}
-
-void
-paint3(Reg *r, int bn, long rb, int rn)
-{
- Reg *r1;
- Prog *p;
- int z;
- ulong bb;
-
- z = bn/32;
- bb = 1L << (bn%32);
- if(r->act.b[z] & bb)
- return;
- for(;;) {
- if(!(r->refbehind.b[z] & bb))
- break;
- r1 = r->p1;
- if(r1 == R)
- break;
- if(!(r1->refahead.b[z] & bb))
- break;
- if(r1->act.b[z] & bb)
- break;
- r = r1;
- }
-
- if(LOAD(r) & ~(r->set.b[z] & ~(r->use1.b[z]|r->use2.b[z])) & bb)
- addmove(r, bn, rn, 0);
- for(;;) {
- r->act.b[z] |= bb;
- p = r->prog;
-
- if(r->use1.b[z] & bb) {
- if(debug['R'])
- print("%P", p);
- addreg(&p->from, rn);
- if(p->as == AMOVL && typechlp[var[bn].etype])
- p->as = AMOVQ;
- if(debug['R'])
- print("\t.c%P\n", p);
- }
- if((r->use2.b[z]|r->set.b[z]) & bb) {
- if(debug['R'])
- print("%P", p);
- addreg(&p->to, rn);
- if(p->as == AMOVL && typechlp[var[bn].etype])
- p->as = AMOVQ;
- if(debug['R'])
- print("\t.c%P\n", p);
- }
-
- if(STORE(r) & r->regdiff.b[z] & bb)
- addmove(r, bn, rn, 1);
- r->regu |= rb;
-
- if(r->refbehind.b[z] & bb)
- for(r1 = r->p2; r1 != R; r1 = r1->p2link)
- if(r1->refahead.b[z] & bb)
- paint3(r1, bn, rb, rn);
-
- if(!(r->refahead.b[z] & bb))
- break;
- r1 = r->s2;
- if(r1 != R)
- if(r1->refbehind.b[z] & bb)
- paint3(r1, bn, rb, rn);
- r = r->s1;
- if(r == R)
- break;
- if(r->act.b[z] & bb)
- break;
- if(!(r->refbehind.b[z] & bb))
- break;
- }
-}
-
-void
-addreg(Adr *a, int rn)
-{
-
- a->sym = 0;
- a->name = D_NONE;
- a->type = D_REG;
- a->reg = rn;
- if(rn >= NREG) {
- a->type = D_FREG;
- a->reg = rn-NREG;
- }
-}
-
-/*
- * bit reg
- * 0 R2
- * 1 R3
- * ... ...
- * 10 R12
- * 11 R16
- * ... ...
- * 19 R24
- * 20 R25
- */
-long
-RtoB(int r)
-{
-
- if(r >= 2 && r <= 12)
- return 1L << (r-2);
- if(r >= 16 && r <= 25)
- return 1L << (r-5);
- return 0;
-}
-
-BtoR(long b)
-{
- int r;
-
- b &= 0x001fffffL;
- if(b == 0)
- return 0;
- r = bitno(b) + 2;
- if (r >= 13)
- r += 3;
- return r;
-}
-
-/*
- * bit reg
- * 21 F1
- * 22 F2
- * ... ...
- * 31 F11
- */
-long
-FtoB(int f)
-{
-
- if(f < 1 || f > 11)
- return 0;
- return 1L << (f + 20);
-}
-
-int
-BtoF(long b)
-{
-
- b &= 0xffe00000L;
- if(b == 0)
- return 0;
- return bitno(b) - 20;
-}
diff --git a/sys/src/cmd/7c/sgen.c b/sys/src/cmd/7c/sgen.c
deleted file mode 100644
index 54aaacd4a..000000000
--- a/sys/src/cmd/7c/sgen.c
+++ /dev/null
@@ -1,235 +0,0 @@
-#include "gc.h"
-
-void
-noretval(int n)
-{
-
- if(n & 1) {
- gins(ANOP, Z, Z);
- p->to.type = D_REG;
- p->to.reg = REGRET;
- }
- if(n & 2) {
- gins(ANOP, Z, Z);
- p->to.type = D_FREG;
- p->to.reg = FREGRET;
- }
-}
-
-/*
- * calculate addressability as follows
- * CONST ==> 20 $value
- * NAME ==> 10 name
- * REGISTER ==> 11 register
- * INDREG ==> 12 *[(reg)+offset]
- * &10 ==> 2 $name
- * ADD(2, 20) ==> 2 $name+offset
- * ADD(3, 20) ==> 3 $(reg)+offset
- * &12 ==> 3 $(reg)+offset
- * *11 ==> 11 ??
- * *2 ==> 10 name
- * *3 ==> 12 *(reg)+offset
- * calculate complexity (number of registers)
- */
-void
-xcom(Node *n)
-{
- Node *l, *r;
- int t;
-
- if(n == Z)
- return;
- l = n->left;
- r = n->right;
- n->addable = 0;
- n->complex = 0;
- switch(n->op) {
- case OCONST:
- n->addable = 20;
- return;
-
- case OREGISTER:
- n->addable = 11;
- return;
-
- case OINDREG:
- n->addable = 12;
- return;
-
- case ONAME:
- n->addable = 10;
- return;
-
- case OADDR:
- xcom(l);
- if(l->addable == 10)
- n->addable = 2;
- if(l->addable == 12)
- n->addable = 3;
- break;
-
- case OIND:
- xcom(l);
- if(l->addable == 11)
- n->addable = 12;
- if(l->addable == 3)
- n->addable = 12;
- if(l->addable == 2)
- n->addable = 10;
- break;
-
- case OADD:
- xcom(l);
- xcom(r);
- if(l->addable == 20) {
- if(r->addable == 2)
- n->addable = 2;
- if(r->addable == 3)
- n->addable = 3;
- }
- if(r->addable == 20) {
- if(l->addable == 2)
- n->addable = 2;
- if(l->addable == 3)
- n->addable = 3;
- }
- break;
-
- case OASLMUL:
- case OASMUL:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OASASHL;
- r->vconst = t;
- r->type = types[TINT];
- }
- break;
-
- case OMUL:
- case OLMUL:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OASHL;
- r->vconst = t;
- r->type = types[TINT];
- }
- t = vlog(l);
- if(t >= 0) {
- n->op = OASHL;
- n->left = r;
- n->right = l;
- r = l;
- l = n->left;
- r->vconst = t;
- r->type = types[TINT];
- }
- break;
-
- case OASLDIV:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OASLSHR;
- r->vconst = t;
- r->type = types[TINT];
- }
- break;
-
- case OLDIV:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OLSHR;
- r->vconst = t;
- r->type = types[TINT];
- }
- break;
-
- case OASLMOD:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OASAND;
- r->vconst--;
- }
- break;
-
- case OLMOD:
- xcom(l);
- xcom(r);
- t = vlog(r);
- if(t >= 0) {
- n->op = OAND;
- r->vconst--;
- }
- break;
-
- default:
- if(l != Z)
- xcom(l);
- if(r != Z)
- xcom(r);
- break;
- }
- if(n->addable >= 10)
- return;
-
- if(l != Z)
- n->complex = l->complex;
- if(r != Z) {
- if(r->complex == n->complex)
- n->complex = r->complex+1;
- else
- if(r->complex > n->complex)
- n->complex = r->complex;
- }
- if(n->complex == 0)
- n->complex++;
-
- switch(n->op) {
- case OFUNC:
- n->complex = FNX;
- break;
-
- case OEQ:
- case ONE:
- case OLE:
- case OLT:
- case OGE:
- case OGT:
- case OHI:
- case OHS:
- case OLO:
- case OLS:
- /*
- * immediate operators, make const on right
- */
- if(l->op == OCONST) {
- n->left = r;
- n->right = l;
- n->op = invrel[relindex(n->op)];
- }
- break;
-
- case OADD:
- case OXOR:
- case OAND:
- case OOR:
- /*
- * immediate operators, make const on right
- */
- if(l->op == OCONST) {
- n->left = r;
- n->right = l;
- }
- break;
- }
-}
-
diff --git a/sys/src/cmd/7c/swt.c b/sys/src/cmd/7c/swt.c
deleted file mode 100644
index 229558d86..000000000
--- a/sys/src/cmd/7c/swt.c
+++ /dev/null
@@ -1,578 +0,0 @@
-#include "gc.h"
-
-void
-swit1(C1 *q, int nc, long def, Node *n)
-{
- Node tn;
-
- regalloc(&tn, &regnode, Z);
- swit2(q, nc, def, n, &tn);
- regfree(&tn);
-}
-
-void
-swit2(C1 *q, int nc, long def, Node *n, Node *tn)
-{
- C1 *r;
- int i;
- Prog *sp;
-
- if(nc < 5) {
- for(i=0; i<nc; i++) {
- if(debug['W'])
- print("case = %.8llux\n", q->val);
- if(bval(q->val)) {
- gopcode(OEQ, n, Z, nodconst(q->val));
- } else {
- gopcode(OSUB, nodconst(q->val), n, tn);
- gopcode(OEQ, tn, Z, nodconst(0));
- }
- patch(p, q->label);
- q++;
- }
- gbranch(OGOTO);
- patch(p, def);
- return;
- }
- i = nc / 2;
- r = q+i;
- if(bval(r->val)) {
- gopcode(OGE, n, Z, nodconst(r->val));
- sp = p;
- swit2(q, i, def, n, tn);
-
- patch(sp, pc);
- swit2(r, nc-i, def, n, tn);
- } else {
- gopcode(OSUB, nodconst(r->val), n, tn);
- gopcode(OGE, tn, Z, nodconst(0));
- sp = p;
- swit2(q, i, def, n, tn);
-
- patch(sp, pc);
- swit2(r, nc-i, def, n, tn);
- }
-/* if(debug['W'])
- print("case > %.8llux\n", r->val);
- gmove(nodconst(r->val), tn);
- gopcode(OLT, tn, n, Z);
- sp = p;
- gopcode(OEQ, n, tn, Z);
- patch(p, r->label);
- swit2(q, i, def, n, tn);
-
- if(debug['W'])
- print("case < %.8llux\n", r->val);
- patch(sp, pc);
- swit2(r+1, nc-i-1, def, n, tn); */
-}
-
-void
-bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
- int sh;
- long v;
- Node *l;
-
- /*
- * n1 gets adjusted/masked value
- * n2 gets address of cell
- * n3 gets contents of cell
- */
- l = b->left;
- if(n2 != Z) {
- regalloc(n1, l, nn);
- reglcgen(n2, l, Z);
- regalloc(n3, l, Z);
- gopcode(OAS, n2, Z, n3);
- gopcode(OAS, n3, Z, n1);
- } else {
- regalloc(n1, l, nn);
- cgen(l, n1);
- }
- if(b->type->shift == 0 && typeu[b->type->etype]) {
- v = ~0 + (1L << b->type->nbits);
- gopcode(OAND, nodconst(v), Z, n1);
- } else {
- sh = 32 - b->type->shift - b->type->nbits;
- if(sh > 0)
- gopcode(OASHL, nodconst(sh), Z, n1);
- sh += b->type->shift;
- if(sh > 0)
- if(typeu[b->type->etype])
- gopcode(OLSHR, nodconst(sh), Z, n1);
- else
- gopcode(OASHR, nodconst(sh), Z, n1);
- }
-}
-
-void
-bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
-{
- long v;
- Node nod, *l;
- int sh;
-
- /*
- * n1 has adjusted/masked value
- * n2 has address of cell
- * n3 has contents of cell
- */
- l = b->left;
- regalloc(&nod, l, Z);
- v = ~0 + (1L << b->type->nbits);
- gopcode(OAND, nodconst(v), Z, n1);
- gopcode(OAS, n1, Z, &nod);
- if(nn != Z)
- gopcode(OAS, n1, Z, nn);
- sh = b->type->shift;
- if(sh > 0)
- gopcode(OASHL, nodconst(sh), Z, &nod);
- v <<= sh;
- gopcode(OAND, nodconst(~v), Z, n3);
- gopcode(OOR, n3, Z, &nod);
- gopcode(OAS, &nod, Z, n2);
-
- regfree(&nod);
- regfree(n1);
- regfree(n2);
- regfree(n3);
-}
-
-long
-outstring(char *s, long n)
-{
- long r;
-
- if(suppress)
- return nstring;
- r = nstring;
- while(n) {
- string[mnstring] = *s++;
- mnstring++;
- nstring++;
- if(mnstring >= NSNAME) {
- gpseudo(ADATA, symstring, nodconst(0L));
- p->from.offset += nstring - NSNAME;
- p->reg = NSNAME;
- p->to.type = D_SCONST;
- memmove(p->to.sval, string, NSNAME);
- mnstring = 0;
- }
- n--;
- }
- return r;
-}
-
-int
-mulcon(Node *n, Node *nn)
-{
- Node *l, *r, nod1, nod2;
- Multab *m;
- long v;
- int o;
- char code[sizeof(m->code)+2], *p;
-
- if(typefd[n->type->etype])
- return 0;
- l = n->left;
- r = n->right;
- if(l->op == OCONST) {
- l = r;
- r = n->left;
- }
- if(r->op != OCONST)
- return 0;
- v = convvtox(r->vconst, n->type->etype);
- if(v != r->vconst) {
- if(debug['M'])
- print("%L multiply conv: %lld\n", n->lineno, r->vconst);
- return 0;
- }
- m = mulcon0(v);
- if(!m) {
- if(debug['M'])
- print("%L multiply table: %lld\n", n->lineno, r->vconst);
- return 0;
- }
- if(debug['M'] && debug['v'])
- print("%L multiply: %ld\n", n->lineno, v);
-
- memmove(code, m->code, sizeof(m->code));
- code[sizeof(m->code)] = 0;
-
- p = code;
- if(p[1] == 'i')
- p += 2;
- regalloc(&nod1, n, nn);
- cgen(l, &nod1);
- if(v < 0)
- gopcode(OSUB, &nod1, nodconst(0), &nod1);
- regalloc(&nod2, n, Z);
-
-loop:
- switch(*p) {
- case 0:
- regfree(&nod2);
- gopcode(OAS, &nod1, Z, nn);
- regfree(&nod1);
- return 1;
- case '+':
- o = OADD;
- goto addsub;
- case '-':
- o = OSUB;
- addsub: /* number is r,n,l */
- v = p[1] - '0';
- r = &nod1;
- if(v&4)
- r = &nod2;
- n = &nod1;
- if(v&2)
- n = &nod2;
- l = &nod1;
- if(v&1)
- l = &nod2;
- gopcode(o, l, n, r);
- break;
- default: /* op is shiftcount, number is r,l */
- v = p[1] - '0';
- r = &nod1;
- if(v&2)
- r = &nod2;
- l = &nod1;
- if(v&1)
- l = &nod2;
- v = *p - 'a';
- if(v < 0 || v >= 32) {
- diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
- break;
- }
- gopcode(OASHL, nodconst(v), l, r);
- break;
- }
- p += 2;
- goto loop;
-}
-
-void
-sextern(Sym *s, Node *a, long o, long w)
-{
- long e, lw;
-
- for(e=0; e<w; e+=NSNAME) {
- lw = NSNAME;
- if(w-e < lw)
- lw = w-e;
- gpseudo(ADATA, s, nodconst(0));
- p->from.offset += o+e;
- p->reg = lw;
- p->to.type = D_SCONST;
- memmove(p->to.sval, a->cstring+e, lw);
- }
-}
-
-void
-gextern(Sym *s, Node *a, long o, long w)
-{
- gpseudo(ADATA, s, a);
- p->from.offset += o;
- p->reg = w;
- if(p->to.type == D_OREG)
- p->to.type = D_CONST;
-}
-
-void zname(Biobuf*, char*, int, int);
-char* zaddr(char*, Adr*, int);
-void zwrite(Biobuf*, Prog*, int, int);
-void outhist(Biobuf*);
-
-void
-zwrite(Biobuf *b, Prog *p, int sf, int st)
-{
- char bf[100], *bp;
-
- bf[0] = p->as;
- bf[1] = p->reg;
- bf[2] = p->lineno;
- bf[3] = p->lineno>>8;
- bf[4] = p->lineno>>16;
- bf[5] = p->lineno>>24;
- bp = zaddr(bf+6, &p->from, sf);
- bp = zaddr(bp, &p->to, st);
- Bwrite(b, bf, bp-bf);
-}
-
-void
-outcode(void)
-{
- struct { Sym *sym; short type; } h[NSYM];
- Prog *p;
- Sym *s;
- int sf, st, t, sym;
-
- if(debug['S']) {
- for(p = firstp; p != P; p = p->link)
- if(p->as != ADATA && p->as != AGLOBL)
- pc--;
- for(p = firstp; p != P; p = p->link) {
- print("%P\n", p);
- if(p->as != ADATA && p->as != AGLOBL)
- pc++;
- }
- }
- outhist(&outbuf);
- for(sym=0; sym<NSYM; sym++) {
- h[sym].sym = S;
- h[sym].type = 0;
- }
- sym = 1;
- for(p = firstp; p != P; p = p->link) {
- jackpot:
- sf = 0;
- s = p->from.sym;
- while(s != S) {
- sf = s->sym;
- if(sf < 0 || sf >= NSYM)
- sf = 0;
- t = p->from.name;
- if(h[sf].type == t)
- if(h[sf].sym == s)
- break;
- zname(&outbuf, s->name, t, sym);
- s->sym = sym;
- h[sym].sym = s;
- h[sym].type = t;
- sf = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- break;
- }
- st = 0;
- s = p->to.sym;
- while(s != S) {
- st = s->sym;
- if(st < 0 || st >= NSYM)
- st = 0;
- t = p->to.name;
- if(h[st].type == t)
- if(h[st].sym == s)
- break;
- zname(&outbuf, s->name, t, sym);
- s->sym = sym;
- h[sym].sym = s;
- h[sym].type = t;
- st = sym;
- sym++;
- if(sym >= NSYM)
- sym = 1;
- if(st == sf)
- goto jackpot;
- break;
- }
- zwrite(&outbuf, p, sf, st);
- }
- firstp = P;
- lastp = P;
-}
-
-void
-outhist(Biobuf *b)
-{
- Hist *h;
- char *p, *q, *op;
- Prog pg;
- int n;
-
- pg = zprog;
- pg.as = AHISTORY;
- for(h = hist; h != H; h = h->link) {
- p = h->name;
- op = 0;
- if(p && p[0] != '/' && h->offset == 0 && pathname && pathname[0] == '/') {
- op = p;
- p = pathname;
- }
- while(p) {
- q = utfrune(p, '/');
- if(q) {
- n = q-p;
- if(n == 0)
- n = 1; /* leading "/" */
- q++;
- } else {
- n = strlen(p);
- q = 0;
- }
- if(n) {
- Bputc(b, ANAME);
- Bputc(b, D_FILE);
- Bputc(b, 1);
- Bputc(b, '<');
- Bwrite(b, p, n);
- Bputc(b, 0);
- }
- p = q;
- if(p == 0 && op) {
- p = op;
- op = 0;
- }
- }
- pg.lineno = h->line;
- pg.to.type = zprog.to.type;
- pg.to.offset = h->offset;
- if(h->offset)
- pg.to.type = D_CONST;
-
- zwrite(b, &pg, 0, 0);
- }
-}
-
-void
-zname(Biobuf *b, char *n, int t, int s)
-{
- char bf[3];
-
- bf[0] = ANAME;
- bf[1] = t; /* type */
- bf[2] = s; /* sym */
- Bwrite(b, bf, 3);
- Bwrite(b, n, strlen(n)+1);
-}
-
-char*
-zaddr(char *bp, Adr *a, int s)
-{
- long l;
- vlong v;
- Ieee e;
-
- bp[0] = a->type;
- bp[1] = a->reg;
- bp[2] = s;
- bp[3] = a->name;
- bp += 4;
- switch(a->type) {
- default:
- diag(Z, "unknown type %d in zaddr", a->type);
-
- case D_NONE:
- case D_REG:
- case D_FREG:
- case D_FCREG:
- break;
-
- case D_OREG:
- case D_CONST:
- case D_BRANCH:
- v = a->offset;
- bp[0] = v;
- bp[1] = v>>8;
- bp[2] = v>>16;
- bp[3] = v>>24;
- bp[4] = v>>32;
- bp[5] = v>>40;
- bp[6] = v>>48;
- bp[7] = v>>56;
- bp += 8;
- break;
-
- case D_SCONST:
- memmove(bp, a->sval, NSNAME);
- bp += NSNAME;
- break;
-
- case D_FCONST:
- ieeedtod(&e, a->dval);
- l = e.l;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4;
- l = e.h;
- bp[0] = l;
- bp[1] = l>>8;
- bp[2] = l>>16;
- bp[3] = l>>24;
- bp += 4;
- break;
- }
- return bp;
-}
-
-long
-align(long i, Type *t, int op)
-{
- long o;
- Type *v;
- int w;
-
- o = i;
- w = 1;
- switch(op) {
- default:
- diag(Z, "unknown align opcode %d", op);
- break;
-
- case Asu2: /* padding at end of a struct */
- w = SZ_VLONG;
- if(packflg)
- w = packflg;
- break;
-
- case Ael1: /* initial allign of struct element */
- for(v=t; v->etype==TARRAY; v=v->link)
- ;
- w = ewidth[v->etype];
- if(w <= 0 || w >= SZ_VLONG)
- w = SZ_VLONG;
- if(packflg)
- w = packflg;
- break;
-
- case Ael2: /* width of a struct element */
- o += t->width;
- break;
-
- case Aarg0: /* initial passbyptr argument in arg list */
- if(typesu[t->etype]) {
- o = align(o, types[TIND], Aarg1);
- o = align(o, types[TIND], Aarg2);
- }
- break;
-
- case Aarg1: /* initial allign of parameter */
- w = ewidth[t->etype];
- if(w <= 0 || w >= SZ_VLONG) {
- w = SZ_VLONG;
- break;
- }
- w = 1; /* little endian no adjustment */
- break;
-
- case Aarg2: /* width of a parameter */
- o += t->width;
- w = SZ_LONG;
- break;
-
- case Aaut3: /* total allign of automatic */
- o = align(o, t, Ael1);
- o = align(o, t, Ael2);
- break;
- }
- o = round(o, w);
- if(debug['A'])
- print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
- return o;
-}
-
-long
-maxround(long max, long v)
-{
- v += SZ_VLONG-1;
- if(v > max)
- max = round(v, SZ_VLONG);
- return max;
-}
diff --git a/sys/src/cmd/7c/txt.c b/sys/src/cmd/7c/txt.c
deleted file mode 100644
index ef6bd0fbd..000000000
--- a/sys/src/cmd/7c/txt.c
+++ /dev/null
@@ -1,1306 +0,0 @@
-#include "gc.h"
-
-void
-ginit(void)
-{
- Type *t;
-
- thechar = '7';
- thestring = "alpha";
- exregoffset = REGEXT;
- exfregoffset = FREGEXT;
- listinit();
- nstring = 0;
- mnstring = 0;
- nrathole = 0;
- pc = 0;
- breakpc = -1;
- continpc = -1;
- cases = C;
- firstp = P;
- lastp = P;
- tfield = types[TLONG];
-
- typeword = typechlvp;
- typecmplx = typesu;
-
- zprog.link = P;
- zprog.as = AGOK;
- zprog.reg = NREG;
- zprog.from.type = D_NONE;
- zprog.from.name = D_NONE;
- zprog.from.reg = NREG;
- zprog.to = zprog.from;
-
- regnode.op = OREGISTER;
- regnode.class = CEXREG;
- regnode.reg = REGTMP;
- regnode.complex = 0;
- regnode.addable = 11;
- regnode.type = types[TLONG];
-
- constnode.op = OCONST;
- constnode.class = CXXX;
- constnode.complex = 0;
- constnode.addable = 20;
- constnode.type = types[TLONG];
-
- fconstnode.op = OCONST;
- fconstnode.class = CXXX;
- fconstnode.complex = 0;
- fconstnode.addable = 20;
- fconstnode.type = types[TDOUBLE];
-
- nodsafe = new(ONAME, Z, Z);
- nodsafe->sym = slookup(".safe");
- nodsafe->type = types[TINT];
- nodsafe->etype = types[TINT]->etype;
- nodsafe->class = CAUTO;
- complex(nodsafe);
-
- t = typ(TARRAY, types[TCHAR]);
- symrathole = slookup(".rathole");
- symrathole->class = CGLOBL;
- symrathole->type = t;
-
- nodrat = new(ONAME, Z, Z);
- nodrat->sym = symrathole;
- nodrat->type = types[TIND];
- nodrat->etype = TVOID;
- nodrat->class = CGLOBL;
- complex(nodrat);
- nodrat->type = t;
-
- nodret = new(ONAME, Z, Z);
- nodret->sym = slookup(".ret");
- nodret->type = types[TIND];
- nodret->etype = TIND;
- nodret->class = CPARAM;
- nodret = new(OIND, nodret, Z);
- complex(nodret);
-
- memset(reg, 0, sizeof(reg));
- reg[REGZERO] = 1;
-}
-
-void
-gclean(void)
-{
- int i;
- Sym *s;
-
- for(i=0; i<NREG; i++)
- if(i != REGZERO)
- if(reg[i])
- diag(Z, "reg %d left allocated", i);
- for(i=NREG; i<NREG+NREG; i+=2)
- if(reg[i])
- diag(Z, "freg %d left allocated", i-NREG);
- while(mnstring)
- outstring("", 1L);
- symstring->type->width = nstring;
- symrathole->type->width = nrathole;
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link) {
- if(s->type == T)
- continue;
- if(s->type->width == 0)
- continue;
- if(s->class != CGLOBL && s->class != CSTATIC)
- continue;
- if(s->type == types[TENUM])
- continue;
- gpseudo(AGLOBL, s, nodconst(s->type->width));
- }
- nextpc();
- p->as = AEND;
- outcode();
-}
-
-void
-nextpc(void)
-{
-
- p = alloc(sizeof(*p));
- *p = zprog;
- p->lineno = nearln;
- pc++;
- if(firstp == P) {
- firstp = p;
- lastp = p;
- return;
- }
- lastp->link = p;
- lastp = p;
-}
-
-void
-gargs(Node *n, Node *tn1, Node *tn2)
-{
- long regs;
- Node fnxargs[20], *fnxp;
-
- regs = cursafe;
-
- fnxp = fnxargs;
- garg1(n, tn1, tn2, 0, &fnxp); /* compile fns to temps */
-
- curarg = 0;
- fnxp = fnxargs;
- garg1(n, tn1, tn2, 1, &fnxp); /* compile normal args and temps */
-
- cursafe = regs;
-}
-
-void
-garg1(Node *n, Node *tn1, Node *tn2, int f, Node **fnxp)
-{
- Node nod;
-
- if(n == Z)
- return;
- if(n->op == OLIST) {
- garg1(n->left, tn1, tn2, f, fnxp);
- garg1(n->right, tn1, tn2, f, fnxp);
- return;
- }
- if(f == 0) {
- if(n->complex >= FNX) {
- regsalloc(*fnxp, n);
- nod = znode;
- nod.op = OAS;
- nod.left = *fnxp;
- nod.right = n;
- nod.type = n->type;
- cgen(&nod, Z);
- (*fnxp)++;
- }
- return;
- }
- if(typesu[n->type->etype]) {
- regaalloc(tn2, n);
- if(n->complex >= FNX) {
- sugen(*fnxp, tn2, n->type->width);
- (*fnxp)++;
- } else
- sugen(n, tn2, n->type->width);
- return;
- }
- if(REGARG != NREG && curarg == 0 &&
- (typechlp[n->type->etype] || typev[n->type->etype])) {
- regaalloc1(tn1, n);
- if(n->complex >= FNX) {
- cgen(*fnxp, tn1);
- (*fnxp)++;
- } else
- cgen(n, tn1);
- return;
- }
- if(vconst(n) == 0) {
- regaalloc(tn2, n);
- gopcode(OAS, n, Z, tn2);
- return;
- }
- regalloc(tn1, n, Z);
- if(n->complex >= FNX) {
- cgen(*fnxp, tn1);
- (*fnxp)++;
- } else
- cgen(n, tn1);
- regaalloc(tn2, n);
- gopcode(OAS, tn1, Z, tn2);
- regfree(tn1);
-}
-
-Node*
-nodconst(long v)
-{
- constnode.vconst = v;
- return &constnode;
-}
-
-Node*
-nodfconst(double d)
-{
- fconstnode.fconst = d;
- return &fconstnode;
-}
-
-void
-nodreg(Node *n, Node *nn, int reg)
-{
- *n = regnode;
- n->reg = reg;
- n->type = nn->type;
- n->lineno = nn->lineno;
-}
-
-void
-regret(Node *n, Node *nn)
-{
- int r;
-
- r = REGRET;
- if(typefd[nn->type->etype])
- r = FREGRET+NREG;
- nodreg(n, nn, r);
- reg[r]++;
-}
-
-void
-regalloc(Node *n, Node *tn, Node *o)
-{
- int i, j;
- static int lasti;
-
- switch(tn->type->etype) {
- case TCHAR:
- case TUCHAR:
- case TSHORT:
- case TUSHORT:
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TIND:
- case TVLONG:
- case TUVLONG:
- if(o != Z && o->op == OREGISTER) {
- i = o->reg;
- if(i >= 0 && i < NREG - 1)
- goto out;
- }
- j = lasti + REGRET+1;
- for(i=REGRET+1; i<NREG; i++) {
- if(j >= NREG)
- j = REGRET+1;
- if(reg[j] == 0) {
- i = j;
- goto out;
- }
- j++;
- }
- diag(tn, "out of fixed registers");
- goto err;
-
- case TFLOAT:
- case TDOUBLE:
- if(o != Z && o->op == OREGISTER) {
- i = o->reg;
- if(i >= NREG && i < NREG+NREG)
- goto out;
- }
- j = NREG + 12 + lasti;
- for(i=NREG; i<NREG+NREG; i++) {
- if(j >= NREG+NREG)
- j = NREG;
- if(reg[j] == 0) {
- i = j;
- goto out;
- }
- j++;
- }
- diag(tn, "out of float registers");
- goto err;
- }
- diag(tn, "unknown type in regalloc: %T", tn->type);
-err:
- i = -1;
-out:
- if(i >= 0)
- reg[i]++;
- lasti++;
- if(lasti >= 5)
- lasti = 0;
- nodreg(n, tn, i);
-}
-
-void
-regialloc(Node *n, Node *tn, Node *o)
-{
- Node nod;
-
- nod = *tn;
- nod.type = types[TIND];
- regalloc(n, &nod, o);
-}
-
-void
-regfree(Node *n)
-{
- int i;
-
- i = 0;
- if(n->op != OREGISTER && n->op != OINDREG)
- goto err;
- i = n->reg;
- if(i < 0 || i >= sizeof(reg))
- goto err;
- if(reg[i] <= 0)
- goto err;
- reg[i]--;
- return;
-err:
- diag(n, "error in regfree: %d op %O", i, n->op);
-}
-
-void
-regsalloc(Node *n, Node *nn)
-{
- cursafe = align(cursafe, nn->type, Aaut3);
- maxargsafe = maxround(maxargsafe, cursafe+curarg);
- *n = *nodsafe;
- n->xoffset = -(stkoff + cursafe);
- n->type = nn->type;
- n->etype = nn->type->etype;
- n->lineno = nn->lineno;
-}
-
-void
-regaalloc1(Node *n, Node *nn)
-{
- nodreg(n, nn, REGARG);
- reg[REGARG]++;
- curarg = align(curarg, nn->type, Aarg1);
- curarg = align(curarg, nn->type, Aarg2);
- maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regaalloc(Node *n, Node *nn)
-{
- curarg = align(curarg, nn->type, Aarg1);
- *n = *nn;
- n->op = OINDREG;
- n->reg = REGSP;
- n->xoffset = curarg + SZ_VLONG;
- n->complex = 0;
- n->addable = 20;
- curarg = align(curarg, nn->type, Aarg2);
- maxargsafe = maxround(maxargsafe, cursafe+curarg);
-}
-
-void
-regind(Node *n, Node *nn)
-{
-
- if(n->op != OREGISTER) {
- diag(n, "regind not OREGISTER");
- return;
- }
- n->op = OINDREG;
- n->type = nn->type;
-}
-
-void
-raddr(Node *n, Prog *p)
-{
- Adr a;
-
- naddr(n, &a);
- if(a.type == D_CONST && a.offset == 0) {
- a.type = D_REG;
- a.reg = 0;
- }
- if(a.type != D_REG && a.type != D_FREG) {
- if(n)
- diag(n, "bad in raddr: %O", n->op);
- else
- diag(n, "bad in raddr: <null>");
- p->reg = NREG;
- } else
- p->reg = a.reg;
-}
-
-void
-naddr(Node *n, Adr *a)
-{
- vlong v;
-
- a->type = D_NONE;
- if(n == Z)
- return;
- switch(n->op) {
- default:
- bad:
- diag(n, "bad in naddr: %O", n->op);
- break;
-
- case OREGISTER:
- a->type = D_REG;
- a->sym = S;
- a->reg = n->reg;
- if(a->reg >= NREG) {
- a->type = D_FREG;
- a->reg -= NREG;
- }
- break;
-
- case OIND:
- naddr(n->left, a);
- if(a->type == D_REG) {
- a->type = D_OREG;
- break;
- }
- if(a->type == D_CONST) {
- a->type = D_OREG;
- break;
- }
- goto bad;
-
- case OINDREG:
- a->type = D_OREG;
- a->sym = S;
- a->offset = n->xoffset;
- a->reg = n->reg;
- break;
-
- case ONAME:
- a->etype = n->etype;
- a->type = D_OREG;
- a->name = D_STATIC;
- a->sym = n->sym;
- a->offset = n->xoffset;
- if(n->class == CSTATIC)
- break;
- if(n->class == CEXTERN || n->class == CGLOBL) {
- a->name = D_EXTERN;
- break;
- }
- if(n->class == CAUTO) {
- a->name = D_AUTO;
- break;
- }
- if(n->class == CPARAM) {
- a->name = D_PARAM;
- break;
- }
- goto bad;
-
- case OCONST:
- a->sym = S;
- a->reg = NREG;
- if(typefd[n->type->etype]) {
- a->type = D_FCONST;
- a->dval = n->fconst;
- } else if(typev[n->type->etype]) {
- a->type = D_CONST;
- a->offset = n->vconst;
- } else {
- a->type = D_CONST;
- a->offset = convvtox(n->vconst, TLONG); /* alpha arithmetic */
- }
- break;
-
- case OADDR:
- naddr(n->left, a);
- if(a->type == D_OREG) {
- a->type = D_CONST;
- break;
- }
- goto bad;
-
- case OADD:
- if(n->left->op == OCONST) {
- naddr(n->left, a);
- v = a->offset;
- naddr(n->right, a);
- } else {
- naddr(n->right, a);
- v = a->offset;
- naddr(n->left, a);
- }
- a->offset += v;
- break;
-
- }
-}
-
-void
-fop(int as, int f1, int f2, Node *t)
-{
- Node nod1, nod2, nod3;
-
- nodreg(&nod1, t, NREG+f1);
- nodreg(&nod2, t, NREG+f2);
- regalloc(&nod3, t, t);
- gopcode(as, &nod1, &nod2, &nod3);
- gmove(&nod3, t);
- regfree(&nod3);
-}
-
-void
-gmove(Node *f, Node *t)
-{
- int ft, tt, a;
- Node nod;
- double d;
-
- ft = f->type->etype;
- tt = t->type->etype;
-
- if(ft == TDOUBLE && f->op == OCONST) {
- d = f->fconst;
- if(d == 0.0) {
- a = FREGZERO;
- goto ffreg;
- }
- if(d == 0.5) {
- a = FREGHALF;
- goto ffreg;
- }
- if(d == 1.0) {
- a = FREGONE;
- goto ffreg;
- }
- if(d == 2.0) {
- a = FREGTWO;
- goto ffreg;
- }
- if(d == -.5) {
- fop(OSUB, FREGHALF, FREGZERO, t);
- return;
- }
- if(d == -1.0) {
- fop(OSUB, FREGONE, FREGZERO, t);
- return;
- }
- if(d == -2.0) {
- fop(OSUB, FREGTWO, FREGZERO, t);
- return;
- }
- if(d == 1.5) {
- fop(OADD, FREGONE, FREGHALF, t);
- return;
- }
- if(d == 2.5) {
- fop(OADD, FREGTWO, FREGHALF, t);
- return;
- }
- if(d == 3.0) {
- fop(OADD, FREGTWO, FREGONE, t);
- return;
- }
- }
- if(ft == TFLOAT && f->op == OCONST) {
- d = f->fconst;
- if(d == 0) {
- a = FREGZERO;
- ffreg:
- nodreg(&nod, f, NREG+a);
- gmove(&nod, t);
- return;
- }
- }
- /*
- * a load --
- * put it into a register then
- * worry what to do with it.
- */
- if(f->op == ONAME || f->op == OINDREG || f->op == OIND) {
- switch(ft) {
- default:
- a = AMOVL;
- break;
- case TVLONG:
- case TUVLONG:
- /* todo: optimise freg case? */
- a = AMOVQ;
-#ifdef is_this_right
- if(typefd[tt]) {
- /* special case can load mem to Freg */
- regalloc(&nod, t, t);
- gins(AMOVL, f, &nod);
- a = ACVTQT;
- if(tt == TFLOAT)
- a = ACVTQS;
- gins(a, &nod, &nod);
- gmove(&nod, t);
- regfree(&nod);
- return;
- }
-#endif is_this_right
- break;
- case TFLOAT:
- a = AMOVS;
- break;
- case TDOUBLE:
- a = AMOVT;
- break;
- case TCHAR:
- a = AMOVB;
- break;
- case TUCHAR:
- a = AMOVBU;
- break;
- case TSHORT:
- a = AMOVW;
- break;
- case TUSHORT:
- a = AMOVWU;
- break;
- }
- if(typechlp[ft] && typeilp[tt])
- regalloc(&nod, t, t);
- else
- regalloc(&nod, f, t);
- gins(a, f, &nod);
- gmove(&nod, t);
- regfree(&nod);
- return;
- }
-
- /*
- * a store --
- * put it into a register then
- * store it.
- */
- if(t->op == ONAME || t->op == OINDREG || t->op == OIND) {
- switch(tt) {
- default:
- a = AMOVL;
- break;
- case TUCHAR:
- case TCHAR:
- a = AMOVB;
- break;
- case TUSHORT:
- case TSHORT:
- a = AMOVW;
- break;
- case TFLOAT:
- a = AMOVS;
- break;
- case TDOUBLE:
- a = AMOVT;
- break;
- case TVLONG:
- case TUVLONG:
- a = AMOVQ;
- break;
- }
- if(!typefd[ft] && vconst(f) == 0) {
- gins(a, f, t);
- return;
- }
- if(ft == tt)
- regalloc(&nod, t, f);
- else
- regalloc(&nod, t, Z);
- gmove(f, &nod);
- gins(a, &nod, t);
- regfree(&nod);
- return;
- }
-
- /*
- * type x type cross table
- */
- a = AGOK;
- switch(ft) {
- case TDOUBLE:
- case TFLOAT:
- switch(tt) {
- case TDOUBLE:
- a = AMOVT;
- break;
- case TFLOAT:
- a = ACVTTS;
- if(ft == TFLOAT)
- a = AMOVT;
- break;
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TUVLONG:
- case TVLONG:
- case TIND:
- case TSHORT:
- case TUSHORT:
- case TCHAR:
- case TUCHAR:
- /*warn(Z, "float to fix"); /**/
- regalloc(&nod, f, Z); /* should be type float */
- gins(ACVTTQ, f, &nod);
- gins(AMOVT, &nod, nodrat);
- regfree(&nod);
- gins(AMOVQ, nodrat, t);
- gmove(t, t);
- if(nrathole < SZ_VLONG)
- nrathole = SZ_VLONG;
- return;
- }
- break;
- case TVLONG:
- case TUVLONG:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- goto fxtofl;
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TIND:
- case TSHORT:
- case TUSHORT:
- case TCHAR:
- case TUCHAR:
- a = AMOVL;
- break;
- case TVLONG:
- case TUVLONG:
- a = AMOVQ;
- break;
- }
- break;
- case TINT:
- case TUINT:
- case TULONG:
- case TLONG:
- case TIND:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- goto fxtofl;
- case TVLONG:
- case TUVLONG:
- if (ft == TULONG || ft == TUINT) {
- a = AMOVLU;
- break;
- }
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TIND:
- case TSHORT:
- case TUSHORT:
- case TCHAR:
- case TUCHAR:
- a = AMOVQ;
- break;
- }
- break;
- case TSHORT:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- goto fxtofl;
- case TINT:
- case TUINT:
- case TULONG:
- case TLONG:
- case TVLONG:
- case TUVLONG:
- case TIND:
- a = AMOVW;
- break;
- case TSHORT:
- case TUSHORT:
- case TCHAR:
- case TUCHAR:
- a = AMOVQ;
- break;
- }
- break;
- case TUSHORT:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- goto fxtofl;
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TVLONG:
- case TUVLONG:
- case TIND:
- a = AMOVWU;
- break;
- case TSHORT:
- case TUSHORT:
- case TCHAR:
- case TUCHAR:
- a = AMOVQ;
- break;
- }
- break;
- case TCHAR:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- goto fxtofl;
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TVLONG:
- case TUVLONG:
- case TIND:
- case TSHORT:
- case TUSHORT:
- a = AMOVB;
- break;
- case TCHAR:
- case TUCHAR:
- a = AMOVQ;
- break;
- }
- break;
- case TUCHAR:
- switch(tt) {
- case TDOUBLE:
- case TFLOAT:
- fxtofl:
- /*warn(Z, "fix to float"); /**/
- regalloc(&nod, t, Z); /* should be type float */
- gins(AMOVQ, f, nodrat);
- gins(AMOVT, nodrat, &nod);
- a = ACVTQT;
- if(tt == TFLOAT)
- a = ACVTQS;
- gins(a, &nod, t);
- regfree(&nod);
- if(nrathole < SZ_VLONG)
- nrathole = SZ_VLONG;
- return;
- case TINT:
- case TUINT:
- case TLONG:
- case TULONG:
- case TVLONG:
- case TUVLONG:
- case TIND:
- case TSHORT:
- case TUSHORT:
- a = AMOVBU;
- break;
- case TCHAR:
- case TUCHAR:
- a = AMOVQ;
- break;
- }
- break;
- }
- if(a == AMOVQ || a == AMOVS || a == AMOVT)
- if(samaddr(f, t))
- return;
- gins(a, f, t);
-}
-
-void
-gins(int a, Node *f, Node *t)
-{
-
- nextpc();
- p->as = a;
- if(f != Z)
- naddr(f, &p->from);
- if(t != Z)
- naddr(t, &p->to);
- if(debug['g'])
- print("%P\n", p);
-}
-
-void
-gopcode(int o, Node *f1, Node *f2, Node *t)
-{
- int a, et;
- Adr ta;
- Node nod;
-
- et = TLONG;
- if(f1 != Z && f1->type != T) {
- if(f1->op == OCONST && t != Z && t->type != T)
- et = t->type->etype;
- else
- et = f1->type->etype;
- }
- a = AGOK;
- switch(o) {
- case OAS:
- gmove(f1, t);
- return;
-
- case OASADD:
- case OADD:
- a = AADDL;
- if(et == TFLOAT)
- a = AADDS;
- else
- if(et == TDOUBLE)
- a = AADDT;
- else
- if(et == TVLONG || et == TUVLONG)
- a = AADDQ;
- break;
-
- case OASSUB:
- case OSUB:
- a = ASUBL;
- if(et == TFLOAT)
- a = ASUBS;
- else
- if(et == TDOUBLE)
- a = ASUBT;
- else
- if(et == TVLONG || et == TUVLONG)
- a = ASUBQ;
- break;
-
- case OASOR:
- case OOR:
- a = AOR;
- break;
-
- case OASAND:
- case OAND:
- a = AAND;
- break;
-
- case OASXOR:
- case OXOR:
- a = AXOR;
- break;
-
- case OASLSHR:
- case OLSHR:
- a = ASRLL;
- if(et == TVLONG || et == TUVLONG)
- a = ASRLQ;
- break;
-
- case OASASHR:
- case OASHR:
- a = ASRAL;
- if(et == TVLONG || et == TUVLONG)
- a = ASRAQ;
- break;
-
- case OASASHL:
- case OASHL:
- a = ASLLL;
- if(et == TVLONG || et == TUVLONG)
- a = ASLLQ;
- break;
-
- case OFUNC:
- a = AJSR;
- break;
-
- case OASLMUL:
- case OLMUL:
- case OASMUL:
- case OMUL:
- a = AMULL;
- if(et == TFLOAT)
- a = AMULS;
- else
- if(et == TDOUBLE)
- a = AMULT;
- else
- if(et == TVLONG || et == TUVLONG)
- a = AMULQ;
- break;
-
- case OASDIV:
- case ODIV:
- a = ADIVL;
- if(et == TFLOAT)
- a = ADIVS;
- else
- if(et == TDOUBLE)
- a = ADIVT;
- else
- if(et == TVLONG || et == TUVLONG)
- a = ADIVQ;
- break;
-
- case OASMOD:
- case OMOD:
- a = AMODL;
- if(et == TVLONG || et == TUVLONG)
- a = AMODQ;
- break;
-
- case OASLMOD:
- case OLMOD:
- a = AMODLU;
- if(et == TVLONG || et == TUVLONG)
- a = AMODQU;
- break;
-
- case OASLDIV:
- case OLDIV:
- a = ADIVLU;
- if(et == TVLONG || et == TUVLONG)
- a = ADIVQU;
- break;
-
- case OEQ:
- case ONE:
- a = ACMPEQ;
- if(typefd[et])
- a = ACMPTEQ;
- else if (vconst(t) == 0) {
- a = (o == OEQ) ? ABEQ : ABNE;
- t = Z;
- break;
- }
- goto cmp;
-
- case OLT:
- case OGE:
- a = ACMPGT;
- if(typefd[et])
- a = ACMPTGT;
- else if (vconst(t) == 0) {
- a = (o == OLT) ? ABLT : ABGE;
- t = Z;
- break;
- }
- goto cmp;
-
- case OLE:
- case OGT:
- a = ACMPGE;
- if(typefd[et])
- a = ACMPTGE;
- else
- if(vconst(t) == 0) {
- a = (o == OLE)? ABLE: ABGT;
- t = Z;
- break;
- }
- goto cmp;
-
- case OLO:
- case OHS:
- a = ACMPUGT;
- goto cmp;
-
- case OLS:
- case OHI:
- a = ACMPUGE;
- goto cmp;
-
- cmp:
- nextpc();
- p->as = a;
- raddr(f1, p);
- naddr(t, &p->from);
- regalloc(&nod, t, Z);
- naddr(&nod, &p->to);
- if(debug['g'])
- print("%P\n", p);
- if(o == OEQ || o == OLT || o == OLE || o == OLO || o == OLS)
- a = typefd[et]? AFBNE: ABNE;
- else
- a = typefd[et]? AFBEQ: ABEQ;
- nextpc();
- p->as = a;
- naddr(&nod, &p->from);
- regfree(&nod);
- if(debug['g'])
- print("%P\n", p);
- return;
- }
- if(a == AGOK)
- diag(Z, "bad in gopcode %O", o);
- nextpc();
- p->as = a;
- if(f1 != Z)
- naddr(f1, &p->from);
- if(f2 != Z) {
- naddr(f2, &ta);
- p->reg = ta.reg;
- if(ta.type == D_CONST && ta.offset == 0)
- p->reg = REGZERO;
- }
- if(t != Z)
- naddr(t, &p->to);
- if(debug['g'])
- print("%P\n", p);
-}
-
-samaddr(Node *f, Node *t)
-{
-
- if(f->op != t->op)
- return 0;
- switch(f->op) {
-
- case OREGISTER:
- if(f->reg != t->reg)
- break;
- return 1;
- }
- return 0;
-}
-
-void
-gbranch(int o)
-{
- int a;
-
- a = AGOK;
- switch(o) {
- case ORETURN:
- a = ARET;
- break;
- case OGOTO:
- a = AJMP;
- break;
- }
- nextpc();
- if(a == AGOK) {
- diag(Z, "bad in gbranch %O", o);
- nextpc();
- }
- p->as = a;
-}
-
-void
-patch(Prog *op, long pc)
-{
-
- op->to.offset = pc;
- op->to.type = D_BRANCH;
-}
-
-void
-gpseudo(int a, Sym *s, Node *n)
-{
-
- nextpc();
- p->as = a;
- p->from.type = D_OREG;
- p->from.sym = s;
- if(a == ATEXT)
- p->reg = (profileflg ? 0 : NOPROF);
- p->from.name = D_EXTERN;
- if(s->class == CSTATIC)
- p->from.name = D_STATIC;
- naddr(n, &p->to);
- if(a == ADATA || a == AGLOBL)
- pc--;
-}
-
-int
-sconst(Node *n)
-{
- vlong vv;
-
- if(n->op == OCONST) {
- if(!typefd[n->type->etype]) {
- vv = n->vconst;
- if(vv >= -32766LL && vv < 32766LL)
- return 1;
- }
- }
- return 0;
-}
-
-int
-sval(long v)
-{
- if(v >= -32766L && v < 32766L)
- return 1;
- return 0;
-}
-
-int
-bval(vlong v)
-{
-
- if(v >= 0LL && v < 256LL)
- return 1;
- return 0;
-}
-
-int
-bconst(Node *n)
-{
- vlong vv;
-
- if(n->op == OCONST) {
- if(!typefd[n->type->etype]) {
- vv = n->vconst;
- if(vv >= 0LL && vv < 256LL)
- return 1;
- }
- }
- return 0;
-}
-
-long
-exreg(Type *t)
-{
- long o;
-
- if(typechlp[t->etype]) {
- if(exregoffset <= 12)
- return 0;
- o = exregoffset;
- exregoffset--;
- return o;
- }
- if(typefd[t->etype]) {
- if(exfregoffset <= 19)
- return 0;
- o = exfregoffset + NREG;
- exfregoffset--;
- return o;
- }
- return 0;
-}
-
-schar ewidth[NTYPE] =
-{
- -1, /* [TXXX] */
- SZ_CHAR, /* [TCHAR] */
- SZ_CHAR, /* [TUCHAR] */
- SZ_SHORT, /* [TSHORT] */
- SZ_SHORT, /* [TUSHORT] */
- SZ_INT, /* [TINT] */
- SZ_INT, /* [TUINT] */
- SZ_LONG, /* [TLONG] */
- SZ_LONG, /* [TULONG] */
- SZ_VLONG, /* [TVLONG] */
- SZ_VLONG, /* [TUVLONG] */
- SZ_FLOAT, /* [TFLOAT] */
- SZ_DOUBLE, /* [TDOUBLE] */
- SZ_IND, /* [TIND] */
- 0, /* [TFUNC] */
- -1, /* [TARRAY] */
- 0, /* [TVOID] */
- -1, /* [TSTRUCT] */
- -1, /* [TUNION] */
- SZ_INT, /* [TENUM] */
-};
-
-long ncast[NTYPE] =
-{
- 0, /* [TXXX] */
- BCHAR|BUCHAR, /* [TCHAR] */
- BCHAR|BUCHAR, /* [TUCHAR] */
- BSHORT|BUSHORT, /* [TSHORT] */
- BSHORT|BUSHORT, /* [TUSHORT] */
- BINT|BUINT|BLONG|BULONG|BIND, /* [TINT] */
- BINT|BUINT|BLONG|BULONG|BIND, /* [TUINT] */
- BINT|BUINT|BLONG|BULONG|BIND, /* [TLONG] */
- BINT|BUINT|BLONG|BULONG|BIND, /* [TULONG] */
- BVLONG|BUVLONG, /* [TVLONG] */
- BVLONG|BUVLONG, /* [TUVLONG] */
- BFLOAT, /* [TFLOAT] */
- BDOUBLE, /* [TDOUBLE] */
- BLONG|BULONG|BIND, /* [TIND] */
- 0, /* [TFUNC] */
- 0, /* [TARRAY] */
- 0, /* [TVOID] */
- BSTRUCT, /* [TSTRUCT] */
- BUNION, /* [TUNION] */
- 0, /* [TENUM] */
-};
diff --git a/sys/src/cmd/7l/asm.c b/sys/src/cmd/7l/asm.c
deleted file mode 100644
index a92ab88b5..000000000
--- a/sys/src/cmd/7l/asm.c
+++ /dev/null
@@ -1,1220 +0,0 @@
-#include "l.h"
-
-#define LPUT(c)\
- {\
- cbp[0] = (c);\
- cbp[1] = (c)>>8;\
- cbp[2] = (c)>>16;\
- cbp[3] = (c)>>24;\
- cbp += 4;\
- cbc -= 4;\
- if(cbc <= 0)\
- cflush();\
- }
-
-#define CPUT(c)\
- {\
- cbp[0] = (c);\
- cbp++;\
- cbc--;\
- if(cbc <= 0)\
- cflush();\
- }
-
-#define VLPUT(c)\
- {\
- cbp[0] = (c);\
- cbp[1] = (c)>>8;\
- cbp[2] = (c)>>16;\
- cbp[3] = (c)>>24;\
- cbp[4] = (c)>>32;\
- cbp[5] = (c)>>40;\
- cbp[6] = (c)>>48;\
- cbp[7] = (c)>>56;\
- cbp += 8;\
- cbc -= 8;\
- if(cbc <= 0)\
- cflush();\
- }
-#define LPUTBE(c)\
- {\
- cbp[0] = (c)>>24;\
- cbp[1] = (c)>>16;\
- cbp[2] = (c)>>8;\
- cbp[3] = (c);\
- cbp += 4;\
- cbc -= 4;\
- if(cbc <= 0)\
- cflush();\
- }
-
-long
-entryvalue(void)
-{
- char *a;
- Sym *s;
-
- a = INITENTRY;
- if(*a >= '0' && *a <= '9')
- return atolwhex(a);
- s = lookup(a, 0);
- if(s->type == 0)
- return INITTEXT;
- if(s->type != STEXT && s->type != SLEAF)
- diag("entry not text: %s", s->name);
- return s->value;
-}
-
-void
-asmb(void)
-{
- Prog *p;
- vlong t;
- Optab *o;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f asm\n", cputime());
- Bflush(&bso);
- seek(cout, HEADR, 0);
- pc = INITTEXT;
- for(p = firstp; p != P; p = p->link) {
- if(p->as == ATEXT) {
- curtext = p;
- autosize = p->to.offset + 8;
- }
- if(p->pc != pc) {
- diag("phase error %lux sb %lux",
- p->pc, pc);
- if(!debug['a'])
- prasm(curp);
- pc = p->pc;
- }
- if (p->as == AMOVQ || p->as == AMOVT) {
- if ((p->from.reg == REGSP) && (p->from.offset&7) != 0
- || (p->to.reg == REGSP) && (p->to.offset&7) != 0)
- diag("bad stack alignment: %P", p);
- if ((p->from.reg == REGSB) && (p->from.offset&7) != 0
- || (p->to.reg == REGSB) && (p->to.offset&7) != 0)
- diag("bad global alignment: %P", p);
- }
- curp = p;
- o = oplook(p); /* could probably avoid this call */
- if(asmout(p, o)) {
- p = p->link;
- pc += 4;
- }
- pc += o->size;
- }
- if(debug['a'])
- Bprint(&bso, "\n");
- Bflush(&bso);
- cflush();
-
- curtext = P;
- switch(HEADTYPE) {
- case 0:
- seek(cout, rnd(HEADR+textsize, 8192), 0);
- break;
- case 1:
- case 2:
- case 3:
- seek(cout, HEADR+textsize, 0);
- break;
- }
- for(t = 0; t < datsize; t += sizeof(buf)-100) {
- if(datsize-t > sizeof(buf)-100)
- datblk(t, sizeof(buf)-100);
- else
- datblk(t, datsize-t);
- }
-
- symsize = 0;
- lcsize = 0;
- if(!debug['s']) {
- if(debug['v'])
- Bprint(&bso, "%5.2f sym\n", cputime());
- Bflush(&bso);
- switch(HEADTYPE) {
- case 0:
- seek(cout, rnd(HEADR+textsize, 8192)+datsize, 0);
- break;
- case 2:
- case 1:
- case 3:
- seek(cout, HEADR+textsize+datsize, 0);
- break;
- }
- if(!debug['s'])
- asmsym();
- if(debug['v'])
- Bprint(&bso, "%5.2f pc\n", cputime());
- Bflush(&bso);
- if(!debug['s'])
- asmlc();
- cflush();
- }
-
- if(debug['v'])
- Bprint(&bso, "%5.2f header\n", cputime());
- Bflush(&bso);
- seek(cout, 0L, 0);
- switch(HEADTYPE) {
- case 0:
- lput(0x0183L); /* magic and sections */
- lput(0L); /* time and date */
- vlput(rnd(HEADR+textsize, 8192)+datsize);
- lput(symsize); /* nsyms */
- lput(0x50L|(7L<<16)); /* size of optional hdr and flags */
- lput(0413|(0x101L<<16)); /* magic and version */
- lput(-1); /* pad for alignment */
-
- vlput(rnd(HEADR+textsize, 8192)); /* sizes */
- vlput(datsize);
- vlput(bsssize);
- vlput(entryvalue()); /* va of entry */
- vlput(INITTEXT-HEADR); /* va of base of text */
- vlput(INITDAT); /* va of base of data */
- vlput(INITDAT+datsize); /* va of base of bss */
- lput(~0L); /* gp reg mask */
- /* dubious stuff starts here */
- lput(0L);
- lput(0L);
- lput(0L);
- lput(0L);
- lput(~0L); /* gp value ?? */
- break;
- case 1:
- lput(0x0183L); /* magic and sections */
- lput(0L); /* time and date */
- vlput(HEADR+textsize+datsize);
- lput(symsize); /* nsyms */
- lput(0x54L|(7L<<16)); /* size of optional hdr and flags */
- lput(0407|(0x101L<<16)); /* magic and version */
- lput(-1); /* pad for alignment */
-
- vlput(textsize); /* sizes */
- vlput(datsize);
- vlput(bsssize);
- vlput(entryvalue()); /* va of entry */
- vlput(INITTEXT); /* va of base of text */
- vlput(INITDAT); /* va of base of data */
- vlput(INITDAT+datsize); /* va of base of bss */
- lput(~0L); /* gp reg mask */
- /* dubious stuff starts here */
- lput(lcsize);
- lput(0L);
- lput(0L);
- lput(0L);
- lput(~0L); /* gp value ?? */
- lput(0L); /* complete mystery */
- break;
- case 2:
- lputbe(0x84b); /* magic */
- lputbe(textsize); /* sizes */
- lputbe(datsize);
- lputbe(bsssize);
- lputbe(symsize); /* nsyms */
- lputbe(entryvalue()); /* va of entry */
- lputbe(0L);
- lputbe(lcsize);
- break;
- case 3:
- /* ``headerless'' boot image -- magic no is a branch */
- lput(0xc3e00007); /* magic (branch) */
- lputbe(textsize); /* sizes */
- lputbe(datsize);
- lputbe(bsssize);
- lputbe(symsize); /* nsyms */
- lputbe(entryvalue()); /* va of entry */
- lputbe(0L);
- lputbe(lcsize);
- break;
- }
- cflush();
-}
-
-void
-lput(long l)
-{
- LPUT(l);
-}
-
-void
-lputbe(long l)
-{
- LPUTBE(l);
-}
-
-void
-vlput(vlong l)
-{
- VLPUT(l);
-}
-
-void
-cflush(void)
-{
- int n;
-
- n = sizeof(buf.cbuf) - cbc;
- if(n)
- write(cout, buf.cbuf, n);
- cbp = buf.cbuf;
- cbc = sizeof(buf.cbuf);
-}
-
-void
-asmsym(void)
-{
- Prog *p;
- Auto *a;
- Sym *s;
- int h;
-
- s = lookup("etext", 0);
- if(s->type == STEXT)
- putsymb(s->name, 'T', s->value, s->version);
-
- for(h=0; h<NHASH; h++)
- for(s=hash[h]; s!=S; s=s->link)
- switch(s->type) {
- case SCONST:
- putsymb(s->name, 'D', s->value, s->version);
- continue;
-
- case SDATA:
- putsymb(s->name, 'D', s->value+INITDAT, s->version);
- continue;
-
- case SBSS:
- putsymb(s->name, 'B', s->value+INITDAT, s->version);
- continue;
-
- case SFILE:
- putsymb(s->name, 'f', s->value, s->version);
- continue;
- }
-
- for(p=textp; p!=P; p=p->cond) {
- s = p->from.sym;
- if(s->type != STEXT && s->type != SLEAF)
- continue;
-
- /* filenames first */
- for(a=p->to.autom; a; a=a->link)
- if(a->type == D_FILE)
- putsymb(a->sym->name, 'z', a->offset, 0);
- else
- if(a->type == D_FILE1)
- putsymb(a->sym->name, 'Z', a->offset, 0);
-
- if(s->type == STEXT)
- putsymb(s->name, 'T', s->value, s->version);
- else
- putsymb(s->name, 'L', s->value, s->version);
-
- /* frame, auto and param after */
- putsymb(".frame", 'm', p->to.offset+8, 0);
- for(a=p->to.autom; a; a=a->link)
- if(a->type == D_AUTO)
- putsymb(a->sym->name, 'a', -a->offset, 0);
- else
- if(a->type == D_PARAM)
- putsymb(a->sym->name, 'p', a->offset, 0);
- }
- if(debug['v'] || debug['n'])
- Bprint(&bso, "symsize = %lud\n", symsize);
- Bflush(&bso);
-}
-
-void
-putsymb(char *s, int t, long v, int ver)
-{
- int i, f;
-
- if(t == 'f')
- s++;
- LPUTBE(v);
- if(ver)
- t += 'a' - 'A';
- CPUT(t+0x80); /* 0x80 is variable length */
-
- if(t == 'Z' || t == 'z') {
- CPUT(s[0]);
- for(i=1; s[i] != 0 || s[i+1] != 0; i += 2) {
- CPUT(s[i]);
- CPUT(s[i+1]);
- }
- CPUT(0);
- CPUT(0);
- i++;
- }
- else {
- for(i=0; s[i]; i++)
- CPUT(s[i]);
- CPUT(0);
- }
- symsize += 4 + 1 + i + 1;
-
- if(debug['n']) {
- if(t == 'z' || t == 'Z') {
- Bprint(&bso, "%c %.8lux ", t, v);
- for(i=1; s[i] != 0 || s[i+1] != 0; i+=2) {
- f = ((s[i]&0xff) << 8) | (s[i+1]&0xff);
- Bprint(&bso, "/%x", f);
- }
- Bprint(&bso, "\n");
- return;
- }
- if(ver)
- Bprint(&bso, "%c %.8lux %s<%d>\n", t, v, s, ver);
- else
- Bprint(&bso, "%c %.8lux %s\n", t, v, s);
- }
-}
-
-#define MINLC 4
-void
-asmlc(void)
-{
- long oldpc, oldlc;
- Prog *p;
- long v, s;
-
- oldpc = INITTEXT;
- oldlc = 0;
- for(p = firstp; p != P; p = p->link) {
- if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
- if(p->as == ATEXT)
- curtext = p;
- if(debug['L'])
- Bprint(&bso, "%6lux %P\n",
- p->pc, p);
- continue;
- }
- if(debug['L'])
- Bprint(&bso, "\t\t%6ld", lcsize);
- v = (p->pc - oldpc) / MINLC;
- while(v) {
- s = 127;
- if(v < 127)
- s = v;
- CPUT(s+128); /* 129-255 +pc */
- if(debug['L'])
- Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
- v -= s;
- lcsize++;
- }
- s = p->line - oldlc;
- oldlc = p->line;
- oldpc = p->pc + MINLC;
- if(s > 64 || s < -64) {
- CPUT(0); /* 0 vv +lc */
- CPUT(s>>24);
- CPUT(s>>16);
- CPUT(s>>8);
- CPUT(s);
- if(debug['L']) {
- if(s > 0)
- Bprint(&bso, " lc+%ld(%d,%ld)\n",
- s, 0, s);
- else
- Bprint(&bso, " lc%ld(%d,%ld)\n",
- s, 0, s);
- Bprint(&bso, "%6lux %P\n",
- p->pc, p);
- }
- lcsize += 5;
- continue;
- }
- if(s > 0) {
- CPUT(0+s); /* 1-64 +lc */
- if(debug['L']) {
- Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
- Bprint(&bso, "%6lux %P\n",
- p->pc, p);
- }
- } else {
- CPUT(64-s); /* 65-128 -lc */
- if(debug['L']) {
- Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
- Bprint(&bso, "%6lux %P\n",
- p->pc, p);
- }
- }
- lcsize++;
- }
- while(lcsize & 1) {
- s = 129;
- CPUT(s);
- lcsize++;
- }
- if(debug['v'] || debug['L'])
- Bprint(&bso, "lcsize = %ld\n", lcsize);
- Bflush(&bso);
-}
-
-void
-datblk(long s, long n)
-{
- Prog *p;
- char *cast;
- long l, fl, j, d;
- int i, c;
-
- memset(buf.dbuf, 0, n+100);
- for(p = datap; p != P; p = p->link) {
- curp = p;
- l = p->from.sym->value + p->from.offset - s;
- c = p->reg;
- i = 0;
- if(l < 0) {
- if(l+c <= 0)
- continue;
- while(l < 0) {
- l++;
- i++;
- }
- }
- if(l >= n)
- continue;
- if(p->as != AINIT && p->as != ADYNT) {
- for(j=l+(c-i)-1; j>=l; j--)
- if(buf.dbuf[j]) {
- print("%P\n", p);
- diag("multiple initialization");
- break;
- }
- }
- switch(p->to.type) {
- default:
- diag("unknown mode in initialization\n%P", p);
- break;
-
- case D_FCONST:
- switch(c) {
- default:
- case 4:
- fl = ieeedtof(p->to.ieee);
- cast = (char*)&fl;
- for(; i<c; i++) {
- buf.dbuf[l] = cast[fnuxi8[i]];
- l++;
- }
- break;
- case 8:
- cast = (char*)p->to.ieee;
- for(; i<c; i++) {
- buf.dbuf[l] = cast[fnuxi8[i]];
- l++;
- }
- break;
- }
- break;
-
- case D_SCONST:
- for(; i<c; i++) {
- buf.dbuf[l] = p->to.sval[i];
- l++;
- }
- break;
-
- case D_CONST:
- d = p->to.offset;
- if(p->to.sym) {
- if(p->to.sym->type == STEXT ||
- p->to.sym->type == SLEAF)
- d += p->to.sym->value;
- if(p->to.sym->type == SDATA)
- d += p->to.sym->value + INITDAT;
- if(p->to.sym->type == SBSS)
- d += p->to.sym->value + INITDAT;
- }
- cast = (char*)&d;
- switch(c) {
- default:
- diag("bad nuxi %d %d\n%P", c, i, curp);
- break;
- case 1:
- for(; i<c; i++) {
- buf.dbuf[l] = cast[inuxi1[i]];
- l++;
- }
- break;
- case 2:
- for(; i<c; i++) {
- buf.dbuf[l] = cast[inuxi2[i]];
- l++;
- }
- break;
- case 4:
- for(; i<c; i++) {
- buf.dbuf[l] = cast[inuxi4[i]];
- l++;
- }
- break;
- case 8:
- for(; i<4; i++) {
- buf.dbuf[l] = cast[inuxi4[i]];
- l++;
- }
- d = p->to.offset >> 32;
- for(; i<c; i++) {
- buf.dbuf[l] = cast[inuxi4[i-4]];
- l++;
- }
- break;
- }
- break;
- }
- }
- write(cout, buf.dbuf, n);
-}
-
-#define OP_RRR(op,r1,r2,r3)\
- (op|(((r1)&31L)<<16)|(((r2)&31L)<<21)|((r3)&31L))
-#define OP_IRR(op,i,r2,r3)\
- (op|(((i)&255L)<<13)|0x1000|(((r2)&31L)<<21)|((r3)&31L))
-#define OP_MEM(op,d,r1,r2)\
- (op|(((r1)&31L)<<16)|(((r2)&31L)<<21)|((d)&0xffff))
-#define OP_BR(op,d,r1)\
- (op|((d)&0x1fffff)|(((r1)&31L)<<21))
-
-int
-asmout(Prog *p, Optab *o)
-{
- long o1, o2, o3, o4, o5, o6;
- vlong v;
- int r, a;
-
- o1 = 0;
- o2 = 0;
- o3 = 0;
- o4 = 0;
- o5 = 0;
- o6 = 0;
- switch(o->type) {
- default:
- diag("unknown type %d", o->type);
- if(!debug['a'])
- prasm(p);
- break;
-
- case 0: /* pseudo ops */
- break;
-
- case 1: /* register-register moves */
- if(p->as == AMOVB || p->as == AMOVW) /* noop should rewrite */
- diag("forbidden SEX: %P", p);
- if(p->as == AMOVBU || p->as == AMOVWU) {
- v = 1;
- if (p->as == AMOVWU)
- v = 3;
- o1 = OP_IRR(opcode(AZAPNOT), v, p->from.reg, p->to.reg);
- }
- else {
- a = AOR;
- if(p->as == AMOVL)
- a = AADDL;
- if(p->as == AMOVLU)
- a = AEXTLL;
- o1 = OP_RRR(opcode(a), REGZERO, p->from.reg, p->to.reg);
- }
- break;
-
- case 2: /* <operate> r1,[r2],r3 */
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- o1 = OP_RRR(opcode(p->as), p->from.reg, r, p->to.reg);
- break;
-
- case 3: /* <operate> $n,[r2],r3 */
- v = regoff(&p->from);
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- o1 = OP_IRR(opcode(p->as), v, r, p->to.reg);
- break;
-
- case 4: /* beq r1,sbra */
- if(p->cond == P)
- v = -4 >> 2;
- else
- v = (p->cond->pc - pc-4) >> 2;
- o1 = OP_BR(opcode(p->as), v, p->from.reg);
- break;
-
- case 5: /* jmp [r1],0(r2) */
- r = p->reg;
- a = p->as;
- if(r == NREG) {
- r = o->param;
-/* if(a == AJMP && p->to.reg == REGLINK)
- a = ARET; /* this breaks the kernel -- maybe we need to clear prediction stack on each context switch... */
- }
- o1 = OP_MEM(opcode(a), 0, p->to.reg, r);
- break;
-
- case 6: /* movq $n,r1 and movq $soreg,r1 */
- r = p->from.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->from);
- o1 = OP_MEM(opcode(AMOVA), v, r, p->to.reg);
- break;
-
- case 7: /* movbu r1, r2 */
- v = 1;
- if (p->as == AMOVWU)
- v = 3;
- o1 = OP_IRR(opcode(AZAPNOT), v, p->from.reg, p->to.reg);
- break;
-
- case 8: /* mov r, soreg ==> stq o(r) */
- r = p->to.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->to);
- if (p->as == AMOVQ || p->as == AMOVT)
- if ((r == REGSP || r == REGSB) && (v&7) != 0)
- diag("bad alignment: %P", p);
- o1 = OP_MEM(opcode(p->as+AEND), v, r, p->from.reg);
- break;
-
- case 9: /* mov soreg, r ==> ldq o(r) */
- r = p->from.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->from);
- if (p->as == AMOVQ || p->as == AMOVT)
- if ((r == REGSP || r == REGSB) && (v&7) != 0)
- diag("bad alignment: %P", p);
- o1 = OP_MEM(opcode(p->as), v, r, p->to.reg);
- break;
-
- case 10: /* movb r1,r2 */
- v = 64 - 8;
- if (p->as == AMOVW)
- v = 64 - 16;
- o1 = OP_IRR(opcode(ASLLQ), v, p->from.reg, p->to.reg);
- o2 = OP_IRR(opcode(ASRAQ), v, p->to.reg, p->to.reg);
- break;
-
- case 11: /* jmp lbra */
- if(p->cond == P)
- v = -4 >> 2;
- else
- v = (p->cond->pc - pc-4) >> 2;
- a = ABR;
- r = REGZERO;
- if (p->as == AJSR) {
- a = ABSR;
- r = REGLINK;
- }
- o1 = OP_BR(opcode(a), v, r);
- break;
-
- case 12: /* addq $n,[r2],r3 ==> lda */
- v = regoff(&p->from);
- if (p->as == ASUBQ)
- v = -v;
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- o1 = OP_MEM(opcode(AMOVA), v, r, p->to.reg);
- break;
-
- case 13: /* <op> $scon,[r2],r3 */
- v = regoff(&p->from);
- if(p->to.reg == REGTMP || p->reg == REGTMP)
- diag("cant synthesize large constant\n%P", p);
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- o1 = OP_MEM(opcode(AMOVA), v, REGZERO, REGTMP);
- o2 = OP_RRR(opcode(p->as), REGTMP, r, p->to.reg);
- break;
-
- case 14: /* <op> $lcon,[r2],r3 */
- v = regoff(&p->from);
- if(v & 0x8000)
- v += 0x10000;
- if(p->to.reg == REGTMP || p->reg == REGTMP)
- diag("cant synthesize large constant\n%P", p);
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- o1 = OP_MEM(opcode(AMOVA), v, REGZERO, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, REGTMP);
- o3 = OP_RRR(opcode(p->as), REGTMP, r, p->to.reg);
- break;
-
- case 15: /* mov $lcon,r1 */
- v = regoff(&p->from);
- if(v & 0x8000)
- v += 0x10000;
- o1 = OP_MEM(opcode(AMOVA), v, o->param, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, p->to.reg);
- break;
-
- case 16: /* mov $qcon,r1 */
- v = regoff(&p->from);
- if(v & 0x8000)
- v += 0x10000;
- if((v>>31)&1)
- v += (1LL<<32);
- if((v>>47)&1)
- v += (1LL<<48);
- o1 = OP_MEM(opcode(AMOVA), v>>32, o->param, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>48, REGTMP, REGTMP);
- o3 = OP_IRR(opcode(ASLLQ), 32, REGTMP, REGTMP);
- o4 = OP_MEM(opcode(AMOVA), v, REGTMP, REGTMP);
- o5 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, p->to.reg);
- break;
-
- case 17: /* mov f1,f2 ==> fcpys f1,f1,f2 */
- o1 = OP_RRR(opcode(ACPYS), p->from.reg, p->from.reg, p->to.reg);
- break;
-
- case 18: /* call_pal imm */
- v = regoff(&p->from);
- o1 = OP_MEM(opcode(ACALL_PAL), v, 0, 0);
- break;
-
- case 19: /* mov r, loreg ==> ldah,stq */
- r = p->to.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->to);
- if (p->as == AMOVQ || p->as == AMOVT)
- if ((r == REGSP || r == REGSB) && (v&7) != 0)
- diag("bad alignment: %P", p);
- if(v & 0x8000)
- v += 0x10000;
- o1 = OP_MEM(opcode(AMOVAH), v>>16, r, REGTMP);
- o2 = OP_MEM(opcode(p->as+AEND), v, REGTMP, p->from.reg);
- break;
-
- case 20: /* mov loreg, r ==> ldah,ldq */
- r = p->from.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->from);
- if (p->as == AMOVQ || p->as == AMOVT)
- if ((r == REGSP || r == REGSB) && (v&7) != 0)
- diag("bad alignment: %P", p);
- if(v & 0x8000)
- v += 0x10000;
- o1 = OP_MEM(opcode(AMOVAH), v>>16, r, REGTMP);
- o2 = OP_MEM(opcode(p->as), v, REGTMP, p->to.reg);
- break;
-
-#ifdef NEVER
- case 21: /* mov r1,$qoreg */
- r = p->to.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->to);
- if(v & 0x8000)
- v += 0x10000;
- if((v>>31)&1)
- v += (1LL<<32);
- if((v>>47)&1)
- v += (1LL<<48);
- o1 = OP_MEM(opcode(AMOVA), v>>32, r, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>48, REGTMP, REGTMP);
- o3 = OP_IRR(opcode(ASLLQ), 32, REGTMP, REGTMP);
- o4 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, REGTMP);
- o5 = OP_MEM(opcode(p->as+AEND), v, REGTMP, p->from.reg);
- break;
-
- case 22: /* mov $qoreg,r1 */
- r = p->from.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->from);
- if(v & 0x8000)
- v += 0x10000;
- if((v>>31)&1)
- v += (1LL<<32);
- if((v>>47)&1)
- v += (1LL<<48);
- o1 = OP_MEM(opcode(AMOVA), v>>32, r, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>48, REGTMP, REGTMP);
- o3 = OP_IRR(opcode(ASLLQ), 32, REGTMP, REGTMP);
- o4 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, REGTMP);
- o5 = OP_MEM(opcode(p->as), v, REGTMP, p->to.reg);
- break;
-#endif
-
- case 23: /* <op> $qcon,r1 */
- if(p->to.reg == REGTMP || p->reg == REGTMP)
- diag("cant synthesize large constant\n%P", p);
- v = regoff(&p->from);
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- if(v & 0x8000)
- v += 0x10000;
- if((v>>31)&1)
- v += (1LL<<32);
- if((v>>47)&1)
- v += (1LL<<48);
- o1 = OP_MEM(opcode(AMOVA), v>>32, REGZERO, REGTMP);
- o2 = OP_MEM(opcode(AMOVAH), v>>48, REGTMP, REGTMP);
- o3 = OP_IRR(opcode(ASLLQ), 32, REGTMP, REGTMP);
- o4 = OP_MEM(opcode(AMOVA), v, REGTMP, REGTMP);
- o5 = OP_MEM(opcode(AMOVAH), v>>16, REGTMP, REGTMP);
- o6 = OP_RRR(opcode(p->as), REGTMP, r, p->to.reg);
- break;
-
- case 24: /* movq Fn, FPCR */
- r = p->from.reg;
- o1 = OP_RRR(opcode(AADDT+AEND), r, r, r);
- break;
-
- case 25: /* movq FPCR, Fn */
- r = p->to.reg;
- o1 = OP_RRR(opcode(AADDS+AEND), r, r, r);
- break;
-
- case 26: /* movq Rn, C_PREG */
- r = p->from.reg;
- o1 = OP_RRR(opcode(ASUBQ+AEND), r, r, 0) | p->to.reg & 255;
- break;
-
- case 27: /* movq C_PREG, Rn */
- r = p->to.reg;
- o1 = OP_RRR(opcode(AADDQ+AEND), r, r, 0) | p->from.reg & 255;
- break;
-
- case 28: /* cvttq r1,r3 */
- r = p->from.reg;
- o1 = OP_RRR(opcode(p->as), r, REGZERO, p->to.reg);
- break;
-
- case 29: /* movq pcc, rpcc -> Rn */
- o1 = OP_MEM(opcode(ARPCC), 0, REGZERO, p->to.reg);
- break;
-
- case 30: /* rei/mb/trapb */
- o1 = OP_MEM(opcode(p->as), 0, REGZERO, REGZERO);
- break;
-
- case 31: /* fetch (Rn) */
- o1 = OP_MEM(opcode(p->as), 0, REGZERO, p->from.reg);
- break;
-
- case 32: /* movqp r, soreg ==> stqp o(r) */
- r = p->to.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->to);
- if (v < -0x800 || v >= 0x800)
- diag("physical store out of range\n%P", p);
- v &= 0xfff;
- o1 = OP_MEM(opcode(p->as+AEND), v, r, p->from.reg);
- break;
-
- case 33: /* movqp soreg, r ==> ldqp o(r) */
- r = p->from.reg;
- if(r == NREG)
- r = o->param;
- v = regoff(&p->from);
- if (v < -0x800 || v >= 0x800)
- diag("physical load out of range\n%P", p);
- v &= 0xfff;
- o1 = OP_MEM(opcode(p->as), v, r, p->to.reg);
- break;
-
- case 34: /* <operate> $-n,[r2],r3 */
- v = regoff(&p->from);
- r = p->reg;
- if(r == NREG)
- r = p->to.reg;
- switch (a = p->as) {
- case AAND:
- a = AANDNOT;
- break;
- case AANDNOT:
- a = AAND;
- break;
- case AOR:
- a = AORNOT;
- break;
- case AORNOT:
- a = AOR;
- break;
- case AXOR:
- a = AXORNOT;
- break;
- case AXORNOT:
- a = AXOR;
- break;
- default:
- diag("bad in NCON case: %P", p);
- }
- v = ~v;
- o1 = OP_IRR(opcode(a), v, r, p->to.reg);
- break;
-
- case 40: /* word */
- o1 = regoff(&p->to);
- break;
-
- }
- switch(o->size) {
- default:
- if(debug['a'])
- Bprint(&bso, " %.8lux:\t\t%P\n", p->pc, p);
- break;
- case 4:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux\t%P\n", p->pc, o1, p);
- LPUT(o1);
- break;
- case 8:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux %.8lux %P\n", p->pc, o1, o2, p);
- LPUT(o1);
- LPUT(o2);
- break;
- case 12:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %P\n", p->pc, o1, o2, o3, p);
- LPUT(o1);
- LPUT(o2);
- LPUT(o3);
- break;
- case 16:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %P\n",
- p->pc, o1, o2, o3, o4, p);
- LPUT(o1);
- LPUT(o2);
- LPUT(o3);
- LPUT(o4);
- break;
- case 20:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux %P\n",
- p->pc, o1, o2, o3, o4, o5, p);
- LPUT(o1);
- LPUT(o2);
- LPUT(o3);
- LPUT(o4);
- LPUT(o5);
- break;
- case 24:
- if(debug['a'])
- Bprint(&bso, " %.8lux: %.8lux %.8lux %.8lux %.8lux %.8lux %.8lux %P\n",
- p->pc, o1, o2, o3, o4, o5, o6, p);
- LPUT(o1);
- LPUT(o2);
- LPUT(o3);
- LPUT(o4);
- LPUT(o5);
- LPUT(o6);
- break;
- }
- return 0;
-}
-
-#define OP(x,y) (((x)<<26)|((y)<<5))
-#define FP(x) OP(22, (x)|0xc0) /* note: this sets round/trap modes (dynamic, software?). not used for cvtxx? */
-#define FP2(x) OP(22, (x) /*|0x080*/) /* note: this sets round/trap modes (chopped, software?). used for cvtxx? */
-#define FP3(x) OP(22, (x)|0x080) /* note: this sets round/trap modes (dynamic, software?). not used for cvtxx? */
-
-long
-opcode(int a)
-{
- switch (a) {
- /* loads */
- case AMOVB: /* misnomer; pretend it's ok for now */
-diag("opcode(AMOVB)");
- case AMOVBU: return OP(10, 0); /* v 3 */
- case AMOVW: /* misnomer; pretend it's ok for now */
-diag("opcode(AMOVW)");
- case AMOVWU: return OP(12, 0); /* v 3 */
- case AMOVL: return OP(40, 0);
- case AMOVQ: return OP(41, 0);
- case AMOVQU: return OP(11, 0);
- case AMOVS: return OP(34, 0);
- case AMOVT: return OP(35, 0);
-
- /* stores */
- case AMOVB+AEND: /* misnomer; pretend it's ok for now */
- case AMOVBU+AEND: return OP(14, 0); /* v 3 */
- case AMOVW+AEND: /* misnomer; pretend it's ok for now */
- case AMOVWU+AEND: return OP(13, 0); /* v 3 */
- case AMOVL+AEND: return OP(44, 0);
- case AMOVQ+AEND: return OP(45, 0);
- case AMOVQU+AEND: return OP(15, 0);
- case AMOVS+AEND: return OP(38, 0);
- case AMOVT+AEND: return OP(39, 0);
-
- /* physical */
- case AMOVLP+AEND: return OP(31, 0)|0x8000;
- case AMOVQP+AEND: return OP(31, 0)|0x9000;
- case AMOVLP: return OP(27, 0)|0x8000;
- case AMOVQP: return OP(27, 0)|0x9000;
-
- /* load address */
- case AMOVA: return OP(8, 0);
- case AMOVAH: return OP(9, 0);
-
- /* locking */
- case AMOVLL: return OP(42, 0); /* load locked */
- case AMOVQL: return OP(43, 0); /* load locked */
- case AMOVLC+AEND: return OP(46, 0); /* store cond */
- case AMOVQC+AEND: return OP(47, 0); /* store cond */
-
- case AADDL: return OP(16, 0);
- case AADDLV: return OP(16, 64);
- case AADDQ: return OP(16, 32);
- case AADDQV: return OP(16, 96);
- case AS4ADDL: return OP(16, 2);
- case AS4ADDQ: return OP(16, 34);
- case AS8ADDL: return OP(16, 18);
- case AS8ADDQ: return OP(16, 50);
- case AS4SUBL: return OP(16, 11);
- case AS4SUBQ: return OP(16, 43);
- case AS8SUBL: return OP(16, 27);
- case AS8SUBQ: return OP(16, 59);
- case ASUBL: return OP(16, 9);
- case ASUBLV: return OP(16, 73);
- case ASUBQ: return OP(16, 41);
- case ASUBQV: return OP(16, 105);
- case ACMPEQ: return OP(16, 45);
- case ACMPGT: return OP(16, 77);
- case ACMPGE: return OP(16, 109);
- case ACMPUGT: return OP(16, 29);
- case ACMPUGE: return OP(16, 61);
- case ACMPBLE: return OP(16, 15);
-
- case AAND: return OP(17, 0);
- case AANDNOT: return OP(17, 8);
- case AOR: return OP(17, 32);
- case AORNOT: return OP(17, 40);
- case AXOR: return OP(17, 64);
- case AXORNOT: return OP(17, 72);
-
- case ACMOVEQ: return OP(17, 36);
- case ACMOVNE: return OP(17, 38);
- case ACMOVLT: return OP(17, 68);
- case ACMOVGE: return OP(17, 70);
- case ACMOVLE: return OP(17, 100);
- case ACMOVGT: return OP(17, 102);
- case ACMOVLBS: return OP(17, 20);
- case ACMOVLBC: return OP(17, 22);
-
- case AMULL: return OP(19, 0);
- case AMULQ: return OP(19, 32);
- case AMULLV: return OP(19, 64);
- case AMULQV: return OP(19, 96);
- case AUMULH: return OP(19, 48);
-
- case ASLLQ: return OP(18, 57);
- case ASRLQ: return OP(18, 52);
- case ASRAQ: return OP(18, 60);
-
- case AEXTBL: return OP(18, 6);
- case AEXTWL: return OP(18, 22);
- case AEXTLL: return OP(18, 38);
- case AEXTQL: return OP(18, 54);
- case AEXTWH: return OP(18, 90);
- case AEXTLH: return OP(18, 106);
- case AEXTQH: return OP(18, 122);
-
- case AINSBL: return OP(18, 11);
- case AINSWL: return OP(18, 27);
- case AINSLL: return OP(18, 43);
- case AINSQL: return OP(18, 59);
- case AINSWH: return OP(18, 87);
- case AINSLH: return OP(18, 103);
- case AINSQH: return OP(18, 119);
-
- case AMSKBL: return OP(18, 2);
- case AMSKWL: return OP(18, 18);
- case AMSKLL: return OP(18, 34);
- case AMSKQL: return OP(18, 50);
- case AMSKWH: return OP(18, 82);
- case AMSKLH: return OP(18, 98);
- case AMSKQH: return OP(18, 114);
-
- case AZAP: return OP(18, 48);
- case AZAPNOT: return OP(18, 49);
-
- case AJMP: return OP(26, 0);
- case AJSR: return OP(26, 512);
- case ARET: return OP(26, 1024);
-
- case ABR: return OP(48, 0);
- case ABSR: return OP(52, 0);
-
- case ABEQ: return OP(57, 0);
- case ABNE: return OP(61, 0);
- case ABLT: return OP(58, 0);
- case ABGE: return OP(62, 0);
- case ABLE: return OP(59, 0);
- case ABGT: return OP(63, 0);
- case ABLBC: return OP(56, 0);
- case ABLBS: return OP(60, 0);
-
- case AFBEQ: return OP(49, 0);
- case AFBNE: return OP(53, 0);
- case AFBLT: return OP(50, 0);
- case AFBGE: return OP(54, 0);
- case AFBLE: return OP(51, 0);
- case AFBGT: return OP(55, 0);
-
- case ATRAPB: return OP(24, 0);
- case AMB: return OP(24, 0x200);
- case AFETCH: return OP(24, 0x400);
- case AFETCHM: return OP(24, 0x500);
- case ARPCC: return OP(24, 0x600);
-
- case ACPYS: return OP(23, 32);
- case ACPYSN: return OP(23, 33);
- case ACPYSE: return OP(23, 34);
- case AADDS+AEND: return OP(23, 37); /* MF_FPCR */
- case AADDT+AEND: return OP(23, 36); /* MT_FPCR */
- case ACVTLQ: return OP(23, 16);
- case ACVTQL: return OP(23, 48); /* XXX trap mode */
- case AFCMOVEQ: return OP(23, 42);
- case AFCMOVNE: return OP(23, 43);
- case AFCMOVLT: return OP(23, 44);
- case AFCMOVGE: return OP(23, 45);
- case AFCMOVLE: return OP(23, 46);
- case AFCMOVGT: return OP(23, 47);
-
- case AADDS: return FP(0);
- case AADDT: return FP(32);
- case ACMPTEQ: return FP3(37);
- case ACMPTGT: return FP3(38);
- case ACMPTGE: return FP3(39);
- case ACMPTUN: return FP3(36);
-
- case ACVTQS: return FP2(60);
- case ACVTQT: return FP2(62);
- case ACVTTS: return FP2(44);
- case ACVTTQ: return FP2(47);
-
- case ADIVS: return FP(3);
- case ADIVT: return FP(35);
- case AMULS: return FP(2);
- case AMULT: return FP(34);
- case ASUBS: return FP(1);
- case ASUBT: return FP(33);
-
- case ACALL_PAL: return 0;
- case AREI: return OP(30, 0x400); /* HW_REI */
-
- case AADDQ+AEND: return OP(25,0); /* HW_MFPR */
- case ASUBQ+AEND: return OP(29,0); /* HW_MTPR */
- }
- diag("bad op %A(%d)", a, a);
- return 0;
-}
-
diff --git a/sys/src/cmd/7l/compat.c b/sys/src/cmd/7l/compat.c
deleted file mode 100644
index 1d9f89e43..000000000
--- a/sys/src/cmd/7l/compat.c
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(ulong n)
-{
- void *p;
-
- while(n & 7)
- n++;
- while(nhunk < n)
- gethunk();
- p = hunk;
- nhunk -= n;
- hunk += n;
- return p;
-}
-
-void
-free(void *p)
-{
- USED(p);
-}
-
-void*
-calloc(ulong m, ulong n)
-{
- void *p;
-
- n *= m;
- p = malloc(n);
- memset(p, 0, n);
- return p;
-}
-
-void*
-realloc(void *p, ulong n)
-{
- fprint(2, "realloc(0x%p %ld) called\n", p, n);
- abort();
- return 0;
-}
-
-void*
-mysbrk(ulong size)
-{
- return sbrk(size);
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
- USED(v, pc);
-}
diff --git a/sys/src/cmd/7l/l.h b/sys/src/cmd/7l/l.h
deleted file mode 100644
index e5f853c82..000000000
--- a/sys/src/cmd/7l/l.h
+++ /dev/null
@@ -1,316 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "../7c/7.out.h"
-
-typedef struct Adr Adr;
-typedef struct Sym Sym;
-typedef struct Autom Auto;
-typedef struct Prog Prog;
-typedef struct Optab Optab;
-typedef struct Oprang Oprang;
-typedef uchar Opcross[32][2][32];
-typedef struct Count Count;
-
-#define P ((Prog*)0)
-#define S ((Sym*)0)
-#define TNAME (curtext&&curtext->from.sym?curtext->from.sym->name:noname)
-
-struct Adr
-{
- union
- {
- vlong offset;
- char* sval;
- Ieee* ieee;
- };
- union
- {
- Auto* autom;
- Sym* sym;
- };
- char type;
- char reg;
- char name;
- char class;
-};
-struct Prog
-{
- Adr from;
- Adr to;
- union
- {
- long regused;
- Prog* forwd;
- };
- Prog* cond;
- Prog* link;
- long pc;
- long line;
- uchar mark;
- uchar optab;
- uchar as;
- char reg;
-};
-struct Sym
-{
- char *name;
- short type;
- short version;
- short become;
- short frame;
- long value;
- Sym* link;
-};
-struct Autom
-{
- Sym* sym;
- Auto* link;
- long offset;
- short type;
-};
-struct Optab
-{
- uchar as;
- char a1;
- char a2;
- char a3;
- char type;
- char size;
- char param;
-};
-struct Oprang
-{
- Optab* start;
- Optab* stop;
-};
-struct Count
-{
- long count;
- long outof;
-};
-
-enum
-{
- STEXT = 1,
- SDATA,
- SBSS,
- SDATA1,
- SXREF,
- SLEAF,
- SFILE,
- SCONST,
-
- C_NONE = 0,
- C_REG,
- C_FREG,
- C_FCREG,
- C_PREG,
- C_PCC,
- C_ZCON,
- C_BCON,
- C_NCON,
- C_SCON,
- C_UCON,
- C_LCON,
- C_QCON,
- C_SACON,
- C_SECON,
- C_LACON,
- C_LECON,
- C_SBRA,
- C_LBRA,
- C_SAUTO,
- C_SEXT,
- C_LAUTO,
- C_LEXT,
- C_ZOREG,
- C_SOREG,
- C_LOREG,
- C_GOK,
-
- NSCHED = 20,
-
-/* mark flags */
- FOLL = 1<<0,
- LABEL = 1<<1,
- LEAF = 1<<2,
- SYNC = 1<<3,
- BRANCH = 1<<4,
- LABEL2 = 1<<5,
- COMPARE = 1<<6,
- NOSCHED = 1<<7,
-
- BIG = 32760,
- STRINGSZ = 200,
- NHASH = 10007,
- NHUNK = 100000,
- MINSIZ = 64,
- NENT = 100,
- MAXIO = 8192,
- MAXHIST = 20, /* limit of path elements for history symbols */
-};
-
-union
-{
- struct
- {
- uchar cbuf[MAXIO]; /* output buffer */
- uchar xbuf[MAXIO]; /* input buffer */
- };
- char dbuf[1];
-} buf;
-
-long HEADR; /* length of header */
-int HEADTYPE; /* type of header */
-long INITDAT; /* data location */
-long INITRND; /* data round above text location */
-long INITTEXT; /* text location */
-char* INITENTRY; /* entry point */
-long autosize;
-Biobuf bso;
-long bsssize;
-int cbc;
-uchar* cbp;
-int cout;
-Auto* curauto;
-Auto* curhist;
-Prog* curp;
-Prog* curtext;
-Prog* datap;
-long datsize;
-char debug[128];
-Prog* etextp;
-Prog* firstp;
-char fnuxi8[8];
-char* noname;
-Sym* hash[NHASH];
-Sym* histfrog[MAXHIST];
-int histfrogp;
-int histgen;
-char* library[50];
-char* libraryobj[50];
-int libraryp;
-int xrefresolv;
-char* hunk;
-char inuxi1[1];
-char inuxi2[2];
-char inuxi4[4];
-Prog* lastp;
-long lcsize;
-char literal[32];
-int nerrors;
-long nhunk;
-vlong offset;
-Opcross opcross[7];
-Oprang oprange[ALAST];
-char* outfile;
-long pc;
-Prog *prog_divq;
-Prog *prog_divqu;
-Prog *prog_modq;
-Prog *prog_modqu;
-Prog *prog_divl;
-Prog *prog_divlu;
-Prog *prog_modl;
-Prog *prog_modlu;
-uchar repop[ALAST];
-long symsize;
-Prog* textp;
-long textsize;
-long thunk;
-int version;
-char xcmp[32][32];
-Prog zprg;
-int dtype;
-
-extern char* anames[];
-extern Optab optab[];
-
-#pragma varargck type "A" int
-#pragma varargck type "A" uint
-#pragma varargck type "D" Adr*
-#pragma varargck type "N" Adr*
-#pragma varargck type "P" Prog*
-#pragma varargck type "S" char*
-
-#pragma varargck argpos diag 1
-
-int Aconv(Fmt*);
-int Dconv(Fmt*);
-int Nconv(Fmt*);
-int Pconv(Fmt*);
-int Sconv(Fmt*);
-int aclass(Adr*);
-void addhist(long, int);
-void addnop(Prog*);
-void append(Prog*, Prog*);
-void asmb(void);
-void asmlc(void);
-int asmout(Prog*, Optab*);
-void asmsym(void);
-long atolwhex(char*);
-Prog* brloop(Prog*);
-Biobuf bso;
-void buildop(void);
-void buildrep(int, int);
-void cflush(void);
-int cmp(int, int);
-int compound(Prog*);
-int conflict(long, long);
-double cputime(void);
-void datblk(long, long);
-int depend(long, long);
-void diag(char*, ...);
-Prog *divsubr(int);
-void dodata(void);
-void doprof1(void);
-void doprof2(void);
-long entryvalue(void);
-void errorexit(void);
-void exchange(Prog*);
-int find1(long, int);
-void follow(void);
-Prog *genXXX(Prog *, int, Adr*, int, Adr*);
-Prog *genRRR(Prog *, int, int, int, int);
-Prog *genIRR(Prog *, int, vlong, int, int);
-Prog *genstore(Prog *, int, int, vlong, int);
-Prog *genload(Prog *, int, vlong, int, int);
-Prog *genjmp(Prog *, int, vlong, int);
-void gethunk(void);
-void histtoauto(void);
-double ieeedtod(Ieee*);
-long ieeedtof(Ieee*);
-void initdiv(void);
-void ldobj(int, long, char*);
-void loadlib(void);
-void listinit(void);
-Sym* lookup(char*, int);
-void lput(long);
-void lputbe(long);
-void mkfwd(void);
-void* mysbrk(ulong);
-void names(void);
-void nocache(Prog*);
-void noops(void);
-void nuxiinit(void);
-void objfile(char*);
-int ocmp(void*, void*);
-long opcode(int);
-Optab* oplook(Prog*);
-void patch(void);
-void prasm(Prog*);
-void prepend(Prog*, Prog*);
-Prog* prg(void);
-int pseudo(Prog*);
-void putsymb(char*, int, long, int);
-vlong regoff(Adr*);
-long regused(Prog*);
-int relinv(int);
-long rnd(long, long);
-void sched(Prog*, Prog*);
-void span(void);
-void vlput(vlong);
-void undef(void);
-void xdefine(char*, int, long);
-void xfol(Prog*);
diff --git a/sys/src/cmd/7l/list.c b/sys/src/cmd/7l/list.c
deleted file mode 100644
index c2dc9da3f..000000000
--- a/sys/src/cmd/7l/list.c
+++ /dev/null
@@ -1,246 +0,0 @@
-#include "l.h"
-
-void
-listinit(void)
-{
-
- fmtinstall('A', Aconv);
- fmtinstall('D', Dconv);
- fmtinstall('P', Pconv);
- fmtinstall('S', Sconv);
- fmtinstall('N', Nconv);
-}
-
-void
-prasm(Prog *p)
-{
- print("%P\n", p);
-}
-
-int
-Pconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Prog *p;
- int a;
-
- p = va_arg(fp->args, Prog*);
- curp = p;
- a = p->as;
- if(a == ADATA)
- snprint(str, sizeof str, "(%ld) %A %D/%d,%D",
- p->line, a, &p->from, p->reg, &p->to);
- else
- if(p->reg == NREG)
- snprint(str, sizeof str, "(%ld) %A %D,%D",
- p->line, a, &p->from, &p->to);
- else
- if(p->from.type != D_FREG)
- snprint(str, sizeof str, "(%ld) %A %D,R%d,%D",
- p->line, a, &p->from, p->reg, &p->to);
- else
- snprint(str, sizeof str, "(%ld) %A %D,F%d,%D",
- p->line, a, &p->from, p->reg, &p->to);
- return fmtstrcpy(fp, str);
-}
-
-int
-Aconv(Fmt *fp)
-{
- char *s;
- int a;
-
- a = va_arg(fp->args, int);
- s = "???";
- if(a >= AXXX && a <= AEND)
- s = anames[a];
- return fmtstrcpy(fp, s);
-}
-
-int
-Dconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- long v;
-
- a = va_arg(fp->args, Adr*);
- switch(a->type) {
-
- default:
- snprint(str, sizeof str, "GOK-type(%d)", a->type);
- break;
-
- case D_NONE:
- str[0] = 0;
- if(a->name != D_NONE || a->reg != NREG || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(NONE)", a, a->reg);
- break;
-
- case D_CONST:
- snprint(str, sizeof str, "$%N", a);
- if(a->reg != NREG)
- snprint(str, sizeof str, "%N(R%d)(CONST)", a, a->reg);
- break;
-
- case D_OREG:
- if(a->reg != NREG)
- snprint(str, sizeof str, "%N(R%d)", a, a->reg);
- else
- snprint(str, sizeof str, "%N", a);
- break;
-
- case D_REG:
- snprint(str, sizeof str, "R%d", a->reg);
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(REG)", a, a->reg);
- break;
-
- case D_PREG:
- snprint(str, sizeof str, "P%d", a->reg & 255);
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(PREG)", a, a->reg);
- break;
-
- case D_FREG:
- snprint(str, sizeof str, "F%d", a->reg);
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(FREG)", a, a->reg);
- break;
-
- case D_FCREG:
- snprint(str, sizeof str, "FPCR");
- if(a->name != D_NONE || a->sym != S)
- snprint(str, sizeof str, "%N(R%d)(FCREG)", a, a->reg);
- break;
-
- case D_BRANCH: /* botch */
- if(curp->cond != P) {
- v = curp->cond->pc;
- if(v >= INITTEXT)
- v -= INITTEXT-HEADR;
- if(a->sym != S)
- snprint(str, sizeof str, "%s+%.5lux(BRANCH)", a->sym->name, v);
- else
- snprint(str, sizeof str, "%.5lux(BRANCH)", v);
- } else
- if(a->sym != S)
- snprint(str, sizeof str, "%s+%lld(APC)", a->sym->name, a->offset);
- else
- snprint(str, sizeof str, "%lld(APC)", a->offset);
- break;
-
- case D_FCONST:
- snprint(str, sizeof str, "$%e", ieeedtod(a->ieee));
- break;
-
- case D_SCONST:
- snprint(str, sizeof str, "$\"%S\"", a->sval);
- break;
- }
- return fmtstrcpy(fp, str);
-}
-
-int
-Nconv(Fmt *fp)
-{
- char str[STRINGSZ];
- Adr *a;
- Sym *s;
-
- a = va_arg(fp->args, Adr*);
- s = a->sym;
- if(s == S) {
- snprint(str, sizeof str, "%lld", a->offset);
- goto out;
- }
- switch(a->name) {
- default:
- snprint(str, sizeof str, "GOK-name(%d)", a->name);
- break;
-
- case D_NONE:
- snprint(str, sizeof str, "%lld", a->offset);
- break;
-
- case D_EXTERN:
- snprint(str, sizeof str, "%s+%lld(SB)", s->name, a->offset);
- break;
-
- case D_STATIC:
- snprint(str, sizeof str, "%s<>+%lld(SB)", s->name, a->offset);
- break;
-
- case D_AUTO:
- snprint(str, sizeof str, "%s-%lld(SP)", s->name, -a->offset);
- break;
-
- case D_PARAM:
- snprint(str, sizeof str, "%s+%lld(FP)", s->name, a->offset);
- break;
- }
-out:
- return fmtstrcpy(fp, str);
-}
-
-int
-Sconv(Fmt *fp)
-{
- int i, c;
- char str[STRINGSZ], *p, *a;
-
- a = va_arg(fp->args, char*);
- p = str;
- for(i=0; i<sizeof(long); i++) {
- c = a[i] & 0xff;
- if(c >= 'a' && c <= 'z' ||
- c >= 'A' && c <= 'Z' ||
- c >= '0' && c <= '9' ||
- c == ' ' || c == '%') {
- *p++ = c;
- continue;
- }
- *p++ = '\\';
- switch(c) {
- case 0:
- *p++ = 'z';
- continue;
- case '\\':
- case '"':
- *p++ = c;
- continue;
- case '\n':
- *p++ = 'n';
- continue;
- case '\t':
- *p++ = 't';
- continue;
- }
- *p++ = (c>>6) + '0';
- *p++ = ((c>>3) & 7) + '0';
- *p++ = (c & 7) + '0';
- }
- *p = 0;
- return fmtstrcpy(fp, str);
-}
-
-void
-diag(char *fmt, ...)
-{
- char buf[STRINGSZ], *tn;
- va_list arg;
-
- tn = "??none??";
- if(curtext != P && curtext->from.sym != S)
- tn = curtext->from.sym->name;
- va_start(arg, fmt);
- vseprint(buf, buf+sizeof(buf), fmt, arg);
- va_end(arg);
- print("%s: %s\n", tn, buf);
-
- nerrors++;
- if(nerrors > 10) {
- print("too many errors\n");
- errorexit();
- }
-}
diff --git a/sys/src/cmd/7l/mkfile b/sys/src/cmd/7l/mkfile
deleted file mode 100644
index a8e6d210c..000000000
--- a/sys/src/cmd/7l/mkfile
+++ /dev/null
@@ -1,33 +0,0 @@
-</$objtype/mkfile
-
-TARG=7l
-OFILES=\
- asm.$O\
- list.$O\
- noop.$O\
- obj.$O\
- optab.$O\
- pass.$O\
- sched.$O\
- span.$O\
- enam.$O\
- compat.$O\
-
-HFILES=\
- l.h\
- ../7c/7.out.h\
-
-BIN=/$objtype/bin
-</sys/src/cmd/mkone
-
-enam.$O: ../7c/enam.c
- $CC $CFLAGS ../7c/enam.c
-
-x:V: $O.out
- $O.out -la -o/dev/null x.7
-
-test:V: $O.out
- rm -f xxx
- mv $O.out xxx
- ./xxx $OFILES
- cmp $O.out xxx
diff --git a/sys/src/cmd/7l/noop.c b/sys/src/cmd/7l/noop.c
deleted file mode 100644
index e7f9b655b..000000000
--- a/sys/src/cmd/7l/noop.c
+++ /dev/null
@@ -1,947 +0,0 @@
-#include "l.h"
-
-Prog *divuconst(Prog *, uvlong, int, int, int);
-Prog *divconst(Prog *, vlong, int, int, int);
-Prog *modconst(Prog *, vlong, int, int, int);
-void excise(Prog *);
-
-void
-noops(void)
-{
- Prog *p, *p1, *q, *q1, *q2;
- int o, curframe, curbecome, maxbecome, shift;
-
- /*
- * find leaf subroutines
- * become sizes
- * frame sizes
- * strip NOPs
- * expand RET and other macros
- * expand BECOME pseudo
- * use conditional moves where appropriate
- */
-
- if(debug['v'])
- Bprint(&bso, "%5.2f noops\n", cputime());
- Bflush(&bso);
-
- curframe = 0;
- curbecome = 0;
- maxbecome = 0;
- curtext = 0;
-
- q = P;
- for(p = firstp; p != P; p = p->link) {
-
- /* find out how much arg space is used in this TEXT */
- if(p->to.type == D_OREG && p->to.reg == REGSP)
- if(p->to.offset > curframe)
- curframe = p->to.offset;
-
- switch(p->as) {
- case ATEXT:
- if(curtext && curtext->from.sym) {
- curtext->from.sym->frame = curframe;
- curtext->from.sym->become = curbecome;
- if(curbecome > maxbecome)
- maxbecome = curbecome;
- }
- curframe = 0;
- curbecome = 0;
-
- p->mark |= LABEL|LEAF|SYNC;
- if(p->link)
- p->link->mark |= LABEL;
- curtext = p;
- break;
-
- /* don't mess with what we don't understand */
- case AWORD:
- case ACALL_PAL:
- /* etc. */
- p->mark |= LABEL;
- for(q1=p->link; q1 != P; q1 = q1->link) {
- q1->mark |= LABEL;
- if(q1->as != AXORNOT) /* used as NOP in PALcode */
- break;
- }
- break;
-
- case ARET:
- /* special form of RET is BECOME */
- if(p->from.type == D_CONST)
- if(p->from.offset > curbecome)
- curbecome = p->from.offset;
-
- if(p->link != P)
- p->link->mark |= LABEL;
- break;
-
- case ANOP:
- q1 = p->link;
- q->link = q1; /* q is non-nop */
- q1->mark |= p->mark;
- continue;
-
- case AJSR:
- if(curtext != P)
- curtext->mark &= ~LEAF;
- case ABEQ:
- case ABNE:
- case ABGE:
- case ABGT:
- case ABLE:
- case ABLT:
- case ABLBC:
- case ABLBS:
- case AFBEQ:
- case AFBNE:
- case AFBGE:
- case AFBGT:
- case AFBLE:
- case AFBLT:
- case AJMP:
- p->mark |= BRANCH;
- q1 = p->cond;
- if(q1 != P) {
- while(q1->as == ANOP) {
- q1 = q1->link;
- p->cond = q1;
- }
- if(!(q1->mark & LEAF)) {
- if (q1->mark & LABEL)
- q1->mark |= LABEL2;
- else
- q1->mark |= LABEL;
- }
- } else
- p->mark |= LABEL;
- q1 = p->link;
- if(q1 != P) {
- if (q1->mark & LABEL)
- q1->mark |= LABEL2;
- else
- q1->mark |= LABEL;
- }
- else
- p->mark |= LABEL; /* ??? */
- break;
-
- case ADIVQ:
- case ADIVQU:
- case AMODQ:
- case AMODQU:
- case ADIVL:
- case ADIVLU:
- case AMODL:
- case AMODLU:
- if(p->from.type == D_CONST /*&& !debug['d']*/)
- continue;
- if(prog_divq == P)
- initdiv();
- if(curtext != P)
- curtext->mark &= ~LEAF;
- break;
- }
- q = p;
- }
-
- if(curtext && curtext->from.sym) {
- curtext->from.sym->frame = curframe;
- curtext->from.sym->become = curbecome;
- if(curbecome > maxbecome)
- maxbecome = curbecome;
- }
-
- if(debug['b'])
- print("max become = %d\n", maxbecome);
- xdefine("ALEFbecome", STEXT, maxbecome);
-
- curtext = 0;
- for(p = firstp; p != P; p = p->link) {
- switch(p->as) {
- case ATEXT:
- curtext = p;
- break;
- case AJSR:
- if(curtext != P && curtext->from.sym != S && curtext->to.offset >= 0) {
- o = maxbecome - curtext->from.sym->frame;
- if(o <= 0)
- break;
- /* calling a become or calling a variable */
- if(p->to.sym == S || p->to.sym->become) {
- curtext->to.offset += o;
- if(debug['b']) {
- curp = p;
- print("%D calling %D increase %d\n",
- &curtext->from, &p->to, o);
- }
- }
- }
- break;
- }
- }
-
- for(p = firstp; p != P; p = p->link) {
- o = p->as;
- switch(o) {
- case ATEXT:
- curtext = p;
- autosize = p->to.offset + 8;
- if(autosize <= 8)
- if(curtext->mark & LEAF) {
- p->to.offset = -8;
- autosize = 0;
- }
- if (autosize & 4)
- autosize += 4;
-
- q = p;
- if(autosize)
- q = genIRR(p, ASUBQ, autosize, NREG, REGSP);
- else if(!(curtext->mark & LEAF)) {
- if(debug['v'])
- Bprint(&bso, "save suppressed in: %s\n",
- curtext->from.sym->name);
- Bflush(&bso);
- curtext->mark |= LEAF;
- }
-
- if(curtext->mark & LEAF) {
- if(curtext->from.sym)
- curtext->from.sym->type = SLEAF;
- break;
- }
-
- genstore(q, AMOVL, REGLINK, 0LL, REGSP);
- break;
-
- case ARET:
- nocache(p);
- if(p->from.type == D_CONST)
- goto become;
- if(curtext->mark & LEAF) {
- if(!autosize) {
- p->as = AJMP;
- p->from = zprg.from;
- p->to.type = D_OREG;
- p->to.offset = 0;
- p->to.reg = REGLINK;
- break;
- }
-
- p->as = AADDQ;
- p->from.type = D_CONST;
- p->from.offset = autosize;
- p->to.type = D_REG;
- p->to.reg = REGSP;
-
- q = prg();
- q->as = AJMP;
- q->line = p->line;
- q->to.type = D_OREG;
- q->to.offset = 0;
- q->to.reg = REGLINK;
- q->mark |= BRANCH;
-
- q->link = p->link;
- p->link = q;
- break;
- }
- p->as = AMOVL;
- p->from.type = D_OREG;
- p->from.offset = 0;
- p->from.reg = REGSP;
- p->to.type = D_REG;
- p->to.reg = REGLINK;
-
- q = p;
- if(autosize)
- q = genIRR(p, AADDQ, autosize, NREG, REGSP);
-
- q1 = prg();
- q1->as = AJMP;
- q1->line = p->line;
- q1->to.type = D_OREG;
- q1->to.offset = 0;
- q1->to.reg = REGLINK;
- q1->mark |= BRANCH;
-
- q1->link = q->link;
- q->link = q1;
- break;
-
- become:
- if(curtext->mark & LEAF) {
-
- q = prg();
- q->line = p->line;
- q->as = AJMP;
- q->from = zprg.from;
- q->to = p->to;
- q->cond = p->cond;
- q->link = p->link;
- q->mark |= BRANCH;
- p->link = q;
-
- p->as = AADDQ;
- p->from = zprg.from;
- p->from.type = D_CONST;
- p->from.offset = autosize;
- p->to = zprg.to;
- p->to.type = D_REG;
- p->to.reg = REGSP;
-
- break;
- }
- q = prg();
- q->line = p->line;
- q->as = AJMP;
- q->from = zprg.from;
- q->to = p->to;
- q->cond = p->cond;
- q->link = p->link;
- q->mark |= BRANCH;
- p->link = q;
-
- q = genIRR(p, AADDQ, autosize, NREG, REGSP);
-
- p->as = AMOVL;
- p->from = zprg.from;
- p->from.type = D_OREG;
- p->from.offset = 0;
- p->from.reg = REGSP;
- p->to = zprg.to;
- p->to.type = D_REG;
- p->to.reg = REGLINK;
-
- break;
-
-
- /* All I wanted was a MOVB... */
- case AMOVB:
- case AMOVW:
- /* rewrite sign extend; could use v3 extension in asmout case 1 */
- if (p->to.type == D_REG) {
- nocache(p);
- shift = (p->as == AMOVB) ? (64-8) : (64-16);
- if (p->from.type == D_REG) {
- p->as = ASLLQ;
- p->reg = p->from.reg;
- p->from.type = D_CONST;
- p->from.offset = shift;
- q = genIRR(p, ASRAQ, shift, p->to.reg, p->to.reg);
- break;
- }
- else {
- p->as = (p->as == AMOVB) ? AMOVBU : AMOVWU;
- q = genIRR(p, ASLLQ, shift, p->to.reg, p->to.reg);
- q = genIRR(q, ASRAQ, shift, p->to.reg, p->to.reg);
- }
- }
- /* fall through... */
- case AMOVBU:
- case AMOVWU:
- if(!debug['x'])
- break; /* use BWX extension */
- o = p->as;
- nocache(p);
- if (p->from.type == D_OREG) {
- if (p->to.type != D_REG)
- break;
- p->as = AMOVQU;
- q = genXXX(p, AEXTBL, &p->to, REGTMP2, &p->to);
- if (o == AMOVW || o == AMOVWU)
- q->as = AEXTWL;
- p->to.reg = REGTMP2;
- if ((p->from.offset & 7) != 0 || aclass(&p->from) != C_SOREG) {
- q1 = genXXX(p, AMOVA, &p->from, NREG, &q->to);
- q1->from.offset &= 7;
- q->from = q->to;
- }
- else
- q->from.reg = p->from.reg;
- if (o == AMOVB || o == AMOVW)
- genXXX(q, o, &q->to, NREG, &q->to);
- }
- else if (p->to.type == D_OREG) {
- if (aclass(&p->from) == C_ZCON) {
- p->from.type = D_REG;
- p->from.reg = REGZERO;
- }
- else if (p->from.type != D_REG)
- break;
- p->as = AMOVQU;
- q = genRRR(p, AMSKBL, p->to.reg, REGTMP2, REGTMP2);
- q1 = genRRR(q, AINSBL, p->to.reg, p->from.reg, REGTMP);
- if (o == AMOVW || o == AMOVWU) {
- q->as = AMSKWL;
- q1->as = AINSWL;
- }
- q2 = genXXX(q1, AOR, &q->to, REGTMP, &q->to);
- genXXX(q2, AMOVQU, &q->to, NREG, &p->to);
- p->from = p->to;
- p->to = q->to;
- if ((p->from.offset & 7) != 0 || aclass(&p->from) != C_SOREG) {
- q->from.reg = REGTMP;
- q1->from.reg = REGTMP;
- q = genXXX(p, AMOVA, &p->from, NREG, &q->from);
- q->from.offset &= 7;
- }
- }
- break;
-
- case ASLLL:
- p->as = ASLLQ;
- p = genXXX(p, AADDL, &p->to, REGZERO, &p->to);
- break;
-
- case ASRLL:
- if (p->to.type != D_REG) {
- diag("illegal dest type in %P", p);
- break;
- }
- if (p->reg == NREG)
- p->reg = p->to.reg;
-
- q = genXXX(p, ASRLQ, &p->from, REGTMP, &p->to);
-
- p->as = AZAP;
- p->from.type = D_CONST;
- p->from.offset = 0xf0;
- p->to.reg = REGTMP;
- p = q;
-
- p = genXXX(p, AADDL, &p->to, REGZERO, &p->to);
- break;
-
- case ASRAL:
- p->as = ASRAQ;
- break;
-
- case ADIVQ:
- case ADIVQU:
- case AMODQ:
- case AMODQU:
- case ADIVL:
- case ADIVLU:
- case AMODL:
- case AMODLU:
- /* if (debug['d'])
- print("%P\n", p); */
- if(p->to.type != D_REG)
- break;
- /*if(debug['d'] && p->from.type == D_CONST) {
- q = genRRR(p, p->as, REGTMP, p->reg, p->to.reg);
- p->as = AMOVQ;
- p->reg = NREG;
- p->to.reg = REGTMP;
- p = q;
- }*/
- if(p->from.type == D_CONST) {
- if (p->reg == NREG)
- p->reg = p->to.reg;
- switch (p->as) {
- case ADIVQ:
- q = divconst(p, p->from.offset, p->reg, p->to.reg, 64);
- break;
- case ADIVQU:
- q = divuconst(p, p->from.offset, p->reg, p->to.reg, 64);
- break;
- case AMODQ:
- q = modconst(p, p->from.offset, p->reg, p->to.reg, 64);
- break;
- case AMODQU:
- q = divuconst(p, p->from.offset, p->reg, REGTMP2, 64);
- q = genIRR(q, AMULQ, p->from.offset, REGTMP2, REGTMP2);
- q = genRRR(q, ASUBQ, REGTMP2, p->reg, p->to.reg);
- break;
- case ADIVL:
- q = divconst(p, p->from.offset, p->reg, p->to.reg, 32);
- break;
- case ADIVLU:
- q = divuconst(p, p->from.offset, p->reg, p->to.reg, 32);
- break;
- case AMODL:
- q = modconst(p, p->from.offset, p->reg, p->to.reg, 32);
- break;
- case AMODLU:
- q = divuconst(p, p->from.offset, p->reg, REGTMP2, 32);
- q = genIRR(q, AMULQ, p->from.offset, REGTMP2, REGTMP2);
- q = genRRR(q, ASUBQ, REGTMP2, p->reg, p->to.reg);
- break;
- }
- excise(p);
- p = q;
- break;
- }
- if(p->from.type != D_REG){
- diag("bad instruction %P", p);
- break;
- }
- o = p->as;
- q = genIRR(p, ASUBQ, 16LL, NREG, REGSP);
- q = genstore(q, AMOVQ, p->from.reg, 8LL, REGSP);
- if (o == ADIVL || o == ADIVL || o == AMODL || o == AMODLU)
- q->as = AMOVL;
-
- q = genRRR(q, AMOVQ, p->reg, NREG, REGTMP);
- if (p->reg == NREG)
- q->from.reg = p->to.reg;
-
- /* CALL appropriate */
- q1 = prg();
- q1->link = q->link;
- q->link = q1;
-
- q1->as = AJSR;
- q1->line = p->line;
- q1->to.type = D_BRANCH;
- q1->cond = divsubr(o);
- q1->mark |= BRANCH;
- q = q1;
-
- q = genRRR(q, AMOVQ, REGTMP, NREG, p->to.reg);
- q = genIRR(q, AADDQ, 16LL, NREG, REGSP);
- excise(p);
- p = q;
- break;
-
- /* Attempt to replace {cond. branch, mov} with a cmov */
- /* XXX warning: this is all a bit experimental */
- case ABEQ:
- case ABNE:
- case ABGE:
- case ABGT:
- case ABLE:
- case ABLT:
- case ABLBC:
- case ABLBS:
- q = p->link;
- if (q == P)
- break;
- q1 = q->link;
- if (q1 != p->cond || q1 == P)
- break;
-/*print("%P\n", q); /* */
- if (q->to.type != D_REG)
- break;
- if (q->from.type != D_REG && (q->from.type != D_CONST || q->from.name != D_NONE))
- break;
- if (q->mark&LABEL2)
- break;
-/* print("%P\n", q); /* */
- if (q->as != AMOVQ) /* XXX can handle more than this! */
- break;
- q->as = (p->as^1) + ACMOVEQ-ABEQ; /* sleazy hack */
- q->reg = p->from.reg; /* XXX check CMOVx operand order! */
- excise(p); /* XXX p's LABEL? */
- if (!(q1->mark&LABEL2))
- q1->mark &= ~LABEL;
- break;
- case AFBEQ:
- case AFBNE:
- case AFBGE:
- case AFBGT:
- case AFBLE:
- case AFBLT:
- q = p->link;
- if (q == P)
- break;
- q1 = q->link;
- if (q1 != p->cond || q1 == P)
- break;
- if (q->from.type != D_FREG || q->to.type != D_FREG)
- break;
-/* print("%P\n", q); /* */
- if (q->mark&LABEL2)
- break;
- if (q->as != AMOVT) /* XXX can handle more than this! */
- break;
- q->as = (p->as^1) + AFCMOVEQ-AFBEQ; /* sleazy hack */
- q->reg = p->from.reg; /* XXX check CMOVx operand order! */
- excise(p); /* XXX p's LABEL? */
- if (!(q1->mark&LABEL2))
- q1->mark &= ~LABEL;
- break;
- }
- }
-
- curtext = P;
- q = P; /* p - 1 */
- q1 = firstp; /* top of block */
- o = 0; /* count of instructions */
- for(p = firstp; p != P; p = p1) {
- p1 = p->link;
- o++;
- if(p->mark & NOSCHED){
- if(q1 != p){
- sched(q1, q);
- }
- for(; p != P; p = p->link){
- if(!(p->mark & NOSCHED))
- break;
- q = p;
- }
- p1 = p;
- q1 = p;
- o = 0;
- continue;
- }
- if(p->mark & (LABEL|SYNC)) {
- if(q1 != p)
- sched(q1, q);
- q1 = p;
- o = 1;
- }
- if(p->mark & (BRANCH|SYNC)) {
- sched(q1, p);
- q1 = p1;
- o = 0;
- }
- if(o >= NSCHED) {
- sched(q1, p);
- q1 = p1;
- o = 0;
- }
- q = p;
- }
-}
-
-void
-nocache(Prog *p)
-{
- p->optab = 0;
- p->from.class = 0;
- p->to.class = 0;
-}
-
-/* XXX use of this may lose important LABEL flags, check that this isn't happening (or fix) */
-void
-excise(Prog *p)
-{
- Prog *q;
-
- q = p->link;
- *p = *q;
-}
-
-void
-initdiv(void)
-{
- Sym *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8;
- Prog *p;
-
- s1 = lookup("_divq", 0);
- s2 = lookup("_divqu", 0);
- s3 = lookup("_modq", 0);
- s4 = lookup("_modqu", 0);
- s5 = lookup("_divl", 0);
- s6 = lookup("_divlu", 0);
- s7 = lookup("_modl", 0);
- s8 = lookup("_modlu", 0);
- for(p = firstp; p != P; p = p->link)
- if(p->as == ATEXT) {
- if(p->from.sym == s1)
- prog_divq = p;
- if(p->from.sym == s2)
- prog_divqu = p;
- if(p->from.sym == s3)
- prog_modq = p;
- if(p->from.sym == s4)
- prog_modqu = p;
- if(p->from.sym == s5)
- prog_divl = p;
- if(p->from.sym == s6)
- prog_divlu = p;
- if(p->from.sym == s7)
- prog_modl = p;
- if(p->from.sym == s8)
- prog_modlu = p;
- }
- if(prog_divq == P) {
- diag("undefined: %s", s1->name);
- prog_divq = curtext;
- }
- if(prog_divqu == P) {
- diag("undefined: %s", s2->name);
- prog_divqu = curtext;
- }
- if(prog_modq == P) {
- diag("undefined: %s", s3->name);
- prog_modq = curtext;
- }
- if(prog_modqu == P) {
- diag("undefined: %s", s4->name);
- prog_modqu = curtext;
- }
- if(prog_divl == P) {
- diag("undefined: %s", s5->name);
- prog_divl = curtext;
- }
- if(prog_divlu == P) {
- diag("undefined: %s", s6->name);
- prog_divlu = curtext;
- }
- if(prog_modl == P) {
- diag("undefined: %s", s7->name);
- prog_modl = curtext;
- }
- if(prog_modlu == P) {
- diag("undefined: %s", s8->name);
- prog_modlu = curtext;
- }
-}
-
-Prog *
-divsubr(int o)
-{
- switch(o) {
- case ADIVQ:
- return prog_divq;
- case ADIVQU:
- return prog_divqu;
- case AMODQ:
- return prog_modq;
- case AMODQU:
- return prog_modqu;
- case ADIVL:
- return prog_divl;
- case ADIVLU:
- return prog_divlu;
- case AMODL:
- return prog_modl;
- case AMODLU:
- return prog_modlu;
- default:
- diag("bad op %A in divsubr", o);
- return prog_modlu;
- }
-}
-
-Prog*
-divuconst(Prog *p, uvlong y, int num, int quot, int bits)
-{
- int logy, i, shift;
- uvlong k, m, n, mult, tmp, msb;
-
- if(num == NREG)
- num = quot;
- if(y == 0) {
- diag("division by zero");
- return p;
- }
- if(y == 1)
- return genRRR(p, AMOVQ, num, NREG, quot);
-
- if(num == REGTMP || quot == REGTMP)
- diag("bad register in divuconst");
-
- tmp = y;
- for(logy = -1; tmp != 0; logy++)
- tmp >>= 1;
-
- msb = (1LL << (bits-1));
- if((y & (y-1)) == 0) /* power of 2 */
- return genIRR(p, ASRLQ, logy, num, quot);
- if(y > msb)
- return genIRR(p, ACMPUGE, y, num, quot);
-
- /* k = (-2^(bits+logy)) % y */
- m = msb/y;
- n = msb%y;
- if(debug['d'])
- Bprint(&bso, "divuconst: y=%lld msb=%lld m=%lld n=%lld\n",
- y, msb, m, n);
- for(i = 0; i <= logy; i++) {
- m *= 2LL;
- n *= 2LL;
- if(n > y) {
- m += 1LL;
- n -= y;
- }
- }
- if(debug['d'])
- Bprint(&bso, "divuconst: y=%lld msb=%lld m=%lld n=%lld\n",
- y, msb, m, n);
- k = y - n;
- if(k > (1LL << logy)) {
- mult = 2LL*m + 1LL;
- bits++;
- } else
- mult = m + 1LL;
-
- shift = bits + logy;
- if(debug['d'])
- Bprint(&bso, "divuconst: y=%lld mult=%lld shift=%d bits=%d k=%lld\n",
- y, mult, shift, bits, k);
- if(bits <= 32) {
- p = genIRR(p, AMOVQ, mult, NREG, REGTMP);
- p = genRRR(p, AEXTLL, REGZERO, num, quot);
- p = genRRR(p, AMULQ, REGTMP, quot, quot);
- p = genIRR(p, ASRLQ, shift, quot, quot);
- p = genRRR(p, AADDL, quot, REGZERO, quot);
- return p;
- }
- if(bits == 33) {
- if(shift < 64) {
- mult <<= (64-shift);
- shift = 64;
- }
- p = genIRR(p, AMOVQ, mult, NREG, REGTMP);
- p = genRRR(p, AEXTLL, REGZERO, num, quot);
- p = genRRR(p, AUMULH, REGTMP, quot, quot);
- if(shift != 64)
- p = genIRR(p, ASRLQ, shift-64, quot, quot);
- p = genRRR(p, AADDL, quot, REGZERO, quot);
- return p;
- }
- if(bits <= 64) {
- if(shift < 64) {
- mult <<= (64-shift);
- shift = 64;
- }
- p = genIRR(p, AMOVQ, mult, NREG, REGTMP);
- p = genRRR(p, AUMULH, REGTMP, num, quot);
- if(shift != 64)
- p = genIRR(p, ASRLQ, shift-64, quot, quot);
- return p;
- }
-
- p = genIRR(p, AMOVQ, mult, NREG, REGTMP);
- p = genRRR(p, AUMULH, REGTMP, num, REGTMP);
- p = genRRR(p, AADDQ, num, REGTMP, quot);
- p = genRRR(p, ACMPUGT, REGTMP, quot, REGTMP);
- p = genIRR(p, ASLLQ, 128-shift, REGTMP, REGTMP);
- p = genIRR(p, ASRLQ, shift-64, quot, quot);
- p = genRRR(p, AADDQ, REGTMP, quot, quot);
- return p;
-}
-
-Prog *
-divconst(Prog *p, vlong y, int num, int quot, int bits)
-{
- vlong yabs;
- Prog *q;
-
- yabs = y;
- if (y < 0)
- yabs = -y;
- q = genRRR(p, ASUBQ, num, REGZERO, REGTMP2);
- if (num != quot)
- q = genRRR(q, AMOVQ, num, NREG, quot);
- q = genRRR(q, ACMOVGT, REGTMP2, REGTMP2, quot);
- q = divuconst(q, yabs, quot, quot, bits-1);
- q = genRRR(q, ASUBQ, quot, REGZERO, REGTMP);
- q = genRRR(q, (y < 0)? ACMOVLT: ACMOVGT, REGTMP, REGTMP2, quot);
- return q;
-}
-
-Prog *
-modconst(Prog *p, vlong y, int num, int quot, int bits)
-{
- vlong yabs;
- Prog *q;
-
- yabs = y;
- if (y < 0)
- yabs = -y;
- q = genRRR(p, ASUBQ, num, REGZERO, REGTMP2);
- q = genRRR(q, ACMOVLT, num, REGTMP2, REGTMP2);
- q = divuconst(q, yabs, REGTMP2, REGTMP2, bits-1);
- q = genRRR(q, ASUBQ, REGTMP2, REGZERO, REGTMP);
- q = genRRR(q, ACMOVLT, REGTMP, num, REGTMP2);
- q = genIRR(q, AMULQ, yabs, REGTMP2, REGTMP2);
- q = genRRR(q, ASUBQ, REGTMP2, num, quot);
- return q;
-}
-
-Prog *
-genXXX(Prog *q, int op, Adr *from, int reg, Adr *to)
-{
- Prog *p;
-
- p = prg();
- p->as = op;
- p->line = q->line;
- p->from = *from;
- p->to = *to;
- p->reg = reg;
- p->link = q->link;
- q->link = p;
- return p;
-}
-
-Prog *
-genRRR(Prog *q, int op, int from, int reg, int to)
-{
- Prog *p;
-
- p = prg();
- p->as = op;
- p->line = q->line;
- p->from.type = D_REG;
- p->from.reg = from;
- p->to.type = D_REG;
- p->to.reg = to;
- p->reg = reg;
- p->link = q->link;
- q->link = p;
- return p;
-}
-
-Prog *
-genIRR(Prog *q, int op, vlong v, int reg, int to)
-{
- Prog *p;
-
- p = prg();
- p->as = op;
- p->line = q->line;
- p->from.type = D_CONST;
- p->from.offset = v;
- p->to.type = D_REG;
- p->to.reg = to;
- p->reg = reg;
- p->link = q->link;
- q->link = p;
- return p;
-}
-
-Prog *
-genstore(Prog *q, int op, int from, vlong offset, int to)
-{
- Prog *p;
-
- p = prg();
- p->as = op;
- p->line = q->line;
- p->from.type = D_REG;
- p->from.reg = from;
- p->to.type = D_OREG;
- p->to.reg = to;
- p->to.offset = offset;
- p->reg = NREG;
- p->link = q->link;
- q->link = p;
- return p;
-}
-
-Prog *
-genload(Prog *q, int op, vlong offset, int from, int to)
-{
- Prog *p;
-
- p = prg();
- p->as = op;
- p->line = q->line;
- p->from.type = D_OREG;
- p->from.offset = offset;
- p->from.reg = from;
- p->to.type = D_REG;
- p->to.reg = to;
- p->reg = NREG;
- p->link = q->link;
- q->link = p;
- return p;
-}
diff --git a/sys/src/cmd/7l/obj.c b/sys/src/cmd/7l/obj.c
deleted file mode 100644
index 793e5825e..000000000
--- a/sys/src/cmd/7l/obj.c
+++ /dev/null
@@ -1,1350 +0,0 @@
-#include "l.h"
-#include <ar.h>
-
-#ifndef DEFAULT
-#define DEFAULT '9'
-#endif
-
-char *noname = "<none>";
-char symname[] = SYMDEF;
-char thechar = '7';
-char *thestring = "alpha";
-
-/*
- * -H0 -T0x12000004C -D0x140000000 is abbrev unix
- * -H1 -T0x20000000 -R4 is bootp() format
- * -H2 -T8224 -R8192 is plan9 format
- */
-
-void
-main(int argc, char *argv[])
-{
- int c;
- char *a;
-
- Binit(&bso, 1, OWRITE);
- cout = -1;
- listinit();
- outfile = 0;
- nerrors = 0;
- curtext = P;
- HEADTYPE = -1;
- INITTEXT = -1;
- INITDAT = -1;
- INITRND = -1;
- INITENTRY = 0;
-
- ARGBEGIN {
- default:
- c = ARGC();
- if(c >= 0 && c < sizeof(debug))
- debug[c]++;
- break;
- case 'o':
- outfile = ARGF();
- break;
- case 'E':
- a = ARGF();
- if(a)
- INITENTRY = a;
- break;
- case 'T':
- a = ARGF();
- if(a)
- INITTEXT = atolwhex(a);
- break;
- case 'D':
- a = ARGF();
- if(a)
- INITDAT = atolwhex(a);
- break;
- case 'R':
- a = ARGF();
- if(a)
- INITRND = atolwhex(a);
- break;
- case 'H':
- a = ARGF();
- if(a)
- HEADTYPE = atolwhex(a);
- /* do something about setting INITTEXT */
- break;
- } ARGEND
-
- USED(argc);
-
- if(*argv == 0) {
- diag("usage: 7l [-options] objects");
- errorexit();
- }
- if(!debug['9'] && !debug['B'] && !debug['U'])
- debug[DEFAULT] = 1;
- if(HEADTYPE == -1) {
- if(debug['U'])
- HEADTYPE = 0;
- if(debug['B'])
- HEADTYPE = 1;
- if(debug['9'])
- HEADTYPE = 2;
- }
- switch(HEADTYPE) {
- default:
- diag("unknown -H option");
- errorexit();
-
- case 0: /* unix simple */
- HEADR = 32L+80L;
- if(INITTEXT == -1)
- INITTEXT = 0x120000070LL; /* BUG */
- if(INITDAT == -1)
- INITDAT = 0x140000000LL; /* BUG */
- if(INITRND == -1)
- INITRND = 0;
- break;
-
- case 1: /* boot */
- HEADR = 32L+84L;
- if(INITTEXT == -1)
- INITTEXT = 0x20000074L;
- if(INITDAT == -1)
- INITDAT = 0;
- if(INITRND == -1)
- INITRND = 8;
- break;
- case 2: /* plan 9 */
- HEADR = 32L;
- if(INITTEXT == -1)
- INITTEXT = 8224;
- if(INITDAT == -1)
- INITDAT = 0;
- if(INITRND == -1)
- INITRND = 8192;
- break;
- case 3: /* ``headerless'' tftp boot -- uses branch as magic */
- HEADR = 32L;
- if(INITTEXT == -1)
- INITTEXT = 0x20000020L;
- if(INITDAT == -1)
- INITDAT = 0;
- if(INITRND == -1)
- INITRND = 8;
- break;
- }
- if(INITDAT != 0 && INITRND != 0)
- print("warning: -D0x%lux is ignored because of -R0x%lux\n",
- INITDAT, INITRND);
- if(debug['v'])
- Bprint(&bso, "HEADER = -H0x%d -T0x%lux -D0x%lux -R0x%lux\n",
- HEADTYPE, INITTEXT, INITDAT, INITRND);
- Bflush(&bso);
- zprg.as = AGOK;
- zprg.reg = NREG;
- zprg.from.name = D_NONE;
- zprg.from.type = D_NONE;
- zprg.from.reg = NREG;
- zprg.to = zprg.from;
- buildop();
- histgen = 0;
- textp = P;
- datap = P;
- pc = 0;
- dtype = 4;
- if(outfile == 0)
- outfile = "7.out";
- cout = create(outfile, 1, 0775);
- if(cout < 0) {
- diag("%s: cannot create", outfile);
- errorexit();
- }
- nuxiinit();
-
- version = 0;
- cbp = buf.cbuf;
- cbc = sizeof(buf.cbuf);
- firstp = prg();
- lastp = firstp;
-
- if(INITENTRY == 0) {
- INITENTRY = "_main";
- if(debug['p'])
- INITENTRY = "_mainp";
- if(!debug['l'])
- lookup(INITENTRY, 0)->type = SXREF;
- } else
- lookup(INITENTRY, 0)->type = SXREF;
-
- while(*argv)
- objfile(*argv++);
- if(!debug['l'])
- loadlib();
- firstp = firstp->link;
- if(firstp == P)
- goto out;
- patch();
- if(debug['p'])
- if(debug['1'])
- doprof1();
- else
- doprof2();
- follow();
- if(firstp == P)
- goto out;
- noops();
- dodata(); /* is before follow() on other arch */
- span();
- asmb();
- undef();
-
-out:
- if(debug['v']) {
- Bprint(&bso, "%5.2f cpu time\n", cputime());
- Bprint(&bso, "%ld memory used\n", thunk);
- Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
- Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
- }
- Bflush(&bso);
- errorexit();
-}
-
-void
-loadlib(void)
-{
- int i;
- long h;
- Sym *s;
-
-loop:
- xrefresolv = 0;
- for(i=0; i<libraryp; i++) {
- if(debug['v'])
- Bprint(&bso, "%5.2f autolib: %s\n", cputime(), library[i]);
- objfile(library[i]);
- }
- if(xrefresolv)
- for(h=0; h<nelem(hash); h++)
- for(s = hash[h]; s != S; s = s->link)
- if(s->type == SXREF)
- goto loop;
-}
-
-void
-errorexit(void)
-{
-
- Bflush(&bso);
- if(nerrors) {
- if(cout >= 0)
- remove(outfile);
- exits("error");
- }
- exits(0);
-}
-
-void
-objfile(char *file)
-{
- long off, esym, cnt, l;
- int f, work;
- Sym *s;
- char magbuf[SARMAG];
- char name[100], pname[150];
- struct ar_hdr arhdr;
- char *e, *start, *stop;
-
- if(file[0] == '-' && file[1] == 'l') {
- if(debug['9'])
- snprint(name, sizeof name, "/%s/lib/lib%s.a", thestring, file+2);
- else
- snprint(name, sizeof name, "/usr/%clib/lib%s.a", thechar, file+2);
- file = name;
- }
- if(debug['v'])
- Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
- Bflush(&bso);
- f = open(file, 0);
- if(f < 0) {
- diag("cannot open file: %s", file);
- errorexit();
- }
- l = read(f, magbuf, SARMAG);
- if(l != SARMAG || strncmp(magbuf, ARMAG, SARMAG)){
- /* load it as a regular file */
- l = seek(f, 0L, 2);
- seek(f, 0L, 0);
- ldobj(f, l, file);
- close(f);
- return;
- }
-
- if(debug['v'])
- Bprint(&bso, "%5.2f ldlib: %s\n", cputime(), file);
- l = read(f, &arhdr, SAR_HDR);
- if(l != SAR_HDR) {
- diag("%s: short read on archive file symbol header", file);
- goto out;
- }
- if(strncmp(arhdr.name, symname, strlen(symname))) {
- diag("%s: first entry not symbol header", file);
- goto out;
- }
-
- esym = SARMAG + SAR_HDR + atolwhex(arhdr.size);
- off = SARMAG + SAR_HDR;
-
- /*
- * just bang the whole symbol file into memory
- */
- seek(f, off, 0);
- cnt = esym - off;
- start = malloc(cnt + 10);
- cnt = read(f, start, cnt);
- if(cnt <= 0){
- close(f);
- return;
- }
- stop = &start[cnt];
- memset(stop, 0, 10);
-
- work = 1;
- while(work){
- if(debug['v'])
- Bprint(&bso, "%5.2f library pass: %s\n", cputime(), file);
- Bflush(&bso);
- work = 0;
- for(e = start; e < stop; e = strchr(e+5, 0) + 1) {
- s = lookup(e+5, 0);
- if(s->type != SXREF)
- continue;
- snprint(pname, sizeof pname, "%s(%s)", file, s->name);
- if(debug['v'])
- Bprint(&bso, "%5.2f library: %s\n", cputime(), pname);
- Bflush(&bso);
- l = e[1] & 0xff;
- l |= (e[2] & 0xff) << 8;
- l |= (e[3] & 0xff) << 16;
- l |= (e[4] & 0xff) << 24;
- seek(f, l, 0);
- l = read(f, &arhdr, SAR_HDR);
- if(l != SAR_HDR)
- goto bad;
- if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
- goto bad;
- l = atolwhex(arhdr.size);
- ldobj(f, l, pname);
- if(s->type == SXREF) {
- diag("%s: failed to load: %s", file, s->name);
- errorexit();
- }
- work = 1;
- xrefresolv = 1;
- }
- }
- return;
-
-bad:
- diag("%s: bad or out of date archive", file);
-out:
- close(f);
-}
-
-int
-zaddr(uchar *p, Adr *a, Sym *h[])
-{
- int i, c;
- vlong l;
- Sym *s;
- Auto *u;
-
- c = p[2];
- if(c < 0 || c > NSYM){
- print("sym out of range: %d\n", c);
- p[0] = ALAST+1;
- return 0;
- }
- a->type = p[0];
- a->reg = p[1];
- a->sym = h[p[2]];
- a->name = p[3];
- c = 4;
-
- if(a->reg < 0 || a->reg > NREG) {
- print("register out of range %d\n", a->reg);
- p[0] = ALAST+1;
- return 0; /* force real diagnostic */
- }
-
- switch(a->type) {
- default:
- print("unknown type %d\n", a->type);
- p[0] = ALAST+1;
- return 0; /* force real diagnostic */
-
- case D_NONE:
- case D_REG:
- case D_FREG:
- case D_PREG:
- case D_FCREG:
- case D_PCC:
- break;
-
- case D_BRANCH:
- case D_OREG:
- case D_CONST:
- a->offset = (uvlong)p[4] | ((uvlong)p[5]<<8L) |
- ((uvlong) p[6]<<16L) | ((uvlong) p[7]<<24L) |
- ((uvlong) p[8]<<32L) | ((uvlong) p[9]<<40L) |
- ((uvlong) p[10]<<48L) | ((uvlong) p[11]<<56L);
- c += 8;
- break;
-
- case D_SCONST:
- while(nhunk < NSNAME)
- gethunk();
- a->sval = (char*)hunk;
- nhunk -= NSNAME;
- hunk += NSNAME;
-
- memmove(a->sval, p+4, NSNAME);
- c += NSNAME;
- break;
-
- case D_FCONST:
- while(nhunk < sizeof(Ieee))
- gethunk();
- a->ieee = (Ieee*)hunk;
- nhunk -= sizeof(Ieee);
- hunk += sizeof(Ieee);
-
- a->ieee->l = p[4] | (p[5]<<8) |
- (p[6]<<16) | (p[7]<<24);
- a->ieee->h = p[8] | (p[9]<<8) |
- (p[10]<<16) | (p[11]<<24);
- c += 8;
- break;
- }
- s = a->sym;
- if(s == S)
- return c;
- i = a->name;
- if(i != D_AUTO && i != D_PARAM)
- return c;
-
- l = a->offset;
- for(u=curauto; u; u=u->link)
- if(u->sym == s)
- if(u->type == i) {
- if(u->offset > l)
- u->offset = l;
- return c;
- }
-
- while(nhunk < sizeof(Auto))
- gethunk();
- u = (Auto*)hunk;
- nhunk -= sizeof(Auto);
- hunk += sizeof(Auto);
-
- u->link = curauto;
- curauto = u;
- u->sym = s;
- u->offset = l;
- u->type = i;
- return c;
-}
-
-void
-addlib(char *obj)
-{
- char name[1024], comp[256], *p;
- int i;
-
- if(histfrogp <= 0)
- return;
-
- if(histfrog[0]->name[1] == '/') {
- name[0] = 0;
- i = 1;
- } else
- if(histfrog[0]->name[1] == '.') {
- snprint(name, sizeof name, ".");
- i = 0;
- } else {
- if(debug['9'])
- snprint(name, sizeof name, "/%s/lib", thestring);
- else
- snprint(name, sizeof name, "/usr/%clib", thechar);
- i = 0;
- }
-
- for(; i<histfrogp; i++) {
- snprint(comp, sizeof comp, histfrog[i]->name+1);
- for(;;) {
- p = strstr(comp, "$O");
- if(p == 0)
- break;
- memmove(p+1, p+2, strlen(p+2)+1);
- p[0] = thechar;
- }
- for(;;) {
- p = strstr(comp, "$M");
- if(p == 0)
- break;
- if(strlen(comp)+strlen(thestring)-2+1 >= sizeof comp) {
- diag("library component too long");
- return;
- }
- memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
- memmove(p, thestring, strlen(thestring));
- }
- if(strlen(name) + strlen(comp) + 3 >= sizeof(name)) {
- diag("library component too long");
- return;
- }
- strcat(name, "/");
- strcat(name, comp);
- }
- for(i=0; i<libraryp; i++)
- if(strcmp(name, library[i]) == 0)
- return;
- if(libraryp == nelem(library)){
- diag("too many autolibs; skipping %s", name);
- return;
- }
-
- p = malloc(strlen(name) + 1);
- strcpy(p, name);
- library[libraryp] = p;
- p = malloc(strlen(obj) + 1);
- strcpy(p, obj);
- libraryobj[libraryp] = p;
- libraryp++;
-}
-
-void
-addhist(long line, int type)
-{
- Auto *u;
- Sym *s;
- int i, j, k;
-
- u = malloc(sizeof(Auto));
- s = malloc(sizeof(Sym));
- s->name = malloc(2*(histfrogp+1) + 1);
-
- u->sym = s;
- u->type = type;
- u->offset = line;
- u->link = curhist;
- curhist = u;
-
- j = 1;
- for(i=0; i<histfrogp; i++) {
- k = histfrog[i]->value;
- s->name[j+0] = k>>8;
- s->name[j+1] = k;
- j += 2;
- }
-}
-
-void
-histtoauto(void)
-{
- Auto *l;
-
- while(l = curhist) {
- curhist = l->link;
- l->link = curauto;
- curauto = l;
- }
-}
-
-void
-collapsefrog(Sym *s)
-{
- int i;
-
- /*
- * bad encoding of path components only allows
- * MAXHIST components. if there is an overflow,
- * first try to collapse xxx/..
- */
- for(i=1; i<histfrogp; i++)
- if(strcmp(histfrog[i]->name+1, "..") == 0) {
- memmove(histfrog+i-1, histfrog+i+1,
- (histfrogp-i-1)*sizeof(histfrog[0]));
- histfrogp--;
- goto out;
- }
-
- /*
- * next try to collapse .
- */
- for(i=0; i<histfrogp; i++)
- if(strcmp(histfrog[i]->name+1, ".") == 0) {
- memmove(histfrog+i, histfrog+i+1,
- (histfrogp-i-1)*sizeof(histfrog[0]));
- goto out;
- }
-
- /*
- * last chance, just truncate from front
- */
- memmove(histfrog+0, histfrog+1,
- (histfrogp-1)*sizeof(histfrog[0]));
-
-out:
- histfrog[histfrogp-1] = s;
-}
-
-void
-nopout(Prog *p)
-{
- p->as = ANOP;
- p->from.type = D_NONE;
- p->to.type = D_NONE;
-}
-
-uchar*
-readsome(int f, uchar *buf, uchar *good, uchar *stop, int max)
-{
- int n;
-
- n = stop - good;
- memmove(buf, good, stop - good);
- stop = buf + n;
- n = MAXIO - n;
- if(n > max)
- n = max;
- n = read(f, stop, n);
- if(n <= 0)
- return 0;
- return stop + n;
-}
-
-void
-ldobj(int f, long c, char *pn)
-{
- long ipc;
- Prog *p, *t;
- uchar *bloc, *bsize, *stop;
- Sym *h[NSYM], *s, *di;
- int v, o, r, skip;
-
- bsize = buf.xbuf;
- bloc = buf.xbuf;
- di = S;
-
-newloop:
- memset(h, 0, sizeof(h));
- version++;
- histfrogp = 0;
- ipc = pc;
- skip = 0;
-
-loop:
- if(c <= 0)
- goto eof;
- r = bsize - bloc;
- if(r < 100 && r < c) { /* enough for largest prog */
- bsize = readsome(f, buf.xbuf, bloc, bsize, c);
- if(bsize == 0)
- goto eof;
- bloc = buf.xbuf;
- goto loop;
- }
- o = bloc[0]; /* as */
- if(o <= AXXX || o >= ALAST) {
- diag("%s: line %ld: opcode out of range %d", pn, pc-ipc, o);
- print(" probably not a .7 file\n");
- errorexit();
- }
- if(o == ANAME) {
- stop = memchr(&bloc[3], 0, bsize-&bloc[3]);
- if(stop == 0){
- bsize = readsome(f, buf.xbuf, bloc, bsize, c);
- if(bsize == 0)
- goto eof;
- bloc = buf.xbuf;
- stop = memchr(&bloc[3], 0, bsize-&bloc[3]);
- if(stop == 0){
- fprint(2, "%s: name too long\n", pn);
- errorexit();
- }
- }
- v = bloc[1]; /* type */
- o = bloc[2]; /* sym */
- bloc += 3;
- c -= 3;
-
- r = 0;
- if(v == D_STATIC)
- r = version;
- s = lookup((char*)bloc, r);
- c -= &stop[1] - bloc;
- bloc = stop + 1;
-
- if(debug['W'])
- print(" ANAME %s\n", s->name);
- h[o] = s;
- if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
- s->type = SXREF;
- if(v == D_FILE) {
- if(s->type != SFILE) {
- histgen++;
- s->type = SFILE;
- s->value = histgen;
- }
- if(histfrogp < MAXHIST) {
- histfrog[histfrogp] = s;
- histfrogp++;
- } else
- collapsefrog(s);
- }
- goto loop;
- }
-
- if(nhunk < sizeof(Prog))
- gethunk();
- p = (Prog*)hunk;
- nhunk -= sizeof(Prog);
- hunk += sizeof(Prog);
-
- p->as = o;
- p->reg = bloc[1] & 0x7f;
- if(bloc[1] & 0x80)
- p->mark = NOSCHED;
- p->line = bloc[2] | (bloc[3]<<8) | (bloc[4]<<16) | (bloc[5]<<24);
-
- r = zaddr(bloc+6, &p->from, h) + 6;
- r += zaddr(bloc+r, &p->to, h);
- bloc += r;
- c -= r;
-
- if(p->reg < 0 || p->reg > NREG)
- diag("register out of range %d", p->reg);
-
- p->link = P;
- p->cond = P;
-
- if(debug['W'])
- print("%P\n", p);
-
- switch(o) {
- case AHISTORY:
- if(p->to.offset == -1) {
- addlib(pn);
- histfrogp = 0;
- goto loop;
- }
- addhist(p->line, D_FILE); /* 'z' */
- if(p->to.offset)
- addhist(p->to.offset, D_PREG); /* 'Z' */
- histfrogp = 0;
- goto loop;
-
- case AEND:
- histtoauto();
- if(curtext != P)
- curtext->to.autom = curauto;
- curauto = 0;
- curtext = P;
- if(c)
- goto newloop;
- return;
-
- case AGLOBL:
- s = p->from.sym;
- if(s == S) {
- diag("GLOBL must have a name\n%P", p);
- errorexit();
- }
- if(s->type == 0 || s->type == SXREF) {
- s->type = SBSS;
- s->value = 0;
- }
- if(s->type != SBSS) {
- diag("redefinition: %s\n%P", s->name, p);
- s->type = SBSS;
- s->value = 0;
- }
- if(p->to.offset > s->value)
- s->value = p->to.offset;
- break;
-
- case ADYNT:
- if(p->to.sym == S) {
- diag("DYNT without a sym\n%P", p);
- break;
- }
- di = p->to.sym;
- p->reg = 4;
- if(di->type == SXREF) {
- if(debug['z'])
- Bprint(&bso, "%P set to %d\n", p, dtype);
- di->type = SCONST;
- di->value = dtype;
- dtype += 4;
- }
- if(p->from.sym == S)
- break;
-
- p->from.offset = di->value;
- p->from.sym->type = SDATA;
- if(curtext == P) {
- diag("DYNT not in text: %P", p);
- break;
- }
- p->to.sym = curtext->from.sym;
- p->to.type = D_CONST;
- p->link = datap;
- datap = p;
- break;
-
- case AINIT:
- if(p->from.sym == S) {
- diag("INIT without a sym\n%P", p);
- break;
- }
- if(di == S) {
- diag("INIT without previous DYNT\n%P", p);
- break;
- }
- p->from.offset = di->value;
- p->from.sym->type = SDATA;
- p->link = datap;
- datap = p;
- break;
-
- case ADATA:
- if(p->from.sym == S) {
- diag("DATA without a sym\n%P", p);
- break;
- }
- p->link = datap;
- datap = p;
- break;
-
- case AGOK:
- diag("unknown opcode\n%P", p);
- p->pc = pc;
- pc++;
- break;
-
- case ATEXT:
- if(curtext != P) {
- histtoauto();
- curtext->to.autom = curauto;
- curauto = 0;
- }
- skip = 0;
- curtext = p;
- autosize = (p->to.offset+3L) & ~3L;
- if (autosize & 4)
- autosize += 4;
- p->to.offset = autosize;
- autosize += 8;
- s = p->from.sym;
- if(s == S) {
- diag("TEXT must have a name\n%P", p);
- errorexit();
- }
- if(s->type != 0 && s->type != SXREF) {
- if(p->reg & DUPOK) {
- skip = 1;
- goto casedef;
- }
- diag("redefinition: %s\n%P", s->name, p);
- }
- s->type = STEXT;
- s->value = pc;
- lastp->link = p;
- lastp = p;
- p->pc = pc;
- pc++;
- if(textp == P) {
- textp = p;
- etextp = p;
- goto loop;
- }
- etextp->cond = p;
- etextp = p;
- break;
-
- case AMOVS:
- if(skip)
- goto casedef;
-
- if(p->from.type == D_FCONST) {
- /* size sb 9 max */
- snprint(literal, sizeof literal, "$%lux", ieeedtof(p->from.ieee));
- s = lookup(literal, 0);
- if(s->type == 0) {
- s->type = SBSS;
- s->value = 4;
- t = prg();
- t->as = ADATA;
- t->line = p->line;
- t->from.type = D_OREG;
- t->from.sym = s;
- t->from.name = D_EXTERN;
- t->reg = 4;
- t->to = p->from;
- t->link = datap;
- datap = t;
- }
- p->from.type = D_OREG;
- p->from.sym = s;
- p->from.name = D_EXTERN;
- p->from.offset = 0;
- }
- goto casedef;
-
- case AMOVT:
- if(skip)
- goto casedef;
-
- if(p->from.type == D_FCONST) {
- /* size sb 18 max */
- snprint(literal, sizeof literal, "$%lux.%lux",
- p->from.ieee->l, p->from.ieee->h);
- s = lookup(literal, 0);
- if(s->type == 0) {
- s->type = SBSS;
- s->value = 8;
- t = prg();
- t->as = ADATA;
- t->line = p->line;
- t->from.type = D_OREG;
- t->from.sym = s;
- t->from.name = D_EXTERN;
- t->reg = 8;
- t->to = p->from;
- t->link = datap;
- datap = t;
- }
- p->from.type = D_OREG;
- p->from.sym = s;
- p->from.name = D_EXTERN;
- p->from.offset = 0;
- }
- goto casedef;
-
- case AMOVQ:
- if(skip)
- goto casedef;
-
- if (p->from.type == D_FREG || p->to.type == D_FREG)
- p->as = AMOVT; /* stupid compiler optimiser kkludge */
-
- case AMOVL:
- case AMOVW:
- case AMOVB:
- /* BOTCH */
- if (p->from.type == D_CONST)
- if (p->from.offset == 0LL && p->from.name == D_NONE) {
- p->from.type = D_REG;
- p->from.reg = REGZERO;
- }
- goto casedef;
-
- default:
- casedef:
- if(skip)
- nopout(p);
-
- if(p->to.type == D_BRANCH)
- p->to.offset += ipc;
- lastp->link = p;
- lastp = p;
- p->pc = pc;
- pc++;
- break;
- }
- goto loop;
-
-eof:
- diag("truncated object file: %s", pn);
-}
-
-Sym*
-lookup(char *symb, int v)
-{
- Sym *s;
- char *p;
- long h;
- int c0, l;
-
- h = v;
- for(p=symb; c0 = *p; p++)
- h = h+h+h + c0;
- l = (p - symb) + 1;
- if(h < 0)
- h = ~h;
- h %= NHASH;
- for(s = hash[h]; s != S; s = s->link)
- if(s->version == v)
- if(memcmp(s->name, symb, l) == 0)
- return s;
-
- while(nhunk < sizeof(Sym))
- gethunk();
- s = (Sym*)hunk;
- nhunk -= sizeof(Sym);
- hunk += sizeof(Sym);
-
- s->name = malloc(l);
- memmove(s->name, symb, l);
-
- s->link = hash[h];
- s->type = 0;
- s->version = v;
- s->value = 0;
- hash[h] = s;
- return s;
-}
-
-Prog*
-prg(void)
-{
- Prog *p;
-
- while(nhunk < sizeof(Prog))
- gethunk();
- p = (Prog*)hunk;
- nhunk -= sizeof(Prog);
- hunk += sizeof(Prog);
-
- *p = zprg;
- return p;
-}
-
-void
-gethunk(void)
-{
- char *h;
- long nh;
-
- nh = NHUNK;
- if(thunk >= 5L*NHUNK) {
- nh = 5L*NHUNK;
- if(thunk >= 25L*NHUNK)
- nh = 25L*NHUNK;
- }
- h = mysbrk(nh);
- if(h == (char*)-1) {
- diag("out of memory");
- errorexit();
- }
- hunk = h;
- nhunk = nh;
- thunk += nh;
-}
-
-void
-doprof1(void)
-{
- Sym *s;
- long n;
- Prog *p, *q;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f profile 1\n", cputime());
- Bflush(&bso);
- s = lookup("__mcount", 0);
- n = 1;
- for(p = firstp->link; p != P; p = p->link) {
- if(p->as == ATEXT) {
- q = prg();
- q->line = p->line;
- q->link = datap;
- datap = q;
- q->as = ADATA;
- q->from.type = D_OREG;
- q->from.name = D_EXTERN;
- q->from.offset = n*4;
- q->from.sym = s;
- q->reg = 4;
- q->to = p->from;
- q->to.type = D_CONST;
-
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- p->link = q;
- p = q;
- p->as = AMOVL;
- p->from.type = D_OREG;
- p->from.name = D_EXTERN;
- p->from.sym = s;
- p->from.offset = n*4 + 4;
- p->to.type = D_REG;
- p->to.reg = REGTMP;
-
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- p->link = q;
- p = q;
- p->as = AADDQ;
- p->from.type = D_CONST;
- p->from.offset = 1;
- p->to.type = D_REG;
- p->to.reg = REGTMP;
-
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- p->link = q;
- p = q;
- p->as = AMOVL;
- p->from.type = D_REG;
- p->from.reg = REGTMP;
- p->to.type = D_OREG;
- p->to.name = D_EXTERN;
- p->to.sym = s;
- p->to.offset = n*4 + 4;
-
- n += 2;
- continue;
- }
- }
- q = prg();
- q->line = 0;
- q->link = datap;
- datap = q;
-
- q->as = ADATA;
- q->from.type = D_OREG;
- q->from.name = D_EXTERN;
- q->from.sym = s;
- q->reg = 4;
- q->to.type = D_CONST;
- q->to.offset = n;
-
- s->type = SBSS;
- s->value = n*4;
-}
-
-void
-doprof2(void)
-{
- Sym *s2, *s4;
- Prog *p, *q, *q2, *ps2, *ps4;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f profile 2\n", cputime());
- Bflush(&bso);
-
- if(debug['e']){
- s2 = lookup("_tracein", 0);
- s4 = lookup("_traceout", 0);
- }else{
- s2 = lookup("_profin", 0);
- s4 = lookup("_profout", 0);
- }
- if(s2->type != STEXT || s4->type != STEXT) {
- if(debug['e'])
- diag("_tracein/_traceout not defined %d %d", s2->type, s4->type);
- else
- diag("_profin/_profout not defined");
- return;
- }
-
- ps2 = P;
- ps4 = P;
- for(p = firstp; p != P; p = p->link) {
- if(p->as == ATEXT) {
- if(p->from.sym == s2) {
- ps2 = p;
- p->reg = 1;
- }
- if(p->from.sym == s4) {
- ps4 = p;
- p->reg = 1;
- }
- }
- }
- for(p = firstp; p != P; p = p->link) {
- if(p->as == ATEXT) {
- if(p->reg != NREG) {
- for(;;) {
- q = p->link;
- if(q == P)
- break;
- if(q->as == ATEXT)
- break;
- p = q;
- }
- continue;
- }
-
- /*
- * JSR profin, R2
- */
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- if(debug['e']){ /* embedded tracing */
- q2 = prg();
- p->link = q2;
- q2->link = q;
-
- q2->line = p->line;
- q2->pc = p->pc;
-
- q2->as = AJMP;
- q2->to.type = D_BRANCH;
- q2->to.sym = p->to.sym;
- q2->cond = q->link;
- }else
- p->link = q;
- p = q;
- p->as = AJSR;
- p->to.type = D_BRANCH;
- p->cond = ps2;
- p->to.sym = s2;
-
- continue;
- }
- if(p->as == ARET) {
- /*
- * JSR (default)
- */
- if(debug['e']){ /* embedded tracing */
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- p->link = q;
- p = q;
- }
- /*
- * JSR profout
- */
- p->as = AJSR;
- p->to.type = D_BRANCH;
- p->cond = ps4;
- p->to.sym = s4;
-
-
- /*
- * RET
- */
- q = prg();
- q->line = p->line;
- q->pc = p->pc;
- q->link = p->link;
- p->link = q;
- p = q;
- p->as = ARET;
-
- continue;
- }
- }
-}
-
-void
-nuxiinit(void)
-{
- int i, c;
-
- for(i=0; i<4; i++) {
- c = find1(0x04030201L, i+1);
- if(i <= 4)
- inuxi4[i] = c;
- if(i <= 2)
- inuxi2[i] = c;
- if(i <= 1)
- inuxi1[i] = c;
- }
- for (i = 0; i < 4; i++) {
- c = find1(0x04030201L, i+1);
- fnuxi8[i] = c;
- fnuxi8[i+4] = c + sizeof(long);
- }
-
- if(debug['v']) {
- Bprint(&bso, "inuxi = ");
- for(i=0; i<1; i++)
- Bprint(&bso, "%d", inuxi1[i]);
- Bprint(&bso, " ");
- for(i=0; i<2; i++)
- Bprint(&bso, "%d", inuxi2[i]);
- Bprint(&bso, " ");
- for(i=0; i<4; i++)
- Bprint(&bso, "%d", inuxi4[i]);
- Bprint(&bso, " ");
- Bprint(&bso, "\nfnuxi = ");
- for(i=0; i<8; i++)
- Bprint(&bso, "%d", fnuxi8[i]);
- Bprint(&bso, "\n");
- }
- Bflush(&bso);
-}
-
-find1(long l, int c)
-{
- char *p;
- int i;
-
- p = (char*)&l;
- for(i=0; i<4; i++)
- if(*p++ == c)
- return i;
- return 0;
-}
-
-long
-ieeedtof(Ieee *ieee)
-{
- int exp;
- long v;
-
- if(ieee->h == 0)
- return 0;
- exp = (ieee->h>>20) & ((1L<<11)-1L);
- exp -= (1L<<10) - 2L;
- v = (ieee->h & 0xfffffL) << 3;
- v |= (ieee->l >> 29) & 0x7L;
- if((ieee->l >> 28) & 1) {
- v++;
- if(v & 0x800000L) {
- v = (v & 0x7fffffL) >> 1;
- exp++;
- }
- }
- if(exp <= -126 || exp >= 130)
- diag("double fp to single fp overflow");
- v |= ((exp + 126) & 0xffL) << 23;
- v |= ieee->h & 0x80000000L;
- return v;
-}
-
-double
-ieeedtod(Ieee *ieee)
-{
- Ieee e;
- double fr;
- int exp;
-
- if(ieee->h & (1L<<31)) {
- e.h = ieee->h & ~(1L<<31);
- e.l = ieee->l;
- return -ieeedtod(&e);
- }
- if(ieee->l == 0 && ieee->h == 0)
- return 0;
- fr = ieee->l & ((1L<<16)-1L);
- fr /= 1L<<16;
- fr += (ieee->l>>16) & ((1L<<16)-1L);
- fr /= 1L<<16;
- fr += (ieee->h & (1L<<20)-1L) | (1L<<20);
- fr /= 1L<<21;
- exp = (ieee->h>>20) & ((1L<<11)-1L);
- exp -= (1L<<10) - 2L;
- return ldexp(fr, exp);
-}
diff --git a/sys/src/cmd/7l/optab.c b/sys/src/cmd/7l/optab.c
deleted file mode 100644
index 0f2852e80..000000000
--- a/sys/src/cmd/7l/optab.c
+++ /dev/null
@@ -1,141 +0,0 @@
-#include "l.h"
-
-#define X 99
-
-Optab optab[] =
-{
- { ATEXT, C_LEXT, C_NONE, C_LCON, 0, 0, 0 },
- { ATEXT, C_LEXT, C_REG, C_LCON, 0, 0, 0 },
-
- { AMOVQ, C_REG, C_NONE, C_REG, 1, 4, 0 },
- { AMOVQ, C_SCON, C_NONE, C_REG, 6, 4, REGZERO },
- { AMOVQ, C_SECON,C_NONE, C_REG, 6, 4, REGSB },
- { AMOVQ, C_SACON,C_NONE, C_REG, 6, 4, REGSP },
-
- { AMOVQ, C_LCON, C_NONE, C_REG, 15, 8, REGZERO },
- { AMOVQ, C_LECON,C_NONE, C_REG, 15, 8, REGSB },
- { AMOVQ, C_LACON,C_NONE, C_REG, 15, 8, REGSP },
-
- { AMOVQ, C_QCON, C_NONE, C_REG, 16,20, REGZERO },
-
- { AMOVQ, C_REG, C_NONE, C_SOREG, 8, 4, REGZERO },
- { AMOVQ, C_REG, C_NONE, C_SEXT, 8, 4, REGSB },
- { AMOVQ, C_REG, C_NONE, C_SAUTO, 8, 4, REGSP },
-
- { AMOVQ, C_SOREG,C_NONE, C_REG, 9, 4, REGZERO },
- { AMOVQ, C_SEXT, C_NONE, C_REG, 9, 4, REGSB },
- { AMOVQ, C_SAUTO,C_NONE, C_REG, 9, 4, REGSP },
-
- { AMOVQ, C_REG, C_NONE, C_LOREG, 19, 8, REGZERO },
- { AMOVQ, C_REG, C_NONE, C_LEXT, 19, 8, REGSB },
- { AMOVQ, C_REG, C_NONE, C_LAUTO, 19, 8, REGSP },
-
- { AMOVQ, C_LOREG,C_NONE, C_REG, 20, 8, REGZERO },
- { AMOVQ, C_LEXT, C_NONE, C_REG, 20, 8, REGSB },
- { AMOVQ, C_LAUTO,C_NONE, C_REG, 20, 8, REGSP },
-/*
- { AMOVBU, C_REG, C_NONE, C_REG, 7, 4, 0 },
- { AMOVB, C_REG, C_NONE, C_REG, 10, 8, 0 },
-*/
- { AMOVT, C_FREG, C_NONE, C_FREG, 17, 4, 0 },
-
- { AMOVT, C_FREG, C_NONE, C_SOREG, 8, 4, REGZERO },
- { AMOVT, C_FREG, C_NONE, C_SEXT, 8, 4, REGSB },
- { AMOVT, C_FREG, C_NONE, C_SAUTO, 8, 4, REGSP },
-
- { AMOVT, C_SOREG,C_NONE, C_FREG, 9, 4, REGZERO },
- { AMOVT, C_SEXT, C_NONE, C_FREG, 9, 4, REGSB },
- { AMOVT, C_SAUTO,C_NONE, C_FREG, 9, 4, REGSP },
-
- { AMOVT, C_FREG, C_NONE, C_LOREG, 19, 8, REGZERO },
- { AMOVT, C_FREG, C_NONE, C_LEXT, 19, 8, REGSB },
- { AMOVT, C_FREG, C_NONE, C_LAUTO, 19, 8, REGSP },
-
- { AMOVT, C_LOREG,C_NONE, C_FREG, 20, 8, REGZERO },
- { AMOVT, C_LEXT, C_NONE, C_FREG, 20, 8, REGSB },
- { AMOVT, C_LAUTO,C_NONE, C_FREG, 20, 8, REGSP },
-
- { AADDQ, C_REG, C_REG, C_REG, 2, 4, 0 },
- { AADDL, C_REG, C_REG, C_REG, 2, 4, 0 },
- { AAND, C_REG, C_REG, C_REG, 2, 4, 0 },
- { AMULQ, C_REG, C_REG, C_REG, 2, 4, 0 },
- { AADDQ, C_REG, C_NONE, C_REG, 2, 4, 0 },
- { AADDL, C_REG, C_NONE, C_REG, 2, 4, 0 },
- { AAND, C_REG, C_NONE, C_REG, 2, 4, 0 },
- { AMULQ, C_REG, C_NONE, C_REG, 2, 4, 0 },
-
- { AADDQ, C_SCON, C_REG, C_REG, 12, 4, 0 },
- { AADDQ, C_SCON, C_NONE, C_REG, 12, 4, 0 },
-
- { AADDL, C_BCON, C_REG, C_REG, 3, 4, 0 },
- { AAND, C_BCON, C_REG, C_REG, 3, 4, 0 },
- { AMULQ, C_BCON, C_REG, C_REG, 3, 4, 0 },
- { AADDL, C_BCON, C_NONE, C_REG, 3, 4, 0 },
- { AAND, C_BCON, C_NONE, C_REG, 3, 4, 0 },
- { AMULQ, C_BCON, C_NONE, C_REG, 3, 4, 0 },
-
-/* { AADDL, C_NCON, C_REG, C_REG, 34, 4, 0 }, */
- { AAND, C_NCON, C_REG, C_REG, 34, 4, 0 },
-/* { AADDL, C_NCON, C_NONE, C_REG, 34, 4, 0 }, */
- { AAND, C_NCON, C_NONE, C_REG, 34, 4, 0 },
-
- { AADDL, C_SCON, C_REG, C_REG, 13, 8, 0 },
- { AAND, C_SCON, C_REG, C_REG, 13, 8, 0 },
- { AMULQ, C_SCON, C_REG, C_REG, 13, 8, 0 },
- { AADDL, C_SCON, C_NONE, C_REG, 13, 8, 0 },
- { AAND, C_SCON, C_NONE, C_REG, 13, 8, 0 },
- { AMULQ, C_SCON, C_NONE, C_REG, 13, 8, 0 },
-
- { AADDQ, C_LCON, C_REG, C_REG, 14,12, 0 },
- { AADDQ, C_LCON, C_NONE, C_REG, 14,12, 0 },
- { AADDL, C_LCON, C_REG, C_REG, 14,12, 0 },
- { AAND, C_LCON, C_REG, C_REG, 14,12, 0 },
- { AMULQ, C_LCON, C_REG, C_REG, 14,12, 0 },
- { AADDL, C_LCON, C_NONE, C_REG, 14,12, 0 },
- { AAND, C_LCON, C_NONE, C_REG, 14,12, 0 },
- { AMULQ, C_LCON, C_NONE, C_REG, 14,12, 0 },
-
- { AADDQ, C_QCON, C_REG, C_REG, 23,24, 0 },
- { AADDQ, C_QCON, C_NONE, C_REG, 23,24, 0 },
- { AADDL, C_QCON, C_REG, C_REG, 23,24, 0 },
- { AAND, C_QCON, C_REG, C_REG, 23,24, 0 },
- { AMULQ, C_QCON, C_REG, C_REG, 23,24, 0 },
- { AADDL, C_QCON, C_NONE, C_REG, 23,24, 0 },
- { AAND, C_QCON, C_NONE, C_REG, 23,24, 0 },
- { AMULQ, C_QCON, C_NONE, C_REG, 23,24, 0 },
-
- { AADDT, C_FREG, C_REG, C_FREG, 2, 4, 0 },
- { AADDT, C_FREG, C_NONE, C_FREG, 2, 4, 0 },
- { ACVTTQ, C_FREG, C_NONE, C_FREG, 28, 4, 0 },
-
- { ABEQ, C_REG, C_NONE, C_SBRA, 4, 4, 0 },
- { AFBEQ, C_FREG, C_NONE, C_SBRA, 4, 4, 0 },
-
- { AJMP, C_NONE, C_NONE, C_SBRA, 11, 4, 0 },
- { AJSR, C_NONE, C_NONE, C_SBRA, 11, 4, 0 },
-
- { AJMP, C_NONE, C_NONE, C_ZOREG, 5, 4, REGZERO },
- { AJSR, C_NONE, C_NONE, C_ZOREG, 5, 4, REGLINK },
- { AJMP, C_NONE, C_REG, C_ZOREG, 5, 4, REGZERO },
- { AJSR, C_NONE, C_REG, C_ZOREG, 5, 4, REGLINK },
- { ACALL_PAL, C_SCON, C_NONE, C_NONE, 18, 4, 0 },
- { AWORD, C_NONE, C_NONE, C_LCON, 40, 4, 0 },
-
- { AMOVT, C_FREG, C_NONE, C_FCREG, 24, 4, 0 },
- { AMOVT, C_FCREG,C_NONE, C_FREG, 25, 4, 0 },
-
- { AMOVQ, C_REG, C_NONE, C_PREG, 26, 4, 0 },
- { AMOVQ, C_PREG, C_NONE, C_REG, 27, 4, 0 },
- { AMOVQ, C_PCC, C_NONE, C_REG, 29, 4, 0 },
-
- { AREI, C_NONE, C_NONE, C_NONE, 30, 4, 0 },
- { AFETCH, C_ZOREG,C_NONE, C_NONE, 31, 4, REGZERO },
-
- { AMOVQL, C_SOREG,C_NONE, C_REG, 9, 4, REGZERO },
- { AMOVQC, C_REG, C_NONE, C_SOREG, 8, 4, REGZERO },
-
- { AMOVQP, C_SOREG,C_NONE, C_REG, 33, 4, REGZERO },
- { AMOVQP, C_REG, C_NONE, C_SOREG, 32, 4, REGZERO },
-
- { AXXX, C_NONE, C_NONE, C_NONE, 0, 4, 0 },
-};
diff --git a/sys/src/cmd/7l/pass.c b/sys/src/cmd/7l/pass.c
deleted file mode 100644
index e0451b532..000000000
--- a/sys/src/cmd/7l/pass.c
+++ /dev/null
@@ -1,495 +0,0 @@
-#include "l.h"
-
-void
-dodata(void)
-{
- int i, t, size;
- Sym *s;
- Prog *p, *p1;
- long orig, orig1, v;
- vlong vv;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f dodata\n", cputime());
- Bflush(&bso);
- for(p = datap; p != P; p = p->link) {
- s = p->from.sym;
- if(p->as == ADYNT || p->as == AINIT)
- s->value = dtype;
- if(s->type == SBSS)
- s->type = SDATA;
- if(s->type != SDATA)
- diag("initialize non-data (%d): %s\n%P",
- s->type, s->name, p);
- v = p->from.offset + p->reg;
- if(v > s->value)
- diag("initialize bounds (%ld): %s\n%P",
- s->value, s->name, p);
- }
-
- /*
- * pass 1
- * assign 'small' variables to data segment
- * (rational is that data segment is more easily
- * addressed through offset on REGSB)
- */
- orig = 0;
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link) {
- t = s->type;
- if(t != SDATA && t != SBSS)
- continue;
- v = s->value;
- if(v == 0) {
- diag("%s: no size", s->name);
- v = 1;
- }
- while(v & 3)
- v++;
-
- s->value = v;
- if(v > MINSIZ)
- continue;
- if (v >= 8)
- orig = rnd(orig, 8);
- s->value = orig;
- orig += v;
- s->type = SDATA1;
- }
- orig = rnd(orig, 8);
- orig1 = orig;
-
- /*
- * pass 2
- * assign 'data' variables to data segment
- */
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link) {
- t = s->type;
- if(t != SDATA) {
- if(t == SDATA1)
- s->type = SDATA;
- continue;
- }
- v = s->value;
- if (v >= 8)
- orig = rnd(orig, 8);
- s->value = orig;
- orig += v;
- s->type = SDATA1;
- }
-
- orig = rnd(orig, 8);
- datsize = orig;
-
- /*
- * pass 3
- * everything else to bss segment
- */
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link) {
- if(s->type != SBSS)
- continue;
- v = s->value;
- if (v >= 8)
- orig = rnd(orig, 8);
- s->value = orig;
- orig += v;
- }
- orig = rnd(orig, 8);
- bsssize = orig-datsize;
-
- /*
- * pass 4
- * add literals to all large values.
- * at this time:
- * small data is allocated DATA
- * large data is allocated DATA1
- * large bss is allocated BSS
- * the new literals are loaded between
- * small data and large data.
- */
- orig = 0;
- for(p = firstp; p != P; p = p->link) {
- if(p->as != AMOVQ)
- continue;
- if(p->from.type != D_CONST)
- continue;
- if(s = p->from.sym) {
- t = s->type;
- if(t != SDATA && t != SDATA1 && t != SBSS)
- continue;
- t = p->from.name;
- if(t != D_EXTERN && t != D_STATIC)
- continue;
- v = s->value + p->from.offset;
- size = 4;
- if(v >= 0 && v <= 0xffff)
- continue;
- if(!strcmp(s->name, "setSB"))
- continue;
- /* size should be 19 max */
- if(strlen(s->name) >= 10) /* has loader address */
- snprint(literal, sizeof literal, "$%p.%llux", s, p->from.offset);
- else
- snprint(literal, sizeof literal, "$%s.%d.%llux", s->name, s->version, p->from.offset);
- } else {
- if(p->from.name != D_NONE)
- continue;
- if(p->from.reg != NREG)
- continue;
- vv = p->from.offset;
- if(vv >= -0x8000LL && vv <= 0x7fff)
- continue;
- if(!(vv & 0xffff))
- continue;
- size = 8;
- if (vv <= 0x7FFFFFFFLL && vv >= -0x80000000LL)
- size = 4;
- /* size should be 17 max */
- snprint(literal, sizeof literal, "$%llux", vv);
- }
- s = lookup(literal, 0);
- if(s->type == 0) {
- s->type = SDATA;
- orig = rnd(orig, size);
- s->value = orig1+orig;
- orig += size;
- p1 = prg();
- p1->line = p->line;
- p1->as = ADATA;
- p1->from.type = D_OREG;
- p1->from.sym = s;
- p1->from.name = D_EXTERN;
- p1->reg = size;
- p1->to = p->from;
- p1->link = datap;
- datap = p1;
- if(debug['C'])
- Bprint(&bso, "literal %P for %P\n", p1, p);
- }
- if(s->type != SDATA)
- diag("literal not data: %s", s->name);
- if (size == 4)
- p->as = AMOVL;
- p->from.type = D_OREG;
- p->from.sym = s;
- p->from.name = D_EXTERN;
- p->from.offset = 0;
- continue;
- }
- orig = rnd(orig, 8);
-
- /*
- * pass 5
- * re-adjust offsets
- */
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link) {
- t = s->type;
- if(t == SBSS) {
- s->value += orig;
- continue;
- }
- if(t == SDATA1) {
- s->type = SDATA;
- s->value += orig;
- continue;
- }
- }
- datsize += orig;
- if (debug['v'] || debug['z'])
- Bprint(&bso, "datsize = %lux, bsssize = %lux\n", datsize, bsssize);
- xdefine("setSB", SDATA, 0L+BIG);
- xdefine("bdata", SDATA, 0L);
- xdefine("edata", SDATA, datsize);
- xdefine("end", SBSS, datsize+bsssize);
- xdefine("etext", STEXT, 0L);
-}
-
-void
-undef(void)
-{
- int i;
- Sym *s;
-
- for(i=0; i<NHASH; i++)
- for(s = hash[i]; s != S; s = s->link)
- if(s->type == SXREF)
- diag("%s: not defined", s->name);
-}
-
-void
-follow(void)
-{
- if(debug['v'])
- Bprint(&bso, "%5.2f follow\n", cputime());
- Bflush(&bso);
-
- firstp = prg();
- lastp = firstp;
- xfol(textp);
-
- firstp = firstp->link;
- lastp->link = P;
-}
-
-void
-xfol(Prog *p)
-{
- Prog *q, *r;
- int a, i;
-
-loop:
- if(p == P)
- return;
- a = p->as;
- if(a == ATEXT)
- curtext = p;
- if(a == AJMP) {
- q = p->cond;
- if(q != P) {
- p->mark = FOLL;
- p = q;
- if(!(p->mark & FOLL))
- goto loop;
- }
- }
- if(p->mark & FOLL) {
- for(i=0,q=p; i<4; i++,q=q->link) {
- if(q == lastp)
- break;
- a = q->as;
- if(a == ANOP) {
- i--;
- continue;
- }
- if(a == AJMP || a == ARET || a == AREI)
- goto copy;
- if(!q->cond || (q->cond->mark&FOLL))
- continue;
- if(a != ABEQ && a != ABNE)
- continue;
- copy:
- for(;;) {
- r = prg();
- *r = *p;
- if(!(r->mark&FOLL))
- print("cant happen 1\n");
- r->mark = FOLL;
- if(p != q) {
- p = p->link;
- lastp->link = r;
- lastp = r;
- continue;
- }
- lastp->link = r;
- lastp = r;
- if(a == AJMP || a == ARET || a == AREI)
- return;
- r->as = ABNE;
- if(a == ABNE)
- r->as = ABEQ;
- r->cond = p->link;
- r->link = p->cond;
- if(!(r->link->mark&FOLL))
- xfol(r->link);
- if(!(r->cond->mark&FOLL))
- print("cant happen 2\n");
- return;
- }
- }
- a = AJMP;
- q = prg();
- q->as = a;
- q->line = p->line;
- q->to.type = D_BRANCH;
- q->to.offset = p->pc;
- q->cond = p;
- p = q;
- }
- p->mark = FOLL;
- lastp->link = p;
- lastp = p;
- if(a == AJMP || a == ARET || a == AREI)
- return;
- if(p->cond != P)
- if(a != AJSR && p->link != P) {
- xfol(p->link);
- p = p->cond;
- if(p == P || (p->mark&FOLL))
- return;
- goto loop;
- }
- p = p->link;
- goto loop;
-}
-
-void
-patch(void)
-{
- long c, vexit;
- Prog *p, *q;
- Sym *s;
- int a;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f patch\n", cputime());
- Bflush(&bso);
- mkfwd();
- s = lookup("exit", 0);
- vexit = s->value;
- for(p = firstp; p != P; p = p->link) {
- a = p->as;
- if(a == ATEXT)
- curtext = p;
- if((a == AJSR || a == AJMP || a == ARET) &&
- p->to.type != D_BRANCH && p->to.sym != S) {
- s = p->to.sym;
- if(s->type != STEXT) {
- diag("undefined: %s\n%P", s->name, p);
- s->type = STEXT;
- s->value = vexit;
- }
- p->to.offset = s->value;
- p->to.type = D_BRANCH;
- }
- if(p->to.type != D_BRANCH)
- continue;
- c = p->to.offset;
- for(q = firstp; q != P;) {
- if(q->forwd != P)
- if(c >= q->forwd->pc) {
- q = q->forwd;
- continue;
- }
- if(c == q->pc)
- break;
- q = q->link;
- }
- if(q == P) {
- diag("branch out of range %ld\n%P", c, p);
- p->to.type = D_NONE;
- }
- p->cond = q;
- }
-
- for(p = firstp; p != P; p = p->link) {
- if(p->as == ATEXT)
- curtext = p;
- if(p->cond != P) {
- p->cond = brloop(p->cond);
- if(p->cond != P)
- if(p->to.type == D_BRANCH)
- p->to.offset = p->cond->pc;
- }
- }
-}
-
-#define LOG 5
-void
-mkfwd(void)
-{
- Prog *p;
- long dwn[LOG], cnt[LOG], i;
- Prog *lst[LOG];
-
- for(i=0; i<LOG; i++) {
- if(i == 0)
- cnt[i] = 1; else
- cnt[i] = LOG * cnt[i-1];
- dwn[i] = 1;
- lst[i] = P;
- }
- i = 0;
- for(p = firstp; p != P; p = p->link) {
- if(p->as == ATEXT)
- curtext = p;
- i--;
- if(i < 0)
- i = LOG-1;
- p->forwd = P;
- dwn[i]--;
- if(dwn[i] <= 0) {
- dwn[i] = cnt[i];
- if(lst[i] != P)
- lst[i]->forwd = p;
- lst[i] = p;
- }
- }
-}
-
-Prog*
-brloop(Prog *p)
-{
- Prog *q;
- int c;
-
- for(c=0; p!=P;) {
- if(p->as != AJMP)
- return p;
- q = p->cond;
- if(q <= p) {
- c++;
- if(q == p || c > 50)
- break;
- }
- p = q;
- }
- return P;
-}
-
-long
-atolwhex(char *s)
-{
- long n;
- int f;
-
- n = 0;
- f = 0;
- while(*s == ' ' || *s == '\t')
- s++;
- if(*s == '-' || *s == '+') {
- if(*s++ == '-')
- f = 1;
- while(*s == ' ' || *s == '\t')
- s++;
- }
- if(s[0]=='0' && s[1]){
- if(s[1]=='x' || s[1]=='X'){
- s += 2;
- for(;;){
- if(*s >= '0' && *s <= '9')
- n = n*16 + *s++ - '0';
- else if(*s >= 'a' && *s <= 'f')
- n = n*16 + *s++ - 'a' + 10;
- else if(*s >= 'A' && *s <= 'F')
- n = n*16 + *s++ - 'A' + 10;
- else
- break;
- }
- } else
- while(*s >= '0' && *s <= '7')
- n = n*8 + *s++ - '0';
- } else
- while(*s >= '0' && *s <= '9')
- n = n*10 + *s++ - '0';
- if(f)
- n = -n;
- return n;
-}
-
-long
-rnd(long v, long r)
-{
- long c;
-
- if(r <= 0)
- return v;
- v += r - 1;
- c = v % r;
- if(c < 0)
- c += r;
- v -= c;
- return v;
-}
diff --git a/sys/src/cmd/7l/sched.c b/sys/src/cmd/7l/sched.c
deleted file mode 100644
index b7339b1e1..000000000
--- a/sys/src/cmd/7l/sched.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "l.h"
-
-void
-sched(Prog *p0, Prog *p1)
-{
-#ifdef CODSCHED
- Prog *p, *q, *t;
- int r, a;
-
- if(debug['X'])
- Bprint(&bso, "\n");
-#endif
- if (p0 == P || p0 == p1)
- return;
- if(debug['X'])
- Bprint(&bso, "sched from %P to %P\n", p0, p1);
-}
-
diff --git a/sys/src/cmd/7l/span.c b/sys/src/cmd/7l/span.c
deleted file mode 100644
index 65ba2df56..000000000
--- a/sys/src/cmd/7l/span.c
+++ /dev/null
@@ -1,584 +0,0 @@
-#include "l.h"
-
-void
-span(void)
-{
- Prog *p;
- Sym *setext;
- Optab *o;
- int m;
- long c;
-
- if(debug['v'])
- Bprint(&bso, "%5.2f span\n", cputime());
- Bflush(&bso);
- c = INITTEXT;
- for(p = firstp; p != P; p = p->link) {
- p->pc = c;
- o = oplook(p);
- m = o->size;
- if(m == 0) {
- if(p->as == ATEXT) {
- curtext = p;
- autosize = p->to.offset + 8;
- if(p->from.sym != S)
- p->from.sym->value = c;
- continue;
- }
- diag("zero-width instruction\n%P", p);
- continue;
- }
- c += m;
- }
- c = rnd(c, 8);
-
- setext = lookup("etext", 0);
- if(setext != S) {
- setext->value = c;
- textsize = c - INITTEXT;
- }
- if(INITRND)
- INITDAT = rnd(c, INITRND);
- if(debug['v'])
- Bprint(&bso, "tsize = %lux\n", textsize);
- Bflush(&bso);
-}
-
-void
-xdefine(char *p, int t, long v)
-{
- Sym *s;
-
- s = lookup(p, 0);
- if(s->type == 0 || s->type == SXREF) {
- s->type = t;
- s->value = v;
- }
-}
-
-vlong /* BUG? */
-regoff(Adr *a)
-{
-
- offset = 0;
- aclass(a);
- return offset;
-}
-
-/*
- * note that we can't generate every 32 bit constant with MOVQA+MOVQAH, hence the
- * comparison with 0x7fff8000. offset >= this value gets incorrectly sign extended in
- * the 64 bit register.
- */
-aclass(Adr *a)
-{
- Sym *s;
- int t;
-
- switch(a->type) {
- case D_NONE:
- return C_NONE;
-
- case D_REG:
- return C_REG;
-
- case D_FREG:
- return C_FREG;
-
- case D_FCREG:
- return C_FCREG;
-
- case D_PREG:
- return C_PREG;
-
- case D_PCC:
- return C_PCC;
-
- case D_OREG:
- switch(a->name) {
- case D_EXTERN:
- case D_STATIC:
- if(a->sym == 0) {
- print("null sym external\n");
- print("%D\n", a);
- return C_GOK;
- }
- t = a->sym->type;
- if(t == 0 || t == SXREF) {
- diag("undefined external: %s in %s",
- a->sym->name, TNAME);
- a->sym->type = SDATA;
- }
- offset = a->sym->value + a->offset - BIG;
- if(offset >= -BIG && offset < BIG)
- return C_SEXT;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LEXT;
- badoff:
- diag("offset out of range: %#llux", offset);
- return C_GOK;
- case D_AUTO:
- offset = autosize + a->offset;
- if(offset >= -BIG && offset < BIG)
- return C_SAUTO;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LAUTO;
- goto badoff;
- case D_PARAM:
- offset = autosize + a->offset + 8L;
- if(offset >= -BIG && offset < BIG)
- return C_SAUTO;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LAUTO;
- goto badoff;
- case D_NONE:
- offset = a->offset;
- if(offset == 0)
- return C_ZOREG;
- if(offset >= -BIG && offset < BIG)
- return C_SOREG;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LOREG;
- goto badoff;
- }
- return C_GOK;
-
- case D_CONST:
- switch(a->name) {
-
- case D_NONE:
- offset = a->offset;
- if(offset > 0) {
- if(offset <= 0xffLL)
- return C_BCON;
- if(offset <= 0x7fffLL)
- return C_SCON;
- if((offset & 0xffffLL) == 0 && offset <= 0x7fff0000LL)
- return C_UCON;
- if (offset < 0x7fff8000LL)
- return C_LCON;
- return C_QCON;
- }
- if(offset == 0)
- return C_ZCON;
- if(offset >= -0x100LL)
- return C_NCON;
- if(offset >= -0x8000LL)
- return C_SCON;
- if((offset & 0xffffLL) == 0 && offset >= -0x80000000LL)
- return C_UCON;
- if (offset >= -0x80000000LL)
- return C_LCON;
- return C_QCON;
-
- case D_EXTERN:
- case D_STATIC:
- s = a->sym;
- if(s == 0) {
- print("null sym const\n");
- print("%D\n", a);
- return C_GOK;
- }
- t = s->type;
- if(t == 0 || t == SXREF) {
- diag("undefined external: %s in %s",
- s->name, TNAME);
- s->type = SDATA;
- }
- if(s->type == STEXT || s->type == SLEAF) {
- offset = s->value + a->offset;
- return C_LCON;
- }
- offset = s->value + a->offset - BIG;
- if (offset == 0L) {
- offset = s->value + a->offset + INITDAT;
- return C_LCON; /* botch */
- }
- if(offset >= -BIG && offset < BIG && offset != 0L)
- return C_SECON;
- if (offset >= -0x80000000LL && offset < 0x7fff8000L && offset != 0LL /*&& offset >= -INITDAT*/)
- return C_LECON;
- /*offset = s->value + a->offset + INITDAT;*/
-/* if (offset >= -BIG && offset < BIG)
- return C_SCON;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LCON; */
- goto badoff;
- /*return C_QCON;*/
-
- case D_AUTO:
- offset = autosize + a->offset;
- if(offset >= -BIG && offset < BIG)
- return C_SACON;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LACON;
- goto badoff;
-
- case D_PARAM:
- offset = autosize + a->offset + 8L;
- if(offset >= -BIG && offset < BIG)
- return C_SACON;
- if (offset >= -0x80000000LL && offset < 0x7fff8000LL)
- return C_LACON;
- goto badoff;
- }
- return C_GOK;
-
- case D_BRANCH:
- return C_SBRA;
- }
- return C_GOK;
-}
-
-Optab*
-oplook(Prog *p)
-{
- int a1, a2, a3, r;
- char *c1, *c3;
- Optab *o, *e;
-
- a1 = p->optab;
- if(a1)
- return optab+(a1-1);
- a1 = p->from.class;
- if(a1 == 0) {
- a1 = aclass(&p->from) + 1;
- p->from.class = a1;
- }
- a1--;
- a3 = p->to.class;
- if(a3 == 0) {
- a3 = aclass(&p->to) + 1;
- p->to.class = a3;
- }
- a3--;
- a2 = C_NONE;
- if(p->reg != NREG)
- a2 = C_REG;
- r = p->as;
- o = oprange[r].start;
- if(o == 0) {
- a1 = opcross[repop[r]][a1][a2][a3];
- if(a1) {
- p->optab = a1+1;
- return optab+a1;
- }
- o = oprange[r].stop; /* just generate an error */
- }
- e = oprange[r].stop;
- c1 = xcmp[a1];
- c3 = xcmp[a3];
- for(; o<e; o++)
- if(o->a2 == a2)
- if(c1[o->a1])
- if(c3[o->a3]) {
- p->optab = (o-optab)+1;
- return o;
- }
- diag("illegal combination %A %d %d %d (opcross %d)",
- p->as, p->from.class-1, a2, a3, a1);
- if(!debug['a'])
- prasm(p);
- o = optab;
- p->optab = (o-optab)+1;
- return o;
-}
-
-int
-cmp(int a, int b)
-{
-
- if(a == b)
- return 1;
- switch(a) {
- case C_QCON:
- if(b == C_ZCON || b == C_BCON || b == C_NCON || b == C_SCON || b == C_UCON || b == C_LCON)
- return 1;
- break;
- case C_LCON:
- if(b == C_ZCON || b == C_BCON || b == C_NCON || b == C_SCON || b == C_UCON)
- return 1;
- break;
- case C_UCON:
- if(b == C_ZCON)
- return 1;
- break;
- case C_SCON:
- if(b == C_ZCON || b == C_BCON || b == C_NCON)
- return 1;
- break;
- case C_BCON:
- if(b == C_ZCON)
- return 1;
- break;
- case C_LACON:
- if(b == C_SACON)
- return 1;
- break;
- case C_LBRA:
- if(b == C_SBRA)
- return 1;
- break;
- case C_LEXT:
- if(b == C_SEXT)
- return 1;
- break;
- case C_LAUTO:
- if(b == C_SAUTO)
- return 1;
- break;
- case C_REG:
-/* if(b == C_ZCON)
- return 1; */
- break;
- case C_LOREG:
- if(b == C_ZOREG || b == C_SOREG)
- return 1;
- break;
- case C_SOREG:
- if(b == C_ZOREG)
- return 1;
- break;
- }
- return 0;
-}
-
-int
-ocmp(void *a1, void *a2)
-{
- Optab *p1, *p2;
- int n;
-
- p1 = a1;
- p2 = a2;
- n = p1->as - p2->as;
- if(n)
- return n;
- n = p1->a1 - p2->a1;
- if(n)
- return n;
- n = p1->a2 - p2->a2;
- if(n)
- return n;
- n = p1->a3 - p2->a3;
- if(n)
- return n;
- return 0;
-}
-
-void
-buildop(void)
-{
- int i, n, r;
-
- for(i=0; i<32; i++)
- for(n=0; n<32; n++)
- xcmp[i][n] = cmp(n, i);
- for(n=0; optab[n].as != AXXX; n++)
- ;
- qsort(optab, n, sizeof(optab[0]), ocmp);
- for(i=0; i<n; i++) {
- r = optab[i].as;
- oprange[r].start = optab+i;
- while(optab[i].as == r)
- i++;
- oprange[r].stop = optab+i;
- i--;
-
- switch(r)
- {
- default:
- diag("unknown op in build: %A", r);
- errorexit();
- case AADDQ:
- oprange[AS4ADDQ] = oprange[r];
- oprange[AS8ADDQ] = oprange[r];
- oprange[ASUBQ] = oprange[r];
- oprange[AS4SUBQ] = oprange[r];
- oprange[AS8SUBQ] = oprange[r];
- break;
- case AADDL:
- oprange[AADDLV] = oprange[r];
- oprange[AS4ADDL] = oprange[r];
- oprange[AS8ADDL] = oprange[r];
- oprange[AADDQV] = oprange[r];
- oprange[ASUBQV] = oprange[r];
- oprange[ASUBL] = oprange[r];
- oprange[ASUBLV] = oprange[r];
- oprange[AS4SUBL] = oprange[r];
- oprange[AS8SUBL] = oprange[r];
- break;
- case AAND:
- oprange[AANDNOT] = oprange[r];
- oprange[AOR] = oprange[r];
- oprange[AORNOT] = oprange[r];
- oprange[AXOR] = oprange[r];
- oprange[AXORNOT] = oprange[r];
- break;
- case AMULQ:
- oprange[ACMPEQ] = oprange[r];
- oprange[ACMPGT] = oprange[r];
- oprange[ACMPGE] = oprange[r];
- oprange[ACMPUGT] = oprange[r];
- oprange[ACMPUGE] = oprange[r];
- oprange[ACMPBLE] = oprange[r];
- oprange[ACMOVEQ] = oprange[r];
- oprange[ACMOVNE] = oprange[r];
- oprange[ACMOVLT] = oprange[r];
- oprange[ACMOVGE] = oprange[r];
- oprange[ACMOVLE] = oprange[r];
- oprange[ACMOVGT] = oprange[r];
- oprange[ACMOVLBS] = oprange[r];
- oprange[ACMOVLBC] = oprange[r];
- oprange[AMULL] = oprange[r];
- oprange[AMULLV] = oprange[r];
- oprange[AMULQV] = oprange[r];
- oprange[AUMULH] = oprange[r];
- oprange[ASLLQ] = oprange[r];
- oprange[ASRLQ] = oprange[r];
- oprange[ASRAQ] = oprange[r];
- oprange[AEXTBL] = oprange[r];
- oprange[AEXTWL] = oprange[r];
- oprange[AEXTLL] = oprange[r];
- oprange[AEXTQL] = oprange[r];
- oprange[AEXTWH] = oprange[r];
- oprange[AEXTLH] = oprange[r];
- oprange[AEXTQH] = oprange[r];
- oprange[AINSBL] = oprange[r];
- oprange[AINSWL] = oprange[r];
- oprange[AINSLL] = oprange[r];
- oprange[AINSQL] = oprange[r];
- oprange[AINSWH] = oprange[r];
- oprange[AINSLH] = oprange[r];
- oprange[AINSQH] = oprange[r];
- oprange[AMSKBL] = oprange[r];
- oprange[AMSKWL] = oprange[r];
- oprange[AMSKLL] = oprange[r];
- oprange[AMSKQL] = oprange[r];
- oprange[AMSKWH] = oprange[r];
- oprange[AMSKLH] = oprange[r];
- oprange[AMSKQH] = oprange[r];
- oprange[AZAP] = oprange[r];
- oprange[AZAPNOT] = oprange[r];
- break;
- case ABEQ:
- oprange[ABNE] = oprange[r];
- oprange[ABGE] = oprange[r];
- oprange[ABLE] = oprange[r];
- oprange[ABGT] = oprange[r];
- oprange[ABLT] = oprange[r];
- break;
- case AFBEQ:
- oprange[AFBNE] = oprange[r];
- oprange[AFBGE] = oprange[r];
- oprange[AFBLE] = oprange[r];
- oprange[AFBGT] = oprange[r];
- oprange[AFBLT] = oprange[r];
- break;
- case AMOVQ:
- oprange[AMOVL] = oprange[r];
- oprange[AMOVLU] = oprange[r];
- oprange[AMOVQU] = oprange[r];
- oprange[AMOVA] = oprange[r];
- oprange[AMOVAH] = oprange[r];
-
- oprange[AMOVBU] = oprange[r];
- oprange[AMOVWU] = oprange[r];
- oprange[AMOVB] = oprange[r];
- oprange[AMOVW] = oprange[r];
- break;
- case AMOVT:
- oprange[AMOVS] = oprange[r];
- break;
- case AADDT:
- oprange[AADDS] = oprange[r];
- oprange[ACMPTEQ] = oprange[r];
- oprange[ACMPTGT] = oprange[r];
- oprange[ACMPTGE] = oprange[r];
- oprange[ACMPTUN] = oprange[r];
- oprange[ADIVS] = oprange[r];
- oprange[ADIVT] = oprange[r];
- oprange[AMULS] = oprange[r];
- oprange[AMULT] = oprange[r];
- oprange[ASUBS] = oprange[r];
- oprange[ASUBT] = oprange[r];
- oprange[ACPYS] = oprange[r];
- oprange[ACPYSN] = oprange[r];
- oprange[ACPYSE] = oprange[r];
- oprange[ACVTLQ] = oprange[r];
- oprange[ACVTQL] = oprange[r];
- oprange[AFCMOVEQ] = oprange[r];
- oprange[AFCMOVNE] = oprange[r];
- oprange[AFCMOVLT] = oprange[r];
- oprange[AFCMOVGE] = oprange[r];
- oprange[AFCMOVLE] = oprange[r];
- oprange[AFCMOVGT] = oprange[r];
- break;
- case ACVTTQ:
- oprange[ACVTQT] = oprange[r];
- oprange[ACVTTS] = oprange[r];
- oprange[ACVTQS] = oprange[r];
- break;
- case AJMP:
- case AJSR:
- break;
- case ACALL_PAL:
- break;
- case AMOVQL:
- oprange[AMOVLL] = oprange[r];
- break;
- case AMOVQC:
- oprange[AMOVLC] = oprange[r];
- break;
- case AMOVQP:
- oprange[AMOVLP] = oprange[r];
- break;
- case AREI:
- oprange[AMB] = oprange[r];
- oprange[ATRAPB] = oprange[r];
- break;
- case AFETCH:
- oprange[AFETCHM] = oprange[r];
- break;
- case AWORD:
- case ATEXT:
- break;
- }
- }
-}
-
-void
-buildrep(int x, int as)
-{
- Opcross *p;
- Optab *e, *s, *o;
- int a1, a2, a3, n;
-
- if(C_NONE != 0 || C_REG != 1 || C_GOK >= 32 || x >= nelem(opcross)) {
- diag("assumptions fail in buildrep");
- errorexit();
- }
- repop[as] = x;
- p = (opcross + x);
- s = oprange[as].start;
- e = oprange[as].stop;
- for(o=e-1; o>=s; o--) {
- n = o-optab;
- for(a2=0; a2<2; a2++) {
- if(a2) {
- if(o->a2 == C_NONE)
- continue;
- } else
- if(o->a2 != C_NONE)
- continue;
- for(a1=0; a1<32; a1++) {
- if(!xcmp[a1][o->a1])
- continue;
- for(a3=0; a3<32; a3++)
- if(xcmp[a3][o->a3])
- (*p)[a1][a2][a3] = n;
- }
- }
- }
- oprange[as].start = 0;
-}
diff --git a/sys/src/cmd/gs/alpha.h b/sys/src/cmd/gs/alpha.h
deleted file mode 100644
index a3cba4e48..000000000
--- a/sys/src/cmd/gs/alpha.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Parameters derived from machine and compiler architecture */
-
- /* ---------------- Scalar alignments ---------------- */
-
-#define ARCH_ALIGN_SHORT_MOD 2
-#define ARCH_ALIGN_INT_MOD 4
-#define ARCH_ALIGN_LONG_MOD 4
-#define ARCH_ALIGN_PTR_MOD 4
-#define ARCH_ALIGN_FLOAT_MOD 4
-#define ARCH_ALIGN_DOUBLE_MOD 8
-#define ARCH_ALIGN_STRUCT_MOD 4
-
- /* ---------------- Scalar sizes ---------------- */
-
-#define ARCH_LOG2_SIZEOF_SHORT 1
-#define ARCH_LOG2_SIZEOF_INT 2
-#define ARCH_LOG2_SIZEOF_LONG 2
-#define ARCH_LOG2_SIZEOF_LONG_LONG 3
-#define ARCH_SIZEOF_PTR 4
-#define ARCH_SIZEOF_FLOAT 4
-#define ARCH_SIZEOF_DOUBLE 8
-#define ARCH_FLOAT_MANTISSA_BITS 24
-#define ARCH_DOUBLE_MANTISSA_BITS 53
-
- /* ---------------- Unsigned max values ---------------- */
-
-#define ARCH_MAX_UCHAR ((unsigned char)0xff + (unsigned char)0)
-#define ARCH_MAX_USHORT ((unsigned short)0xffff + (unsigned short)0)
-#define ARCH_MAX_UINT ((unsigned int)~0 + (unsigned int)0)
-#define ARCH_MAX_ULONG ((unsigned long)~0L + (unsigned long)0)
-
- /* ---------------- Cache sizes ---------------- */
-
-#define ARCH_CACHE1_SIZE 65536
-#define ARCH_CACHE2_SIZE 131072
-
- /* ---------------- Miscellaneous ---------------- */
-
-#define ARCH_IS_BIG_ENDIAN 0
-#define ARCH_PTRS_ARE_SIGNED 0
-#define ARCH_FLOATS_ARE_IEEE 1
-#define ARCH_ARITH_RSHIFT 2
-#define ARCH_CAN_SHIFT_FULL_LONG 1
-#define ARCH_DIV_NEG_POS_TRUNCATES 1
diff --git a/sys/src/cmd/gs/arch.h b/sys/src/cmd/gs/arch.h
index abdec1355..b21ca827a 100644
--- a/sys/src/cmd/gs/arch.h
+++ b/sys/src/cmd/gs/arch.h
@@ -8,8 +8,6 @@
#include "spim.h"
#elif Tpower
#include "mips.h"
-#elif Talpha
-#include "alpha.h"
#elif Tarm
#include "arm.h"
#elif Tamd64
diff --git a/sys/src/cmd/gs/default.alpha.h b/sys/src/cmd/gs/default.alpha.h
deleted file mode 100644
index a3cba4e48..000000000
--- a/sys/src/cmd/gs/default.alpha.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Parameters derived from machine and compiler architecture */
-
- /* ---------------- Scalar alignments ---------------- */
-
-#define ARCH_ALIGN_SHORT_MOD 2
-#define ARCH_ALIGN_INT_MOD 4
-#define ARCH_ALIGN_LONG_MOD 4
-#define ARCH_ALIGN_PTR_MOD 4
-#define ARCH_ALIGN_FLOAT_MOD 4
-#define ARCH_ALIGN_DOUBLE_MOD 8
-#define ARCH_ALIGN_STRUCT_MOD 4
-
- /* ---------------- Scalar sizes ---------------- */
-
-#define ARCH_LOG2_SIZEOF_SHORT 1
-#define ARCH_LOG2_SIZEOF_INT 2
-#define ARCH_LOG2_SIZEOF_LONG 2
-#define ARCH_LOG2_SIZEOF_LONG_LONG 3
-#define ARCH_SIZEOF_PTR 4
-#define ARCH_SIZEOF_FLOAT 4
-#define ARCH_SIZEOF_DOUBLE 8
-#define ARCH_FLOAT_MANTISSA_BITS 24
-#define ARCH_DOUBLE_MANTISSA_BITS 53
-
- /* ---------------- Unsigned max values ---------------- */
-
-#define ARCH_MAX_UCHAR ((unsigned char)0xff + (unsigned char)0)
-#define ARCH_MAX_USHORT ((unsigned short)0xffff + (unsigned short)0)
-#define ARCH_MAX_UINT ((unsigned int)~0 + (unsigned int)0)
-#define ARCH_MAX_ULONG ((unsigned long)~0L + (unsigned long)0)
-
- /* ---------------- Cache sizes ---------------- */
-
-#define ARCH_CACHE1_SIZE 65536
-#define ARCH_CACHE2_SIZE 131072
-
- /* ---------------- Miscellaneous ---------------- */
-
-#define ARCH_IS_BIG_ENDIAN 0
-#define ARCH_PTRS_ARE_SIGNED 0
-#define ARCH_FLOATS_ARE_IEEE 1
-#define ARCH_ARITH_RSHIFT 2
-#define ARCH_CAN_SHIFT_FULL_LONG 1
-#define ARCH_DIV_NEG_POS_TRUNCATES 1
diff --git a/sys/src/cmd/pcc.c b/sys/src/cmd/pcc.c
index b5b93f5f7..c531fd0b8 100644
--- a/sys/src/cmd/pcc.c
+++ b/sys/src/cmd/pcc.c
@@ -16,7 +16,6 @@ Objtype objtype[] = {
{"68020", "2c", "2l", "2", "2.out"},
{"arm", "5c", "5l", "5", "5.out"},
{"amd64", "6c", "6l", "6", "6.out"},
- {"alpha", "7c", "7l", "7", "7.out"},
{"386", "8c", "8l", "8", "8.out"},
{"power64", "9c", "9l", "9", "9.out"},
{"sparc", "kc", "kl", "k", "k.out"},
diff --git a/sys/src/cmd/prof.c b/sys/src/cmd/prof.c
index 0e8806cef..7f7f0f3e3 100644
--- a/sys/src/cmd/prof.c
+++ b/sys/src/cmd/prof.c
@@ -335,7 +335,6 @@ char* trans[] =
{
"386", "8.out",
"68020", "2.out",
- "alpha", "7.out",
"amd64", "6.out",
"arm", "5.out",
"mips", "v.out",
diff --git a/sys/src/cmd/python/pyconfig.h b/sys/src/cmd/python/pyconfig.h
index 27edf0ed2..a01ec73c9 100644
--- a/sys/src/cmd/python/pyconfig.h
+++ b/sys/src/cmd/python/pyconfig.h
@@ -17,7 +17,7 @@
typedef struct Threadarg Threadarg;
-#if defined(T386) || defined(Talpha) || defined(Tarm) || defined(Tpower) || defined(Tamd64) || defined(Tspim)
+#if defined(T386) || defined(Tarm) || defined(Tpower) || defined(Tamd64) || defined(Tspim)
#undef WORDS_BIGENDIAN
#elif defined(Tmips) || defined(Tsparc)
#define WORDS_BIGENDIAN