From a81794df00369f6adf4a06e2f0247d309a196e27 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 6 Apr 2025 16:22:38 -0700 Subject: Fix sieve RA returns maxSlot+1 FunX86 prints as `subi`, uses Sub; Ret uses Add X86 knows that always RPC is passed on stack "as if" a stack arg. sieve uses unsigned ints. Driver expects an array pointer --- .../src/test/java/com/seaofnodes/simple/Chapter15Test.java | 4 ++-- .../src/test/java/com/seaofnodes/simple/Chapter19Test.java | 4 ++-- .../src/test/java/com/seaofnodes/simple/Chapter21Test.java | 2 +- chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.c | 12 ++++++------ .../src/test/java/com/seaofnodes/simple/progs/sieve.smp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'chapter21/src/test/java') diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java index a850b1b8..8da5cf96 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -217,8 +217,8 @@ return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sieve.smp")); CodeGen code = new CodeGen(src+"return sieve(arg);"); code.parse().opto(); - assertEquals("return [int];", code.print()); - assertEquals("int[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); + assertEquals("return [u32];", code.print()); + assertEquals("u32[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); } @Test diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter19Test.java index 6425fb80..9ba8e972 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter19Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter19Test.java @@ -303,8 +303,8 @@ return A[1]; public void sieveOfEratosthenes() throws IOException { String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sieve.smp")); CodeGen code = new CodeGen(src).parse().opto().typeCheck().instSelect("x86_64_v2", "SystemV").GCM().localSched(); - assertEquals("return [int];", code.print()); - //assertEquals("int[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); + assertEquals("return [u32];", code.print()); + //assertEquals("u32[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); } diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 3f764a4c..170a7674 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -89,7 +89,7 @@ public class Chapter21Test { @Test public void testStringExport() throws IOException { TestC.run("stringHash"); } @Test public void testSieve() throws IOException { - String primes = "[2, 3, ]"; + String primes = "25[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ]"; TestC.run("sieve",primes); } diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.c b/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.c index 8c28aea8..b0e85dba 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.c +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.c @@ -3,16 +3,16 @@ typedef struct AryInt { unsigned int len; - unsigned int data[]; + int data[]; } AryInt; -extern AryInt sieve(int N); +extern AryInt *sieve(int N); int main() { - AryInt ps = sieve(10); - printf("["); - for( int i=0; ilen); + for( int i=0; ilen; i++ ) + printf("%d, ",ps->data[i]); printf("]"); return 0; } diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.smp index c5c3824a..6d160b1e 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.smp +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/sieve.smp @@ -3,7 +3,7 @@ val sieve = { int N -> bool[] !ary = new bool[N]; // The primes less than N - int[] !primes = new int[N>>1]; + u32[] !primes = new u32[N>>1]; // Number of primes so far, searching at index p int nprimes = 0, p=2; // Find primes while p^2 < N @@ -24,7 +24,7 @@ val sieve = { int N -> primes[nprimes++] = p; // Copy/shrink the result array - int[] !rez = new int[nprimes]; + u32[] !rez = new u32[nprimes]; for( int j=0; j < nprimes; j++ ) rez[j] = primes[j]; return rez; -- cgit v1.2.3