about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-21 17:19:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-21 17:19:52 -0700
commitf7a2671901bc396ecd5578ba624c4532d6bbf4f3 (patch)
treed64e0eacb0aeef937297a05407ecd2366c82f910
parent963711e4cbc1c87314f66310da2d6f89aa471907 (diff)
downloadmu-f7a2671901bc396ecd5578ba624c4532d6bbf4f3.tar.gz
1119 - preparing to start porting chessboard
Arc version is 15% faster (8.3s vs 9.9s for print-board test) if I use
an intermediate array rather than list. I'm starting to question the
whole tagged-value design, and the current tagged-value implementation
was treating squares as integers in one place anyway, so its benefits
for typing are not great. Might as well create a good baseline for the
Arc vs C++ performance test.
-rw-r--r--chessboard.arc.t10
-rw-r--r--chessboard.mu39
-rw-r--r--mu.arc34
3 files changed, 61 insertions, 22 deletions
diff --git a/chessboard.arc.t b/chessboard.arc.t
index c5698f00..3fac1a7a 100644
--- a/chessboard.arc.t
+++ b/chessboard.arc.t
@@ -154,7 +154,8 @@
 (new-trace "print-board")
 (run-code main
   (default-space:space-address <- new space:literal 30:literal/capacity)
-  (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
+;?   ($print (("init-array\n" literal))) ;? 1
+  (initial-position:integer-array-address <- init-array ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
                                               ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
                                               ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
                                               ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
@@ -162,7 +163,8 @@
                                               ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
                                               ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
                                               ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
-  (b:board-address <- init-board initial-position:list-address)
+;?   ($print (("init-board\n" literal))) ;? 1
+  (b:board-address <- init-board initial-position:integer-array-address)
   (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
   (print-board screen:terminal-address b:board-address)
   (1:string-address/raw <- get screen:terminal-address/deref data:offset)
@@ -194,7 +196,7 @@
   ; fake screen
   (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
   ; initial position
-  (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
+  (initial-position:integer-array-address <- init-array ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
                                               ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
                                               ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
                                               ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
@@ -202,7 +204,7 @@
                                               ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
                                               ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
                                               ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
-  (b:board-address <- init-board initial-position:list-address)
+  (b:board-address <- init-board initial-position:integer-array-address)
   ; move: a2-a4
   (m:move-address <- new move:literal)
   (f:integer-integer-pair-address <- get-address m:move-address/deref from:offset)
diff --git a/chessboard.mu b/chessboard.mu
index 7c0fc0c5..45fc12da 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -9,19 +9,21 @@
 
 (function init-board [
   (default-space:space-address <- new space:literal 30:literal)
-  (initial-position:list-address <- next-input)
+  (initial-position:integer-array-address <- next-input)
   ; assert(length(initial-position) == 64)
-  (len:integer <- list-length initial-position:list-address)
+;?   ($print initial-position:integer-array-address/deref) ;? 1
+  (len:integer <- length initial-position:integer-array-address/deref)
+;?   ($print len:integer) ;? 1
+;?   ($print (("\n" literal))) ;? 1
   (correct-length?:boolean <- equal len:integer 64:literal)
   (assert correct-length?:boolean (("chessboard had incorrect size" literal)))
   (b:board-address <- new board:literal 8:literal)
   (col:integer <- copy 0:literal)
-  (curr:list-address <- copy initial-position:list-address)
   { begin
     (done?:boolean <- equal col:integer 8:literal)
     (break-if done?:boolean)
     (file:file-address-address <- index-address b:board-address/deref col:integer)
-    (file:file-address-address/deref curr:list-address <- init-file curr:list-address)
+    (file:file-address-address/deref <- init-file initial-position:integer-array-address col:integer)
     (col:integer <- add col:integer 1:literal)
     (loop)
   }
@@ -30,20 +32,21 @@
 
 (function init-file [
   (default-space:space-address <- new space:literal 30:literal)
-  (cursor:list-address <- next-input)
+  (position:integer-array-address <- next-input)
+  (index:integer <- next-input)
+  (index:integer <- multiply index:integer 8:literal)
   (result:file-address <- new file:literal 8:literal)
   (row:integer <- copy 0:literal)
   { begin
     (done?:boolean <- equal row:integer 8:literal)
     (break-if done?:boolean)
-    (src:tagged-value-address <- list-value-address cursor:list-address)
     (dest:square-address <- index-address result:file-address/deref row:integer)
-    (dest:square-address/deref <- get src:tagged-value-address/deref payload:offset)  ; unsafe typecast
-    (cursor:list-address <- list-next cursor:list-address)
+    (dest:square-address/deref <- index position:integer-array-address/deref index:integer)
     (row:integer <- add row:integer 1:literal)
+    (index:integer <- add index:integer 1:literal)
     (loop)
   }
-  (reply result:file-address cursor:list-address)
+  (reply result:file-address)
 ])
 
 (function print-board [
@@ -206,15 +209,15 @@
 
 (function chessboard [
   (default-space:space-address <- new space:literal 30:literal)
-  (initial-position:list-address <- init-list ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
-                                              ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
-                                              ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
-                                              ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
-                                              ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal))
-                                              ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
-                                              ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
-                                              ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
-  (b:board-address <- init-board initial-position:list-address)
+  (initial-position:integer-array-address <- init-array ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal))
+                                                        ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+                                                        ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+                                                        ((#\Q literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\q literal))
+                                                        ((#\K literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\k literal))
+                                                        ((#\B literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\b literal))
+                                                        ((#\N literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\n literal))
+                                                        ((#\R literal)) ((#\P literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\_ literal)) ((#\p literal)) ((#\r literal)))
+  (b:board-address <- init-board initial-position:integer-array-address)
   (cursor-mode)
   ; hook up stdin
   (stdin:channel-address <- init-channel 1:literal)
diff --git a/mu.arc b/mu.arc
index 292126b3..d95ae335 100644
--- a/mu.arc
+++ b/mu.arc
@@ -936,6 +936,9 @@
                         (if (len> caller-args.routine* idx)
                           (list caller-args.routine*.idx t)
                           (list nil nil))))
+                rewind-inputs
+                  (do1 nil
+                       (= caller-arg-idx.routine* 0))
                 ; type and otype won't always easily compile. be careful.
                 type
                   (ty (caller-operands.routine* (v arg.0)))
@@ -1934,6 +1937,37 @@
   (result:list-address <- list-next result:list-address)  ; memory leak
   (reply result:list-address))
 
+; create an array out of a list of scalar args
+; only integers for now
+(init-fn init-array
+  (default-space:space-address <- new space:literal 30:literal)
+  (capacity:integer <- copy 0:literal)
+  { begin
+    ; while read curr-value
+    (curr-value:integer exists?:boolean <- next-input)
+    (break-unless exists?:boolean)
+    (capacity:integer <- add capacity:integer 1:literal)
+    (loop)
+  }
+  (result:integer-array-address <- new integer-array:literal capacity:integer)
+  (rewind-inputs)
+;?   (xxx:integer <- next-input) ;? 1
+;?   ($print xxx:integer) ;? 1
+;?   (rewind-inputs) ;? 1
+  (i:integer <- copy 0:literal)
+  { begin
+    ; while read curr-value
+    (done?:boolean <- greater-or-equal i:integer capacity:integer)
+    (break-if done?:boolean)
+    (curr-value:integer exists?:boolean <- next-input)
+    (assert exists?:boolean)
+    (tmp:integer-address <- index-address result:integer-array-address/deref i:integer)
+    (tmp:integer-address/deref <- copy curr-value:integer)
+    (i:integer <- add i:integer 1:literal)
+    (loop)
+  }
+  (reply result:integer-array-address))
+
 (init-fn list-length
   (default-space:space-address <- new space:literal 30:literal)
   (curr:list-address <- next-input)