Skip to content

Commit

Permalink
MMIX 2009 — Release 2011-08-31.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Scherer committed Sep 8, 2011
1 parent 3c78614 commit e7bbfd5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pages to the front (those pages appear at the end). Read the introductory
parts of those documents, and please report any errors you find to
knuth-bug@cs.stanford.edu. If your system is unable to create those documents
for some reason, go to
http://www-cs-faculty.stanford.edu/~knuth/mmix.html
http://www-cs-faculty.stanford.edu/~knuth/mmix-news.html
and download the compressed PostScript files from there.
Say "make clean" when you've got hardcopy.

Expand Down
2 changes: 1 addition & 1 deletion cp.mms
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Main LDA $255,ArgR
LDA $255,ArgW
TRAP 0,Fwrite,StdOut
JMP Main
Done TRAP 0,0,Halt
Done TRAP 0,Halt,0
6 changes: 2 additions & 4 deletions mmix-arith.w
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ octa zero_octa; /* |zero_octa.h=zero_octa.l=0| */
octa neg_one={-1,-1}; /* |neg_one.h=neg_one.l=-1| */
octa inf_octa={0x7ff00000,0}; /* floating point $+\infty$ */
octa standard_NaN={0x7ff80000,0}; /* floating point NaN(.5) */
octa aux; /* auxiliary output of a subroutine */
bool overflow; /* set by certain subroutines for signed arithmetic */

@ It's easy to add and subtract octabytes, if we aren't terribly
worried about speed.
Expand Down Expand Up @@ -172,8 +170,8 @@ octa omult(y,z)
}

@ @<Glob...@>=
extern octa aux; /* secondary output of subroutines with multiple outputs */
extern bool overflow;
octa aux; /* secondary output of subroutines with multiple outputs */
bool overflow; /* set by certain subroutines for signed arithmetic */

@ @<Unpack the mult...@>=
u[3]=y.h>>16, u[2]=y.h&0xffff, u[1]= y.l>>16, u[0]=y.l&0xffff;
Expand Down
2 changes: 1 addition & 1 deletion mmix-doc.w
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,7 @@ for instructions, or to 2 if the key was present in the TC for data,
or to~3 if the key was present in both. This instruction is for the
operating system only. (Changes to the TC are not immediate; so \.{SYNC}
and/or \.{SYNCD} ought to be done when appropriate, as discussed in
{\sc MMIX-PIPE}.)
{\mc MMIX-PIPE}.)

@ We mentioned earlier that
cheap versions of\/ \MMIX\ might calculate the physical addresses with
Expand Down
4 changes: 2 additions & 2 deletions mmix-mem.w
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ static char buf[20];
static char *kind[]={"byte","wyde","tetra","octa"};
extern octa shift_left @,@,@[ARGS((octa y,int s))@];
/* $y\LL s$, $0\le s\le64$ */
extern octa shift_right @,@,@[ARGS((octa y,int s,int uns))@];
/* $y\GG s$, signed if |!uns| */
extern octa shift_right @,@,@[ARGS((octa y,int s,int u))@];
/* $y\GG s$, signed if |!u| */

@ If the |interactive_read_bit| of the |verbose| control is set,
the user is supposed to supply values dynamically. Otherwise
Expand Down
7 changes: 4 additions & 3 deletions mmix-pipe.w
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ extern octa oandn @,@,@[ARGS((octa y,octa z))@];
/* $y\land \bar z$ */
extern octa shift_left @,@,@[ARGS((octa y,int s))@];
/* $y\LL s$, $0\le s\le64$ */
extern octa shift_right @,@,@[ARGS((octa y,int s,int uns))@];
/* $y\GG s$, signed if |!uns| */
extern octa shift_right @,@,@[ARGS((octa y,int s,int u))@];
/* $y\GG s$, signed if |!u| */
extern octa omult @,@,@[ARGS((octa y,octa z))@];
/* unsigned $(|aux|,x)=y\times z$ */
extern octa signed_omult @,@,@[ARGS((octa y,octa z))@];
Expand Down Expand Up @@ -5827,7 +5827,8 @@ already present.)

