diff options
| author | Cliff Click <cliffc@acm.org> | 2025-06-13 15:42:08 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-08-10 11:11:18 -0700 |
| commit | e57bdd315a7918a0d130e1c95648ca4a1b4f08ed (patch) | |
| tree | ea659c39bce731b506347a80f424e3c325ff5326 /src | |
| parent | 08d33f808db30936b273582bcfaddcbc5a57c112 (diff) | |
| download | Simple-e57bdd315a7918a0d130e1c95648ca4a1b4f08ed.tar.gz Simple-e57bdd315a7918a0d130e1c95648ca4a1b4f08ed.zip | |
Chapter 24: Chaining Relationals and Sparse Conditional Constant Propagation
Co-authored-by: Tamás Hadházy <85063808+Hels15@users.noreply.github.com>
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com>
Co-authored-by: Hadházy Tamás <helsgithub15@gmail.com>
Diffstat (limited to 'src')
98 files changed, 2258 insertions, 6457 deletions
diff --git a/src/main/java/com/seaofnodes/simple/IterPeeps.java b/src/main/java/com/seaofnodes/simple/IterPeeps.java index 9ae4231e..18ff470a 100644 --- a/src/main/java/com/seaofnodes/simple/IterPeeps.java +++ b/src/main/java/com/seaofnodes/simple/IterPeeps.java @@ -1,6 +1,8 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeInteger; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.node.*; import com.seaofnodes.simple.print.JSViewer; @@ -46,7 +48,7 @@ import java.util.Random; */ public class IterPeeps { - private final WorkList<Node> _work; + public final WorkList<Node> _work; public IterPeeps( long seed ) { _work = new WorkList<>(seed); } @@ -59,7 +61,7 @@ public class IterPeeps { * Iterate peepholes to a fixed point */ public void iterate( CodeGen code ) { - assert progressOnList(code); + assert progressOnList(code, _work, true); int cnt=0; Node n; @@ -89,7 +91,7 @@ public class IterPeeps { // If there are distant neighbors, move to worklist n.moveDepsToWorklist(); JSViewer.show(); // Show again - assert progressOnList(code); // Very expensive assert + assert progressOnList(code, _work, true); // Very expensive assert } if( n.isUnused() && !(n instanceof StopNode) ) n.kill(); // Just plain dead @@ -109,18 +111,24 @@ public class IterPeeps { // neighbors and these should fail, but will then try to add dependencies // {@link #Node.addDep} which is a side effect in an assert. The {@link // #midAssert} is used to stop this side effect. - private boolean progressOnList(CodeGen code) { + // Pessimistic solver assert + public static boolean progressOnList(CodeGen code, WorkList<Node> list, boolean dir ) { code._midAssert = true; Node changed = code._stop.walk( n -> { - Node m = n; - if( n.compute().isa(n._type) && (!n.iskeep() || n._nid<=6) ) { // Types must be forwards, even if on worklist - if( _work.on(n) ) return null; - m = n.peepholeOpt(); - if( m==null ) return null; - } - System.err.println("BREAK HERE FOR BUG"); - return m; - }); + Node m = n; + Type nval = n.compute(); + if( (!n.iskeep() || n._nid<=8) && // Types must be forwards, even if on worklist + ( dir + ? nval.isa(n._type) // Pesi: new value lifts over old + : n._type.isa(nval) // Opto: new value falls over old + ) ) { + if( list.on(n) ) return null; + m = n.peepholeOpt(); + if( m==null ) return null; + } + System.err.println("BREAK HERE FOR BUG"); + return m; + }); code._midAssert = false; return changed==null; } @@ -176,7 +184,7 @@ public class IterPeeps { /** * True if Node is on the WorkList */ - boolean on( E x ) { return _on.get(x._nid); } + public boolean on( E x ) { return _on.get(x._nid); } boolean isEmpty() { return _len==0; } /** diff --git a/src/main/java/com/seaofnodes/simple/Parser.java b/src/main/java/com/seaofnodes/simple/Parser.java index 8a6b1967..f80e8f2c 100644 --- a/src/main/java/com/seaofnodes/simple/Parser.java +++ b/src/main/java/com/seaofnodes/simple/Parser.java @@ -142,7 +142,7 @@ public class Parser { _scope.mem(new MemMergeNode(false)); // Parse the sys import - _lexer = new Lexer(com.seaofnodes.simple.sys.SYS); + _lexer = new Lexer(sys.SYS); while( !_lexer.isEOF() ) { parseStatement(); _lexer.skipWhiteSpace(); @@ -160,18 +160,26 @@ public class Parser { // default main). FunNode main = _code.link(_code._main); StopNode stop = _code._stop; + // Gather an explicit main + FunNode xmain = null; + for( Node n : stop._inputs ) + if( n instanceof ReturnNode ret && "main".equals(ret.fun()._name) ) + if( xmain != null ) throw Utils.TODO(); + else xmain = ret.fun(); + if( main.ret().expr()._type==Type.TOP && main.uctrl()==null ) { // Kill an empty default main; so it does not attempt to put a // "main" in any final ELF file main.setDef(1,XCTRL); // Delete default start input stop.delDef(stop._inputs.find(main.ret())); + if( xmain != null ) + _code.setMain(xmain); + } else { // We have a non-empty default main. - // Check for an explicit main - for( Node n : stop._inputs ) - if( n instanceof FunNode fun && fun._name.equals("main") ) - // Found an explicit "main" AND we have a default "main" - throw error("Cannot define both an explicit main and a default main"); + if( xmain != null ) + // Found an explicit "main" AND we have a default "main" + throw error("Cannot define both an explicit main and a default main"); main._name = "main"; } @@ -540,9 +548,8 @@ public class Parser { // Parse a conditional expression, merging results. private Node parseTrinary( Node pred, String fside ) { - pred.keep(); - // IfNode takes current control and predicate + pred.keep(); Node ifNode = new IfNode(ctrl(), pred).peephole(); // Setup projection nodes Node ifT = new CProjNode(ifNode. keep(), 0, "True" ).peephole().keep(); @@ -712,7 +719,7 @@ public class Parser { // Type is sane if( et!=Type.BOTTOM && !et.shallowISA(t) ) - expr = peep(new CastNode(t,null,expr)); + expr = peep(new CastNode(t.isConstant() ? t : t.widen(),null,expr)); return expr; } @@ -818,7 +825,7 @@ public class Parser { // Lift type to the declaration. This will report as an error later if // we cannot lift the type. if( !lift._type.isa(t) ) - lift = peep(new CastNode(t,null,lift)); + lift = peep(new CastNode(t.widen(),null,lift)); // Define a new name if( !_scope.define(name,t,xfinal || fld_final,lift, loc) ) throw error("Redefining name '" + name + "'", loc); @@ -1037,49 +1044,100 @@ public class Parser { } private Node parseBitwise() { - Node lhs = parseComparison(); + Node lhs = parseEquality(); while( true ) { if( false ) ; else if( matchOp('&') ) lhs = new AndNode(loc(),lhs,null); else if( matchOp('|') ) lhs = new OrNode(loc(),lhs,null); else if( match ("^") ) lhs = new XorNode(loc(),lhs,null); else break; - lhs.setDef(2,parseComparison()); + lhs.setDef(2,parseEquality()); lhs = peep(lhs); } return lhs; } + + + /** + * Parse an eq/ne expression + */ + private Node parseEquality() { + Node lhs = parseComparison(); + while( true ) { + boolean eq = false; + if( match("==") ) eq = true; + else if( !match("!=") ) break; + lhs.keep(); + Node rhs = parseComparison(); + lhs = peep(new BoolNode.EQ(lhs.unkeep(),rhs).widen()); + if( !eq ) lhs = peep(new NotNode(lhs)); + } + return lhs; + } + /** * Parse an expression of the form: * * <pre> - * expr : additiveExpr op additiveExpr + * expr : shiftExpr < shiftExpr <= shiftExpr... + * expr : shiftExpr > shiftExpr >= shiftExpr... * </pre> * @return an comparator expression {@link Node}, never {@code null} */ private Node parseComparison() { - var lhs = parseShift(); + Node lhs = parseShift(); + int dir = 0; + while( true ) { - int idx=0; boolean negate=false; - // Test for any local nodes made, and "keep" lhs during peepholes + int dir0; if( false ) ; - else if( match("==") ) { idx=2; lhs = new BoolNode.EQ(lhs, null); } - else if( match("!=") ) { idx=2; lhs = new BoolNode.EQ(lhs, null); negate=true; } - else if( match("<=") ) { idx=2; lhs = new BoolNode.LE(lhs, null); } - else if( match("<" ) ) { idx=2; lhs = new BoolNode.LT(lhs, null); } - else if( match(">=") ) { idx=1; lhs = new BoolNode.LE(null, lhs); } - else if( match(">" ) ) { idx=1; lhs = new BoolNode.LT(null, lhs); } + else if( match("<=" ) ) dir0 = -1; + else if( match(">=" ) ) dir0 = -2; + else if( match("<" ) ) dir0 = 1; + else if( match(">" ) ) dir0 = 2; else break; - // Peepholes can fire, but lhs is already "hooked", kept alive - lhs.setDef(idx,parseShift()); - lhs = peep(lhs.widen()); - if( negate ) // Extra negate for != - lhs = peep(new NotNode(lhs)); + lhs.keep(); + // Check and record direction + if( dir==0 ) { + dir = Math.abs(dir0); + Node rhs = parseShift(); + lhs = makeCompBool(dir0,lhs.unkeep(),rhs); // Convert to a bool + } else if( dir == Math.abs(dir0) ) { + // e0 < lhs < ??? + Node ifNode = new IfNode(ctrl(), lhs).peephole(); + Node ifT = new CProjNode(ifNode. keep(), 0, "True" ).peephole(); + Node ifF = new CProjNode(ifNode.unkeep(), 1, "False").peephole(); + // False side does nothing + ScopeNode fScope = _scope.dup(); + fScope.ctrl(ifF); + // True side executes next part of range + ctrl(ifT); + _scope.addGuards(ifT,lhs,false); + Node rhs = parseShift(); + _scope.removeGuards(ifT); // TODO: I think should remain true as long as possible + Node next = makeCompBool(dir0, lhs, rhs).keep(); + // Merge result + RegionNode r = ctrl(_scope.mergeScopes(fScope, loc())); + assert next._type.meet(lhs._type).isa( TypeInteger.BOOL ); + lhs = peep(new PhiNode("",TypeInteger.BOOL,r,next.unkeep(),lhs.unkeep())); + r.peephole(); + } else { + throw error("Mixing relational directions in a chained relational test"); + } } return lhs; } + private Node makeCompBool( int dir0, Node lhs, Node rhs ) { + // Convert to a bool + if( Math.abs(dir0)==2 ) // Swap direction + { Node tmp = lhs; lhs = rhs; rhs = tmp; } + lhs = peep(dir0 < 0 ? new BoolNode.LE(lhs,rhs) : new BoolNode.LT(lhs,rhs)); + return peep(lhs.widen()); + } + + /** * Parse an additive expression * @@ -1493,6 +1551,8 @@ public class Parser { Type tf = f._t; if( tf instanceof TypeMemPtr ftmp && ftmp.isFRef() ) tf = ftmp.makeFrom(((TypeMemPtr)(TYPES.get(ftmp._obj._name)))._obj); + if( base.isAry() && tf instanceof TypeConAry con ) + tf = con.elem(); // Field offset; fixed for structs, computed for arrays Node off = (name.equals("[]") // If field is an array body @@ -1662,7 +1722,6 @@ public class Parser { // Into the call CallNode call = (CallNode)new CallNode(loc(), args.asAry()).peephole(); - // Post-call setup CallEndNode cend = (CallEndNode)new CallEndNode(call).peephole(); call.peephole(); // Rerun peeps after CallEnd, allows early inlining diff --git a/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java index 6c958f32..3715d015 100644 --- a/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java +++ b/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java @@ -7,6 +7,7 @@ import com.seaofnodes.simple.print.*; import com.seaofnodes.simple.type.*; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.SB; +import com.seaofnodes.simple.util.Utils; import java.io.IOException; import java.util.*; @@ -30,7 +31,6 @@ public class CodeGen { Export, // Export } public Phase _phase; - // --------------------------- // Compilation source code public final String _src; @@ -124,7 +124,7 @@ public class CodeGen { // are structurally equal. public final HashMap<Node,Node> _gvn = new HashMap<>(); - // + // Source of unique function indices private int _fidx =0; public TypeFunPtr makeFun( TypeFunPtr fun ) { int fidx = _fidx++; @@ -132,23 +132,33 @@ public class CodeGen { return fun.makeFrom(fidx); } // Signature for MAIN - public final TypeFunPtr _main; - // Reverse from a constant function pointer to the IR function being called - public FunNode link( TypeFunPtr tfp ) { - assert tfp.isConstant(); - return _linker.get(tfp.makeFrom(Type.BOTTOM)); + public TypeFunPtr _main; + public void setMain(FunNode main) { + _main = main.sig(); + link(main); + } + // Reverse from a constant function pointer to the IR function being called. + // Error to call with a non-constant TFP + public FunNode link( TypeFunPtr tfp ) { return link(tfp.fidx()); } + // Return the FunNode from a fidx + public FunNode link( int fidx ) { + FunNode fun =_linker.atX(fidx); + if( fun!=null && fun.isDead() ) { + _linker.setX(fidx,null); fun = null; } + return fun; } // Insert linker mapping from constant function signature to the function // being called. public void link(FunNode fun) { - _linker.put(fun.sig().makeFrom(Type.BOTTOM),fun); + int fidx = fun.sig().fidx(); + _linker.setX(fidx,fun); } // "Linker" mapping from constant TypeFunPtrs to heads of function. These // TFPs all have exact single fidxs and their return is wiped to BOTTOM (so // the return is not part of the match). - private final HashMap<TypeFunPtr,FunNode> _linker = new HashMap<>(); + final Ary<FunNode> _linker = new Ary<>(FunNode.class); // Parser object public final Parser P; @@ -185,59 +195,14 @@ public class CodeGen { _phase = Phase.Opto; long t0 = System.currentTimeMillis(); - // Pessimistic peephole optimization on a worklist - _iter.iterate(this); - - // OPTIMISTIC PASS GOES HERE - - // Not really a true optimistic pass, but look for unlinked functions. - // This can be removed, which may trigger another round of pessimistic. - // This is the point where we flip from a virtual Call Graph (any call - // can call any function) to having a correct (but conservative) CG. - int progress = 0; - while( progress != _start.nOuts() ) { - progress = _start.nOuts(); - FunNode main = link(_main); - for( int i=0; i<_start.nOuts(); i++ ) { - Node use = _start.out(i); - if( use instanceof FunNode fun && - fun.nIns()==2 && fun.in(1)==_start && fun != main && - (fun._name==null || fun._name.startsWith("sys.")) ) { - add(fun).setDef(1,Parser.XCTRL); - addAll(fun._outputs); - i--; - } - } - _iter.iterate(this); - } - - // Freeze field sizes; do struct layouts; convert field offsets into - // constants. - for( int i=0; i<_start.nOuts(); i++ ) { - Node use = _start.out(i); - if( use instanceof ConFldOffNode off ) { - TypeMemPtr tmp = (TypeMemPtr) Parser.TYPES.get(off._name); - off.subsume( off.asOffset(tmp._obj) ); - i--; - } - } - _iter.iterate(this); - - // To help with testing, sort StopNode returns by NID - Arrays.sort(_stop._inputs._es,0,_stop.nIns(),(x,y) -> x._nid - y._nid ); + Opto.opto(this); _tOpto = (int)(System.currentTimeMillis() - t0); - - // TODO: - // Optimistic - // TODO: - // loop unroll, peel, RCE, etc return this; } public <N extends Node> N add( N n ) { return _iter.add(n); } public void addAll( Ary<Node> ary ) { _iter.addAll(ary); } - // --------------------------- // Last check for bad programs public int _tTypeCheck; diff --git a/src/main/java/com/seaofnodes/simple/codegen/Encoding.java b/src/main/java/com/seaofnodes/simple/codegen/Encoding.java index 1065cd9f..e3684445 100644 --- a/src/main/java/com/seaofnodes/simple/codegen/Encoding.java +++ b/src/main/java/com/seaofnodes/simple/codegen/Encoding.java @@ -189,12 +189,16 @@ public class Encoding { rpos.put(_code._start.loop(),rpo); BitSet visit = _code.visit(); rpo.add(_code._stop); + FunNode main = _code.link(_code._main); for( Node n : _code._start._outputs ) - if( n instanceof FunNode fun ) { + if( n instanceof FunNode fun && fun != main ) { int x = rpo._len; _rpo_cfg(fun, visit, rpos ); assert rpo.at(x) instanceof ReturnNode; } + // Do any main function last... so it lands at offset 0 in the RPO + if( main!=null ) + _rpo_cfg(main, visit, rpos ); rpo.add(_code._start); // Reverse in-place diff --git a/src/main/java/com/seaofnodes/simple/codegen/Opto.java b/src/main/java/com/seaofnodes/simple/codegen/Opto.java new file mode 100644 index 00000000..f8ce1e54 --- /dev/null +++ b/src/main/java/com/seaofnodes/simple/codegen/Opto.java @@ -0,0 +1,264 @@ +package com.seaofnodes.simple.codegen; + +import com.seaofnodes.simple.Parser; +import com.seaofnodes.simple.node.*; +import com.seaofnodes.simple.type.*; +import com.seaofnodes.simple.util.Ary; +import java.util.Arrays; + +// Optimistic Algorithm +abstract public class Opto { + + // Optimistic analysis - extended SCCP + + // Start all Types at TOP, and propagate changes until stable. Unlike a + // normal Sparse Conditional Constant Propagation, this version is + // interprocedural, computing effectively CFA0 in linear time using the + // normal SCCP algorithm. + + // This algo also builds a Call Graph; as Calls become reachable (CONTROL + // not TOP nor XCONTROL), they "link" against the reaching function + // pointers - adding edges from the Call to the Fun, and from the Return to + // the CallEnd. This allows the normal algorithm to use the normal edge + // propagation rules as function argument types stabilize. In the end, we + // get a fairly precise set of Call Graph edges between CallNodes and + // FunNodes. + public static void opto(CodeGen code) { + + // Pessimistic peephole optimization on a worklist - this completes + // whatever peepholes can run after parsing. + code._iter.iterate(code); + + // Reset Types before running the worklist algorithm + Ary<Type> oldTypes = new Ary<>(Type.class); // Used for asserts only + resetToTop(code,oldTypes); + + // The whole-world assumption: we use it if compiling `main`, and not otherwise. + // The assumption is no unknown callers into functions: + // - during or past an Opto phase (but not before, since parse through + // pessimistic must assume somebody calls an unknown function which + // calls everybody). + // - Have a `main` to start tracing the Call Graph from + // - - True for most test cases + // - - False for lacking a main; we assume the linker will call all public functions + + // True if we can make the "whole world" assumption, which means we are + // compiling the program entry: `main`. + boolean wholeWorld = code.link(code._main) != null; + + + // If wholeWorld, remove the Start inputs to functions - they are not + // called unless they get linked (hence go dead and can be removed). + // If not wholeWorld, keep only public methods (and not the std lib). + unlinkStart(wholeWorld,code); + + + // OPTIMISTIC INTERPROCEDURAL SCCP + sccp(code, oldTypes); + + // After SCCP add everything changed to the worklist and see if + // peepholes can make more progress. + moveChangesToWorklist(code, oldTypes); + + // Progress with improved types. E.g. since we have a full Call Graph + // here, we might do better inlining. + code._iter.iterate(code); + + // TODO: + // loop unroll, peel, RCE, etc + + // Freeze field sizes; do struct layouts; convert field offsets into + // constants. + fieldSizes(code); + // Propagate field size constants + code._iter.iterate(code); + + // Throw away the Call Graph + + // The remaining passes assume all calls are unlinked; i.e. we are + // throwing away the Call Graph here. Functions only reachable from + // internal calls need to be re-hooked to stop/start less they go dead. + removeCallGraph(code); + + // To help with testing, sort StopNode Returns by NID + Arrays.sort(code._stop._inputs._es,0,code._stop.nIns(),(x,y) -> x._nid - y._nid ); + } + + // Reset Types before running the worklist algorithm + private static void resetToTop(CodeGen code, Ary<Type> oldTypes ) { + code._start.walk( x -> { + oldTypes.setX(x._nid,x._type); // Record original types for asserts + x._type = Type.TOP; // Reset all Nodes to TOP + code._iter.add(x); // Visit everybody at least once; most Nodes produce better than TOP + // Unlink all existing (conservative) linkages. + if( x instanceof CallNode call ) + call.unlink_all(); + return null; + } ); + } + + + // If wholeWorld, remove the Start inputs to functions - they are not + // called unless they get linked (hence go dead and can be removed). If + // not wholeWorld, keep only public methods (and not the std lib). + private static void unlinkStart(boolean wholeWorld, CodeGen code) { + for( FunNode fun : code._linker ) { + if( fun != null && !fun.isDead() && !funIsPublic(code,wholeWorld,fun) ) { + assert fun.in(1)==code._start; // Start always in slot 1 + fun.removeDeadPath(1); + // By same logic, remove stop->return linkage, without + // remove the (now dead) ReturnNode; it awaits in limbo + // for the opto phase to link to some valid call + code._stop._inputs.del(code._stop._inputs.find(fun.ret())); + fun.ret().delUse(code._stop); + } + } + } + + // Function is public (callable from Start directly). + // - Always true for main + // - Never true for stdlib, or anonymous functions + // - Named functions use `!wholeWorld` + private static boolean funIsPublic( CodeGen code, boolean wholeWorld, FunNode fun ) { + // Always true for main + if( fun.sig().fidx() == code._main.fidx() ) return true; + // Never true for stdlib or anonymous functions + if( fun._name == null || fun._name.startsWith("sys.") ) + return false; + // Named functions (and not stdlib) are callable if not whole-world. + return !wholeWorld; + } + + // As part of building a CallGraph, when opto finds a function ptr flowing + // into a Call, link the Call and Fun. + private static void linkCG(CodeGen code, TypeFunPtr tfp, CallNode call) { + if( tfp.nargs() != call.nargs() ) return; // Error calls hit this + for( long fidxs=tfp.fidxs(); fidxs!=0; fidxs=TypeFunPtr.nextFIDX(fidxs) ) { + int fidx = Long.numberOfTrailingZeros(fidxs); + FunNode fun = code.link(fidx); + // null here means an external function; i.e. this Call + // calls to an outside library and all its arguments escape. + if( fun != null && !call.linked(fun) ) { + call.link( fun ); + code._iter.add(fun); + code._iter.addAll(fun._outputs); + } + } + } + + // The core SCCP algorithm + private static void sccp( CodeGen code, Ary<Type> oldTypes ) { + // Iter workList is empty at this point + // OPTIMISTIC PASS + Node n; + int count = 0; // Debug counter + while( (n = code._iter._work.pop()) != null ) { + if( n.isDead() ) continue; + count++; + Type oval = n._type, nval = n.compute(); + if( oval == nval ) continue; + assert oval.isa(nval); // Types start high and always fall + Type pesiVal = oldTypes.at(n._nid); + assert nval.isa(pesiVal); // Never fall worse than the pessimistic pass + n._type = nval; + + // If a TFP adds a new function input to a call, link to the new Fun + if( nval instanceof TypeFunPtr tfp ) { + for( Node use : n._outputs ) + if( !use._type.isHigh() && use instanceof CallNode call && call.fptr() == n ) + linkCG(code,tfp,call); + } + + // Link a Call which becomes alive + if( n instanceof CallNode call && oval.isHigh() && !nval.isHigh() && call.fptr()._type instanceof TypeFunPtr ) + linkCG(code,call.tfp(),call); + + // Since n._type changed, visit all output neighbors + code._iter.addAll(n._outputs); + n.moveDepsToWorklist(code._iter); + // Quadratic (expensive) small-step assert + assert check(code); + } + } + + // Quadratic (expensive) small-step assert + private static boolean check(CodeGen code) { + code._start.walk( x -> { + Type xval = x.compute(); + assert xval == x._type || (x._type.isa( xval ) && code._iter._work.on( x )); + return null; + }); + return true; + } + + // After SCCP add everything changed to the worklist and see if peepholes + // can make more progress. + private static void moveChangesToWorklist(CodeGen code, Ary<Type> oldTypes) { + code._start.walk( x -> { + assert x.compute() == x._type; // Hit the fixed point + assert x._nid >= oldTypes._len || x._type.isa(oldTypes.at(x._nid)); // Hit at least the bottom-up type + code._iter.add(x); + return null; + }); + } + + // Freeze field sizes; do struct layouts; convert field offsets into + // constants. + private static void fieldSizes( CodeGen code ) { + for( int i=0; i<code._start.nOuts(); i++ ) { + Node use = code._start.out(i); + if( use instanceof ConFldOffNode off ) { + TypeMemPtr tmp = (TypeMemPtr) Parser.TYPES.get(off._name); + off.subsume( off.asOffset(tmp._obj) ); + i--; + } + } + } + + // The remaining passes assume all calls are unlinked; i.e. we are throwing + // away the Call Graph here. Functions only reachable from internal calls + // need to be re-hooked to stop/start less they go dead. + private static void removeCallGraph(CodeGen code) { + code._start.walk( x -> { + // Unlink all existing (conservative) linkages. + if( x instanceof CallNode call ) { + for( Node y : call._outputs ) { + // Keep function alive and hooked to Start so it gets + // codegen'd. Function is callable by this call via + // TFP, although perhaps not by any other means. + if( y instanceof FunNode fun && !(fun.in(1) instanceof StartNode) ) { + ParmNode rpc = fun.rpc(); + if( rpc==null ) // Ensure valid RPC + rpc = makeRPC(fun); + // Insert a hook to Start and Stop + fun.insertDef(1,code._start); + for( Node use : fun._outputs ) + if( use instanceof ParmNode parm ) + parm.insertDef(1,ConstantNode.make(parm._type).peephole()); + code._stop.addDef(fun.ret()); + } + } + call.unlink_all(); + } + return null; + } ); + + } + + // Make a valid Parm RPC. + // First make sure a valid RPC; single-call into multi-fun will have each + // function having a single call site, so the RPC becomes a constant and + // folds - but since multiple targets, the Call never inlines. Recreate a + // valid RPC so codegen (and Eval2) understands the calling convention. + private static ParmNode makeRPC( FunNode fun ) { + ParmNode rpc = new ParmNode("$rpc",0,fun.ret().rpc()._type,fun); + for( int i=1; i<fun.nIns(); i++ ) { + CallEndNode cend = ((CallNode)fun.in(i)).cend(); + rpc.addDef(ConstantNode.make(cend._rpc).peephole()); + } + fun.ret().setDef(3,rpc.init()); + return rpc; + } + + +} diff --git a/src/main/java/com/seaofnodes/simple/node/AddFNode.java b/src/main/java/com/seaofnodes/simple/node/AddFNode.java index 792da62e..4ad02dbb 100644 --- a/src/main/java/com/seaofnodes/simple/node/AddFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/AddFNode.java @@ -5,38 +5,25 @@ import com.seaofnodes.simple.type.TypeFloat; import java.util.BitSet; -public class AddFNode extends Node { - public AddFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class AddFNode extends ArithFNode { + public AddFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "AddF"; } @Override public String glabel() { return "+"; } - @Override - public StringBuilder _print1(StringBuilder sb, BitSet visited) { - in(1)._print0(sb.append("("), visited); - in(2)._print0(sb.append("+"), visited); - return sb.append(")"); - } - - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()+i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x+y; } @Override public Node idealize() { - Node lhs = in(1); - Type t2 = in(2)._type; - // Add of 0. + Type t2 = in(2)._type; if ( t2.isConstant() && t2 instanceof TypeFloat i && i.value()==0 ) - return lhs; + return in(1); + + // Move constants to RHS: con+arg becomes arg+con + if ( in(1)._type.isConstant() && !t2.isConstant() ) + return swap12(); return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/AddNode.java b/src/main/java/com/seaofnodes/simple/node/AddNode.java index c5ba14de..c7fd4daa 100644 --- a/src/main/java/com/seaofnodes/simple/node/AddNode.java +++ b/src/main/java/com/seaofnodes/simple/node/AddNode.java @@ -139,7 +139,7 @@ public class AddNode extends ArithNode { * dep can make progress. */ static PhiNode pcon(Node op, Node dep) { - return op instanceof PhiNode phi && phi.allCons(dep) ? phi : null; + return op instanceof PhiNode phi && !(phi instanceof ParmNode) && phi.allCons(dep) ? phi : null; } // Compare two off-spine nodes and decide what order they should be in. diff --git a/src/main/java/com/seaofnodes/simple/node/ArithFNode.java b/src/main/java/com/seaofnodes/simple/node/ArithFNode.java new file mode 100644 index 00000000..7fa428c6 --- /dev/null +++ b/src/main/java/com/seaofnodes/simple/node/ArithFNode.java @@ -0,0 +1,32 @@ +package com.seaofnodes.simple.node; + +import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeFloat; +import java.util.BitSet; + +public abstract class ArithFNode extends Node { + public ArithFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } + + @Override + public StringBuilder _print1(StringBuilder sb, BitSet visited) { + in(1)._print0(sb.append("("), visited); + in(2)._print0(sb.append(glabel()), visited); + return sb.append(")"); + } + + abstract double doOp(double x, double y); + + @Override + public Type compute() { + Type t1 = in(1)._type, t2 = in(2)._type; + if( t1.isHigh() || t2.isHigh() ) + return TypeFloat.TOP; + if( t1 instanceof TypeFloat f1 && + t2 instanceof TypeFloat f2 ) { + if( f1.isConstant() && f2.isConstant() ) + return TypeFloat.constant(doOp(f1.value(),f2.value())); + } + return t1.meet(t2); + } + +} diff --git a/src/main/java/com/seaofnodes/simple/node/ArithNode.java b/src/main/java/com/seaofnodes/simple/node/ArithNode.java index 96067c8e..f2beaacb 100644 --- a/src/main/java/com/seaofnodes/simple/node/ArithNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ArithNode.java @@ -35,7 +35,7 @@ public abstract class ArithNode extends Node { t2 instanceof TypeInteger y ) return x.isConstant() && y.isConstant() ? con(x,y) - : doOp(x,y); + : doOp(x,y).makeWide( (byte)Math.max(x._widen,y._widen) ); return TypeInteger.BOT; } @@ -56,7 +56,7 @@ public abstract class ArithNode extends Node { if( in(1) instanceof PhiNode lhs && in(2) instanceof PhiNode rhs && lhs.nIns() >= 2 && !lhs.inProgress() && - lhs.region()==rhs.region() && + lhs.region()==rhs.region() && !(lhs.region() instanceof FunNode) && lhs.nIns()>2 && // A 1-input Phi will collapse already // Disallow with self-looping phi; these will collapse (lhs.in(2)!=lhs && rhs.in(2)!=rhs) ) { diff --git a/src/main/java/com/seaofnodes/simple/node/CProjNode.java b/src/main/java/com/seaofnodes/simple/node/CProjNode.java index a6e21ea0..d18f779b 100644 --- a/src/main/java/com/seaofnodes/simple/node/CProjNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CProjNode.java @@ -33,7 +33,7 @@ public class CProjNode extends CFGNode { @Override public Type compute() { Type t = ctrl()._type; - return t instanceof TypeTuple tt ? tt._types[_idx] : Type.BOTTOM; + return t instanceof TypeTuple tt ? tt._types[_idx] : (t.isHigh() ? Type.TOP : Type.BOTTOM); } @Override diff --git a/src/main/java/com/seaofnodes/simple/node/CallEndNode.java b/src/main/java/com/seaofnodes/simple/node/CallEndNode.java index d95af697..a7e50c39 100644 --- a/src/main/java/com/seaofnodes/simple/node/CallEndNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CallEndNode.java @@ -39,16 +39,23 @@ public class CallEndNode extends CFGNode implements MultiNode { @Override public Type compute() { - if( !(in(0) instanceof CallNode call) ) + if( !(in(0) instanceof CallNode call) || call._type != Type.CONTROL ) return TypeTuple.RET.dual(); - Type ret = Type.BOTTOM; - if( addDep(call.fptr())._type instanceof TypeFunPtr tfp ) { + // Mid-fold, just take the one single callers' return type + if( _folding ) return in(1)._type; + // Grab the TFP and use the functions declared return type. + Type ftype = addDep(call.fptr())._type; + Type ret = ftype.isHigh() ? Type.TOP : Type.BOTTOM; + if( ftype instanceof TypeFunPtr tfp ) { ret = tfp.ret(); // Here, if I can figure out I've found *all* callers, then I can meet // across the linked returns and join with the function return type. - if( tfp.isConstant() && nIns()>1 ) { - assert nIns()==2; // Linked exactly once for a constant - ret = ((TypeTuple)in(1)._type).ret(); // Return type + if( 1+tfp.nfcns() == nIns() ) { // A linked function for every concrete function + ret = Type.TOP; + for( int i=1; i<nIns(); i++ ) { + Type tret = in(i)._type instanceof TypeTuple rtt ? rtt.ret() : in(i)._type; + ret = ret.meet(tret); + } } } return TypeTuple.make(call._type,TypeMem.BOT,ret); @@ -72,12 +79,17 @@ public class CallEndNode extends CFGNode implements MultiNode { // Expecting Start, and the Call if( fun.nIns()==3 ) { assert fun.in(1) instanceof StartNode && fun.in(2)==call; - // Disallow self-recursive inlining (loop unrolling by another name) + // Disallow self-recursive inlining (loop unrolling by another name). + // Disallow if still folding other things, as it makes other + // dependency checks carry long chains of half-folded calls. CFGNode idom = call; - while( !(idom instanceof FunNode) && idom!=null ) + while( true ) { idom = idom.idom(); + if( idom instanceof FunNode ) break; + if( idom instanceof CallEndNode cend && cend._folding ) break; + } // Inline? - if( idom != fun && idom != null ) { + if( idom instanceof FunNode fun2 && fun2 != fun && !fun2._folding ) { // Trivial inline: rewrite _folding = true; // Rewrite Fun so the normal RegionNode ideal collapses @@ -95,6 +107,8 @@ public class CallEndNode extends CFGNode implements MultiNode { // Bump the global version number invalidating them en-masse. CodeGen.CODE.invalidateIDepthCaches(); return this; + } else { + addDep(idom); } } else { addDep(fun); diff --git a/src/main/java/com/seaofnodes/simple/node/CallNode.java b/src/main/java/com/seaofnodes/simple/node/CallNode.java index ba08c87a..47dfdf19 100644 --- a/src/main/java/com/seaofnodes/simple/node/CallNode.java +++ b/src/main/java/com/seaofnodes/simple/node/CallNode.java @@ -115,16 +115,15 @@ public class CallNode extends CFGNode { } // True if Fun is linked to this Call - boolean linked( FunNode fun ) { + public boolean linked( FunNode fun ) { for( Node n : fun._inputs ) if( n == this ) return true; return false; } - // Link so this calls fun - private Node link( FunNode fun ) { + public Node link( FunNode fun ) { assert !linked(fun); fun.addDef(this); for( Node use : fun._outputs ) diff --git a/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java b/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java index 3e1d3c69..c54da2c4 100644 --- a/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ConFldOffNode.java @@ -14,8 +14,8 @@ import java.util.BitSet; */ public class ConFldOffNode extends ConstantNode { - public final String _name; // Struct name - public final String _fname; // Field name + public final String _name; // Struct name + public final String _fname; // Field name public ConFldOffNode( String name, String fname ) { super(TypeInteger.BOT); _name = name; _fname = fname; } @Override public String label() { @@ -37,7 +37,7 @@ public class ConFldOffNode extends ConstantNode { @Override public boolean eq(Node n) { ConFldOffNode off = (ConFldOffNode)n; // Invariant - return _name==off._name && _fname==off._fname && super.eq(n); + return _name.equals(off._name) && _fname.equals(off._fname) && super.eq(n); } @Override int hash() { return super.hash() * _name.hashCode() * _fname.hashCode(); } } diff --git a/src/main/java/com/seaofnodes/simple/node/DivFNode.java b/src/main/java/com/seaofnodes/simple/node/DivFNode.java index 633f3224..0d037a30 100644 --- a/src/main/java/com/seaofnodes/simple/node/DivFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/DivFNode.java @@ -5,29 +5,14 @@ import com.seaofnodes.simple.type.TypeFloat; import java.util.BitSet; -public class DivFNode extends Node { - public DivFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class DivFNode extends ArithFNode { + public DivFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "DivF"; } @Override public String glabel() { return "/"; } - @Override - public StringBuilder _print1(StringBuilder sb, BitSet visited) { - in(1)._print0(sb.append("("), visited); - in(2)._print0(sb.append("/"), visited); - return sb.append(")"); - } - - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()/i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x/y; } @Override public Node idealize() { diff --git a/src/main/java/com/seaofnodes/simple/node/FunNode.java b/src/main/java/com/seaofnodes/simple/node/FunNode.java index 4bd0fd97..2931b9ea 100644 --- a/src/main/java/com/seaofnodes/simple/node/FunNode.java +++ b/src/main/java/com/seaofnodes/simple/node/FunNode.java @@ -80,14 +80,22 @@ public class FunNode extends RegionNode { // Only dead if no callers after SCCP if( unknownCallers() ) return Type.CONTROL; - return super.compute(); + Type t = Type.XCONTROL; + for (int i = 1; i < nIns(); i++) { + // Since no unknown callers, we are not main and the Start input + // will be a Tuple with XControl, so ignore it. Need to be called + // from someplace other than Start + if( !(in(i) instanceof StartNode) ) + t = t.meet(in(i)._type); + } + return t; } @Override public Node idealize() { - // Some linked path dies - Node progress = deadPath(); + // Some linked path dies, except main never kills Start + Node progress = deadPath(unknownCallers()); if( progress!=null ) { if( nIns()==3 && in(2) instanceof CallNode call ) CODE.add(call.cend()); // If Start and one call, check for inline @@ -95,8 +103,11 @@ public class FunNode extends RegionNode { } // Upgrade inferred or user-written return type to actual - if( _ret!=null && _ret._type instanceof TypeTuple tt && tt.ret() != _sig.ret() ) - throw Utils.TODO(); + if( _ret!=null && _ret._type instanceof TypeTuple tt && tt.ret() != _sig.ret() ) { + setSig(_sig.makeFrom(tt.ret())); + return this; + } + // When can we assume no callers? Or no other callers (except main)? // In a partial compilation, we assume Start gets access to any/all @@ -110,8 +121,10 @@ public class FunNode extends RegionNode { // to collapse if( unknownCallers() ) return null; - // If down to a single input, become that input - if( nIns()==2 && !hasPhi() ) { + // If folding (already inlined) down to a single input, become that input. + // Cannot collapse if not-inlining, and might not inline if call site + // calls multiple targets. + if( _folding && nIns()==2 && !hasPhi() ) { CODE.add( CODE._stop ); // Stop will remove dead path CODE.add( _ret ); // Return will compute to TOP control return in(1); // Collapse if no Phis; 1-input Phis will collapse on their own @@ -176,6 +189,14 @@ public class FunNode extends RegionNode { return in; } + // FunNodes must match signature (equivalent: no 2 FunNodes are ever GVN'able) + @Override public boolean eq( Node n ) { + return _sig == ((FunNode)n)._sig; + } + + @Override public int hash() { + return _sig.hashCode(); + } // ------------ // MachNode specifics, shared across all CPUs diff --git a/src/main/java/com/seaofnodes/simple/node/IfNode.java b/src/main/java/com/seaofnodes/simple/node/IfNode.java index c5d687e5..5d751602 100644 --- a/src/main/java/com/seaofnodes/simple/node/IfNode.java +++ b/src/main/java/com/seaofnodes/simple/node/IfNode.java @@ -33,6 +33,7 @@ public class IfNode extends CFGNode implements MultiNode { @Override public Type compute() { // If the If node is not reachable then neither is any following Proj + assert !_inputs.isEmpty(); if (ctrl()._type != Type.CONTROL && ctrl()._type != Type.BOTTOM ) return TypeTuple.IF_NEITHER; Node pred = pred(); @@ -57,11 +58,15 @@ public class IfNode extends CFGNode implements MultiNode { // Hunt up the immediate dominator tree. If we find an identical if // test on either the true or false branch, that side wins. if( !pred()._type.isHighOrConst() ) - for( CFGNode dom = idom(), prior=this; dom!=null; prior = dom, dom = dom.idom() ) + for( CFGNode dom = idom(), prior=this; dom!=null; prior = dom, dom = dom.idom() ) { if( addDep(dom) instanceof IfNode iff && addDep(iff.pred())==pred() && prior instanceof CProjNode prj ) { setDef(1,con( prj._idx==0 ? 1 : 0 )); return this; } + if( dom instanceof RegionNode r ) + for( Node c : r._inputs ) + if( c!= null ) addDep(c); // If region loses input, idom changes + } return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/LoadNode.java b/src/main/java/com/seaofnodes/simple/node/LoadNode.java index b58ea498..58dbfc81 100644 --- a/src/main/java/com/seaofnodes/simple/node/LoadNode.java +++ b/src/main/java/com/seaofnodes/simple/node/LoadNode.java @@ -34,20 +34,32 @@ public class LoadNode extends MemOpNode { @Override public Type compute() { - if( !(mem()._type instanceof TypeMem mem) ) - return _declaredType; // No memory yet? Declared type + Type tmem = mem()._type; + if( !(tmem instanceof TypeMem mem) ) + return tmem; // No memory yet? Assume TOP/BOT assert !_declaredType.isFRef(); // No lifting if ptr might null-check - if( err()!=null || !(ptr()._type instanceof TypeMemPtr tmp) ) - return _declaredType; // No pointer yet? Declared type - Type t = tmp._obj.field(_name)._t; - if( t instanceof TypeConAry ary ) { + Type tptr = ptr()._type; + if( err() != null ) + return _declaredType; + if( !(tptr instanceof TypeMemPtr tmp) ) + return tptr; // No pointer yet? Assume TOP/BOT + // Load field from object + Field f = tmp._obj.field(_name); + // No field? Open objects might yet get the field when falling; + // closed objects with missing field are an error. + if( f == null ) + return tmp.isHigh() ? Type.TOP : _declaredType; + Type t = f._t; + // Load member of constant array + if( t instanceof TypeConAry ary ) t = ary.elem(); // TODO: if offset is known, can peek the constant - } // Lift from declared type and memory input - t = t.join(_declaredType).join(mem._t); + t = t.join(mem._t); if( _declaredType.isFinal() ) t = t.makeRO(); // Deep final applied + // Pinch between declared type + t = t.join(_declaredType); return t; } diff --git a/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java b/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java index 19acc5b9..9ab57714 100644 --- a/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MemMergeNode.java @@ -60,7 +60,12 @@ public class MemMergeNode extends Node { } - @Override public Type compute() { return TypeMem.BOT; } + @Override public Type compute() { + for( Node n : _inputs ) + if( n != null && !n._type.isHigh() ) + return TypeMem.BOT; + return TypeMem.TOP; + } @Override public Node idealize() { if( inProgress() ) return null; diff --git a/src/main/java/com/seaofnodes/simple/node/MinusFNode.java b/src/main/java/com/seaofnodes/simple/node/MinusFNode.java index 99fc3144..5bb0889f 100644 --- a/src/main/java/com/seaofnodes/simple/node/MinusFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MinusFNode.java @@ -20,7 +20,8 @@ public class MinusFNode extends Node { @Override public Type compute() { - if (in(1)._type instanceof TypeFloat i0) + if( in(1)._type.isHigh() ) return TypeFloat.TOP; + if( in(1)._type instanceof TypeFloat i0) return i0.isConstant() ? TypeFloat.constant(-i0.value()) : i0; return TypeFloat.F64; } diff --git a/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/src/main/java/com/seaofnodes/simple/node/MinusNode.java index f26ce37e..3ab74625 100644 --- a/src/main/java/com/seaofnodes/simple/node/MinusNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MinusNode.java @@ -23,7 +23,7 @@ public class MinusNode extends Node { if( in(1)._type.isHigh() ) return TypeInteger.TOP; if( in(1)._type instanceof TypeInteger i0 && i0._min != Long.MIN_VALUE && i0._max != Long.MIN_VALUE ) - return TypeInteger.make(-i0._max,-i0._min); + return TypeInteger.make(-i0._max,-i0._min,i0._widen); return TypeInteger.BOT; } diff --git a/src/main/java/com/seaofnodes/simple/node/MulFNode.java b/src/main/java/com/seaofnodes/simple/node/MulFNode.java index 6fbf4bbb..5c04af43 100644 --- a/src/main/java/com/seaofnodes/simple/node/MulFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/MulFNode.java @@ -5,29 +5,14 @@ import com.seaofnodes.simple.type.TypeFloat; import java.util.BitSet; -public class MulFNode extends Node { - public MulFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class MulFNode extends ArithFNode { + public MulFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "MulF"; } @Override public String glabel() { return "*"; } - @Override - public StringBuilder _print1(StringBuilder sb, BitSet visited) { - in(1)._print0(sb.append("("), visited); - in(2)._print0(sb.append("*"), visited); - return sb.append(")"); - } - - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()*i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x*y; } @Override public Node idealize() { diff --git a/src/main/java/com/seaofnodes/simple/node/NewNode.java b/src/main/java/com/seaofnodes/simple/node/NewNode.java index 1785af4e..9310aa38 100644 --- a/src/main/java/com/seaofnodes/simple/node/NewNode.java +++ b/src/main/java/com/seaofnodes/simple/node/NewNode.java @@ -3,6 +3,7 @@ package com.seaofnodes.simple.node; import com.seaofnodes.simple.codegen.*; import com.seaofnodes.simple.type.*; import com.seaofnodes.simple.util.SB; +import com.seaofnodes.simple.util.Utils; import java.util.BitSet; @@ -61,19 +62,27 @@ public class NewNode extends Node implements MultiNode { public TypeTuple compute() { Field[] fs = _ptr._obj._fields; Type[] ts = new Type[fs.length+2]; - ts[0] = Type.CONTROL; - ts[1] = _ptr; - for( int i=0; i<fs.length; i++ ) { - if( _ptr._obj._fields[i]._one ) { - // Once-only fields use the declared type - ts[i+2] = _ptr._obj._fields[i]._t; - } else { - // Others take from the inputs - Type mt = in(i+2)._type; - TypeMem mem = mt==Type.TOP ? TypeMem.TOP : (TypeMem)mt; - Type tfld = mem._t.meet(mem._t.makeZero()); - Type tfld2 = tfld.join(fs[i]._t ); - ts[i+2] = TypeMem.make(fs[i]._alias,tfld2); + if( in(0)._type.isHigh() ) { + ts[0] = Type.XCONTROL; + ts[1] = _ptr.makeHigh(); + for( int i=0; i<fs.length; i++ ) + ts[i+2] = Type.TOP; + } else { + ts[0] = Type.CONTROL; + ts[1] = _ptr; + for( int i=0; i<fs.length; i++ ) { + if( _ptr._obj._fields[i]._one ) { + // Once-only fields use the declared type + ts[i+2] = _ptr._obj._fields[i]._t; + } else { + // Others take from the inputs + Type mt = in(i+2)._type; + TypeMem mem = mt==Type.TOP ? TypeMem.TOP : (TypeMem)mt; + //Type tfld = mem._t.meet(mem._t.makeZero()); + Type tfld = mem._t; + Type tfld2 = tfld.join(fs[i]._t ); + ts[i+2] = TypeMem.make(fs[i]._alias,tfld2); + } } } return TypeTuple.make(ts); diff --git a/src/main/java/com/seaofnodes/simple/node/Node.java b/src/main/java/com/seaofnodes/simple/node/Node.java index 8981ab0d..458a3407 100644 --- a/src/main/java/com/seaofnodes/simple/node/Node.java +++ b/src/main/java/com/seaofnodes/simple/node/Node.java @@ -1,5 +1,6 @@ package com.seaofnodes.simple.node; +import com.seaofnodes.simple.IterPeeps; import com.seaofnodes.simple.Parser; import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.Utils; @@ -204,9 +205,9 @@ public abstract class Node implements Cloneable { } // Insert the numbered input, sliding other inputs to the right - Node insertDef(int idx, Node new_def) { - _inputs.add(idx,null); - return setDef(idx,new_def); + public void insertDef(int idx, Node new_def) { + _inputs.insert(null,idx); + setDef(idx,new_def); } @@ -233,7 +234,7 @@ public abstract class Node implements Cloneable { // Remove node 'use' from 'def's (i.e. our) output list, by compressing the list in-place. // Return true if the output list is empty afterward. // Error is 'use' does not exist; ok for 'use' to be null. - protected boolean delUse( Node use ) { + public boolean delUse( Node use ) { _outputs.del(_outputs.find(use)); return _outputs.isEmpty(); } @@ -482,7 +483,7 @@ public abstract class Node implements Cloneable { // If changing, add users to worklist. public Type setType(Type type) { Type old = _type; - assert old==null || type.isa(old); // Since _type not set, can just re-run this in assert in the debugger + assert old == null || type.isa(old) : "Monotonicity test failed"; if( old == type ) return old; _type = type; // Set _type late for easier assert debugging CODE.addAll(_outputs); @@ -549,7 +550,7 @@ public abstract class Node implements Cloneable { Ary<Node> _deps; /** - * Add a node to the list of dependencies. Only add it if its not an input + * Add a node to the list of dependencies. Only add it if it's not an input * or output of this node, that is, it is at least one step away. The node * being added must benefit from this node being peepholed. */ @@ -566,13 +567,13 @@ public abstract class Node implements Cloneable { } // Move the dependents onto a worklist, and clear for future dependents. - public void moveDepsToWorklist( ) { - if( _deps==null ) return; - CODE.addAll(_deps); + public void moveDepsToWorklist( ) { moveDepsToWorklist(CODE._iter); } + public void moveDepsToWorklist( IterPeeps iter ) { + if( _deps == null ) return; + iter.addAll(_deps); _deps.clear(); } - // Two nodes are equal if they have the same inputs and the same "opcode" // which means the same Java class, plus same internal parts. @Override public final boolean equals( Object o ) { diff --git a/src/main/java/com/seaofnodes/simple/node/ParmNode.java b/src/main/java/com/seaofnodes/simple/node/ParmNode.java index a14a4fb9..880f936c 100644 --- a/src/main/java/com/seaofnodes/simple/node/ParmNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ParmNode.java @@ -1,6 +1,8 @@ package com.seaofnodes.simple.node; +import com.seaofnodes.simple.Parser; import com.seaofnodes.simple.type.Type; +import com.seaofnodes.simple.type.TypeMemPtr; import java.util.BitSet; public class ParmNode extends PhiNode { @@ -39,6 +41,25 @@ public class ParmNode extends PhiNode { // Always in-progress until we run out of unknown callers @Override public boolean inProgress() { return in(0) instanceof FunNode fun && fun.inProgress(); } + @Override + public Node idealize() { + if( !(region() instanceof FunNode) ) + return in(1); // Input has collapse to e.g. starting control. + // If function is folding, do all possible peeps + if( fun()._folding ) return super.idealize(); + + // Can upgrade minType even while in-progress + if( _minType instanceof TypeMemPtr tmp && _minType.isFRef() ) { + TypeMemPtr tmp2 = (TypeMemPtr) Parser.TYPES.get(tmp._obj._name); + if( tmp2!=null && tmp2 != _minType ) { + _minType = tmp2; + return this; + } + } + // Skip most phi optimizations on parms + return null; + } + @Override public boolean eq( Node n ) { return ((ParmNode)n)._idx==_idx && super.eq(n); } diff --git a/src/main/java/com/seaofnodes/simple/node/PhiNode.java b/src/main/java/com/seaofnodes/simple/node/PhiNode.java index fcbacbc9..bdc0d0fa 100644 --- a/src/main/java/com/seaofnodes/simple/node/PhiNode.java +++ b/src/main/java/com/seaofnodes/simple/node/PhiNode.java @@ -14,6 +14,8 @@ public class PhiNode extends Node { // Int stays Int, Ptr stays Ptr, Control stays Control, Mem stays Mem. Type _minType; + int lattice_drop; + public PhiNode(String label, Type minType, Node... inputs) { super(inputs); _label = label; @@ -55,26 +57,43 @@ public class PhiNode extends Node { public CFGNode region() { return (CFGNode)in(0); } @Override public boolean isMem() { return _minType instanceof TypeMem; } @Override public boolean isPinned() { return true; } + boolean isRPC() { return false; } @Override public Type compute() { if( !(region() instanceof RegionNode r) ) - return region()._type==Type.XCONTROL ? (_type instanceof TypeMem ? TypeMem.TOP : Type.TOP) : _type; + return region()._type==Type.XCONTROL || region()._type==Type.TOP ? (_type instanceof TypeMem ? TypeMem.TOP : Type.TOP) : _type; // During parsing Phis have to be computed type pessimistically. - if( r.inProgress() ) return _minType; + if( r.inProgress() ) + // Loop-Phis must lift to the declared type, because that is how + // the Parser keeps precise types until the loop finishes parsing. + // Similar, ParmNodes use precise minType until all calls are + // linked (post opto). + return r instanceof LoopNode || (this instanceof ParmNode) ? _minType : Type.BOTTOM; // Set type to local top of the starting type - //Type t = _minType.dual(); Type t = Type.TOP; - for (int i = 1; i < nIns(); i++) + for (int i = 1; i < nIns(); i++) { // If the region's control input is live, add this as a dependency // to the control because we can be peeped should it become dead. - if( addDep(r.in(i))._type != Type.XCONTROL ) { + Type ctrl = addDep(r.in(i))._type; + if( ctrl != Type.XCONTROL && ctrl != Type.TOP ) { if( in(i)._type==Type.BOTTOM ) return Type.BOTTOM; t = t.meet(in(i)._type); } - t = t.join( _minType ); - return t; + } + Type newt = t.join( _minType ); + + // phi loop widening part + if( region() instanceof LoopNode && // Only around loops + newt instanceof TypeInteger newi && + // Types changed and are falling (the optimistic case, expected to fall forever) + newi != _type ) { + if( !newi.isConstant() && (!(_type instanceof TypeInteger oldi) || newi._widen <= oldi._widen) ) + return newi.same_but_slightly_wider_than(_minType); + } + + return newt; } @Override @@ -83,7 +102,7 @@ public class PhiNode extends Node { return in(1); // Input has collapse to e.g. starting control. // Can upgrade minType even while in-progress if( _minType instanceof TypeMemPtr tmp && _minType.isFRef() ) { - TypeMemPtr tmp2 = (TypeMemPtr)CodeGen.CODE.P.TYPES.get(tmp._obj._name); + TypeMemPtr tmp2 = (TypeMemPtr) Parser.TYPES.get(tmp._obj._name); if( tmp2!=null && tmp2 != _minType ) { _minType = tmp2; return this; @@ -136,13 +155,14 @@ public class PhiNode extends Node { Node val = in(3-nullx); if( val instanceof CastNode cast ) val = cast.in(1); - if( addDep(r.idom(this)) instanceof IfNode iff && addDep(iff.pred())==val ) { + Node ridom = r.idom(this); + if( ridom instanceof IfNode iff && addDep(iff.pred())==val ) { // Must walk the idom on the null side to make sure we hit False. CFGNode idom = (CFGNode)r.in(nullx); while( idom != null && idom.nIns() > 0 && idom.in(0) != iff ) idom = idom.idom(); if( idom instanceof CProjNode proj && proj._idx==1 ) return val; - } + } else if( ridom != null ) addDep(ridom); } } diff --git a/src/main/java/com/seaofnodes/simple/node/ProjNode.java b/src/main/java/com/seaofnodes/simple/node/ProjNode.java index a0394e5b..586527c8 100644 --- a/src/main/java/com/seaofnodes/simple/node/ProjNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ProjNode.java @@ -41,7 +41,7 @@ public class ProjNode extends Node { @Override public Type compute() { Type t = in(0)._type; - return t instanceof TypeTuple tt ? tt._types[_idx] : Type.BOTTOM; + return t instanceof TypeTuple tt ? tt._types[_idx] : t.oob(); } @Override public Node idealize() { return ((MultiNode)in(0)).pcopy(_idx); } diff --git a/src/main/java/com/seaofnodes/simple/node/RegionNode.java b/src/main/java/com/seaofnodes/simple/node/RegionNode.java index 2b467a8c..b115a260 100644 --- a/src/main/java/com/seaofnodes/simple/node/RegionNode.java +++ b/src/main/java/com/seaofnodes/simple/node/RegionNode.java @@ -37,7 +37,7 @@ public class RegionNode extends CFGNode { public Node idealize() { if( inProgress() ) return null; - Node progress = deadPath(); + Node progress = deadPath(false); if( progress!=null ) return progress; // If down to a single input, become that input @@ -46,10 +46,10 @@ public class RegionNode extends CFGNode { // If a CFG diamond with no merging, delete: "if( pred ) {} else {};" if( !hasPhi() && nIns()>3 && // No Phi users, just a control user - in(1) instanceof CProjNode p1 && - in(2) instanceof CProjNode p2 && - addDep(p1.in(0))==addDep(p2.in(0)) && - p1.in(0) instanceof IfNode iff ) { + in(1) instanceof CProjNode p1 && + in(2) instanceof CProjNode p2 && + addDep(p1.in(0))==addDep(p2.in(0)) && + p1.in(0) instanceof IfNode iff ) { // Replace with the iff.ctrl directly if( nIns()==3 ) return iff.ctrl(); // Just delete the path for fat Regions @@ -83,16 +83,21 @@ public class RegionNode extends CFGNode { return null; } - Node deadPath() { + Node deadPath(boolean skipStart) { // Delete dead paths into a Region - int path = findDeadInput(); + int path = findDeadInput(skipStart ? 2 :1); if( path==0 ) return null; + // Do not delete the entry path of a loop (ok to remove the back edge // and make the loop a single-entry Region which folds away the Loop). // Folding the entry path confused the loop structure, moving the // backedge to the entry point. if( this instanceof LoopNode loop && loop.entry()==in(path) ) return null; + return removeDeadPath(path); + } + + public Node removeDeadPath(int path) { // Cannot use the obvious output iterator here, because a Phi deleting // an input might recursively delete *itself*. This shuffles the // output array, and we might miss iterating an unrelated Phi. So on @@ -101,15 +106,16 @@ public class RegionNode extends CFGNode { while( nouts != nOuts() ) { nouts = nOuts(); for( int i=0; i<nOuts(); i++ ) - if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() ) + if( out(i) instanceof PhiNode phi && phi.nIns()==nIns() ) { + CodeGen.CODE.addAll(phi.in(path)._outputs); CodeGen.CODE.addAll(phi.delDef(path)._outputs); + } } return isDead() ? Parser.XCTRL : delDef(path); } - - private int findDeadInput() { - for( int i=1; i<nIns(); i++ ) + private int findDeadInput(int startIdx) { + for( int i=startIdx; i<nIns(); i++ ) if( in(i)._type==Type.XCONTROL ) return i; return 0; // All inputs alive @@ -130,10 +136,10 @@ public class RegionNode extends CFGNode { if( use instanceof PhiNode ) { for( Node data : use._outputs ) { if( !(data instanceof PhiNode phi2) || phi2.region()!=this ) - { addDep(use); if( data!=null ) addDep(data); return true; } + { addDep(use); if( data!=null ) addDep(data); return true; } } } else - { addDep(use); return true; } // Control user + { addDep(use); return true; } // Control user } return false; } @@ -155,7 +161,8 @@ public class RegionNode extends CFGNode { // Walk the LHS & RHS idom trees in parallel until they match, or either fails. // Because this does not cache, it can be linear in the size of the program. for( int i=1; i<nIns(); i++ ) - lca = cfg(i)._idom(lca,dep); + if( !cfg(i)._type.isHigh() ) + lca = cfg(i)._idom(lca,dep); return lca; } diff --git a/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/src/main/java/com/seaofnodes/simple/node/ReturnNode.java index 7971733a..0aa70214 100644 --- a/src/main/java/com/seaofnodes/simple/node/ReturnNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ReturnNode.java @@ -116,12 +116,17 @@ public class ReturnNode extends CFGNode { } @Override public Parser.ParseException err() { - return expr()._type/*mt*/==Type.BOTTOM ? mixerr(ti,tf,tp,tn,_fun._loc) : null; + if( ctrl()._type != Type.CONTROL ) return null; // Exit path is dead + return expr()._type==Type.BOTTOM || expr()._type==Type.TOP ? mixerr(ti,tf,tp,tn,_fun._loc) : null; } static Parser.ParseException mixerr( boolean ti, boolean tf, boolean tp, boolean tn, Parser.Lexer loc ) { if( !ti && !tf && !tp && !tn ) + // Hit when the function never returns. e.g. `f = { -> return f() };` return Parser.error("No defined return type", loc); + // Rather ugly way to print conflicting return types + int cnt = (ti?1:0) + (tf?1:0) + (tp||tn?1:0); + if( cnt==1 ) return null; // Uniform return type, something else errored and will report SB sb = new SB().p("No common type amongst "); if( ti ) sb.p("int and "); if( tf ) sb.p("f64 and "); diff --git a/src/main/java/com/seaofnodes/simple/node/StoreNode.java b/src/main/java/com/seaofnodes/simple/node/StoreNode.java index 5fb274db..8e33512a 100644 --- a/src/main/java/com/seaofnodes/simple/node/StoreNode.java +++ b/src/main/java/com/seaofnodes/simple/node/StoreNode.java @@ -132,6 +132,8 @@ public class StoreNode extends MemOpNode { public Parser.ParseException err() { Parser.ParseException err = super.err(); if( err != null ) return err; + if( ptr()._type == Type.TOP ) + return null; // This means we have an error input, report elsewhere TypeMemPtr tmp = (TypeMemPtr)ptr()._type; if( tmp._obj.field(_name)._final && !_init ) return Parser.error("Cannot modify final field '"+_name+"'",_loc); diff --git a/src/main/java/com/seaofnodes/simple/node/SubFNode.java b/src/main/java/com/seaofnodes/simple/node/SubFNode.java index 5c7e969f..3fc4f7ca 100644 --- a/src/main/java/com/seaofnodes/simple/node/SubFNode.java +++ b/src/main/java/com/seaofnodes/simple/node/SubFNode.java @@ -5,38 +5,21 @@ import com.seaofnodes.simple.type.TypeFloat; import java.util.BitSet; -public class SubFNode extends Node { - public SubFNode(Node lhs, Node rhs) { super(null, lhs, rhs); } +public class SubFNode extends ArithFNode { + public SubFNode(Node lhs, Node rhs) { super(lhs, rhs); } @Override public String label() { return "SubF"; } @Override public String glabel() { return "-"; } - @Override - public StringBuilder _print1(StringBuilder sb, BitSet visited) { - in(1)._print0(sb.append("("), visited); - in(2)._print0(sb.append("-"), visited); - return sb.append(")"); - } - - @Override - public Type compute() { - if (in(1)._type instanceof TypeFloat i0 && - in(2)._type instanceof TypeFloat i1) { - if (i0.isConstant() && i1.isConstant()) - return TypeFloat.constant(i0.value()-i1.value()); - } - return in(1)._type.meet(in(2)._type); - } + @Override double doOp( double x, double y ) { return x-y; } @Override public Node idealize() { - Node lhs = in(1); - Type t2 = in(2)._type; - // Sub of 0. + Type t2 = in(2)._type; if ( t2.isConstant() && t2 instanceof TypeFloat i && i.value()==0 ) - return lhs; + return in(1); return null; } diff --git a/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java b/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java index c098ad99..e02183a0 100644 --- a/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java +++ b/src/main/java/com/seaofnodes/simple/node/ToFloatNode.java @@ -20,12 +20,10 @@ public class ToFloatNode extends Node { @Override public Type compute() { + if( in(1)._type.isHigh() ) return TypeFloat.F64.dual(); if( in(1)._type == Type.NIL ) return TypeFloat.FZERO; - if (in(1)._type instanceof TypeInteger i0 ) { - if( i0.isHigh() ) return TypeFloat.F64.dual(); - if( i0.isConstant() ) - return TypeFloat.constant(i0.value()); - } + if( in(1)._type instanceof TypeInteger i0 && i0.isConstant() ) + return TypeFloat.constant(i0.value()); return TypeFloat.F64; } diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/arm/NotARM.java b/src/main/java/com/seaofnodes/simple/node/cpus/arm/NotARM.java index 027a8128..d78421ca 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/arm/NotARM.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/arm/NotARM.java @@ -19,7 +19,7 @@ public class NotARM extends MachConcreteNode implements MachNode{ short reg1 = enc.reg(in(1)); int subs = arm.imm_inst(arm.OP_SUBS, 0, reg1, self); enc.add4(subs); - int cset = arm.cond_set(arm.OP_CSET, 31, arm.COND.EQ, 63, reg1); + int cset = arm.cond_set(arm.OP_CSET, 31, arm.COND.EQ, 31, reg1); enc.add4(cset); } diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java b/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java index 01b46b8d..e1b3b3b6 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/arm/SetARM.java @@ -20,6 +20,7 @@ public class SetARM extends MachConcreteNode implements MachNode { @Override public RegMask outregmap() { return arm.WMASK; } @Override public void encoding( Encoding enc ) { + // Using RM==RN==31 implies a *zero* value, not R31. int body = arm.cset(arm.OP_CSET,0b11111, arm.make_condition(_bop), 0b011111, enc.reg(this)); enc.add4(body); } diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java b/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java index 9dbf724d..a5dac751 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/arm/arm.java @@ -216,7 +216,9 @@ public class arm extends Machine { assert 0 <= rm && rm < 32; assert 0 <= rn && rn < 32; assert 0 <= rd && rd < 32; - return (opcode << 21) | (rm << 15) | (cond.ordinal() << 12) | (rn << 5) | rd; + // Is one of the standard conditions, excluding AL and NV, encoded in the "cond" field with its least significant bit inverted. + int actualCond = cond.ordinal() ^ 1; + return (opcode << 21) | (rm << 16) | (actualCond << 12) | (0b01 << 10) | (rn << 5) | rd; } static public int cset(int opcode, COND cond, int rn, int rd) { @@ -563,29 +565,6 @@ public class arm extends Machine { return (opcode << 26) | delta; } - @Override public RegMask callArgMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { return callInMask(tfp,idx,maxArgSlot); } - static RegMask callInMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { - if( idx==0 ) return CodeGen.CODE._rpcMask; - if( idx==1 ) return null; - // Count floats in signature up to index - if( idx-2 >= tfp.nargs() ) return null; // Anti-dependence - // Count floats in signature up to index - int fcnt=0; - for( int i=2; i<idx; i++ ) - if( tfp.arg(i-2) instanceof TypeFloat) - fcnt++; - // Floats up to XMMS in XMM registers - if( tfp.arg(idx-2) instanceof TypeFloat ) { - if( fcnt < XMMS.length ) - return XMMS[fcnt]; - } else { - RegMask[] cargs = CALLINMASK; - if( idx-2-fcnt < cargs.length ) - return cargs[idx-2-fcnt]; - } - throw Utils.TODO(); // Pass on stack slot - } - public static long decodeImm12(int imm12) { int immr = (imm12 >> 6) & 0x3F; int imms = imm12 & 0x3F; @@ -609,6 +588,31 @@ public class arm extends Machine { return val; } + @Override public RegMask callArgMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { return callInMask(tfp,idx,maxArgSlot); } + static RegMask callInMask(TypeFunPtr tfp, int idx, int maxArgSlot ) { + if( idx==0 ) return CodeGen.CODE._rpcMask; + if( idx==1 ) return null; + // Count floats in signature up to index + if( idx-2 >= tfp.nargs() ) return null; // Anti-dependence + // Count floats in signature up to index + int fcnt=0; + for( int i=2; i<idx; i++ ) + if( tfp.arg(i-2) instanceof TypeFloat) + fcnt++; + // Floats up to XMMS in XMM registers + if( tfp.arg(idx-2) instanceof TypeFloat ) { + if( fcnt < XMMS.length ) + return XMMS[fcnt]; + } else { + RegMask[] cargs = CALLINMASK; + if( idx-2-fcnt < cargs.length ) + return cargs[idx-2-fcnt]; + } + // Pass on stack slot (8 and higher) + if( maxArgSlot>0 ) throw Utils.TODO(); + return new RegMask(MAX_REG + 1 + (idx - 2)); + } + // Return the max stack slot used by this signature, or 0 @Override public short maxArgSlot( TypeFunPtr tfp ) { int icnt=0, fcnt=0; // Count of ints, floats @@ -691,7 +695,7 @@ public class arm extends Machine { private Node cmp(BoolNode bool){ Node cmp = _cmp(bool); - return new SetARM(cmp, IfNode.negate(bool.op())); + return new SetARM(cmp, bool.op()); } private Node _cmp(BoolNode bool) { if( bool.isFloat() ) diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java b/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java index 93c90052..b9e6e5ba 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/riscv/MemOpRISC.java @@ -49,6 +49,9 @@ public abstract class MemOpRISC extends MemOpNode implements MachNode { if( _declaredType == TypeInteger.BOOL) func3=4; // LBU if( _declaredType == TypeInteger.U16 ) func3=5; // LHU if( _declaredType == TypeInteger.U32 ) func3=6; // LWU + if( _declaredType instanceof TypeInteger ti ) { + if( -128 <= ti._min && ti._max < 128 ) func3 = 0; // LB + } // float if( _declaredType == TypeFloat.F32) func3 = 2; // fLW fSW diff --git a/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java b/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java index 0eff2afe..177e35ab 100644 --- a/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java +++ b/src/main/java/com/seaofnodes/simple/node/cpus/x86_64_v2/SetX86.java @@ -35,6 +35,7 @@ public class SetX86 extends MachConcreteNode implements MachNode { case "<" -> _unsigned ? 0x92 : 0x9C; // SETB /SETL case "<=" -> _unsigned ? 0x96 : 0x9E; // SETBE/SETLE case ">=" -> _unsigned ? 0x93 : 0x9D; // SETAE/SETGE + case ">" -> _unsigned ? 0x97 : 0x9F; // SETA /SETG default -> throw Utils.TODO(); }); enc.add1(x86_64_v2.modrm(x86_64_v2.MOD.DIRECT, 0, dst)); diff --git a/src/main/java/com/seaofnodes/simple/type/Type.java b/src/main/java/com/seaofnodes/simple/type/Type.java index b7a8408e..2d5a6d04 100644 --- a/src/main/java/com/seaofnodes/simple/type/Type.java +++ b/src/main/java/com/seaofnodes/simple/type/Type.java @@ -316,7 +316,8 @@ public class Type /*implements Cloneable*/ { } // True if this "isa" t; e.g. 17 isa TypeInteger.BOT - public boolean isa( Type t ) { return meet(t)==t; } + // Applies for pessimistic case + public boolean isa( Type t ) { return meet(t)==t; } // True if this "isa" t up to named structures public boolean shallowISA( Type t ) { return isa(t); } @@ -329,6 +330,9 @@ public class Type /*implements Cloneable*/ { // Is forward-reference public boolean isFRef() { return false; } + // Cap at limits + public Type oob() { return isHigh() ? TOP : BOTTOM; } + // ---------------------------------------------------------- // Cyclic types! Flag the start of a cyclic type by putting a sentinel in @@ -477,6 +481,7 @@ public class Type /*implements Cloneable*/ { Type _glb(boolean mem) { assert is_simple(); return Type.BOTTOM; } Type _close() { return this; } + public Type widen() { return this; } // ---------------------------------------------------------- diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAry.java b/src/main/java/com/seaofnodes/simple/type/TypeConAry.java index d4003f87..c5543030 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAry.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAry.java @@ -51,6 +51,8 @@ public class TypeConAry<A> extends Type { @Override public boolean isHigh() { return this==TOP; } @Override boolean _isConstant() { return true; } + @Override Type _glb(boolean mem) { return this; } + @Override boolean _isGLB(boolean mem) { return true; } // Meet-over-elements type public Type elem() { diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java b/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java index fd2b2635..9e5f0a2d 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAryB.java @@ -15,7 +15,7 @@ public class TypeConAryB extends TypeConAry<byte[]> { @Override public int len() { return _ary.length; } @Override public int log_size() { return 0; } @Override public String str() { return "[\""+new String(_ary)+"\"]"; } - @Override boolean eq(Type t) { return Arrays.equals(_ary,((TypeConAryB)t)._ary); } + @Override boolean eq(Type t) { return t instanceof TypeConAryB ary && Arrays.equals(_ary,ary._ary); } @Override int hash() { return Arrays.hashCode(_ary); } @Override public void write( ByteArrayOutputStream baos ) { baos.write(_ary,0,_ary.length); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java b/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java index 924e3d73..8228887e 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeConAryI.java @@ -12,6 +12,6 @@ public class TypeConAryI extends TypeConAry<int[]> { @Override public int len() { return _ary.length; } @Override public int log_size() { return 2; } @Override public String str() { return "[i32]"; } - @Override boolean eq(Type t) { return Arrays.equals(_ary,((TypeConAryI)t)._ary); } + @Override boolean eq(Type t) { return t instanceof TypeConAryI ary && Arrays.equals(_ary,ary._ary); } @Override int hash() { return Arrays.hashCode(_ary); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java b/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java index b21dd451..ddef9651 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeFunPtr.java @@ -158,8 +158,13 @@ public class TypeFunPtr extends TypeNil { public Type ret() { return _ret; } public int nargs() { return _sig.length; } public int fidx() { assert Long.bitCount(_fidxs)==1; return Long.numberOfTrailingZeros(_fidxs); } + public int nfcns() { + if( _fidxs < 0 ) return Integer.MAX_VALUE; // Infinite choices + return Long.bitCount(_fidxs); + } + // Used to walk over type structures @Override int nkids() { return _sig.length+1; } @Override Type at( int idx ) { return idx == _sig.length ? _ret : _sig[idx]; @@ -235,7 +240,7 @@ public class TypeFunPtr extends TypeNil { return tilde+fidx; } - // Usage: for( long fidxs=fidxs(); fidxs!=0; fidxs=nextFIDX(fidxs) { int fidxs = Long.numberOfTrailingZeros(fidxs); ... } + // Usage: for( long fidxs=fidxs(); fidxs!=0; fidxs=nextFIDX(fidxs) ) { int fidx = Long.numberOfTrailingZeros(fidxs); ... } public static long nextFIDX(long fidxs) { return fidxs & (fidxs-1); } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeInteger.java b/src/main/java/com/seaofnodes/simple/type/TypeInteger.java index 99f237a9..97c17a34 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeInteger.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeInteger.java @@ -18,24 +18,49 @@ public class TypeInteger extends Type { */ public long _min, _max; + public byte _widen; + private static final Ary<TypeInteger> FREE = new Ary<>(TypeInteger.class); - private TypeInteger(long min, long max) { super(TINT); init(min,max); } - private TypeInteger init(long min, long max) { _min = min; _max = max; return this; } - public static TypeInteger malloc(long lo, long hi) { return FREE.isEmpty() ? new TypeInteger(lo,hi) : FREE.pop().init(lo,hi); } - public static TypeInteger make(long lo, long hi) { - TypeInteger i = malloc(lo,hi); + private TypeInteger(long min, long max, byte widen) { super(TINT); init(min,max,widen); } + private TypeInteger init(long min, long max, byte widen) { + // Constants must always have a widen value of zero. Widening is only + // meaningful for ranges of values - which otherwide can increase in + // range size indefinitely. + assert min!=max || widen==0; // Constants always zero widen + _min = min; _max = max; _widen=widen; + return this; + } + public static TypeInteger malloc(long lo, long hi, byte widen) { return FREE.isEmpty() ? new TypeInteger(lo,hi,widen) : FREE.pop().init(lo,hi,widen); } + public static TypeInteger make(long lo, long hi) { return make(lo,hi,(byte)0); } + public static TypeInteger make(long lo, long hi, byte widen) { + TypeInteger i = malloc(lo,hi,lo==hi ? 0 : widen); TypeInteger t2 = i.intern(); return t2==i ? i : t2.free(i); } + public TypeInteger makeWide(byte widen) { + if( widen == _widen ) return this; + if( _min == Long.MIN_VALUE && _max == Long.MAX_VALUE ) + return TypeInteger.BOT; + if( _min==_max ) return this; // Leave constants always narrow + return make(_min,_max,widen); + } @Override TypeInteger free(Type t) { TypeInteger i = (TypeInteger)t; i._min = i._max = 0; + i._widen = 0; i._hash = 0; i._dual = null; FREE.push(i); return this; } + public Type same_but_slightly_wider_than( Type minType ) { + return _widen < 3 ? make(_min,_max, (byte)(_widen+1)) : minType; + } + // Force max widen + @Override public Type widen() { + return _widen==3 ? this : make(_min,_max,(byte)3); + } public static TypeInteger constant(long con) { return make(con, con); } public final static TypeInteger ZERO= make(0,0); @@ -43,20 +68,22 @@ public class TypeInteger extends Type { public final static TypeInteger TRUE= make(1,1); public final static TypeInteger TWO = make(2,2); // Shows up in some Simple tests as the starting argument - public final static TypeInteger I1 = make(-1,0); - public final static TypeInteger I8 = make(-128,127); - public final static TypeInteger I16 = make(-32768,32767); - public final static TypeInteger I32 = make(-1L<<31,(1L<<31)-1); - public final static TypeInteger BOT = make(Long.MIN_VALUE,Long.MAX_VALUE); + public final static TypeInteger I1 = make(-1,0,(byte)3); + public final static TypeInteger I8 = make(-128,127,(byte)3); + public final static TypeInteger I16 = make(-32768,32767,(byte)3); + public final static TypeInteger I32 = make(-1L<<31,(1L<<31)-1,(byte)3); + public final static TypeInteger BOT = make(Long.MIN_VALUE,Long.MAX_VALUE,(byte)3); public final static TypeInteger TOP = (TypeInteger)BOT.dual(); - public final static TypeInteger U1 = make(0,1); + public final static TypeInteger U1 = make(0,1,(byte)3); public final static TypeInteger BOOL= U1; - public final static TypeInteger U8 = make(0,255); - public final static TypeInteger U16 = make(0,65535); - public final static TypeInteger U32 = make(0,(1L<<32)-1); + public final static TypeInteger U8 = make(0,255,(byte)3); + public final static TypeInteger U16 = make(0,65535,(byte)3); + public final static TypeInteger U32 = make(0,(1L<<32)-1,(byte)3); + + public final static TypeInteger FATBOOL = make(0,1,(byte)2); - public static void gather(ArrayList<Type> ts) { ts.add(I32); ts.add(BOT); ts.add(U1); ts.add(I1); ts.add(U8); } + public static void gather(ArrayList<Type> ts) { ts.add(I32); ts.add(BOT); ts.add(U1); ts.add(I1); ts.add(U8); ts.add(ZERO); ts.add(FATBOOL); } @Override public String str() { if( _isConstant() ) return ""+_min; @@ -95,6 +122,7 @@ public class TypeInteger extends Type { else if (-0xFFFFFFFFL <= _min && _min <= 0xFFFFFFFFL) return 2; else return 3; } + if( -128 <= _min && _max < 128 ) return 0; // 1 byte throw Utils.TODO(); } @@ -122,11 +150,11 @@ public class TypeInteger extends Type { if( other instanceof TypeConAry ary ) return ary.imeet(this); // Invariant from caller: 'this' != 'other' and same class (TypeInteger) TypeInteger i = (TypeInteger)other; // Contract - return make(Math.min(_min,i._min), Math.max(_max,i._max)); + return make(Math.min(_min,i._min), Math.max(_max,i._max), (byte)Math.max(_widen,i._widen)); } @Override TypeInteger xdual() { - return _min==_max ? this : malloc(_max,_min); + return _min==_max ? this : malloc(_max,_min,(byte)(-_widen)); } @Override public TypeInteger nonZero() { @@ -146,8 +174,8 @@ public class TypeInteger extends Type { return isHigh() ? dual() : this; } - @Override int hash() { return Utils.fold(_min) * Utils.fold(_max); } + @Override int hash() { return Utils.fold(_min) * Utils.fold(_max) + _widen; } @Override public boolean eq( Type t ) { - return t instanceof TypeInteger i && _min==i._min && _max==i._max; + return t instanceof TypeInteger i && _min==i._min && _max==i._max && _widen==i._widen; } } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java b/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java index 6041155d..689b73ce 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeMemPtr.java @@ -61,6 +61,7 @@ public class TypeMemPtr extends TypeNil { public TypeMemPtr makeFrom(TypeStruct obj) { return obj==_obj ? this : make(_nil, obj, _one); } public TypeMemPtr makeNullable() { return makeFrom((byte)3); } @Override TypeMemPtr makeFrom(byte nil) { return nil==_nil ? this : make(nil, _obj, _one); } + public TypeMemPtr makeHigh() { return make((byte)0,_obj.makeHigh(),false); } // An abstract pointer, pointing to either a Struct or an Array. // Can also be null or not, so 4 choices {TOP,BOT} x {nil,not} diff --git a/src/main/java/com/seaofnodes/simple/type/TypeRPC.java b/src/main/java/com/seaofnodes/simple/type/TypeRPC.java index bd5e2923..a1389540 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeRPC.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeRPC.java @@ -1,5 +1,6 @@ package com.seaofnodes.simple.type; +import com.seaofnodes.simple.util.Ary; import com.seaofnodes.simple.util.SB; import com.seaofnodes.simple.util.Utils; import java.util.ArrayList; @@ -13,19 +14,31 @@ public class TypeRPC extends Type { // A set of CallEndNode IDs (or StopNode); commonly just one. // Basically a sparse bit set - final HashSet<Integer> _rpcs; + HashSet<Integer> _rpcs; // If true, invert the meaning of the bits - final boolean _any; + boolean _any; - private TypeRPC(boolean any, HashSet<Integer> rpcs) { - super(TRPC); - _any = any; - _rpcs = rpcs; + private static final Ary<TypeRPC> FREE = new Ary<>(TypeRPC.class); + private TypeRPC init(boolean any, HashSet<Integer> rpcs) { _any=any; _rpcs=rpcs; return this; } + private TypeRPC() { super(TRPC); } + private static TypeRPC malloc(boolean any, HashSet<Integer> rpcs) { + return (FREE.isEmpty() ? new TypeRPC() : FREE.pop()).init(any,rpcs); } private static TypeRPC make(boolean any, HashSet<Integer> rpcs) { - return new TypeRPC(any,rpcs).intern(); + TypeRPC rpc = (FREE.isEmpty() ? new TypeRPC() : FREE.pop()).init(any,rpcs); + TypeRPC t2 = rpc.intern(); + return t2==rpc ? rpc : t2.free(rpc); } + @Override TypeRPC free(Type t) { + TypeRPC rpc = (TypeRPC)t; + rpc._rpcs = null; + rpc._dual = null; + rpc._hash = 0; + FREE.push(rpc); + return this; + } + @Override boolean isFree() { return _rpcs==null; } public static TypeRPC constant(int cend) { HashSet<Integer> rpcs = new HashSet<>(); @@ -82,8 +95,7 @@ public class TypeRPC extends Type { return make(any,rpcs); } - @Override - Type xdual() { return new TypeRPC(!_any,_rpcs); } + @Override Type xdual() { return malloc(!_any,_rpcs); } @Override boolean _isConstant() { return !_any && _rpcs.size()==1; } @Override boolean _isGLB(boolean mem) { return true; } diff --git a/src/main/java/com/seaofnodes/simple/type/TypeStruct.java b/src/main/java/com/seaofnodes/simple/type/TypeStruct.java index 73fecdab..1cabbe32 100644 --- a/src/main/java/com/seaofnodes/simple/type/TypeStruct.java +++ b/src/main/java/com/seaofnodes/simple/type/TypeStruct.java @@ -68,6 +68,12 @@ public class TypeStruct extends Type { Field.make("#" ,len , lenAlias,true ,false), Field.make("[]",body,bodyAlias,efinal,false)); } + public TypeStruct makeHigh() { + Field[] fs = new Field[_fields.length]; + for( int i=0; i<_fields.length; i++ ) + fs[i] = _fields[i].makeFrom(Type.TOP); + return make(_name,false,fs); + } public TypeStruct add( Field f ) { assert _open && find(f._fname)==-1; // No double field names diff --git a/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index 1e1a1dc3..de6c5a6b 100644 --- a/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -1,8 +1,6 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.node.cpus.arm.arm; -import com.seaofnodes.simple.node.cpus.riscv.riscv; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -14,21 +12,70 @@ public class BrainFuckTest { @Test public void testBrainFuck() throws IOException { String brain_fuck = "Hello World!\n"; - TestC.run("brain_fuck", brain_fuck, 40); + String src = +""" +// -*- mode: java; -*- +val brain_fuck = { -> + var !program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; + int d = 0; + u8[] !output = new u8[0]; + u8[] !data = new u8[100]; - EvalRisc5 R5 = TestRisc5.build("brain_fuck", 0, 28, false); + for( int pc = 0; pc < program#; pc++ ) { + var command = program[pc]; + if (command == 62) { + d++; + } else if (command == 60) { + d--; + } else if (command == 43) { + data[d]++; + } else if (command == 45) { + data[d]--; + } else if (command == 46) { + // Output a byte; increase the output array size + var old = output; + output = new u8[output# + 1]; + for( int i = 0; i < old#; i++ ) + output[i] = old[i]; + output[old#] = data[d]; // Add the extra byte on the end + } else if (command == 44) { + data[d] = 42; + } else if (command == 91) { + if (data[d] == 0) { + for( int d = 1; d > 0; ) { + command = program[++pc]; + if (command == 91) d++; + if (command == 93) d--; + } + } + } else if (command == 93) { + if (data[d]) { + for( int d = 1; d > 0; ) { + command = program[--pc]; + if (command == 93) d++; + if (command == 91) d--; + } + } + } + } + return output; +}; +"""; + TestC.run(src,"brain_fuck", null, brain_fuck, 40); + + EvalRisc5 R5 = TestRisc5.build("brain_fuck", src, 0, 28, false); int trap = R5.step(100000); assertEquals(0,trap); - int ptr = (int)R5.regs[riscv.A0]; + int ptr = (int)R5.regs[com.seaofnodes.simple.node.cpus.riscv.riscv.A0]; assertEquals(brain_fuck.length(),R5.ld4s(ptr)); for( int i=0; i<brain_fuck.length(); i++ ) assertEquals(brain_fuck.charAt(i), R5.ld1z(ptr+4+i)); - EvalArm64 A5 = TestArm64.build("brain_fuck", 0, 28, false); + EvalArm64 A5 = TestArm64.build("brain_fuck", src, 0, 28, false); int trap_arm = A5.step(100000); assertEquals(0,trap_arm); assertEquals(0,trap); - int ptr_arm = (int)A5.regs[arm.X0]; + int ptr_arm = (int)A5.regs[com.seaofnodes.simple.node.cpus.arm.arm.X0]; assertEquals(brain_fuck.length(),A5.ld4s(ptr_arm)); for( int i=0; i<brain_fuck.length(); i++ ) diff --git a/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/src/test/java/com/seaofnodes/simple/Chapter11Test.java index 4f70913d..99aa9579 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter11Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter11Test.java @@ -6,293 +6,6 @@ import static org.junit.Assert.assertEquals; public class Chapter11Test { - // A placeholder test used to rapidly rotate through fuzzer produced issues - @Test - public void testFuzzer() { - CodeGen code = new CodeGen( -""" -while(---- -arg) { - while(-arg) { - while(-----arg*---0) { - int N=--false==false<--arg; - while(N<-4==N) { - N=N+N; - } - } - { - int kzEl_r7EYz = (3*----0!=-arg) < (37*--97!=0/arg==arg) <= -(--arg!=0); - while(kzEl_r7EYz<---1) { - kzEl_r7EYz=kzEl_r7EYz+kzEl_r7EYz*arg>=24; - if(7) continue; - kzEl_r7EYz=false; - if(-kzEl_r7EYz+arg<-3) continue; - else { - while(kzEl_r7EYz) continue; - arg=----3; - kzEl_r7EYz=-(-----arg*1>-kzEl_r7EYz); - int v2uF_4ba=9; - } - } - } - int pjcp7rv=arg; - { - int m2ya3=--arg-pjcp7rv; - while(m2ya3<-----pjcp7rv>=pjcp7rv+--pjcp7rv!=---pjcp7rv!=-arg<---(-m2ya3)>m2ya3<=-----true>14!=--m2ya3) { - m2ya3=m2ya3+-(--0<=false<pjcp7rv/arg<=-true); - while((--m2ya3)<--arg<-----arg*false!=arg<pjcp7rv*arg) { - pjcp7rv=-3+-arg; - break; - } - while(-3) { - while(67+0-61) m2ya3=m2ya3; - if(----pjcp7rv==---(---arg)) pjcp7rv=0!=-23; - else pjcp7rv=----89; - while(m2ya3!=m2ya3<pjcp7rv) m2ya3=1; - while(--arg<=pjcp7rv) pjcp7rv=-32<=-m2ya3+62; - } - break; - } - } - { - int arg=-1<-9!=(-arg>=-pjcp7rv>=arg<=arg); - while(arg<-arg) { - arg=arg+--arg; - { - while((--93)--pjcp7rv*-pjcp7rv+arg) arg=0-(6>=(--(---41/(0))!=--pjcp7rv)>=---2*33); - pjcp7rv=11; - int c=pjcp7rv; - if(--107) break; - else break; - } - } - } - pjcp7rv=pjcp7rv; - int aR0Wkua=-pjcp7rv==pjcp7rv; - { - if(-0!=-0) while(-true) break; - else { - while(aR0Wkua) pjcp7rv=-0/pjcp7rv; - pjcp7rv=pjcp7rv; - } - } - } - if(-arg) { - { - int Isdlt0fr91=0!=arg; - while(Isdlt0fr91<-Isdlt0fr91==-Isdlt0fr91+true) { - Isdlt0fr91=Isdlt0fr91+-1!=true; - if(-arg) if(--arg<=Isdlt0fr91) Isdlt0fr91=-Isdlt0fr91; - int i=---arg<---arg!=--40; - { - int jVX43Ln4Dm=-(6)==-Isdlt0fr91/----0; - while(jVX43Ln4Dm<--(3-3)) { - jVX43Ln4Dm=jVX43Ln4Dm+-0<25; - i=24<--(jVX43Ln4Dm); - } - } - i=(arg!=----false>=7); - int Te=5>-arg; - break; - } - } - arg=arg!=--true/arg; - { - int UX=arg; - while(UX<-3*arg) { - UX=UX+arg/-1; - arg=-3--(-UX- -47<arg==--arg==arg)/arg- -UX>=-arg; - if(---12) while(-UX) break; - break; - } - } - continue; - } - if(arg) arg=--0; - else if(1) continue; - int DtTlhjYq=19==arg; - { - arg=--DtTlhjYq<=(DtTlhjYq/---DtTlhjYq<=-DtTlhjYq); - if(---arg) continue; - else { - int Zsl=40; - while(Zsl<--Zsl--false>((Zsl))==Zsl!=--DtTlhjYq-DtTlhjYq-DtTlhjYq) { - Zsl=Zsl+arg; - } - } - if((arg)) if(-DtTlhjYq) { - } - else while(((2)==3*arg/DtTlhjYq)<=0==---arg) return false; - else { - int lwbF=arg>=0; - while(lwbF<57) { - lwbF=lwbF+--(-arg+lwbF)>=-2>=arg!=arg; - arg=----0+0; - while(49) break; - if(true) DtTlhjYq=-----arg; - DtTlhjYq=0!=-----(0); - } - } - arg=---arg!=DtTlhjYq/--0; - DtTlhjYq=-DtTlhjYq/(--arg<arg); - if(32) { - int q=-DtTlhjYq; - while(q<arg*(0*q)/0) { - q=q+DtTlhjYq; - DtTlhjYq=arg; - } - } - else if(--arg) if(15) break; - else arg=0==arg<=-55>DtTlhjYq; - else { - } - DtTlhjYq=-0; - { - while((0)<-arg) DtTlhjYq=-DtTlhjYq; - } - if(30/--(arg)>=0) DtTlhjYq=-0>=arg; - else { - int Y2wcIQJ=--DtTlhjYq*---11; - if(arg==arg) { - Y2wcIQJ=-----Y2wcIQJ; - Y2wcIQJ=Y2wcIQJ<7; - if(DtTlhjYq) arg=arg; - else break; - while(-arg!=-31==(false<=-15>=-DtTlhjYq+--6*-----Y2wcIQJ<=---arg!=-Y2wcIQJ<=---0<-arg*--Y2wcIQJ)) DtTlhjYq=arg!=3; - } - continue; - } - arg=DtTlhjYq; - arg=--3/(---arg)>=80>=-DtTlhjYq<=DtTlhjYq; - arg=51+---(-true)!=arg!=----1==-DtTlhjYq; - if(11<=arg) if((arg)+79<32+(-arg)) continue; - else if(true==DtTlhjYq) break; - break; - } -} -if(arg!=62==arg) { - while(---arg) { - { - int bhmDacPM=arg/arg; - while(bhmDacPM<arg) { - bhmDacPM=bhmDacPM+80*((-bhmDacPM)/---bhmDacPM>1)<bhmDacPM-2!=7; - arg=-0; - arg=bhmDacPM>=-arg+-arg; - break; - } - } - int arg=true; - arg=arg<=arg; - { - int KlC=30; - while(KlC<-2) { - KlC=KlC+-1!=25<=-KlC>KlC>----0; - int Ij=arg>=-arg<=---10; - { - int LAbgurVa2R=-arg!=Ij; - while(LAbgurVa2R<-true) { - LAbgurVa2R=LAbgurVa2R+Ij; - KlC=-LAbgurVa2R; - Ij=42*(-Ij>true); - while(Ij) arg=KlC; - KlC=-----7>-(--KlC<--7)==-LAbgurVa2R; - } - } - int a=Ij<=-KlC; - if(Ij) { - int r1W=a!=-false; - } - else { - arg=56>=Ij; - while(54) break; - arg=8>=-(a<--Ij)/a>=-a-KlC; - } - int Yt_T=KlC; - arg=KlC; - } - } - if(----false/--arg/12+-----0) if(-9+-arg) while(arg!=(arg)) arg=--1>=-71-arg!=---(--arg*11+102)/--arg; - else if(----arg) continue; - if(-arg-arg) { - arg=-(-arg)*--(-3)<(-7==-arg----arg); - { - int arg=arg; - while(arg<-0>arg==-arg-(-arg>1+11)) { - arg=arg+6-arg!=--0>---30>=---arg<=arg/(3)+---arg; - } - } - arg=-arg+arg; - arg=--47+-arg<1>arg*(-arg==-arg- -0>3); - arg=(----arg)!=arg+--59; - arg=- -4+arg==-(arg)-arg; - } - else { - while(--true-----true*-25+-18>arg>=-----(-arg)---13) { - arg=-0+--true<false; - continue; - } - arg=true<=arg; - break; - } - arg=arg*22<--(0+-arg); - { - continue; - } - } - arg=1*---((3<=true)==---2); - arg=7+-(-1); - return arg+--true; -} -else { - int o3ypEsewxM=-(---arg); - int vzXB=(-(---11<=--o3ypEsewxM>=--0))<=-0/-arg; - int L=-arg; - int B4mHcrf=---vzXB; - int oZWGdzZl=-o3ypEsewxM; - int K6tQqa1=11; - while(0!=--L) { - int sdZfTM=vzXB*true+K6tQqa1; - while(sdZfTM<false) { - sdZfTM=sdZfTM+arg; - sdZfTM=oZWGdzZl; - K6tQqa1=-K6tQqa1; - arg=---K6tQqa1; - while((3+-K6tQqa1)<oZWGdzZl) { - if(-----(-1)) sdZfTM=-false; - {} - } - K6tQqa1=vzXB!=-(B4mHcrf+-7>false); - sdZfTM=vzXB; - } - } - L=false; - while(31) B4mHcrf=arg; - oZWGdzZl=-0<--oZWGdzZl<=--2; - if(K6tQqa1>=20<=46) { - if(-1+-L) if(oZWGdzZl) { - int wmhv=-----0; - } - int arg=0; - o3ypEsewxM=---(oZWGdzZl); - return -oZWGdzZl/0; - } - else if(arg) { - int yKk5=B4mHcrf>=4>K6tQqa1<-B4mHcrf/o3ypEsewxM; - return -K6tQqa1; - } - else { - if(---0) { - {} - {} - } - return o3ypEsewxM; - } -} -"""); - code.parse().opto().typeCheck().GCM(); - assertEquals("return 9;", code.print()); - } - - @Test public void testPrimes() { CodeGen code = new CodeGen( diff --git a/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/src/test/java/com/seaofnodes/simple/Chapter18Test.java index 42f80d86..00b6292e 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -116,7 +116,7 @@ var fcn = arg ? { int x -> x*x; } : { int x -> x+x; }; return fcn(3); """); code.parse().opto(); - assertEquals("Stop[ return #2; return (Parm_x($fun21,i64,3)*x); return (Parm_x($fun22,i64,3)<<1); ]", code._stop.toString()); + assertEquals("Stop[ return #2; return 9; return 6; ]", code._stop.toString()); assertEquals("6", Eval2.eval(code, 0)); assertEquals("9", Eval2.eval(code, 1)); } @@ -126,7 +126,7 @@ return fcn(3); public void testFcn5() { CodeGen code = new CodeGen("val fact = { int x -> x <= 1 ? 1 : x*fact(x-1); }; return fact(arg);"); code.parse().opto().typeCheck(); - assertEquals("Stop[ return #2; return Phi(Region,1,(Parm_x(fact,i64,arg,(x-1))*#2)); ]", code._stop.toString()); + assertEquals("Stop[ return #2; return Phi(Region,1,(Parm_x(fact,i64)*#2)); ]", code._stop.toString()); assertEquals( "1", Eval2.eval(code, 0)); assertEquals( "1", Eval2.eval(code, 1)); assertEquals( "2", Eval2.eval(code, 2)); @@ -142,7 +142,7 @@ struct S { int i; }; val newS = { int x -> return new S { i=x; }; }; return newS(1).i; """); - code.parse().opto().typeCheck().GCM(); + code.parse().opto().typeCheck(); assertEquals("return 1;", code._stop.toString()); assertEquals("1", Eval2.eval(code, 0)); } @@ -157,8 +157,8 @@ val f = {->1;}; val g = {->2;}; return 2; """); - code.parse().opto().typeCheck().GCM(); - assertEquals("Stop[ return 1; return 1; return 2; ]", code._stop.toString()); + code.parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); assertEquals("1", Eval2.eval(code, 0)); } @@ -292,7 +292,7 @@ for(;;) { val g = { -> g(); }; -return 0; +return g(); """); try { code.parse().opto().typeCheck(); fail(); } catch( Exception e ) { assertEquals("No defined return type",e.getMessage()); } diff --git a/src/test/java/com/seaofnodes/simple/Chapter19Test.java b/src/test/java/com/seaofnodes/simple/Chapter19Test.java index e2a155ce..6d751946 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter19Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter19Test.java @@ -23,7 +23,38 @@ return 0; @Test public void testString() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); + String src = +""" +struct String { + u8[] cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { String self, String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; CodeGen code = new CodeGen(src).parse().opto().typeCheck().GCM().localSched(); assertEquals("Stop[ return Phi(Region,1,0,0,1); return Phi(Region,._hashCode,Phi(Region,123456789,Phi(Loop,0,(.[]+((Phi_hash<<5)-Phi_hash))))); ]", code._stop.toString()); //assertEquals("-4898613127354160978", Eval2.eval(code, 2)); @@ -292,8 +323,20 @@ return A[1]; @Test public void testNewton() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp")) - + "flt farg = arg; return test_sqrt(farg);"; + String src = +""" +val test_sqrt = { flt x -> + flt epsilon = 1e-15; + flt guess = x; + while( 1 ) { + flt next = (x/guess + guess)/2; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; + guess = next; + } +}; +flt farg = arg; return test_sqrt(farg); +"""; CodeGen code = new CodeGen(src).driver(Phase.LocalSched,"x86_64_v2", "SystemV"); assertEquals("return Phi(Loop,(cvtf,arg),(mulf,(addf,(divf,cvtf,Phi_guess),Phi_guess),0.5f));", code.print()); }; @@ -301,7 +344,39 @@ return A[1]; @Test public void sieveOfEratosthenes() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sieve.smp")); + String src = +""" +val sieve = { int N -> + // The main Sieve array + bool[] !ary = new bool[N]; + // The primes less than N + 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 + while( p*p < N ) { + // skip marked non-primes + while( ary[p] ) p++; + // p is now a prime + primes[nprimes++] = p; + // Mark out the rest non-primes + for( int i = p + p; i < ary#; i+= p ) + ary[i] = true; + p++; + } + + // Now just collect the remaining primes, no more marking + for( ; p < N; p++ ) + if( !ary[p] ) + primes[nprimes++] = p; + + // Copy/shrink the result array + u32[] !rez = new u32[nprimes]; + for( int j=0; j < nprimes; j++ ) + rez[j] = primes[j]; + return rez; +}; +"""; CodeGen code = new CodeGen(src).driver(Phase.LocalSched,"x86_64_v2", "SystemV"); assertEquals("return []u32;", code.print()); //assertEquals("u32[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20)); @@ -316,7 +391,7 @@ val fcn = arg ? { int x -> x*x; } : { int x -> x+x; }; return fcn(2)*10 + fcn(3); """); code.driver(Phase.LocalSched,"x86_64_v2", "SystemV"); - assertEquals("Stop[ return (add,#2,(muli,#2)); return (mul,Parm_x($fun21,i64),x); return (shli,Parm_x($fun22,i64)); ]", code.print()); + assertEquals("Stop[ return (add,#2,(muli,#2)); return (mul,Parm_x($fun21,[2-3]),x); return (shli,Parm_x($fun22,[2-3])); ]", code.print()); } @Test diff --git a/src/test/java/com/seaofnodes/simple/Chapter20Test.java b/src/test/java/com/seaofnodes/simple/Chapter20Test.java index dcea5c87..02de57a2 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter20Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter20Test.java @@ -1,12 +1,7 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.print.ASMPrinter; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.*; @@ -73,8 +68,20 @@ return sqrt(arg) + sqrt(cast_int); @Test public void testNewtonFloat() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp")) - + "flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0);"; + String src = +""" +val test_sqrt = { flt x -> + flt epsilon = 1e-15; + flt guess = x; + while( 1 ) { + flt next = (x/guess + guess)/2; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; + guess = next; + } +}; +flt farg = arg; return test_sqrt(farg) + test_sqrt(farg+2.0); +"""; testCPU(src,"x86_64_v2", "SystemV",39,null); testCPU(src,"riscv" , "SystemV",17,null); testCPU(src,"arm" , "SystemV",18,null); @@ -92,7 +99,17 @@ return sqrt(arg) + sqrt(cast_int); @Test public void testArray1() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/array1.smp")); + String src = +""" +int[] !ary = new int[arg]; +// Fill [0,1,2,3,4,...] +for( int i=0; i<ary#; i++ ) + ary[i] = i; +// Fill [0,1,3,6,10,...] +for( int i=0; i<ary#-1; i++ ) + ary[i+1] += ary[i]; +return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 +"""; testCPU(src,"x86_64_v2", "SystemV",-1,"return .[];"); testCPU(src,"riscv" , "SystemV", 8,"return (add,.[],(mul,.[],1000));"); testCPU(src,"arm" , "SystemV", 5,"return (add,.[],(mul,.[],1000));"); @@ -101,7 +118,38 @@ return sqrt(arg) + sqrt(cast_int); @Test public void testString() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); + String src = +""" +struct String { + u8[] cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { String self, String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; testCPU(src,"x86_64_v2", "SystemV", 9,null); testCPU(src,"riscv" , "SystemV", 3,null); testCPU(src,"arm" , "SystemV", 3,null); diff --git a/src/test/java/com/seaofnodes/simple/Chapter21Test.java b/src/test/java/com/seaofnodes/simple/Chapter21Test.java index 7f4898e0..ec55735e 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter21Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter21Test.java @@ -15,7 +15,25 @@ public class Chapter21Test { @Test public void testJig() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); + String src = +""" +struct s0 { + bool v1; + i16 v2; + int v3; + i8 v4; + byte v5; +}; +while(new s0.v3) + while(new s0.v5<<new s0.v4) {} +if(0) { + if(0) { + flt !P5ZUD4=new s0.v2; + } + while(0) {} +} +return new s0.v1; +"""; testCPU(src,"x86_64_v2", "Win64" ,-1,null); testCPU(src,"riscv" , "SystemV",-1,null); testCPU(src,"arm" , "SystemV",-1,null); @@ -48,7 +66,17 @@ public class Chapter21Test { @Test public void testArray1() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/array1.smp")); + String src = +""" +int[] !ary = new int[arg]; +// Fill [0,1,2,3,4,...] +for( int i=0; i<ary#; i++ ) + ary[i] = i; +// Fill [0,1,3,6,10,...] +for( int i=0; i<ary#-1; i++ ) + ary[i+1] += ary[i]; +return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 +"""; testCPU(src,"x86_64_v2", "SystemV",-1,"return .[];"); testCPU(src,"riscv" , "SystemV", 7,"return (add,.[],(mul,.[],1000));"); testCPU(src,"arm" , "SystemV", 5,"return (add,.[],(mul,.[],1000));"); @@ -56,7 +84,19 @@ public class Chapter21Test { @Test public void testAntiDeps1() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/antiDep1.smp")); + String src = +""" +struct S { int f; }; +var v0 = new S; +S? v1; +if (arg) v1 = new S; +if (v1) { + v0.f = v1.f; +} else { + v0.f = 2; +} +return v0; +"""; testCPU(src,"x86_64_v2", "SystemV", 7,"return mov(mov(S));"); testCPU(src,"riscv" , "SystemV",10,"return mov(mov(S));"); testCPU(src,"arm" , "SystemV",10,"return mov(mov(S));"); @@ -64,18 +104,92 @@ public class Chapter21Test { @Test public void testString() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/stringHash.smp")); + String src = +""" +struct String { + u8[] cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { String self, String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; testCPU(src,"x86_64_v2", "SystemV", 9,null); testCPU(src,"riscv" , "SystemV", 3,null); testCPU(src,"arm" , "SystemV", 3,null); } @Test public void testStringExport() throws IOException { - TestC.run("stringHash", 9); + String src = +""" +struct String { + u8[] cs; + int _hashCode; +}; + +// Compare two Strings +val equals = { String self, String s -> + if( self == s ) return true; + if( self.cs# != s.cs# ) return false; + for( int i=0; i< self.cs#; i++ ) + if( self.cs[i] != s.cs[i] ) + return false; + return true; +}; + +// Return the String hashCode (cached, and never 0) +val hashCode = { String self -> + self._hashCode + ? self._hashCode + : (self._hashCode = _hashCodeString(self)); +}; + +val _hashCodeString = { String self -> + int hash=0; + for( int i=0; i< self.cs#; i++ ) + hash = hash*31 + self.cs[i]; + if( !hash ) hash = 123456789; + return hash; +}; +"""; + TestC.run(src, "stringHash",null, "", 9); } @Test public void testLoop2() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/loop2.smp")); + String src = +""" +int i = 0; +while(true) { + i += 1; + if( i==0 ) continue; + if( i==1 ) continue; + if( i==2 ) break; + continue; +} +return i; +"""; 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));"); @@ -94,9 +208,22 @@ public class Chapter21Test { 8 2.828427 (4.44089e-16) 9 3.000000 (0) """; - TestC.run("newtonFloat",result,34); + String src = +""" +val test_sqrt = { flt x -> + flt epsilon = 1e-15; + flt guess = x; + while( 1 ) { + flt next = (x/guess + guess)/2; + if( guess-epsilon <= next & next <= guess+epsilon ) return guess; + //if( guess==next ) return guess; + guess = next; + } +}; +"""; + TestC.run(src, "newtonFloat", null, result, 34); - EvalRisc5 R5 = TestRisc5.build("newtonFloat", 0, 10, false); + EvalRisc5 R5 = TestRisc5.build("newtonFloat",src, 0, 10, false); R5.fregs[riscv.FA0 - riscv.F_OFFSET] = 3.0; int trap_r5 = R5.step(1000); assertEquals(0,trap_r5); @@ -104,7 +231,7 @@ public class Chapter21Test { assertEquals(1.732051,R5.fregs[riscv.FA0 - riscv.F_OFFSET], 0.00001); // arm - EvalArm64 A5 = TestArm64.build("newtonFloat", 0, 10, false); + EvalArm64 A5 = TestArm64.build("newtonFloat", src,0, 10, false); A5.fregs[arm.D0 - arm.D_OFFSET] = 3.0; int trap_arm = A5.step(1000); assertEquals(0,trap_arm); @@ -113,6 +240,39 @@ public class Chapter21Test { @Test public void testSieve() throws IOException { + String src = +""" +val sieve = { int N -> + // The main Sieve array + bool[] !ary = new bool[N]; + // The primes less than N + 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 + while( p*p < N ) { + // skip marked non-primes + while( ary[p] ) p++; + // p is now a prime + primes[nprimes++] = p; + // Mark out the rest non-primes + for( int i = p + p; i < ary#; i+= p ) + ary[i] = true; + p++; + } + + // Now just collect the remaining primes, no more marking + for( ; p < N; p++ ) + if( !ary[p] ) + primes[nprimes++] = p; + + // Copy/shrink the result array + u32[] !rez = new u32[nprimes]; + for( int j=0; j < nprimes; j++ ) + rez[j] = primes[j]; + return rez; +}; +"""; // The primes int[] primes = new int[] { 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, }; SB sb = new SB().p(primes.length).p("["); @@ -121,11 +281,11 @@ public class Chapter21Test { String sprimes = sb.p("]").toString(); // Compile, link against native C; expect the above string of primes to be printed out by C - TestC.run("sieve",sprimes, 257); + TestC.run(src, "sieve", null, sprimes, 257); // Evaluate on RISC5 emulator; expect return of an array of primes in // the simulated heap. - EvalRisc5 R5 = TestRisc5.build("sieve", 100, 160, false); + EvalRisc5 R5 = TestRisc5.build("sieve", src, 100, 160, false); int trap = R5.step(10000); assertEquals(0,trap); // Return register A0 holds sieve(100) @@ -137,7 +297,7 @@ public class Chapter21Test { // Evaluate on ARM5 emulator; expect return of an array of primes in // the simulated heap. - EvalArm64 A5 = TestArm64.build("sieve", 100, 160, false); + EvalArm64 A5 = TestArm64.build("sieve", src, 100, 160, false); int trap_arm = A5.step(10000); assertEquals(0, trap_arm); int ary_arm = (int)A5.regs[arm.X0]; @@ -148,17 +308,30 @@ public class Chapter21Test { } @Test public void testFibExport() throws IOException { + String src = +""" +val fib = {int n -> + int f1=1; + int f2=1; + while( n-- > 1 ){ + int temp = f1+f2; + f1=f2; + f2=temp; + } + return f2; +}; +"""; String fib = "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]"; - TestC.run("fib", fib, 24); + TestC.run(src, "fib", null, fib, 24); - EvalRisc5 R5 = TestRisc5.build("fib", 9, 17, false); + EvalRisc5 R5 = TestRisc5.build("fib", src, 9, 17, false); int trap = R5.step(100); assertEquals(0,trap); // Return register A0 holds fib(8)==55 assertEquals(55,R5.regs[riscv.A0]); // arm - EvalArm64 A5 = TestArm64.build("fib", 9, 17, false); + EvalArm64 A5 = TestArm64.build("fib", src, 9, 17, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); // Return register X0 holds fib(8)==55 @@ -166,8 +339,19 @@ public class Chapter21Test { } @Test public void testPerson() throws IOException { + String src = + """ + struct Person { + i32 age; + }; + + val fcn = { Person?[] ps, int x -> + if( ps[x] ) + ps[x].age++; + }; + """; String person = "6\n"; - TestC.run("person", person, 0); + TestC.run(src, "person", null, person, 0); // Memory layout starting at PS: int ps = 1<<16; // Person array pointer starts at heap start @@ -178,7 +362,7 @@ public class Chapter21Test { int p1 = ps+4*8+1*8; // P2 = { age } // sizeof=8 int p2 = ps+4*8+2*8; - EvalRisc5 R5 = TestRisc5.build("person", ps, 0, false); + EvalRisc5 R5 = TestRisc5.build("person", src, ps, 0, false); R5.regs[riscv.A1] = 1; // Index 1 R5.st8(ps,3); // Length R5.st8(ps+1*8,p0); @@ -194,7 +378,7 @@ public class Chapter21Test { assertEquals(17+1,R5.ld8(p1)); assertEquals(60+0,R5.ld8(p2)); - EvalArm64 A5 = TestArm64.build("person", ps, 0, false); + EvalArm64 A5 = TestArm64.build("person", src, ps, 0, false); A5.regs[arm.X1] = 1; // Index 1 A5.st8(ps, 3); A5.st8(ps+1*8,p0); @@ -214,12 +398,19 @@ public class Chapter21Test { @Test public void testArgCount() throws IOException { // Test passes more args than registers in Sys5, which is far far more // than what Win64 allows - so Win64 gets a lot more spills here. + String src = +""" +val addAll = { int i0, flt f1, int i2, flt f3, int i4, flt f5, int i6, flt f7, int x8, flt f9, int i10, flt f11, int i12, flt f13, int i14, flt f15, int x16, flt f17 int x18, flt f19 -> + return + i0 + f1+ i2+ f3+ i4+ f5+ i6+ f7+ x8 +f9 + + i10+f11+i12+f13+i14+f15+x16+f17+x18+f19 ; +}; +"""; String arg_count = "191.000000\n"; - TestC.run("arg_count", arg_count, - TestC.CALL_CONVENTION.equals("Win64") ? 42 : 15); + TestC.run(src, "arg_count", null, arg_count, TestC.CALL_CONVENTION.equals("Win64") ? 42 : 15); - EvalRisc5 R5 = TestRisc5.build("no_stack_arg_count", 0, 0, false); + EvalRisc5 R5 = TestRisc5.build("no_stack_arg_count", src, 0, 4, false); // Todo: handle stack(imaginary stack in emulator) // pass in float arguments @@ -249,7 +440,7 @@ public class Chapter21Test { assertEquals(22.8, result, 0.00001); // arm - EvalArm64 A5 = TestArm64.build("no_stack_arg_count", 0, 0, false); + EvalArm64 A5 = TestArm64.build("no_stack_arg_count", src, 0, 4, false); A5.fregs[arm.D0 - arm.D_OFFSET] = 1.1; A5.fregs[arm.D1 - arm.D_OFFSET] = 1.1; diff --git a/src/test/java/com/seaofnodes/simple/Chapter22Test.java b/src/test/java/com/seaofnodes/simple/Chapter22Test.java index f6410b6a..78b9e7a1 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter22Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter22Test.java @@ -15,8 +15,24 @@ public class Chapter22Test { @Test public void testJig() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); - //String src = Files.readString(Path.of("docs/examples/BubbleSort.smp")); + String src = +""" +val fib = {int n -> + int temp=0; + int f1=1; + int f2=1; + int i=n; + while( i>1 ){ + temp = f1+f2; + f1=f2; + f2=temp; + i=i-1; + } + return f2; +}; + +fib(10); +"""; testCPU(src,"x86_64_v2", "Win64" ,-1,null); testCPU(src,"riscv" , "SystemV",-1,null); testCPU(src,"arm" , "SystemV",-1,null); @@ -51,11 +67,11 @@ return 0; assertEquals(56, testCPUSize(src, "arm","SystemV",4,"return 0;")); // do assertEquals here - EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away", 0, 4, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away", src,0, 4, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away", 0, 4, false); + EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away", src, 0, 4, false); trap = A5.step(100); assertEquals(0,trap); @@ -71,11 +87,11 @@ return 0; return 0; """; - EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away_2", 0, 4, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_not_fold_away_2", src, 0, 4, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away_2", 0, 4, false); + EvalArm64 A5 = TestArm64.build("sext_str_not_fold_away_2", src, 0, 4, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); @@ -95,11 +111,11 @@ p.age = (arg<<48)>>48; return 0; """; - EvalRisc5 R5 = TestRisc5.build("sext_str_fold_away", 0, 5, false); + EvalRisc5 R5 = TestRisc5.build("sext_str_fold_away", src, 0, 5, false); int trap = R5.step(100); assertEquals(0,trap); - EvalArm64 A5 = TestArm64.build("sext_str_fold_away", 0, 5, false); + EvalArm64 A5 = TestArm64.build("sext_str_fold_away", src, 0, 5, false); int trap_arm = A5.step(100); assertEquals(0,trap_arm); @@ -112,8 +128,19 @@ return 0; // Int now is changed to 4 bytes. @Test public void testPerson() throws IOException { + String src = +""" +struct Person { + i32 age; +}; + +val fcn = { Person?[] ps, int x -> + if( ps[x] ) + ps[x].age++; +}; +"""; String person = "6\n"; - TestC.run("person", person, 0); + TestC.run(src, "person", null, person, 0); // Memory layout starting at PS: int ps = 1<<16; // Person array pointer starts at heap start @@ -124,7 +151,7 @@ return 0; int p1 = ps+4*8+1*8; // P2 = { age } // sizeof=8 int p2 = ps+4*8+2*8; - EvalRisc5 R5 = TestRisc5.build("person", ps, 0, false); + EvalRisc5 R5 = TestRisc5.build("person", src, ps, 0, false); R5.regs[riscv.A1] = 1; // Index 1 R5.st8(ps,3); // Length R5.st8(ps+1*8,p0); @@ -140,7 +167,7 @@ return 0; assertEquals(17+1,R5.ld8(p1)); assertEquals(60+0,R5.ld8(p2)); - EvalArm64 A5 = TestArm64.build("person", ps, 0, false); + EvalArm64 A5 = TestArm64.build("person", src, ps, 0, false); A5.regs[arm.X1] = 1; // Index 1 A5.st8(ps, 3); A5.st8(ps+1*8,p0); @@ -179,18 +206,22 @@ return cc.cz; @Test public void testHelloWorld() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/helloWorld.smp")); + String src = +""" +sys.io.p("Hello, World!"); +return 0; +"""; TestC.run(src,TestC.CALL_CONVENTION,null, null,null,"build/objs/helloWorld","","Hello, World!",0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("helloWorld", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("helloWorld", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Hello, World!",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("helloWorld", 0, 2, false); + EvalArm64 arm = TestArm64.build("helloWorld", src,0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -220,17 +251,21 @@ return sum(is); @Test @Ignore public void testEcho() throws IOException { - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/echo.smp")); + String src = +""" +// Echo stdin to stdout. +return sys.io.p( sys.io.stdin() ); +"""; TestC.run(src,TestC.CALL_CONVENTION,null, null,null,"build/objs/echo","","",0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("echo", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("echo", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("echo", 0, 2, false); + EvalArm64 arm = TestArm64.build("echo", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); diff --git a/src/test/java/com/seaofnodes/simple/Chapter23Test.java b/src/test/java/com/seaofnodes/simple/Chapter23Test.java index 9d500266..94e13a87 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter23Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter23Test.java @@ -14,18 +14,13 @@ public class Chapter23Test { @Test public void testJig() throws IOException { - String src = -""" -var apply = { i64 x, { i64 -> u32 } fcn -> - return fcn(x); -} -"""; + //String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/jig.smp")); + String src = Files.readString(Path.of("docs/examples/BubbleSort.smp")); + testCPU(src,"x86_64_v2", "Win64" ,-1,null); + testCPU(src,"riscv" , "SystemV",-1,null); + testCPU(src,"arm" , "SystemV",-1,null); } - @Test @Ignore - public void myOwnSake2() throws IOException { - TestC.runS("print","Or",0); - } static CodeGen testCPU( String src, String cpu, String os, int spills, String stop ) { CodeGen code = new CodeGen(src).driver(CodeGen.Phase.Encoding,cpu,os); @@ -40,17 +35,32 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testOr() throws IOException { - TestC.runS("or1","Or",0); + String src = + """ + int a = 1; + int b = 0; + + if(a++ || b++ ) { + if(b == 0 && a == 2) { + sys.io.p("Or"); + } + } else{ + sys.io.p("And"); + } + return 0; + """; + + TestC.runSF("or1", src, null, "Or", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("or1", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("or1", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Or",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("or1", 0, 2, false); + EvalArm64 arm = TestArm64.build("or1", src,0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -59,17 +69,29 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testAnd() throws IOException { - TestC.runS("and1","And",0); + String src = + """ + int a = 1; + int b = 1; + + if(a && b) { + sys.io.p("And"); + } else { + sys.io.p("Or"); + } + return 0; + """; + TestC.runSF("and1", src, null, "And", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and1", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and1", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("And",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and1", 0, 2, false); + EvalArm64 arm = TestArm64.build("and1", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -78,24 +100,38 @@ var apply = { i64 x, { i64 -> u32 } fcn -> @Test public void testAndPtr() throws IOException { + // Todo: have one src here String src = -""" -struct S { S? fld; }; -val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; -return ptr && ptr.fld ? "true" : "false"; - """; + """ + struct S { S? fld; }; + val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; + return ptr && ptr.fld ? "true" : "false"; + """; + String src2 = + """ + struct S { S? fld; }; + + val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; + if( ptr && ptr.fld ) { + sys.io.p("true"); + } else { + sys.io.p("false"); + } + + return 0; + """; CodeGen code = new CodeGen(src).parse().opto().typeCheck(); assertEquals("[97-117][ 116,114,117,101]", Eval2.eval(code, 0)); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("ptrand", 1, 8, false); + EvalRisc5 R5 = TestRisc5.build("ptrand",src2, 1, 8, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("false",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("ptrand", 1, 8, false); + EvalArm64 arm = TestArm64.build("ptrand", src2, 1, 8, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -105,37 +141,80 @@ return ptr && ptr.fld ? "true" : "false"; // conditional side effect @Test public void testCondSideEffAnd() throws IOException { - TestC.runS("and2","Effected",0); + String src = + """ + int a = 1; + int b = 1; + + int x=1; + int y=1; + int z=0; + + int g = x++ && y++ && z++; + + if(x == 2 && y == 2 && z == 1 && g == 0) { + sys.io.p("Effected"); + } else { + sys.io.p("Not effected"); + } + return 0; + """; + + TestC.runSF("and2", src, null, "Effected", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and2", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and2", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Effected",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and2", 0, 2, false); + EvalArm64 arm = TestArm64.build("and2", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); assertEquals("Effected",arm._stdout.toString()); } - @Test public void testCondSideEffOr() throws IOException { - TestC.runS("or2","Effected",0); + String src = + """ + int a = 1; + int b = 1; + + int x = -1; + int y=1; + int z= -1; + + int g = x++ || y++ || z++; + + int switch = 0; + if(x == 4 || y == 4 || z == 4) { + switch = -1; + } else { + switch = 1; + } + int cd = 1; + if((x == 0 && y == 1 && z==-1) && switch && g) { + sys.io.p("Effected"); + } else { + sys.io.p("Not effected"); + } + return 0; + """; + TestC.runSF("or2", src, null, "Effected", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("or2", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("or2", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Effected",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("or2", 0, 2, false); + EvalArm64 arm = TestArm64.build("or2", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); @@ -145,23 +224,41 @@ return ptr && ptr.fld ? "true" : "false"; // test it with function calls @Test public void testFuncCall() throws IOException { - TestC.runS("and3","Or",0); + String src = + """ + // -*- mode: java; -*- + int a = 1; + int b = 1; + + var sq = { int x -> + x*x; + }; + + if(a && sq(0)) { + sys.io.p("And"); + } else { + sys.io.p("Or"); + } + return 0; + """; + TestC.runSF("and3", src, null, "Or", 0); // Evaluate on RISC5 emulator - EvalRisc5 R5 = TestRisc5.build("and3", 0, 2, false); + EvalRisc5 R5 = TestRisc5.build("and3", src, 0, 2, false); int trap = R5.step(100); assertEquals(0,trap); assertEquals(0,R5.regs[riscv.A0]); assertEquals("Or",R5._stdout.toString()); // Evaluate on ARM emulator - EvalArm64 arm = TestArm64.build("and3", 0, 2, false); + EvalArm64 arm = TestArm64.build("and3", src, 0, 2, false); trap = arm.step(100); assertEquals(0,trap); assertEquals(0,arm.regs[0]); assertEquals("Or",arm._stdout.toString()); } + @Test public void testFRefFields() { String src = diff --git a/src/test/java/com/seaofnodes/simple/Chapter24Test.java b/src/test/java/com/seaofnodes/simple/Chapter24Test.java new file mode 100644 index 00000000..1d67949a --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/Chapter24Test.java @@ -0,0 +1,689 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.node.cpus.riscv.riscv; +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; + +public class Chapter24Test { + + @Test + public void testJig() throws IOException { + String src = "int v0=0; v0 = arg && 0== 0 !=0;"; + testCPU(src,"x86_64_v2", "Win64" ,-1,null); + testCPU(src,"riscv" , "SystemV",-1,null); + testCPU(src,"arm" , "SystemV",-1,null); + } + + static CodeGen testCPU( String src, String cpu, String os, int spills, String stop ) { + CodeGen code = new CodeGen(src).driver(CodeGen.Phase.Encoding,cpu,os); + int delta = spills>>3; + if( delta==0 ) delta = 1; + if( spills != -1 ) + assertEquals("Expect spills:",spills,code._regAlloc._spillScaled,delta); + if( stop != null ) + assertEquals(stop, code._stop.toString()); + return code; + } + + @Test + public void testOr() throws IOException { + String src = +""" +int a = 1; +int b = 0; + +if(a++ || b++ ) { + if(b == 0 && a == 2) { + sys.io.p("Or"); + } +} else{ + sys.io.p("And"); +} +return 0; +"""; + + TestC.runSF("or1", src, null, "Or", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("or1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Or",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("or1", src,0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Or",arm._stdout.toString()); + } + + @Test + public void testAnd() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +if(a && b) { + sys.io.p("And"); +} else { + sys.io.p("Or"); +} +return 0; +"""; + TestC.runSF("and1", src, null, "And", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("And",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and1", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("And",arm._stdout.toString()); + } + + @Test + public void testAndPtr() throws IOException { + // Todo: have one src here + String src = +""" +struct S { S? fld; }; +val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; +return ptr && ptr.fld ? "true" : "false"; +"""; + String src2 = +""" +struct S { S? fld; }; + +val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; +if( ptr && ptr.fld ) { + sys.io.p("true"); +} else { + sys.io.p("false"); +} + +return 0; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("[97-117][ 116,114,117,101]", Eval2.eval(code, 0)); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("ptrand",src2, 1, 8, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("false",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("ptrand", src2, 1, 8, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("false",arm._stdout.toString()); + } + + // conditional side effect + @Test + public void testCondSideEffAnd() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +int x=1; +int y=1; +int z=0; + +int g = x++ && y++ && z++; + +if(x == 2 && y == 2 && z == 1 && g == 0) { + sys.io.p("Effected"); +} else { + sys.io.p("Not effected"); +} +return 0; +"""; + + TestC.runSF("and2", src, null, "Effected", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Effected",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Effected",arm._stdout.toString()); + } + + + @Test + public void testCondSideEffOr() throws IOException { + String src = +""" +int a = 1; +int b = 1; + +int x = -1; +int y=1; +int z= -1; + +int g = x++ || y++ || z++; + +int switch = 0; +if(x == 4 || y == 4 || z == 4) { + switch = -1; +} else { + switch = 1; +} +int cd = 1; +if((x == 0 && y == 1 && z==-1) && switch && g) { + sys.io.p("Effected"); +} else { + sys.io.p("Not effected"); +} +return 0; +"""; + TestC.runSF("or2", src, null, "Effected", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("or2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Effected",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("or2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Effected",arm._stdout.toString()); + } + + // test it with function calls + @Test + public void testFuncCall() throws IOException { + String src = +""" +// -*- mode: java; -*- +int a = 1; +int b = 1; + +var sq = { int x -> + x*x; +}; + +if(a && sq(0)) { + sys.io.p("And"); +} else { + sys.io.p("Or"); +} +return 0; +"""; + TestC.runSF("and3", src, null, "Or", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("and3", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Or",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("and3", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Or",arm._stdout.toString()); + } + + // test it with function calls + @Test + public void testStack1() throws IOException { + String src = +""" +int something_specific = 11; + +if (10 < something_specific < 20) { + sys.io.p("In Range"); +} else { + sys.io.p("Out of Range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_1", src, null, "In Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_1", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_1", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack2() throws IOException { + String src = +""" +int score = 75; + +if (60 <= score < 90) { + sys.io.p("In Range"); +} else { +sys.io.p("Out of range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_2", src, null, "In Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_2", src, 0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_2", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack3() throws IOException { + String src = +""" +var sq = { int x -> + x*x; +}; + +int score = 5; + +val str = (sq(2) <= score < sq(3)) ? "In Range" : "Out of range"; +sys.io.p(str); +return 0; +"""; + + TestC.runSF("stacked_r_3", src, null, "In Range", 5); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_3", src, 0, 5, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_3", src, 0, 5, false); + int trap_1 = arm.step(100); + assertEquals(0,trap_1); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + @Test + public void testStack4() throws IOException { + String src = +""" +int something_specific = 9; + +if (10 < something_specific < 20) { + sys.io.p("In Range"); +} else { + sys.io.p("Out of Range"); +} +return 0; +"""; + + TestC.runSF("stacked_r_4", src, null, "Out of Range", 0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_4", src,0, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("Out of Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_4", src, 0, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("Out of Range",arm._stdout.toString()); + } + + @Test + public void testStack5() throws IOException { + String src = +""" +var sq = { int x -> + x*x; +}; + +int score = 5; + +if (sq(2) <= score < sq(3)) { +sys.io.p("In Range"); +} else { +sys.io.p("Out of range"); +} + +return 0; +"""; + TestC.runSF("stacked_r_5", src, null, "In Range", 5); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_5", src, 0, 7, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(0,R5.regs[riscv.A0]); + assertEquals("In Range",R5._stdout.toString()); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_5", src, 0, 7, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(0,arm.regs[0]); + assertEquals("In Range",arm._stdout.toString()); + } + + + @Test + public void testStack6() { + try { new CodeGen( + """ + return 0 < arg > 1; + """ + ).parse(); fail(); } + catch( RuntimeException e ) { assertEquals("Mixing relational directions in a chained relational test",e.getMessage()); } + } + + @Test + public void testStack9() throws IOException { + String stack9 = "1"; + String src = +""" +var stack9 = { int x -> + (x < 1) == 1; +}; +"""; + String src2 = +""" +return (0 < 1) == 1; +"""; + TestC.run(src, "stacked_r_9x", null, stack9,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_9", src2, 0, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_9", src2, 0, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + @Test + public void testStack10() throws IOException { + String stack10 = "1"; + String src = +""" +var stack10 = { int x -> + (x < 1) == (1>x); +}; +"""; + String src2 = +""" +return (0 < 1) == (1>0); +"""; + TestC.run(src, "stacked_r_10x", null, stack10,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_10", src2, 0, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_10", src2,0, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + @Test + public void testStack11() throws IOException { + String stack11 = "1"; + String src = +""" +var stack11 = { int x -> + 0 < x < x+1 < 4; +}; +"""; + String src2 = +""" +return 0 < arg < arg+1 < 4; +"""; + TestC.run(src, "stacked_r_11x", null, stack11,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_11", src2, 1, 2, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_11", src2, 1, 2, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + // shows that it is parsed as + // ((0 != x) != 2) + @Test + public void testStack12() throws IOException { + String stack11 = "1"; + String src = + """ + var stack12 = { int x -> + 0 != x != 2; + }; + """; + String src2 = + """ + return 0 != arg != 2; + """; + TestC.run(src, "stacked_r_12x", null, stack11,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_12", src2, 1, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_12", src2, 1, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + + // shows that it is parsed as + // ((0 == x) == 1) + @Test + public void testStack13() throws IOException { + String stack12 = "1"; + String src = + """ + var stack13 = { int x -> + 0 == x == 1; + }; + """; + String src2 = + """ + return 0 == arg == 1; + """; + TestC.run(src, "stacked_r_13x", null, stack12,0); + + // Evaluate on RISC5 emulator + EvalRisc5 R5 = TestRisc5.build("stacked_r_13", src2, 1, 0, false); + int trap = R5.step(100); + assertEquals(0,trap); + assertEquals(1,R5.regs[riscv.A0]); + + // Evaluate on ARM emulator + EvalArm64 arm = TestArm64.build("stacked_r_13", src2, 1, 0, false); + trap = arm.step(100); + assertEquals(0,trap); + assertEquals(1,arm.regs[0]); + } + + @Test + public void testFRefFields() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] buf; + // Skip whitespace + val skip = { Scan s -> + while( s.buf[s.x] <= ' ' ) + s.x++; + }; + // Peek a character; if matched consume it, else false. + val peek = { Scan s, u8 c -> + skip(s); + if( s.buf[s.x] != c ) return false; + s.x++; + return true; + }; +}; +Scan !s = new Scan{ buf = " q"; }; +return Scan.peek(s,'q'); +"""; + + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return Phi(Region,0,1);", code._stop.toString()); + assertEquals("1", Eval2.eval(code, 0)); + testCPU(src,"x86_64_v2", "Win64" ,17,null); + }; + + @Test + public void testFRefFields2() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] buf; + // Skip whitespace + val skip = { -> + while( buf[x] <= ' ' ) + x++; + return self; + }; +}; +val s = new Scan{ buf = " q"; }; +return s.skip().x; +"""; + + try { new CodeGen(src).parse().opto().typeCheck(); fail(); } + catch( Exception e ) { assertEquals("Argument #0 isa *Scan {i64 x; *[]u8 buf; { *Scan -> *Scan {i64 !x; *[]u8 buf; {21} skip; } #21} skip; }, but must be a *Scan {i64 !x; *[]u8 buf; ... }",e.getMessage()); } + }; + + + @Test + public void testMethod() { + String src = +""" +// A hypothetical scanner class +struct Scan { + int !x; + u8[~] buf; + // Skip whitespace + val skip = { -> + while( buf[x] <= ' ' ) + x++; + }; + val require = { u8 ch -> + skip(); + buf[x++]==ch; + }; +}; +Scan !s = new Scan{ buf = " [1,2]"; }; +return s.require('['); +"""; + + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return (.[]==91);", code._stop.toString()); + assertEquals("1", Eval2.eval(code, 0)); + testCPU(src,"x86_64_v2", "Win64" ,16,null); + }; + + @Test + public void testSCCP0() { + String src = +""" +int x = 1; +int cnt = 5; +while (cnt) { + cnt -= 1; + if (x == 0) { + x += 1; + } +} +return x; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); + } + + @Test + public void testSCCP1() { + String src = +""" +int x = 1; +int cnt = 5; +while( cnt-- ) + if( x == 1 ) + x = 2-x; +return x; +"""; + CodeGen code = new CodeGen(src).parse().opto().typeCheck(); + assertEquals("return 1;", code._stop.toString()); + } + +} diff --git a/src/test/java/com/seaofnodes/simple/Eval2.java b/src/test/java/com/seaofnodes/simple/Eval2.java index 094b5143..5994e7e1 100644 --- a/src/test/java/com/seaofnodes/simple/Eval2.java +++ b/src/test/java/com/seaofnodes/simple/Eval2.java @@ -308,14 +308,23 @@ public abstract class Eval2 { case TypeMem mem -> "MEM"; case TypeMemPtr tmp -> { if( tmp._obj.isAry() ) { // Constant array ptr - TypeConAry con = (TypeConAry)tmp._obj.field("[]")._t; - Object[] xs = new Object[con.len()]; - for( int i=0; i<con.len(); i++ ) - xs[i] = con.at8(i); - yield xs; + Type elem = tmp._obj.field("[]")._t; + if( elem instanceof TypeConAry con ) { + Object[] xs = new Object[con.len()]; + for( int i=0; i<con.len(); i++ ) + xs[i] = con.at8(i); + yield xs; + } else { + // Generic constant array, used as a default input to a + // function; should never execute. + yield new Object[0]; + } } else { - throw Utils.TODO(); // Constant non-array ptr + // Generic TMP (since Simple is not currently making actual + // memory constants), used as a default input to a function; + // should never execute. + yield tmp.toString(); } } default -> null; diff --git a/src/test/java/com/seaofnodes/simple/EvalArm64.java b/src/test/java/com/seaofnodes/simple/EvalArm64.java index c719b8e8..9575d9fe 100644 --- a/src/test/java/com/seaofnodes/simple/EvalArm64.java +++ b/src/test/java/com/seaofnodes/simple/EvalArm64.java @@ -74,7 +74,6 @@ public class EvalArm64 { trap = 1 + 1; // Handle access violation on instruction read. break; } - if( (pc & 3)!=0 ) { trap = 1; // Handle PC-misaligned access break; @@ -342,7 +341,6 @@ public class EvalArm64 { regs[arm.X0] = _heap; _heap += (int)size; pc = (int)rval; - rdid = -1; } if( pc == Encoding.SENTINEL_WRITE ) { ByteArrayOutputStream baos = switch((int)regs[0]) { @@ -353,33 +351,42 @@ public class EvalArm64 { baos.write(_buf,(int)regs[1],(int)regs[2]); regs[0] = regs[2]; pc = (int)rval; - rdid = -1; } pc -= 4; + rdid = -1; break; } case 0x9A: { + int encodedCond = (ir >> 12) & 0xF; + int decodedCond = encodedCond ^ 1; // conditional select(csel) int rm = (ir >> 16) & 0x1F; - switch((ir >> 12) & 0xF) { - case 0x0: if(Z) rval = regs[rm]; break; // eq - case 0x1: if(!Z) rval = regs[rm]; break; // ne - case 0x2: if(C) rval = regs[rm]; break; // cs - case 0x3: if(!C) rval = regs[rm]; break; - case 0x4: if(N) rval = regs[rm]; break; // mi - case 0x5: if(!N) rval = regs[rm]; break; // pl - case 0x6: if(V) rval = regs[rm]; break; // vs - case 0x7: if(!V) rval = regs[rm]; break; // vc - case 0x8: if(C && !Z) rval = regs[rm]; break; // hi - case 0x9: if(!C || Z) rval = regs[rm]; break; // ls - case 0xA: if(N == V) rval = regs[rm]; break; // ge - case 0xB: if(N != V) rval = regs[rm]; break; // lt - case 0xC: if(!Z && N == V) rval = regs[rm]; break; // gt - case 0xD: if(Z || N != V) rval = regs[rm]; break; // le - case 0xE: rval = regs[rm]; break; // always executed(al) - default: rval = regs[(ir >> 5) & 0x1F]; - } + int rn = (ir >> 5) & 0x1F; + boolean cond = switch (decodedCond) { + case 0x0 -> Z ; // eq + case 0x1 -> !Z ; // ne + case 0x2 -> C ; // cs + case 0x3 -> !C ; + case 0x4 -> N ; // mi + case 0x5 -> !N ; // pl + case 0x6 -> V ; // vs + case 0x7 -> !V ; // vc + case 0x8 -> ( C && !Z ) ; // hi + case 0x9 -> (!C || Z ) ; // ls + case 0xA -> ( N == V) ; // ge + case 0xB -> ( N != V) ; // lt + case 0xC -> (!Z && N == V) ; // gt + case 0xD -> ( Z || N != V ); // le + case 0xE -> true ; // always + case 0xF -> false ; // never + default -> throw Utils.TODO(); + }; +// int reg = cond ? rn : rm; +// rval = reg==31 ? 0 : regs[reg]; +// if( cond ) rval++; + if(cond) rval = 1; + else rval = 0; break; } case 0x9B: { // mul diff --git a/src/test/java/com/seaofnodes/simple/MergeSortTest.java b/src/test/java/com/seaofnodes/simple/MergeSortTest.java index 65eb525c..9c7c1360 100644 --- a/src/test/java/com/seaofnodes/simple/MergeSortTest.java +++ b/src/test/java/com/seaofnodes/simple/MergeSortTest.java @@ -13,15 +13,54 @@ import static org.junit.Assert.fail; public class MergeSortTest { @Test public void testMergeSort0() throws IOException { + // Test merge sort on a small array of primes + String src = +""" + val merge_sort = { int[] a -> + int[] !b = new int[a#]; + copy_array (a, 0, a#, b); + split_merge(a, 0, a#, b); + }; + + val split_merge = { int[] b, int begin, int end, int[] a -> + if (end - begin <= 1) + return 0; + int middle = (end + begin) / 2; + split_merge(a, begin, middle, b); + split_merge(a, middle, end, b); + merge(b, begin, middle, end, a); + return 0; + }; + + val merge = { int[] b, int begin, int middle, int end, int[] a -> + int i = begin, j = middle; + + for (int k = begin; k < end; k++) { + // && and || + bool cond = false; + if (i < middle) { + if (j >= end) cond = true; + else if (a[i] <= a[j]) cond = true; + } + if (cond) b[k] = a[i++]; + else b[k] = a[j++]; + } + }; + + val copy_array = { int[] a, int begin, int end, int[] b -> + for (int k = begin; k < end; k++) + b[k] = a[k]; + }; +"""; int[] primes = new int[] { 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, }; SB sb = new SB().p(primes.length).p("["); for( int prime : primes ) sb.p(prime).p(", "); String sprimes = sb.p("]").toString(); - TestC.run("sort", sprimes, 40); + TestC.run(src, "sort", null, sprimes, 40); - EvalRisc5 R5 = TestRisc5.build("src/test/java/com/seaofnodes/simple/progs", "sort", "merge_sort", 0, 36, false); + EvalRisc5 R5 = TestRisc5.build("src/test/java/com/seaofnodes/simple/progs",src, "sort", "merge_sort", 0, 36, false); // Allocate an array of primes, filled in reverse order int ps = R5._heap; R5._heap += (primes.length+1)*8; // 25 primes, and length @@ -39,7 +78,6 @@ public class MergeSortTest { assertEquals(primes[i], R5.ld8(ps+(i+1)*8)); // TODO: replace with ARM Eval - String src = Files.readString(Path.of("src/test/java/com/seaofnodes/simple/progs/sort.smp")); Chapter21Test.testCPU(src,"arm", "SystemV",36,null); } } diff --git a/src/test/java/com/seaofnodes/simple/Simple.java b/src/test/java/com/seaofnodes/simple/Simple.java index f765d939..be582a64 100644 --- a/src/test/java/com/seaofnodes/simple/Simple.java +++ b/src/test/java/com/seaofnodes/simple/Simple.java @@ -283,7 +283,7 @@ Options: if ( !TestC.CPU_PORT.equals( cpu ) || !TestC.CALL_CONVENTION.equals( abi ) ) throw bad("cannot run code on not native target"); String exe = TestC.OS.startsWith("Windows") ? base+".exe" : base; - String result = com.seaofnodes.simple.TestC.gcc(base+".o", null, null, true, exe); + String result = TestC.gcc(base+".o", null, null, true, exe); System.out.print(result); } } diff --git a/src/test/java/com/seaofnodes/simple/TestArm64.java b/src/test/java/com/seaofnodes/simple/TestArm64.java index 5d7d1361..a1c02ede 100644 --- a/src/test/java/com/seaofnodes/simple/TestArm64.java +++ b/src/test/java/com/seaofnodes/simple/TestArm64.java @@ -14,13 +14,19 @@ import static org.junit.Assert.assertEquals; public class TestArm64 { public static EvalArm64 build( String file, int arg, int spills, boolean print ) throws IOException { - return build("src/test/java/com/seaofnodes/simple/progs",file, arg, spills, print); + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String src = Files.readString(Path.of(dir + "/"+file+".smp")); + return build(dir,src, file, arg, spills, print); + } + + public static EvalArm64 build( String name, String src, int arg, int spills, boolean print ) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + return build(dir, src ,name, arg, spills, print); } // Compile and run a simple program - public static EvalArm64 build( String dir, String file, int arg, int spills, boolean print ) throws IOException { + public static EvalArm64 build( String dir, String src, String file, int arg, int spills, boolean print ) throws IOException { // Compile and export Simple - String src = Files.readString(Path.of(dir+"/"+file+".smp")); CodeGen code = new CodeGen(src).driver("arm", "SystemV",null); if( print ) { code.print_as_hex(); System.out.print(code.asm()); } diff --git a/src/test/java/com/seaofnodes/simple/TestC.java b/src/test/java/com/seaofnodes/simple/TestC.java index dbe9f02f..f1831929 100644 --- a/src/test/java/com/seaofnodes/simple/TestC.java +++ b/src/test/java/com/seaofnodes/simple/TestC.java @@ -40,14 +40,31 @@ public abstract class TestC { String src = Files.readString(Path.of(sfile)); run(src,CALL_CONVENTION,arg, "",standalone? null: cfile,efile,"S",expected,spills); } + + // link with c and also inline + public static void run(String src, String file, TypeInteger arg, String expected, int spills) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String cfile = dir+"/"+file+".c"; + String efile = "build/objs/"+file; + run(src, CALL_CONVENTION, arg, "", cfile, efile, "S", expected, spills); + } + public static void run(String dir, String file, String expected, int spills ) throws IOException { run(dir, file,null, expected, spills, false); } + // Do not link with c file - no inline. public static void runS(String file, String expected, int spills ) throws IOException { run("src/test/java/com/seaofnodes/simple/progs", file, null, expected, spills, true); } + + // Do not link with c file - just inline with source. + public static void runSF(String name, String src, TypeInteger arg, String expected, int spills ) throws IOException { + String efile = "build/objs/"+name; + run(src,CALL_CONVENTION,arg, "",null,efile,"S",expected,spills); + } + public static void runS(String file, TypeInteger arg, String expected, int spills ) throws IOException { run("src/test/java/com/seaofnodes/simple/progs", file, arg, expected, spills, true); } diff --git a/src/test/java/com/seaofnodes/simple/TestRisc5.java b/src/test/java/com/seaofnodes/simple/TestRisc5.java index 041ed833..a8f6817e 100644 --- a/src/test/java/com/seaofnodes/simple/TestRisc5.java +++ b/src/test/java/com/seaofnodes/simple/TestRisc5.java @@ -13,13 +13,19 @@ import static org.junit.Assert.*; public abstract class TestRisc5 { public static EvalRisc5 build( String file, int arg, int spills, boolean print ) throws IOException { - return build("src/test/java/com/seaofnodes/simple/progs",file, null, arg, spills, print); + String dir = "src/test/java/com/seaofnodes/simple/progs"; + String src = Files.readString(Path.of(dir + "/"+file+".smp")); + return build(dir,src, file, null, arg, spills, print); + } + + public static EvalRisc5 build( String name, String src, int arg, int spills, boolean print ) throws IOException { + String dir = "src/test/java/com/seaofnodes/simple/progs"; + return build(dir, src ,name, null, arg, spills, print); } // Compile and run a simple program - public static EvalRisc5 build( String dir, String file, String main, int arg, int spills, boolean print ) throws IOException { + public static EvalRisc5 build( String dir, String src, String file, String main, int arg, int spills, boolean print ) throws IOException { // Compile and export Simple - String src = Files.readString(Path.of(dir+"/"+file+".smp")); CodeGen code = new CodeGen(src).driver("riscv", "SystemV",null); if( print ) { code.print_as_hex(); System.out.print(code.asm()); } diff --git a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java index fee0f2a8..c837bd6f 100644 --- a/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java +++ b/src/test/java/com/seaofnodes/simple/evaluator/Scheduler.java @@ -594,7 +594,7 @@ public class Scheduler { * @param start The start node * @return The final schedule. */ - public static Scheduler.Block schedule(StartNode start) { + public static Block schedule(StartNode start) { var scheduler = new Scheduler(); scheduler.doMarkAlive(start); scheduler.doBuildCTF(start); diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java b/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java index 856e6a24..f6e12e11 100644 --- a/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java +++ b/src/test/java/com/seaofnodes/simple/fuzzer/Reducer.java @@ -174,4 +174,4 @@ public class Reducer { }); } -} +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java index 7d9e6483..dde5a1dc 100644 --- a/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java +++ b/src/test/java/com/seaofnodes/simple/fuzzer/ScriptGenerator.java @@ -440,7 +440,7 @@ public class ScriptGenerator { int idx = random.nextInt(forwardStructs.size()+10); TypeStruct struct; if (idx < 10) { - var name = getStructName(); + var name = getStructName(); struct = new TypeStruct(name); forwardStructs.add(struct); } else { @@ -935,4 +935,4 @@ public class ScriptGenerator { else sb.append(v.name); } -} +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/and1.smp b/src/test/java/com/seaofnodes/simple/progs/and1.smp deleted file mode 100644 index ef4c904f..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and1.smp +++ /dev/null @@ -1,10 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -if(a && b) { - sys.io.p("And"); -} else { - sys.io.p("Or"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/and2.smp b/src/test/java/com/seaofnodes/simple/progs/and2.smp deleted file mode 100644 index 2a463c94..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and2.smp +++ /dev/null @@ -1,16 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -int x=1; -int y=1; -int z=0; - -int g = x++ && y++ && z++; - -if(x == 2 && y == 2 && z == 1 && g == 0) { - sys.io.p("Effected"); -} else { - sys.io.p("Not effected"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/and3.smp b/src/test/java/com/seaofnodes/simple/progs/and3.smp deleted file mode 100644 index aadbdfed..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/and3.smp +++ /dev/null @@ -1,14 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -var sq = { int x -> - x*x; -}; - -if(a && sq(0)) { - sys.io.p("And"); -} else { - sys.io.p("Or"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp b/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp deleted file mode 100644 index b18dfd16..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/antiDep1.smp +++ /dev/null @@ -1,11 +0,0 @@ -// -*- mode: java; -*- -struct S { int f; }; -var v0 = new S; -S? v1; -if (arg) v1 = new S; -if (v1) { - v0.f = v1.f; -} else { - v0.f = 2; -} -return v0; diff --git a/src/test/java/com/seaofnodes/simple/progs/arg_count.smp b/src/test/java/com/seaofnodes/simple/progs/arg_count.smp deleted file mode 100644 index 6b6bc0ae..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/arg_count.smp +++ /dev/null @@ -1,6 +0,0 @@ -// -*- mode: java; -*- -val addAll = { int i0, flt f1, int i2, flt f3, int i4, flt f5, int i6, flt f7, int x8, flt f9, int i10, flt f11, int i12, flt f13, int i14, flt f15, int x16, flt f17 int x18, flt f19 -> - return - i0 + f1+ i2+ f3+ i4+ f5+ i6+ f7+ x8 +f9 + - i10+f11+i12+f13+i14+f15+x16+f17+x18+f19 ; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/array1.smp b/src/test/java/com/seaofnodes/simple/progs/array1.smp deleted file mode 100644 index 6b10f92c..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/array1.smp +++ /dev/null @@ -1,9 +0,0 @@ -// -*- mode: java; -*- -int[] !ary = new int[arg]; -// Fill [0,1,2,3,4,...] -for( int i=0; i<ary#; i++ ) - ary[i] = i; -// Fill [0,1,3,6,10,...] -for( int i=0; i<ary#-1; i++ ) - ary[i+1] += ary[i]; -return ary[1] * 1000 + ary[3]; // 1 * 1000 + 6 diff --git a/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp b/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp deleted file mode 100644 index ed90cb84..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/brain_fuck.smp +++ /dev/null @@ -1,46 +0,0 @@ -// -*- mode: java; -*- -val brain_fuck = { -> - u8[] !program = new u8[106];program[0] = 43;program[1] = 43;program[2] = 43;program[3] = 43;program[4] = 43;program[5] = 43;program[6] = 43;program[7] = 43;program[8] = 91;program[9] = 62;program[10] = 43;program[11] = 43;program[12] = 43;program[13] = 43;program[14] = 91;program[15] = 62;program[16] = 43;program[17] = 43;program[18] = 62;program[19] = 43;program[20] = 43;program[21] = 43;program[22] = 62;program[23] = 43;program[24] = 43;program[25] = 43;program[26] = 62;program[27] = 43;program[28] = 60;program[29] = 60;program[30] = 60;program[31] = 60;program[32] = 45;program[33] = 93;program[34] = 62;program[35] = 43;program[36] = 62;program[37] = 43;program[38] = 62;program[39] = 45;program[40] = 62;program[41] = 62;program[42] = 43;program[43] = 91;program[44] = 60;program[45] = 93;program[46] = 60;program[47] = 45;program[48] = 93;program[49] = 62;program[50] = 62;program[51] = 46;program[52] = 62;program[53] = 45;program[54] = 45;program[55] = 45;program[56] = 46;program[57] = 43;program[58] = 43;program[59] = 43;program[60] = 43;program[61] = 43;program[62] = 43;program[63] = 43;program[64] = 46;program[65] = 46;program[66] = 43;program[67] = 43;program[68] = 43;program[69] = 46;program[70] = 62;program[71] = 62;program[72] = 46;program[73] = 60;program[74] = 45;program[75] = 46;program[76] = 60;program[77] = 46;program[78] = 43;program[79] = 43;program[80] = 43;program[81] = 46;program[82] = 45;program[83] = 45;program[84] = 45;program[85] = 45;program[86] = 45;program[87] = 45;program[88] = 46;program[89] = 45;program[90] = 45;program[91] = 45;program[92] = 45;program[93] = 45;program[94] = 45;program[95] = 45;program[96] = 45;program[97] = 46;program[98] = 62;program[99] = 62;program[100] = 43;program[101] = 46;program[102] = 62;program[103] = 43;program[104] = 43;program[105] = 46; - int d = 0; - u8[] !output = new u8[0]; - u8[] !data = new u8[100]; - - for( int pc = 0; pc < program#; pc++ ) { - var command = program[pc]; - if (command == 62) { - d++; - } else if (command == 60) { - d--; - } else if (command == 43) { - data[d]++; - } else if (command == 45) { - data[d]--; - } else if (command == 46) { - // Output a byte; increase the output array size - var old = output; - output = new u8[output# + 1]; - for( int i = 0; i < old#; i++ ) - output[i] = old[i]; - output[old#] = data[d]; // Add the extra byte on the end - } else if (command == 44) { - data[d] = 42; - } else if (command == 91) { - if (data[d] == 0) { - for( int d = 1; d > 0; ) { - command = program[++pc]; - if (command == 91) d++; - if (command == 93) d--; - } - } - } else if (command == 93) { - if (data[d]) { - for( int d = 1; d > 0; ) { - command = program[--pc]; - if (command == 93) d++; - if (command == 91) d--; - } - } - } - } - return output; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/echo.smp b/src/test/java/com/seaofnodes/simple/progs/echo.smp deleted file mode 100644 index 8eafd73b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/echo.smp +++ /dev/null @@ -1,3 +0,0 @@ -// -*- mode: java; -*- -// Echo stdin to stdout. -return sys.io.p( sys.io.stdin() ); diff --git a/src/test/java/com/seaofnodes/simple/progs/fib.smp b/src/test/java/com/seaofnodes/simple/progs/fib.smp deleted file mode 100644 index 1512541b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/fib.smp +++ /dev/null @@ -1,11 +0,0 @@ -// -*- mode: java; -*- -val fib = {int n -> - int f1=1; - int f2=1; - while( n-- > 1 ){ - int temp = f1+f2; - f1=f2; - f2=temp; - } - return f2; -};
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp b/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp deleted file mode 100644 index 07ff935f..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/helloWorld.smp +++ /dev/null @@ -1,3 +0,0 @@ -// -*- mode: java; -*- -sys.io.p("Hello, World!"); -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/jig.smp b/src/test/java/com/seaofnodes/simple/progs/jig.smp deleted file mode 100644 index f7a5d202..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/jig.smp +++ /dev/null @@ -1,16 +0,0 @@ -// -*- mode: java; -*- -val fib = {int n -> - int temp=0; - int f1=1; - int f2=1; - int i=n; - while( i>1 ){ - temp = f1+f2; - f1=f2; - f2=temp; - i=i-1; - } - return f2; -}; - -fib(10); diff --git a/src/test/java/com/seaofnodes/simple/progs/large.smp b/src/test/java/com/seaofnodes/simple/progs/large.smp deleted file mode 100644 index 7f151f60..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/large.smp +++ /dev/null @@ -1,5344 +0,0 @@ - -struct stbi_io_callbacks { - { i64 u8[] int -> int } read = "C"; // fill 'data' with 'size' bytes. return number of bytes actually read - { i64 int -> int } skip = "C"; // skip the next 'n' bytes, or 'unget' the last -n bytes if negative - { i64 -> int } eof = "C"; // returns nonzero if we are at end of file/data -}; - -struct stbi__context { - u32 img_x, img_y; - int img_n, img_out_n; - - stbi_io_callbacks io; - u8[]io_user_data; - - int read_from_callbacks; - int buflen; - u8[] buffer_start; - int callback_already_read; - - u8[] img_buffer; - int img_buffer_end; - u8[] img_buffer_original; - int img_buffer_original_end; -}; - -{ stbi__context -> u8 } stbi__get8 = "C"; - -val sample = { stbi__context s, int pal_len -> - var palette = new u8[1024]; - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - for (int i=0; i < pal_len; ++i) { - palette[i*4+3] = 0; - - palette[i*4+0] = stbi__get8(s); - palette[i*4+1] = stbi__get8(s); - palette[i*4+2] = stbi__get8(s); - palette[i*4+3] = 255; - for (int j=0; j < pal_len; ++j) { - palette[j*4+3] = 0; - - palette[j*4+0] = stbi__get8(s); - palette[j*4+1] = stbi__get8(s); - palette[j*4+2] = stbi__get8(s); - palette[j*4+3] = 255; - } - } - - return palette; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/loop2.smp b/src/test/java/com/seaofnodes/simple/progs/loop2.smp deleted file mode 100644 index 01ec827e..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/loop2.smp +++ /dev/null @@ -1,10 +0,0 @@ -// -*- mode: java; -*- -int i = 0; -while(true) { - i += 1; - if( i==0 ) continue; - if( i==1 ) continue; - if( i==2 ) break; - continue; -} -return i; diff --git a/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp b/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp deleted file mode 100644 index be2dffec..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/newtonFloat.smp +++ /dev/null @@ -1,12 +0,0 @@ -// -*- mode: java; -*- -// Newtons approximation to the square root -val test_sqrt = { flt x -> - flt epsilon = 1e-15; - flt guess = x; - while( 1 ) { - flt next = (x/guess + guess)/2; - if( guess-epsilon <= next & next <= guess+epsilon ) return guess; - //if( guess==next ) return guess; - guess = next; - } -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/no_stack_arg_count.smp b/src/test/java/com/seaofnodes/simple/progs/no_stack_arg_count.smp deleted file mode 100644 index 20a05445..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/no_stack_arg_count.smp +++ /dev/null @@ -1,6 +0,0 @@ -// -*- mode: java; -*- -val addAll = { int i0, flt f1, int i2, flt f3, int i4, flt f5, int i6, flt f7, int x8, flt f9, int i10, flt f11, int i12, flt f13, int i14, flt f15 -> - return - i0 + f1+ i2+ f3+ i4+ f5+ i6+ f7+ x8 +f9 + - i10+f11+i12+f13+i14+f15; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/or1.smp b/src/test/java/com/seaofnodes/simple/progs/or1.smp deleted file mode 100644 index f5f526c3..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/or1.smp +++ /dev/null @@ -1,12 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 0; - -if(a++ || b++ ) { - if(b == 0 && a == 2) { - sys.io.p("Or"); - } -} else{ - sys.io.p("And"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/or2.smp b/src/test/java/com/seaofnodes/simple/progs/or2.smp deleted file mode 100644 index ac688b5a..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/or2.smp +++ /dev/null @@ -1,23 +0,0 @@ -// -*- mode: java; -*- -int a = 1; -int b = 1; - -int x = -1; -int y=1; -int z= -1; - -int g = x++ || y++ || z++; - -int switch = 0; -if(x == 4 || y == 4 || z == 4) { - switch = -1; -} else { - switch = 1; -} -int cd = 1; -if((x == 0 && y == 1 && z==-1) && switch && g) { - sys.io.p("Effected"); -} else { - sys.io.p("Not effected"); -} -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/person.smp b/src/test/java/com/seaofnodes/simple/progs/person.smp deleted file mode 100644 index 507fb83b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/person.smp +++ /dev/null @@ -1,9 +0,0 @@ -// -*-java-*- -struct Person { - i32 age; -}; - -val fcn = { Person?[] ps, int x -> - if( ps[x] ) - ps[x].age++; -};
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/print.smp b/src/test/java/com/seaofnodes/simple/progs/print.smp deleted file mode 100644 index 3bb86268..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/print.smp +++ /dev/null @@ -1,8 +0,0 @@ -int x = 1; - -int y = 2; -if(x == 1) { -y = 1; -} - -return y;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/ptrand.smp b/src/test/java/com/seaofnodes/simple/progs/ptrand.smp deleted file mode 100644 index 9d7bce88..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/ptrand.smp +++ /dev/null @@ -1,10 +0,0 @@ -struct S { S? fld; }; - -val ptr = arg == 1 ? null : new S{fld = arg==1 ? null : new S{fld = null;};}; -if( ptr && ptr.fld ) { - sys.io.p("true"); -} else { - sys.io.p("false"); -} - -return 0; diff --git a/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp b/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp deleted file mode 100644 index 67369feb..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/riscv_load.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -Person !p = new Person; -p.age += arg; -return p.age; diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp deleted file mode 100644 index cfb3fbcc..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_1.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person {i64 age;} -Person !p = new Person; -p.age += arg; -return p.age; diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp deleted file mode 100644 index 0cf70392..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_fold_away.smp +++ /dev/null @@ -1,5 +0,0 @@ -// Should fold away sign extend -struct Person { i8 age;}; -Person !p = new Person; -p.age = (arg<<48)>>48; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp deleted file mode 100644 index 48cc6409..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -Person !p = new Person; -p.age = (arg<<17)>>17; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp b/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp deleted file mode 100644 index 3120429b..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sext_str_not_fold_away_2.smp +++ /dev/null @@ -1,4 +0,0 @@ -struct Person { i32 age;}; -Person !p = new Person; -p.age = (arg<<48)>>48; -return 0;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/sieve.smp b/src/test/java/com/seaofnodes/simple/progs/sieve.smp deleted file mode 100644 index 569dbb96..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sieve.smp +++ /dev/null @@ -1,31 +0,0 @@ -// -*- mode: java; -*- -val sieve = { int N -> - // The main Sieve array - bool[] !ary = new bool[N]; - // The primes less than N - 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 - while( p*p < N ) { - // skip marked non-primes - while( ary[p] ) p++; - // p is now a prime - primes[nprimes++] = p; - // Mark out the rest non-primes - for( int i = p + p; i < ary#; i+= p ) - ary[i] = true; - p++; - } - - // Now just collect the remaining primes, no more marking - for( ; p < N; p++ ) - if( !ary[p] ) - primes[nprimes++] = p; - - // Copy/shrink the result array - u32[] !rez = new u32[nprimes]; - for( int j=0; j < nprimes; j++ ) - rez[j] = primes[j]; - return rez; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/sort.smp b/src/test/java/com/seaofnodes/simple/progs/sort.smp deleted file mode 100644 index ae3f4f23..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/sort.smp +++ /dev/null @@ -1,38 +0,0 @@ -// -*- mode: java; -*- -// based on the top-down version from https://en.wikipedia.org/wiki/Merge_sort - -val merge_sort = { int[] a -> - int[] !b = new int[a#]; - copy_array (a, 0, a#, b); - split_merge(a, 0, a#, b); -}; - -val split_merge = { int[] b, int begin, int end, int[] a -> - if (end - begin <= 1) - return 0; - int middle = (end + begin) / 2; - split_merge(a, begin, middle, b); - split_merge(a, middle, end, b); - merge(b, begin, middle, end, a); - return 0; -}; - -val merge = { int[] b, int begin, int middle, int end, int[] a -> - int i = begin, j = middle; - - for (int k = begin; k < end; k++) { - // && and || - bool cond = false; - if (i < middle) { - if (j >= end) cond = true; - else if (a[i] <= a[j]) cond = true; - } - if (cond) b[k] = a[i++]; - else b[k] = a[j++]; - } -}; - -val copy_array = { int[] a, int begin, int end, int[] b -> - for (int k = begin; k < end; k++) - b[k] = a[k]; -}; diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c new file mode 100644 index 00000000..d44d5387 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_10x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack10(int x); + +int main() { +int result = stack10(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c new file mode 100644 index 00000000..d71979d1 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_11x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack11(int x); + +int main() { +int result = stack11(1); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c new file mode 100644 index 00000000..a4e425cb --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_12x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack12(int x); + +int main() { +int result = stack12(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c new file mode 100644 index 00000000..a3a51d0e --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_13x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack13(int x); + +int main() { +int result = stack13(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c b/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c new file mode 100644 index 00000000..4f93ba24 --- /dev/null +++ b/src/test/java/com/seaofnodes/simple/progs/stacked_r_9x.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +__attribute__ ((CALL_CONV)) +extern int stack9(int x); + +int main() { +int result = stack9(0); + +printf("%d", result); +return 0; +}
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/store_peep.smp b/src/test/java/com/seaofnodes/simple/progs/store_peep.smp deleted file mode 100644 index c3feddd5..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/store_peep.smp +++ /dev/null @@ -1,3 +0,0 @@ -i64 a = 123456789012345; -i32 b = a; // truncate high order bits -return b;
\ No newline at end of file diff --git a/src/test/java/com/seaofnodes/simple/progs/stringHash.smp b/src/test/java/com/seaofnodes/simple/progs/stringHash.smp deleted file mode 100644 index 3fa2174c..00000000 --- a/src/test/java/com/seaofnodes/simple/progs/stringHash.smp +++ /dev/null @@ -1,30 +0,0 @@ -// -*- mode: java; -*- -struct String { - u8[] cs; - int _hashCode; -}; - -// Compare two Strings -val equals = { String self, String s -> - if( self == s ) return true; - if( self.cs# != s.cs# ) return false; - for( int i=0; i< self.cs#; i++ ) - if( self.cs[i] != s.cs[i] ) - return false; - return true; -}; - -// Return the String hashCode (cached, and never 0) -val hashCode = { String self -> - self._hashCode - ? self._hashCode - : (self._hashCode = _hashCodeString(self)); -}; - -val _hashCodeString = { String self -> - int hash=0; - for( int i=0; i< self.cs#; i++ ) - hash = hash*31 + self.cs[i]; - if( !hash ) hash = 123456789; - return hash; -}; |
