├── .gitattributes ├── .gitignore ├── AUTHOR ├── LICENSE ├── Makefile ├── README.md ├── TODO ├── cforth_tools ├── Makefile ├── OkadBack.cf ├── addlabel.py ├── cf2f.py ├── cfword.py ├── f2cf.py ├── hello.cfs ├── relative.py └── template.cfs ├── configure.py ├── examples ├── actor │ ├── actor_pair.cll │ ├── actor_v1.cll │ ├── actor_v2.cll │ ├── actor_v3.cll │ ├── actor_v4.cll │ ├── actor_v5.cll │ ├── sactor_arg.cll │ ├── sactor_before.cll │ ├── sactor_dup.cll │ ├── sactor_multicalls.cll │ ├── sactor_v1.cll │ ├── sactor_v2.cll │ ├── sactor_v3.cll │ ├── sactor_v4.cll │ ├── sactor_v5.cll │ └── sactor_v6.cll ├── bithack │ ├── bithack1.cll │ ├── bithack2.cll │ ├── bithack3.cll │ ├── ceil_avg.cll │ ├── count.cll │ ├── cycle.cll │ ├── exchange.cll │ ├── floor_avg.cll │ ├── haszerobyte.cll │ ├── intro.cll │ └── roundpower.cll ├── cluster │ └── cluster.cll ├── fixedpoint │ ├── cos_radius.cll │ ├── cos_round.cll │ ├── fft_inplace.cll │ ├── fft_working.cll │ └── hello.cll ├── future │ ├── disparity.cll │ ├── gaussseidel.cll │ ├── gaussseidel2.cll │ ├── insertionsort.cll │ └── ssd.cll ├── io │ ├── blink.cll │ ├── blink2.cll │ ├── crystal-oscillator.cll │ ├── simple-wait.cll │ └── square-wave.cll ├── mapreduce │ ├── map-pair.cll │ ├── map.cll │ ├── mapreduce.cll │ ├── reduce-pair.cll │ └── reduce.cll ├── matrixmultiply │ ├── matrixmult-noplace.cll │ ├── matrixmult4-dup.cll │ ├── matrixmult4.cll │ └── matrixmult6.cll ├── md5 │ ├── assume.cll │ ├── leftrotate.cll │ ├── md1-circular2.cll │ ├── md1-optopt.cll │ ├── md1-rightrot-noassume.cll │ ├── md1-rightrot.cll │ ├── md2-noopt-rightrot.cll │ ├── md2-noopt.cll │ ├── md3-nolayout.cll │ └── md5-rightrot-sim.cll ├── module │ ├── module_concrete.cll │ ├── module_global.cll │ ├── module_mapreduce.cll │ ├── module_pair.cll │ ├── module_pinning.cll │ └── module_simple.cll ├── parallel │ ├── convolution-noghost.cll │ ├── convolution-pair.cll │ ├── convolution.cll │ ├── prefixsum.cll │ ├── ssd-heu.cll │ ├── ssd.cll │ └── swap.cll ├── rom │ ├── complex0.cll │ ├── complex1.cll │ ├── complex2.cll │ ├── complex3.cll │ ├── cos.cll │ ├── div17.cll │ ├── fir-par2.cll │ ├── fir-par4.cll │ ├── fir.cll │ ├── interp.cll │ ├── poly.cll │ ├── simple.cll │ ├── sqrt0.cll │ ├── sqrt1.cll │ └── sqrt2.cll ├── sensors │ ├── accelerometer.cll │ ├── compiled-code │ │ ├── README │ │ ├── accelerometer-noopt3.aforth │ │ ├── accelerometer-power-meas.aforth │ │ ├── codesize-comp │ │ │ ├── complete.aforth │ │ │ ├── complete.info │ │ │ ├── noactor.aforth │ │ │ ├── noactor.info │ │ │ ├── nolayout.aforth │ │ │ └── nolayout.info │ │ ├── guesture-recognition-msp430-sim.aforth │ │ ├── guesture-recognition-opt.aforth │ │ ├── hmm-filter13-noacc.aforth │ │ ├── hmm-filter13-sim.aforth │ │ ├── hmm-noacc.aforth │ │ ├── hmm-sim.aforth │ │ └── processing-power-meas.aforth │ ├── filter13.cll │ ├── hmm.cll │ ├── hmm_allactors.cll │ ├── hmm_noactor.cll │ ├── hmm_nolayout.cll │ ├── hmm_one_module.cll │ └── hmm_print.cll ├── sha │ ├── sha.cll │ ├── sha_f1.cll │ └── sha_f2.cll ├── simple │ ├── add.cll │ ├── array.cll │ ├── array2.cll │ ├── assign.cll │ ├── extendshift.cll │ ├── function-pair.cll │ ├── function.cll │ ├── function2.cll │ ├── hello-io.cll │ ├── hello.cll │ ├── if.cll │ ├── offset.cll │ ├── pair1.cll │ ├── pair2.cll │ ├── part2core.cll │ ├── square.cll │ ├── unroll.cll │ └── while.cll └── super │ ├── large │ ├── ceil.rkt │ ├── count_a.rkt │ ├── floor.rkt │ ├── interp_large.rkt │ └── roundpower.rkt │ ├── programs │ └── small │ ├── complexA.rkt │ ├── complexB.rkt │ ├── complexC.rkt │ ├── fff.rkt │ ├── fir.rkt │ ├── ggg.rkt │ ├── hhh.rkt │ ├── iii.rkt │ ├── iii_ex.rkt │ ├── interp.rkt │ ├── rrotate.rkt │ ├── sha_fa-opt-nolenlimit.rkt │ ├── sha_fa-opt-nolenlimit.time │ ├── sha_fa-opt.aforth │ ├── sha_fa-opt.time │ ├── sha_fa.stat │ ├── shaf_a.rkt │ ├── shaf_b.rkt │ └── test.rkt ├── src ├── README ├── a-star.rkt ├── arrayforth-basic-optimize.rkt ├── arrayforth-def.rkt ├── arrayforth-miner.rkt ├── arrayforth-optimize.rkt ├── arrayforth-print.rkt ├── arrayforth.rkt ├── ast-util.rkt ├── ast.rkt ├── chlorophyll-test.rkt ├── chlorophyll.rkt ├── communication.cpp ├── compiler.rkt ├── exp.rkt ├── header.rkt ├── layout-rohin │ ├── layout-map.rkt │ ├── layout-tests │ │ ├── md5.in │ │ ├── ssd.in │ │ ├── strangeness.rkt │ │ └── test-layout.rkt │ ├── layout.rkt │ └── nmap.rkt ├── layout-sa.rkt ├── optimize-distributor.rkt ├── parser.rkt ├── partition-storage.rkt ├── partitioner.rkt ├── qap │ ├── graph2matrix.py │ ├── sa_qap.cpp │ └── sa_qap_fix.cpp ├── routing.rkt ├── separator.rkt ├── space-estimator.rkt ├── symbolic │ ├── ops-rosette.rkt │ ├── simulator.rkt │ ├── test-simulator.rkt │ └── test-simulator2.rkt ├── synthesizer.rkt ├── test-compiler.rkt ├── test-miner.rkt ├── test-partitioner.rkt ├── test-simulator.rkt ├── visitor-arrayaccess.rkt ├── visitor-cloner.rkt ├── visitor-codegen.rkt ├── visitor-collector.rkt ├── visitor-comminsert.rkt ├── visitor-cprinter.rkt ├── visitor-desugar.rkt ├── visitor-divider.rkt ├── visitor-evaluator.rkt ├── visitor-expr-interpreter.rkt ├── visitor-flow.rkt ├── visitor-funccalllink.rkt ├── visitor-heupartition.rkt ├── visitor-initial.rkt ├── visitor-interface.rkt ├── visitor-interpreter.rkt ├── visitor-linker.rkt ├── visitor-loopbound.rkt ├── visitor-loopopt.rkt ├── visitor-lowerbound.rkt ├── visitor-mapreduce.rkt ├── visitor-memory.rkt ├── visitor-module-expander.rkt ├── visitor-offset.rkt ├── visitor-placeset.rkt ├── visitor-placetype.rkt ├── visitor-postunroll.rkt ├── visitor-printer.rkt ├── visitor-regalloc.rkt ├── visitor-rename.rkt ├── visitor-tempinsert.rkt ├── visitor-tempinsert2.rkt ├── visitor-tempremove.rkt └── visitor-unroll.rkt ├── testdata ├── 1 ├── 2 ├── 10 ├── 72 ├── 136 ├── 200 ├── 232 ├── 4_1 ├── 4_2 ├── gen.py ├── md5 ├── null └── out │ ├── add_200.out │ └── if_4_1.out └── tests ├── add-pair.cll ├── add.cll ├── for-array-fancy.cll ├── for-array-fancy2.cll ├── for-array1.cll ├── for-array2.cll ├── for-array3.cll ├── for-array4.cll ├── for-array5.cll ├── function.cll ├── function2.cll ├── if_concrete.cll ├── if_symbolic.cll ├── space_concrete.cll ├── space_symbolic.cll └── while.cll /.gitattributes: -------------------------------------------------------------------------------- 1 | *.cf linguist-language=Forth 2 | *.cfs linguist-language=Forth 3 | *.aforth linguist-language=Forth 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | compiled/* 2 | testdata/out* 3 | src/qap/sa_qap 4 | *output-* 5 | 6 | *~ 7 | */compiled/* 8 | *.bestsofar 9 | *.block 10 | *.dat 11 | *.cpp 12 | *.graph 13 | *.layout 14 | *.part 15 | *.tmp 16 | 17 | !output/communication.cpp 18 | -------------------------------------------------------------------------------- /AUTHOR: -------------------------------------------------------------------------------- 1 | Phitchaya Mangpo Phothilimthana 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 University of California, Berkeley. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | * Redistributions of source code must retain the above copyright 6 | notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | * Neither the name of the nor the 11 | names of its contributors may be used to endorse or promote products 12 | derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 18 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | python configure.py 3 | raco make src/compiler.rkt 4 | raco exe src/chlorophyll.rkt 5 | raco exe src/chlorophyll-test.rkt 6 | 7 | clean: 8 | rm src/chlorophyll src/chlorophyll-test src/output*.tmp 9 | rm -r examples/*/output-* src/compiled 10 | 11 | 12 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO 2 | - should allow to cast from int <--> fixed point 3 | (right now only allowed at the function boundary) 4 | - rethink key for cache (no mem-size, etc.) 5 | - other optimizations: dce, instr fetch, first order funcs 6 | - no need to use lock in cache.rkt 7 | 8 | FASTER PARTITIONER 9 | - infer each function first (see issue about racket) 10 | 11 | ISSUE ABOUT RACKET 12 | - incremental solving not working 13 | - branch debug 14 | 15 | MEMO 16 | - same VarDecl => same sym-place!!! 17 | 18 | BENCHMARKS 19 | * faster sqrt 20 | - matrix multiply 21 | - insertion sort 22 | - mergesort (function, recursion) 23 | - disparity 24 | - transpose 25 | - DP (activity scheduling) 26 | - fibonacci 27 | - shortest path 28 | - MST 29 | - DFS, BFS 30 | - heap 31 | - blackscholes (float, log, exp) 32 | - FFT 33 | 34 | PARALLEL MODULE 35 | - (clone ast) is very confusing 36 | -------------------------------------------------------------------------------- /cforth_tools/Makefile: -------------------------------------------------------------------------------- 1 | CF2F=./cf2f.py 2 | F2CF=./f2cf.py 3 | BACK_CF=./OkadBack.cf 4 | WORK_CF=$(DESTDIR)/OkadWork.cf 5 | NEW_CFS=template.cfs 6 | 7 | all: work.cf 8 | 9 | back.cf: $(BACK_CF) 10 | cp $(BACK_CF) back.cf 11 | 12 | work.cf: $(NEW_CFS) back.cf 13 | cp back.cf work.cf 14 | $(F2CF) $(NEW_CFS) work.cf 15 | 16 | work.cfs: work.cf 17 | $(CF2F) work.cf > work.cfs 18 | 19 | back.cfs: back.cf 20 | $(CF2F) back.cf > back.cfs 21 | 22 | diff: back.cfs work.cfs 23 | diff back.cfs work.cfs | tee diff.log 24 | 25 | install: work.cf 26 | cp work.cf $(WORK_CF) 27 | cp work.cf OkadWork.cf 28 | 29 | clean: 30 | rm -f back.cfs work.cf work.cfs OkadWork.cf 31 | -------------------------------------------------------------------------------- /cforth_tools/OkadBack.cf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mangpo/chlorophyll/ab6d4268c5d12aa66eff817c678aaf7ebf935ba7/cforth_tools/OkadBack.cf -------------------------------------------------------------------------------- /cforth_tools/addlabel.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 'add labels to assembly-language dump' 3 | import sys, os, re 4 | from collections import defaultdict 5 | WATCHED = ['js', 'jns', 'jz', 'jnz', 'jc', 'jnc', 'jg', 'jng', 'loop', 'loope'] 6 | TARGETS = {} 7 | BY_ADDRESS = {} 8 | LABELS = defaultdict(list) 9 | def find_unlabeled(contents): 10 | 'find all lines with hard-coded addresses we need to fix' 11 | for line in list(contents): 12 | if line[:27].isspace() and line.split()[0].endswith(':'): 13 | parts = [line[0:27]] + line[27:].split() 14 | label = parts[1][:-1] # chop colon 15 | number = address(label) 16 | print 'label %s = %s' % (label, number) 17 | LABELS[number].append(label) 18 | else: 19 | parts = [line[0:28]] + line[28:].split() 20 | if parts[0][0].isdigit(): 21 | BY_ADDRESS[int(parts[0].split()[0], 16)] = line 22 | if len(parts) > 2 and parts[1] in WATCHED and parts[2].startswith('0x'): 23 | target = parts[2] 24 | number = address(target) 25 | TARGETS[number] = [target, line] 26 | print 'target %s = %s' % (target, number) 27 | def readfile(filename): 28 | 'read in a file, closing it properly' 29 | input = open(filename) 30 | data = map(str.rstrip, input.readlines()) 31 | input.close() 32 | return data 33 | def writefile(filename, contents): 34 | 'write out a file, closing it properly' 35 | output = open(filename, 'w') 36 | for line in contents: 37 | print >>output, line 38 | output.close() 39 | def address(label): 40 | 'return the address of a label as number' 41 | match = re.compile('[a-z]*0x([0-9a-f]+)').match(label) 42 | if match: 43 | return int(match.groups()[0], 16) 44 | def fixup(filename): 45 | 'edit the file in-place, adding labels where needed' 46 | contents = readfile(filename) 47 | find_unlabeled(contents) 48 | for number in TARGETS: 49 | target, line = TARGETS[number] 50 | label = '' 51 | if number in LABELS: 52 | label = LABELS[number][0] 53 | else: 54 | if number in BY_ADDRESS: 55 | label = 'branch' + target 56 | LABELS[number] = [label] 57 | label_line = BY_ADDRESS[number] 58 | index = contents.index(label_line) 59 | contents.insert(index, (' ' * 27) + label + ':') 60 | if label: 61 | index = contents.index(line) 62 | print 'replacing %s in "%s" with %s' % (target, line, label) 63 | contents[index] = line.replace(target, label, 1) 64 | writefile(filename, contents) 65 | if __name__ == '__main__': 66 | print fixup(sys.argv[1]) 67 | -------------------------------------------------------------------------------- /cforth_tools/hello.cfs: -------------------------------------------------------------------------------- 1 | {block 200} 2 | ( user f18 code) reclaim 790 load | br 3 | 4 | {block 202} 5 | ( ga application tools) 6 | : a-com [ 10 ] ; | * 7 | : a-bps 921600 ; 8 | : c-com [ 3 ] ; | * 9 | : c-bps 921600 ; 10 | : host 206 ; | * 11 | : target 208 ; | , 12 | 13 | ( modules) | * 14 | : sram [ 264 ] ; | * 15 | : pf [ 360 ] ; | * 16 | : ether [ 720 ] ; | , 17 | 18 | ( utils) | * 19 | : streamer [ 282 ] ; | * 20 | : loader [ 210 ] ; | , | , 21 | 22 | : selftest ( port) [ 708 ] load ; :var stp [0x3] 23 | : autotest ( port) [ 712 ] load ; 24 | 25 | {block 216} 26 | 792 load 27 | 28 | {block 360} 29 | ( polyforth vm) reclaim | , 30 | ( sram) sram load | , 31 | ( serial) 38 fh 3 loads reclaim | , 32 | ( stack) 106 node $39 org 278 load 14 fh 2 loads | , 33 | ( coprocs) 22 fh 4 loads | , 34 | ( bitsy) 105 node 18 fh 2 loads | , 35 | ( coprocs) 30 fh 4 loads | , 36 | ( flash to sram) 86 fh 2 loads reclaim | , 37 | ( erase and burn flash) 288 load | , 38 | ( spi speedup) 290 load | , 39 | ( serial wires) 102 node $20 org | , 40 | : start @ !b start ; 1709 bin | , 41 | ( ganglia) 44 fh load ( snorkel) 48 fh load | , 42 | ( spi) 50 fh load 43 | 44 | {block 362} 45 | ( - load descriptors) 46 | : l, dup +node 100 /mod 1 and 2* swap 1 and + 1714 + 47 | push 32 32 pop /part ( warm) $a9 /p ; 48 | : ganglia nns for i -1 + n-nn l, next ; | , 49 | 50 | ( sea of mk1) ganglia | , 51 | ( snorkel) 207 +node 1605 /ram up /b $37 /p | , 52 | ( sram) sram 2 + load | , 53 | ( vm) 2 fh load | , 54 | ( serial) 4 fh load | , 55 | ( additional i/o) 6 fh load | , 56 | ( md5) 792 load | , 57 | ( clock nodes) exit | , 58 | 517 +node 517 /ram io /b $200 /p | , 59 | 516 +node 516 /ram left dup /a /p right /b | , 60 | 61 | {block 790} 62 | host target | cr 63 | 10 node 800 load 64 | 110 node 804 load 65 | 111 node 806 load 66 | 67 | {block 792} 68 | : /node dup +node /ram ; | cr 69 | 10 /node $0 /p 70 | 110 /node $0 /p 71 | 111 /node $0 /p 72 | 73 | {block 800} 74 | ( -) # 10 ( id 0 mem 0) 0 org | cr 75 | | br 76 | : main = $0 0 2 push drop pop dup down b! !b warm = $0 ; | cr 77 | 78 | {block 804} 79 | ( -) # 110 ( id 2 mem 0) 0 org | cr 80 | | br 81 | : main = $0 0 right b! @b down b! @b . + push drop pop warm = $0 ; | cr 82 | 83 | {block 806} 84 | ( -) # 111 ( id 3 mem 0) 0 org | cr 85 | | br 86 | : main = $0 0 1 push drop pop dup right b! !b warm = $0 ; | cr 87 | 88 | -------------------------------------------------------------------------------- /cforth_tools/relative.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 'convert relative call or jmp address to EIP address' 3 | import sys, os 4 | def relative(offset, instruction_address): 5 | return '0x%x' % ((offset + instruction_address) & 0xffffffff) 6 | if __name__ == '__main__': 7 | if len(sys.argv) < 3: 8 | print >>sys.stderr, 'Usage: %s OFFSET ADDRESS_OF_INSTRUCTION' 9 | else: 10 | print relative(int(sys.argv[1], 16), int(sys.argv[2], 16)) 11 | -------------------------------------------------------------------------------- /cforth_tools/template.cfs: -------------------------------------------------------------------------------- 1 | {block 200} 2 | ( user f18 code) reclaim 790 load | br 3 | 4 | {block 202} 5 | ( ga application tools) 6 | : a-com [ 10 ] ; | * 7 | : a-bps 921600 ; 8 | : c-com [ 3 ] ; | * 9 | : c-bps 921600 ; 10 | : host 206 ; | * 11 | : target 208 ; | , 12 | 13 | ( modules) | * 14 | : sram [ 264 ] ; | * 15 | : pf [ 360 ] ; | * 16 | : ether [ 720 ] ; | , 17 | 18 | ( utils) | * 19 | : streamer [ 282 ] ; | * 20 | : loader [ 210 ] ; | , | , 21 | 22 | : selftest ( port) [ 708 ] load ; :var stp [0x3] 23 | : autotest ( port) [ 712 ] load ; 24 | 25 | {block 216} 26 | 792 load 27 | 28 | {block 360} 29 | ( polyforth vm) reclaim | , 30 | ( sram) sram load | , 31 | ( serial) 38 fh 3 loads reclaim | , 32 | ( stack) 106 node $39 org 278 load 14 fh 2 loads | , 33 | ( coprocs) 22 fh 4 loads | , 34 | ( bitsy) 105 node 18 fh 2 loads | , 35 | ( coprocs) 30 fh 4 loads | , 36 | ( flash to sram) 86 fh 2 loads reclaim | , 37 | ( erase and burn flash) 288 load | , 38 | ( spi speedup) 290 load | , 39 | ( serial wires) 102 node $20 org | , 40 | : start @ !b start ; 1709 bin | , 41 | ( ganglia) 44 fh load ( snorkel) 48 fh load | , 42 | ( spi) 50 fh load 43 | 44 | {block 362} 45 | ( - load descriptors) 46 | : l, dup +node 100 /mod 1 and 2* swap 1 and + 1714 + 47 | push 32 32 pop /part ( warm) $a9 /p ; 48 | : ganglia nns for i -1 + n-nn l, next ; | , 49 | 50 | ( sea of mk1) ganglia | , 51 | ( snorkel) 207 +node 1605 /ram up /b $37 /p | , 52 | ( sram) sram 2 + load | , 53 | ( vm) 2 fh load | , 54 | ( serial) 4 fh load | , 55 | ( additional i/o) 6 fh load | , 56 | ( md5) 792 load | , 57 | ( clock nodes) exit | , 58 | 517 +node 517 /ram io /b $200 /p | , 59 | 516 +node 516 /ram left dup /a /p right /b | , 60 | 61 | {block 790} 62 | ( fir) host | * 63 | target | cr 64 | 0 node 10 fh load 65 | 66 | {block 792} 67 | ( - load descriptor) 68 | : /node ( n) dup +node /ram ; | cr 69 | 0 /node $0 /p 70 | 71 | {block 800} 72 | ( -) # 0 0 org | cr 73 | 0 , 0 , 0 , 0 , 44 , 55 , | cr 74 | : call dup ; 75 | : add for call next ; 76 | 77 | -------------------------------------------------------------------------------- /configure.py: -------------------------------------------------------------------------------- 1 | import commands, sys, os 2 | 3 | # F18A superoptimizer 4 | status, output = commands.getstatusoutput("raco planet show | grep aforth-optimizer.plt") 5 | 6 | if len(output) == 0: 7 | print "F18A superoptimizer is not installed properly." 8 | sys.exit(0) 9 | 10 | if output.find("mangpo") == -1: 11 | print "F18A superoptimizer (aforth-optimizer.plt) package has to be installed under \"mangpo\" and not your name." 12 | print "Run:" 13 | print "raco planet unlink aforth-optimizer.plt 1 0" 14 | print "raco planet link mangpo aforth-optimizer.plt 1 0 " 15 | sys.exit(0) 16 | 17 | # Z3 18 | status, output = commands.getstatusoutput("z3") 19 | 20 | if not (output.find("not found") == -1): 21 | print "Please edit environmental variable PATH to point to z3." 22 | sys.exit(0) 23 | 24 | # Simulated Annealing 25 | os.system("g++ -O3 src/qap/sa_qap_fix.cpp -o src/qap/sa_qap") 26 | 27 | # Create path.rtk 28 | status, abs_path = commands.getstatusoutput("pwd") 29 | f = open("src/path.rkt", "w") 30 | f.write("#lang racket\n") 31 | f.write("(provide (all-defined-out))\n") 32 | f.write("(define srcpath \"" + abs_path + "/src\")\n") 33 | f.write("(define datapath \"" + abs_path + "/testdata\")\n") 34 | print "src/path.rkt is created." 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/actor/actor_pair.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 2 --> 100 5 | actor edge@(0~>2); 6 | 7 | int::2@(0,0) edge(int::2@(2,2) a){ 8 | a::0 = a::0 +@2 1; 9 | a::1 = a::1 +@2 2; 10 | return a; 11 | } 12 | 13 | void main(){ 14 | int::2@(0,0) x; 15 | int@0 b; 16 | x::0 = 100; 17 | x::1 = 200; 18 | while(1) { 19 | if(b >@0 0) { 20 | x = edge(x); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/actor/actor_v1.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 2 --> 002 5 | actor edge@(0~>2); 6 | 7 | int@0 edge(int@2 a){ 8 | return a +@2 1; 9 | } 10 | 11 | void main(){ 12 | int@0 x, b; 13 | b = 0; 14 | x = 0; 15 | while(b < 10) { 16 | if(b >@0 5) { 17 | x = edge(x); 18 | //out(x); 19 | x = edge(x); 20 | //out(x); 21 | } 22 | b = b+1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/actor/actor_v2.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 1 --> 100 5 | # 2 --> 200 6 | actor edge@(0~>1); 7 | 8 | int@0 edge(int@1 a){ 9 | int@2 b; 10 | return a +@1 b; 11 | } 12 | 13 | void main(){ 14 | int@0 x, b; 15 | x = 0; 16 | while(1) { 17 | if(b >@0 0) { 18 | x = edge(x); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/actor/actor_v3.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 1 --> 100 5 | # 2 --> 200 6 | actor edge@(0~>1); 7 | actor edge@(0~>2); 8 | 9 | int@0 edge(int@2 a){ 10 | int@1 b; 11 | return a +@2 b; 12 | } 13 | 14 | void main(){ 15 | int@0 x, b; 16 | x = 0; 17 | while(1) { 18 | if(b >@0 0) { 19 | x = edge(x); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/actor/actor_v4.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 1 --> 100 5 | # 2 --> 200 6 | actor edge@(0~>1); 7 | actor edge@(1~>2); 8 | 9 | int@0 edge(int@2 a){ 10 | int@1 b; 11 | return a +@2 b; 12 | } 13 | 14 | void main(){ 15 | int@0 x, b; 16 | x = 0; 17 | while(1) { 18 | if(b >@0 0) { 19 | x = edge(x); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/actor/actor_v5.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | # 0 --> 000 4 | # 2 --> 001 5 | actor edge@(0~>2); 6 | 7 | int@0 edge(int@2 a){ 8 | return a +@2 1; 9 | } 10 | 11 | void main(){ 12 | int@0 x, b; 13 | b = 0; 14 | x = 0; 15 | while(b < 10) { 16 | if(b >@0 5) { 17 | x = edge(x); 18 | out(x); 19 | x = edge(x); 20 | out(x); 21 | } 22 | b = b+1; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/actor/sactor_arg.cll: -------------------------------------------------------------------------------- 1 | // c 2 | 3 | # 0 --> 000 4 | # 1 --> 201 5 | 6 | # 5 --> 001 7 | # 6 --> 101 8 | 9 | actor* derive; 10 | int@0 derive(int@5 x) { 11 | int@6 y; 12 | return x +@5 y; 13 | } 14 | 15 | void main() { 16 | int@0 x; 17 | int@1 y; 18 | x = derive(y); 19 | } 20 | -------------------------------------------------------------------------------- /examples/actor/sactor_before.cll: -------------------------------------------------------------------------------- 1 | // c 2 | 3 | int@1 c; 4 | 5 | actor* f; 6 | int@0 f(int@1 x) { 7 | return x +@1 c; 8 | } 9 | 10 | void main() { 11 | int@0 x; 12 | c = 1; 13 | x = f(x); 14 | } 15 | -------------------------------------------------------------------------------- /examples/actor/sactor_dup.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | 4 | # 0 --> 000 5 | # 1 --> 001 6 | # 2 --> 002 7 | 8 | int c; 9 | 10 | actor* edge@(0~>2); 11 | int edge(int a){ 12 | c = c + 1; 13 | return a + c; 14 | } 15 | 16 | int f(int x) { 17 | return edge(x); 18 | } 19 | 20 | void main(){ 21 | int@1 x; 22 | int@0 b; 23 | c = 0; 24 | x = 0; 25 | for(i from 0 to 10) { 26 | x = f(x); 27 | //out(x); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/actor/sactor_multicalls.cll: -------------------------------------------------------------------------------- 1 | // c 2 | 3 | # 0 --> 000 4 | # 1 --> 002 5 | # 2 --> 102 6 | 7 | int@1 a[10]; 8 | int@2 c; 9 | 10 | actor* get_a; 11 | int@0 get_a(int@1 i) { 12 | return a[i] + c; 13 | } 14 | 15 | void main() { 16 | int i; 17 | c = 1; 18 | i = get_a(i); 19 | i = get_a(i); 20 | } 21 | -------------------------------------------------------------------------------- /examples/actor/sactor_v1.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | actor* edge@(0~>2); 4 | 5 | int edge(int@2 a){ 6 | return a + 1; 7 | } 8 | 9 | void main(){ 10 | int@0 x, b; 11 | b = 0; 12 | x = 0; 13 | while(b < 10) { 14 | if(b > 5) { 15 | x = edge(x); 16 | out(x); 17 | x = edge(x); 18 | out(x); 19 | } 20 | b = b+1; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/actor/sactor_v2.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | actor* edge@(0~>1); 4 | 5 | int@2 c; 6 | 7 | int edge(int@1 a){ 8 | c = c + 1; 9 | return a + c; 10 | } 11 | 12 | void main(){ 13 | int@0 x, b; 14 | c = 0; 15 | x = 0; 16 | for (i from 0 to 10) { 17 | x = edge(x); 18 | //out(x); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/actor/sactor_v3.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | actor* edge; 4 | 5 | fix1_t edge(int a){ 6 | return a + 0.06; 7 | } 8 | 9 | actor* wrap; 10 | 11 | fix1_t wrap(fix1_t a){ 12 | return edge(a) + 0.0025; 13 | } 14 | 15 | void main(){ 16 | fix1_t x; 17 | int b; 18 | b = 0; 19 | x = 0; 20 | while(b < 10) { 21 | if(b > 5) { 22 | x = wrap(x); 23 | out(x); 24 | x = wrap(x); 25 | out(x); 26 | } 27 | b = b+1; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/actor/sactor_v4.cll: -------------------------------------------------------------------------------- 1 | // c 2 | 3 | module Hmm() { 4 | 5 | actor* derive_group; 6 | int derive_group(fix9_t::3 acc){ 7 | int x, y; 8 | return x + y + 99; 9 | } 10 | 11 | int forward_proc_inc(int o){ 12 | return 0; 13 | } 14 | 15 | int start; 16 | 17 | int input(fix9_t::3 acc){ 18 | int ret; 19 | if(start == 0) { 20 | start = 1; 21 | } else { 22 | ret = forward_proc_inc(derive_group(acc)); 23 | } 24 | return ret; 25 | } 26 | 27 | } 28 | 29 | hmm1 = new Hmm(); 30 | hmm2 = new Hmm(); 31 | 32 | int filter(fix9_t::3 acc) { 33 | return 1; 34 | } 35 | 36 | actor* step; 37 | int step(fix9_t::3@(2,2,2) acc) { 38 | int@0 ord1; 39 | int@1 ord2; 40 | ord1 = ord1 | hmm1.input(acc); 41 | ord2 = ord2 | hmm2.input(acc); 42 | return ord1 |@2 ord2; 43 | } 44 | 45 | void main() { 46 | fix9_t::3 acc; 47 | int o; 48 | if(filter(acc)) { 49 | o = step(acc); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/actor/sactor_v5.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | 4 | # 0 --> 000 5 | # 1 --> 100 6 | # 2 --> 101 7 | # 3 --> 001 8 | actor* edge@(0~>2); 9 | 10 | int@1 c; 11 | int@3 d; 12 | 13 | int edge(int@2 a){ 14 | c = c + 1; 15 | return a + c + d; 16 | } 17 | 18 | void main(){ 19 | int@0 x; 20 | x = 0; 21 | for(i from 0 to 10) { 22 | x = edge(x); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/actor/sactor_v6.cll: -------------------------------------------------------------------------------- 1 | // c 2 | 3 | # 0 --> 001 4 | # 1 --> 201 5 | # 2 --> 100 6 | # 3 --> 102 7 | 8 | actor* add; 9 | int@0 add(int@1 x) { 10 | return x + 1; 11 | } 12 | 13 | actor* sub; 14 | int@2 sub(int@3 x) { 15 | return x - 1; 16 | } 17 | 18 | void main() { 19 | int@0 x; 20 | int@2 y; 21 | x = 100; 22 | y = 100; 23 | x = add(x); 24 | y = sub(y); 25 | } 26 | -------------------------------------------------------------------------------- /examples/bithack/bithack1.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 x; 3 | x = in(); 4 | out(x - (x & in())); 5 | } 6 | -------------------------------------------------------------------------------- /examples/bithack/bithack2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | out(~(in() - in())); 3 | } 4 | -------------------------------------------------------------------------------- /examples/bithack/bithack3.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 x, y; 3 | x = in(); 4 | y = in(); 5 | out((x^y) ^ (x&y)); 6 | } 7 | -------------------------------------------------------------------------------- /examples/bithack/ceil_avg.cll: -------------------------------------------------------------------------------- 1 | 2 | int p15_ceil_avg(int x, int y) { 3 | int o1,o2; 4 | o1 = x | y; 5 | o2 = x ^ y; 6 | o2 = o2 >> 1; 7 | return o1 - o2; 8 | } 9 | 10 | void main() { 11 | int x; 12 | x = p15_ceil_avg(1,2); 13 | } 14 | -------------------------------------------------------------------------------- /examples/bithack/count.cll: -------------------------------------------------------------------------------- 1 | int f(int x) { 2 | int o1,o2; 3 | o1 = x >> 1; 4 | o1 = o1 & 87381; //0x15555; 5 | x = x - o1; 6 | 7 | o1 = x & 209715; //0x33333; 8 | o2 = x >> 2; 9 | o2 = o2 & 209715; //0x33333; 10 | x = o1 + o2; 11 | 12 | o1 = x >> 4; 13 | x = o1 + x; 14 | 15 | x = x & 3855; //0x0f0f; 16 | x = (x + (x >> 8)); 17 | x = (x + (x >> 16)); 18 | 19 | return x & 63; //0x3f; 20 | } 21 | 22 | void main() { 23 | int x; 24 | x = f(1); 25 | } 26 | -------------------------------------------------------------------------------- /examples/bithack/cycle.cll: -------------------------------------------------------------------------------- 1 | int p21_cycle(int x, int a, int b, int c) { 2 | int o1,o2,o3,o4; 3 | o1 = -(x == c); 4 | o2 = a ^ c; 5 | o3 = -(x == a); 6 | o4 = b ^ c; 7 | o1 = o1 & o2; 8 | o3 = o3 & o4; 9 | o1 = o1 ^ o3; 10 | return o1 ^ c; 11 | } 12 | 13 | void main() { 14 | int x; 15 | x = p21_cycle(1,1,2,3); 16 | } 17 | -------------------------------------------------------------------------------- /examples/bithack/exchange.cll: -------------------------------------------------------------------------------- 1 | 2 | int p19_exchange(int x, int m, int k) { 3 | int o1,o4; 4 | // assert(k <=16); 5 | o1 = x >> k; 6 | o1 = x ^ o1; 7 | o1 = o1 & m; 8 | o4 = o1 << k; 9 | o4 = o4 ^ o1; 10 | return o4 ^ x; 11 | } 12 | void main() { 13 | int x; 14 | x = p19_exchange(1,2,3); 15 | } 16 | -------------------------------------------------------------------------------- /examples/bithack/floor_avg.cll: -------------------------------------------------------------------------------- 1 | 2 | int p14_floor_avg(int x, int y) { 3 | int o1,o2; 4 | o1 = x & y; 5 | o2 = x ^ y; 6 | o2 = o2 >> 1; 7 | return o1 + o2; 8 | } 9 | 10 | void main() { 11 | int x; 12 | x = p14_floor_avg(1,2); 13 | } 14 | -------------------------------------------------------------------------------- /examples/bithack/haszerobyte.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int v; 3 | v = in(); 4 | v = ~((((v & 32639) + 32639) | v) | 32639); 5 | } 6 | -------------------------------------------------------------------------------- /examples/bithack/intro.cll: -------------------------------------------------------------------------------- 1 | int f(int a, int b, int c) { 2 | return (~a & ~b) ^ c; 3 | } 4 | 5 | void main() { 6 | int x; 7 | x= f(1,2,3); 8 | } 9 | -------------------------------------------------------------------------------- /examples/bithack/roundpower.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int v; 3 | v = v - 1; 4 | v = v | (v >> 1); 5 | v = v | (v >> 2); 6 | v = v | (v >> 4); 7 | v = v | (v >> 8); 8 | v = v | (v >> 16); 9 | v = v + 1; 10 | } 11 | -------------------------------------------------------------------------------- /examples/cluster/cluster.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | cluster int@{[0:20]=0,[20:40]=1} x[40]; 3 | 4 | for(i from 0 to 40)@{[0:20]=0,[20:40]=1} { 5 | x[i] = x[x[i]]; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/fixedpoint/cos_radius.cll: -------------------------------------------------------------------------------- 1 | // x ranges from [0,pi/2] in radius unit 2 | fix3_t cos(fix3_t x) { 3 | fix3_t y; 4 | fix3_t@{[0:5]=place(y)} coeff[5] = {-0.000023154 , -0.0013854 , 0.041664 , -0.5, 1}; 5 | 6 | fix3_t@place(y) sum; 7 | 8 | y = x * x; 9 | sum = 0; 10 | for(i from 0 to 5) { 11 | sum = sum *@place(y) y +@place(y) coeff[i]; 12 | } 13 | 14 | return (sum); 15 | } 16 | 17 | void main() { 18 | // pi is out of range, so use 0 for the second test case. 19 | // {0, pi, pi/2, pi/4, pi/6, pi/3} 20 | fix3_t x[6] = {0, 0, 1.570796, 0.785398, 0.523599, 1.047198}; 21 | fix3_t y[6]; 22 | 23 | /* 24 | for(i from 0 to 6) { 25 | x[i] = in(); 26 | }*/ 27 | 28 | y = map(cos, x); 29 | for(i from 0 to 6) { 30 | out(y[i]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/fixedpoint/cos_round.cll: -------------------------------------------------------------------------------- 1 | // x ranges from [0,1] in round unit 2 | fix2_t cos(fix2_t x) { 3 | fix2_t y; 4 | fix2_t@{[0:4]=place(y)} coeff[4] = {-0.0043 , 0.0794 , -0.6459 , 0.5708}; 5 | fix2_t@place(y) sum; 6 | 7 | x = x << 2; 8 | if(x < 0) { 9 | x = x + 1; 10 | } else { 11 | x = 1 - x; 12 | } 13 | 14 | y = x * x; 15 | sum = 0; 16 | for(i from 0 to 4) { 17 | sum = sum *@place(y) y +@place(y) coeff[i]; 18 | } 19 | 20 | return (sum * x + x); 21 | } 22 | 23 | void main() { 24 | // {0, pi, pi/2, pi/4, pi/6, pi/3} 25 | fix2_t x[6] = {0, 0.5, 0.25, 0.125, 0.083333, 0.166667}; 26 | fix2_t y[6]; 27 | // use fix2_t@{[0:3]=0,[3:6]=1} x[6] for distributed array. 28 | 29 | /* 30 | for(i from 0 to 6) { 31 | x[i] = in(); 32 | }*/ 33 | 34 | y = map(cos, x); 35 | for(i from 0 to 6) { 36 | out(y[i]); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/fixedpoint/hello.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | fix2_t@0 a; 3 | fix2_t@1 b; 4 | fix2_t@2 c; 5 | c = 0.125 *@2 a *@2 b; 6 | } 7 | -------------------------------------------------------------------------------- /examples/future/disparity.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:15]=0} l[15]; // 3 x 5 3 | int pl; 4 | 5 | int@{[0:9]=2} local_l[9]; 6 | int local_r[9]; 7 | 8 | int local_p; 9 | int col_l; 10 | int col_r; 11 | int index_l; 12 | 13 | int min; 14 | int diff; 15 | int index; 16 | int sum; 17 | 18 | col_r = 0; 19 | col_l = 0; 20 | 21 | // right input 22 | for(i from 0 to 3) { 23 | local_r[col_r +@place(col_r) i] = in(); 24 | } 25 | col_r = col_r +@place(col_r) 3; 26 | if(col_r >=@place(col_r) 9) { col_r = 0; } 27 | 28 | // left input 29 | for(i from 0 to 3) { 30 | l[col_l +@place(col_l) i] = in(); 31 | } 32 | col_l = col_l +@place(col_l) 3; 33 | if(col_l >=@place(col_l) 15) { col_l = 0; } 34 | 35 | // init for each round 36 | pl = col_l; 37 | for(i from 0 to 3) { 38 | local_l[i] = l[pl +@place(pl) i]; 39 | } 40 | pl = pl +@place(pl) 3; 41 | if(pl >=@place(pl) 15) { pl = 0; } 42 | 43 | for(i from 0 to 3) { 44 | local_l[3+i] = l[pl +@place(pl) i]; 45 | } 46 | pl = pl +@place(pl) 3; 47 | if(pl >=@place(pl) 15) { pl = 0; } 48 | 49 | local_p = 6; 50 | min = 65536; 51 | for(i from 0 to 5) { 52 | // get a column of data for l 53 | for(j from 0 to 3) { 54 | local_l[local_p +@place(local_p) j] = l[pl +@place(local_p) j]; 55 | } 56 | local_p = local_p +@place(local_p) 3; 57 | if(local_p >=@place(local_p) 9) { local_p = 0; } 58 | pl = pl +@place(pl) 3; 59 | if(pl >=@place(pl) 15) { pl = 0; } 60 | 61 | // SSD 62 | sum = 0; 63 | for(j from 0 to 9) { 64 | index_l = local_p +@place(local_p) j; 65 | if(index_l >=@place(local_p) 9) { index_l = index_l -@place(local_p) 9; } 66 | 67 | diff = local_l[index_l] - local_r[j]; 68 | sum = sum + diff * diff; 69 | } 70 | if(sum < min) { 71 | min = sum; 72 | index = i; 73 | } 74 | } 75 | out(index); 76 | 77 | } 78 | -------------------------------------------------------------------------------- /examples/future/gaussseidel.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:25]=0} u[25] = {0 , 0 , 0 , 0 , 0 , 0 , 5040 , 8486 , 23482 , 0 , 0 , 4248 , 4001 , 23913 , 0 , 0 , 16115 , 19261 , 21272 , 0 , 0 , 0 , 0 , 0 , 0}; 3 | int@{[0:25]=1} f[25] = {22442 , 11420 , 14167 , 20374 , 7279 , 18470 , 12430 , 13446 , 24101 , 9591 , 4297 , 11817 , 18110 , 16272 , 22013 , 5307 , 14097 , 5951 , 22507 , 17813 , 12112 , 13295 , 6886 , 5850 , 15208}; 4 | int e; 5 | int val; 6 | //int t; 7 | int col; 8 | 9 | //t = 0; 10 | e = 65536; 11 | //while(t < 10) { 12 | while(e > 2) { 13 | e = 0; 14 | for(i from 6 to 19) { 15 | col = i %@place(col) 5; 16 | if(col != 0) { 17 | if(col != 4) { 18 | val = ((64880 */16 64880 */16 f[i]) + u[i-1] + u[i+1] + u[i-5] + u[i+5]) >>@place(val) 2; 19 | //val = (f[i] + u[i-1] + u[i+1] + u[i-5] + u[i+5]) >> 2; 20 | e = e +@place(e) (val -@place(val) u[i]) */16@place(val) (val -@place(val) u[i]); 21 | u[i] = val; 22 | }} 23 | } 24 | //t = t+1; 25 | } 26 | out(e); 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/future/gaussseidel2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:25]=0} u[25] = {0 , 0 , 0 , 0 , 0 , 0 , 5040 , 8486 , 23482 , 0 , 0 , 4248 , 4001 , 23913 , 0 , 0 , 16115 , 19261 , 21272 , 0 , 0 , 0 , 0 , 0 , 0}; 3 | int@{[0:25]=1} f[25] = {22442 , 11420 , 14167 , 20374 , 7279 , 18470 , 12430 , 13446 , 24101 , 9591 , 4297 , 11817 , 18110 , 16272 , 22013 , 5307 , 14097 , 5951 , 22507 , 17813 , 12112 , 13295 , 6886 , 5850 , 15208}; 4 | int val; 5 | int col; 6 | 7 | for(i from 6 to 19) { 8 | col = i %@place(col) 5; 9 | if(col != 0) { 10 | if(col != 4) { 11 | val = ((64880 */16 64880 */16 f[i]) +@0 u[i-@any 1] +@0 u[i+@any 1] +@0 u[i-@any 5] +@0 u[i+@any 5]) >>@place(val) 2; 12 | //val = (f[i] + u[i-1] + u[i+1] + u[i-5] + u[i+5]) >> 2; 13 | u[i] = val; 14 | }} 15 | } 16 | out(u[6]); 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/future/insertionsort.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int[] x[100]; 3 | int temp; 4 | int j; 5 | 6 | for(i from 0 to 100) { 7 | temp = x[i]; 8 | j = i-1; 9 | while(j >= 0 && x[j] > temp) { 10 | x[j+1] = x[j]; 11 | j = j-1; 12 | } 13 | x[j+1] = temp; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/future/ssd.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | // N (width) = 40, M (height) = 3 3 | // W = 1, K = 16 4 | int[] ssd[120]; 5 | int[] l[120]; 6 | int[] r[120]; 7 | int N, M; 8 | N = 40; 9 | 10 | //for(int m = W/2; m < M - W/2; m++) { // row 11 | for(m from 1 to 2) { 12 | //for(int n = K + W/2; n < N - W/2; n++) { // column 13 | for(n from 17 to 39) { 14 | int min; 15 | min = 100000; 16 | int index; 17 | index = -1; 18 | 19 | //for(int k = 0; k < K; k++) { 20 | for(k from 0 to 16) { 21 | int sum; 22 | sum = 0; 23 | //for(int i = m - W/2; i <= m + W/2; i++) { // row 24 | int i; 25 | i = m - 1; 26 | while(i <= m + 1) { 27 | //for(int j = n - W/2; j <= n + W/2; j++) { // column 28 | int j; 29 | j = n - 1; 30 | while(j <= n + 1) { 31 | if(j - k >= 0) { 32 | sum = (l[i*N + j] - r[i*N + j-k]) * (l[i*N + j] - r[i*N + j-k]) + sum; 33 | if(min > sum) { 34 | min = sum; 35 | index = k; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | ssd[m*N + n] = index; 42 | } 43 | } 44 | } 45 | 46 | /* 47 | # msgs = 281600220 48 | # synthesis time = 2756 s = 45 min 49 | 50 | core = 0, space = 178, ops = # 51 | core = 1, space = 212, ops = # 52 | core = 2, space = 0, ops = # 53 | core = 3, space = 184, ops = # 54 | core = 4, space = 0, ops = # 55 | core = 5, space = 146, ops = # 56 | core = 6, space = 244, ops = # 57 | core = 7, space = 244, ops = # 58 | core = 8, space = 232, ops = # 59 | core = 9, space = 178, ops = # 60 | core = 10, space = 0, ops = # 61 | core = 11, space = 244, ops = # 62 | core = 12, space = 178, ops = # 63 | core = 13, space = 244, ops = # 64 | core = 14, space = 244, ops = # 65 | core = 15, space = 244, ops = # 66 | 67 | void@(# . 0) main() { 68 | int@{[0:32]=12, [32:64]=0, [64:96]=9, [96:120]=5} ssd; 69 | int@{[0:32]=14, [32:64]=6, [64:96]=7, [96:120]=8} l; 70 | int@{[0:32]=13, [32:64]=11, [64:96]=15, [96:120]=1} r; 71 | int@3 (N M); 72 | N= 40@3 73 | for(m from 1 to 2)@place(any) { 74 | for(n from 17 to 39)@place(any) { 75 | int@3 (min); 76 | min= 100000@3 77 | int@8 (index); 78 | index= (-@8 1@8) 79 | for(k from 0 to 16)@place(any) { 80 | int@3 (sum); 81 | sum= 0@3 82 | int@3 (i); 83 | i= (m -@3 1@3) 84 | (i <=@3 (m +@3 1@3))) { 85 | int@3 (j); 86 | j= (n -@3 1@3) 87 | (j <=@3 (n +@3 1@3))) { 88 | if(((j -@3 k) >=@3 0@3)) { 89 | sum= (((l[((i *@3 N) +@3 j)] -@3 r[(((i *@3 N) +@3 j) -@3 k)]) *@3 (l[((i *@3 N) +@3 j)] -@3 r[(((i *@3 N) +@3 j) -@3 k)])) +@3 sum) 90 | if((min >@3 sum)) { 91 | min= sum 92 | index= k 93 | } 94 | } 95 | } 96 | } 97 | } 98 | 99 | ssd[((m *@3 N) +@3 n)]= index 100 | } 101 | 102 | } 103 | 104 | } 105 | */ 106 | -------------------------------------------------------------------------------- /examples/io/blink.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | // Blinks an LED connected from a voltage source to pin 0 in node 417 4 | // pin 417.0 = eval board header pin J36.3 5 | 6 | //delay for 0.5 seconds (The measured delay was 0.492 seconds) 7 | void delay(){ 8 | for (i from 0 to 1000){ 9 | delay_ns(417, 500000, 1.8); 10 | } 11 | } 12 | 13 | void main(){ 14 | while (1){ 15 | set_io(417, SINK); 16 | delay(); 17 | set_io(417, IMPED); 18 | delay(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/io/blink2.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | // This waits for the transitions of a square wave on pin 705.0 4 | // and toggles pin 705.1 at a much slower rate. with a 5 | // 32Khz input, this will switch the output at 1Hz. 6 | 7 | // Square wave input on node 705 pin 0, header J32.1 8 | // LED from source to node 705 pin 1, header J32.4 9 | 10 | void main(){ 11 | int c; 12 | c = 0; 13 | while (1){ 14 | 15 | while (c < 16000){ //off cycle 16 | set_io(705, IMPED, IMPED, IMPED, IMPED, WAKEUP_HIGH); 17 | digital_wakeup(705); 18 | set_io(705, IMPED, IMPED, IMPED, IMPED, WAKEUP_LOW); 19 | digital_wakeup(705); 20 | c = c + 1; 21 | } 22 | while (c > 0){ 23 | set_io(705, IMPED, SINK, IMPED, IMPED, WAKEUP_HIGH); 24 | digital_wakeup(705); 25 | set_io(705, IMPED, SINK, IMPED, IMPED, WAKEUP_LOW); 26 | digital_wakeup(705); 27 | c = c - 1; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/io/crystal-oscillator.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | // requires a 32.768 khz watch crystal from 715.0 to gnd 4 | 5 | void osc(int k){//, int n){ 6 | int half; 7 | half = k/2; 8 | //for (i from 0 to n){ 9 | for (i from 0 to 5000){ 10 | set_io(715, SOURCE); 11 | delay_unext(715, half); 12 | set_io(715, SINK); 13 | delay_unext(715, half); 14 | } 15 | set_io(715, IMPED); 16 | for (i from 0 to 30000){ 17 | if (digital_read(715, 0)){ 18 | while (1){ 19 | 20 | set_io(715, SOURCE); 21 | set_io(715, HIGH_IMPEDANCE, WAKEUP_LOW); 22 | digital_wakeup(715); 23 | 24 | set_io(715, SINK); 25 | set_io(715, HIGH_IMPEDANCE, WAKEUP_HIGH); 26 | digital_wakeup(715); 27 | 28 | } 29 | } 30 | } 31 | } 32 | 33 | void main(){ 34 | int period; 35 | period = 12400; 36 | while (1){ 37 | osc(period); 38 | period = period + 1; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /examples/io/simple-wait.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | 3 | // this waits for the transitions of a square wave on pin 705.0 4 | // and toggles pin 705.1 to mirror it 5 | 6 | // Square wave input on node 705 pin 0, header J32.1 7 | // Output on node 705 pin 1, header J32.4 8 | 9 | void main(){ 10 | while (1){ 11 | set_io(705, IMPED, SINK, IMPED, IMPED, WAKEUP_HIGH); 12 | digital_wakeup(705); 13 | set_io(705, IMPED, HIGH, IMPED, IMPED, WAKEUP_LOW); 14 | digital_wakeup(705); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/io/square-wave.cll: -------------------------------------------------------------------------------- 1 | // -*- c -*- 2 | // generate a square wave on pin 0 in node 517 (715.17) 3 | // evalboard header pin J36.2 4 | // 5 | // This was used to test accuracy of delay_ns 6 | 7 | void main(){ 8 | while (1){ 9 | set_io(517, 3); 10 | delay_ns(517, 1000, 1.8); 11 | set_io(517, 2); 12 | delay_ns(517, 1000, 1.8); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/mapreduce/map-pair.cll: -------------------------------------------------------------------------------- 1 | int ssd(int::2 a, int b) { 2 | int temp; 3 | temp = (a::0 + a::1) -@place(temp) b; 4 | return temp *@place(temp) temp; 5 | } 6 | 7 | void main() { 8 | int::2@({[0:5]=0,[5:10]=1},{[0:5]=2,[5:10]=3}) x[10] = {(7 , 3) , (7 , 9) , (0 , 1) , (6 , 4) , (9 , 9), (4 , 9) , (4 , 0) , (10 , 7) , (2 , 4) , (3 , 10)}; 9 | int@{[0:5],[5:10]} y[10] = {4 , 2 , 10 , 6 , 5 , 6 , 1 , 5 , 6 , 7}; 10 | int@{[0:5],[5:10]} z[10]; 11 | z = map(ssd, x, y); 12 | for(i from 0 to 10) { 13 | out(z[i]); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/mapreduce/map.cll: -------------------------------------------------------------------------------- 1 | int ssd(int a, int b) { 2 | int temp; 3 | temp = a -@place(temp) b; 4 | return temp *@place(temp) temp; 5 | } 6 | 7 | void main() { 8 | int@{[0:5]=0,[5:10]=1} x[10] = {7 , 3 , 7 , 9 , 0 , 1 , 6 , 4 , 9 , 9}; 9 | int@{[0:5],[5:10]} y[10] = {4 , 2 , 10 , 6 , 5 , 6 , 1 , 5 , 6 , 7}; 10 | int@{[0:5],[5:10]} z[10]; 11 | z = map(ssd, x, y); 12 | for(i from 0 to 10) { 13 | out(z[i]); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/mapreduce/mapreduce.cll: -------------------------------------------------------------------------------- 1 | int ssd(int a, int b) { 2 | int temp; 3 | temp = a -@place(temp) b; 4 | return temp *@place(temp) temp; 5 | } 6 | 7 | int add(int a, int b) { 8 | return a + b; 9 | } 10 | 11 | void main() { 12 | int@{[0:5]=0,[5:10]=1} x[10] = {7 , 3 , 7 , 9 , 0 , 1 , 6 , 4 , 9 , 9}; 13 | int@{[0:5],[5:10]} y[10] = {4 , 2 , 10 , 6 , 5 , 6 , 1 , 5 , 6 , 7}; 14 | int ans; 15 | 16 | ans = reduce(add, 0, map(ssd,x,y)); 17 | out(ans); 18 | } 19 | -------------------------------------------------------------------------------- /examples/mapreduce/reduce-pair.cll: -------------------------------------------------------------------------------- 1 | int::2 cadd(int::2 a, int::2 b) { 2 | int::2 z; 3 | z::0 = a::0 +@place(z::0) b::0; 4 | z::1 = a::1 +@place(z::1) b::1 +@place(z::1) (z::0 >>@place(z::0) 16); 5 | z::0 = z::0 &@place(z::0) 65535; 6 | return z; 7 | } 8 | 9 | void main() { 10 | int::2@({[0:5]=0,[5:10]=1},{[0:5]=2,[5:10]=3}) x[10] = {(7 , 3) , (7 , 9) , (0 , 1) , (6 , 4) , (9 , 9), (4 , 9) , (4 , 0) , (10 , 7) , (2 , 4) , (3 , 10)}; 11 | int::2 ans; 12 | ans = reduce(cadd, 0, x); 13 | out(ans::0); 14 | out(ans::1); 15 | } 16 | -------------------------------------------------------------------------------- /examples/mapreduce/reduce.cll: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | 5 | void main() { 6 | int@{[0:5]=0,[5:10]=1} x[10] = {7 , 3 , 7 , 9 , 0 , 1 , 6 , 4 , 9 , 9}; 7 | int ans; 8 | ans = reduce(add, 0, x); 9 | out(ans); 10 | } 11 | -------------------------------------------------------------------------------- /examples/matrixmultiply/matrixmult-noplace.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:36]=5} A[36]; 3 | int@{[0:36]=13} B[36]; 4 | int@{[0:36]=16} C[36]; 5 | int@13 sum; 6 | 7 | for(i from 0 to 6)@any { 8 | for(j from 0 to 6)@any { 9 | sum = 0; 10 | for(k from 0 to 6)@any { 11 | sum = (sum + (A[((6 * i) + k)] * B[((6 * k) + j)])); 12 | } 13 | 14 | C[((6 * i) + j)] = sum; 15 | } 16 | 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /examples/matrixmultiply/matrixmult4-dup.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:16]=0} A[16] = {0 , 9 , 10 , 10 , 0 , 0 , 4 , 8 , 3 , 1 , 10 , 8 , 3 , 10 , 3 , 9}; 3 | int@{[0:16]=1} B[16] = {0 , 5 , 8 , 9 , 6 , 4 , 7 , 2 , 7 , 6 , 10 , 4 , 5 , 8 , 9 , 0}; 4 | int@{[0:16]=2} C[16]; 5 | 6 | /* 7 | 174 176 253 58 8 | 68 88 112 16 9 | 116 143 203 69 10 | 126 145 205 59 11 | 12 | ae b0 fd 3a 13 | 44 58 70 10 14 | 74 8f cb 45 15 | 7e 91 cd 3b 16 | */ 17 | 18 | int sum; 19 | int a[4]; 20 | 21 | //A[0] = in(); 22 | 23 | for(i from 0 to 4)@any { 24 | for(k from 0 to 4) { 25 | a[k] = A[4 *@place(A[i]) i +@place(A[i]) k]; 26 | } 27 | for(j from 0 to 4)@any { 28 | sum = 0; 29 | for(k from 0 to 4)@any { 30 | sum = (sum + (a[k] * B[((4 *@place(B[k]) k) +@place(B[k]) j)])); 31 | } 32 | C[((4 *@place(C[i]) i) +@place(C[i]) j)] = sum; 33 | } 34 | } 35 | 36 | //out(C[0]); 37 | for(i from 0 to 4)@any { 38 | for(j from 0 to 4)@any { 39 | out(C[(4 * i) + j]); 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /examples/matrixmultiply/matrixmult4.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:16]=0} A[16] = {0 , 9 , 10 , 10 , 0 , 0 , 4 , 8 , 3 , 1 , 10 , 8 , 3 , 10 , 3 , 9}; 3 | int@{[0:16]=1} B[16] = {0 , 5 , 8 , 9 , 6 , 4 , 7 , 2 , 7 , 6 , 10 , 4 , 5 , 8 , 9 , 0}; 4 | int@{[0:16]=2} C[16]; 5 | 6 | /* 7 | 174 176 253 58 8 | 68 88 112 16 9 | 116 143 203 69 10 | 126 145 205 59 11 | 12 | ae b0 fd 3a 13 | 44 58 70 10 14 | 74 8f cb 45 15 | 7e 91 cd 3b 16 | */ 17 | 18 | int sum; 19 | 20 | for(i from 0 to 4)@any { 21 | for(j from 0 to 4)@any { 22 | sum = 0; 23 | for(k from 0 to 4)@any { 24 | sum = (sum + (A[4 *@place(A[i]) i +@place(A[i]) k] * B[((4 *@place(B[k]) k) +@place(B[k]) j)])); 25 | } 26 | C[((4 *@place(C[i]) i) +@place(C[i]) j)] = sum; 27 | } 28 | } 29 | 30 | out(C[0]); 31 | /*for(i from 0 to 4)@any { 32 | for(j from 0 to 4)@any { 33 | out(C[(4 * i) + j]); 34 | } 35 | }*/ 36 | } 37 | 38 | -------------------------------------------------------------------------------- /examples/matrixmultiply/matrixmult6.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:36]=5} A[36]; 3 | int@{[0:36]=13} B[36]; 4 | int@{[0:36]=16} C[36]; 5 | int@13 sum; 6 | 7 | for(i from 0 to 36)@any { 8 | A[i] = in(); 9 | } 10 | 11 | for(i from 0 to 36)@any { 12 | B[i] = in(); 13 | } 14 | 15 | for(i from 0 to 6)@any { 16 | for(j from 0 to 6)@any { 17 | sum = 0; 18 | for(k from 0 to 6)@any { 19 | sum = (sum +@13 (A[((6 *@5 i) +@5 k)] *@13 B[((6 *@13 k) +@13 j)])); 20 | } 21 | 22 | C[((6 *@16 i) +@16 j)] = sum; 23 | } 24 | 25 | } 26 | 27 | for(i from 0 to 36)@any { 28 | out(C[i]); 29 | } 30 | 31 | } 32 | 33 | /* 34 | void main() { 35 | int@{[0:36]=5} A[36]; 36 | int@{[0:36]=13} B[36]; 37 | int@{[0:36]=16} C[36]; 38 | int@16 sum; 39 | 40 | for(i from 0 to 36)@any { 41 | A[i] = in(); 42 | } 43 | 44 | for(i from 0 to 36)@any { 45 | B[i] = in(); 46 | } 47 | 48 | for(i from 0 to 6)@any { 49 | for(j from 0 to 6)@any { 50 | sum = 0; 51 | for(k from 0 to 6)@any { 52 | sum = (sum +@16 (A[((6 *@5 i) +@5 k)] *@13 B[((6 *@13 k) +@13 j)])); 53 | } 54 | 55 | C[((6 *@16 i) +@16 j)] = sum; 56 | } 57 | 58 | } 59 | 60 | for(i from 0 to 36)@any { 61 | out(C[i]); 62 | } 63 | 64 | } 65 | */ 66 | -------------------------------------------------------------------------------- /examples/md5/assume.cll: -------------------------------------------------------------------------------- 1 | /* syntax */ 2 | 3 | int@0 fff(int@0 b, int@0 c, int@0 d) { 4 | assume(b <= 65535); 5 | assume(c <= 65535); 6 | assume(d <= 65535); 7 | return (b &@0 c) |@0 ((b ^@0 65535) &@0 d); 8 | } 9 | 10 | /*int::2@(1,1) fff2(int::2@(1,1) b, int::2@(1,1) c, int::2@(1,1) d) { 11 | assume(b::0 <= 65535); 12 | assume(b::1 <= 65535); 13 | assume(c::0 <= 65535); 14 | assume(d::1 <= 65535); 15 | return (b &@(1,1) c) |@(1,1) ((b ^@(1,1) 65535) &@(1,1) d); 16 | }*/ 17 | 18 | /*int ggg(int b, int c, int d) { 19 | return (d & b) | ((d ^ 65535) & c); 20 | } 21 | int iii(int b, int c, int d) { 22 | return b ^ c ^ d; 23 | } 24 | int jjj(int b, int c, int d) { 25 | return c ^ (b | (d ^ 65535)); 26 | }*/ 27 | 28 | void main() { 29 | out(fff(1,2,3)); 30 | /*int::2@(1,1) x; 31 | x = fff2(1,2,3);*/ 32 | } 33 | -------------------------------------------------------------------------------- /examples/md5/leftrotate.cll: -------------------------------------------------------------------------------- 1 | // comment 2 | 3 | int::2@(2, 2) leftrotate2(int::2@(6,7) x, int@8 r) { 4 | int::2@(2, 2) output; 5 | int@8 swap; 6 | if(r >@8 16) { 7 | swap = x::0; 8 | x::0 = x::1; 9 | x::1 = swap; 10 | r = r -@8 16; 11 | } 12 | r = 16 -@8 r; 13 | 14 | int::2@(6,6) y0; 15 | int::2@(7,7) y1; 16 | y0 = x::0 >>>@6 r; 17 | y1 = x::1 >>>@7 r; 18 | output::0 = (y1::0 +@6 (y0::1 >>@6 2)) &@6 65535; 19 | output::1 = (y0::0 +@7 (y1::1 >>@7 2)) &@7 65535; 20 | return output; 21 | } 22 | 23 | int::2@(2, 2) leftrotate1(int::2@(0,0) x, int@0 r) { 24 | int::2@(2, 2) output; 25 | int@0 swap; 26 | int@1 r2; 27 | int::2@(1,1) x2; 28 | if(r >@0 16) { 29 | swap = x::0; 30 | x::0 = x::1; 31 | x::1 = swap; 32 | r = r -@0 16; 33 | } 34 | x2 = x; 35 | r2 = r; 36 | output::0 = ((x2::1 >>@1 (16 -@1 r2)) |@1 (x2::0 <<@1 r2)) &@1 65535; 37 | output::1 = ((x2::0 >>@1 (16 -@1 r2)) |@1 (x2::1 <<@1 r2)) &@1 65535; 38 | return output; 39 | } 40 | 41 | void main() { 42 | int::2 out1; 43 | int::2 out2; 44 | int::2 input; 45 | input::0 = 8614; 46 | input::1 = 23318; 47 | out1 = leftrotate1(input, 23); 48 | out2 = leftrotate2(input, 23); 49 | out(out1::0); 50 | out(out1::1); 51 | out(out2::0); 52 | out(out2::1); 53 | } 54 | -------------------------------------------------------------------------------- /examples/module/module_concrete.cll: -------------------------------------------------------------------------------- 1 | // Module example 2 | 3 | module Op(c, arr) { 4 | int add(int@2 a, int@2 b) { 5 | int@1 x[3] = arr; 6 | return a + x[c] + b; 7 | } 8 | } 9 | 10 | m1 = new Op(0,{1,2,3})@{000,001,002}; 11 | m2 = new Op(1,{111,222,333})@REG(200,202); 12 | 13 | void main() { 14 | int@0 o1; 15 | int o2; 16 | o1 = m1.add(1,2); 17 | o2 = m2.add(3,4); 18 | o1 = o1 + o2; 19 | out(o1); 20 | } 21 | -------------------------------------------------------------------------------- /examples/module/module_global.cll: -------------------------------------------------------------------------------- 1 | // global varialbes and arrays 2 | 3 | int o; 4 | 5 | module Add(init) { 6 | int s[8] = init; 7 | 8 | void inc() { 9 | for(i from 0 to 8) { 10 | s[i] = s[i] + o; 11 | } 12 | } 13 | 14 | int val() { 15 | int sum; 16 | sum = 0; 17 | for(i from 0 to 8) { 18 | sum = sum + s[i]; 19 | } 20 | return sum; 21 | } 22 | } 23 | 24 | add1 = new Add({0,1,2,3,4,5,6,7}); 25 | add2 = new Add({1,1,1,1,1,1,1,1}); 26 | 27 | void main() { 28 | out(add1.val()); 29 | out(add2.val()); 30 | 31 | o = 1; 32 | add1.inc(); 33 | add2.inc(); 34 | out(add1.val()); 35 | out(add2.val()); 36 | 37 | o = 2; 38 | add1.inc(); 39 | add2.inc(); 40 | out(add1.val()); 41 | out(add2.val()); 42 | } 43 | -------------------------------------------------------------------------------- /examples/module/module_mapreduce.cll: -------------------------------------------------------------------------------- 1 | // Module example 2 | 3 | module Op() { 4 | int ssd(int a, int b) { 5 | int temp; 6 | temp = a -@place(temp) b; 7 | return temp *@place(temp) temp; 8 | } 9 | 10 | int add(int a, int b) { 11 | return a + b; 12 | } 13 | 14 | int f() { 15 | int@{[0:5],[5:10]} x[10] = {7 , 3 , 7 , 9 , 0 , 1 , 6 , 4 , 9 , 9}; 16 | int@{[0:5],[5:10]} y[10] = {4 , 2 , 10 , 6 , 5 , 6 , 1 , 5 , 6 , 7}; 17 | int ans; 18 | ans = reduce(add, 0, map(ssd,x,y)); 19 | return ans; 20 | } 21 | } 22 | 23 | m1 = new Op(); 24 | m2 = new Op(); 25 | 26 | void main() { 27 | int o1; 28 | int o2; 29 | 30 | o1 = m1.f(); 31 | o2 = m2.f(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/module/module_pair.cll: -------------------------------------------------------------------------------- 1 | // Module example 2 | 3 | module Op(c) { 4 | int::2 add(int::2 a) { 5 | a::0 = a::0 + c; 6 | a::1 = a::1 + c; 7 | return a; 8 | } 9 | } 10 | 11 | m1 = new Op(10); 12 | m2 = new Op(1); 13 | 14 | void main() { 15 | int::2 o1; 16 | int::2 o2; 17 | int::2 ans; 18 | 19 | o1 = m1.add(o1); 20 | o2 = m2.add(o2); 21 | ans = o1 + o2; 22 | } 23 | -------------------------------------------------------------------------------- /examples/module/module_pinning.cll: -------------------------------------------------------------------------------- 1 | // Module example 2 | 3 | # 0 --> 100 4 | 5 | module Op(c, arr) { 6 | # 0 --> 001 7 | int@1 add(int@0 a, int@0 b) { 8 | int x[3] = arr; 9 | return a +@place(b) x[c] + b; 10 | } 11 | } 12 | 13 | m1 = new Op(0,{1,2,3})@{000,001,002}; 14 | m2 = new Op(1,{111,222,333})@REG(200,202); 15 | 16 | void main() { 17 | int@0 o1; 18 | int o2; 19 | o1 = m1.add(1,2); 20 | o2 = m2.add(3,4); 21 | o1 = o1 + o2; 22 | //out(o1); 23 | } 24 | -------------------------------------------------------------------------------- /examples/module/module_simple.cll: -------------------------------------------------------------------------------- 1 | // Module example 2 | 3 | # 0 --> 100 4 | 5 | module Op(c, arr) { 6 | int add(int a, int b) { 7 | int x[3] = arr; 8 | return a +@place(b) x[c] + b; 9 | } 10 | } 11 | 12 | m1 = new Op(0,{1,2,3})@{000,001,002}; 13 | m2 = new Op(1,{111,222,333})@REG(200,202); 14 | 15 | void main() { 16 | int@0 o1; 17 | int o2; 18 | o1 = m1.add(1,2); 19 | o2 = m2.add(3,4); 20 | o1 = o1 + o2; 21 | //out(o1); 22 | } 23 | -------------------------------------------------------------------------------- /examples/parallel/convolution-noghost.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:14]=0} inp0[14] = {7 , 5 , 2 , 3 , 7 , 0 , 4 , 2 , 8 , 7,0,0,0,0}; 3 | int@{[0:14]=1} inp1[14] = {6 , 1 , 4 , 9 , 8 , 5 , 5 , 0 , 3 , 3,0,0,0,0}; 4 | int@{[0:14]=2} inp2[14] = {5 , 4 , 1 , 3 , 1 , 0 , 1 , 0 , 9 , 4,0,0,0,0}; 5 | int@{[0:14]=3} inp3[14] = {5 , 1 , 3 , 6 , 9 , 5 , 9 , 8 , 2 , 9, 10 , 2 , 8 , 8}; 6 | 7 | int@{[0:10]=20,[10:20]=21,[20:30]=22,[30:40]=23} x[40]; 8 | int@10 sum0; 9 | int@11 sum1; 10 | int@12 sum2; 11 | int@13 sum3; 12 | 13 | int@10 kernel0[5] = {1,1,1,1,1}; 14 | int@11 kernel1[5] = {1,1,1,1,1}; 15 | int@12 kernel2[5] = {1,1,1,1,1}; 16 | int@13 kernel3[5] = {1,1,1,1,1}; 17 | 18 | /*for(i from 0 to 10) { 19 | inp0[i] = in(); 20 | inp1[i] = in(); 21 | inp2[i] = in(); 22 | inp3[i] = in(); 23 | } 24 | 25 | for(i from 10 to 14) { 26 | inp3[i] = in(); 27 | }*/ 28 | inp0[0] = in(); 29 | 30 | for(i from 0 to 4) { 31 | inp0[i +@any 10] = inp1[i]; 32 | inp1[i +@any 10] = inp2[i]; 33 | inp2[i +@any 10] = inp3[i]; 34 | } 35 | 36 | for(i from 0 to 10) { 37 | sum0 = 0; 38 | for(j from 0 to 5) { 39 | sum0 = sum0 +@place(sum0) inp0[i +@any j] *@place(sum0) kernel0[j]; 40 | } 41 | x[i] = sum0; 42 | } 43 | 44 | for(i from 0 to 10) { 45 | sum1 = 0; 46 | for(j from 0 to 5) { 47 | sum1 = sum1 +@place(sum1) inp1[i +@any j] *@place(sum1) kernel1[j]; 48 | } 49 | x[i +@any 10] = sum1; 50 | } 51 | 52 | for(i from 0 to 10) { 53 | sum2 = 0; 54 | for(j from 0 to 5) { 55 | sum2 = sum2 +@place(sum2) inp2[i +@any j] *@place(sum2) kernel2[j]; 56 | } 57 | x[i +@any 20] = sum2; 58 | } 59 | 60 | for(i from 0 to 10) { 61 | sum3 = 0; 62 | for(j from 0 to 5) { 63 | sum3 = sum3 +@place(sum3) inp3[i +@any j] *@place(sum3) kernel3[j]; 64 | } 65 | x[i +@any 30] = sum3; 66 | } 67 | 68 | out(x[39]); 69 | 70 | /*for(i from 0 to 40) { 71 | out(x[i]); 72 | }*/ 73 | } 74 | -------------------------------------------------------------------------------- /examples/parallel/convolution-pair.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | ghost@({[0:14]=0,[10:24]=1,[20:34]=2,[30:44]=3},{[0:14]=10,[10:24]=11,[20:34]=12,[30:44]=13}) 3 | int::2@({[0:10]=0,[10:20]=1,[20:30]=2,[30:44]=3},{[0:10]=10,[10:20]=11,[20:30]=12,[30:44]=13}) 4 | in[44] = { 5 | (7 , 5) , (2 , 3) , (7 , 0) , (4 , 2) , (8 , 7) , 6 | (6 , 1) , (4 , 9) , (8 , 5) , (5 , 0) , (3 , 3) , 7 | (5 , 4) , (1 , 3) , (1 , 0) , (1 , 0) , (9 , 4) , 8 | (5 , 1) , (3 , 6) , (9 , 5) , (9 , 8) , (2 , 9) , 9 | (5 , 0) , (3 , 1) , (0 , 0) , (4 , 6) , (0 , 9) , 10 | (2 , 2) , (4 , 1) , (4 , 0) , (8 , 5) , (2 , 8) , 11 | (8 , 3) , (1 , 6) , (6 , 3) , (1 , 8) , (9 , 3) , 12 | (8 , 5) , (6 , 9) , (3 , 9) , (6 , 9) , (1 , 4) , 13 | (9 , 4) , (6 , 6) , (10 , 2) , (8 , 8)}; 14 | int::2@({[0:10]=4,[10:20]=5,[20:30]=6,[30:40]=7},{[0:10]=14,[10:20]=15,[20:30]=16,[30:40]=17}) x[40]; 15 | 16 | for(i from 0 to 40) { 17 | int::2 kernel[5] = {(1,1),(1,1),(1,1),(1,1),(1,1)}; 18 | int::2 sum; 19 | sum = 0; 20 | for(j from 0 to 5) { 21 | sum = in[i +@any j]@place(in[i]) * kernel[j] +@place(sum) sum; 22 | } 23 | x[i] = sum; 24 | } 25 | 26 | for(i from 0 to 40) { 27 | out(x::0[i]); 28 | out(x::1[i]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/parallel/convolution.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | //ghost@{[0:14]=0,[10:24]=1,[20:34]=2,[30:44]=3} 3 | //ghost int@{[0:10]=0,[10:20]=1,[20:30]=2,[30:44]=3} 4 | ghost int[10]@{0,1,2,3,3} 5 | in[44] = { 6 | 7 , 5 , 2 , 3 , 7 , 0 , 4 , 2 , 8 , 7 , 7 | 6 , 1 , 4 , 9 , 8 , 5 , 5 , 0 , 3 , 3 , 8 | 5 , 4 , 1 , 3 , 1 , 0 , 1 , 0 , 9 , 4 , 9 | 5 , 1 , 3 , 6 , 9 , 5 , 9 , 8 , 2 , 9 , 10 | 10 , 2 , 8 , 8}; 11 | int@{[0:10]=4,[10:20]=5,[20:30]=6,[30:40]=7} x[40]; 12 | 13 | for(i from 0 to 40) { 14 | int kernel[5] = {1,1,1,1,1}; 15 | int sum; 16 | sum = 0; 17 | for(j from 0 to 5) { 18 | sum = in[i +@any j]@place(in[i]) * kernel[j] +@place(sum) sum; 19 | } 20 | x[i] = sum; 21 | } 22 | 23 | for(i from 0 to 40) { 24 | out(x[i]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/parallel/prefixsum.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:10]=0,[10:20]=1,[20:30]=2,[30:40]=3,[40:50]=4,[50:60]=5,[60:70]=6,[70:80]=7,[80:90]=8,[90:100]=9} x[100] = 3 | {0 , 10 , 3 , 5 , 0 , 7 , 10 , 5 , 3 , 0 , 2 , 2 , 9 , 8 , 5 , 8 , 9 , 1 , 3 , 8 , 5 , 7 , 4 , 2 , 0 , 5 , 4 , 7 , 5 , 10 , 10 , 2 , 5 , 7 , 3 , 8 , 6 , 4 , 0 , 9 , 3 , 7 , 3 , 7 , 2 , 0 , 10 , 9 , 7 , 10 , 1 , 8 , 2 , 6 , 6 , 10 , 6 , 7 , 4 , 1 , 3 , 7 , 10 , 10 , 10 , 7 , 8 , 2 , 9 , 2 , 4 , 3 , 3 , 6 , 2 , 8 , 0 , 9 , 2 , 9 , 9 , 4 , 9 , 5 , 9 , 3 , 8 , 10 , 6 , 1 , 7 , 9 , 5 , 2 , 10 , 4 , 0 , 2 , 4 , 0}; 4 | //x[0] = in(); 5 | for(i from 1 to 100) { 6 | x[i] = x[i] +@place(x[i]) x[i -@any 1]; 7 | } 8 | out(x[99]); 9 | } 10 | -------------------------------------------------------------------------------- /examples/parallel/ssd-heu.cll: -------------------------------------------------------------------------------- 1 | int::2 cadd0(int::2 a, int b) { 2 | int::2 z; 3 | z::0 = a::0 + b; 4 | z::1 = a::1 + (z::0 >> 16); 5 | z::0 = z::0 & 65535; 6 | return z; 7 | } 8 | 9 | int::2 cadd1(int::2 a, int b) { 10 | int::2 z; 11 | z::0 = a::0 + b; 12 | z::1 = a::1 + (z::0 >> 16); 13 | z::0 = z::0 & 65535; 14 | return z; 15 | } 16 | 17 | int::2 cadd2(int::2 a, int b) { 18 | int::2 z; 19 | z::0 = a::0 + b; 20 | z::1 = a::1 + (z::0 >> 16); 21 | z::0 = z::0 & 65535; 22 | return z; 23 | } 24 | 25 | int::2 cadd3(int::2 a, int b) { 26 | int::2 z; 27 | z::0 = a::0 + b; 28 | z::1 = a::1 + (z::0 >> 16); 29 | z::0 = z::0 & 65535; 30 | return z; 31 | } 32 | 33 | void main() { 34 | int[]@{[0:40]=0,[40:80]=1,[80:120]=2,[120:160]=3} l[160] = {22 , 97 , 93 , 90 , 88 , 56 , 42 , 70 , 75 , 87 , 45 , 40 , 20 , 79 , 96 , 35 , 28 , 76 , 80 , 2 , 19 , 68 , 93 , 17 , 43 , 61 , 31 , 16 , 29 , 93 , 69 , 90 , 32 , 41 , 25 , 0 , 6 , 55 , 48 , 90 , 26 , 49 , 82 , 57 , 29 , 2 , 40 , 11 , 9 , 33 , 15 , 90 , 50 , 77 , 11 , 38 , 87 , 26 , 20 , 48 , 75 , 27 , 16 , 93 , 66 , 93 , 33 , 17 , 62 , 74 , 85 , 28 , 22 , 51 , 71 , 11 , 54 , 5 , 88 , 6 , 98 , 76 , 69 , 38 , 28 , 44 , 40 , 65 , 47 , 26 , 35 , 45 , 11 , 31 , 5 , 58 , 30 , 40 , 60 , 98 , 72 , 6 , 29 , 87 , 51 , 28 , 78 , 51 , 52 , 44 , 91 , 83 , 90 , 16 , 10 , 15 , 47 , 75 , 24 , 10 , 2 , 30 , 55 , 81 , 13 , 53 , 48 , 39 , 93 , 17 , 30 , 95 , 22 , 45 , 5 , 98 , 99 , 17 , 89 , 37 , 85 , 65 , 47 , 10 , 85 , 68 , 87 , 68 , 41 , 74 , 80 , 50 , 71 , 12 , 54 , 50 , 35 , 95 , 54 , 66}; 35 | int[]@{[0:40]=4,[40:80]=5,[80:120]=6,[120:160]=7} r[160] = {17 , 71 , 84 , 0 , 67 , 24 , 28 , 12 , 47 , 46 , 96 , 41 , 62 , 31 , 47 , 23 , 79 , 24 , 73 , 29 , 68 , 97 , 42 , 39 , 100 , 74 , 42 , 89 , 32 , 28 , 63 , 74 , 45 , 96 , 53 , 92 , 86 , 100 , 27 , 89 , 95 , 18 , 44 , 29 , 3 , 29 , 21 , 71 , 80 , 48 , 56 , 10 , 57 , 16 , 67 , 92 , 96 , 87 , 8 , 58 , 34 , 18 , 76 , 83 , 78 , 46 , 13 , 75 , 1 , 37 , 24 , 67 , 100 , 35 , 7 , 32 , 62 , 4 , 68 , 20 , 67 , 60 , 36 , 78 , 81 , 96 , 97 , 62 , 16 , 54 , 24 , 24 , 24 , 44 , 76 , 10 , 62 , 94 , 37 , 1 , 50 , 50 , 89 , 1 , 59 , 86 , 49 , 95 , 78 , 16 , 99 , 76 , 37 , 54 , 58 , 96 , 78 , 23 , 56 , 87 , 27 , 85 , 88 , 4 , 91 , 92 , 31 , 68 , 80 , 100 , 82 , 86 , 4 , 15 , 16 , 90 , 51 , 2 , 74 , 85 , 83 , 39 , 39 , 10 , 2 , 38 , 13 , 16 , 65 , 13 , 48 , 54 , 97 , 10 , 56 , 98 , 16 , 47 , 2 , 95}; 36 | int::2 sum; 37 | 38 | int temp0; 39 | int temp1; 40 | int temp2; 41 | int temp3; 42 | int::2@(8,18) sum_local0; 43 | int::2@(9,19) sum_local1; 44 | int::2@(10,20) sum_local2; 45 | int::2@(11,21) sum_local3; 46 | 47 | l[0] = in(); 48 | sum_local0 = 0; 49 | sum_local1 = 0; 50 | sum_local2 = 0; 51 | sum_local3 = 0; 52 | 53 | for(i from 0 to 40) { 54 | temp0 = l[i] - r[i]; 55 | sum_local0 = cadd0(sum_local0, temp0 * temp0); 56 | } 57 | for(i from 40 to 80) { 58 | temp1 = l[i] - r[i]; 59 | sum_local1 = cadd1(sum_local1, temp1 * temp1); 60 | } 61 | for(i from 80 to 120) { 62 | temp2 = l[i] - r[i]; 63 | sum_local2 = cadd2(sum_local2, temp2 * temp2); 64 | } 65 | for(i from 120 to 160) { 66 | temp3 = l[i] - r[i]; 67 | sum_local3 = cadd3(sum_local3, temp3 * temp3); 68 | } 69 | 70 | sum = sum_local0 + sum_local1 + sum_local2 + sum_local3; 71 | sum::1 = sum::1 + ((sum::0 >> 16) & 3); 72 | sum::0 = sum::0 & 65535; 73 | out(sum::0); //16224 74 | out(sum::1); //2 75 | } 76 | 77 | -------------------------------------------------------------------------------- /examples/parallel/ssd.cll: -------------------------------------------------------------------------------- 1 | int::2@(8, 18) cadd0(int::2@(8, 18) a, int@8 b) { 2 | int::2@(8, 18) z; 3 | z::0 = a::0 +@8 b; 4 | z::1 = a::1 +@18 (z::0 >>@8 16); 5 | z::0 = z::0 &@8 65535; 6 | return z; 7 | } 8 | int::2@(9, 19) cadd1(int::2@(9, 19) a, int@9 b) { 9 | int::2@(9, 19) z; 10 | z::0 = a::0 +@9 b; 11 | z::1 = a::1 +@19 (z::0 >>@9 16); 12 | z::0 = z::0 &@9 65535; 13 | return z; 14 | } 15 | 16 | int::2@(10, 20) cadd2(int::2@(10, 20) a, int@10 b) { 17 | int::2@(10, 20) z; 18 | z::0 = a::0 +@10 b; 19 | z::1 = a::1 +@20 (z::0 >>@10 16); 20 | z::0 = z::0 &@10 65535; 21 | return z; 22 | } 23 | 24 | int::2@(11, 21) cadd3(int::2@(11, 21) a, int@11 b) { 25 | int::2@(11, 21) z; 26 | z::0 = a::0 +@11 b; 27 | z::1 = a::1 +@21 (z::0 >>@11 16); 28 | z::0 = z::0 &@11 65535; 29 | return z; 30 | } 31 | 32 | void main() { 33 | int@{[0:40]=0,[40:80]=1,[80:120]=2,[120:160]=3} l[160] = {22 , 97 , 93 , 90 , 88 , 56 , 42 , 70 , 75 , 87 , 45 , 40 , 20 , 79 , 96 , 35 , 28 , 76 , 80 , 2 , 19 , 68 , 93 , 17 , 43 , 61 , 31 , 16 , 29 , 93 , 69 , 90 , 32 , 41 , 25 , 0 , 6 , 55 , 48 , 90 , 26 , 49 , 82 , 57 , 29 , 2 , 40 , 11 , 9 , 33 , 15 , 90 , 50 , 77 , 11 , 38 , 87 , 26 , 20 , 48 , 75 , 27 , 16 , 93 , 66 , 93 , 33 , 17 , 62 , 74 , 85 , 28 , 22 , 51 , 71 , 11 , 54 , 5 , 88 , 6 , 98 , 76 , 69 , 38 , 28 , 44 , 40 , 65 , 47 , 26 , 35 , 45 , 11 , 31 , 5 , 58 , 30 , 40 , 60 , 98 , 72 , 6 , 29 , 87 , 51 , 28 , 78 , 51 , 52 , 44 , 91 , 83 , 90 , 16 , 10 , 15 , 47 , 75 , 24 , 10 , 2 , 30 , 55 , 81 , 13 , 53 , 48 , 39 , 93 , 17 , 30 , 95 , 22 , 45 , 5 , 98 , 99 , 17 , 89 , 37 , 85 , 65 , 47 , 10 , 85 , 68 , 87 , 68 , 41 , 74 , 80 , 50 , 71 , 12 , 54 , 50 , 35 , 95 , 54 , 66}; 34 | int@{[0:40]=4,[40:80]=5,[80:120]=6,[120:160]=7} r[160] = {17 , 71 , 84 , 0 , 67 , 24 , 28 , 12 , 47 , 46 , 96 , 41 , 62 , 31 , 47 , 23 , 79 , 24 , 73 , 29 , 68 , 97 , 42 , 39 , 100 , 74 , 42 , 89 , 32 , 28 , 63 , 74 , 45 , 96 , 53 , 92 , 86 , 100 , 27 , 89 , 95 , 18 , 44 , 29 , 3 , 29 , 21 , 71 , 80 , 48 , 56 , 10 , 57 , 16 , 67 , 92 , 96 , 87 , 8 , 58 , 34 , 18 , 76 , 83 , 78 , 46 , 13 , 75 , 1 , 37 , 24 , 67 , 100 , 35 , 7 , 32 , 62 , 4 , 68 , 20 , 67 , 60 , 36 , 78 , 81 , 96 , 97 , 62 , 16 , 54 , 24 , 24 , 24 , 44 , 76 , 10 , 62 , 94 , 37 , 1 , 50 , 50 , 89 , 1 , 59 , 86 , 49 , 95 , 78 , 16 , 99 , 76 , 37 , 54 , 58 , 96 , 78 , 23 , 56 , 87 , 27 , 85 , 88 , 4 , 91 , 92 , 31 , 68 , 80 , 100 , 82 , 86 , 4 , 15 , 16 , 90 , 51 , 2 , 74 , 85 , 83 , 39 , 39 , 10 , 2 , 38 , 13 , 16 , 65 , 13 , 48 , 54 , 97 , 10 , 56 , 98 , 16 , 47 , 2 , 95}; 35 | int::2@(21,21) sum; 36 | 37 | int@8 temp0; 38 | int@9 temp1; 39 | int@10 temp2; 40 | int@11 temp3; 41 | int::2@(8,18) sum_local0; 42 | int::2@(9,19) sum_local1; 43 | int::2@(10,20) sum_local2; 44 | int::2@(11,21) sum_local3; 45 | 46 | //l[0] = in(); 47 | sum_local0 = 0; 48 | sum_local1 = 0; 49 | sum_local2 = 0; 50 | sum_local3 = 0; 51 | 52 | for(i from 0 to 40) { 53 | temp0 = l[i] -@place(temp0) r[i]; 54 | sum_local0 = cadd0(sum_local0, temp0 *@place(temp0) temp0); 55 | } 56 | for(i from 40 to 80) { 57 | temp1 = l[i] -@place(temp1) r[i]; 58 | sum_local1 = cadd1(sum_local1, temp1 *@place(temp1) temp1); 59 | } 60 | for(i from 80 to 120) { 61 | temp2 = l[i] -@place(temp2) r[i]; 62 | sum_local2 = cadd2(sum_local2, temp2 *@place(temp2) temp2); 63 | } 64 | for(i from 120 to 160) { 65 | temp3 = l[i] -@place(temp3) r[i]; 66 | sum_local3 = cadd3(sum_local3, temp3 *@place(temp3) temp3); 67 | } 68 | 69 | sum = sum_local0 +@(32,21) sum_local1 +@(32,21) sum_local2 +@(32,21) sum_local3; 70 | sum::1 = sum::1 +@21 ((sum::0 >>@21 16) &@21 3); 71 | sum::0 = sum::0 &@21 65535; 72 | out(sum::0); //16224 73 | out(sum::1); //2 74 | } 75 | 76 | -------------------------------------------------------------------------------- /examples/parallel/swap.cll: -------------------------------------------------------------------------------- 1 | int::2@(12,12) swap0(int@0 x, int@4 y, int@0 m0, int@4 m1) { 2 | int::2@(12,12) output; 3 | output::0 = (y &@place(y) m1) |@12 (x &@place(x) ~@place(x) m0); 4 | output::1 = (y &@place(y) ~@place(y) m1) |@12 (x &@place(x) m0); 5 | return output; 6 | } 7 | 8 | int::2@(13,13) swap1(int@1 x, int@5 y, int@1 m0, int@5 m1) { 9 | int::2@(13,13) output; 10 | output::0 = (y &@place(y) m1) |@13 (x &@place(x) ~@place(x) m0); 11 | output::1 = (y &@place(y) ~@place(y) m1) |@13 (x &@place(x) m0); 12 | return output; 13 | } 14 | 15 | int::2@(14,14) swap2(int@2 x, int@6 y, int@2 m0, int@6 m1) { 16 | int::2@(14,14) output; 17 | output::0 = (y &@place(y) m1) |@14 (x &@place(x) ~@place(x) m0); 18 | output::1 = (y &@place(y) ~@place(y) m1) |@14 (x &@place(x) m0); 19 | return output; 20 | } 21 | 22 | int::2@(15,15) swap3(int@3 x, int@7 y, int@3 m0, int@7 m1) { 23 | int::2@(15,15) output; 24 | output::0 = (y &@place(y) m1) |@15 (x &@place(x) ~@place(x) m0); 25 | output::1 = (y &@place(y) ~@place(y) m1) |@15 (x &@place(x) m0); 26 | return output; 27 | } 28 | 29 | void main() { 30 | //x' = (y & m) | (x & !m), y' = (y & ~m) | (x & m) 31 | 32 | int@{[0:15]=0,[15:30]=1,[30:45]=2,[45:60]=3} x[60] = {9384 , 6757 , 36599 , 41715 , 38371 , 26178 , 23545 , 6083 , 1659 , 21090 , 53463 , 27567 , 9845 , 38229 , 6215 , 57900 , 49991 , 41841 , 52798 , 58710 , 64429 , 55435 , 22829 , 2860 , 1464 , 57658 , 46811 , 10989 , 51967 , 3593 , 47393 , 38244 , 30200 , 11081 , 17290 , 65224 , 10669 , 21785 , 20995 , 5087 , 52534 , 33547 , 61489 , 53218 , 17573 , 13935 , 55211 , 60559 , 2028 , 27073 , 2913 , 34988 , 22464 , 28740 , 53614 , 48961 , 36941 , 46641 , 60737 , 8352}; 33 | int@{[0:15]=4,[15:30]=5,[30:45]=6,[45:60]=7} y[60] = {33771 , 63253 , 24549 , 53501 , 19211 , 9316 , 40089 , 18853 , 40278 , 50456 , 33684 , 15316 , 47434 , 56388 , 32313 , 28354 , 33602 , 46621 , 26489 , 19700 , 51622 , 12297 , 50130 , 48668 , 18826 , 16920 , 62056 , 54507 , 26931 , 50957 , 19187 , 36565 , 24912 , 20426 , 11216 , 5947 , 48302 , 62682 , 34124 , 48275 , 21530 , 20559 , 65187 , 27221 , 21550 , 18407 , 47065 , 17712 , 194 , 42981 , 65515 , 25425 , 2745 , 37446 , 14003 , 29997 , 52711 , 11181 , 46626 , 62657}; 34 | int@{[0:15]=8,[15:30]=9,[30:45]=10,[45:60]=11} m[60] = {36981 , 23549 , 57213 , 53765 , 7848 , 19047 , 13071 , 26345 , 4040 , 52880 , 58560 , 15811 , 7315 , 29863 , 6789 , 47241 , 20197 , 48638 , 43314 , 61303 , 41273 , 21678 , 54386 , 11268 , 5464 , 62318 , 401 , 62508 , 63921 , 39129 , 20727 , 18596 , 46407 , 6851 , 11532 , 54554 , 32071 , 55132 , 9104 , 6259 , 34373 , 28775 , 8117 , 22558 , 43486 , 7072 , 46618 , 56764 , 49902 , 27910 , 22584 , 22073 , 8403 , 21894 , 12259 , 738 , 48847 , 46803 , 47958 , 37200}; 35 | int::2@(12,12) temp0; 36 | int::2@(13,13) temp1; 37 | int::2@(14,14) temp2; 38 | int::2@(15,15) temp3; 39 | 40 | /*x[0] = in(); 41 | x[15] = in(); 42 | x[30] = in(); 43 | x[45] = in();*/ 44 | 45 | 46 | for(i from 0 to 15) { 47 | temp0 = swap0(x[i],y[i],m[i],m[i]); 48 | x[i] = temp0::0; 49 | y[i] = temp0::1; 50 | } 51 | for(i from 15 to 30) { 52 | temp1 = swap1(x[i],y[i],m[i],m[i]); 53 | x[i] = temp1::0; 54 | y[i] = temp1::1; 55 | } 56 | for(i from 30 to 45) { 57 | temp2 = swap2(x[i],y[i],m[i],m[i]); 58 | x[i] = temp2::0; 59 | y[i] = temp2::1; 60 | } 61 | for(i from 45 to 60) { 62 | temp3 = swap3(x[i],y[i],m[i],m[i]); 63 | x[i] = temp3::0; 64 | y[i] = temp3::1; 65 | } 66 | 67 | out(x[0]); //16224 0xa4e9 68 | out(x[15]); //42217 0x6aa4 69 | out(x[30]); //59891 0xe9f3 70 | out(x[45]); //10223 0x27ef 71 | } 72 | -------------------------------------------------------------------------------- /examples/rom/complex0.cll: -------------------------------------------------------------------------------- 1 | int cosine(int x) { 2 | int y; 3 | int coeff[4] = {-281 , 5203 , -42329 , 37407}; 4 | int sum; 5 | 6 | x = x << 2; 7 | if(x < 0) { 8 | x = x + 65536; 9 | } else { 10 | x = 65536 - x; 11 | } 12 | 13 | y = x */16 x; 14 | sum = 0; 15 | for(i from 0 to 4) { 16 | sum = (sum */16 y) + coeff[i]; 17 | } 18 | 19 | return (sum */16 x) + x; 20 | } 21 | 22 | int sqrt(int::2 x) { 23 | int res; 24 | int add; 25 | int temp; 26 | int::2 g2; 27 | 28 | res = 0; 29 | add = 32768; 30 | for(i from 0 to 16) { 31 | temp = res | add; 32 | g2 = temp *:2 temp; 33 | g2::0 = (g2::0 << 2) + ((g2::1 >> 16) & 3); 34 | g2::1 = g2::1 & 65535; 35 | if(x::0 > g2::0) { 36 | res = temp; 37 | } else { 38 | if(x::0 == g2::0) { 39 | if(x::1 >= g2::1) { 40 | res = temp; 41 | } 42 | } 43 | } 44 | add = add >>@place(add) 1; 45 | } 46 | return res; 47 | } 48 | 49 | void main() { 50 | int cos; 51 | int::2 cos2; 52 | int::2 sin2; 53 | int rev; 54 | int sin; 55 | 56 | rev = in(); 57 | cos = cosine(rev); 58 | out(cos); 59 | 60 | cos2 = cos *:2 cos; 61 | cos2::0 = (cos2::0 << 2) + ((cos2::1 >> 16) & 3); 62 | cos2::1 = cos2::1 & 65535; 63 | 64 | if(cos2::1 > 0) { 65 | sin2::1 = 65536 - cos2::1; 66 | sin2::0 = 65535 - cos2::0; 67 | } else { 68 | sin2::1 = 0; 69 | sin2::0 = 65536 - cos2::0; 70 | } 71 | sin = sqrt(sin2); 72 | if(rev < 0) { 73 | sin = -sin; 74 | } 75 | out(sin); 76 | } 77 | -------------------------------------------------------------------------------- /examples/rom/complex1.cll: -------------------------------------------------------------------------------- 1 | int@1 cosine(int@1 x) { 2 | int@3 y; 3 | int@3 coeff[4] = {-281 , 5203 , -42329 , 37407}; 4 | int@3 sum; 5 | 6 | x = x <<@1 2; 7 | if(x <@1 0) { 8 | x = x +@1 65536; 9 | } else { 10 | x = 65536 -@1 x; 11 | } 12 | 13 | y = x */16 x; 14 | sum = 0; 15 | for(i from 0 to 4) { 16 | sum = (sum */16 y) + coeff[i]; 17 | } 18 | 19 | return (sum */16 x) + x; 20 | } 21 | 22 | int@7 sqrt(int::2@(4,0) x) { 23 | int@7 res; 24 | int@0 add; 25 | int@7 temp; 26 | int::2@(4,0) g2; 27 | 28 | res = 0; 29 | add = 32768; 30 | for(i from 0 to 16) { 31 | temp = res | add; 32 | g2 = temp *:2 temp; 33 | g2::0 = (g2::0 << 2) + ((g2::1 >> 16) & 3); 34 | g2::1 = g2::1 &@0 65535; 35 | if(x::0 > g2::0) { 36 | res = temp; 37 | } else { 38 | if(x::0 == g2::0) { 39 | if(x::1 >= g2::1) { 40 | res = temp; 41 | } 42 | } 43 | } 44 | add = add >>@place(add) 1; 45 | } 46 | return res; 47 | } 48 | 49 | void main() { 50 | int cos; 51 | int::2 cos2; 52 | int::2 sin2; 53 | int rev; 54 | int sin; 55 | 56 | rev = in(); 57 | cos = cosine(rev); 58 | out(cos); 59 | 60 | cos2 = cos *:2 cos; 61 | cos2::0 = (cos2::0 << 2) + ((cos2::1 >> 16) & 3); 62 | cos2::1 = cos2::1 & 65535; 63 | 64 | if(cos2::1 > 0) { 65 | sin2::1 = 65536 - cos2::1; 66 | sin2::0 = 65535 - cos2::0; 67 | } else { 68 | sin2::1 = 0; 69 | sin2::0 = 65536 - cos2::0; 70 | } 71 | sin = sqrt(sin2); 72 | if(rev < 0) { 73 | sin = -sin; 74 | } 75 | out(sin); 76 | } 77 | -------------------------------------------------------------------------------- /examples/rom/complex2.cll: -------------------------------------------------------------------------------- 1 | int@1 cosine(int@1 x) { 2 | int@3 y; 3 | int@3 coeff[4] = {-281 , 5203 , -42329 , 37407}; 4 | int@3 sum; 5 | 6 | x = x <<@1 2; 7 | if(x < 0) { 8 | x = x +@1 65536; 9 | } else { 10 | x = 65536 -@1 x; 11 | } 12 | 13 | y = x */16@1 x; 14 | sum = 0; 15 | for(i from 0 to 4) { 16 | sum = (sum */16@3 y) +@3 coeff[i]; 17 | } 18 | 19 | return (sum */16@1 x) +@1 x; 20 | } 21 | 22 | int@7 sqrt(int::2@(4,0) x) { 23 | int@7 res; 24 | int@0 add; 25 | int@7 temp; 26 | int::2@(4,0) g2; 27 | 28 | res = 0; 29 | add = 32768; 30 | for(i from 0 to 16) { 31 | temp = res | add; 32 | g2 = temp *:2 temp; 33 | g2::0 = (g2::0 <<@4 2) +@4 ((g2::1 >> 16) & 3); 34 | g2::1 = g2::1 &@0 65535; 35 | if(x::0 >@4 g2::0) { 36 | res = temp; 37 | } else { 38 | if(x::0 ==@4 g2::0) { 39 | if(x::1 >=@0 g2::1) { 40 | res = temp; 41 | } 42 | } 43 | } 44 | add = add >>@place(add) 1; 45 | } 46 | return res; 47 | } 48 | 49 | void main() { 50 | int cos; 51 | int::2 cos2; 52 | int::2 sin2; 53 | int rev; 54 | int sin; 55 | 56 | rev = in(); 57 | cos = cosine(rev); 58 | out(cos); 59 | 60 | cos2 = cos *:2 cos; 61 | cos2::0 = (cos2::0 << 2) + ((cos2::1 >> 16) & 3); 62 | cos2::1 = cos2::1 & 65535; 63 | 64 | if(cos2::1 > 0) { 65 | sin2::1 = 65536 - cos2::1; 66 | sin2::0 = 65535 - cos2::0; 67 | } else { 68 | sin2::1 = 0; 69 | sin2::0 = 65536 - cos2::0; 70 | } 71 | sin = sqrt(sin2); 72 | if(rev < 0) { 73 | sin = -sin; 74 | } 75 | out(sin); 76 | } 77 | -------------------------------------------------------------------------------- /examples/rom/complex3.cll: -------------------------------------------------------------------------------- 1 | int@1 cosine(int@1 x) { 2 | int@3 y; 3 | int@3 coeff[4] = {-281 , 5203 , -42329 , 37407}; 4 | int@3 sum; 5 | 6 | x = x <<@1 2; 7 | if(x < 0) { 8 | x = x +@1 65536; 9 | } else { 10 | x = 65536 -@1 x; 11 | } 12 | 13 | y = x */16@1 x; 14 | sum = 0; 15 | for(i from 0 to 4) { 16 | sum = (sum */16@3 y) +@3 coeff[i]; 17 | } 18 | 19 | return (sum */16@1 x) +@1 x; 20 | } 21 | 22 | int@7 sqrt(int::2@(4,0) x) { 23 | int@7 res; 24 | int@0 add; 25 | int@7 temp; 26 | int::2@(4,0) g2; 27 | 28 | res = 0; 29 | add = 32768; 30 | for(i from 0 to 16) { 31 | temp = res |@7 add; 32 | g2 = temp *:2@7 temp; 33 | g2::0 = (g2::0 <<@4 2) +@4 ((g2::1 >>@0 16) &@0 3); 34 | g2::1 = g2::1 &@0 65535; 35 | if(x::0 >@4 g2::0) { 36 | res = temp; 37 | } else { 38 | if(x::0 ==@4 g2::0) { 39 | if(x::1 >=@0 g2::1) { 40 | res = temp; 41 | } 42 | } 43 | } 44 | add = add >>@place(add) 1; 45 | } 46 | return res; 47 | } 48 | 49 | void main() { 50 | int@5 cos; 51 | int::2@(6,5) cos2; 52 | int::2@(6,5) sin2; 53 | int@1 rev; 54 | int@8 sin; 55 | 56 | rev = in(); 57 | cos = cosine(rev); 58 | out(cos); 59 | 60 | cos2 = cos *:2@5 cos; 61 | cos2::0 = (cos2::0 <<@6 2) +@6 ((cos2::1 >>@6 16) &@6 3); 62 | cos2::1 = cos2::1 &@5 65535; 63 | 64 | if(cos2::1 >@5 0) { 65 | sin2::1 = 65536 -@5 cos2::1; 66 | sin2::0 = 65535 -@6 cos2::0; 67 | } else { 68 | sin2::1 = 0; 69 | sin2::0 = 65536 -@6 cos2::0; 70 | } 71 | sin = sqrt(sin2); 72 | if(rev < 0) { 73 | sin = -@8 sin; 74 | } 75 | out(sin); 76 | } 77 | -------------------------------------------------------------------------------- /examples/rom/cos.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 x; 3 | int@0 y; 4 | int coeff[4] = {-281 , 5203 , -42329 , 37407}; 5 | int@0 sum; 6 | 7 | x = in() << 2; 8 | if(x < 0) { 9 | x = x + 65536; 10 | } else { 11 | x = 65536 - x; 12 | } 13 | 14 | y = x */16 x; 15 | sum = 0; 16 | for(i from 0 to 4) { 17 | sum = sum */16 y + coeff[i]; 18 | } 19 | 20 | out(sum */16 x + x); 21 | } 22 | -------------------------------------------------------------------------------- /examples/rom/div17.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | out(in()/17); 3 | } 4 | -------------------------------------------------------------------------------- /examples/rom/fir-par2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:8]=0} filter0[8] = {8192,131071,131071,65536,65536,32768,32768,16384}; 3 | int@{[0:8]=1} filter1[8] = {131071,8192,16384,32768,32768,65536,65536,131071}; 4 | int@{[0:8]=0} x0[8] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0}; 5 | int@{[0:8]=1} x1[8] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0}; 6 | int@0 sum0, b0; 7 | int@1 sum1, b1; 8 | int@2 offset; // offset 0 9 | 10 | b0 = offset; 11 | b1 = offset; 12 | x1[b1] = x0[b0]; 13 | x0[b0] = in(); 14 | sum0 = 0; 15 | sum1 = 0; 16 | 17 | for(i from 0 to 8) { 18 | sum0 = sum0 +@0 filter0[i] */17@0 x0[b0]; 19 | b0 = (b0 +@0 1) &@0 7; 20 | } 21 | 22 | for(i from 0 to 8) { 23 | sum1 = sum1 +@1 filter1[i] */17@1 x1[b1]; 24 | b1 = (b1 +@1 1) &@1 7; 25 | } 26 | 27 | offset = (offset +@place(offset) 1) &@place(offset) 7; 28 | out(sum0 +@1 sum1); 29 | } 30 | -------------------------------------------------------------------------------- /examples/rom/fir-par4.cll: -------------------------------------------------------------------------------- 1 | 2 | void main() { 3 | int@{[0:4]=0} filter0[4] = {8192,32768,32768,16384}; 4 | int@{[0:4]=1} filter1[4] = {65536,131071,131071,65536}; 5 | int@{[0:4]=2} filter2[4] = {131071,65536,65536,131071}; 6 | int@{[0:4]=3} filter3[4] = {32768,8192,16384,32768}; 7 | int@{[0:4]=0} x0[4] = {0 , 0 , 0 , 0}; 8 | int@{[0:4]=1} x1[4] = {0 , 0 , 0 , 0}; 9 | int@{[0:4]=2} x2[4] = {0 , 0 , 0 , 0}; 10 | int@{[0:4]=3} x3[4] = {0 , 0 , 0 , 0}; 11 | 12 | int@0 sum0, b0; 13 | int@1 sum1, b1; 14 | int@2 sum2, b2; 15 | int@3 sum3, b3; 16 | int@4 offset; // offset 0 17 | 18 | b0 = offset; 19 | b1 = b0; 20 | b2 = b1; 21 | b3 = b2; 22 | x3[b3] = x2[b2]; 23 | x2[b2] = x1[b1]; 24 | x1[b1] = x0[b0]; 25 | x0[b0] = in(); 26 | sum0 = 0; 27 | sum1 = 0; 28 | sum2 = 0; 29 | sum3 = 0; 30 | 31 | for(i from 0 to 4) { 32 | sum0 = sum0 +@0 filter0[i] */17@0 x0[b0]; 33 | b0 = (b0 +@0 1) &@0 3; 34 | } 35 | 36 | for(i from 0 to 4) { 37 | sum1 = sum1 +@1 filter1[i] */17@1 x1[b1]; 38 | b1 = (b1 +@1 1) &@1 3; 39 | } 40 | 41 | for(i from 0 to 4) { 42 | sum2 = sum2 +@2 filter2[i] */17@2 x2[b2]; 43 | b2 = (b2 +@2 1) &@2 3; 44 | } 45 | 46 | for(i from 0 to 4) { 47 | sum3 = sum3 +@3 filter3[i] */17@3 x3[b3]; 48 | b3 = (b3 +@3 1) &@3 3; 49 | } 50 | 51 | offset = (offset +@place(offset) 1) &@place(offset) 3; 52 | out(sum3 +@2 sum2 +@1 sum1 +@0 sum0); 53 | } 54 | -------------------------------------------------------------------------------- /examples/rom/fir.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:16]=0} filter[16] = {8192,8192,16384,32768,32768,65536,65536,131071,131071,131071,131071,65536,65536,32768,32768,16384}; 3 | int@{[0:16]=0} x[16] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0}; 4 | int@0 bbb; 5 | int@1 sum, offset; // offset 0 6 | 7 | bbb = offset; 8 | x[bbb] = in(); 9 | sum = 0; 10 | 11 | for(i from 0 to 16) { 12 | sum = sum +@1 filter[i] */17@0 x[bbb]; 13 | bbb = (bbb +@0 1) &@0 15; 14 | } 15 | 16 | offset = (offset +@1 1) &@1 15; 17 | out(sum); 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/rom/interp.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:9]=0} table[9] = {0, 450, 900, 1350, 1800, 2250, 2700, 3150, 3600}; 3 | int d; 4 | int r; 5 | int input; 6 | 7 | input = in(); 8 | r = input & 63; 9 | d = input >> 6; 10 | out(table[d] + (((table[d+1] - table[d])*r) >> 6)); 11 | } 12 | -------------------------------------------------------------------------------- /examples/rom/poly.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int coeff[8] = {31 , -46 , 54 , -72 , -51 , -46 , -67 , 69}; 3 | int@0 x, ans; 4 | x = in(); 5 | ans = 0; 6 | for(i from 0 to 8) { 7 | ans = ans */16 x + coeff[i]; 8 | } 9 | out(ans); 10 | } 11 | -------------------------------------------------------------------------------- /examples/rom/simple.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2@(0,0) x, y; 3 | y = x +@(0,0) x; 4 | } 5 | -------------------------------------------------------------------------------- /examples/rom/sqrt0.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2 x; 3 | int res; 4 | int add; 5 | int temp; 6 | int::2 g2; 7 | 8 | res = 0; 9 | add = 32768; 10 | 11 | x::0 = in(); // high 12 | x::1 = in(); // low 13 | for(i from 0 to 16) { 14 | temp = res | add; 15 | g2 = temp *:2 temp; 16 | g2::0 = (g2::0 << 2) + ((g2::1 >> 16) & 3); 17 | g2::1 = g2::1 & 65535; 18 | if(x::0 > g2::0) { 19 | res = temp; 20 | } else { 21 | if(x::0 == g2::0) { 22 | if(x::1 >= g2::1) { 23 | res = temp; 24 | } 25 | } 26 | } 27 | //out(res); 28 | add = add >> 1; 29 | } 30 | out(res); 31 | } 32 | -------------------------------------------------------------------------------- /examples/rom/sqrt1.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2@(0,1) x; 3 | int@1 res; 4 | int@1 add; 5 | int@1 temp; 6 | int::2@(0,0) g2; 7 | 8 | res = 0; 9 | add = 32768; 10 | 11 | x::0 = in(); // high 12 | x::1 = in(); // low 13 | for(i from 0 to 16) { 14 | temp = res | add; 15 | g2 = temp *:2 temp; 16 | g2::0 = (g2::0 << 2) + ((g2::1 >> 16) & 3); 17 | g2::1 = g2::1 & 65535; 18 | if(x::0 > g2::0) { 19 | res = temp; 20 | } else { 21 | if(x::0 == g2::0) { 22 | if(x::1 >= g2::1) { 23 | res = temp; 24 | } 25 | } 26 | } 27 | //out(res); 28 | add = add >>@place(add) 1; 29 | } 30 | out(res); 31 | } 32 | -------------------------------------------------------------------------------- /examples/rom/sqrt2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2@(0,1) x; 3 | int@1 res; 4 | int@1 add; 5 | int@1 temp; 6 | int::2@(0,0) g2; 7 | 8 | res = 0; 9 | add = 32768; 10 | 11 | x::0 = in(); // high 12 | x::1 = in(); // low 13 | for(i from 0 to 16) { 14 | temp = res |@place(temp) add; 15 | g2 = temp *:2@2 temp; 16 | g2::0 = (g2::0 <<@0 2) +@0 ((g2::1 >>@0 16) &@0 3); 17 | g2::1 = g2::1 &@0 65535; 18 | if(x::0 >@0 g2::0) { 19 | res = temp; 20 | } else { 21 | if(x::0 ==@0 g2::0) { 22 | if(x::1 >=@1 g2::1) { 23 | res = temp; 24 | } 25 | } 26 | } 27 | //out(res); 28 | add = add >>@place(add) 1; 29 | } 30 | out(res); 31 | } 32 | -------------------------------------------------------------------------------- /examples/sensors/compiled-code/README: -------------------------------------------------------------------------------- 1 | hmm-noacc.aforth 2 | --> final classifier code with out accelerometer reading 3 | hmm-filter13-no-acc.aforth 4 | --> less accuracy version (skip 13 accelerometer readings before processing a new one) 5 | 6 | accelerometer-opt.aforth 7 | --> read from accelermoter at ~200Hz 8 | accelerometer-power-meas.aforth 9 | --> measure the power consumption of accelerometer reading 10 | guesture-recognition-opt.aforth 11 | --> complete guesture recognition application 12 | guesture-recognition-msp430-sim.aforth 13 | --> measure classifcation accuracy on the msp430 14 | processing-power-meas.aforth 15 | --> measure power consumption for processing the acceleromter readings 16 | -------------------------------------------------------------------------------- /examples/sensors/compiled-code/codesize-comp/complete.info: -------------------------------------------------------------------------------- 1 | 205 25 39.0625% 2 | 104 54 84.375% 3 | 4 51 79.6875% 4 | 3 53 82.8125% 5 | 2 53 82.8125% 6 | 1 33 51.5625% 7 | 212 25 39.0625% 8 | 111 54 84.375% 9 | 11 51 79.6875% 10 | 10 53 82.8125% 11 | 9 53 82.8125% 12 | 8 33 51.5625% 13 | 102 57 89.0625% 14 | 101 48 75.0% 15 | 103 62 96.875% 16 | 105 21 32.8125% 17 | 106 44 68.75% 18 | 109 55 85.9375% 19 | 108 48 75.0% 20 | 110 62 96.875% 21 | 112 23 35.9375% 22 | 113 44 68.75% 23 | 201 45 70.3125% 24 | 202 49 76.5625% 25 | 203 51 79.6875% 26 | 204 4 6.25% 27 | 206 62 96.875% 28 | 207 44 68.75% 29 | 208 45 70.3125% 30 | 209 49 76.5625% 31 | 210 51 79.6875% 32 | 211 4 6.25% 33 | 213 62 96.875% 34 | 214 44 68.75% 35 | 301 3 4.6875% 36 | 302 38 59.375% 37 | 303 27 42.1875% 38 | 304 16 25.0% 39 | 305 25 39.0625% 40 | 306 44 68.75% 41 | 307 3 4.6875% 42 | 308 14 21.875% 43 | 309 47 73.4375% 44 | 310 20 31.25% 45 | 311 16 25.0% 46 | 312 16 25.0% 47 | 313 44 68.75% 48 | 401 3 4.6875% 49 | 403 10 15.625% 50 | 404 3 4.6875% 51 | 405 18 28.125% 52 | 406 14 21.875% 53 | 407 19 29.6875% 54 | 408 17 26.5625% 55 | 409 14 21.875% 56 | 411 8 12.5% 57 | 412 6 9.375% 58 | 501 3 4.6875% 59 | 502 3 4.6875% 60 | 503 13 20.3125% 61 | 504 12 18.75% 62 | 505 17 26.5625% 63 | 506 40 62.5% 64 | 507 61 95.3125% 65 | 508 57 89.0625% 66 | 509 44 68.75% 67 | 510 58 90.625% 68 | 511 50 78.125% 69 | 600 41 64.0625% 70 | 601 5 7.8125% 71 | 602 3 4.6875% 72 | 607 22 34.375% 73 | 713 41 64.0625% 74 | 608 52 81.25% 75 | 609 5 7.8125% 76 | 610 5 7.8125% 77 | 611 5 7.8125% 78 | 708 68* 106.25% 79 | 709 14 21.875% 80 | 711 5 7.8125% 81 | 712 5 7.8125% 82 | 715 43 67.1875% 83 | Total: 82 nodes, 2609 words, 28.309461805555557% 84 | -------------------------------------------------------------------------------- /examples/sensors/compiled-code/codesize-comp/noactor.info: -------------------------------------------------------------------------------- 1 | 1 64 100.0% 2 | 2 82* 128.125% 3 | 3 77* 120.3125% 4 | 4 68* 106.25% 5 | 5 7 10.9375% 6 | 6 6 9.375% 7 | 8 64 100.0% 8 | 9 80* 125.0% 9 | 10 75* 117.1875% 10 | 11 64 100.0% 11 | 101 70* 109.375% 12 | 102 68* 106.25% 13 | 103 64 100.0% 14 | 104 63 98.4375% 15 | 105 32 50.0% 16 | 106 56 87.5% 17 | 108 75* 117.1875% 18 | 109 64 100.0% 19 | 110 63 98.4375% 20 | 111 63 98.4375% 21 | 112 33 51.5625% 22 | 113 51 79.6875% 23 | 201 69* 107.8125% 24 | 202 47 73.4375% 25 | 203 48 75.0% 26 | 204 18 28.125% 27 | 205 17 26.5625% 28 | 206 87* 135.9375% 29 | 207 53 82.8125% 30 | 208 69* 107.8125% 31 | 209 51 79.6875% 32 | 210 50 78.125% 33 | 211 16 25.0% 34 | 212 19 29.6875% 35 | 213 83* 129.6875% 36 | 214 52 81.25% 37 | 301 9 14.0625% 38 | 302 35 54.6875% 39 | 303 15 23.4375% 40 | 304 19 29.6875% 41 | 305 16 25.0% 42 | 306 62 96.875% 43 | 307 13 20.3125% 44 | 308 16 25.0% 45 | 309 48 75.0% 46 | 310 18 28.125% 47 | 311 16 25.0% 48 | 312 16 25.0% 49 | 313 61 95.3125% 50 | 314 7 10.9375% 51 | 401 8 12.5% 52 | 404 12 18.75% 53 | 405 15 23.4375% 54 | 406 17 26.5625% 55 | 407 8 12.5% 56 | 408 18 28.125% 57 | 409 15 23.4375% 58 | 411 9 14.0625% 59 | 412 8 12.5% 60 | 413 8 12.5% 61 | 414 7 10.9375% 62 | 501 8 12.5% 63 | 502 7 10.9375% 64 | 503 7 10.9375% 65 | 504 13 20.3125% 66 | 505 17 26.5625% 67 | 506 51 79.6875% 68 | 507 63 98.4375% 69 | 508 61 95.3125% 70 | 509 40 62.5% 71 | 510 64 100.0% 72 | 511 50 78.125% 73 | 600 41 64.0625% 74 | 601 6 9.375% 75 | 602 3 4.6875% 76 | 603 3 4.6875% 77 | 604 3 4.6875% 78 | 605 3 4.6875% 79 | 606 3 4.6875% 80 | 607 22 34.375% 81 | 713 41 64.0625% 82 | 608 52 81.25% 83 | 609 5 7.8125% 84 | 610 5 7.8125% 85 | 611 5 7.8125% 86 | 708 68* 106.25% 87 | 709 14 21.875% 88 | 711 5 7.8125% 89 | 712 5 7.8125% 90 | 715 43 67.1875% 91 | Total: 90 nodes, 3152 words, 34.201388888888886% 92 | =================== 93 | 2 82* 128.125% 94 | 3 77* 120.3125% 95 | 4 68* 106.25% 96 | 9 80* 125.0% 97 | 10 75* 117.1875% 98 | 101 70* 109.375% 99 | 102 68* 106.25% 100 | 108 75* 117.1875% 101 | 201 69* 107.8125% 102 | 206 87* 135.9375% 103 | 208 69* 107.8125% 104 | 213 83* 129.6875% 105 | -------------------------------------------------------------------------------- /examples/sensors/compiled-code/codesize-comp/nolayout.info: -------------------------------------------------------------------------------- 1 | 4 62 96.875% 2 | 5 69* 107.8125% 3 | 6 70* 109.375% 4 | 7 77* 120.3125% 5 | 8 47 73.4375% 6 | 9 74* 115.625% 7 | 10 74* 115.625% 8 | 11 16 25.0% 9 | 12 11 17.1875% 10 | 103 14 21.875% 11 | 104 74* 115.625% 12 | 105 68* 106.25% 13 | 106 75* 117.1875% 14 | 107 71* 110.9375% 15 | 108 68* 106.25% 16 | 109 62 96.875% 17 | 110 89* 139.0625% 18 | 111 15 23.4375% 19 | 112 56 87.5% 20 | 203 54 84.375% 21 | 204 49 76.5625% 22 | 205 74* 115.625% 23 | 206 60 93.75% 24 | 207 33 51.5625% 25 | 208 63 98.4375% 26 | 209 71* 110.9375% 27 | 210 76* 118.75% 28 | 211 36 56.25% 29 | 212 83* 129.6875% 30 | 213 52 81.25% 31 | 302 51 79.6875% 32 | 303 83* 129.6875% 33 | 304 68* 106.25% 34 | 305 42 65.625% 35 | 306 15 23.4375% 36 | 307 50 78.125% 37 | 308 34 53.125% 38 | 309 74* 115.625% 39 | 310 83* 129.6875% 40 | 311 57 89.0625% 41 | 312 53 82.8125% 42 | 313 6 9.375% 43 | 404 3 4.6875% 44 | 405 13 20.3125% 45 | 406 6 9.375% 46 | 407 16 25.0% 47 | 408 4 6.25% 48 | 409 6 9.375% 49 | 410 11 17.1875% 50 | 411 76* 118.75% 51 | 412 9 14.0625% 52 | 413 6 9.375% 53 | 500 3 4.6875% 54 | 501 3 4.6875% 55 | 502 3 4.6875% 56 | 503 3 4.6875% 57 | 504 3 4.6875% 58 | 505 11 17.1875% 59 | 506 12 18.75% 60 | 507 64 100.0% 61 | 508 20 31.25% 62 | 509 20 31.25% 63 | 510 58 90.625% 64 | 511 38 59.375% 65 | 600 41 64.0625% 66 | 601 3 4.6875% 67 | 602 3 4.6875% 68 | 603 3 4.6875% 69 | 604 3 4.6875% 70 | 605 3 4.6875% 71 | 606 3 4.6875% 72 | 607 22 34.375% 73 | 713 41 64.0625% 74 | 608 52 81.25% 75 | 609 5 7.8125% 76 | 610 5 7.8125% 77 | 611 5 7.8125% 78 | 708 68* 106.25% 79 | 709 14 21.875% 80 | 711 5 7.8125% 81 | 712 5 7.8125% 82 | 715 43 67.1875% 83 | Total: 82 nodes, 3071 words, 33.322482638888886% 84 | ================= 85 | 5 69* 107.8125% 86 | 6 70* 109.375% 87 | 7 77* 120.3125% 88 | 9 74* 115.625% 89 | 10 74* 115.625% 90 | 104 74* 115.625% 91 | 105 68* 106.25% 92 | 106 75* 117.1875% 93 | 107 71* 110.9375% 94 | 108 68* 106.25% 95 | 110 89* 139.0625% 96 | 205 74* 115.625% 97 | 209 71* 110.9375% 98 | 210 76* 118.75% 99 | 212 83* 129.6875% 100 | 303 83* 129.6875% 101 | 304 68* 106.25% 102 | 309 74* 115.625% 103 | 310 83* 129.6875% 104 | 411 76* 118.75% 105 | 20 nodes 106 | -------------------------------------------------------------------------------- /examples/sensors/filter13.cll: -------------------------------------------------------------------------------- 1 | // This program is used for making acc vector pass the filter only if it hasn't passed in the previous 13 steps. 2 | 3 | int count; 4 | 5 | int filter() { 6 | int ret1, ret2; 7 | ret2 = 0; 8 | count = count + 1; 9 | if(ret1 > 0) { 10 | if(count > 0) { 11 | ret2 = 1; 12 | count = -13; // 13 steps 13 | } 14 | } 15 | return ret2; 16 | } 17 | 18 | void main() { 19 | int x; 20 | x = filter(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/sha/sha.cll: -------------------------------------------------------------------------------- 1 | int::2 rightrotate(int::2 x, int r) { 2 | int::2 out; 3 | int swap; 4 | int r2; 5 | int::2 x2; 6 | if(r > 16) { 7 | swap = x::0; 8 | x::0 = x::1; 9 | x::1 = swap; 10 | r = r - 16; 11 | } 12 | x2 = x; 13 | r2 = r; 14 | out::0 = ((x2::1 << (16 - r2)) | (x2::0 >> r2)) & 65535; 15 | out::1 = ((x2::0 << (16 - r2)) | (x2::1 >> r2)) & 65535; 16 | return out; 17 | } 18 | 19 | int::2 rightshift(int::2 x, int r) { 20 | int::2 out; 21 | int swap; 22 | if(r > 16) { 23 | x::0 = x::1; 24 | x::1 = 0; 25 | r = r - 16; 26 | } 27 | out::0 = ((x::1 << (16 - r)) | (x::0 >> r)) & 65535; 28 | out::1 = x::1 >> r; 29 | return out; 30 | } 31 | 32 | int::2 wadd(int::2 x, int::2 y) { 33 | int::2 z; 34 | z::0 = x::0 + y::0; 35 | z::1 = x::1 + y::1 + ((z::0 >> 16) & 3); 36 | z::0 = z::0 & 65535; 37 | z::1 = z::1 & 65535; 38 | return z; 39 | } 40 | 41 | int::2 hadd(int::2 x, int::2 y) { 42 | int::2 z; 43 | z::0 = x::0 + y::0; 44 | z::1 = x::1 + y::1 + ((z::0 >> 16) & 3); 45 | z::0 = z::0 & 65535; 46 | z::1 = z::1 & 65535; 47 | return z; 48 | } 49 | 50 | int::2 add0(int::2 x, int::2 y) { 51 | int::2 z; 52 | z::0 = x::0 + y::0; 53 | z::1 = x::1 + y::1 + ((z::0 >> 16) & 3); 54 | z::0 = z::0 & 65535; 55 | z::1 = z::1 & 65535; 56 | return z; 57 | } 58 | 59 | void main() { 60 | int::2 hash[8]; 61 | int::2 k[64]; 62 | int::2 message[16]; 63 | int::2 w[64]; 64 | 65 | int::2 a; 66 | int::2 b; 67 | int::2 c; 68 | int::2 d; 69 | int::2 e; 70 | int::2 f; 71 | int::2 g; 72 | int::2 h; 73 | 74 | int::2 s0; 75 | int::2 s1; 76 | 77 | 78 | int::2 w15; 79 | int::2 w2; 80 | //int::2 x1; 81 | int::2 ch; 82 | int::2 temp1; 83 | //int::2 x0; 84 | int::2 maj; 85 | int::2 temp2; 86 | 87 | // For each 512-bit chunks 88 | for(i from 0 to 16) { 89 | w[i] = message[i]; 90 | } 91 | 92 | for(i from 16 to 63) { 93 | w15 = w[i-15]; 94 | w2 = w[i-2]; 95 | s0 = rightrotate(w15,7) ^ rightrotate(w15,18) ^ rightshift(w15,3); 96 | s1 = rightrotate(w2,17) ^ rightrotate(w2,19) ^ rightshift(w2,3); 97 | w[i] = wadd(w[i-16] + w[i-7], s0 + s1); 98 | } 99 | 100 | a = hash[0]; 101 | b = hash[1]; 102 | c = hash[2]; 103 | d = hash[3]; 104 | e = hash[4]; 105 | f = hash[5]; 106 | g = hash[6]; 107 | 108 | for(i from 0 to 63) { 109 | s1 = rightrotate(e,6) ^ rightrotate(e,11) ^ rightrotate(e,25); 110 | ch = (e & f) ^ ((~e) & g); 111 | temp1 = add0(h + s1, ch + k[i]) + w[i]; 112 | s0 = rightrotate(a,2) ^ rightrotate(a,13) ^ rightrotate(a,22); 113 | maj = (a & b) ^ (a & c) ^ (b & c); 114 | temp2 = s0 + maj; 115 | 116 | h = g; 117 | g = f; 118 | f = e; 119 | e = add0(d,temp1); 120 | d = c; 121 | c = b; 122 | b = a; 123 | a = add0(temp1,temp2); 124 | } 125 | 126 | hash[0] = hadd(hash[0],a); 127 | hash[1] = hadd(hash[1],b); 128 | hash[2] = hadd(hash[2],c); 129 | hash[3] = hadd(hash[3],d); 130 | hash[4] = hadd(hash[4],e); 131 | hash[5] = hadd(hash[5],f); 132 | hash[6] = hadd(hash[6],g); 133 | hash[7] = hadd(hash[7],h); 134 | } 135 | -------------------------------------------------------------------------------- /examples/sha/sha_f1.cll: -------------------------------------------------------------------------------- 1 | int::2 f1(int::2 e, int::2 f, int::2 g) { 2 | return (e & f) ^ ((~e) & g); 3 | } 4 | 5 | void main() { 6 | int::2 a, b, c; 7 | a = f1(a,b,c); 8 | } 9 | -------------------------------------------------------------------------------- /examples/sha/sha_f2.cll: -------------------------------------------------------------------------------- 1 | int::2 f2(int::2 a, int::2 b, int::2 c) { 2 | return (a & b) ^ (a & c) ^ (b & c); 3 | } 4 | 5 | void main() { 6 | int::2 a, b, c; 7 | a = f2(a,b,c); 8 | } 9 | -------------------------------------------------------------------------------- /examples/simple/add.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:25],[25:50],[50:75],[75:100]} x[100]; 3 | int@{[0:25],[25:50],[50:75],[75:100]} y[100]; 4 | int@{[0:25],[25:50],[50:75],[75:100]} z[100]; 5 | 6 | for(i from 0 to 100) { 7 | x[i] = in(); 8 | } 9 | 10 | for(i from 0 to 100) { 11 | y[i] = in(); 12 | } 13 | 14 | for(i from 0 to 100) { 15 | z[i] = x[i] +@place(z[i]) y[i]; 16 | } 17 | 18 | for(i from 0 to 100) { 19 | out(z[i]); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/simple/array.cll: -------------------------------------------------------------------------------- 1 | int@{[0:5]=1,[5:10]=2} x[10] = {1,2,3,4,5,6,7,8,9,10}; 2 | int@1 y[10] = {1,1,1,1,1,1,1,-1,-1,-1}; 3 | int@0 z[10]; 4 | 5 | void main() { 6 | for(i from 0 to 10) { 7 | z[i] = x[i] +@place(x[i]) y[i]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/simple/array2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:5]=0,[5:10]=1} x[10] = {1,2,3,4,5,6,7,8,9,10}; 3 | int y[10] = {1,1,1,1,1,1,1,1,1,1}; 4 | int z[10]; 5 | 6 | for(i from 0 to 10) { 7 | z[i] = x[i] +@place(x[i]) y[i]; 8 | } 9 | 10 | out(z[0]); 11 | } 12 | -------------------------------------------------------------------------------- /examples/simple/assign.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2@({[0:10]=0},{[0:10]=1}) x[10] = {(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10)}; 3 | for(i from 0 to 10) { 4 | x[i] = x[i] + 10; 5 | out(x::0[i]); 6 | out(x::1[i]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/simple/extendshift.cll: -------------------------------------------------------------------------------- 1 | void main () { 2 | int::2 x; 3 | x = 54083 >>> 6; 4 | out(x::0); 5 | out(x::1); 6 | } 7 | -------------------------------------------------------------------------------- /examples/simple/function-pair.cll: -------------------------------------------------------------------------------- 1 | int::3@(0,0,0) aaa() { 2 | int::3@(1,0,0) x; 3 | x::0 = 0; 4 | x::1 = 1; 5 | x::2 = 2; 6 | return x; 7 | } 8 | 9 | int::3@(0,1,0) bbb(int::3@(0,2,3) x) { 10 | return x; 11 | } 12 | 13 | void main() { 14 | int::3@(0,0,0) x; 15 | x = bbb(aaa()); 16 | out(x::0); 17 | out(x::1); 18 | out(x::2); 19 | } 20 | -------------------------------------------------------------------------------- /examples/simple/function.cll: -------------------------------------------------------------------------------- 1 | int@0 sum(int@2 a,int@2 b,int@2 c,int@0 d) { 2 | return a +@2 b +@2 c +@0 d; 3 | } 4 | 5 | void main() { 6 | int@1 a; 7 | int@1 b; 8 | int@2 c; 9 | int@2 d; 10 | a = 1; 11 | b = 2; 12 | c = 3; 13 | d = 4; 14 | out(sum(a,b,c,256 + sum(d,c,b,a))); 15 | } 16 | -------------------------------------------------------------------------------- /examples/simple/function2.cll: -------------------------------------------------------------------------------- 1 | int sum(int a,int b,int c,int d) { 2 | return a + b + c + d; 3 | } 4 | 5 | void main() { 6 | int@0 a; 7 | int b; 8 | int c; 9 | int d; 10 | a = 1; 11 | b = 2; 12 | c = 3; 13 | d = 4; 14 | out(sum(a,b,c,256 + sum(d,c,b,a))); 15 | } 16 | -------------------------------------------------------------------------------- /examples/simple/hello-io.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 a; 3 | int@1 b; 4 | int@2 c; 5 | a = in(); 6 | b = in(); 7 | c = a +@2 b; 8 | out(c); 9 | } 10 | -------------------------------------------------------------------------------- /examples/simple/hello.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 a; 3 | int@1 b; 4 | int@2 c; 5 | c = 3 *@2 a *@2 b; 6 | } 7 | -------------------------------------------------------------------------------- /examples/simple/if.cll: -------------------------------------------------------------------------------- 1 | int@3 one() { 2 | return 1; 3 | } 4 | 5 | int@3 two() { 6 | return 2; 7 | } 8 | 9 | int@3 three() { 10 | return 3; 11 | } 12 | 13 | void main() { 14 | int@0 x; 15 | int z; 16 | int j; 17 | 18 | x = one(); 19 | z = three(); 20 | j = 4; 21 | 22 | if(j == 0) { 23 | x = x +@1 two(); 24 | } else { 25 | z = two() +@2 z; 26 | } 27 | 28 | out(x); 29 | out(z); 30 | } 31 | -------------------------------------------------------------------------------- /examples/simple/offset.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:2]=0,[2:4]=0} x[4]; 3 | int@{[0:2]=1,[2:4]=0} y[4] = {1,2,3,4}; 4 | 5 | out(y[0]); 6 | out(y[2]); 7 | for(i from 0 to 4) { 8 | x[i] = y[i] + 1; 9 | } 10 | 11 | for(i from 0 to 4) { 12 | out(x[i]); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/simple/pair1.cll: -------------------------------------------------------------------------------- 1 | int::2@(2,2) func(int::2@(2,2) x) { 2 | return 10; 3 | } 4 | 5 | int::2@(2,2) func2(int z, int::2@(2,2) x) { 6 | int::2 a; 7 | a::0 = x::0; 8 | a::1 = z; 9 | return a; 10 | } 11 | 12 | void main() { 13 | int::2 a, b, c; 14 | int::2@({[0:5]=1, [5:10]=1},{[0:10]}) y[10]; 15 | 16 | c = a + b; 17 | 18 | y[0] = y[1] + y[2]; 19 | y::0[3] = y::0[4] + y::0[5]; 20 | 21 | c = y[1]; 22 | 23 | c = func2(1, func(0)); 24 | out(c::0); 25 | out(c::1); 26 | } 27 | -------------------------------------------------------------------------------- /examples/simple/pair2.cll: -------------------------------------------------------------------------------- 1 | int::2@(1,2) func(int::2@(1,2) x) { 2 | return 10; 3 | } 4 | 5 | int::2@(1,2) func2(int z, int::2@(1,2) x) { 6 | int::2 a; 7 | a::0 = x::0; 8 | a::1 = z; 9 | return a; 10 | } 11 | 12 | void main() { 13 | int::2 a, b, c; 14 | int::2@({[0:5], [5:10]},{[0:10]}) y[10]; 15 | c = a + b; 16 | 17 | y[0] = y[1] + y[2]; 18 | y::0[3] = y::0[4] + y::0[5]; 19 | 20 | c = y[1]; 21 | 22 | c = func2(1, func(0)); 23 | out(c::0); 24 | out(c::1); 25 | } 26 | -------------------------------------------------------------------------------- /examples/simple/part2core.cll: -------------------------------------------------------------------------------- 1 | # 0 --> 000 2 | # 1 --> 100 3 | # 2 --> 200 4 | noroute@{1} 5 | 6 | void main() { 7 | int@0 a; 8 | int@1 b; 9 | int@2 c; 10 | c = 3 *@2 a *@2 b; 11 | } 12 | -------------------------------------------------------------------------------- /examples/simple/square.cll: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 10; 3 | } 4 | 5 | void main () { 6 | int@0 a; 7 | fix1_t@1 b; 8 | fix2_t::2@(2,2) c; 9 | fix9_t@3 d; 10 | a = a**2; 11 | b = b**2; 12 | c = c**2; 13 | d = d**2; 14 | a = -1**2 * -f()**2 + 3; 15 | } 16 | -------------------------------------------------------------------------------- /examples/simple/unroll.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:50]=0,[50:75]=1,[75:100]=2} x[100]; 3 | for(i from 0 to 10) { 4 | for(j from 0 to 10) { 5 | x[10*i + j] = 10*i + j; 6 | out(x[10*i + j]); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/simple/while.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@1 i; 3 | int@2 x[10] = {0,0,0,0,0,0,0,0,0,0}; 4 | i = 0; 5 | while(i <@1 10) { 6 | x[i] = i; 7 | i = i +@1 2; 8 | } 9 | 10 | for(i from 0 to 10) { 11 | out(x[i]); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/super/large/ceil.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "p15_ceil_avg" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ !+ " 13 | 2 0 (restrict #t #f #f #f) #f 14 | "0 a! !+ !+ ") 15 | (block 16 | "0 " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "0 ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "0 b! @b " 25 | 0 1 (restrict #t #f #f #f) #f 26 | "0 b! @b ") 27 | (block 28 | "over - and + " 29 | 2 1 (restrict #t #f #f #f) #f 30 | "over - and + ") 31 | (block 32 | "2 b! !b " 33 | 1 0 (restrict #t #f #f #f) #f 34 | "2 b! !b ") 35 | (block 36 | "1 b! @b " 37 | 0 1 (restrict #t #f #f #f) #f 38 | "1 b! @b ") 39 | (block 40 | "0 b! @b " 41 | 0 1 (restrict #t #f #f #f) #f 42 | "0 b! @b ") 43 | (block 44 | "or " 45 | 2 1 (restrict #t #f #f #f) #f 46 | "or ") 47 | (block 48 | "push drop pop " 49 | 2 1 (restrict #t #f #f #f) #f 50 | "push drop pop ") 51 | (block 52 | "dup " 53 | 0 1 (restrict #t #f #f #f) #f 54 | "dup ") 55 | (block 56 | "2/ " 57 | 1 1 (restrict #t #f #f #f) #f 58 | "2/ ") 59 | (block 60 | "push drop pop " 61 | 2 1 (restrict #t #f #f #f) #f 62 | "push drop pop ") 63 | (block 64 | "2 b! @b " 65 | 0 1 (restrict #t #f #f #f) #f 66 | "2 b! @b ") 67 | (block 68 | "over " 69 | 0 1 (restrict #t #f #f #f) #f 70 | "over ") 71 | (block 72 | "- 1 + + " 73 | 2 1 (restrict #t #f #f #f) #f 74 | "- 1 + + ") 75 | (block 76 | "push drop pop " 77 | 2 1 (restrict #f #f #f #f) #f 78 | "push drop pop ") 79 | ) 80 | #f) 81 | ) 82 | 3 18 #f) 83 | ) 84 | (define name "ceil") 85 | (define dir "super/large") 86 | (define time (current-seconds)) 87 | (define real-opts (superoptimize program name 2 3 #t dir #:id 5)) 88 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 89 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 90 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 91 | (lambda () (aforth-syntax-print real-opts 2 3 #:id 5))) 92 | -------------------------------------------------------------------------------- /examples/super/large/count_a.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0)) 8 | (funcdecl "f" 9 | ;; linklist 10 | (list 11 | (block 12 | "@b" 13 | 0 1 (restrict #t #f #f #f) #f 14 | "@b") 15 | (block 16 | "87381 " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "87381 ") 19 | (block 20 | "and " 21 | 2 1 (restrict #t #f #f #f) #f 22 | "and ") 23 | (block 24 | "0 b! !b " 25 | 1 0 (restrict #t #f #f #f) #f 26 | "0 b! !b ") 27 | (block 28 | "dup " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "dup ") 31 | (block 32 | "0 b! @b " 33 | 0 1 (restrict #t #f #f #f) #f 34 | "0 b! @b ") 35 | (block 36 | "- 1 + + " 37 | 2 1 (restrict #t #f #f #f) #f 38 | "- 1 + + ") 39 | (block 40 | "push drop pop " 41 | 2 1 (restrict #t #f #f #f) #f 42 | "push drop pop ") 43 | (block 44 | "dup " 45 | 0 1 (restrict #t #f #f #f) #f 46 | "dup ") 47 | (block 48 | "209715 " 49 | 0 1 (restrict #t #f #f #f) #f 50 | "209715 ") 51 | (block 52 | "and " 53 | 2 1 (restrict #t #f #f #f) #f 54 | "and ") 55 | (block 56 | "0 b! !b " 57 | 1 0 (restrict #t #f #f #f) #f 58 | "0 b! !b ") 59 | (block 60 | "dup " 61 | 0 1 (restrict #t #f #f #f) #f 62 | "dup ") 63 | (block 64 | "2/ 2/ " 65 | 1 1 (restrict #t #f #f #f) #f 66 | "2/ 2/ ") 67 | (block 68 | "1 b! !b " 69 | 1 0 (restrict #t #f #f #f) #f 70 | "1 b! !b ") 71 | (block 72 | "1 b! @b " 73 | 0 1 (restrict #t #f #f #f) #f 74 | "1 b! @b ") 75 | (block 76 | "209715 " 77 | 0 1 (restrict #t #f #f #f) #f 78 | "209715 ") 79 | (block 80 | "and " 81 | 2 1 (restrict #t #f #f #f) #f 82 | "and ") 83 | (block 84 | "1 b! !b " 85 | 1 0 (restrict #t #f #f #f) #f 86 | "1 b! !b ") 87 | (block 88 | "0 b! @b " 89 | 0 1 (restrict #t #f #f #f) #f 90 | "0 b! @b ") 91 | (block 92 | "1 b! @b " 93 | 0 1 (restrict #t #f #f #f) #f 94 | "1 b! @b ") 95 | (block 96 | "+ " 97 | 2 1 (restrict #t #f #f #f) #f 98 | "+ ") 99 | (block 100 | "push drop pop " 101 | 2 1 (restrict #t #f #f #f) #f 102 | "push drop pop ") 103 | (block 104 | "dup " 105 | 0 1 (restrict #t #f #f #f) #f 106 | "dup ") 107 | ) 108 | #f) 109 | ) 110 | 2 18 #f) 111 | ) 112 | (define name "count_a") 113 | (define dir "super/large") 114 | (define time (current-seconds)) 115 | (define real-opts (superoptimize program name 2 3 #t dir #:id 1)) 116 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 117 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 118 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 119 | (lambda () (aforth-syntax-print real-opts 2 3 #:id 5))) 120 | -------------------------------------------------------------------------------- /examples/super/large/floor.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | 9 | (funcdecl "p14_floor_avg" 10 | ;; linklist 11 | (list 12 | (block 13 | "0 a! !+ !+ " 14 | 2 0 (restrict #t #f #f #f) #f 15 | "0 a! !+ !+ ") 16 | (block 17 | "0 " 18 | 0 1 (restrict #t #f #f #f) #f 19 | "0 ") 20 | (block 21 | "1 b! @b " 22 | 0 1 (restrict #t #f #f #f) #f 23 | "1 b! @b ") 24 | (block 25 | "0 b! @b " 26 | 0 1 (restrict #t #f #f #f) #f 27 | "0 b! @b ") 28 | (block 29 | "and " 30 | 2 1 (restrict #t #f #f #f) #f 31 | "and ") 32 | (block 33 | "2 b! !b " 34 | 1 0 (restrict #t #f #f #f) #f 35 | "2 b! !b ") 36 | (block 37 | "1 b! @b " 38 | 0 1 (restrict #t #f #f #f) #f 39 | "1 b! @b ") 40 | (block 41 | "0 b! @b " 42 | 0 1 (restrict #t #f #f #f) #f 43 | "0 b! @b ") 44 | (block 45 | "or " 46 | 2 1 (restrict #t #f #f #f) #f 47 | "or ") 48 | (block 49 | "push drop pop " 50 | 2 1 (restrict #t #f #f #f) #f 51 | "push drop pop ") 52 | (block 53 | "dup " 54 | 0 1 (restrict #t #f #f #f) #f 55 | "dup ") 56 | (block 57 | "2/ " 58 | 1 1 (restrict #t #f #f #f) #f 59 | "2/ ") 60 | (block 61 | "push drop pop " 62 | 2 1 (restrict #t #f #f #f) #f 63 | "push drop pop ") 64 | (block 65 | "2 b! @b " 66 | 0 1 (restrict #t #f #f #f) #f 67 | "2 b! @b ") 68 | (block 69 | "over " 70 | 0 1 (restrict #t #f #f #f) #f 71 | "over ") 72 | (block 73 | "+ " 74 | 2 1 (restrict #t #f #f #f) #f 75 | "+ ") 76 | (block 77 | "push drop pop " 78 | 2 1 (restrict #f #f #f #f) #f 79 | "push drop pop ") 80 | ) 81 | #f) 82 | ) 83 | 3 18 #f) 84 | ) 85 | (define name "floor") 86 | (define dir "super/large") 87 | (define time (current-seconds)) 88 | (define real-opts (superoptimize program name 2 3 #t dir #:id 5)) 89 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 90 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 91 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 92 | (lambda () (aforth-syntax-print real-opts 2 3 #:id 5))) 93 | -------------------------------------------------------------------------------- /examples/super/large/interp_large.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 450 900 1350 1800 2250 2700 3150 3600 0 0)) 8 | (funcdecl "main" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 " 13 | 0 1 (restrict #t #f #f #f) #f 14 | "0 ") 15 | (block 16 | "right b! @b " 17 | 0 1 (restrict #t #f #f #f) "right" 18 | "right b! @b ") 19 | (block 20 | "push drop pop " 21 | 2 1 (restrict #t #f #f #f) #f 22 | "push drop pop ") 23 | (block 24 | "dup " 25 | 0 1 (restrict #t #f #f #f) #f 26 | "dup ") 27 | (block 28 | "63 " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "63 ") 31 | (block 32 | "and " 33 | 2 1 (restrict #t #f #f #f) #f 34 | "and ") 35 | (block 36 | "3 b! !b " 37 | 1 0 (restrict #t #f #f #f) #f 38 | "10 b! !b ") 39 | (block 40 | "dup " 41 | 0 1 (restrict #t #f #f #f) #f 42 | "dup ") 43 | (block 44 | "2/ 2/ 2/ 2/ 2/ 2/ " 45 | 1 1 (restrict #t #f #f #f) #f 46 | "2/ 2/ 2/ 2/ 2/ 2/ ") 47 | (block 48 | "2 b! !b " 49 | 1 0 (restrict #t #f #f #f) #f 50 | "9 b! !b ") 51 | (block 52 | "2 b! @b " 53 | 0 1 (restrict #t #f #f #f) #f 54 | "9 b! @b ") 55 | (block 56 | "b! @b " 57 | 1 1 (restrict #t #f #f #f) #f 58 | "b! @b ") 59 | (block 60 | "2 b! @b " 61 | 0 1 (restrict #t #f #f #f) #f 62 | "9 b! @b ") 63 | (block 64 | "1 + b! @b " 65 | 1 1 (restrict #t #f #f #f) #f 66 | "1 + b! @b ") 67 | (block 68 | "2 b! @b " 69 | 0 1 (restrict #t #f #f #f) #f 70 | "9 b! @b ") 71 | (block 72 | "b! @b " 73 | 1 1 (restrict #t #f #f #f) #f 74 | "b! @b ") 75 | (block 76 | "- 1 + + " 77 | 2 1 (restrict #t #f #f #f) #f 78 | "- 1 + + ") 79 | (block 80 | "3 b! @b " 81 | 0 1 (restrict #t #f #f #f) #f 82 | "10 b! @b ") 83 | ) 84 | #f) 85 | ) 86 | 4 18 #hash((0 . 0) (2 . 9) (3 . 10) (4 . 11))) 87 | ) 88 | (define name "interp-large") 89 | (define dir "super/large") 90 | (define time (current-seconds)) 91 | (define real-opts (superoptimize program name 3 3 #t dir #:id 7)) 92 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 93 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 94 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 95 | (lambda () (aforth-syntax-print real-opts 3 3 #:id 7))) 96 | -------------------------------------------------------------------------------- /examples/super/programs: -------------------------------------------------------------------------------- 1 | LARGE 2 | 3 | : p14_floor_avg = $0 0 a! !+ !+ 0 1 b! @b 0 b! @b and 2 b! !b 1 b! @b 0 b! @b or push drop pop dup 2/ push drop pop 2 b! @b over . + push drop pop = $0 ; | cr 4 | (data . 1) 5 | 6 | : p15_ceil_avg = $0 3 a! !+ !+ 0 4 b! @b 3 b! @b over - and . + 5 b! !b 4 b! @b 3 b! @b or push drop pop dup 2/ push drop pop 5 b! @b over - 1 . + . + push drop pop = $0 ; | cr 7 | (data . 1) 8 | 9 | p23_count 10 | @b 87381 and 0 b! !b dup 0 b! @b - 1 . + . + push drop pop dup 209715 and 0 b! !b dup 2/ 2/ 1 b! !b 1 b! @b 209715 and 1 b! !b 0 b! @b 1 b! @b . + push drop pop dup 11 | (data . 1) 12 | 13 | p23_count_full 14 | dup 2/ 0 b! !b 0 b! @b 87381 and 0 b! !b dup 0 b! @b - 1 . + . + push drop pop dup 209715 and 0 b! !b dup 2/ 2/ 1 b! !b 1 b! @b 209715 and 1 b! !b 0 b! @b 1 b! @b . + push drop pop dup 2/ 2/ 2/ 2/ 0 b! !b 0 b! @b over . + push drop pop dup 3855 and push drop pop dup over 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ . + push drop pop dup over 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ . + push drop pop dup 63 and push drop pop 15 | 16 | p24_roundpower 17 | : main = $0 0 dup 1 - 1 . + . + push drop pop dup over 2/ over - and . + push drop pop dup over 2/ 2/ over - and . + push drop pop dup over 2/ 2/ 2/ 2/ over - and . + push drop pop dup over 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ over - and . + push drop pop dup over 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ over - and . + push drop pop dup 1 . + push drop pop warm = $0 ; | cr 18 | (data . 1) 19 | 20 | interp_large 21 | 0 right b! @b push drop pop dup 63 and 3 b! !b dup 2/ 2/ 2/ 2/ 2/ 2/ 2 b! !b 2 b! @b b! @b 2 b! @b 1 . + b! @b 2 b! @b b! @b - 1 . + . + 3 b! @b 22 | (data . 3) (memory) 23 | 24 | ------------------------------------------- 25 | SMALL 26 | 27 | : fff = $0 0 a! !+ !+ push pop dup 1 b! @b and over 65535 or 0 b! @b and over - and . + push drop pop = $0 ; | cr 28 | : ggg = $0 0 a! push !+ !+ pop dup 1 b! @b and over 65535 or 0 b! @b and over - and . + push drop pop = $0 ; | cr 29 | : hhh = $0 0 a! !+ push !+ pop 1 b! @b over or 0 b! @b or push drop pop = $0 ; | cr 30 | : iii = $0 0 a! !+ push !+ pop dup 1 b! @b 0 b! @b 65535 or over - and . + or push drop pop = $0 ; | cr 31 | 32 | shaf_a 33 | : f1 = 0 a! !+ !+ push pop dup 1 b! @b and over - 0 b! @b and or push drop pop ; 34 | (constraint (data . 2) (return . 1)) 35 | 36 | shaf_b 37 | : f2 = $0 0 a! !+ !+ push pop dup 1 b! @b and over 0 b! @b and or 1 b! @b 0 b! @b and or push drop pop ; 38 | (constraint (data . 2) (return . 1)) 39 | 40 | fir 41 | push drop pop pop a! right b! !b dup 1 + 15 and push drop pop 42 | (constraint (data . 1) a memory) 43 | 44 | complexA 45 | drop pop a 3 b! !b 0 b! !b 3 b! @b up b! !b 0 b! @b 2* 2* up b! @b 3 and + 46 | ((data . 2)) 47 | 48 | complexB 49 | drop 3 and . + push drop pop dup 0 b! @b 50 | ((data . 2)) 51 | 52 | complexC 53 | drop 65536 over - 1 . + . + push drop pop 54 | ((data . 2)) 55 | 56 | rrotate 57 | 2 b! !b push drop pop 2 b! @b 0 b! !b up b! @b 0 b! @b 2/ 2/ + 65535 and 58 | ((data . 2) (return . 1)) 59 | 60 | interp 61 | 2 b! !b 2 b! @b b! @b 2 b! @b 1 + b! @b 2 b! @b b! @b - 1 + + 62 | ((data . 2)) 63 | 64 | -------------------------------------------------------------------------------- /examples/super/small/complexA.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0)) 8 | (funcdecl "main" 9 | ;; linklist 10 | (list 11 | 12 | (block 13 | "drop pop " 14 | 1 1 (restrict #t #t #f #f) #f 15 | "drop pop ") 16 | (block 17 | "a " 18 | 0 1 (restrict #t #f #f #f) #f 19 | "a ") 20 | (block 21 | "3 b! !b " 22 | 1 0 (restrict #t #f #f #f) #f 23 | "3 b! !b ") 24 | (block 25 | "0 b! !b " 26 | 1 0 (restrict #t #f #f #f) #f 27 | "0 b! !b ") 28 | (block 29 | "3 b! @b " 30 | 0 1 (restrict #t #f #f #f) #f 31 | "3 b! @b ") 32 | (block 33 | "up b! !b " 34 | 1 0 (restrict #t #f #f #f) "up" 35 | "up b! !b ") 36 | (block 37 | "0 b! @b " 38 | 0 1 (restrict #t #f #f #f) #f 39 | "0 b! @b ") 40 | (block 41 | "2* 2* " 42 | 1 1 (restrict #t #f #f #f) #f 43 | "2* 2* ") 44 | (block 45 | "up b! @b " 46 | 0 1 (restrict #t #f #f #f) "up" 47 | "up b! @b ") 48 | (block 49 | "3 " 50 | 0 1 (restrict #t #f #f #f) #f 51 | "3 ") 52 | (block 53 | "and " 54 | 2 1 (restrict #t #f #f #f) #f 55 | "and ") 56 | (block 57 | "+ " 58 | 2 1 (restrict #f #f #f #f) #f 59 | "+ ") 60 | ) 61 | #f) 62 | ) 63 | 4 18 #f) 64 | ) 65 | (define name "complexA") 66 | (define dir "super/small") 67 | (define time (current-seconds)) 68 | (define real-opts (superoptimize program name 4 4 #t dir #:id 1)) 69 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 70 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 71 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 72 | (lambda () (aforth-syntax-print real-opts 4 4 #:id 11))) 73 | -------------------------------------------------------------------------------- /examples/super/small/complexB.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0)) 8 | (funcdecl "main" 9 | ;; linklist 10 | (list 11 | 12 | (block 13 | "drop " 14 | 1 0 (restrict #t #f #f #f) #f 15 | "drop ") 16 | (block 17 | "3 " 18 | 0 1 (restrict #t #f #f #f) #f 19 | "3 ") 20 | (block 21 | "and " 22 | 2 1 (restrict #t #f #f #f) #f 23 | "and ") 24 | (block 25 | "+ " 26 | 2 1 (restrict #t #f #f #f) #f 27 | "+ ") 28 | (block 29 | "push drop pop " 30 | 2 1 (restrict #t #f #f #f) #f 31 | "push drop pop ") 32 | (block 33 | "dup " 34 | 1 2 (restrict #t #f #f #f) #f 35 | "dup ") 36 | (block 37 | "0 b! @b " 38 | 0 1 (restrict #f #f #f #f) #f 39 | "0 b! @b ") 40 | ) 41 | #f) 42 | ) 43 | 1 18 #f) 44 | ) 45 | (define name "complexB") 46 | (define dir "super/small") 47 | (define time (current-seconds)) 48 | (define real-opts (superoptimize program name 4 4 #t dir #:id 11)) 49 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 50 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 51 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 52 | (lambda () (aforth-syntax-print real-opts 4 4 #:id 11))) 53 | -------------------------------------------------------------------------------- /examples/super/small/complexC.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '()) 8 | (funcdecl "1if" 9 | ;; linklist 10 | (list 11 | 12 | (block 13 | "drop " 14 | 1 0 (restrict #t #f #f #f) #f 15 | "drop ") 16 | (block 17 | "65536 " 18 | 0 1 (restrict #t #f #f #f) #f 19 | "65536 ") 20 | (block 21 | "over " 22 | 0 1 (restrict #t #f #f #f) #f 23 | "over ") 24 | (block 25 | "- 1 + + " 26 | 2 1 (restrict #t #f #f #f) #f 27 | "- 1 + + ") 28 | (block 29 | "push drop pop " 30 | 2 1 (restrict #f #f #f #f) #f 31 | "push drop pop ") 32 | ) 33 | #f) 34 | ) 35 | 0 18 #f) 36 | ) 37 | (define name "complexC") 38 | (define dir "super/small") 39 | (define time (current-seconds)) 40 | (define real-opts (superoptimize program name 4 4 #t dir #:id 9)) 41 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 42 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 43 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 44 | (lambda () (aforth-syntax-print real-opts 4 4 #:id 9))) 45 | -------------------------------------------------------------------------------- /examples/super/small/fff.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "fff" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ !+ push pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! !+ !+ push pop ") 15 | (block 16 | "dup " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "dup ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "and " 25 | 2 1 (restrict #t #f #f #f) #f 26 | "and ") 27 | (block 28 | "over " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "over ") 31 | (block 32 | "65535 " 33 | 0 1 (restrict #t #f #f #f) #f 34 | "65535 ") 35 | (block 36 | "or " 37 | 2 1 (restrict #t #f #f #f) #f 38 | "or ") 39 | (block 40 | "0 b! @b " 41 | 0 1 (restrict #t #f #f #f) #f 42 | "0 b! @b ") 43 | (block 44 | "and " 45 | 2 1 (restrict #t #f #f #f) #f 46 | "and ") 47 | (block 48 | "over - and + " 49 | 2 1 (restrict #t #f #f #f) #f 50 | "over - and + ") 51 | (block 52 | "push drop pop " 53 | 2 1 (restrict #f #f #f #f) #f 54 | "push drop pop ") 55 | ) 56 | '((<= . 65535) (<= . 65535) (<= . 65535))) 57 | ) 58 | 3 18 #f) 59 | ) 60 | (define name "fff") 61 | (define dir "super/small") 62 | (define time (current-seconds)) 63 | (define real-opts (superoptimize program name 8 8 #t dir #:id 36)) 64 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 65 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 66 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 67 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 36))) 68 | -------------------------------------------------------------------------------- /examples/super/small/fir.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(8192 8192 16384 32768 32768 65536 65536 131071 131071 131071 131071 65536 65536 32768 32768 16384 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) 8 | (funcdecl "main" 9 | ;; linklist 10 | (list 11 | (block 12 | "push drop pop " 13 | 2 1 (restrict #t #t #f #f) #f 14 | "push drop pop ") 15 | (block 16 | "pop a! " 17 | 0 0 (restrict #t #t #f #t) #f 18 | "pop a! ") 19 | (block 20 | "right b! !b " 21 | 1 0 (restrict #t #t #f #f) "right" 22 | "right b! !b ") 23 | (block 24 | "dup " 25 | 0 1 (restrict #t #t #f #f) #f 26 | "dup ") 27 | (block 28 | "1 " 29 | 0 1 (restrict #t #t #f #f) #f 30 | "1 ") 31 | (block 32 | "+ " 33 | 2 1 (restrict #t #t #f #f) #f 34 | "+ ") 35 | (block 36 | "15 " 37 | 0 1 (restrict #t #t #f #f) #f 38 | "15 ") 39 | (block 40 | "and " 41 | 2 1 (restrict #t #t #f #f) #f 42 | "and ") 43 | (block 44 | "push drop pop " 45 | 2 1 (restrict #t #t #f #f) #f 46 | "push drop pop ") 47 | ) 48 | #f) 49 | ) 50 | 4 18 #hash((0 . 0) (2 . 16) (4 . 32))) 51 | ) 52 | (define name "fir") 53 | (define dir "super/small") 54 | (define time (current-seconds)) 55 | (define real-opts (superoptimize program name 3 3 #t dir #:id 4)) 56 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 57 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 58 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 59 | (lambda () (aforth-syntax-print real-opts 3 3 #:id 4))) 60 | -------------------------------------------------------------------------------- /examples/super/small/ggg.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "ggg" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! push !+ !+ pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! push !+ !+ pop ") 15 | (block 16 | "dup " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "dup ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "and " 25 | 2 1 (restrict #t #f #f #f) #f 26 | "and ") 27 | (block 28 | "over " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "over ") 31 | (block 32 | "65535 " 33 | 0 1 (restrict #t #f #f #f) #f 34 | "65535 ") 35 | (block 36 | "or " 37 | 2 1 (restrict #t #f #f #f) #f 38 | "or ") 39 | (block 40 | "0 b! @b " 41 | 0 1 (restrict #t #f #f #f) #f 42 | "0 b! @b ") 43 | (block 44 | "and " 45 | 2 1 (restrict #t #f #f #f) #f 46 | "and ") 47 | (block 48 | "over - and + " 49 | 2 1 (restrict #t #f #f #f) #f 50 | "over - and + ") 51 | (block 52 | "push drop pop " 53 | 2 1 (restrict #f #f #f #f) #f 54 | "push drop pop ") 55 | ) 56 | '((<= . 65535) (<= . 65535) (<= . 65535))) 57 | ) 58 | 59 | 3 18 #f) 60 | ) 61 | (define name "ggg") 62 | (define dir "super/small") 63 | (define time (current-seconds)) 64 | (define real-opts (superoptimize program name 8 8 #t dir #:id 36)) 65 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 66 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 67 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 68 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 36))) 69 | -------------------------------------------------------------------------------- /examples/super/small/hhh.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "hhh" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ push !+ pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! !+ push !+ pop ") 15 | (block 16 | "1 b! @b " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "1 b! @b ") 19 | (block 20 | "over " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "over ") 23 | (block 24 | "or " 25 | 2 1 (restrict #t #f #f #f) #f 26 | "or ") 27 | (block 28 | "0 b! @b " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "0 b! @b ") 31 | (block 32 | "or " 33 | 2 1 (restrict #t #f #f #f) #f 34 | "or ") 35 | (block 36 | "push drop pop " 37 | 2 1 (restrict #f #f #f #f) #f 38 | "push drop pop ") 39 | ) 40 | '((<= . 65535) (<= . 65535) (<= . 65535))) 41 | ) 42 | 3 18 #f) 43 | ) 44 | (define name "hhh") 45 | (define dir "super/small") 46 | (define time (current-seconds)) 47 | (define real-opts (superoptimize program name 8 8 #t dir #:id 36)) 48 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 49 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 50 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 51 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 36))) 52 | -------------------------------------------------------------------------------- /examples/super/small/iii.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "iii" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ push !+ pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! !+ push !+ pop ") 15 | (block 16 | "dup " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "dup ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "0 b! @b " 25 | 0 1 (restrict #t #f #f #f) #f 26 | "0 b! @b ") 27 | (block 28 | "65535 " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "65535 ") 31 | (block 32 | "or " 33 | 2 1 (restrict #t #f #f #f) #f 34 | "or ") 35 | (block 36 | "over - and + " 37 | 2 1 (restrict #t #f #f #f) #f 38 | "over - and + ") 39 | (block 40 | "or " 41 | 2 1 (restrict #t #f #f #f) #f 42 | "or ") 43 | (block 44 | "push drop pop " 45 | 2 1 (restrict #f #f #f #f) #f 46 | "push drop pop ") 47 | ) 48 | '((<= . 65535) (<= . 65535) (<= . 65535))) 49 | ) 50 | 3 18 #f) 51 | ) 52 | (define name "iii") 53 | (define dir "super/small") 54 | (define time (current-seconds)) 55 | (define real-opts (superoptimize program name 8 8 #t dir #:id 36)) 56 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 57 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 58 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 59 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 36))) 60 | -------------------------------------------------------------------------------- /examples/super/small/iii_ex.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0)) 8 | (funcdecl "iii" 9 | ;; linklist 10 | (list 11 | (block 12 | "a! " 13 | 1 0 (restrict #t #t #f #f) #f 14 | "a! ") 15 | (block 16 | "push " 17 | 1 0 (restrict #t #t #f #t) #f 18 | "push ") 19 | (block 20 | "a " 21 | 0 1 (restrict #t #f #f #t) #f 22 | "a ") 23 | (block 24 | "- " 25 | 1 1 (restrict #t #f #f #t) #f 26 | "- ") 27 | (block 28 | "over " 29 | 2 3 (restrict #t #f #f #t) #f 30 | "over ") 31 | (block 32 | "65535 " 33 | 0 1 (restrict #t #f #f #t) #f 34 | "65535 ") 35 | (block 36 | "or " 37 | 2 1 (restrict #t #f #f #t) #f 38 | "or ") 39 | (block 40 | "and " 41 | 2 1 (restrict #t #f #f #t) #f 42 | "and ") 43 | (block 44 | "or " 45 | 2 1 (restrict #t #f #f #t) #f 46 | "or ") 47 | (block 48 | "pop " 49 | 0 1 (restrict #t #f #f #f) #f 50 | "pop ") 51 | (block 52 | "or " 53 | 2 1 (restrict #f #f #f #f) #f 54 | "or ") 55 | ) 56 | '((<= . 65535) (<= . 65535) (<= . 65535))) 57 | ) 58 | 3 18 #f) 59 | ) 60 | (define name "iii_ex") 61 | (define dir "super/small") 62 | (define time (current-seconds)) 63 | (define real-opts (superoptimize program name 8 8 #t dir #:id 36)) 64 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 65 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 66 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 67 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 36))) 68 | -------------------------------------------------------------------------------- /examples/super/small/interp.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 450 900 1350 1800 2250 2700 3150 3600 0 0)) 8 | (funcdecl "main" 9 | ;; linklist 10 | (list 11 | 12 | (block 13 | "2 b! !b " 14 | 1 0 (restrict #t #f #f #f) #f 15 | "9 b! !b ") 16 | (block 17 | "2 b! @b " 18 | 0 1 (restrict #t #f #f #f) #f 19 | "9 b! @b ") 20 | (block 21 | "b! @b " 22 | 1 1 (restrict #t #f #f #f) #f 23 | "b! @b ") 24 | (block 25 | "2 b! @b " 26 | 0 1 (restrict #t #f #f #f) #f 27 | "9 b! @b ") 28 | (block 29 | "1 + b! @b " 30 | 1 1 (restrict #t #f #f #f) #f 31 | "1 + b! @b ") 32 | (block 33 | "2 b! @b " 34 | 0 1 (restrict #t #f #f #f) #f 35 | "9 b! @b ") 36 | (block 37 | "b! @b " 38 | 1 1 (restrict #t #f #f #f) #f 39 | "b! @b ") 40 | (block 41 | "- 1 + + " 42 | 2 1 (restrict #f #f #f #f) #f 43 | "- 1 + + ") 44 | ) 45 | #f) 46 | ) 47 | 4 18 #hash((0 . 0) (2 . 9) (3 . 10) (4 . 11))) 48 | ) 49 | (define name "interp") 50 | (define dir "super/small") 51 | (define time (current-seconds)) 52 | (define real-opts (superoptimize program name 3 3 #t dir #:id 7)) 53 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 54 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 55 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 56 | (lambda () (aforth-syntax-print real-opts 3 3 #:id 7))) 57 | -------------------------------------------------------------------------------- /examples/super/small/rrotate.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0 0 0)) 8 | 9 | (funcdecl "leftrotate" 10 | ;; linklist 11 | (list 12 | 13 | (block 14 | "2 b! !b " 15 | 1 0 (restrict #t #f #f #f) #f 16 | "2 b! !b ") 17 | 18 | (block 19 | "push drop pop " 20 | 2 1 (restrict #t #f #f #f) #f 21 | "push drop pop ") 22 | 23 | (block 24 | "2 b! @b " 25 | 0 1 (restrict #t #f #f #f) #f 26 | "2 b! @b ") 27 | (block 28 | "0 b! !b " 29 | 1 0 (restrict #t #f #f #f) #f 30 | "0 b! !b ") 31 | 32 | (block 33 | "up b! @b " 34 | 0 1 (restrict #t #f #f #f) "up" 35 | "up b! @b ") 36 | (block 37 | "0 b! @b " 38 | 0 1 (restrict #t #f #f #f) #f 39 | "0 b! @b ") 40 | (block 41 | "2/ 2/ " 42 | 1 1 (restrict #t #f #f #f) #f 43 | "2/ 2/ ") 44 | (block 45 | "+ " 46 | 2 1 (restrict #t #f #f #f) #f 47 | "+ ") 48 | (block 49 | "65535 " 50 | 0 1 (restrict #t #f #f #f) #f 51 | "65535 ") 52 | (block 53 | "and " 54 | 2 1 (restrict #f #f #f #f) #f 55 | "and ") 56 | ) 57 | #f) 58 | ) 59 | 5 18 #f) 60 | ) 61 | (define name "rrotate") 62 | (define dir "super/small") 63 | (define time (current-seconds)) 64 | (define real-opts (superoptimize program name 8 8 #t dir #:id 26)) 65 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 66 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 67 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 26))) 68 | -------------------------------------------------------------------------------- /examples/super/small/sha_fa-opt-nolenlimit.rkt: -------------------------------------------------------------------------------- 1 | (aforth 2 | ;; linklist 3 | (list 4 | (vardecl '(0 0)) 5 | (funcdecl "f1" 6 | ;; linklist 7 | (list 8 | (block 9 | "dup push or nop and pop or" 10 | 3 1 (restrict #f #f #f #f) #f 11 | "0 a! !+ !+ push pop dup 1 b! @b and over - 0 b! @b and or push drop pop ") 12 | ) 13 | '(#f #f #f)) 14 | ) 15 | 2 18 #f) 16 | -------------------------------------------------------------------------------- /examples/super/small/sha_fa-opt-nolenlimit.time: -------------------------------------------------------------------------------- 1 | 4055 2 | -------------------------------------------------------------------------------- /examples/super/small/sha_fa-opt.aforth: -------------------------------------------------------------------------------- 1 | {block 802} 2 | ( -) # 11 ( id 1 mem 2) 0 org | cr 3 | 0 , 0 , | br 4 | : f1 = $0 0 a! !+ dup !+ over and 0 b! over - @b and or push drop pop = $0 ; | cr 5 | 6 | -------------------------------------------------------------------------------- /examples/super/small/sha_fa-opt.time: -------------------------------------------------------------------------------- 1 | 2648 2 | -------------------------------------------------------------------------------- /examples/super/small/sha_fa.stat: -------------------------------------------------------------------------------- 1 | 30 21 "0 a! !+ !+ push pop dup 1 b! @b and over - 0 b! @b" "0 a! !+ dup !+ over and 0 b! over - nop @b" 2 | 6 6 "and or push drop pop" "and or push drop pop" 3 | -------------------------------------------------------------------------------- /examples/super/small/shaf_a.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0)) 8 | (funcdecl "f1" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ !+ push pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! !+ !+ push pop ") 15 | (block 16 | "dup " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "dup ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "and " 25 | 2 1 (restrict #t #f #f #f) #f 26 | "and ") 27 | (block 28 | "over " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "over ") 31 | (block 32 | "- " 33 | 1 1 (restrict #t #f #f #f) #f 34 | "- ") 35 | (block 36 | "0 b! @b " 37 | 0 1 (restrict #t #f #f #f) #f 38 | "0 b! @b ") 39 | (block 40 | "and " 41 | 2 1 (restrict #t #f #f #f) #f 42 | "and ") 43 | (block 44 | "or " 45 | 2 1 (restrict #t #f #f #f) #f 46 | "or ") 47 | (block 48 | "push drop pop " 49 | 2 1 (restrict #f #f #f #f) #f 50 | "push drop pop ") 51 | ) 52 | '(#f #f #f))) 53 | 2 18 #f) 54 | ) 55 | (define name "sha_fa") 56 | (define dir "super/small") 57 | (define time (current-seconds)) 58 | (define real-opts (superoptimize program name 2 3 #t dir #:id 1)) 59 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 60 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 61 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 62 | (lambda () (aforth-syntax-print real-opts 2 3 #:id 1))) 63 | -------------------------------------------------------------------------------- /examples/super/small/shaf_b.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0)) 8 | (funcdecl "f2" 9 | ;; linklist 10 | (list 11 | (block 12 | "0 a! !+ !+ push pop " 13 | 3 1 (restrict #t #f #f #f) #f 14 | "0 a! !+ !+ push pop ") 15 | (block 16 | "dup " 17 | 0 1 (restrict #t #f #f #f) #f 18 | "dup ") 19 | (block 20 | "1 b! @b " 21 | 0 1 (restrict #t #f #f #f) #f 22 | "1 b! @b ") 23 | (block 24 | "and " 25 | 2 1 (restrict #t #f #f #f) #f 26 | "and ") 27 | (block 28 | "over " 29 | 0 1 (restrict #t #f #f #f) #f 30 | "over ") 31 | (block 32 | "0 b! @b " 33 | 0 1 (restrict #t #f #f #f) #f 34 | "0 b! @b ") 35 | (block 36 | "and " 37 | 2 1 (restrict #t #f #f #f) #f 38 | "and ") 39 | (block 40 | "or " 41 | 2 1 (restrict #t #f #f #f) #f 42 | "or ") 43 | (block 44 | "1 b! @b " 45 | 0 1 (restrict #t #f #f #f) #f 46 | "1 b! @b ") 47 | (block 48 | "0 b! @b " 49 | 0 1 (restrict #t #f #f #f) #f 50 | "0 b! @b ") 51 | (block 52 | "and " 53 | 2 1 (restrict #t #f #f #f) #f 54 | "and ") 55 | (block 56 | "or " 57 | 2 1 (restrict #t #f #f #f) #f 58 | "or ") 59 | (block 60 | "push drop pop " 61 | 2 1 (restrict #f #f #f #f) #f 62 | "push drop pop ") 63 | ) 64 | '(#f #f #f)) 65 | ) 66 | 2 18 #f) 67 | ) 68 | (define name "sha_fb") 69 | (define dir "super/small") 70 | (define time (current-seconds)) 71 | (define real-opts (superoptimize program name 2 3 #t dir #:id 2)) 72 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 73 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 74 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 75 | (lambda () (aforth-syntax-print real-opts 2 3 #:id 1))) 76 | -------------------------------------------------------------------------------- /examples/super/small/test.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "../../../src/header.rkt" "../../../src/arrayforth.rkt" "../../../src/arrayforth-optimize.rkt" "../../../src/arrayforth-print.rkt") 3 | (define program 4 | (aforth 5 | ;; linklist 6 | (list 7 | (vardecl '(0 0 0 0 0)) 8 | 9 | (funcdecl "leftrotate" 10 | ;; linklist 11 | (list 12 | (block 13 | "0 b! !b " 14 | 0 1 (restrict #f #f #f #f) #f 15 | "0 b! !b ") 16 | ) 17 | #f) 18 | ) 19 | 5 18 #f) 20 | ) 21 | (define name "test") 22 | (define dir "super/small") 23 | (define time (current-seconds)) 24 | (define real-opts (superoptimize program name 8 8 #t dir #:id 26)) 25 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.time" dir name) (lambda () (pretty-display (- (current-seconds) time)))) 26 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.rkt" dir name) (lambda () (aforth-struct-print real-opts))) 27 | (with-output-to-file #:exists 'truncate (format "~a/~a-opt.aforth" dir name) 28 | (lambda () (aforth-syntax-print real-opts 8 8 #:id 26))) 29 | -------------------------------------------------------------------------------- /src/README: -------------------------------------------------------------------------------- 1 | Current Implementation 2 | 3 | 1) 4 | int a, b, c; 5 | => a, b, c will be put in the same place 6 | 7 | 2) 8 | int@1 a; 9 | int@x b; 10 | int@y c; 11 | => x != y != 1 12 | 13 | 3) 14 | no support for @any @here yet 15 | -------------------------------------------------------------------------------- /src/a-star.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | ;; Adapted from http://jeapostrophe.github.io/2013-04-15-astar-post.html 4 | 5 | (require rackunit 6 | racket/unit 7 | racket/match 8 | racket/list 9 | data/heap 10 | 2htdp/image 11 | racket/runtime-path) 12 | 13 | (provide (all-defined-out)) 14 | 15 | (define-signature graph^ 16 | (node? edge? node-edges edge-src edge-cost edge-dest)) 17 | 18 | (define (A* graph@ initial node-cost) 19 | (define-values/invoke-unit graph@ (import) (export graph^)) 20 | (define count 0) 21 | 22 | (define node->best-path (make-hash)) 23 | (define node->best-path-cost (make-hash)) 24 | 25 | (hash-set! node->best-path initial empty) 26 | (hash-set! node->best-path-cost initial 0) 27 | 28 | (define (node-total-estimate-cost n) 29 | (+ (node-cost n) (hash-ref node->best-path-cost n))) 30 | (define (node-cmp x y) 31 | (<= (node-total-estimate-cost x) 32 | (node-total-estimate-cost y))) 33 | (define open-set (make-heap node-cmp)) 34 | (heap-add! open-set initial) 35 | 36 | (begin0 37 | (let/ec esc 38 | (for ([x (in-heap/consume! open-set)]) 39 | (set! count (add1 count)) 40 | (define h-x (node-cost x)) 41 | (define path-x (hash-ref node->best-path x)) 42 | 43 | (when (zero? h-x) 44 | (esc (reverse path-x))) 45 | 46 | (define g-x (hash-ref node->best-path-cost x)) 47 | (for ([x->y (in-list (node-edges x))]) 48 | (define y (edge-dest x->y)) 49 | (define new-g-y (+ g-x (edge-cost x->y))) 50 | (define old-g-y 51 | (hash-ref node->best-path-cost y +inf.0)) 52 | (when (< new-g-y old-g-y) 53 | (hash-set! node->best-path-cost y new-g-y) 54 | (hash-set! node->best-path y (cons x->y path-x)) 55 | (heap-add! open-set y)))) 56 | #f) 57 | 58 | ;;(printf "visited ~a nodes\n" count) 59 | )) 60 | 61 | -------------------------------------------------------------------------------- /src/chlorophyll-test.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "compiler.rkt") 4 | 5 | (define (test file name input capacity w h part) 6 | (pretty-display (test-simulate file name input capacity w h part))) 7 | 8 | (define width (make-parameter 2)) ;; minimum 9 | (define height (make-parameter 3)) ;; minimum 10 | (define memory (make-parameter 256)) ;; 64 words x 4 slots 11 | (define syn-part (make-parameter #t)) 12 | 13 | (define-values (input-file input) 14 | (command-line 15 | #:once-each 16 | [("-c" "--columns") c 17 | "Number of columns of nodes [default=2]" 18 | (width (string->number c))] 19 | 20 | [("-r" "--rows") r 21 | "Number of rows of nodes [default=3]" 22 | (height (string->number r))] 23 | 24 | [("-m" "--memory") m 25 | "Size of memory in each node in slots (# of words times 4) [default=256]" 26 | (memory (string->number m))] 27 | 28 | [("--heu-partition") "Use heuristic partitioner instead of synthesizing partitioner [default=synthesizing]" 29 | (syn-part #f)] 30 | 31 | #:args (filename in) 32 | (values filename in))) 33 | 34 | (test input-file 35 | (first (string-split (last (string-split input-file "/")) ".")) 36 | input 37 | (memory) (width) (height) (syn-part)) -------------------------------------------------------------------------------- /src/chlorophyll.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "compiler.rkt") 4 | 5 | (define width (make-parameter 2)) ;; minimum 6 | (define height (make-parameter 3)) ;; minimum 7 | (define memory (make-parameter 256)) ;; 64 words x 4 slots 8 | (define opt (make-parameter #f)) 9 | (define syn-part (make-parameter #t)) 10 | 11 | (define input-file 12 | (command-line 13 | #:once-each 14 | [("-c" "--columns") c 15 | "Number of columns of nodes [default=2]" 16 | (width (string->number c))] 17 | 18 | [("-r" "--rows") r 19 | "Number of rows of nodes [default=3]" 20 | (height (string->number r))] 21 | 22 | [("-m" "--memory") m 23 | "Size of memory in each node in slots (# of words times 4) [default=256]" 24 | (memory (string->number m))] 25 | 26 | [("-o" "--optimize") "Superoptimization on [default=off]" 27 | (opt #t)] 28 | 29 | [("--heu-partition") "Use heuristic partitioner instead of synthesizing partitioner [default=synthesizing]" 30 | (syn-part #f)] 31 | 32 | #:args (filename) 33 | filename)) 34 | 35 | (compile-and-optimize input-file 36 | (first (string-split (last (string-split input-file "/")) ".")) 37 | (memory) #:w (width) #:h (height) #:opt (opt) 38 | #:partition (syn-part)) 39 | -------------------------------------------------------------------------------- /src/communication.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define N 300 7 | 8 | typedef struct int2 { 9 | int fst,snd; 10 | int2() { 11 | fst = 0; 12 | snd = 0; 13 | } 14 | int2(int x, int y) { 15 | fst = x; 16 | snd = y; 17 | } 18 | }int2; 19 | 20 | typedef struct int3 { 21 | int fst,snd,thd; 22 | int3() { 23 | fst = 0; 24 | snd = 0; 25 | thd = 0; 26 | } 27 | int3(int x, int y, int z) { 28 | fst = x; 29 | snd = y; 30 | thd = z; 31 | } 32 | }int3; 33 | 34 | typedef struct int4 { 35 | int fst,snd,thd,frth; 36 | int4() { 37 | fst = 0; 38 | snd = 0; 39 | thd = 0; 40 | frth = 0; 41 | } 42 | int4(int w, int x, int y, int z) { 43 | fst = w; 44 | snd = x; 45 | thd = y; 46 | frth = z; 47 | } 48 | }int4; 49 | 50 | typedef struct long2 { 51 | long fst,snd; 52 | long2() { 53 | fst = 0; 54 | snd = 0; 55 | } 56 | long2(long x, long y) { 57 | fst = x; 58 | snd = y; 59 | } 60 | }long2; 61 | 62 | typedef struct long3 { 63 | long fst,snd,thd; 64 | long3() { 65 | fst = 0; 66 | snd = 0; 67 | thd = 0; 68 | } 69 | long3(long x, long y, long z) { 70 | fst = x; 71 | snd = y; 72 | thd = z; 73 | } 74 | }long3; 75 | 76 | typedef struct long4 { 77 | long fst,snd,thd,frth; 78 | long4() { 79 | fst = 0; 80 | snd = 0; 81 | thd = 0; 82 | frth = 0; 83 | } 84 | long4(long w, long x, long y, long z) { 85 | fst = w; 86 | snd = x; 87 | thd = y; 88 | frth = z; 89 | } 90 | }long4; 91 | 92 | //////////////////////////////////////////////////////////////////// 93 | 94 | long neg_ext = -1 << 18; 95 | long finitize(long x) { 96 | long ret = x & 0x3ffff; 97 | if(ret & 0x20000) 98 | return ret | neg_ext; 99 | else 100 | return ret; 101 | } 102 | 103 | long2 divmod(long x, long y) { 104 | long d, r; 105 | d = x/y; 106 | r = x%y; 107 | return long2(r,d); 108 | } 109 | 110 | long2 mult2(long x, long y) { 111 | long res, h, l; 112 | res = x*y; 113 | h = res >> 18; 114 | l = finitize(res); // res & 0x3ffff; 115 | return long2(h,l); 116 | } 117 | 118 | long2 rightrot(long x, long y) { 119 | long h, l; 120 | h = x >> y; 121 | l = finitize(x << (18 - y)); // (x << (18 - y)) & 0x3ffff; 122 | return long2(h,l); 123 | } 124 | 125 | //////////////////////////////////////////////////////////////////// 126 | 127 | long channel[N]; 128 | bool empty[N]; 129 | std::mutex wlock[N]; 130 | 131 | void setup() { 132 | for(int i=0; iid car) 20 | (define val->size cadr) 21 | (define val->core caddr) 22 | (define val->dependencies cadddr) 23 | 24 | (define add-layout-entry! add-ntuple!) 25 | 26 | (define (id->val layout-map id) 27 | (get-by-nth-key layout-map 0 id)) 28 | 29 | (define (core->vals layout-map core) 30 | (get-list-by-nth-val layout-map 2 core)) 31 | 32 | (define (all-cores layout-map) 33 | (set->list (apply set (map caddr (get-all-values layout-map))))) 34 | -------------------------------------------------------------------------------- /src/layout-rohin/layout-tests/md5.in: -------------------------------------------------------------------------------- 1 | 10 4 4 2 | 0 2 2 3 | 0 7 2 4 | 1 3 64 5 | 6 7 64 6 | 2 3 128 7 | 7 8 128 8 | 3 8 128 9 | 3 4 64 10 | 8 9 64 11 | 5 3 64 12 | 5 8 64 13 | 14 | -------------------------------------------------------------------------------- /src/layout-rohin/layout-tests/ssd.in: -------------------------------------------------------------------------------- 1 | 18 5 5 2 | 0 1 6 3 | 1 2 7 4 | 2 3 7 5 | 3 4 7 6 | 4 5 7 7 | 5 6 7 8 | 6 7 7 9 | 7 8 7 10 | 8 9 7 11 | 9 10 7 12 | 11 12 7 13 | 12 13 7 14 | 13 14 7 15 | 14 15 7 16 | 15 16 7 17 | 16 17 1 18 | 19 | -------------------------------------------------------------------------------- /src/layout-rohin/layout-tests/strangeness.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "../nmap.rkt" "../layout-map.rkt" "../layout.rkt" "test-layout.rkt") 4 | 5 | (define layout-map (parse-input "md5.in")) 6 | (define core1 (val->core (id->val layout-map 0))) 7 | (define core2 (val->core (id->val layout-map 1))) 8 | ; (size-of-core layout-map core1) returns 256. It should return a 9 | ; formula. 10 | ; Debugged to this point: 11 | 12 | (filter (lambda (x) (equal? (list-ref x 2) core1)) 13 | (get-all-values layout-map)) ; Formula, as expected 14 | (get-list-by-nth-val layout-map 2 core1) ; Not a formula!! 15 | 16 | ; The first piece of code (i.e. the filter) is just the body of 17 | ; get-list-by-nth-val (with the arguments substituted in), so the two 18 | ; expressions *should* return the same thing... 19 | -------------------------------------------------------------------------------- /src/layout-rohin/layout-tests/test-layout.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "../layout.rkt" "../layout-map.rkt") 4 | 5 | (provide (all-defined-out)) 6 | 7 | (define (parse-input file) 8 | (with-input-from-file file 9 | (lambda () 10 | (let* ((params (map string->number (string-split (read-line)))) 11 | (n (car params)) 12 | (width (cadr params)) 13 | (height (caddr params)) 14 | (layout-map (make-layout-map))) 15 | (for ([i (range n)] 16 | [core (make-symbolic-physical-cores n width height)]) 17 | ; Use the max size to enforce separate cores 18 | ; Initially no dependencies 19 | (add-layout-entry! layout-map i 256 core '())) 20 | 21 | (define (loop) 22 | (let ((line (map string->number (string-split (read-line))))) 23 | (unless (null? line) 24 | (let ((id1 (car line)) 25 | (id2 (cadr line)) 26 | (num-msg (caddr line))) 27 | (let ((val1 (id->val layout-map id1)) 28 | (val2 (id->val layout-map id2))) 29 | (add-layout-entry! layout-map id1 256 30 | (val->core val1) 31 | (cons (cons (val->core val2) 32 | num-msg) 33 | (val->dependencies val1))) 34 | (add-layout-entry! layout-map id2 256 35 | (val->core val2) 36 | (cons (cons (val->core val1) 37 | num-msg) 38 | (val->dependencies val2))))) 39 | (loop)))) 40 | (loop) 41 | layout-map)))) 42 | 43 | (define (test-file file) 44 | (solve-layout (parse-input file) #:max-cost 100000)) 45 | 46 | (test-file "md5.in") 47 | -------------------------------------------------------------------------------- /src/layout-rohin/layout.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | ; TODO: Creating the actual layout map. See main.rkt. 4 | ; A layout map is created for tests in layout-tests/test-layout.rkt 5 | 6 | ; Note: Need to check on how equality of symbolic variables works. 7 | ; If there are two different symbolic variables a and b representing 8 | ; two different physical cores, but then the solver decides to set 9 | ; them to the same physical core, what will (= a b) do? Might it be 10 | ; better to use (equal? a b) ? (This is important for determining the 11 | ; estimated size of a core.) 12 | 13 | (require "layout-map.rkt") 14 | 15 | (provide (all-defined-out)) 16 | 17 | (define (physical-core x y) 18 | (cons x y)) 19 | 20 | (define (physical-core-x core) (car core)) 21 | (define (physical-core-y core) (cdr core)) 22 | ; Need to implement equality so that symbolic variables are compared. 23 | ; Hashing is tricky. Just do a terrible hash function, and make sure 24 | ; you never hash cores. 25 | #|(struct physical-core (x y) #:transparent 26 | #:methods 27 | gen:equal+hash 28 | [(define (equal-proc a b equal?-recur) 29 | 5) 30 | (print 31 | (and (= (physical-core-x a) (physical-core-x b)) 32 | (= (physical-core-y a) (physical-core-y b)))) 33 | (newline) 34 | (and (= (physical-core-x a) (physical-core-x b)) 35 | (= (physical-core-y a) (physical-core-y b)))) 36 | (define (hash-proc a hash-recur) 37 | 3) 38 | (define (hash2-proc a hash2-recur) 39 | 5)])|# 40 | 41 | (define (make-symbolic-physical-cores n width height) 42 | (build-list n (lambda (i) 43 | (define-symbolic* x number?) 44 | (define-symbolic* y number?) 45 | (assert (>= x 0)) 46 | (assert (>= y 0)) 47 | (assert (< x width)) 48 | (assert (< y height)) 49 | (physical-core x y)))) 50 | 51 | ; A procedure to check if two cores are equal that works with symbolic 52 | ; cores. Need to make sure to only compare (symbolic) numbers. 53 | (define (equal-cores? a b) 54 | (and (= (physical-core-x a) (physical-core-x b)) 55 | (= (physical-core-y a) (physical-core-y b)))) 56 | 57 | (define (size-of-core layout-map core) 58 | (foldr + 0 (map val->size (core->vals layout-map core)))) 59 | #| 60 | (define (size-of-core layout-map core) 61 | (define (naive-size-of-core core) 62 | (apply + (map val->size (core->vals layout-map core)))) 63 | (foldr + 0 64 | (map naive-size-of-core 65 | (filter (lambda (other) (equal-cores? other core)) 66 | (all-cores layout-map))))) 67 | |# 68 | 69 | (define (manhattan-distance core1 core2) 70 | (+ (abs (- (physical-core-x core1) (physical-core-x core2))) 71 | (abs (- (physical-core-y core1) (physical-core-y core2))))) 72 | 73 | (define (flatmap fn lst) 74 | (flatten (map fn lst))) 75 | 76 | (define (routing-cost layout-map) 77 | ; Sum of all of the routing costs 78 | (apply + 79 | ; Loop over each core 80 | (flatmap 81 | (lambda (core) 82 | ; Loop over each value 83 | (flatmap 84 | (lambda (val) 85 | ; Loop over each dependency 86 | (map 87 | (lambda (pair) 88 | (let ((other-core (car pair)) 89 | (scale (cdr pair))) 90 | ; Estimate routing cost 91 | (* scale 92 | (manhattan-distance core other-core)))) 93 | (val->dependencies val))) ; List of dependencies 94 | (core->vals layout-map core))) ; List of values 95 | (all-cores layout-map)))) ; List of all cores 96 | 97 | ; TODO: Improve max-cost default value 98 | (define (solve-layout layout-map #:capacity [capacity 256] 99 | #:max-cost [max-cost 1000]) 100 | (for-each (lambda (core) 101 | (assert (<= (size-of-core layout-map core) capacity))) 102 | (all-cores layout-map)) 103 | (solve (assert (<= (routing-cost layout-map) max-cost))) 104 | (map (lambda (core) 105 | (physical-core (evaluate (physical-core-x core)) 106 | (evaluate (physical-core-y core)))) 107 | (all-cores layout-map))) 108 | 109 | ; Minimal Testing 110 | (define (run-tests) 111 | (define test-map (make-layout-map)) 112 | (add-layout-entry! test-map 0 10 (physical-core 1 0) 113 | (list (cons (physical-core 2 3) 5) 114 | (cons (physical-core 1 1) 2))) 115 | (print (routing-cost test-map)) 116 | (newline) 117 | (solve-layout test-map) 118 | ;(check-layout test-map #:capacity 5) 119 | (solve #t)) 120 | 121 | ;(run-tests) 122 | -------------------------------------------------------------------------------- /src/layout-rohin/nmap.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | ; An n-map provides a one-to-one-to-one-to... mapping. Each nmap 4 | ; contains ntuples. ntuples can be accessed by any of their 5 | ; elements. Since we want a one-to-one-to... mapping, when we add a 6 | ; new tuple, any existing bindings for any of the keys are removed. 7 | 8 | (provide (all-defined-out)) 9 | 10 | ; An n-map is a list of n hashmaps. 11 | ; The nth hashmap maps the nth key to the k-tuple value. 12 | ; Assumption: n >= 1 13 | (define (make-nmap n) 14 | (build-list n (lambda (x) (make-hash)))) 15 | 16 | (define (add-ntuple! nmap . args) 17 | (unless (<= (length nmap) (length args)) 18 | (error "Incorrect number of arguments to add-ntuple")) 19 | (let* ((n (length nmap)) 20 | (keys (take args n))) 21 | (for-each (lambda (index key) (remove-by-nth-key! nmap index key)) 22 | (range n) keys) 23 | (for-each (lambda (hash key) (hash-set! hash key args)) 24 | nmap keys))) 25 | 26 | (define (get-by-nth-key nmap index key) 27 | (hash-ref (list-ref nmap index) key)) 28 | 29 | (define (get-all-values nmap) 30 | (hash-values (car nmap))) 31 | 32 | ; Gets all of the values where the item at position index is val. 33 | ; Note that if there are m keys and n elements in the value, then the 34 | ; index should satisfy m <= index < n. 35 | ; For index < m, should just used get-by-nth-key. 36 | (define (get-list-by-nth-val nmap index val) 37 | (filter (lambda (x) (equal? (list-ref x index) val)) 38 | (get-all-values nmap))) 39 | 40 | (define (has-nth-key? nmap index key) 41 | (hash-has-key? (list-ref nmap index) key)) 42 | 43 | ; Removes the mapping, if it exists. 44 | ; If it does not exist, does nothing. 45 | (define (remove-by-nth-key! nmap index key) 46 | (when (has-nth-key? nmap index key) 47 | (for-each hash-remove! nmap 48 | (take (get-by-nth-key nmap index key) (length nmap))))) 49 | -------------------------------------------------------------------------------- /src/qap/graph2matrix.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | import sys, numpy 5 | 6 | def abs(x): 7 | if x < 0: 8 | x = 0 - x 9 | return x 10 | 11 | # INPUT: 12 | # P - number of code partitions 13 | # W,H - width and height of the grid processors 14 | # u_0, v_0, f_0 15 | # u_1, v_1, f_1 16 | # until EOF 17 | 18 | # OUTPUT: 19 | # N - which is W*H 20 | # D: N x N matrix 21 | # F: N x N matrix 22 | if __name__ == "__main__": 23 | inp = open(sys.argv[1], 'r') 24 | weight = (sys.argv[2] == '--weight') 25 | 26 | # P W H 27 | s = inp.readline().split() 28 | assert(len(s) == 3) 29 | p,w,h = [int(x) for x in s] 30 | n = w*h 31 | assert(n >= p) 32 | 33 | # N 34 | print(n) 35 | print() 36 | 37 | # D - manhattan distrance matrix 38 | for x1 in xrange(h): 39 | for y1 in xrange(w): 40 | for x2 in xrange(h): 41 | for y2 in xrange(w): 42 | print(abs(x1-x2) + abs(y1-y2),end=' ') 43 | 44 | print() 45 | print() 46 | 47 | # F - Flow 48 | f = numpy.zeros((n,n)) 49 | s = inp.readline() 50 | while(s): 51 | s = s.split() 52 | if len(s) == 3: 53 | # u v f_uv 54 | (u,v,w) = [int(x) for x in s] 55 | if weight: 56 | f[u][v] = f[u][v] + w 57 | f[v][u] = f[v][u] + w 58 | else: 59 | f[u][v] = 1 60 | f[v][u] = 1 61 | assert(u != v) 62 | elif len(s) != 0: 63 | raise "Flow information is given as 'u v f' per line." 64 | s = inp.readline() 65 | 66 | for row in f: 67 | for x in row: 68 | print(int(x),end=' ') 69 | print() 70 | 71 | -------------------------------------------------------------------------------- /src/routing.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | (require "header.rkt" "a-star.rkt" 3 | math/matrix) 4 | 5 | (provide route-obs coords->index index->coords) 6 | 7 | (define debug #f) 8 | 9 | (define (coords->index x y w) 10 | (+ (* y w) x)) 11 | 12 | (define (index->coords core w) 13 | (cons (index-x core w) (index-y core w))) 14 | 15 | (define (index-x core w) (modulo core w)) 16 | (define (index-y core w) (floor (/ core w))) 17 | 18 | (define (make-map w h obstacles) 19 | (build-matrix h w (λ (y x) 20 | (when 21 | debug 22 | (pretty-display `(,x ,y ,(coords->index x y w) 23 | ,(not (set-member? obstacles (coords->index x y w)))))) 24 | (not (set-member? obstacles (coords->index x y w)))))) 25 | 26 | (struct map-node (M x y) #:transparent) 27 | (struct map-edge (src dx dy dest)) 28 | 29 | (define ((make-node-cost GX GY) n) 30 | (match-define (map-node M x y) n) 31 | (+ (abs (- x GX)) 32 | (abs (- y GY)))) 33 | 34 | (define-unit map@ 35 | (import) (export graph^) 36 | 37 | (define node? map-node?) 38 | (define edge? map-edge?) 39 | (define edge-src map-edge-src) 40 | (define edge-dest map-edge-dest) 41 | 42 | (define (edge-cost e) 1) ;; TODO: optimize routing by playing with cost 43 | 44 | (define (node-edges n) 45 | (match-define (map-node M x y) n) 46 | (append* 47 | (for*/list ([dx (in-list '(1 0 -1))] 48 | [dy (in-list '(1 0 -1))] 49 | #:when 50 | (and (not (and (zero? dx) (zero? dy))) 51 | (or (zero? dx) (zero? dy)))) 52 | (cond 53 | [(and (<= 0 (+ dx x) (sub1 (matrix-num-cols M))) 54 | (<= 0 (+ dy y) (sub1 (matrix-num-rows M))) 55 | (matrix-ref M (+ dy y) (+ dx x))) 56 | (define dest (map-node M (+ dx x) (+ dy y))) 57 | (list (map-edge n dx dy dest))] 58 | [else 59 | empty]))))) 60 | 61 | (define (route-edges core-a core-b w h obstacles) 62 | ;; (pretty-display `(route ,core-a ,core-b ,w ,h ,obstacles)) 63 | (define a-x (index-x core-a w)) 64 | (define a-y (index-y core-a w)) 65 | (define b-x (index-x core-b w)) 66 | (define b-y (index-y core-b w)) 67 | (when debug (pretty-display (list 'inside-route a-x a-y b-x b-y))) 68 | 69 | (define map (make-map w h obstacles)) 70 | (when debug 71 | (for ([row (matrix-rows map)]) 72 | (pretty-display row))) 73 | (define ret (A* map@ 74 | (map-node map a-x a-y) 75 | (make-node-cost b-x b-y))) 76 | ;; (unless ret 77 | ;; (raise (format "routing: no available route between cores ~a and ~a" 78 | ;; core-a core-b))) 79 | ret) 80 | 81 | (define (route-indices core-a core-b w h obstacles) 82 | (if (or (equal? core-a (* w h)) (equal? core-a (add1 (* w h))) 83 | (equal? core-b (* w h)) (equal? core-b (add1 (* w h)))) 84 | (list core-a core-b) 85 | (let ([edges (route-edges core-a core-b w h obstacles)]) 86 | (and edges 87 | (let ([nodes (if (empty? edges) empty 88 | (cons (map-edge-src (first edges)) 89 | (for/list ([edge edges]) 90 | (map-edge-dest edge))))]) 91 | (for/list ([node nodes]) 92 | (coords->index (map-node-x node) (map-node-y node) w))))))) 93 | 94 | (define (route-obs core-a core-b w h obstacles) 95 | (define indices (route-indices core-a core-b w h obstacles)) 96 | (pretty-display `(route-obs ,core-a ,core-b ,indices)) 97 | (and indices (not (empty? indices)) indices)) 98 | 99 | -------------------------------------------------------------------------------- /src/space-estimator.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (provide (all-defined-out)) 4 | 5 | (define est-data1 4) 6 | (define est-data2 6) ;; 8 is too high 7 | (define est-num 5) 8 | (define est-var 4) ; @p a! @ . addr 9 | (define est-comm 8) ; @p a! ! . up 10 | (define est-acc-arr 4) ; @p @p . + a! @ 11 | (define est-for 8) ; 32 @p a! ! . | @p a! @ 1 . + ! . (20) 12 | (define est-if 8) ;; call => 4 ;; :def if _ ; ] then _ ; => 4 13 | (define est-while 8) ;; :while _ if _ while ; then ; 14 | (define est-funccall 4) 15 | (define est-funcreturn 18) ;; data & 0 a! ! 0 a! @ 16 | 17 | (define space-map 18 | #hash(("~" . 1) 19 | ("!" . 1) 20 | ("*" . 25) ; @p 17 for +* unext, (20 + 31)/2 = 25 21 | ("/" . 24) 22 | ("%" . 18) 23 | ("/%" . 17) 24 | ("*/17" . 7) 25 | ("*/16" . 7) 26 | ("*:2" . 20) 27 | ("**2" . 37) ; (+ 12 25)) 28 | ("+" . 2) ; . + 29 | ("-" . 10) ; - @p . + 1 . + 30 | (">>" . 12) 31 | ("<<" . 12) 32 | (">>>" . 37) 33 | ("<" . 10) ; a < b --> a - b < 0 - @p . + num . + -if 34 | ("<=" . 10) ; a <= b --> a - b - 1 < 0 - @p . + num -if 35 | (">=" . 10) 36 | (">" . 10) 37 | ("==" . 10) ; a == b - @p . + num . + if 38 | ("!=" . 10) 39 | ("&" . 1) 40 | ("^" . 1) 41 | ("|" . 5) ; over - and . + 42 | ("&&" . 2) ; if(c1 && c2) { a } --> c1 if c2 if a then then 43 | ("||" . 6) ; if(c1 || c2) { a } --> c1 if call ; 44 | )) 45 | 46 | (define (est-space x) 47 | (dict-ref space-map x)) 48 | 49 | -------------------------------------------------------------------------------- /src/symbolic/ops-rosette.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require (only-in rosette [<< sym/<<] [>>> sym/>>>])) 4 | 5 | (provide (all-defined-out)) 6 | 7 | (define-syntax-rule (assert-return c message val) 8 | (begin 9 | (assert c message) 10 | val)) 11 | 12 | (define-syntax-rule (<< x y bit) (sym/<< x y)) 13 | (define-syntax-rule (>>> x y bit) (sym/>>> x y)) 14 | 15 | (define (finitize num bit) 16 | (match (coerce num number?) 17 | [(? term? v) v] 18 | [v (let* ([mask (arithmetic-shift -1 bit)] 19 | [masked (bitwise-and (bitwise-not mask) v)]) 20 | (if (bitwise-bit-set? masked (- bit 1)) 21 | (bitwise-ior mask masked) 22 | masked))])) 23 | 24 | ;; This function is very memory expensive in Rosette 25 | (define (vector-copy! dest dest-start src 26 | [src-start 0] [src-end (vector-length src)]) 27 | ;;(pretty-display `(vector-copy! ,src-start ,src-end ,(- src-end src-start))) 28 | (for ([i (in-range (- src-end src-start))]) 29 | ;;(pretty-display `(copy-* ,(quotient (current-memory-use) 1000))) 30 | (vector-set! dest (+ dest-start i) 31 | (vector-ref src (+ src-start i)))) 32 | ) 33 | 34 | 35 | 36 | ;; This function is very memory expensive in Rosette 37 | (define (vector-copy-len! dest dest-start 38 | src src-start len) 39 | (for ([i (in-range len)]) 40 | ;;(pretty-display `(copy-* ,i)) 41 | (vector-set! dest (+ dest-start i) 42 | (vector-ref src (+ src-start i)))) 43 | ) 44 | 45 | ;; TODO: do we need this? 46 | (define (vector-copy-len vec start len) 47 | ;(pretty-display `(vector-copy ,start ,len)) 48 | (for/vector ([i len]) (vector-ref vec (+ start i)))) 49 | 50 | 51 | (define (vector-extract a b shift) 52 | ;(pretty-display `(vector-extract ,a ,b ,shift)) 53 | (define len (vector-length a)) 54 | (define pos (- len shift)) 55 | (define vec (make-vector len)) 56 | (for ([i (in-range pos)]) 57 | ;(pretty-display `(first ,i ,(+ shift i))) 58 | (vector-set! vec i (vector-ref a (+ shift i)))) 59 | (for ([i (in-range shift)]) 60 | ;(pretty-display `(second ,(+ pos i) ,i)) 61 | (vector-set! vec (+ pos i) (vector-ref b i))) 62 | ;(pretty-display `(vector-extract-ret ,vec)) 63 | vec) 64 | 65 | (define (smmul u v bit) 66 | (define byte2 (quotient bit 2)) 67 | (define low-mask (sub1 (arithmetic-shift 1 byte2))) 68 | 69 | (define u0 (bitwise-and u low-mask)) 70 | (define u1 (>> u byte2)) 71 | (define v0 (bitwise-and v low-mask)) 72 | (define v1 (>> v byte2)) 73 | 74 | (define w0 (finitize (* u0 v0) bit)) 75 | (define t (finitize (+ (* u1 v0) (sym/>>> w0 byte2)) bit)) 76 | (define w1 (bitwise-and t low-mask)) 77 | (define w2 (>> t byte2)) 78 | (set! w1 (finitize (+ (* u0 v1) w1) bit)) 79 | (finitize (+ (* u1 v1) w2 (>> w1 byte2)) bit)) 80 | 81 | (define (ummul u v bit) 82 | (define byte2 (quotient bit 2)) 83 | (define low-mask (sub1 (arithmetic-shift 1 byte2))) 84 | 85 | (define u0 (bitwise-and u low-mask)) 86 | (define u1 (bitwise-and (>> u byte2) low-mask)) 87 | (define v0 (bitwise-and v low-mask)) 88 | (define v1 (bitwise-and (>> v byte2) low-mask)) 89 | 90 | (finitize 91 | (+ (* u1 v1) 92 | (sym/>>> (* u1 v0) byte2) 93 | (sym/>>> (* u0 v1) byte2) 94 | (sym/>>> (+ (bitwise-and (* u1 v0) low-mask) 95 | (bitwise-and (* u0 v1) low-mask) 96 | (sym/>>> (* u0 v0) byte2)) 97 | byte2)) 98 | bit)) 99 | 100 | ;; (define (smmul x y bit) 101 | ;; (define p (*h x y)) 102 | ;; (define t1 (bitwise-and (>> x (sub1 bit)) y)) 103 | ;; (define t2 (bitwise-and (>> y (sub1 bit)) x)) 104 | ;; (finitize (- p t1 t2) bit)) 105 | 106 | ;; (define (ummul x y bit) 107 | ;; (*h x y)) 108 | -------------------------------------------------------------------------------- /src/symbolic/test-simulator.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "../arrayforth.rkt" "simulator.rkt") 4 | 5 | (define code 6 | (aforth 7 | ;; linklist 8 | (list 9 | (vardecl '(0 -281 5203 -42329 37407 0)) 10 | (funcdecl "1if" 11 | ;; linklist 12 | (list 13 | (-iftf 14 | ;; linklist 15 | (list 16 | (block 17 | "0 b! " 18 | 0 0 (restrict #t #f #f #f) #f 19 | "0 b! ") 20 | ) 21 | ;; linklist 22 | (list 23 | (block 24 | "0 b! " 25 | 0 0 (restrict #t #f #f #f) #f 26 | "0 b! ") 27 | ) 28 | ) 29 | (funccall "1if") 30 | ) 31 | #f) 32 | (funcdecl "main" 33 | ;; linklist 34 | (list 35 | (funccall "--u/mod") 36 | (block 37 | "0 b!" 38 | 0 0 (restrict #t #f #f #f) "0" 39 | "0 b!") 40 | (ift 41 | ;; linklist 42 | (list 43 | (forloop 44 | ;; linklist 45 | (list 46 | ) 47 | ;; linklist 48 | (list 49 | (block 50 | "2* " 51 | 1 1 (restrict #t #f #f #f) #f 52 | "2* ") 53 | ) 54 | #f #f #f) 55 | (block 56 | "dup " 57 | 1 2 (restrict #t #f #f #f) #f 58 | "dup ") 59 | ) 60 | ) 61 | 62 | (funccall "1if") 63 | ;(funccall "*.") 64 | (block 65 | "0 b! !b " 66 | 1 0 (restrict #t #f #f #f) #f 67 | "0 b! !b ") 68 | (block 69 | "3 b! !b " 70 | 1 0 (restrict #t #f #f #f) #f 71 | "5 b! !b ") 72 | (forloop 73 | ;; linklist 74 | (list 75 | (block 76 | "1 a! 3 " 77 | 0 1 (restrict #t #t #f #f) #f 78 | "1 a! 3 ") 79 | ) 80 | ;; linklist 81 | (list 82 | (block 83 | "3 b! @b " 84 | 0 1 (restrict #t #t #f #f) #f 85 | "5 b! @b ") 86 | (block 87 | "0 b! @b " 88 | 0 1 (restrict #t #t #f #f) #f 89 | "0 b! @b ") 90 | ;(funccall "*.") 91 | (block 92 | "@+ " 93 | 1 1 (restrict #t #t #f #f) #f 94 | "@+ ") 95 | (block 96 | "3 b! !b " 97 | 1 0 (restrict #t #t #f #f) #f 98 | "5 b! !b ") 99 | ) 100 | '((1 . opt) 1 . opt) 0 4) 101 | (block 102 | "3 b! @b " 103 | 0 1 (restrict #t #f #f #f) #f 104 | "5 b! @b ") 105 | ;(funccall "*.") 106 | (block 107 | "up b! !b " 108 | 1 0 (restrict #t #f #f #f) "up" 109 | "up b! !b ") 110 | ;(funccall "1if") 111 | ) 112 | #f) 113 | ) 114 | 4 18 #hash((0 . 0) (1 . 1) (3 . 5) (4 . 6))) 115 | ) 116 | 117 | (define state-i (get-progstate 4)) 118 | (define state-f (analyze-reg-b code state-i 0)) 119 | (aforth-struct-print code) 120 | -------------------------------------------------------------------------------- /src/symbolic/test-simulator2.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "../arrayforth.rkt" "simulator.rkt") 4 | 5 | (define code 6 | (list 7 | (iftf 8 | ;; list 9 | (list 10 | (block 11 | "drop " 12 | 1 0 (restrict #t #f #f #f) #f 13 | "drop " #;#t) 14 | (block 15 | "131072 io b! !b " 16 | 0 0 (restrict #t #f #f #f) "io" 17 | "131072 io b! !b " #;#f) 18 | ) 19 | ;; list 20 | (list 21 | (block 22 | "drop " 23 | 1 0 (restrict #t #f #f #f) #f 24 | "drop " #;()) 25 | (block 26 | "196608 io b! !b " 27 | 0 0 (restrict #t #f #f #f) "io" 28 | "196608 io b! !b " #;()) 29 | ) 30 | ) 31 | )) 32 | 33 | (define state-i (get-progstate 0)) 34 | (define state-f (analyze-reg-b code state-i 108)) 35 | (aforth-struct-print code) 36 | -------------------------------------------------------------------------------- /src/synthesizer.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require 4 | (rename-in rosette/lang/assert [assert* assert]) 5 | rosette/base/bool rosette/base/value 6 | rosette/lang/debug rosette/util/array) 7 | 8 | (define (get-sym) 9 | (define-symbolic a number?) 10 | a) 11 | 12 | (synthesize #:forall (list (get-sym) (get-sym)) 13 | #:assume #t 14 | #:guarantee #t) 15 | 16 | (current-solution) 17 | 18 | (define-symbolic b number?) 19 | (define-symbolic c number?) 20 | (equal? b c) -------------------------------------------------------------------------------- /src/test-miner.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "arrayforth.rkt" "arrayforth-def.rkt" 4 | "arrayforth-print.rkt" 5 | "arrayforth-optimize.rkt" 6 | ) 7 | 8 | (define program 9 | (vector 10 | (aforth 11 | ;; linklist 12 | (list 13 | (vardecl '()) 14 | (funcdecl "osc" 15 | ;; linklist 16 | (list 17 | (forloop 18 | ;; linklist 19 | (list 20 | (block 21 | "4999 " 22 | 0 1 (restrict #t #f #f #f) #f 23 | "4999 ") 24 | ) 25 | ;; linklist 26 | (list 27 | (block 28 | "io b! 196608 !b " 29 | 0 0 (restrict #t #f #f #f) "io" 30 | "io b! 196608 !b ") 31 | (block 32 | "dup " 33 | 0 1 (restrict #t #f #f #f) #f 34 | "dup ") 35 | (forloop 36 | ;; linklist 37 | (list 38 | ) 39 | ;; linklist 40 | (list 41 | ) 42 | #f #f #f) 43 | (block 44 | "io b! 131072 !b " 45 | 0 0 (restrict #t #f #f #f) "io" 46 | "io b! 131072 !b ") 47 | (block 48 | "dup " 49 | 0 1 (restrict #t #f #f #f) #f 50 | "dup ") 51 | (forloop 52 | ;; linklist 53 | (list 54 | ) 55 | ;; linklist 56 | (list 57 | ) 58 | #f #f #f) 59 | ) 60 | '(#f . #f) 0 5000) 61 | ) 62 | #f) 63 | (funcdecl "main" 64 | ;; linklist 65 | (list 66 | (funccall "osc") 67 | ) 68 | #f) 69 | ) 70 | 0 18 #f #f #f #f) 71 | )) 72 | (set! program (define-repeating-codes program 1 1)) 73 | (aforth-syntax-print program 1 1) 74 | (aforth-struct-print program) 75 | ;(define real-opts (superoptimize program "test" 1 1)) 76 | ;(aforth-syntax-print real-opts 1 1) 77 | -------------------------------------------------------------------------------- /src/test-partitioner.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "header.rkt" 4 | "parser.rkt" 5 | "compiler.rkt" 6 | "partitioner.rkt" 7 | "partition-storage.rkt" 8 | rackunit) 9 | 10 | (define testdir "../tests/") 11 | 12 | (define (optimize-file file name cores capacity max-msgs) 13 | (set-outdir file name) 14 | (define my-ast (parse file)) 15 | (optimize-comm my-ast #:cores cores #:capacity capacity #:max-msgs max-msgs 16 | #:verbose #t)) 17 | 18 | ;; Check with expected number of messages 19 | (define (test-num-msgs name expected-msgs 20 | #:cores [cores 4] #:capacity [capacity 256] #:max-msgs [max-msgs 8] 21 | [file (string-append testdir name ".cll")]) 22 | (check-equal? 23 | (result-msgs (optimize-file file name cores capacity max-msgs)) 24 | expected-msgs 25 | name) 26 | ) 27 | 28 | ;; Consistency Test 29 | (define (test-consistent name 30 | [cores 4] [capacity 256] [max-msgs 8] 31 | [file1 (string-append testdir name "_concrete.cll")] 32 | [file2 (string-append testdir name "_symbolic.cll")]) 33 | (let ([res1 (optimize-file file1 (string-append name "_concrete") cores capacity max-msgs)] 34 | [res2 (optimize-file file2 (string-append name "_symbolic") cores capacity max-msgs)]) 35 | (check-equal? (result-msgs res1) (result-msgs res2)) 36 | (check-true (cores-equal? (result-cores res1) (result-cores res2))))) 37 | 38 | ;; No error test 39 | (define (no-error name [cores 4] [capacity 256] [max-msgs #f] 40 | [file (string-append testdir name ".cll")]) 41 | (optimize-file file name cores capacity max-msgs)) 42 | 43 | (test-num-msgs "for-array1" 0) 44 | (test-num-msgs "for-array2" 0) 45 | (test-num-msgs "for-array3" 0) 46 | ;(test-num-msgs "for-array4" 20 #:max-msgs 100 #:capacity 512) 47 | ;(test-num-msgs "for-array5" 0) 48 | ;(test-num-msgs "add" 100 #:cores 8 #:max-msgs 200 #:capacity 350) 49 | ;(test-num-msgs "add-pair" 100 #:cores 8 #:max-msgs 200 #:capacity 300) 50 | ;(test-num-msgs "function" 2 #:capacity 512) 51 | ;(test-num-msgs "function2" 4) 52 | ;(test-num-msgs "while" 300 #:max-msgs 800) 53 | 54 | ;(test-consistent "space") 55 | ;(test-consistent "if") 56 | -------------------------------------------------------------------------------- /src/test-simulator.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "compiler.rkt") 4 | 5 | (define result (list)) 6 | 7 | (define (test file name input capacity #:w [w 5] #:h [h 4] #:partition [part #t]) 8 | (set! result (cons 9 | (cons name (test-simulate file name input capacity w h part)) 10 | result))) 11 | 12 | ;(test "../examples/simple/hello.cll" "hello" "null" 256) 13 | ;(test "../examples/simple/array.cll" "array" "10" 256) 14 | ;(test "../examples/simple/assign.cll" "assign" "null" 512) 15 | ;(test "../examples/simple/if.cll" "if" "4_1" 512) 16 | ;(test "../examples/simple/offset.cll" "offset" "4_1" 512) 17 | ;(test "../examples/simple/add.cll" "add" "200" 1024) 18 | ;(test "../examples/simple/function.cll" "function" "null" 256) 19 | ;(test "../examples/simple/function-pair.cll" "function-pair" "null" 512 #:w 2 #:h 3) 20 | ;(test "../examples/simple/pair1.cll" "pair1" "null" 512) 21 | ;(test "../examples/simple/pair2.cll" "pair2" "null" 512) 22 | ;(test "../examples/simple/while.cll" "while" "10" 256) 23 | ;(test "../examples/simple/unroll.cll" "unroll" "null" 1024 #:w 2 #:h 3) 24 | ;(test "../examples/simple/extendshift.cll" "extendshift" "null" 256) 25 | ;(test "../examples/simple/global.cll" "global" "null" 256) 26 | 27 | ;(test "../examples/matrixmultiply/matrixmult6.cll" "matrixmult6" "72" 500) ;capacity issue 28 | ;(test "../examples/matrixmultiply/matrixmult4-dup.cll" "matrixmult4-dup" "null" 500) 29 | 30 | ;(test "../examples/mapreduce/map.cll" "map" "null" 290) 31 | ;(test "../examples/mapreduce/map-pair.cll" "map-pair" "null" 290) 32 | ;(test "../examples/mapreduce/reduce.cll" "reduce" "null" 290) 33 | ;(test "../examples/mapreduce/reduce-pair.cll" "reduce-pair" "null" 290 #:partition #f) 34 | ;(test "../examples/mapreduce/mapreduce.cll" "mapreduce" "null" 290 #:partition #f) 35 | 36 | ;(test "../examples/rom/interp.cll" "interp" "1" 256 #:w 3 #:h 3) 37 | ;(test "../examples/rom/poly.cll" "poly" "1" 256 #:w 3 #:h 3) 38 | ;(test "../examples/rom/cos.cll" "cos" "1" 300 #:w 3 #:h 3) 39 | ;(test "../examples/rom/sqrt2.cll" "sqrt2" "2" 400 #:w 3 #:h 3) 40 | ;(test "../examples/rom/complex3.cll" "complex3" "1" 300 #:w 4 #:h 4) 41 | 42 | ;(test "../examples/md5/md5-rightrot-sim.cll" "md5-rightrot-sim" "null" 1024 #:w 8 #:h 8) 43 | ;(test "../examples/md5/leftrotate.cll" "leftrotate" "null" 1024 #:w 3 #:h 4) 44 | 45 | ;(test "../examples/parallel/ssd.cll" "ssd" "null" 512 #:w 8 #:h 8) 46 | ;(test "../examples/parallel/swap.cll" "swap" "null" 512 #:w 8 #:h 8) 47 | ;(test "../examples/parallel/prefixsum.cll" "prefixsum" "null" 512 #:w 8 #:h 8) 48 | ;(test "../examples/parallel/convolution.cll" "convolution" "null" 400 #:w 4 #:h 4 #:partition #f) 49 | ;(test "../examples/parallel/convolution-pair.cll" "convolution-pair" "null" 400 #:w 8 #:h 8 #:partition #f) 50 | 51 | ;(test "../examples/fixedpoint/cos_round.cll" "cos_round" "null" 256 #:w 3 #:h 3) 52 | ;(test "../examples/fixedpoint/cos_radius.cll" "cos_radius" "null" 256 #:w 3 #:h 3) 53 | 54 | ;(test "../examples/module/module_simple.cll" "module_simple" "null" 256 #:w 3 #:h 3) 55 | ;(test "../examples/sensors/hmm_test.cll" "hmm_test" "null" 256 #:w 3 #:h 3) 56 | 57 | (test "../examples/actor/actor_v1.cll" "actor_v1" "null" 256 #:w 3 #:h 3) 58 | 59 | 60 | (for ([res (reverse result)]) 61 | (pretty-display res)) 62 | -------------------------------------------------------------------------------- /src/visitor-collector.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "header.rkt" 4 | "ast.rkt" "visitor-interface.rkt" ) 5 | 6 | (provide (all-defined-out)) 7 | 8 | (define place-collector% 9 | (class* object% (visitor<%>) 10 | (super-new) 11 | (init-field collect?) 12 | 13 | (define (create-set place) 14 | (if (collect? place) 15 | (set place) 16 | (set))) 17 | 18 | (define (place-set place) 19 | (cond 20 | [(list? place) 21 | (foldl (lambda (p var-set) (set-union var-set (send p accept this))) 22 | (set) place)] 23 | 24 | [(pair? place) 25 | (place-set (car place))] 26 | 27 | [(is-a? place TypeExpansion%) 28 | (foldl (lambda (x placeset) (set-union placeset (place-set x))) 29 | (set) 30 | (get-field place-list place))] 31 | 32 | [else (create-set place)])) 33 | 34 | (define/public (visit ast) 35 | 36 | (define-syntax-rule (union-set-from-list x) 37 | (foldl (lambda (ele var-set) (set-union var-set (send ele accept this))) 38 | (set) x)) 39 | 40 | (cond 41 | [(is-a? ast Livable%) 42 | (place-set (get-field place ast)) 43 | ] 44 | 45 | [(is-a? ast LivableGroup%) 46 | (place-set (get-field place-list ast)) 47 | ] 48 | 49 | [(is-a? ast For%) 50 | (let ([ret (place-set (get-field place-list ast))]) 51 | (set-union ret (send (get-field body ast) accept this)))] 52 | 53 | [(is-a? ast Num%) 54 | (send (get-field n ast) accept this) 55 | ] 56 | 57 | [(is-a? ast Var%) 58 | (set) ; we handle var at declaration. 59 | ] 60 | 61 | [(is-a? ast UnaExp%) 62 | (set-union (send (get-field op ast) accept this) 63 | (send (get-field e1 ast) accept this)) 64 | ] 65 | 66 | [(is-a? ast BinExp%) 67 | (set-union (send (get-field op ast) accept this) 68 | (send (get-field e1 ast) accept this) 69 | (send (get-field e2 ast) accept this)) 70 | ] 71 | 72 | [(is-a? ast Assign%) 73 | (set-union (send (get-field lhs ast) accept this) 74 | (send (get-field rhs ast) accept this)) 75 | ] 76 | 77 | [(is-a? ast Return%) 78 | (set)] 79 | 80 | [(is-a? ast FuncCall%) 81 | (union-set-from-list (get-field args ast))] 82 | 83 | [(is-a? ast If%) 84 | (set-union (send (get-field condition ast) accept this) 85 | (send (get-field true-block ast) accept this) 86 | (let ([false-block (get-field false-block ast)]) 87 | (if false-block 88 | (send false-block accept this) 89 | (set)))) 90 | ] 91 | 92 | [(is-a? ast While%) 93 | (set-union (send (get-field pre ast) accept this) 94 | (send (get-field condition ast) accept this) 95 | (send (get-field body ast) accept this))] 96 | 97 | [(is-a? ast Block%) 98 | (union-set-from-list (get-field stmts ast))] 99 | 100 | [(is-a? ast FuncDecl%) 101 | (let ([return-set (if (get-field return ast) 102 | (send (get-field return ast) accept this) 103 | (set))] 104 | [args-set (send (get-field args ast) accept this)] 105 | [body-set (send (get-field body ast) accept this)]) 106 | (set-union (set-union return-set args-set) body-set))] 107 | 108 | [else (raise (format "Error: var-collector unimplemented for ~a" ast))] 109 | )))) 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/visitor-expr-interpreter.rkt: -------------------------------------------------------------------------------- 1 | #lang s-exp rosette 2 | 3 | (require "header.rkt" "ast.rkt" "ast-util.rkt" "visitor-interface.rkt") 4 | 5 | (provide (all-defined-out)) 6 | 7 | (define expr-interpreter% 8 | (class* object% (visitor<%>) 9 | (super-new) 10 | (init-field [var #f] [from #f] [to #f] [env #f]) 11 | 12 | (define (compute-range e1 e2 op) 13 | (cons (op (car e1) (car e2)) (op (cdr e1) (cdr e2)))) 14 | 15 | (define/public (visit ast) 16 | (cond 17 | [(is-a? ast Array%) 18 | (raise (format "visitor-expr-interpreter: not support Array '~a' at line ~a" 19 | (get-field name ast) (send ast get-line)))] 20 | 21 | [(is-a? ast Num%) 22 | (define n (get-field n (get-field n ast))) 23 | (new Range% [from n] [to n])] 24 | 25 | [(is-a? ast Var%) 26 | (cond 27 | [var 28 | (if (equal? (get-field name ast) var) 29 | (new Range% [from from] [to to]) 30 | (send ast clone))] 31 | [env 32 | (define range (lookup env ast)) 33 | (new Range% [from (car range)] [to (cdr range)])] 34 | [else 35 | (raise "visitor-expr-interpreter: 'var' and 'env' cannot be #f at the same time")])] 36 | 37 | [(is-a? ast UnaExp%) 38 | (define e1-ret (send (get-field e1 ast) accept this)) 39 | (define op (get-field op (get-field op ast))) 40 | (if (is-a? e1-ret Range%) 41 | (let ([e1-from (get-field from e1-ret)] 42 | [e1-to (get-field to e1-ret)]) 43 | (if (equal? op "-") 44 | (new Range% 45 | [from (- e1-to)] 46 | [to (- e1-from)]) 47 | (raise (format "visitor-exp-interpreter: not support Unaray operation '~a' at line ~a" op (send ast get-line))))) 48 | (send ast clone))] 49 | 50 | [(is-a? ast BinExp%) 51 | ;(pretty-display (format "EXPR: BinExp ~a" (send ast to-string))) 52 | (define e1-ret (send (get-field e1 ast) accept this)) 53 | (define e2-ret (send (get-field e2 ast) accept this)) 54 | (define op (get-field op (get-field op ast))) 55 | 56 | (if (and (is-a? e1-ret Range%) (is-a? e2-ret Range%)) 57 | (let* ([e1-from (get-field from e1-ret)] 58 | [e1-to (get-field to e1-ret)] 59 | [e2-from (get-field from e2-ret)] 60 | [e2-to (get-field to e2-ret)] 61 | [range 62 | (lambda (op) 63 | (new Range% [from (op e1-from e2-from)] [to (op e1-to e2-to)]))]) 64 | ;(pretty-display `(ret ,e1-from ,e1-to ,e2-from ,e2-to)) 65 | ;(pretty-display `(e1-to ,e1-to ,(number? e1-to) ,(symbolic? e1-to) ,(list? e1-to))) 66 | (cond 67 | [(equal? op "*") (range *)] 68 | 69 | [(equal? op "+") (range +)] 70 | 71 | [(equal? op "<<") (range arithmetic-shift)] 72 | 73 | [(equal? op "-") 74 | (new Range% [from (- e1-from e2-to)] [to (- e1-to e2-from)])] 75 | 76 | [(equal? op ">>") 77 | (new Range% 78 | [from (arithmetic-shift e1-from (- e2-to))] 79 | [to (arithmetic-shift e1-to (- e2-from))])] 80 | 81 | [else 82 | (raise (format "visitor-expr-interpreter: not support Binary operation '~a' at line ~a" op (send ast get-line)))])) 83 | 84 | (new BinExp% [op (get-field op ast)] [e1 e1-ret] [e2 e2-ret]))] 85 | 86 | [(is-a? ast Range%) 87 | ast] 88 | 89 | [else 90 | (raise (format "visitor-expr-interpreter: unimplemented for ~a" ast))] 91 | 92 | )))) 93 | 94 | -------------------------------------------------------------------------------- /src/visitor-funccalllink.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "header.rkt" 4 | "ast.rkt" "ast-util.rkt" 5 | "visitor-interface.rkt") 6 | 7 | (provide (all-defined-out)) 8 | 9 | (define funccall-linker% 10 | (class* object% (visitor<%>) 11 | (super-new) 12 | (define funcdecls (make-hash)) 13 | 14 | (hash-set! funcdecls "in" (get-stdin)) 15 | (hash-set! funcdecls "out" (get-stdout)) 16 | 17 | (for ([node (append analog-nodes digital-nodes)]) 18 | (hash-set! funcdecls 19 | (format "digital_read~a" node) (get-digital-read node)) 20 | (hash-set! funcdecls 21 | (format "set_io~a" node) (get-set-io node)) 22 | (hash-set! funcdecls 23 | (format "digital_wakeup~a" node) (get-digital-wakeup node)) 24 | (hash-set! funcdecls 25 | (format "delay_ns~a" node) (get-delay-ns node)) 26 | (hash-set! funcdecls 27 | (format "delay_unext~a" node) (get-delay-unext node))) 28 | 29 | (define/public (visit ast) 30 | (cond 31 | [(is-a? ast UnaExp%) 32 | ;; (pretty-display (format "FLINK: UnaExp ~a" (send ast to-string))) 33 | (send (get-field e1 ast) accept this)] 34 | 35 | [(is-a? ast BinExp%) 36 | ;; (pretty-display (format "FLINK: BinExp ~a" (send ast to-string))) 37 | (send (get-field e1 ast) accept this) 38 | (send (get-field e2 ast) accept this)] 39 | 40 | [(is-a? ast FuncCall%) 41 | ;; (pretty-display (format "FLINK: FuncCall ~a, sig=~a" (get-field name ast) 42 | ;; (hash-ref funcdecls (get-field name ast)))) 43 | (set-field! signature ast (hash-ref funcdecls (get-field name ast))) 44 | (for ([arg (get-field args ast)]) 45 | (send arg accept this)) 46 | ] 47 | 48 | [(is-a? ast Send%) 49 | (send (get-field data ast) accept this)] 50 | 51 | [(is-a? ast Assign%) 52 | ;; (pretty-display (format "FLINK: Assign")) 53 | (send (get-field lhs ast) accept this) 54 | (send (get-field rhs ast) accept this)] 55 | 56 | [(is-a? ast Return%) 57 | (define val (get-field val ast)) 58 | (if (list? val) 59 | (for ([v val]) 60 | (send v accept this)) 61 | (send val accept this))] 62 | 63 | [(is-a? ast If%) 64 | (send (get-field condition ast) accept this) 65 | (send (get-field true-block ast) accept this) 66 | (when (get-field false-block ast) 67 | (send (get-field false-block ast) accept this))] 68 | 69 | [(is-a? ast While%) 70 | (send (get-field pre ast) accept this) 71 | (send (get-field condition ast) accept this) 72 | (send (get-field body ast) accept this)] 73 | 74 | [(is-a? ast For%) 75 | ;; (pretty-display (format "FLINK: For")) 76 | (send (get-field body ast) accept this) 77 | ] 78 | 79 | [(is-a? ast VarDeclDup%) 80 | (define old-loop (get-field loop ast)) 81 | (set-field! loop ast (get-field myclone old-loop)) 82 | ;; (pretty-display (format "FLINK: Dup ~a, old-loop = ~a, loop=~a" ast old-loop 83 | ;; (get-field myclone old-loop))) 84 | ] 85 | 86 | [(is-a? ast Block%) 87 | (when (is-a? ast BlockDup%) 88 | (define old-loop (get-field loop ast)) 89 | (set-field! loop ast (get-field myclone old-loop))) 90 | (for ([stmt (get-field stmts ast)]) 91 | (send stmt accept this))] 92 | 93 | [(is-a? ast FuncDecl%) 94 | ;; (pretty-display (format "FLINK: FuncDecl ~a" (get-field name ast))) 95 | (hash-set! funcdecls (get-field name ast) ast) 96 | (send (get-field body ast) accept this)] 97 | )))) 98 | 99 | 100 | (define (clone x) 101 | (define ret (send x clone)) 102 | (send ret accept (new funccall-linker%)) 103 | ret) 104 | 105 | -------------------------------------------------------------------------------- /src/visitor-interface.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (provide (all-defined-out)) 4 | 5 | (define visitor<%> 6 | (interface () visit)) 7 | -------------------------------------------------------------------------------- /src/visitor-lowerbound.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "header.rkt" 4 | "ast.rkt" "ast-util.rkt" "arrayforth.rkt" 5 | "visitor-interface.rkt") 6 | 7 | (provide (all-defined-out)) 8 | 9 | ;; Evaluate expression by treating constants as they are 10 | ;; but treating variables as 0s. 11 | (define lowerbound% 12 | (class* object% (visitor<%>) 13 | (super-new) 14 | 15 | (define/public (visit ast) 16 | (cond 17 | [(is-a? ast Num%) 18 | (get-field n (get-field n ast))] 19 | 20 | [(is-a? ast Var%) 21 | 0] 22 | 23 | [(is-a? ast UnaExp%) 24 | (define op (get-field op (get-field op ast))) 25 | (define e1 (send (get-field e1 ast) accept this)) 26 | 27 | (cond 28 | [(equal? op "~") 29 | (bitwise-xor e1 (sub1 (arithmetic-shift 1 ga-bit)))] 30 | [(equal? op "-") 31 | (- 0 e1)] 32 | [else 33 | (raise (format "visitor-lowerbound: unimplemented for unary operator ~a" op))])] 34 | 35 | [(is-a? ast BinExp%) 36 | (define op (get-field op (get-field op ast))) 37 | (define e1 (send (get-field e1 ast) accept this)) 38 | (define e2 (send (get-field e2 ast) accept this)) 39 | 40 | (cond 41 | [(equal? op "+") (+ e1 e2)] 42 | [(equal? op "-") (- e1 e2)] 43 | [(equal? op "*") (* e1 e2)] 44 | [(equal? op ">>") (arithmetic-shift e1 (- 0 e2))] 45 | [(equal? op "<<") (arithmetic-shift e1 e2)] 46 | [(equal? op "&") (bitwise-and e1 e2)] 47 | [(equal? op "|") (bitwise-ior e1 e2)] 48 | [(equal? op "^") (bitwise-xor e1 e2)] 49 | [else 50 | (raise (format "visitor-lowerbound: unimplemented for binary operator ~a" op))])] 51 | 52 | [(is-a? ast FuncCall%) 53 | 0] 54 | 55 | [else 56 | (raise (format "visitor-lowerbound: unimplemented for ~a" ast))])))) 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/visitor-postunroll.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "header.rkt" 4 | "ast.rkt" "ast-util.rkt" "visitor-interface.rkt" 5 | "visitor-expr-interpreter.rkt") 6 | 7 | (provide (all-defined-out)) 8 | 9 | (define post-unroller% 10 | (class* object% (visitor<%>) 11 | (super-new) 12 | (define functions (set "main")) 13 | (define arrays (make-hash)) 14 | (define env (make-hash)) 15 | 16 | (define debug #t) 17 | 18 | (define (push-scope) 19 | ;(pretty-display `(push-scope)) 20 | (let ([new-env (make-hash)]) 21 | (dict-set! new-env "__up__" env) 22 | (set! env new-env))) 23 | 24 | (define (pop-scope) 25 | ;(pretty-display `(pop-scope)) 26 | (set! env (dict-ref env "__up__"))) 27 | 28 | (define/public (visit ast) 29 | (cond 30 | [(is-a? ast ArrayDecl%) 31 | (when debug 32 | (pretty-display (format "POSTUNROLL: ArrayDecl ~a" (get-field var ast)))) 33 | ;; only construct ghost region when it is not initialized. 34 | (when (and (get-field ghost ast) (empty? (get-field ghost ast))) 35 | (when debug (pretty-display "DECLARE!")) 36 | (hash-set! arrays (get-field var ast) ast))] 37 | 38 | [(is-a? ast Array%) 39 | (when debug 40 | (pretty-display (format "POSTUNROLL: Array ~a" (send ast to-string)))) 41 | (when (and (get-field ghost ast) (hash-has-key? arrays (get-field name ast))) 42 | (when debug (pretty-display "GHOST!")) 43 | (define range (send (get-field index ast) 44 | accept (new expr-interpreter% [env env]))) 45 | (define decl (hash-ref arrays (get-field name ast))) 46 | (send decl add-ghost-region range (get-field place-type ast)))] 47 | 48 | [(is-a? ast UnaExp%) 49 | (send (get-field e1 ast) accept this)] 50 | 51 | [(is-a? ast BinExp%) 52 | (send (get-field e1 ast) accept this) 53 | (send (get-field e2 ast) accept this)] 54 | 55 | [(is-a? ast FuncCall%) 56 | (set! functions (set-add functions (get-field name ast))) 57 | (for ([arg (get-field args ast)]) 58 | (send arg accept this))] 59 | 60 | [(is-a? ast For%) 61 | (push-scope) 62 | (declare env 63 | (get-field name (get-field iter ast)) 64 | (cons (get-field from ast) (sub1 (get-field to ast)))) 65 | (send (get-field body ast) accept this) 66 | (pop-scope) 67 | ] 68 | 69 | [(is-a? ast If%) 70 | (send (get-field condition ast) accept this) 71 | (send (get-field true-block ast) accept this) 72 | (when (get-field false-block ast) 73 | (send (get-field false-block ast) accept this))] 74 | 75 | [(is-a? ast While%) 76 | (send (get-field condition ast) accept this) 77 | (send (get-field body ast) accept this)] 78 | 79 | [(is-a? ast Assign%) 80 | (send (get-field lhs ast) accept this) 81 | (send (get-field rhs ast) accept this)] 82 | 83 | [(is-a? ast Return%) 84 | (define val (get-field val ast)) 85 | (if (list? val) 86 | (for ([v val]) 87 | (send v accept this)) 88 | (send val accept this))] 89 | 90 | [(is-a? ast FuncDecl%) 91 | (send (get-field body ast) accept this)] 92 | 93 | [(is-a? ast Block%) 94 | (for ([stmt (get-field stmts ast)]) 95 | (send stmt accept this)) 96 | 97 | (when (is-a? ast Program%) 98 | (set-field! 99 | stmts ast 100 | (filter (lambda (x) 101 | (or (not (is-a? x FuncDecl%)) 102 | (set-member? functions (get-field name x)))) 103 | (get-field stmts ast)))) 104 | ] 105 | 106 | [else void])))) 107 | -------------------------------------------------------------------------------- /src/visitor-tempremove.rkt: -------------------------------------------------------------------------------- 1 | #lang racket 2 | 3 | (require "header.rkt" 4 | "ast.rkt" 5 | "ast-util.rkt" 6 | "visitor-interface.rkt") 7 | 8 | (provide (all-defined-out)) 9 | 10 | (define temp-remover% 11 | (class* object% (visitor<%>) 12 | (super-new) 13 | (define removed (list)) 14 | (define debug #f) 15 | 16 | (define/public (visit ast) 17 | (cond 18 | [(is-a? ast If%) 19 | (send (get-field true-block ast) accept this) 20 | (when (get-field false-block ast) 21 | (send (get-field false-block ast) accept this))] 22 | 23 | [(is-a? ast While%) 24 | (send (get-field pre ast) accept this) 25 | (send (get-field body ast) accept this)] 26 | 27 | [(is-a? ast For%) 28 | (send (get-field body ast) accept this)] 29 | 30 | [(is-a? ast Block%) 31 | (define (remove-temp lst) 32 | ;(pretty-display `(remove-temp ,lst)) 33 | (if (empty? lst) 34 | lst 35 | (let* ([rest (remove-temp (cdr lst))] 36 | [me (car lst)] 37 | [next (and (not (empty? rest)) (car rest))]) 38 | (if (and next (is-a? me Assign%) (is-a? next Assign%)) 39 | (let ([def (get-field lhs me)] 40 | [use (get-field rhs next)]) 41 | (begin 42 | (when debug 43 | (pretty-display `(remove-temp ,(send def to-string) ,(send use to-string)))) 44 | (if (and (is-a? def Temp%) (is-a? use Temp%) 45 | (equal? (get-field name def) (get-field name use)) 46 | (equal? (get-field sub def) (get-field sub use))) 47 | (begin 48 | (when debug (pretty-display "REMOVE!")) 49 | (set! removed (cons (get-field name def) removed)) 50 | (cons (new Assign% [lhs (get-field lhs next)] [rhs (get-field rhs me)]) 51 | (cdr rest))) 52 | (cons me rest)))) 53 | (cons me rest))))) 54 | 55 | (for ([stmt (get-field stmts ast)]) 56 | (send stmt accept this)) 57 | (set-field! stmts ast (remove-temp (get-field stmts ast)))] 58 | 59 | [(is-a? ast FuncDecl%) 60 | (set! removed (list)) 61 | (define body (get-field body ast)) 62 | ;; Remove unnecesssy temps in the body. 63 | (send (get-field body ast) accept this) 64 | ;; Remove declarations associated to those temps. 65 | (set-field! stmts body 66 | (filter (lambda (x) 67 | (not (and (is-a? x VarDecl%) 68 | (not (pair? (get-field type x))) ;; not tuple type 69 | (member (car (get-field var-list x)) removed)))) 70 | (get-field stmts body))) 71 | ] 72 | 73 | )))) 74 | 75 | 76 | -------------------------------------------------------------------------------- /testdata/1: -------------------------------------------------------------------------------- 1 | 100 2 | 3 | -------------------------------------------------------------------------------- /testdata/10: -------------------------------------------------------------------------------- 1 | 22 45 96 15 93 70 25 58 72 94 2 | -------------------------------------------------------------------------------- /testdata/136: -------------------------------------------------------------------------------- 1 | 4 8 3 10 2 8 8 7 6 8 6 0 10 7 10 2 10 5 6 3 5 4 8 9 8 4 5 4 4 10 1 5 4 10 5 5 0 1 10 8 0 8 3 5 4 1 2 7 8 6 1 1 9 9 2 8 0 4 3 8 6 4 5 7 1 10 4 7 9 8 9 10 6 2 8 5 10 7 8 2 10 0 3 7 0 8 4 8 1 6 7 5 1 2 2 1 1 5 4 8 0 5 2 10 0 10 1 5 10 8 0 0 4 5 8 9 4 1 0 10 8 0 4 4 1 8 6 0 10 7 3 4 7 2 4 7 2 | -------------------------------------------------------------------------------- /testdata/2: -------------------------------------------------------------------------------- 1 | 0 2 | 10000 3 | -------------------------------------------------------------------------------- /testdata/200: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 9 10 2 | 1 1 1 1 1 1 1 1 1 1 3 | 1 2 3 4 5 6 7 8 9 10 4 | 1 1 1 1 1 1 1 1 1 1 5 | 1 2 3 4 5 6 7 8 9 10 6 | 1 1 1 1 1 1 1 1 1 1 7 | 1 2 3 4 5 6 7 8 9 10 8 | 1 1 1 1 1 1 1 1 1 1 9 | 1 2 3 4 5 6 7 8 9 10 10 | 1 1 1 1 1 1 1 1 1 1 11 | 12 | 1 1 1 1 1 1 1 1 1 1 13 | 1 1 1 1 1 1 1 1 1 1 14 | 1 1 1 1 1 1 1 1 1 1 15 | 1 1 1 1 1 1 1 1 1 1 16 | 1 1 1 1 1 1 1 1 1 1 17 | 1 1 1 1 1 1 1 1 1 1 18 | 1 1 1 1 1 1 1 1 1 1 19 | 1 1 1 1 1 1 1 1 1 1 20 | 1 1 1 1 1 1 1 1 1 1 21 | 1 1 1 1 1 1 1 1 1 1 22 | 23 | -------------------------------------------------------------------------------- /testdata/232: -------------------------------------------------------------------------------- 1 | 10 3 4 10 8 10 1 8 5 9 7 10 0 4 1 10 10 6 0 4 9 1 0 9 9 7 5 2 5 2 7 2 4 2 2 6 10 8 0 8 9 6 10 8 1 8 4 8 3 4 8 4 8 6 7 7 10 4 3 4 4 1 5 5 2 3 5 2 2 5 0 10 6 5 1 10 9 5 0 8 10 9 4 5 10 3 7 4 10 5 10 1 3 2 2 0 0 1 10 9 6 9 1 1 2 2 5 7 7 7 2 9 6 4 9 6 2 1 9 3 8 7 7 6 8 3 9 1 2 0 10 0 10 0 9 10 2 1 1 2 10 1 2 5 5 4 6 3 8 2 8 0 3 9 7 0 3 4 3 4 6 3 10 6 1 6 1 10 3 2 5 2 10 9 10 3 6 1 2 0 8 2 1 4 5 10 7 0 0 3 10 10 0 8 4 1 6 4 10 1 4 0 9 2 2 4 8 5 3 7 10 6 1 1 7 6 1 3 2 8 4 7 9 9 8 8 6 2 8 6 0 6 2 | -------------------------------------------------------------------------------- /testdata/4_1: -------------------------------------------------------------------------------- 1 | 1 2 3 4 2 | 3 | 4 | -------------------------------------------------------------------------------- /testdata/4_2: -------------------------------------------------------------------------------- 1 | 4 6 19 53 2 | 3 | -------------------------------------------------------------------------------- /testdata/72: -------------------------------------------------------------------------------- 1 | 6 5 7 6 10 5 0 6 9 4 7 10 8 2 8 9 2 8 8 9 5 6 8 9 2 6 9 5 0 0 1 6 0 4 0 8 9 0 9 3 3 9 0 0 8 10 6 6 4 10 5 9 1 4 5 0 2 4 10 3 9 5 6 0 9 1 10 3 8 10 5 6 2 | -------------------------------------------------------------------------------- /testdata/gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import random, sys 4 | 5 | if __name__ == "__main__": 6 | n = int(sys.argv[1]) 7 | min = 0 8 | max = int(sys.argv[2]) 9 | 10 | if max < 0: 11 | min = max 12 | max = -max 13 | 14 | delim = False 15 | if len(sys.argv) > 3: 16 | delim = sys.argv[3] 17 | # for i in xrange(n): 18 | # sys.stdout.write(str(random.randint(0,max))) 19 | # sys.stdout.write(' ') 20 | # sys.stdout.write('\n') 21 | 22 | for i in xrange(n): 23 | print random.randint(min,max), 24 | if delim: 25 | print delim, 26 | print "" 27 | -------------------------------------------------------------------------------- /testdata/md5: -------------------------------------------------------------------------------- 1 | 42104 55146 2 | 46934 59591 3 | 28891 9248 4 | 52974 49597 5 | 4015 62844 6 | 50730 18311 7 | 17939 43056 8 | 38145 64838 9 | 39128 27008 10 | 63407 35652 11 | 23473 65535 12 | 55230 35164 13 | 4386 27536 14 | 29075 64920 15 | 17294 42617 16 | 2081 18868 17 | 9570 63006 18 | 45888 49216 19 | 23121 9822 20 | 51114 59830 21 | 4189 54831 22 | 5203 580 23 | 59009 55457 24 | 64456 59347 25 | 52710 8673 26 | 2006 49975 27 | 3463 62677 28 | 5357 17754 29 | 59653 43491 30 | 41976 64751 31 | 729 26479 32 | 19594 36138 33 | 14658 65530 34 | 63105 34673 35 | 24866 28061 36 | 14348 64997 37 | 59972 42174 38 | 53161 19422 39 | 19296 63163 40 | 48240 48831 41 | 32454 10395 42 | 10234 60065 43 | 12421 54511 44 | 7429 1160 45 | 53305 55764 46 | 39397 59099 47 | 31992 8098 48 | 22117 50348 49 | 8772 62505 50 | 65431 17194 51 | 9127 43924 52 | 41017 64659 53 | 22979 25947 54 | 52370 36620 55 | 62589 65519 56 | 24017 34180 57 | 32335 28584 58 | 59104 65068 59 | 17172 41729 60 | 4513 19976 61 | 32386 63315 62 | 62005 48442 63 | 53947 10967 64 | 54161 60294 65 | 66 | 7 67 | 12 68 | 17 69 | 22 70 | 7 71 | 12 72 | 17 73 | 22 74 | 7 75 | 12 76 | 17 77 | 22 78 | 7 79 | 12 80 | 17 81 | 22 82 | 5 83 | 9 84 | 14 85 | 20 86 | 5 87 | 9 88 | 14 89 | 20 90 | 5 91 | 9 92 | 14 93 | 20 94 | 5 95 | 9 96 | 14 97 | 20 98 | 4 99 | 11 100 | 16 101 | 23 102 | 4 103 | 11 104 | 16 105 | 23 106 | 4 107 | 11 108 | 16 109 | 23 110 | 4 111 | 11 112 | 16 113 | 23 114 | 6 115 | 10 116 | 15 117 | 21 118 | 6 119 | 10 120 | 15 121 | 21 122 | 6 123 | 10 124 | 15 125 | 21 126 | 6 127 | 10 128 | 15 129 | 21 130 | 131 | 8961 26437 132 | 43913 61389 133 | 56574 39098 134 | 21622 4146 135 | 0 0 136 | 1 0 137 | 2 0 138 | 3 0 139 | 4 0 140 | 5 0 141 | 6 0 142 | 7 0 143 | 8 0 144 | 9 0 145 | 10 0 146 | 11 0 147 | 12 0 148 | 13 0 149 | 14 0 150 | 15 0 151 | -------------------------------------------------------------------------------- /testdata/null: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mangpo/chlorophyll/ab6d4268c5d12aa66eff817c678aaf7ebf935ba7/testdata/null -------------------------------------------------------------------------------- /testdata/out/add_200.out: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 4 4 | 5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 2 12 | 2 13 | 2 14 | 2 15 | 2 16 | 2 17 | 2 18 | 2 19 | 2 20 | 2 21 | 2 22 | 3 23 | 4 24 | 5 25 | 6 26 | 7 27 | 8 28 | 9 29 | 10 30 | 11 31 | 2 32 | 2 33 | 2 34 | 2 35 | 2 36 | 2 37 | 2 38 | 2 39 | 2 40 | 2 41 | 2 42 | 3 43 | 4 44 | 5 45 | 6 46 | 7 47 | 8 48 | 9 49 | 10 50 | 11 51 | 2 52 | 2 53 | 2 54 | 2 55 | 2 56 | 2 57 | 2 58 | 2 59 | 2 60 | 2 61 | 2 62 | 3 63 | 4 64 | 5 65 | 6 66 | 7 67 | 8 68 | 9 69 | 10 70 | 11 71 | 2 72 | 2 73 | 2 74 | 2 75 | 2 76 | 2 77 | 2 78 | 2 79 | 2 80 | 2 81 | 2 82 | 3 83 | 4 84 | 5 85 | 6 86 | 7 87 | 8 88 | 9 89 | 10 90 | 11 91 | 2 92 | 2 93 | 2 94 | 2 95 | 2 96 | 2 97 | 2 98 | 2 99 | 2 100 | 2 101 | -------------------------------------------------------------------------------- /testdata/out/if_4_1.out: -------------------------------------------------------------------------------- 1 | 1 2 | 5 3 | -------------------------------------------------------------------------------- /tests/add-pair.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int::2@{[0:25],[25:50]} x[50]; 3 | int::2@{[0:25],[25:50]} y[50]; 4 | int::2@{[0:25],[25:50]} z[50]; 5 | 6 | for(i from 0 to 50) { 7 | z[i] = x[i] +@place(z[i]) y[i]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/add.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:25]=0,[25:50]=2,[50:75]=3,[75:100]=4} x[100]; 3 | int@{[0:25],[25:50],[50:75],[75:100]} y[100]; 4 | int@{[0:25],[25:50],[50:75],[75:100]} z[100]; 5 | 6 | for(i from 0 to 100) { 7 | z[i] = x[i] +@place(z[i]) y[i]; 8 | //z[i] = x[i] +@place(i) y[i]; //can't do place(i) when we don't know i 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/for-array-fancy.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int[]@{[0:10],[10:20]} x[20]; 3 | int[]@{[0:5],[5:10]} y[10]; 4 | 5 | for(i from 0 to 10)@{[0:5],[5:10]} { 6 | x[i] = x[2*i] + x[2*i+1] + y[i]; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/for-array-fancy2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int[]@{[0:20]=0,[20:40]=1} x[40]; 3 | int[]@{[0:20]=0,[20:40]=1} y[40]; 4 | 5 | for(i from 0 to 40)@{[0:20]=0,[20:40]=1} { 6 | for(j from 0 to 40)@{[0:20]=0,[20:40]=1} { 7 | x[i] = x[i] +@place(i) y[j]; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/for-array1.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:20]=0,[20:40]=1} x[40]; 3 | int@{[0:20]=0,[20:40]=1} y[40]; 4 | for(i from 0 to 40)@{[0:20]=0,[20:40]=1} { 5 | x[i] = 0; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/for-array2.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:20]=1, [20:40]=0} x[40]; 3 | int@{[0:20]=1, [20:40]=0} y[40]; 4 | 5 | for(i from 0 to 40)@{[0:20]=1, [20:40]=0} { 6 | x[i] = (x[i] +@{[0:20], [20:40];i} y[i]); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /tests/for-array3.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:20],[20:40]} x[40]; 3 | int@{[0:20],[20:40]} y[40]; 4 | 5 | for(i from 0 to 40)@{[0:20],[20:40]} { 6 | x[i] = x[i] +@place(x[i]) y[i]; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/for-array4.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:20]=0,[20:40]=1} x[40]; 3 | int@{[0:20]=0,[20:40]=0} y[40]; 4 | 5 | for(i from 0 to 40) { 6 | x[i] = x[i] + y[i]; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/for-array5.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@{[0:10]} x[10]; 3 | cluster int@0 y[10]; 4 | 5 | for(i from 0 to 10)@0 { 6 | x[i] = y[x[i]] + i; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/function.cll: -------------------------------------------------------------------------------- 1 | int abs(int x) { 2 | if(x < 0) { 3 | return -x; 4 | } else { 5 | return x; 6 | } 7 | } 8 | 9 | int square_distance(int x, int y) { 10 | return (x - y) * (x - y); 11 | } 12 | 13 | int main() { 14 | int@0 x; 15 | int@1 y; 16 | return abs(x) + abs(y) * square_distance(x,y); 17 | } 18 | -------------------------------------------------------------------------------- /tests/function2.cll: -------------------------------------------------------------------------------- 1 | int@2 sum(int@1 a,int@1 b,int@2 c,int@2 d) { 2 | return a +@1 b +@2 c +@2 d; 3 | } 4 | 5 | void main() { 6 | int@1 a; 7 | int@1 b; 8 | int@2 c; 9 | int@2 d; 10 | int@0 ret; 11 | ret = sum(a,b,sum(a,b,c,d),sum(a,b,c,d)); 12 | } 13 | -------------------------------------------------------------------------------- /tests/if_concrete.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 x; 3 | int@0 y; 4 | int@0 z; 5 | int@0 j; 6 | 7 | if(j %@0 2 ==@0 0) { 8 | x = x +@0 y; 9 | } else { 10 | z = y +@0 z; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/if_symbolic.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@0 x; 3 | int y; 4 | int z; 5 | int j; 6 | 7 | if(j % 2 == 0) { 8 | x = x + y; 9 | } else { 10 | z = y + z; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/space_concrete.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@1 x; 3 | int@1 y; 4 | int@1 z; 5 | 6 | for(i from 0 to 4) { 7 | x = x +@1 y +@1 z; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/space_symbolic.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@1 x; 3 | int y; 4 | int z; 5 | 6 | for(i from 0 to 4) { 7 | x = x + y + z; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/while.cll: -------------------------------------------------------------------------------- 1 | void main() { 2 | int@1 i, j; 3 | i = 0; 4 | 5 | while(i <@1 10) { 6 | j = 0; 7 | while(j <= i) { 8 | j = j + 1; 9 | } 10 | i = i+@2 1; 11 | } 12 | } 13 | --------------------------------------------------------------------------------