@<Cases for stage 1 execution@>=
case noop:@+if (data->interrupt&F_BIT) goto emulate_virt;
case jmp: case pushj: case incrl: case unsave: goto fin_ex;
case incrl: case unsave: goto fin_ex;
case jmp: case pushj: data->go.o=data->z.o; goto fin_ex;
case sav:@+if (!(data->mem_x)) goto fin_ex;
case incgamma: case save: data->i=st; goto switch1;
case decgamma: case unsav: data->i=ld; goto switch1;
Expand Down
6 changes: 3 additions & 3 deletions mmix-sim.w
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ extern octa oand @,@,@[ARGS((octa y,octa z))@];
/* $y\land z$ */
extern octa shift_left @,@,@[ARGS((octa y,int s))@];
/* $y\LL s$, $0\le s\le64$ */
extern octa shift_right @,@,@[ARGS((octa y,int s,int uns))@];
/* $y\GG s$, signed if |!uns| */
extern octa shift_right @,@,@[ARGS((octa y,int s,int u))@];
/* $y\GG s$, signed if |!u| */
extern octa omult @,@,@[ARGS((octa y,octa z))@];
/* unsigned $(|aux|,x)=y\times z$ */
extern octa signed_omult @,@,@[ARGS((octa y,octa z))@];
Expand Down Expand Up @@ -2197,7 +2197,7 @@ case GET:@+if (yy!=0 || zz>=32) goto illegal_inst;
case PUT: case PUTI:@+ if (yy!=0 || xx>=32) goto illegal_inst;
strcpy(rhs,"%z = %#z");
if (xx>=8) {
if (xx<=11) goto illegal_inst; /* can't change rC, rN, rO, rS */
if (xx<=11 && xx!=8) goto illegal_inst; /* can't change rN, rO, rS */
if (xx<=18) goto privileged_inst;
if (xx==rA) @<Get ready to update rA@>@;
else if (xx==rL) @<Set $L=z=\min(z,L)$@>@;
Expand Down
32 changes: 21 additions & 11 deletions mmixal.w
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ stand respectively for
$(x\times y)\bmod2^{64}$ (multiplication), $\lfloor x/y\rfloor$ (division),
$\lfloor2^{64}x/y\rfloor$ (fractional division), $x\bmod y$ (remainder),
$(x\times2^y)\bmod2^{64}$ (left~shift), $\lfloor x/2^y\rfloor$
(right shift), and $x\land y$ (bitwise and) on unsigned octabytes.
(right shift), and $x\mathbin{\char`\&}y$ (bitwise and) on unsigned octabytes.
Division is legal only if $y>0$; fractional division is
legal only if $x<y$. None of the strong binary operations can be
applied to register numbers.

The weak binary operations \.{x+y}, \.{x-y}, \.{x\char'174 y}, and
\.{x\^y} stand respectively for $(x+y)\bmod2^{64}$ (addition),
$(x-y)\bmod2^{64}$ (subtraction),
$x\lor y$ (bitwise or), and $x\oplus y$ (bitwise exclusive-or) on
$(x-y)\bmod2^{64}$ (subtraction), $x\mathbin{\mkern1mu\vert\mkern1mu}y$
(bitwise or), and $x\oplus y$ (bitwise exclusive-or) on
unsigned octabytes. These operations can be applied to register
numbers only in four contexts: $\<register>+\<pure>$, $\<pure>+\<register>$,
$\<register>-\<pure>$
Expand Down Expand Up @@ -969,8 +969,8 @@ extern octa oand @,@,@[ARGS((octa y,octa z))@];
/* $y\land z$ */
extern octa shift_left @,@,@[ARGS((octa y,int s))@];
/* $y\LL s$, $0\le s\le64$ */
extern octa shift_right @,@,@[ARGS((octa y,int s,int uns))@];
/* $y\GG s$, signed if |!uns| */
extern octa shift_right @,@,@[ARGS((octa y,int s,int u))@];
/* $y\GG s$, signed if |!u| */
extern octa omult @,@,@[ARGS((octa y,octa z))@];
/* unsigned $(|aux|,x)=y\times z$ */
extern octa odiv @,@,@[ARGS((octa x,octa y,octa z))@];
Expand Down Expand Up @@ -1080,7 +1080,7 @@ as a comment by the assembler.
@<Check for a line directive@>=
{
for (p=buffer+1;isspace(*p);p++);
for (j=*p++-'0';isdigit(*p);p++) j=10*j+*p-'0';
for (j=0;isdigit(*p);p++) j=10*j+*p-'0';
for (;isspace(*p);p++);
if (*p=='\"') {
if (!filename[filename_count]) {
Expand All @@ -1089,11 +1089,17 @@ as a comment by the assembler.
panic("Capacity exceeded: Out of filename memory");
@.Capacity exceeded...@>
}
for (p++,q=filename[filename_count];*p && *p!='\"';p++,q++) *q=*p;
for (p++,k=0;*p && *p!='\"' && k<FILENAME_MAX; p++,k++)
filename[filename_count][k]=*p;
if (k==FILENAME_MAX) panic("Capacity exceeded: File name too long");
if (*p=='\"' && *(p-1)!='\"') { /* yes, it's a line directive */
*q='\0';
filename[filename_count][k]='\0';
for (k=0;strcmp(filename[k],filename[filename_count])!=0;k++);
if (k==filename_count) filename_count++;
if (k==filename_count) {
if (filename_count==256)
panic("Capacity exceeded: More than 256 file names");
filename_count++;
}
cur_file=k;
line_no=j-1;
}
Expand Down Expand Up @@ -2448,7 +2454,7 @@ switch(*p++) {
case '%': rt_op=mod;@+break;
case '<': rt_op=shl;@+goto sh_check;
case '>': rt_op=shr;
sh_check:@+if (*p++==*(p-1)) break;
sh_check: p++;@+if (*(p-1)==*(p-2)) break;
derr("syntax error at `%c'",*(p-2));
@.syntax error...@>
case '&': rt_op=and;@+break;
Expand Down Expand Up @@ -2557,7 +2563,7 @@ case shl: case shr: binary_check("compute a bitwise shift of");
if (top_val.equiv.h || top_val.equiv.l>63) next_val.equiv=zero_octa;
else if (op_stack[op_ptr]==shl)
next_val.equiv=shift_left(next_val.equiv,top_val.equiv.l);
else next_val.equiv=shift_right(next_val.equiv,top_val.equiv.l,true);
else next_val.equiv=shift_right(next_val.equiv,top_val.equiv.l,1);
goto fin_bin;
case and: binary_check("compute bitwise and of");
next_val.equiv.h&=top_val.equiv.h, next_val.equiv.l&=top_val.equiv.l;
Expand Down Expand Up @@ -2813,7 +2819,11 @@ case 2:@+if (!(op_bits&two_arg_bit))
if (op_bits&one_arg_bit)
derr("opcode `%s' must not have two operands",op_field)@;
else derr("opcode `%s' must have more than two operands",op_field);
if ((op_bits&(three_arg_bit+mem_bit))==three_arg_bit) goto make_two_three;
@<Do a two-operand operation@>;
make_two_three: val_stack[2]=val_stack[1], val_ptr=3;
val_stack[1].equiv=zero_octa, val_stack[1].link=NULL,
val_stack[1].status=pure; /* insert \.0 as the second operand */
case 3:@+if (!(op_bits&three_arg_bit))
derr("opcode `%s' must not have three operands",op_field);
@<Do a three-operand operation@>;
Expand Down

0 comments on commit e7bbfd5

Please sign in to comment.