Skip to content

Commit

Permalink
MMIX 2009 — MMIX home 2019-02-19.
Browse files Browse the repository at this point in the history
  • Loading branch information
ascherer committed Apr 5, 2021
1 parent 574a667 commit 785d8ce
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 139 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 mmixal.dvi -o mmixal-intro.ps
dvips -pp 0-8 mmix-sim.dvi -o mmix-sim-intro.ps
dvips -pp 0-13 -o mmixal-intro.ps mmixal.dvi
dvips -pp 0-8 -o mmix-sim-intro.ps mmix-sim.dvi

all: mmixal mmix mmotype mmmix

clean:
rm -f *~ *.o *.c *.h *.tex *.log *.dvi *.toc *.idx *.scn *.ps core
rm -f *~ *.o *.c *.h *.tex *.log *.dvi *.toc *.idx *.scn *.ps *.pdf 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>
@#
main()
int main()
{
printf("#define ABSTIME %ld\n",time(NULL));
return 0;
Expand Down
41 changes: 21 additions & 20 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]!=k) {
if (u[j+n]!=(tetra)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: return q;
case 0+0: default: 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,char,int))@];@+@t}\6{@>
octa fpack @,@,@[ARGS((octa,int,int,int))@];@+@t}\6{@>
octa fpack(f,e,s,r)
octa f; /* the normalized fraction part */
int e; /* the raw exponent */
char s; /* the sign */
int 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,char,int))@];@+@t}\6{@>
tetra sfpack @,@,@[ARGS((octa,int,int,int))@];@+@t}\6{@>
tetra sfpack(f,e,s,r)
octa f; /* the fraction part */
int e; /* the raw exponent */
char s; /* the sign */
int 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@>;
case 4*zro+zro: case 4*zro+num: case 4*num+zro: x=zero_octa;@+break;
default: 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;
case 4*zro+zro: case 4*inf+inf: x=standard_NaN;
default: 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|@>;
case 4*zro+zro: x=zero_octa;
default: 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 (strlen(s)>=e) printf("%.*s.%s",e,s,s+e);
else if ((int)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@>;
no_const_found: next_char=s;@+return -1;
next_char=s;@+return -1;
}

@ @<Glob...@>=
Expand Down Expand Up @@ -1399,9 +1399,10 @@ 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 @@ -1436,7 +1437,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; /* leading zeros removed after decimal point */
register int zeros=0; /* 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 @@ -1480,7 +1481,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) {
make_it_zero: exp=-99999;@+ goto packit;
exp=-99999;@+ goto packit;
}
if (x<0) {
make_it_infinite: exp=99999;@+ goto packit;
Expand Down Expand Up @@ -1590,7 +1591,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;
case 4*zro+zro: return 0;
default: 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 @@ -1622,7 +1623,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: return z;
case inf: case zro: default: return z;
case num: @<Integerize and |return|@>;
}
}
Expand Down Expand Up @@ -1664,7 +1665,7 @@ octa fixit(z,r)
if (!r) r=cur_round;
switch (zt) {
case nan: case inf: exceptions|=I_BIT;@+return z;
case zro: return zero_octa;
case zro: default: 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 @@ -1735,7 +1736,7 @@ octa froot(z,r)
else@+switch (zt) {
case nan:@+ if (!(z.h&0x80000)) exceptions|=I_BIT, z.h|=0x80000;
return z;
case inf: case zro: x=z;@+break;
default: 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 @@ -1794,7 +1795,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|@>;
zero_out: x=zero_octa;
default: 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]=strlen(pipe_seq[j]);
for (j=div;j<=max_pipe_op;j++) int_stages[j]=(int)strlen((char*)pipe_seq[j]);
for (;j<=max_real_command;j++) int_stages[j]=1;
for (j=mul0,n=0;j<=mul8;j++)
if (strlen(pipe_seq[j])>n) n=strlen(pipe_seq[j]);
if (strlen((char*)pipe_seq[j])>(unsigned int)n) n=(int)strlen((char*)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
64 changes: 32 additions & 32 deletions mmix-io.w
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ protect the standard input, output, and error streams from being
preempted.

@<Sub...@>=
octa mmix_fopen @,@,@[ARGS((unsigned char,octa,octa))@];@+@t}\6{@>
octa mmix_fopen @,@,@[ARGS((unsigned int,octa,octa))@];@+@t}\6{@>
octa mmix_fopen(handle,name,mode)
unsigned char handle;
unsigned int handle;
octa name,mode;
{
char name_buf[FILENAME_MAX];
if (mode.h || mode.l>4) goto abort;
if (mmgetchars(name_buf,FILENAME_MAX,name,0)==FILENAME_MAX) goto abort;
if (mode.h || mode.l>4) goto failure;
if (mmgetchars(name_buf,FILENAME_MAX,name,0)==FILENAME_MAX) goto failure;
if (sfile[handle].mode!=0 && handle>2) fclose(sfile[handle].fp);
sfile[handle].fp=fopen(name_buf,mode_string[mode.l]);
if (!sfile[handle].fp) goto abort;
if (!sfile[handle].fp) goto failure;
sfile[handle].mode=mode_code[mode.l];
return zero_octa; /* success */
abort: sfile[handle].mode=0;
failure: sfile[handle].mode=0;
return neg_one; /* failure */
}

