summaryrefslogtreecommitdiff
path: root/test/cminor
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-02-09 14:55:48 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-02-09 14:55:48 +0000
commit2ae43be7b9d4118335c9d2cef6e098f9b9f807fe (patch)
treebbb5e49ccbf7e3614966571acc317f8d318fecad /test/cminor
Initial import of compcert
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/cminor')
-rw-r--r--test/cminor/Makefile76
-rw-r--r--test/cminor/aes.cmp364
-rw-r--r--test/cminor/almabench.cmp159
-rw-r--r--test/cminor/fft.cm149
-rw-r--r--test/cminor/fib.cm7
-rw-r--r--test/cminor/integr.cm25
-rw-r--r--test/cminor/manyargs.cm53
-rw-r--r--test/cminor/qsort.cm30
-rw-r--r--test/cminor/sha1.cmp189
9 files changed, 1052 insertions, 0 deletions
diff --git a/test/cminor/Makefile b/test/cminor/Makefile
new file mode 100644
index 0000000..35d3e07
--- /dev/null
+++ b/test/cminor/Makefile
@@ -0,0 +1,76 @@
+CCOMP=../../ccomp
+CPP=cpp -P
+CC=gcc
+CFLAGS=-g
+VPATH=../harness ../lib
+
+PROGS=fib integr qsort fft sha1 aes almabench manyargs
+
+all_s: $(PROGS:%=%.s)
+
+all: $(PROGS)
+
+$(PROGS:%=%.s): $(CCOMP)
+
+fib: fib.o mainfib.o
+ $(CC) $(CFLAGS) -o fib fib.o mainfib.o
+clean::
+ rm -f fib
+
+integr: integr.o mainintegr.o
+ $(CC) $(CFLAGS) -o integr integr.o mainintegr.o
+clean::
+ rm -f integr
+
+qsort: qsort.o mainqsort.o
+ $(CC) $(CFLAGS) -o qsort qsort.o mainqsort.o
+clean::
+ rm -f qsort
+
+fft: fft.o mainfft.o staticlib.o
+ $(CC) $(CFLAGS) -o fft fft.o mainfft.o staticlib.o -lm
+clean::
+ rm -f fft
+
+sha1: sha1.o mainsha1.o staticlib.o
+ $(CC) $(CFLAGS) -o sha1 sha1.o mainsha1.o staticlib.o
+clean::
+ rm -f sha1 sha1.cm
+
+aes: aes.o mainaes.o
+ $(CC) $(CFLAGS) -o aes aes.o mainaes.o
+clean::
+ rm -f aes aes.cm
+
+almabench: almabench.o mainalmabench.o staticlib.o
+ $(CC) $(CFLAGS) -o almabench almabench.o mainalmabench.o staticlib.o -lm
+clean::
+ rm -f almabench almabench.cm
+
+manyargs: manyargs.o mainmanyargs.o
+ $(CC) $(CFLAGS) -o manyargs manyargs.o mainmanyargs.o
+clean::
+ rm -f manyargs
+
+.SUFFIXES:
+
+.SUFFIXES: .cmp .cm .s .o .c .S
+
+.cmp.s:
+ $(CPP) $*.cmp > $*.cm
+ $(CCOMP) $(FLAGS) $*.cm
+
+.cm.s:
+ $(CCOMP) $(FLAGS) $*.cm
+
+.c.o:
+ $(CC) $(CFLAGS) -c $<
+
+.s.o:
+ $(AS) $(ASFLAGS) -o $*.o $<
+
+.S.o:
+ $(AS) $(ASFLAGS) -o $*.o $<
+
+clean::
+ rm -f *.s *.o *~
diff --git a/test/cminor/aes.cmp b/test/cminor/aes.cmp
new file mode 100644
index 0000000..35eabc4
--- /dev/null
+++ b/test/cminor/aes.cmp
@@ -0,0 +1,364 @@
+/* AES cipher. To be preprocessed with cpp -P. */
+
+#define GETU32(pt) int32[pt]
+#define PUTU32(ct,st) int32[ct] = st
+
+#define rk(n) int32[rk_ + (n) * 4]
+#define Te0(n) int32["Te0" + (n) * 4]
+#define Te1(n) int32["Te1" + (n) * 4]
+#define Te2(n) int32["Te2" + (n) * 4]
+#define Te3(n) int32["Te3" + (n) * 4]
+#define Te4(n) int32["Te4" + (n) * 4]
+#define Td0(n) int32["Td0" + (n) * 4]
+#define Td1(n) int32["Td1" + (n) * 4]
+#define Td2(n) int32["Td2" + (n) * 4]
+#define Td3(n) int32["Td3" + (n) * 4]
+#define Td4(n) int32["Td4" + (n) * 4]
+#define rcon(n) int32["rcon" + (n) * 4]
+
+/**
+ * Expand the cipher key into the encryption key schedule.
+ *
+ * @return the number of rounds for the given cipher key size.
+ */
+"rijndaelKeySetupEnc"(rk_, cipherKey, keyBits) : int -> int -> int -> int
+{
+ var i, temp;
+ i = 0;
+
+ rk(0) = GETU32(cipherKey );
+ rk(1) = GETU32(cipherKey + 4);
+ rk(2) = GETU32(cipherKey + 8);
+ rk(3) = GETU32(cipherKey + 12);
+ if (keyBits == 128) {
+ {{ loop {
+ temp = rk(3);
+ rk(4) = rk(0) ^
+ (Te4((temp >>u 16) & 0xff) & 0xff000000) ^
+ (Te4((temp >>u 8) & 0xff) & 0x00ff0000) ^
+ (Te4((temp ) & 0xff) & 0x0000ff00) ^
+ (Te4((temp >>u 24) ) & 0x000000ff) ^
+ rcon(i);
+ rk(5) = rk(1) ^ rk(4);
+ rk(6) = rk(2) ^ rk(5);
+ rk(7) = rk(3) ^ rk(6);
+ if ((i = i + 1) == 10) {
+ return 10;
+ }
+ rk_ = rk_ + 4 * 4;
+ } }}
+ }
+ rk(4) = GETU32(cipherKey + 16);
+ rk(5) = GETU32(cipherKey + 20);
+ if (keyBits == 192) {
+ {{ loop {
+ temp = rk( 5);
+ rk( 6) = rk( 0) ^
+ (Te4((temp >>u 16) & 0xff) & 0xff000000) ^
+ (Te4((temp >>u 8) & 0xff) & 0x00ff0000) ^
+ (Te4((temp ) & 0xff) & 0x0000ff00) ^
+ (Te4((temp >>u 24) ) & 0x000000ff) ^
+ rcon(i);
+ rk( 7) = rk( 1) ^ rk( 6);
+ rk( 8) = rk( 2) ^ rk( 7);
+ rk( 9) = rk( 3) ^ rk( 8);
+ if ((i = i + 1) == 8) {
+ return 12;
+ }
+ rk(10) = rk( 4) ^ rk( 9);
+ rk(11) = rk( 5) ^ rk(10);
+ rk_ = rk_ + 6 * 4;
+ } }}
+ }
+ rk(6) = GETU32(cipherKey + 24);
+ rk(7) = GETU32(cipherKey + 28);
+ if (keyBits == 256) {
+ {{ loop {
+ temp = rk( 7);
+ rk( 8) = rk( 0) ^
+ (Te4((temp >>u 16) & 0xff) & 0xff000000) ^
+ (Te4((temp >>u 8) & 0xff) & 0x00ff0000) ^
+ (Te4((temp ) & 0xff) & 0x0000ff00) ^
+ (Te4((temp >>u 24) ) & 0x000000ff) ^
+ rcon(i);
+ rk( 9) = rk( 1) ^ rk( 8);
+ rk(10) = rk( 2) ^ rk( 9);
+ rk(11) = rk( 3) ^ rk(10);
+ if ((i = i + 1) == 7) {
+ return 14;
+ }
+ temp = rk(11);
+ rk(12) = rk( 4) ^
+ (Te4((temp >>u 24) ) & 0xff000000) ^
+ (Te4((temp >>u 16) & 0xff) & 0x00ff0000) ^
+ (Te4((temp >>u 8) & 0xff) & 0x0000ff00) ^
+ (Te4((temp ) & 0xff) & 0x000000ff);
+ rk(13) = rk( 5) ^ rk(12);
+ rk(14) = rk( 6) ^ rk(13);
+ rk(15) = rk( 7) ^ rk(14);
+
+ rk_ = rk_ + 8 * 4;
+ } }}
+ }
+ return 0;
+}
+
+/**
+ * Expand the cipher key into the decryption key schedule.
+ *
+ * @return the number of rounds for the given cipher key size.
+ */
+"rijndaelKeySetupDec"(rk_, cipherKey, keyBits) : int -> int -> int -> int
+{
+ var Nr, i, j, temp;
+
+ /* expand the cipher key: */
+ Nr = "rijndaelKeySetupEnc"(rk_, cipherKey, keyBits) : int -> int -> int -> int;
+ /* invert the order of the round keys: */
+ i = 0; j = 4 * Nr;
+ {{ loop {
+ if (! (i < j)) exit;
+ temp = rk(i ); rk(i ) = rk(j ); rk(j ) = temp;
+ temp = rk(i + 1); rk(i + 1) = rk(j + 1); rk(j + 1) = temp;
+ temp = rk(i + 2); rk(i + 2) = rk(j + 2); rk(j + 2) = temp;
+ temp = rk(i + 3); rk(i + 3) = rk(j + 3); rk(j + 3) = temp;
+ i = i + 4;
+ j = j - 4;
+ } }}
+ /* apply the inverse MixColumn transform to all round keys but the first and the last: */
+ i = 1;
+ {{ loop {
+ if (! (i < Nr)) exit;
+ rk_ = rk_ + 4 * 4;
+ rk(0) =
+ Td0(Te4((rk(0) >>u 24) ) & 0xff) ^
+ Td1(Te4((rk(0) >>u 16) & 0xff) & 0xff) ^
+ Td2(Te4((rk(0) >>u 8) & 0xff) & 0xff) ^
+ Td3(Te4((rk(0) ) & 0xff) & 0xff);
+ rk(1) =
+ Td0(Te4((rk(1) >>u 24) ) & 0xff) ^
+ Td1(Te4((rk(1) >>u 16) & 0xff) & 0xff) ^
+ Td2(Te4((rk(1) >>u 8) & 0xff) & 0xff) ^
+ Td3(Te4((rk(1) ) & 0xff) & 0xff);
+ rk(2) =
+ Td0(Te4((rk(2) >>u 24) ) & 0xff) ^
+ Td1(Te4((rk(2) >>u 16) & 0xff) & 0xff) ^
+ Td2(Te4((rk(2) >>u 8) & 0xff) & 0xff) ^
+ Td3(Te4((rk(2) ) & 0xff) & 0xff);
+ rk(3) =
+ Td0(Te4((rk(3) >>u 24) ) & 0xff) ^
+ Td1(Te4((rk(3) >>u 16) & 0xff) & 0xff) ^
+ Td2(Te4((rk(3) >>u 8) & 0xff) & 0xff) ^
+ Td3(Te4((rk(3) ) & 0xff) & 0xff);
+ i = i + 1;
+ } }}
+ return Nr;
+}
+
+"rijndaelEncrypt"(rk_, Nr, pt, ct): int -> int -> int -> int -> void
+{
+ var s0, s1, s2, s3, t0, t1, t2, t3, r;
+
+ /*
+ * map byte array block to cipher state
+ * and add initial round key:
+ */
+ s0 = GETU32(pt ) ^ rk(0);
+ s1 = GETU32(pt + 4) ^ rk(1);
+ s2 = GETU32(pt + 8) ^ rk(2);
+ s3 = GETU32(pt + 12) ^ rk(3);
+ /*
+ * Nr - 1 full rounds:
+ */
+ r = Nr >>u 1;
+ {{ loop {
+ t0 =
+ Te0((s0 >>u 24) ) ^
+ Te1((s1 >>u 16) & 0xff) ^
+ Te2((s2 >>u 8) & 0xff) ^
+ Te3((s3 ) & 0xff) ^
+ rk(4);
+ t1 =
+ Te0((s1 >>u 24) ) ^
+ Te1((s2 >>u 16) & 0xff) ^
+ Te2((s3 >>u 8) & 0xff) ^
+ Te3((s0 ) & 0xff) ^
+ rk(5);
+ t2 =
+ Te0((s2 >>u 24) ) ^
+ Te1((s3 >>u 16) & 0xff) ^
+ Te2((s0 >>u 8) & 0xff) ^
+ Te3((s1 ) & 0xff) ^
+ rk(6);
+ t3 =
+ Te0((s3 >>u 24) ) ^
+ Te1((s0 >>u 16) & 0xff) ^
+ Te2((s1 >>u 8) & 0xff) ^
+ Te3((s2 ) & 0xff) ^
+ rk(7);
+
+ rk_ = rk_ + 8 * 4;
+ if ((r = r - 1) == 0) exit;
+
+ s0 =
+ Te0((t0 >>u 24) ) ^
+ Te1((t1 >>u 16) & 0xff) ^
+ Te2((t2 >>u 8) & 0xff) ^
+ Te3((t3 ) & 0xff) ^
+ rk(0);
+ s1 =
+ Te0((t1 >>u 24) ) ^
+ Te1((t2 >>u 16) & 0xff) ^
+ Te2((t3 >>u 8) & 0xff) ^
+ Te3((t0 ) & 0xff) ^
+ rk(1);
+ s2 =
+ Te0((t2 >>u 24) ) ^
+ Te1((t3 >>u 16) & 0xff) ^
+ Te2((t0 >>u 8) & 0xff) ^
+ Te3((t1 ) & 0xff) ^
+ rk(2);
+ s3 =
+ Te0((t3 >>u 24) ) ^
+ Te1((t0 >>u 16) & 0xff) ^
+ Te2((t1 >>u 8) & 0xff) ^
+ Te3((t2 ) & 0xff) ^
+ rk(3);
+ } }}
+ /*
+ * apply last round and
+ * map cipher state to byte array block:
+ */
+ s0 =
+ (Te4((t0 >>u 24) ) & 0xff000000) ^
+ (Te4((t1 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Te4((t2 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Te4((t3 ) & 0xff) & 0x000000ff) ^
+ rk(0);
+ PUTU32(ct , s0);
+ s1 =
+ (Te4((t1 >>u 24) ) & 0xff000000) ^
+ (Te4((t2 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Te4((t3 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Te4((t0 ) & 0xff) & 0x000000ff) ^
+ rk(1);
+ PUTU32(ct + 4, s1);
+ s2 =
+ (Te4((t2 >>u 24) ) & 0xff000000) ^
+ (Te4((t3 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Te4((t0 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Te4((t1 ) & 0xff) & 0x000000ff) ^
+ rk(2);
+ PUTU32(ct + 8, s2);
+ s3 =
+ (Te4((t3 >>u 24) ) & 0xff000000) ^
+ (Te4((t0 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Te4((t1 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Te4((t2 ) & 0xff) & 0x000000ff) ^
+ rk(3);
+ PUTU32(ct + 12, s3);
+}
+
+"rijndaelDecrypt"(rk_, Nr, ct, pt) : int -> int -> int -> int -> void
+{
+ var s0, s1, s2, s3, t0, t1, t2, t3, r;
+
+ /*
+ * map byte array block to cipher state
+ * and add initial round key:
+ */
+ s0 = GETU32(ct ) ^ rk(0);
+ s1 = GETU32(ct + 4) ^ rk(1);
+ s2 = GETU32(ct + 8) ^ rk(2);
+ s3 = GETU32(ct + 12) ^ rk(3);
+ /*
+ * Nr - 1 full rounds:
+ */
+ r = Nr >>u 1;
+ {{ loop {
+ t0 =
+ Td0((s0 >>u 24) ) ^
+ Td1((s3 >>u 16) & 0xff) ^
+ Td2((s2 >>u 8) & 0xff) ^
+ Td3((s1 ) & 0xff) ^
+ rk(4);
+ t1 =
+ Td0((s1 >>u 24) ) ^
+ Td1((s0 >>u 16) & 0xff) ^
+ Td2((s3 >>u 8) & 0xff) ^
+ Td3((s2 ) & 0xff) ^
+ rk(5);
+ t2 =
+ Td0((s2 >>u 24) ) ^
+ Td1((s1 >>u 16) & 0xff) ^
+ Td2((s0 >>u 8) & 0xff) ^
+ Td3((s3 ) & 0xff) ^
+ rk(6);
+ t3 =
+ Td0((s3 >>u 24) ) ^
+ Td1((s2 >>u 16) & 0xff) ^
+ Td2((s1 >>u 8) & 0xff) ^
+ Td3((s0 ) & 0xff) ^
+ rk(7);
+
+ rk_ = rk_ + 8 * 4;
+ if ((r = r - 1) == 0) exit;
+
+ s0 =
+ Td0((t0 >>u 24) ) ^
+ Td1((t3 >>u 16) & 0xff) ^
+ Td2((t2 >>u 8) & 0xff) ^
+ Td3((t1 ) & 0xff) ^
+ rk(0);
+ s1 =
+ Td0((t1 >>u 24) ) ^
+ Td1((t0 >>u 16) & 0xff) ^
+ Td2((t3 >>u 8) & 0xff) ^
+ Td3((t2 ) & 0xff) ^
+ rk(1);
+ s2 =
+ Td0((t2 >>u 24) ) ^
+ Td1((t1 >>u 16) & 0xff) ^
+ Td2((t0 >>u 8) & 0xff) ^
+ Td3((t3 ) & 0xff) ^
+ rk(2);
+ s3 =
+ Td0((t3 >>u 24) ) ^
+ Td1((t2 >>u 16) & 0xff) ^
+ Td2((t1 >>u 8) & 0xff) ^
+ Td3((t0 ) & 0xff) ^
+ rk(3);
+ } }}
+ /*
+ * apply last round and
+ * map cipher state to byte array block:
+ */
+ s0 =
+ (Td4((t0 >>u 24) ) & 0xff000000) ^
+ (Td4((t3 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Td4((t2 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Td4((t1 ) & 0xff) & 0x000000ff) ^
+ rk(0);
+ PUTU32(pt , s0);
+ s1 =
+ (Td4((t1 >>u 24) ) & 0xff000000) ^
+ (Td4((t0 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Td4((t3 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Td4((t2 ) & 0xff) & 0x000000ff) ^
+ rk(1);
+ PUTU32(pt + 4, s1);
+ s2 =
+ (Td4((t2 >>u 24) ) & 0xff000000) ^
+ (Td4((t1 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Td4((t0 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Td4((t3 ) & 0xff) & 0x000000ff) ^
+ rk(2);
+ PUTU32(pt + 8, s2);
+ s3 =
+ (Td4((t3 >>u 24) ) & 0xff000000) ^
+ (Td4((t2 >>u 16) & 0xff) & 0x00ff0000) ^
+ (Td4((t1 >>u 8) & 0xff) & 0x0000ff00) ^
+ (Td4((t0 ) & 0xff) & 0x000000ff) ^
+ rk(3);
+ PUTU32(pt + 12, s3);
+}
diff --git a/test/cminor/almabench.cmp b/test/cminor/almabench.cmp
new file mode 100644
index 0000000..e9e8392
--- /dev/null
+++ b/test/cminor/almabench.cmp
@@ -0,0 +1,159 @@
+#define PI 3.14159265358979323846
+#define J2000 2451545.0
+#define JCENTURY 36525.0
+#define JMILLENIA 365250.0
+#define TWOPI (2.0 *f PI)
+#define A2R (PI /f 648000.0)
+#define R2H (12.0 /f PI)
+#define R2D (180.0 /f PI)
+#define GAUSSK 0.01720209895
+#define TEST_LOOPS 20
+#define TEST_LENGTH 36525
+#define sineps 0.3977771559319137
+#define coseps 0.9174820620691818
+
+/* Access to tables */
+#define amas(n) float64["amas" + (n) * 8]
+#define a(x,y) float64["a" + ((x) * 24 + (y) * 8)]
+#define dlm(x,y) float64["dlm" + ((x) * 24 + (y) * 8)]
+#define e(x,y) float64["e" + ((x) * 24 + (y) * 8)]
+#define pi(x,y) float64["pi" + ((x) * 24 + (y) * 8)]
+#define dinc(x,y) float64["dinc" + ((x) * 24 + (y) * 8)]
+#define omega(x,y) float64["omega" + ((x) * 24 + (y) * 8)]
+#define kp(x,y) float64["kp" + ((x) * 72 + (y) * 8)]
+#define ca(x,y) float64["ca" + ((x) * 72 + (y) * 8)]
+#define sa(x,y) float64["sa" + ((x) * 72 + (y) * 8)]
+#define kq(x,y) float64["kq" + ((x) * 80 + (y) * 8)]
+#define cl(x,y) float64["cl" + ((x) * 80 + (y) * 8)]
+#define sl(x,y) float64["sl" + ((x) * 80 + (y) * 8)]
+
+/* Function calls */
+#define cos(x) ("cos_static"(x): float -> float)
+#define sin(x) ("sin_static"(x): float -> float)
+#define atan2(x,y) ("atan2_static"(x,y): float -> float -> float)
+#define asin(x) ("asin_static"(x): float -> float)
+#define sqrt(x) ("sqrt_static"(x): float -> float)
+#define fmod(x,y) ("fmod_static"(x,y): float -> float -> float)
+#define anpm(x) ("anpm"(x) : float -> float)
+
+"anpm"(a): float -> float
+{
+ var w;
+ w = fmod(a,TWOPI);
+ if (absf(w) >=f PI)
+ w = w -f ((a <f 0.0) ? -f TWOPI : TWOPI);
+ return w;
+}
+
+"planetpv" (epoch_, np, pv_): int -> int -> int -> void
+{
+#define epoch(x) float64[epoch_ + (x) * 8]
+#define pv(x,y) float64[pv_ + (x) * 24 + (y) * 8]
+
+ var i, j, k;
+ var t, da, dl, de, dp, di;
+ var doh, dmu, arga, argl, am;
+ var ae, dae, ae2, at, r, v;
+ var si2, xq, xp, tl, xsw;
+ var xcw, xm2, xf, ci2, xms, xmc;
+ var xpxq2, x, y, z;
+
+ t = ((epoch(0) -f J2000) +f epoch(1)) /f JMILLENIA;
+
+ da = a(np,0) +f (a(np,1) +f a(np,2) *f t ) *f t;
+ dl = (3600.0 *f dlm(np,0) +f (dlm(np,1) +f dlm(np,2) *f t ) *f t ) *f A2R;
+ de = e(np,0) +f (e(np,1) +f e(np,2) *f t ) *f t;
+ dp = anpm((3600.0 *f pi(np,0) +f (pi(np,1) +f pi(np,2) *f t ) *f t ) *f A2R );
+ di = (3600.0 *f dinc(np,0) +f (dinc(np,1) +f dinc(np,2) *f t ) *f t ) *f A2R;
+ doh = anpm((3600.0 *f omega(np,0) +f (omega(np,1) +f omega(np,2) *f t ) *f t ) *f A2R );
+
+ dmu = 0.35953620 *f t;
+
+ k = 0;
+ {{ loop {
+ if (! (k < 8)) exit;
+ arga = kp(np,k) *f dmu;
+ argl = kq(np,k) *f dmu;
+ da = da +f (ca(np,k) *f cos(arga) +f sa(np,k) *f sin(arga)) *f 0.0000001;
+ dl = dl +f (cl(np,k) *f cos(argl) +f sl(np,k) *f sin(argl)) *f 0.0000001;
+ k = k + 1;
+ } }}
+
+ arga = kp(np,8) *f dmu;
+ da = da +f t *f (ca(np,8) *f cos(arga) +f sa(np,8) *f sin(arga)) *f 0.0000001;
+
+ k = 8;
+ {{ loop {
+ if (! (k <= 9)) exit;
+ argl = kq(np,k) *f dmu;
+ dl = dl +f t *f ( cl(np,k) *f cos(argl) +f sl(np,k) *f sin(argl) ) *f 0.0000001;
+ k = k + 1;
+ } }}
+
+ dl = "fmod_static"(dl,TWOPI) : float -> float -> float;
+
+ am = dl -f dp;
+ ae = am +f de *f sin(am);
+ k = 0;
+
+ {{ loop {
+ dae = (am -f ae +f de *f sin(ae)) /f (1.0 -f de *f cos(ae));
+ ae = ae +f dae;
+ k = k + 1;
+
+ if ((k >= 10) || (absf(dae) <f 1e-12))
+ exit;
+ } }}
+
+ ae2 = ae /f 2.0;
+ at = 2.0 *f atan2(sqrt((1.0 +f de) /f (1.0 -f de)) *f sin(ae2), cos(ae2));
+
+ r = da *f (1.0 -f de *f cos(ae));
+ v = GAUSSK *f sqrt((1.0 +f 1.0 /f amas(np) ) /f (da *f da *f da));
+
+ si2 = sin(di /f 2.0);
+ xq = si2 *f cos(doh);
+ xp = si2 *f sin(doh);
+ tl = at +f dp;
+ xsw = sin(tl);
+ xcw = cos(tl);
+ xm2 = 2.0 *f (xp *f xcw -f xq *f xsw );
+ xf = da /f sqrt(1.0 -f de *f de);
+ ci2 = cos(di /f 2.0);
+ xms = (de *f sin(dp) +f xsw) *f xf;
+ xmc = (de *f cos(dp) +f xcw) *f xf;
+ xpxq2 = 2.0 *f xp *f xq;
+
+ x = r *f (xcw -f xm2 *f xp);
+ y = r *f (xsw +f xm2 *f xq);
+ z = r *f (-f xm2 *f ci2);
+
+ pv(0,0) = x;
+ pv(0,1) = y *f coseps -f z *f sineps;
+ pv(0,2) = y *f sineps +f z *f coseps;
+
+ x = v *f ((-f 1.0 +f 2.0 *f xp *f xp) *f xms +f xpxq2 *f xmc);
+ y = v *f (( 1.0 -f 2.0 *f xq *f xq ) *f xmc -f xpxq2 *f xms);
+ z = v *f (2.0 *f ci2 *f (xp *f xms +f xq *f xmc));
+
+ pv(1,0) = x;
+ pv(1,1) = y *f coseps -f z *f sineps;
+ pv(1,2) = y *f sineps +f z *f coseps;
+
+#undef epoch
+#undef pv
+}
+
+"radecdist"(state_, rdd_): int -> int -> void
+{
+#define state(x,y) float64[state_ + (x) * 24 + (y) * 8]
+#define rdd(x) float64[rdd_ + (x) * 8]
+
+ rdd(2) = sqrt(state(0,0) *f state(0,0) +f state(0,1) *f state(0,1) +f state(0,2) *f state(0,2));
+ rdd(0) = atan2(state(0,1), state(0,0)) *f R2H;
+ if (rdd(0) <f 0.0) rdd(0) = rdd(0) +f 24.0;
+ rdd(1) = asin(state(0,2) /f rdd(2)) *f R2D;
+
+#undef state
+#undef rdd
+}
diff --git a/test/cminor/fft.cm b/test/cminor/fft.cm
new file mode 100644
index 0000000..b4e6a40
--- /dev/null
+++ b/test/cminor/fft.cm
@@ -0,0 +1,149 @@
+/********************************************************/
+/* A Duhamel-Hollman split-radix dif fft */
+/* Ref: Electronics Letters, Jan. 5, 1984 */
+/* Complex input and output data in arrays x and y */
+/* Length is n. */
+/********************************************************/
+
+"dfft"(x, y, np): int /*float ptr*/ -> int /*float ptr*/ -> int -> int
+{
+ var px, py, /*float ptr*/
+ i, j, k, m, n, i0, i1, i2, i3, is, id, n1, n2, n4, a, e, a3, /*int*/
+ cc1, ss1, cc3, ss3, r1, r2, s1, s2, s3, xt, tpi /*float*/;
+
+ px = x - 8;
+ py = y - 8;
+ i = 2;
+ m = 1;
+
+ {{ loop {
+ if (! (i < np)) exit;
+ i = i+i;
+ m = m+1;
+ } }}
+
+ n = i;
+
+ if (n != np)
+ {
+ i = np + 1;
+ {{ loop {
+ if (! (i <= n)) exit;
+ float64[px + i*8] = 0.0;
+ float64[py + i*8] = 0.0;
+ i = i + 1;
+ } }}
+ }
+
+ n2 = n+n;
+ tpi = 2.0 *f 3.14159265358979323846;
+ k = 1;
+ {{ loop {
+ if (! (k <= m - 1)) exit;
+ n2 = n2 / 2;
+ n4 = n2 / 4;
+ e = tpi /f floatofint(n2);
+ a = 0.0;
+
+ j = 1;
+ {{ loop {
+ if (! (j <= n4)) exit;
+ cc1 = "cos_static"(a) : float -> float;
+ ss1 = "sin_static"(a) : float -> float;
+ a3 = 3.0 *f a;
+ cc3 = "cos_static"(a3) : float -> float;
+ ss3 = "sin_static"(a3) : float -> float;
+ a = e *f floatofint(j);
+ is = j;
+ id = 2 * n2;
+
+ {{ loop {
+ if (! ( is < n )) exit;
+ i0 = is;
+ {{ loop {
+ /* DEBUG "trace"(); */
+ if (! (i0 <= n - 1)) exit;
+ i1 = i0 + n4; /*DEBUG "print_int"(i1); */
+ i2 = i1 + n4; /*DEBUG "print_int"(i2); */
+ i3 = i2 + n4; /*DEBUG "print_int"(i3); */
+ r1 = float64[px+i0*8] -f float64[px+i2*8];
+ /* DEBUG "print_float"(r1); */
+ float64[px+i0*8] = float64[px+i0*8] +f float64[px+i2*8];
+ r2 = float64[px+i1*8] -f float64[px+i3*8];
+ /* DEBUG "print_float"(r2); */
+ float64[px+i1*8] = float64[px+i1*8] +f float64[px+i3*8];
+ s1 = float64[py+i0*8] -f float64[py+i2*8];
+ /* DEBUG "print_float"(s1); */
+ float64[py+i0*8] = float64[py+i0*8] +f float64[py+i2*8];
+ s2 = float64[py+i1*8] -f float64[py+i3*8];
+ /* DEBUG "print_float"(s2); */
+ float64[py+i1*8] = float64[py+i1*8] +f float64[py+i3*8];
+ s3 = r1 -f s2; r1 = r1 +f s2;
+ s2 = r2 -f s1; r2 = r2 +f s1;
+ float64[px+i2*8] = (r1 *f cc1) -f (s2 *f ss1);
+ float64[py+i2*8] = (-f s2 *f cc1) -f (r1 *f ss1);
+ float64[px+i3*8] = (s3 *f cc3) +f (r2 *f ss3);
+ float64[py+i3*8] = (r2 *f cc3) -f (s3 *f ss3);
+ i0 = i0 + id;
+ } }}
+ is = 2 * id - n2 + j;
+ id = 4 * id;
+ } }}
+ j = j + 1;
+ } }}
+ k = k + 1;
+ } }}
+
+/************************************/
+/* Last stage, length=2 butterfly */
+/************************************/
+ is = 1;
+ id = 4;
+
+ {{ loop {
+ if (! ( is < n)) exit;
+ i0 = is;
+ {{ loop {
+ if (! (i0 <= n)) exit;
+ i1 = i0 + 1;
+ r1 = float64[px+i0*8];
+ float64[px+i0*8] = r1 +f float64[px+i1*8];
+ float64[px+i1*8] = r1 -f float64[px+i1*8];
+ r1 = float64[py+i0*8];
+ float64[py+i0*8] = r1 +f float64[py+i1*8];
+ float64[py+i1*8] = r1 -f float64[py+i1*8];
+ i0 = i0 + id;
+ } }}
+ is = 2*id - 1;
+ id = 4 * id;
+ } }}
+
+/*************************/
+/* Bit reverse counter */
+/*************************/
+ j = 1;
+ n1 = n - 1;
+
+ i = 1;
+ {{ loop {
+ if (! (i <= n1)) exit;
+ if (i < j) {
+ xt = float64[px+j*8];
+ float64[px+j*8] = float64[px+i*8];
+ float64[px+i*8] = xt;
+ xt = float64[py+j*8];
+ float64[py+j*8] = float64[py+i*8];
+ float64[py+i*8] = xt;
+ }
+ k = n / 2;
+ {{ loop {
+ if (! (k < j)) exit;
+ j = j - k;
+ k = k / 2;
+ } }}
+ j = j + k;
+ i = i + 1;
+ } }}
+
+ return(n);
+}
diff --git a/test/cminor/fib.cm b/test/cminor/fib.cm
new file mode 100644
index 0000000..42fbdd6
--- /dev/null
+++ b/test/cminor/fib.cm
@@ -0,0 +1,7 @@
+"fib"(n): int -> int
+{
+ if (n < 2)
+ return 1;
+ else
+ return "fib"(n - 1) : int -> int + "fib"(n - 2) : int -> int;
+}
diff --git a/test/cminor/integr.cm b/test/cminor/integr.cm
new file mode 100644
index 0000000..28f0a1d
--- /dev/null
+++ b/test/cminor/integr.cm
@@ -0,0 +1,25 @@
+"square" (x): float -> float
+{
+ return x *f x;
+}
+
+"integr"(f, low, high, n): int -> float -> float -> int -> float
+{
+ var h, x, s, i;
+ h = (high -f low) /f floatofint n;
+ x = low;
+ s = 0.0;
+ i = n;
+ {{ loop {
+ if (! (i > 0)) exit;
+ s = s +f (f(x): float -> float);
+ x = x +f h;
+ i = i - 1;
+ } }}
+ return s *f h;
+}
+
+"test"(n) : int -> float
+{
+ return "integr"("square", 0.0, 1.0, n): int -> float -> float -> int -> float;
+}
diff --git a/test/cminor/manyargs.cm b/test/cminor/manyargs.cm
new file mode 100644
index 0000000..97b1662
--- /dev/null
+++ b/test/cminor/manyargs.cm
@@ -0,0 +1,53 @@
+"f" (i1, i2, i3, i4, i5,
+ i6, i7, i8, i9, i10,
+ f1, f2, f3, f4, f5,
+ f6, f7, f8, f9, f10,
+ f11, f12, f13, f14, f15):
+ int -> int -> int -> int -> int ->
+ int -> int -> int -> int -> int ->
+ float -> float -> float -> float -> float ->
+ float -> float -> float -> float -> float ->
+ float -> float -> float -> float -> float -> void
+{
+ "print_int"(i1): int -> void;
+ "print_int"(i2): int -> void;
+ "print_int"(i3): int -> void;
+ "print_int"(i4): int -> void;
+ "print_int"(i5): int -> void;
+ "print_int"(i6): int -> void;
+ "print_int"(i7): int -> void;
+ "print_int"(i8): int -> void;
+ "print_int"(i9): int -> void;
+ "print_int"(i10): int -> void;
+ "print_float"(f1): float -> void;
+ "print_float"(f2): float -> void;
+ "print_float"(f3): float -> void;
+ "print_float"(f4): float -> void;
+ "print_float"(f5): float -> void;
+ "print_float"(f6): float -> void;
+ "print_float"(f7): float -> void;
+ "print_float"(f8): float -> void;
+ "print_float"(f9): float -> void;
+ "print_float"(f10): float -> void;
+ "print_float"(f11): float -> void;
+ "print_float"(f12): float -> void;
+ "print_float"(f13): float -> void;
+ "print_float"(f14): float -> void;
+ "print_float"(f15): float -> void;
+}
+
+"g" (i1, i2, i3, i4, i5,
+ f1, f2, f3, f4, f5):
+ int -> int -> int -> int -> int ->
+ float -> float -> float -> float -> float -> void
+{
+ "f"(i1,i2,i3,i4,i5, i1,i2,i3,i4,i5,
+ f1,f2,f3,f4,f5, f1,f2,f3,f4,f5, f1,f2,f3,f4,f5):
+ int -> int -> int -> int -> int ->
+ int -> int -> int -> int -> int ->
+ float -> float -> float -> float -> float ->
+ float -> float -> float -> float -> float ->
+ float -> float -> float -> float -> float -> void;
+
+}
+
diff --git a/test/cminor/qsort.cm b/test/cminor/qsort.cm
new file mode 100644
index 0000000..004f8cd
--- /dev/null
+++ b/test/cminor/qsort.cm
@@ -0,0 +1,30 @@
+"quicksort"(lo, hi, a): int -> int -> int -> void
+{
+ var i, j, pivot, temp;
+
+ if (! (lo < hi)) return;
+ i = lo;
+ j = hi;
+ pivot = int32[a + hi * 4];
+ {{ loop {
+ if (! (i < j)) exit;
+ {{ loop {
+ if (i >= hi || int32[a + i * 4] > pivot) exit;
+ i = i + 1;
+ } }}
+ {{ loop {
+ if (j <= lo || int32[a + j * 4] < pivot) exit;
+ j = j - 1;
+ } }}
+ if (i < j) {
+ temp = int32[a + i * 4];
+ int32[a + i * 4] = int32[a + j * 4];
+ int32[a + j * 4] = temp;
+ }
+ } }}
+ temp = int32[a + i * 4];
+ int32[a + i * 4] = int32[a + hi * 4];
+ int32[a + hi * 4] = temp;
+ "quicksort"(lo, i - 1, a) : int -> int -> int -> void;
+ "quicksort"(i + 1, hi, a) : int -> int -> int -> void;
+}
diff --git a/test/cminor/sha1.cmp b/test/cminor/sha1.cmp
new file mode 100644
index 0000000..9a588e4
--- /dev/null
+++ b/test/cminor/sha1.cmp
@@ -0,0 +1,189 @@
+/* SHA-1 cryptographic hash function */
+/* Ref: Handbook of Applied Cryptography, section 9.4.2, algorithm 9.53 */
+
+/* To be preprocessed by cpp -P */
+
+#define ARCH_BIG_ENDIAN
+
+#define rol1(x) (((x) << 1) | ((x) >>u 31))
+#define rol5(x) (((x) << 5) | ((x) >>u 27))
+#define rol30(x) (((x) << 30) | ((x) >>u 2))
+
+"SHA1_copy_and_swap"(src, dst, numwords) : int -> int -> int -> void
+{
+#ifdef ARCH_BIG_ENDIAN
+ "memcpy_static"(dst, src, numwords * 4) : int -> int -> int -> void;
+#else
+ var s, d, a, b;
+ s = src;
+ d = dst;
+ {{ loop {
+ if (numwords <= 0) exit;
+ a = int8u[s];
+ b = int8u[s + 1];
+ int8u[d] = int8u[s + 3];
+ int8u[d + 1] = int8u[s + 2];
+ int8u[d + 2] = b;
+ int8u[d + 3] = a;
+ s = s + 4;
+ d = d + 4;
+ numwords = numwords - 1;
+ } }}
+#endif
+}
+
+#define F(x,y,z) ( z ^ (x & (y ^ z) ) )
+#define G(x,y,z) ( (x & y) | (z & (x | y) ) )
+#define H(x,y,z) ( x ^ y ^ z )
+
+#define Y1 0x5A827999
+#define Y2 0x6ED9EBA1
+#define Y3 0x8F1BBCDC
+#define Y4 0xCA62C1D6
+
+#define context_state(ctx,n) int32[ctx + n * 4]
+#define context_length(ctx) ctx + 20
+#define context_length_hi(ctx) int32[ctx + 20]
+#define context_length_lo(ctx) int32[ctx + 24]
+#define context_numbytes(ctx) int32[ctx + 28]
+#define context_buffer(ctx) (ctx + 32)
+#define context_size 96
+
+"SHA1_transform"(ctx) : int -> void
+{
+ stack 320
+ var i, p, a, b, c, d, e, t;
+
+ /* Convert buffer data to 16 big-endian integers */
+ "SHA1_copy_and_swap"(context_buffer(ctx), &0, 16) : int -> int -> int -> void;
+ /* Expand into 80 integers */
+ i = 16;
+ {{ loop {
+ if (! (i < 80)) exit;
+ p = &0 + i * 4;
+ t = int32[p - 12] ^ int32[p - 32] ^ int32[p - 56] ^ int32[p - 64];
+ int32[p] = rol1(t);
+ i = i + 1;
+ } }}
+
+ /* Initialize working variables */
+ a = context_state(ctx, 0);
+ b = context_state(ctx, 1);
+ c = context_state(ctx, 2);
+ d = context_state(ctx, 3);
+ e = context_state(ctx, 4);
+
+ /* Perform rounds */
+ i = 0;
+ {{ loop {
+ if (! (i < 20)) exit;
+ t = F(b, c, d) + Y1 + rol5(a) + e + int32[&0 + i * 4];
+ e = d; d = c; c = rol30(b); b = a; a = t;
+ i = i + 1;
+ } }}
+ {{ loop {
+ if (! (i < 40)) exit;
+ t = H(b, c, d) + Y2 + rol5(a) + e + int32[&0 + i * 4];
+ e = d; d = c; c = rol30(b); b = a; a = t;
+ i = i + 1;
+ } }}
+ {{ loop {
+ if (! (i < 60)) exit;
+ t = G(b, c, d) + Y3 + rol5(a) + e + int32[&0 + i * 4];
+ e = d; d = c; c = rol30(b); b = a; a = t;
+ i = i + 1;
+ } }}
+ {{ loop {
+ if (! (i < 80)) exit;
+ t = H(b, c, d) + Y4 + rol5(a) + e + int32[&0 + i * 4];
+ e = d; d = c; c = rol30(b); b = a; a = t;
+ i = i + 1;
+ } }}
+
+ /* Update chaining values */
+ context_state(ctx, 0) = context_state(ctx, 0) + a;
+ context_state(ctx, 1) = context_state(ctx, 1) + b;
+ context_state(ctx, 2) = context_state(ctx, 2) + c;
+ context_state(ctx, 3) = context_state(ctx, 3) + d;
+ context_state(ctx, 4) = context_state(ctx, 4) + e;
+}
+
+"SHA1_init"(ctx) : int -> void
+{
+ context_state(ctx, 0) = 0x67452301;
+ context_state(ctx, 1) = 0xEFCDAB89;
+ context_state(ctx, 2) = 0x98BADCFE;
+ context_state(ctx, 3) = 0x10325476;
+ context_state(ctx, 4) = 0xC3D2E1F0;
+ context_numbytes(ctx) = 0;
+ context_length_lo(ctx) = 0;
+ context_length_hi(ctx) = 0;
+}
+
+"SHA1_add_data"(ctx, data, len) : int -> int -> int -> void
+{
+ var t;
+
+ /* Update length */
+ t = context_length_lo(ctx);
+ if ((context_length_lo(ctx) = t + (len << 3)) <u t)
+ context_length_hi(ctx) = context_length_hi(ctx) + 1;
+ context_length_hi(ctx) = context_length_hi(ctx) + (len >>u 29);
+
+ /* If data was left in buffer, pad it with fresh data and munge block */
+ if (context_numbytes(ctx) != 0) {
+ t = 64 - context_numbytes(ctx);
+ if (len <u t) {
+ "memcpy_static"(context_buffer(ctx) + context_numbytes(ctx), data, len)
+ : int -> int -> int -> void;
+ context_numbytes(ctx) = context_numbytes(ctx) + len;
+ return;
+ }
+ "memcpy_static"(context_buffer(ctx) + context_numbytes(ctx), data, t)
+ : int -> int -> int -> void;
+ "SHA1_transform"(ctx) : int -> void;
+ data = data + t;
+ len = len - t;
+ }
+ /* Munge data in 64-byte chunks */
+ {{ loop {
+ if (! (len >=u 64)) exit;
+ "memcpy_static"(context_buffer(ctx), data, 64)
+ : int -> int -> int -> void;
+ "SHA1_transform"(ctx) : int -> void;
+ data = data + 64;
+ len = len - 64;
+ } }}
+ /* Save remaining data */
+ "memcpy_static"(context_buffer(ctx), data, len)
+ : int -> int -> int -> void;
+ context_numbytes(ctx) = len;
+}
+
+"SHA1_finish"(ctx, output) : int -> int -> void
+{
+ var i;
+ i = context_numbytes(ctx);
+ /* Set first char of padding to 0x80. There is always room. */
+ int8u[context_buffer(ctx) + i] = 0x80;
+ i = i + 1;
+ /* If we do not have room for the length (8 bytes), pad to 64 bytes
+ with zeroes and munge the data block */
+ if (i > 56) {
+ "memset_static"(context_buffer(ctx) + i, 0, 64 - i)
+ : int -> int -> int -> void;
+ "SHA1_transform"(ctx) : int -> void;
+ i = 0;
+ }
+ /* Pad to byte 56 with zeroes */
+ "memset_static"(context_buffer(ctx) + i, 0, 56 - i)
+ : int -> int -> int -> void;
+ /* Add length in big-endian */
+ "SHA1_copy_and_swap"(context_length(ctx), context_buffer(ctx) + 56, 2)
+ : int -> int -> int -> void;
+ /* Munge the final block */
+ "SHA1_transform"(ctx) : int -> void;
+ /* Final hash value is in ctx->state modulo big-endian conversion */
+ "SHA1_copy_and_swap"(ctx, output, 5)
+ : int -> int -> int -> void;
+}