["-*- Mode: lispcc -*-"] [(setq ss-verify-run nil) (setq gdb-command-name "gdb-5.2.1") ] [-----grammar (gz start (prog)) (gz prog (global-star ::pr("[[global-star('','\n','\n')]]"))) (gz global (defun) (defclass) (forwardfunc)(forwardclass) (defvar ::pr ("[[defvar]];\n" )) (include)(using) (enum) (typedef ) (namespace-scope) (f :code-exists-once global j ::pr("[[global]]")) (f :code-assert global j ::pr("[[global]]")) (comment) (preprocessor-global)) (gz preprocessor-global (f :ifdef id global-star j ::pr("#ifdef [[id]]\n[[global-star('','','')]]\n#endif /*[[id]]*/\n")) (f :ifndef id global-star j ::pr("#ifndef [[id]]\n[[global-star('','','')]]\n#endif /*[[id]]*/\n")) (f :define id j ::pr("#define [[id]]\n")) ) (gz namespace-scope (f :nas id global-star j ::pr( "namespace [[id]] {\n[[global-star('','','')]]}\n"))) (gz using (f :using scope-qualified-id j ::pr("using [[scope-qualified-id]];\n"))) (gz enum(f :enum (name ::is id) f id-non-plus j j ::pr("enum [[name]] [[id-non-plus('{',',','}')]];\n"))) (gz defun (f :fun function-start javadoc-opt compound-statement j ::pr( "[[javadoc-opt]][[function-start]]\n[[compound-statement]]\n"))) (gz javadoc (:javadoc astring ::pr("/** [[astring]] */\n"))) (gz function-start (globdecl-rest formals template-decl-opt inline-opt method-is-constant-opt ::pr( "[[template-decl-opt]][[inline-opt]][[globdecl-rest]][[formals]]" "[[method-is-constant-opt]]"))) [(save-excursion(goto-char(point-min))(get-globals))] (gz inline ((:inline ::outputs "inline\x20"))) (gz construct ::gets "tr-id*{name}" (f :ctor formals f init-construct-opt j compound-statement j ::pr( (::c "name->print();") "[[formals]][[init-construct-opt]]\n" "[[compound-statement]]\n"))) (gz destruct ::gets "tr-id*{name}" (f :dtor compound-statement j ::pr("virtual ~" (::c "name->print();") "()\n" "[[compound-statement]]\n"))) (gz forwardfunc (f :forward function-start j ::pr( "[[function-start]];\n" ))) (gz pure-virtual (f :pure-virtual function-start j ::pr( "virtual [[function-start]]=0;\n" ))) (gz method-is-constant ((:method-const ::outputs "const"))) (gz template-decl (:template f aformal-star j ::pr( "template [[aformal-star('< ',',',' >')]]\n" ))) [ (gz typename-id (id ::pr("typename [[id]]")))] (gz init-construct (an-init-construct-plus ::pr("[[an-init-construct-plus(':',',','')]]"))) (gz an-init-construct (f id expression j ::pr("[[id]]([[expression]])"))) (gz formals(f aformal-star j ::pr("[[aformal-star('(',',',')')]]"))) (gz aformal(f globdecl-rest j)) (gz array(:array f arraymax-plus j ::pr("[[arraymax-plus('','','')]]"))) (gz arraymax(expression ::pr("[ [[expression]] ]"))) (gz const(:const)) (gz pointer((:ptr ::outputs "*")) ((:constptr ::outputs "*const"))) (gz compound-statement (f :x statement-star j ::pr("{\n[[statement-star('','\n','\n')]]}"))) (gz simple-statement-without-semi (f command j) (defvar) (inc-or-dec) (:z ::pr("")) (assignment) (call-something) (stream-statement)(delete)) (gz delete (f :delete-array expression j ::pr("delete\x5b\x5d [[expression]]")) (f :delete expression j ::pr("delete [[expression]]"))) (gz expression-or-decl (expression)(defvar)) (gz assignment (f assignment-operator (a ::is expression) (b ::is expression) j ::pr("[[a]] [[assignment-operator]] [[b]]"))) (gz command (:break) (:continue)(:return expression-opt ::pr("return [[expression-opt]]"))) (gz simple-statement (simple-statement-without-semi ::pr("[[simple-statement-without-semi]];")) (comment)) (gz comment(f :comment astring j ::pr ("/*[[astring]]*/"))) (gz inc-or-dec(f inc-or-dec-operator expression j)) (gz inc-or-dec-operator ((:inc ::outputs "++")) ((:dec ::outputs "--"))) (gz statement (f :code-assert statement-star j ::pr("[[statement-star('','\n','\n')]]")) (f :use-n-times id astring statement-star j ::pr("[[statement-star('','\n','\n')]]")) (using)(control-stmt) (simple-statement) (compound-statement) (preprocessor) (f :mult-use-n-times f id-astring-star j statement-star j ::pr("[[statement-star('','\n','\n')]]")) ) (gz id-astring (f id astring j)) (gz preprocessor ( f :ifdef id statement j ::pr("#ifdef [[id]]\n[[statement]]\n#endif /*[[id]]*/")) (f :ifndef id statement j ::pr("#ifndef [[id]]\n[[statement]]\n#endif /*[[id]]*/"))) (gz qastring (astring ::pr("\x22[[astring]]\x22"))) (gz expression (scope-qualified-id) (qastring) (character) (call-something) (list-expression)(binary-expression) (array-access) (member-access) (unary-expression) (cast-expression) (array-in-place) (new-expression) (stream-input) (f :lit astring j ::pr("[[astring]]"))) (gz character (f :char astring j ::pr("\x27[[astring]]\x27") )) (gz new-expression(f :new abstract-type expression-star j ::pr("new [[abstract-type]]" "[[expression-star('(',',',')')]]")) (f :new-array abstract-type expression-star j ::pr("new [[abstract-type]]" "[[expression-star('\x5b','\x5d\x5b','\x5d')]]"))) (gz call-something(construct-in-place)(function-call) (method-call)) (gz cast-expression (f cast-operator abstract-type expression j ::pr("[[cast-operator]]<[[abstract-type]]>([[expression]])")) [(:sc :n(long) 1 )] (f :sci-size expression j ::pr("static_cast([[expression]].size())")) ) (gz cast-operator((:sc ::outputs "static_cast")) ((:dc ::outputs "dynamic_cast")) ((:cc ::outputs "const_cast")) ((:rc ::outputs "reinterpret_cast")) ) (gz unary-expression(f unary-operator expression j ::pr("([[unary-operator]][[expression]])"))) (gz construct-in-place(f :c-place (function ::is scope-qualified-id) expression-star j ::pr("[[function]][[expression-star('(',',',')')]]"))) (gz function-call(f :c (function ::is scope-qualified-id) expression-star j ::pr("[[function]][[expression-star('(',',',')')]]"))) (gz member-access (f :d expression id j ::pr("([[expression]].[[id]])")) (f :r expression id j ::pr("([[expression]]->[[id]])"))) (gz method-call (f :mc (object ::is expression) (method ::is scope-qualified-id)expression-star j ::pr("[[object]].[[method]][[expression-star('(',',',')')]]")) (f :ma (object ::is expression) (method ::is scope-qualified-id)expression-star j ::pr("[[object]]->[[method]][[expression-star('(',',',')')]]"))) (gz array-in-place (f :array-in-place expression-star j ::pr("[[expression-star('{',',','}')]]"))) (gz stream-input(f :input (a ::is expression) (b ::is expression) expression-star j ::pr("[[a]] >> [[b]]" (::c"for(many_trees::const_iterator pos=my_expression_star->v.begin();pos!=my_expression_star->v.end();++pos){") ">>" (::c "(*pos)->print();" "}") ))) (gz stream-statement(f stream-operator (a ::is expression) (b ::is expression) expression-star j ::pr("[[a]][[stream-operator]][[b]]" (::c"for(many_trees::const_iterator pos=my_expression_star->v.begin();pos!=my_expression_star->v.end();++pos){") "[[stream-operator]]" (::c "(*pos)->print();" "}")))) (gz list-expression(f list-operator (a ::is expression) (b ::is expression) expression-star j ::pr("([[a]][[list-operator]][[b]]" (::c"for(many_trees::const_iterator pos=my_expression_star->v.begin();pos!=my_expression_star->v.end();++pos){") "[[list-operator]]" (::c "(*pos)->print();" "}") ")"))) (gz binary-expression(f binary-operator (a ::is expression) (b ::is expression)j ::pr("([[a]][[binary-operator]][[b]]" ")"))) (gz array-access (f "!" (array ::is expression) expression-plus j ::pr("[[array]][[expression-plus('\x5b','\x5d\x5b','\x5d')]]"))) (gz defvar (f :var globdecl-rest init-opt j ::pr("[[globdecl-rest]] [[init-opt]]"))) (gz globdecl-rest (id-or-nothing type ::pr("[[type{my_id_or_nothing}]]"))) (gz type ::gets "tr-id-or-nothing*{name}" (f storage-opt typename-opt ref-opt array-opt pointer-star const-opt unsigned-opt long-opt scope-qualified-id template-spec-opt j ::pr("[[storage-opt]][[typename-opt]] [[const-opt]] [[unsigned-opt]] [[long-opt]] [[scope-qualified-id]][[template-spec-opt]][[pointer-star('','','')]] [[ref-opt]] " (::c "name->print();") "[[array-opt]]"))) (gz storage (:static ::pr ("static"))(:extern ::pr ("extern"))(:register ::pr("register"))) (gz typename (:typename ::pr ("typename"))) (gz id-or-nothing (scope-qualified-id)((:n ::outputs "\x20"))) (gz template-spec ( :of f abstract-type-plus j ::pr("< [[abstract-type-plus('',',','')]] >"))) (gz abstract-type (globdecl-rest)) (gz unsigned (:unsigned ::pr ("unsigned"))) (gz long (:long ::pr ("long"))) (gz scope-qualified-id (id) ('operator:paren' ::pr("operator()"))(f parenthesized-id j)) (gz parenthesized-id (:ns (ns ::is id) scope-qualified-id ::pr("[[ns]]::[[scope-qualified-id]]")) (:cl (class ::is id) template-spec-opt scope-qualified-id ::pr("[[class]][[template-spec-opt]]::[[scope-qualified-id]]"))) (gz id-non (id)) (gz ref ((:ref ::outputs "&"))) (gz init (:construct expression-star ::pr("[[expression-star('(',',',')')]]")) (:is expression ::pr("=[[expression]]"))) (gz control-stmt (if) (for) (while) (ford) (forever) (for-from-to)(for-iterator)) (gz if(f :if cond restcond-star else-opt j)) (gz cond(f expression-or-decl compound-statement j ::pr("([[expression-or-decl]])[[compound-statement]]"))) (gz restcond(f expression compound-statement j ::pr("else if([[expression]])[[compound-statement]]"))) (gz else(f :else compound-statement j)) (gz defclass(f class-or-union (name ::is id) template-spec-opt template-decl-opt inherit-opt :cbeg f classdecl-star j j ::pr("[[template-decl-opt]][[class-or-union]] [[name]][[template-spec-opt]][[inherit-opt]] {\n[[classdecl-star{my_name,'','',''}]]} ;\n"))) (gz inherit (:inherit f an-inherit-plus j ::pr(":[[an-inherit-plus('',',','')]]"))) (gz an-inherit(f (protectance ::is id)(name ::is id) j ::pr("[[protectance]] [[name]]"))) (gz forwardclass(f :forwardclass class-or-union id j ::pr("[[class-or-union]] [[id]];\n"))) (gz classdecl ::gets "tr-id*{name}" (defvar ::pr ("[[defvar]];\n" )) (defun) (forwardfunc) (pure-virtual) ((:public ::outputs "public:\n")) (construct ::pr ("[[construct{name}]]")) (destruct ::pr ("[[destruct{name}]]")) (defclass) (typedef )) (gz class-or-union((:class ::outputs "class")) ((:union ::outputs "union"))) (gz typedef (f :typedef globdecl-rest j ::pr("typedef [[globdecl-rest]];\n"))) (gz stream-operator((:out ::outputs "<<")) ((:in ::outputs ">>"))) (gz assignment-operator("=") (">>=") ("<<=") ("+=") ("*=") ("/=") ("-=") (("mod="::outputs"%=")) (("bor="::outputs"\pipe=")) (("band="::outputs"&=")) ([(":or="::outputs "\pipe\pipe=")])) (gz list-operator("+")((:and ::outputs "&&"))("*")((:or ::outputs "\pipe\pipe"))) (gz binary-operator ("-") ("<") [(">")] [(">=")] ("<=") ("==") ((:mod ::outputs "%")) ("<<") (">>") ("!=") ((:band ::outputs "&")) ("/")) (gz unary-operator((:not ::outputs "!")) ((:dr ::outputs "*")) ((:ad ::outputs "&"))((:neg ::outputs "-")) ((:bnot ::outputs "~")) ) (gz for(f :for (a ::is simple-statement-without-semi) (b ::is expression) (c ::is simple-statement-without-semi) compound-statement j ::pr("for ([[a]];[[b]];[[c]])[[compound-statement]]"))) (gz forever(f :forever-counting id compound-statement j ::pr("for (int [[id]]=0; ;++[[id]])[[compound-statement]]") )) (gz ford(f :ford id expression compound-statement j ::pr("for (int [[id]]=0;[[id]]<[[expression]];++[[id]])[[compound-statement]]"))) (gz for-iterator (f :for-iterator id typename-opt (type ::is id) expression compound-statement j ::pr("for ([[typename-opt]] [[type]]::const_iterator [[id]]=[[expression]].begin();" "[[id]]!=[[expression]].end();++[[id]])[[compound-statement]]"))) (gz for-from-to (f :for-from-to id (a ::is expression) (c ::is expression) compound-statement j ::pr("for (int [[id]]=[[a]];[[id]]<[[c]];[[id]]++)[[compound-statement]]") )) (gz while(f :while expression compound-statement j ::pr("while([[expression]])[[compound-statement]]"))) (gz include (f :include id-or-string j ::pr("#include [[id-or-string]]\n"))) (gz id-or-string (id) (qastring)) ] (:include ) (:include )(:using (:ns std cout))(:using(:ns std endl))[(:using (:ns std cerr))] (:include ) (:include ) [(:include )] (:include ) (:include ) (:include ) (:typedef real(double)) (:fun calc-escape(real)() (:x (:var escape(real) :is 1) (:ford nn 496 (:x (*= escape 2) )) (:return escape) )) (:var escape(:const real) :is (:c calc-escape)) (:var logradius2(:const real) :is (:c log escape)) (:fun do-iterations (void)((max-iterations(long))(a(real))(b(real))(didescape(:ptr bool))(outc(:ptr long))(outz2(:ptr real))(orbit(:ptr bool))) (:x (:var xfast(real):is a) (:var yfast(real):is b) [fast starts with an advantage already] (:var xslow(real):is 0) (:var yslow(real):is 0) (:var z2(real):is 0) [quell uninit warning under -O2] (:var c(long):is 0) [we do not use ford because we need the value after it exits] (:for :z (< c max-iterations)(:inc c) (:x (:var x2(real):is(* xfast xfast)) (:var y2(real):is(* yfast yfast)) (= z2 (+ x2 y2)) (:if ((< escape z2) (:x (= (:dr didescape) true) (:break)))) (= yfast (* xfast yfast 2)) (= xfast (- x2 y2)) (= x2 (* xslow xslow)) (= y2 (* yslow yslow)) (= yslow (* xslow yslow 2)) (= xslow (- x2 y2)) (:if ((:and(== xslow xfast)(== yslow yfast)) (:x (= (:dr orbit) true) (:break)))) [this mysterious ordering of operations taken from gmp-mandelbrot] (+= yfast b) (+= xfast a) (:inc c) (= x2 (* xfast xfast)) (= y2 (* yfast yfast)) (= z2 (+ x2 y2)) (:if ((< escape z2) (:x (= (:dr didescape) true) (:break)))) (= yfast (* xfast yfast 2)) (= xfast (- x2 y2)) (:if ((:and(== xslow xfast)(== yslow yfast)) (:x (= (:dr orbit) true) (:break)))) (+= xfast a) (+= yfast b) (+= xslow a) (+= yslow b) )) (= (:dr outc) c) (= (:dr outz2) z2) )) (:fun pythagoras(real)((x(real))(y(real))) (:x (:return (+ (* x x) (* y y))) )) (:fun cardoid-test(bool)((x(real))(y(real))) (:x [q=(x-{\frac {1}{4}})^{2} + y^{2}] (:var q(real):is(:c pythagoras (- x 0.25) y)) [q(q+(x-{\frac {1}{4}}))\leq {\frac {1}{4}}y^{2}.}] (:var lhs(real):is(* q (+ q (- x 0.25)))) (:var rhs(real):is(* y y 0.25)) (:return (<= lhs rhs)) ) ) (:fun first-bulb-test(bool)((x(real))(y(real))) (:x (:var lhs(real):is(:c pythagoras (+ x 1) y)) (:return (<= lhs (/ 1.0 16))) )) (:fun smooth-coloring(real)((z2(real))) (:x [_ nu = n - log_P(log z/log(N)) P=2 nu = n - log_2(log z/log(Radius)) log(sqrt(z2))/log(sqrt(Radius2)) = (0.5*log(z2))/(0.5*log(Radius2)) = log(z2)/log(Radius2) ] (:var inner(real):is (/ (:c log z2)logradius2)) (:c assert (< 0 inner)) (:var nu(real):is(/ (:c log inner) (:c log 2))) (:c assert (< 0 nu)) (:c assert (<= nu 1)) (:return nu) )) (:class wholeset :cbeg ( :public (:var name(:static :ptr :const char)) (:var realheight(:static :const real)) (:fun calcfromi(void)((height(real))(i(real))(a(:ptr real))(b(:ptr real))) (:x [mirror symmetry puts the other side at -0.5, spaced nicely 1 unit away. we also wildly claim nothing interesting happens on the real line.] [As the resolution doubles, this has the effect of putting finer tick marks between the tick marks that already exist from the lower resolution. Therefore, points don't repeat between resolutions.] (:var scale(:const real):is(:c scalecalc height)) (= (:dr b)(*(+ i 0.5)scale)) )) (:fun calcfromj(void)((height(real))(j(real))(a(:ptr real))(b(:ptr real))) (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr a) (-(* j scale)realheight)) )) (:fun scalecalc(:static real)((height(real))) (:x [(:out (:ns std cerr) "scalecalc " height endl)] (:return (/ realheight height)) )) )) (:var (:ns wholeset name)(:ptr :const char):is "Whole Mandelbrot set") (:var (:ns wholeset realheight)(:const real):is(/ (* 15 9) 64.0)) (:class beyondthetip :cbeg ( :public (:var name(:static :ptr :const char)) (:var realheight(:static :const real)) (:fun calcfromi(void)((height(real))(i(real))(a(:ptr real))(b(:ptr real))) (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr b)(*(+ i 0.5)scale)) [see notes in wholeset about 0.5] )) (:fun calcfromj(void)((height(real))(j(real))(a(:ptr real))(b(:ptr real))) (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr a) (- (* j scale)2)) )) (:fun scalecalc(:static real)((height(real))) (:x [(:out (:ns std cerr) "scalecalc " height endl)] (:return (/ realheight height)) )) )) (:var (:ns beyondthetip name)(:ptr :const char):is "Antenna") (:var (:ns beyondthetip realheight)(:const real):is(/ (* 15 3) 128.0)) (:class seahorsevalley :cbeg (:public (:var name(:static :ptr :const char)) (:var realheight(:static :const real)) (:fun calcfromi(void)((height(real))(i(real))(a(:ptr real))(b(:ptr real))) [now this should modify a] [i ranges over height] (:x [center point is -0.75 and we desire approximately 1/16 on each side] (:var centerpoint(:const real):is (:neg 0.75)) (:var scale(:const real):is(:c scalecalc height)) (= (:dr a) (+ (* i scale) (- centerpoint (/ realheight 2)))) [emphasize the coordinates are exact binary numbers] )) (:fun calcfromj(void)((height(real))(j(real))(a(:ptr real))(b(:ptr real))) [this should modify b] [j ranges over width = 2*height] (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr b) (* j scale)) )) (:fun scalecalc(:static real)((height(real))) (:x (:return (/ realheight height)))) )) (:var (:ns seahorsevalley realheight)(:const real):is(/ (* 15.0 5) 512) [approximately 1/8]) (:var (:ns seahorsevalley name)(:ptr :const char):is"Seahorse Valley") [this one is smaller] (:class cardoidcusp :cbeg ( :public (:var name(:static :ptr :const char)) (:var realheight(:static :const real)) (:fun calcfromi(void)((height(real))(i(real))(a(:ptr real))(b(:ptr real))) [now this should modify a] [i ranges over height] (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr a) (+ (* i scale) 0.25)) [emphasize the coordinates are exact binary numbers] )) (:fun calcfromj(void)((height(real))(j(real))(a(:ptr real))(b(:ptr real))) [this should modify b] [j ranges over width = 2*height] (:x (:var scale(:const real):is(:c scalecalc height)) (= (:dr b) (* j scale)) )) (:fun scalecalc(:static real)((height(real))) (:x (:return (/ realheight height)))) )) (:var (:ns cardoidcusp name)(:ptr :const char):is"Elephant Valley") (:var (:ns cardoidcusp realheight)(:const real):is(/(* 25 15.0)1024)) [. generating profiling g++ -Wall -O3 -fprofile-generate -march=native -mtune=native -o prof ~/cplay/ultimate-mandelbrot2.ll.cc ./prof calc 16 0 0 18664 75438 g++ -Wall -O3 -fprofile-use -march=native -mtune=native -o x.umrun ~/cplay/ultimate-mandelbrot2.ll.cc prof improves speed from 87 to 77 seconds mtune was 90 seconds ] [cardoidcusp seahorsevalley wholeset beyondthetip] (:typedef MYREGION (wholeset)) (:fun do-calc(int)((argc(int))(argv(:ptr :ptr char))) (:x (:if ((< argc 7) (:x (:out (:ns std cerr) "need params do-calc" endl) (:return 1) ))) (:var height(:const int) :is (<< 15 (:c atoi (! argv 2)))) (:var totalsplits(int):is(<< 1 (:c atoi (! argv 3)))) (:var mysplit(int):is(:c atoi (! argv 4))) (:var i(int):is(:c atoi (! argv 5))) (:var j(int):is(:c atoi (! argv 6))) (:out cout "$Id: ultimate-mandelbrot2.ll,v 1.39 2019/09/10 06:49:21 kenta Exp $" endl) (:var region(MYREGION)) (:out cout "height " height " totalsplits " totalsplits " mysplit " mysplit " i " i " j " j " scale " (:c (:ns std setprecision) 20) (:mc region scalecalc height) endl) (:out cout "name " (:d region name) endl) (:var piecesize(int):is(/ height totalsplits)) (:var mystart(int):is(* piecesize mysplit)) (+= i mystart) (:out cout "actual i " i endl) (:c assert (< i height)) (:c assert (< j (* 2 height))) (:var a(real)) (:var b(real)) (:mc region calcfromi height i (:ad a)(:ad b)) (:mc region calcfromj height j (:ad a)(:ad b)) (:c printf "a+bi~= %.21f %.21f\n" a b) ["Lf" for long double] (:c assert (:not (:c cardoid-test a b))) (:c assert (:not (:c first-bulb-test a b))) (:var didescape(bool):is false) (:var orbit(bool):is false) (:var c(long)) (:var z2(real)) (:var max-iterations(:const long):is (<< (:sc :n(long) 1 ) 62)) (:c do-iterations max-iterations a b (:ad didescape) (:ad c)(:ad z2)(:ad orbit)) (:out cout "orbit " orbit " didescape " didescape endl) (:if (orbit (:x (:out cout "orbitcount " c endl))) ((:not didescape) (:x (:out cout "still could not find orbit!" endl) )) (:else (:x (:out cout c) (:c printf " %.20e\n" z2) [Le for long double] )) ) (:return 0) )) (:fun main(int)((argc(int))(argv(:ptr :ptr char))) (:x (:if ((< argc 2) (:x (:out (:ns std cerr) "need params" endl) (:return 1) ))) (:if ((== 0 (:c strcmp (! argv 1) "calc")) (:x (:return (:c do-calc argc argv)) ))) (:if ((< argc 6) (:x (:out (:ns std cerr) "need params" endl) (:return 1) ))) (:var log((:ns std ofstream))) (:mc log open (! argv 3)) (:if ((:mc log is-open) (:x (:out (:ns std cerr) "logfile " (! argv 3)endl) )) (:else (:x (:out (:ns std cerr) "could not open log" endl) (:return 1) ))) (:out log "$Id: ultimate-mandelbrot2.ll,v 1.39 2019/09/10 06:49:21 kenta Exp $" endl) (:out log "escape " escape endl) (:var height(:const int) :is (<< 15 (:c atoi (! argv 1)))) (:var width(:const int):is (* 2 height)) (:var max-iterations(:const long):is (<< (:sc :n(long) 1 ) (:c atoi (! argv 2) ))) (:out log width"x"height " " max-iterations endl) (:var totalsplits(int):is(<< 1 (:c atoi (! argv 4)))) (:out log "totalsplits " totalsplits endl) (:var mysplit(int):is(:c atoi (! argv 5))) (:out log "mysplit " mysplit endl) (:var piecesize(int):is(/ height totalsplits)) (:var mystart(int):is(* piecesize mysplit)) (:var myend(int):is(+ mystart piecesize)) (:out log "mystart "mystart" myend " myend " piecesize " piecesize endl) (:var hard(long):is 0) (:var maxseeniterations(long):is 0) [ see ~/r/mandelbrot-notes ] (:var region(MYREGION)) (:out log "name " (:d region name) endl) (:out log "sizeof real " (:c sizeof real) endl) (:var buffer(:ptr float):is(:new-array :n(float) piecesize)) (:c assert buffer) [generate by columns because it compresses better] (:ford j width (:x (:var a(real)) (:var b(real)) (:mc region calcfromj height j (:ad a)(:ad b)) (:for-from-to i mystart myend (:x (:mc region calcfromi height i (:ad a)(:ad b)) (:var c(long)) (:var z2(real)) (:if ((:c cardoid-test a b) (:x (= z2 (:neg 1)))) ((:c first-bulb-test a b) (:x (= z2 (:neg 2)))) (:else (:x (:var didescape(bool):is false) (:var orbit(bool):is false) (:c do-iterations max-iterations a b (:ad didescape) (:ad c)(:ad z2)(:ad orbit)) (:if (orbit (:x (= z2 (:neg 4)) (:if ((< maxseeniterations c) (:x (= maxseeniterations c) (:out log "new max " maxseeniterations " " j " " i" a+bi~= " (:c(:ns std setprecision)20)a" " b endl) ))) )) ((:not didescape) (:x (:inc hard) (= z2 (:neg 3)))) (:else (:x (:var nu(real):is (:c smooth-coloring z2)) (= z2 (- c nu)) [ add 1? ] )) ) ))) [(:out cout a " " b " " c " " z2 " " endl)] [(:c fwrite (:ad c) (:c sizeof c) 1 stdout)] (= (! buffer (- i mystart)) z2) [(:var fz2(float):is z2) (:c fwrite (:ad fz2) (:c sizeof fz2) 1 stdout)] )) (:c fwrite buffer (:c sizeof float) piecesize stdout) )) [(:out cerr "numin numax " numin " " numax endl)] (:out log "hard " hard endl) (:out log "maxseeniterations " maxseeniterations endl) ))