Expand All @@ -123,9 +123,9 @@ void mmix_fake_stdin(f)
}

@ @<Sub...@>=
octa mmix_fclose @,@,@[ARGS((unsigned char))@];@+@t}\6{@>
octa mmix_fclose @,@,@[ARGS((unsigned int))@];@+@t}\6{@>
octa mmix_fclose(handle)
unsigned char handle;
unsigned int handle;
{
if (sfile[handle].mode==0) return neg_one;
if (handle>2 && fclose(sfile[handle].fp)!=0) return neg_one;
Expand All @@ -134,13 +134,13 @@ octa mmix_fclose(handle)
}

@ @<Sub...@>=
octa mmix_fread @,@,@[ARGS((unsigned char,octa,octa))@];@+@t}\6{@>
octa mmix_fread @,@,@[ARGS((unsigned int,octa,octa))@];@+@t}\6{@>
octa mmix_fread(handle,buffer,size)
unsigned char handle;
unsigned int handle;
octa buffer,size;
{
register unsigned char *buf;
register int n;
register unsigned int n;
octa o;
o=neg_one;
if (!(sfile[handle].mode&0x1)) goto done;
Expand Down Expand Up @@ -169,9 +169,9 @@ if (sfile[handle].fp==stdin) {
}

@ @<Sub...@>=
octa mmix_fgets @,@,@[ARGS((unsigned char,octa,octa))@];@+@t}\6{@>
octa mmix_fgets @,@,@[ARGS((unsigned int,octa,octa))@];@+@t}\6{@>
octa mmix_fgets(handle,buffer,size)
unsigned char handle;
unsigned int handle;
octa buffer,size;
{
char buf[256];
Expand All @@ -196,7 +196,7 @@ octa mmix_fgets(handle,buffer,size)

@ @<Read |n<256| characters into |buf|@>=
s=255;
if (size.l<s && !size.h) s=size.l;
if (size.l<(unsigned int)s && !size.h) s=(int)size.l;
if (sfile[handle].fp==stdin)
for (p=buf,n=0;n<s;) {
*p=stdin_chr();
Expand Down Expand Up @@ -224,13 +224,13 @@ prepared on random operating systems might be backwards.
@^system dependencies@>

@<Sub...@>=
octa mmix_fgetws @,@,@[ARGS((unsigned char,octa,octa))@];@+@t}\6{@>
octa mmix_fgetws @,@,@[ARGS((unsigned int,octa,octa))@];@+@t}\6{@>
octa mmix_fgetws(handle,buffer,size)
unsigned char handle;
unsigned int handle;
octa buffer,size;
{
char buf[256];
register int n,s;
register tetra n,s;
register char *p;
octa o;
int eof=0;
Expand All @@ -244,7 +244,7 @@ octa mmix_fgetws(handle,buffer,size)
@<Read |n<128| wyde characters into |buf|@>;
mmputchars((unsigned char*)buf,2*n+2,buffer);
o=incr(o,n);
size=incr(size,-n);
size=incr(size,-(int)n);
if ((n&&buf[2*n-1]=='\n'&&buf[2*n-2]==0) || (!size.l&&!size.h) || eof)
return o;
buffer=incr(buffer,2*n);
Expand Down Expand Up @@ -272,19 +272,19 @@ else for (p=buf,n=0;n<s;) {
*p=*(p+1)='\0';

@ @<Sub...@>=
octa mmix_fwrite @,@,@[ARGS((unsigned char,octa,octa))@];@+@t}\6{@>
octa mmix_fwrite @,@,@[ARGS((unsigned int,octa,octa))@];@+@t}\6{@>
octa mmix_fwrite(handle,buffer,size)
unsigned char handle;
unsigned int handle;
octa buffer,size;
{
char buf[256];
register int n;
register unsigned int n;
if (!(sfile[handle].mode&0x2)) return ominus(zero_octa,size);
if (sfile[handle].mode&0x8) sfile[handle].mode &=~ 0x1;
while (1) {
if (size.h || size.l>=256) n=mmgetchars(buf,256,buffer,-1);
else n=mmgetchars(buf,size.l,buffer,-1);
size=incr(size,-n);
size=incr(size,-(int)n);
if (fwrite(buf,1,n,sfile[handle].fp)!=n) return ominus(zero_octa,size);
fflush(sfile[handle].fp);
if (!size.l && !size.h) return zero_octa;
Expand All @@ -293,13 +293,13 @@ octa mmix_fwrite(handle,buffer,size)
}

@ @<Sub...@>=
octa mmix_fputs @,@,@[ARGS((unsigned char,octa))@];@+@t}\6{@>
octa mmix_fputs @,@,@[ARGS((unsigned int,octa))@];@+@t}\6{@>
octa mmix_fputs(handle,string)
unsigned char handle;
unsigned int handle;
octa string;
{
char buf[256];
register int n;
register unsigned int n;
octa o;
o=zero_octa;
if (!(sfile[handle].mode&0x2)) return neg_one;
Expand All @@ -317,13 +317,13 @@ octa mmix_fputs(handle,string)
}

@ @<Sub...@>=
octa mmix_fputws @,@,@[ARGS((unsigned char,octa))@];@+@t}\6{@>
octa mmix_fputws @,@,@[ARGS((unsigned int,octa))@];@+@t}\6{@>
octa mmix_fputws(handle,string)
unsigned char handle;
unsigned int handle;
octa string;
{
char buf[256];
register int n;
register unsigned int n;
octa o;
o=zero_octa;
if (!(sfile[handle].mode&0x2)) return neg_one;
Expand All @@ -343,9 +343,9 @@ octa mmix_fputws(handle,string)
@ @d sign_bit ((unsigned)0x80000000)

@<Sub...@>=
octa mmix_fseek @,@,@[ARGS((unsigned char,octa))@];@+@t}\6{@>
octa mmix_fseek @,@,@[ARGS((unsigned int,octa))@];@+@t}\6{@>
octa mmix_fseek(handle,offset)
unsigned char handle;
unsigned int handle;
octa offset;
{
if (!(sfile[handle].mode&0x4)) return neg_one;
Expand All @@ -361,9 +361,9 @@ octa mmix_fseek(handle,offset)
}

@ @<Sub...@>=
octa mmix_ftell @,@,@[ARGS((unsigned char))@];@+@t}\6{@>
octa mmix_ftell @,@,@[ARGS((unsigned int))@];@+@t}\6{@>
octa mmix_ftell(handle)
unsigned char handle;
unsigned int handle;
{
register long x;
octa o;
Expand Down
Loading

0 comments on commit 785d8ce

Please sign in to comment.