From 5fb03752b195e99dd251c9d497cccc93335bffe2 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Mon, 21 Apr 2025 11:57:04 -0700 Subject: Code quality on loop with many continues --- .../src/test/java/com/seaofnodes/simple/Chapter21Test.java | 7 +++++++ chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.c | 7 +++++++ chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.smp | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.c create mode 100644 chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.smp (limited to 'chapter21/src/test') diff --git a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 6a22498b..1857367b 100644 --- a/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/chapter21/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -73,6 +73,13 @@ public class Chapter21Test { TestC.run("stringHash", 9); } + @Test public void testLoop2() throws IOException { + String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/loop2.smp")); + testCPU(src,"x86_64_v2", "Win64" ,0,"return (inc,Phi(Loop,0,inc));"); + testCPU(src,"riscv" , "SystemV",0,"return ( Phi(Loop,0,addi) + #1 );"); + testCPU(src,"arm" , "SystemV",0,"return (inc,Phi(Loop,0,inc));"); + } + @Test public void testNewtonExport() throws IOException { String result = """ 0 0.000000 (0) diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.c b/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.c new file mode 100644 index 00000000..934f2d89 --- /dev/null +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.c @@ -0,0 +1,7 @@ + +__attribute__ ((CALL_CONV)) +extern int loop2(); + +int main() { + return loop2(); +} diff --git a/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.smp b/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.smp new file mode 100644 index 00000000..01ec827e --- /dev/null +++ b/chapter21/src/test/java/com/seaofnodes/simple/progs/loop2.smp @@ -0,0 +1,10 @@ +// -*- mode: java; -*- +int i = 0; +while(true) { + i += 1; + if( i==0 ) continue; + if( i==1 ) continue; + if( i==2 ) break; + continue; +} +return i; -- cgit v1.2.3