Skip to content

Commit

Permalink
MMIX 2009 — Release 2021-08-23.
Browse files Browse the repository at this point in the history
New tarball from DEK with a few corrections from MMIX Home.

Back to 'normal', i.e., at least GNU/C issues tons of warnings.
  • Loading branch information
ascherer committed Nov 5, 2021
1 parent 785d8ce commit a0fa1fd
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 149 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ ALL = $(WEBFILES) $(TESTFILES) $(MISCFILES)
basic: mmixal mmix

doc: mmix-doc.ps mmixal.dvi mmix-sim.dvi
dvips -pp 0-13 -o mmixal-intro.ps mmixal.dvi
dvips -pp 0-8 -o mmix-sim-intro.ps mmix-sim.dvi
dvips -pp 0-13 mmixal.dvi -o mmixal-intro.ps
dvips -pp 0-8 mmix-sim.dvi -o mmix-sim-intro.ps

all: mmixal mmix mmotype mmmix

clean:
rm -f *~ *.o *.c *.h *.tex *.log *.dvi *.toc *.idx *.scn *.ps *.pdf core
rm -f *~ *.o *.c *.h *.tex *.log *.dvi *.toc *.idx *.scn *.ps core

mmix-pipe.o: mmix-pipe.c abstime
./abstime > abstime.h
Expand Down
2 changes: 1 addition & 1 deletion abstime.w
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hold more than 32 bits.
#include <stdio.h>
#include <time.h>
@#
int main()
main()
{
printf("#define ABSTIME %ld\n",time(NULL));
return 0;
Expand Down
66 changes: 66 additions & 0 deletions approxGAD.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
* Exercise 7.2.2.3--258 (that number will change)
* a cheap substitute for GAD filtering if domain sizes <= 64
t IS $255
start GREG Data_Segment first domain of given size
next GREG Data_Segment+64 next domain of same size
dom GREG Data_Segment+128 D_k is the octabyte dom+8k
u GREG % bits for U
h GREG % bits for H
i GREG % temp index
j GREG % loop step
k GREG % domain being processed
kk GREG % 8*k
m GREG 6
LOC Data_Segment+128+8 beginning of test data
OCTA #0000000000000030
OCTA #bad0ad0be0facade
OCTA #0000000000000072
OCTA #0000000000000060
OCTA #0000000000000003
OCTA #0000000000000050
LOC #100
Main SET j,0
SET i,56
1H STOU j,start,i Clear start[i..i+7] to zero
SUB i,i,8 i <- i-8
PBNN i,1B while i>=0
CMP t,i,0 t <- -1
STB t,m,start start[m]<-t
SET k,m
1H 8ADDU kk,k,0
LDOU t,kk,dom t <- D_k
SADD t,t,0 t <- |D_k|
CMP i,t,m
CSP t,i,m if t>m set t<-m
LDB i,start,t
STB i,next,k next[k]<-start[t]
STB k,start,t start[t]<-k
SUB k,k,1 k<-k-1
PBP k,1B loop while k>0
DoIt SET u,0 u<-\emptyset
SET h,0 h<-\emptyset
SET i,0 i<-0
LDB k,start,0 k<-start[0]
PBZ k,2F branch unless there was an empty domain
1H INCL j,1 j<-j+1
8ADDU kk,k,0
LDOU t,kk,dom t<-D_k
OR u,u,t U<-U\cup t
ANDN t,t,h t<-t\setminus H
BZ t,Unfeas To Unfeas if D_k will become empty
STOU t,kk,dom D_k<-t
SADD t,u,0 t<-|U|
CMP t,t,j t<-sign(t-j)
BN t,Unfeas To Unfeas if |U|<j
CSZ h,t,u if |U|=j set H<-U
LDB k,k,next k<-next[k]
BP k,1B repeat loop if k>0
BN k,Feas we're done if k<0
2H INCL i,1 i<-i+1 (for domains of size i)
LDB k,i,start k<-start[i]
PBP k,1B repeat loop if k>0
PBZ k,2B increase size if k=0
Feas TRAP 0,Halt,0 normal exit
Unfeas TRAP 0,Halt,0 abnormal exit (domains not feasible)

17 changes: 17 additions & 0 deletions leadingbit.mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
* Dallos's amazing way to extract the leading bit
* (February 2018, exercise 7.1.3--38)
LOC #100
x GREG #3700030014150092
y GREG
a GREG #ff7f3f1f0f070301
b GREG #80c0e0f0f8fcfeff

LOC #100
Main MOR y,a,x smear the transposed mtx downwards
SRU y,y,1 shift right 1, leaking lo bits of octas
MOR y,a,y smear the transposed mtx downwards
MOR y,y,b smear the transposed mtx rightwards
ANDN y,x,y remove all but the leading bit
TRAP 0,Halt,0


41 changes: 20 additions & 21 deletions mmix-arith.w
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ for (i=k=0; i<n; i++) {
example, when dividing the number \Hex{7fff800100000000} by \Hex{800080020005}.

@<If the result was negative, decrease $\hat q$ by 1@>=
if (u[j+n]!=(tetra)k) {
if (u[j+n]!=k) {
qhat--;
for (i=k=0; i<n; i++) {
t=u[i+j]+v[i]+k;
Expand All @@ -329,7 +329,7 @@ octa signed_odiv(y,z)
switch (sy+sz) {
case 2+1: aux=ominus(zero_octa,aux);
if (q.h==sign_bit) overflow=true;
case 0+0: default: return q;
case 0+0: return q;
case 2+0:@+ if (aux.h || aux.l) aux=ominus(zz,aux);
goto negate_q;
case 0+1:@+ if (aux.h || aux.l) aux=ominus(aux,zz);
Expand Down Expand Up @@ -502,11 +502,11 @@ tiny, |X_BIT| if and only if the result is inexact.
@d E_BIT (1<<18) /* external (dynamic) trap bit */

@<Subr...@>=
octa fpack @,@,@[ARGS((octa,int,int,int))@];@+@t}\6{@>
octa fpack @,@,@[ARGS((octa,int,char,int))@];@+@t}\6{@>
octa fpack(f,e,s,r)
octa f; /* the normalized fraction part */
int e; /* the raw exponent */
int s; /* the sign */
char s; /* the sign */
int r; /* the rounding mode */
{
octa o;
Expand Down Expand Up @@ -550,11 +550,11 @@ return o;
having the same conventions as |fpack|.

@<Subr...@>=
tetra sfpack @,@,@[ARGS((octa,int,int,int))@];@+@t}\6{@>
tetra sfpack @,@,@[ARGS((octa,int,char,int))@];@+@t}\6{@>
tetra sfpack(f,e,s,r)
octa f; /* the fraction part */
int e; /* the raw exponent */
int s; /* the sign */
char s; /* the sign */
int r; /* the rounding mode */
{
register tetra o;
Expand Down Expand Up @@ -719,7 +719,7 @@ octa fmult(y,z)
xs=ys+zs-'+'; /* will be |'-'| when the result is negative */
switch (4*yt+zt) {
@t\4@>@<The usual NaN cases@>;
default: case 4*zro+zro: case 4*zro+num: case 4*num+zro: x=zero_octa;@+break;
case 4*zro+zro: case 4*zro+num: case 4*num+zro: x=zero_octa;@+break;
case 4*num+inf: case 4*inf+num: case 4*inf+inf: x=inf_octa;@+break;
case 4*zro+inf: case 4*inf+zro: x=standard_NaN;
exceptions|=I_BIT;@+break;
Expand Down Expand Up @@ -765,7 +765,7 @@ octa fdivide(y,z)
case 4*zro+inf: case 4*zro+num: case 4*num+inf: x=zero_octa;@+break;
case 4*num+zro: exceptions|=Z_BIT;
case 4*inf+num: case 4*inf+zro: x=inf_octa;@+break;
default: case 4*zro+zro: case 4*inf+inf: x=standard_NaN;
case 4*zro+zro: case 4*inf+inf: x=standard_NaN;
exceptions|=I_BIT;@+break;
case 4*num+num: @<Divide nonzero numbers and |return|@>;
}
Expand Down Expand Up @@ -812,7 +812,7 @@ octa fplus(y,z)
case 4*inf+num: case 4*inf+zro: x=inf_octa;@+xs=ys;@+break;
case 4*num+num:@+ if (y.h!=(z.h^0x80000000) || y.l!=z.l)
@<Add nonzero numbers and |return|@>;
default: case 4*zro+zro: x=zero_octa;
case 4*zro+zro: x=zero_octa;
xs=(ys==zs? ys: cur_round==ROUND_DOWN? '-': '+');@+break;
}
if (xs=='-') x.h|=sign_bit;
Expand Down Expand Up @@ -1298,7 +1298,7 @@ explicit exponent only if the alternative would take more than
if (e>17 || e<(int)strlen(s)-17)
printf("%c%s%se%d",s[0],(s[1]? ".": ""),s+1,e-1);
else if (e<0) printf(".%0*d%s",-e,0,s);
else if ((int)strlen(s)>=e) printf("%.*s.%s",e,s,s+e);
else if (strlen(s)>=e) printf("%.*s.%s",e,s,s+e);
else printf("%s%0*d.",s,e-(int)strlen(s),0);

@*Floating point input conversion. Going the other way, we want to
Expand Down Expand Up @@ -1354,7 +1354,7 @@ int scan_const(s)
@<Scan a number and |return|@>;
if (NaN) @<Return the standard NaN@>;
if (strncmp(p,"Inf",3)==0) @<Return infinity@>;
next_char=s;@+return -1;
no_const_found: next_char=s;@+return -1;
}

@ @<Glob...@>=
Expand Down Expand Up @@ -1399,10 +1399,9 @@ a speedy almost-correct one, so we implement the most general case.
for (q=buf0,dec_pt=(char*)0;isdigit(*p);p++) {
val=oplus(val,shift_left(val,2)); /* multiply by 5 */
val=incr(shift_left(val,1),*p-'0');
if (q>buf0 || *p!='0') {
if (q>buf0 || *p!='0')
if (q<buf_max) *q++=*p;
else if (*(q-1)=='0') *(q-1)=*p;@+
}
else if (*(q-1)=='0') *(q-1)=*p;
}
if (NaN) *q++='1';
if (*p=='.') @<Scan a fraction part@>;
Expand Down Expand Up @@ -1437,7 +1436,7 @@ static char buf[785]="00000000"; /* where we put significant input digits */
@ @<Local variables for |scan_const|@>=
register char* dec_pt; /* position of decimal point in |buf| */
register int exp; /* scanned exponent; later used for raw binary exponent */
register int zeros=0; /* leading zeros removed after decimal point */
register int zeros; /* leading zeros removed after decimal point */

@ Here we don't advance |next_char| and force a decimal point until we
know that a syntactically correct exponent exists.
Expand Down Expand Up @@ -1481,7 +1480,7 @@ by $10^{9k}$, for $36\ge k\ge-120$.
@<Move the digits from |buf| to |ff|@>=
x=buf+341+zeros-dec_pt-exp;
if (q==buf0 || x>=1413) {
exp=-99999;@+ goto packit;
make_it_zero: exp=-99999;@+ goto packit;
}
if (x<0) {
make_it_infinite: exp=99999;@+ goto packit;
Expand Down Expand Up @@ -1591,7 +1590,7 @@ int fcomp(y,z)
switch (4*yt+zt) {
case 4*nan+nan: case 4*zro+nan: case 4*num+nan: case 4*inf+nan:
case 4*nan+zro: case 4*nan+num: case 4*nan+inf: return 2;
default: case 4*zro+zro: return 0;
case 4*zro+zro: return 0;
case 4*zro+num: case 4*num+zro: case 4*zro+inf: case 4*inf+zro:
case 4*num+num: case 4*num+inf: case 4*inf+num: case 4*inf+inf:
if (ys!=zs) x=1;
Expand Down Expand Up @@ -1623,7 +1622,7 @@ octa fintegerize(z,r)
if (!r) r=cur_round;
switch (zt) {
case nan:@+if (!(z.h&0x80000)) {@+exceptions|=I_BIT;@+z.h|=0x80000;@+}
case inf: case zro: default: return z;
case inf: case zro: return z;
case num: @<Integerize and |return|@>;
}
}
Expand Down Expand Up @@ -1665,7 +1664,7 @@ octa fixit(z,r)
if (!r) r=cur_round;
switch (zt) {
case nan: case inf: exceptions|=I_BIT;@+return z;
case zro: default: return zero_octa;
case zro: return zero_octa;
case num:@+if (funpack(fintegerize(z,r),&zf,&ze,&zs)==zro) return zero_octa;
if (ze<=1076) o=shift_right(zf,1076-ze,1);
else {
Expand Down Expand Up @@ -1736,7 +1735,7 @@ octa froot(z,r)
else@+switch (zt) {
case nan:@+ if (!(z.h&0x80000)) exceptions|=I_BIT, z.h|=0x80000;
return z;
default: case inf: case zro: x=z;@+break;
case inf: case zro: x=z;@+break;
case num: @<Take the square root and |return|@>;
}
if (zs=='-') x.h|=sign_bit;
Expand Down Expand Up @@ -1795,7 +1794,7 @@ octa fremstep(y,z,delta)
exceptions|=I_BIT;@+break;
case 4*zro+num: case 4*zro+inf: case 4*num+inf: return y;
case 4*num+num: @<Remainderize nonzero numbers and |return|@>;
default: zero_out: x=zero_octa;
zero_out: x=zero_octa;
}
if (ys=='-') x.h|=sign_bit;
return x;
Expand Down
4 changes: 2 additions & 2 deletions mmix-config.w
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,10 @@ for (j=0;j<=funit_count;j++) {
}

@ @<Build table of pipeline stages needed for each opcode@>=
for (j=div;j<=max_pipe_op;j++) int_stages[j]=(int)strlen((char*)pipe_seq[j]);
for (j=div;j<=max_pipe_op;j++) int_stages[j]=strlen(pipe_seq[j]);
for (;j<=max_real_command;j++) int_stages[j]=1;
for (j=mul0,n=0;j<=mul8;j++)
if (strlen((char*)pipe_seq[j])>(unsigned int)n) n=(int)strlen((char*)pipe_seq[j]);
if (strlen(pipe_seq[j])>n) n=strlen(pipe_seq[j]);
int_stages[mul]=n;
int_stages[ld]=int_stages[st]=int_stages[frem]=2;
for (j=0;j<256;j++) stages[j]=int_stages[int_op[j]];
Expand Down
Loading

0 comments on commit a0fa1fd

Please sign in to comment.