• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版ff384e39f1a4342afc72e1e7b1abe6650caf934a (tree)
时间2022-04-12 12:25:31
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Fix an incorrect optimization.

更改概述

差异

--- a/cammy-rpy/draw.py
+++ b/cammy-rpy/draw.py
@@ -2,7 +2,7 @@
22
33 import math, sys
44
5-from rpython.rlib.jit import JitDriver, unroll_safe #, set_param
5+from rpython.rlib.jit import JitDriver, unroll_safe, set_param
66 from rpython.rlib.rfile import create_stdio
77 from rpython.rlib.rfloat import string_to_float
88 from rpython.rlib.rstring import StringBuilder, split
@@ -98,7 +98,7 @@ def drawPNG(program, filename, corners, width, height):
9898
9999
100100 def main(argv):
101- # set_param(None, "trace_limit", 50001)
101+ set_param(None, "trace_limit", 50001)
102102
103103 prog = argv[1]
104104 window = [string_to_float(s) for s in split(argv[2])]
--- a/hive/demo/burning-ship-color.cammy
+++ b/hive/demo/burning-ship-color.cammy
@@ -1,7 +1,7 @@
11 (comp
22 (comp
3- (fractal-membership-color v2/burning-ship (comp nat/8 succ))
4- (monads/maybe/guard (pair/of nat/lte id (fun/const nat/8))))
3+ (fractal-membership-color v2/burning-ship (comp nat/16 succ))
4+ (monads/maybe/guard (pair/of nat/lte id (fun/const nat/16))))
55 (case
66 (comp (comp nat/to-f f/radians-to-turns) h2rgb)
77 (v3/broadcast f-zero)))
--- a/jelly/src/main.rs
+++ b/jelly/src/main.rs
@@ -26,7 +26,7 @@ fn load_tree(handle :&mut Read) -> std::io::Result<RecExpr<SymbolLang>> {
2626
2727 // Rules marked "associative!" can cause explosions.
2828
29-// Rules marked "improvement!" can improve IEEE 754 results in both precision and accuracy, so
29+// Rules marked "improvement!" can improve IEEE 754 results in both precision and/or accuracy, so
3030 // cannot be run backwards.
3131
3232 fn main() -> std::io::Result<()> {
@@ -95,7 +95,7 @@ fn main() -> std::io::Result<()> {
9595
9696 rw!("list-elim-fold"; "(fold nil cons)" => "id"),
9797 rw!("list-unroll-fold-nil"; "(comp nil (fold ?x ?f))" => "?x"),
98- rw!("list-unroll-fold-cons"; "(comp cons (fold ?x ?f))" => "(comp (pair fst (fold ?x ?f)) ?f)"),
98+ rw!("list-unroll-fold-cons"; "(comp cons (fold ?x ?f))" => "(comp (pair fst (comp snd (fold ?x ?f))) ?f)"),
9999
100100 // 2 = 1 + 1
101101 rw!("bool-t-either"; "(comp t either)" => "left"),
@@ -141,7 +141,7 @@ fn main() -> std::io::Result<()> {
141141 ];
142142
143143 let tree = load_tree(&mut std::io::stdin())?;
144- eprintln!("Input expression has cost {}", AstSize.cost_rec(&tree));
144+ eprintln!("Input expression has size {}", AstSize.cost_rec(&tree));
145145
146146 let runner = Runner::default().with_expr(&tree).run(rules);
147147 eprintln!("E-graph finished running: {:?} after {} iterations", runner.stop_reason.unwrap(),
@@ -149,7 +149,8 @@ fn main() -> std::io::Result<()> {
149149
150150 let mut extractor = Extractor::new(&runner.egraph, AstSize);
151151 let (best_cost, best_expr) = extractor.find_best(runner.roots[0]);
152- eprintln!("Best expression has cost {}", best_cost);
152+ // eprintln!("Best expression has size {} and cost {}", best_cost);
153+ eprintln!("Input expression has size {}", AstSize.cost_rec(&best_expr));
153154
154155 std::io::stdout().write_all(best_expr.pretty(78).as_bytes());
155156 std::io::stdout().write_all(b"\n")
--- a/todo.txt
+++ b/todo.txt
@@ -89,12 +89,22 @@
8989 * Homs: pointer to heap-allocated array of two cells
9090 * The first cell is a code pointer
9191 * The second cell is the curried data
92-* Finish CAM
93- * curry/uncurry: write code to new code area, jump to code, call stack
94- * pr/fold: test and jump
95- * pr: pred?
96- * fold: testing for nil, pushing cells in correct order, pairing
97- * lists should use cons cells
98- * current lists are more like arrays...
92+* Optimize CAM
93+ * Peepholes: Several standard improvements are possible
94+ * Atomic instruction emitters would be augmented with ability to look
95+ backwards and cancel out or amend previous instructions
96+ * Taking a label would create a code barrier, to avoid having to
97+ recompute jumps
98+ * TCO, or really any call optimizations
99+ * snoc and other backwards versions of ops
99100 * fun/precomp is an ingredient of CPS transformation
100101 * https://okmij.org/ftp/continuations/undelimited.html
102+* A serious cost model
103+ * Current jelly cost model is AstSize
104+ * O(1) is incorrect for some operations
105+ * Even constant ops have differing costs
106+ * New cost model based on CAM
107+ * id, comp, cons are all free now!
108+ * fst, snd are "term ops", don't touch stack
109+ * so is nearly all of ALU, but fst, snd are also removable by JIT
110+ * in general, ALU ops are more expensive than stack ops!