Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
robertylewis authored Dec 5, 2024
2 parents 896c244 + 985b69d commit 197a14c
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 68 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
uses: actions/checkout@v4
with:
path: 'hw/benchmarks'
ref: ${{ github.event.pull_request.merge_commit_sha }}
ref: ${{ github.event.pull_request.head.sha }}
- name: echo commit
run: echo "sha is ${{ github.event.pull_request.head.sha }}"
- name: Run benchmarks
working-directory: 'hw/benchmarks'
run: chmod -R 1777 ../ && su - cs1260_user -c "cd $(pwd) && eval \$(opam env) && python3 bench.py --repeat 1"
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/benchmark_1.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(define (f x) (- 15 (+ x (+ 8 (- x 2)))))

(print (let ((x 4)) (f x)))
5 changes: 5 additions & 0 deletions benchmarks/benchmark_2.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(define (cube x)
(+ x (+ x x)))

(do (print (let ((x (read-num)))
(+ (let ((y (+ 3 5))) (cube x)) 1))))
1 change: 1 addition & 0 deletions benchmarks/benchmark_3.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(print (if (< (+ 9 8) (+ 3 7)) (+ 6 (+ 9 17)) (+ 13 (- 9 2))))
67 changes: 0 additions & 67 deletions benchmarks/inline-test.lisp

This file was deleted.

3 changes: 3 additions & 0 deletions benchmarks/lchoi-inline.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(define (f x) (+ x x))
(define (g y) (+ (f y) (f y)))
(print (+ (g 2) (g 2)))
4 changes: 4 additions & 0 deletions benchmarks/lchoi-prop.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(let ((x (- 5 4)))
(let ((y (+ x 4)))
(let ((z (+ x y)))
(print (+ x (+ y z))))))
4 changes: 4 additions & 0 deletions benchmarks/lchoi-unroll.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(define (leftshift num bits)
(if (< bits 1) num (+ (leftshift num (- bits 1)) (leftshift num (- bits 1)))))

(print (leftshift 1 11))
12 changes: 12 additions & 0 deletions benchmarks/sum_list.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(define (sum lst)
(if (empty? lst)
0
(+ (left lst) (sum (right lst)))
)
)

(let ((lst (pair 1 (pair 2 (pair 3 (pair 4 ()))))))
(do
(print (sum lst))
)
)
21 changes: 21 additions & 0 deletions benchmarks/sum_of_squares.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(define (square x)
(if (= x 0)
0
(+ x (square (- x 1)))
)
)

(define (sum-of-squares n)
(if (= n 0)
0
(+ (square n) (sum-of-squares (- n 1)))
)
)

(do
(print (sum-of-squares 0))
(newline)
(print (sum-of-squares 5))
(newline)
(print (sum-of-squares 10))
)
23 changes: 23 additions & 0 deletions benchmarks/unsorted_list_search.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(define (search list target)
(if (empty? list)
false
(if (= (left list) target)
0
(let ((index (search (right list) target)))
(if index
(+ 1 index)
false )
)
)
)
)

(let ((lst (pair 1 (pair 2 (pair 3 (pair 4 ()))))))
(do
(print (search lst 1))
(newline)
(print (search lst 0))
(newline)
(print (search lst 4))
)
)
37 changes: 37 additions & 0 deletions benchmarks/whulse-both.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(define (c0) 0)
(define (c1) 1)
(define (c2) 2)
(define (c3) 3)
(define (c4) 4)
(define (c5) 5)
(define (c6) 6)
(define (c7) 7)
(define (c8) 8)
(define (c9) 9)
(define (c10) 10)

(define (add-c1-c2) (+ (c1) (c2)))
(define (add-c3-c4) (+ (c3) (c4)))
(define (add-c5-c6) (+ (c5) (c6)))

(define (sum1) (+ (add-c1-c2) (add-c3-c4)))
(define (sum2) (+ (sum1) (add-c5-c6)))
(define (total-sum) (+ (sum2) (c7)))

(define (funcA) (+ (c1) (c2)))
(define (funcB) (+ (funcA) (c3)))
(define (funcC) (+ (funcB) (c4)))
(define (funcD) (+ (funcC) (funcA)))
(define (funcE) (+ (funcD) (funcC)))
(define (funcF) (+ (funcE) (funcD)))

(let ((v1 (funcF)))
(let ((v2 (if (= v1 30) false true)))
(if v2
(let ((v3 (funcE)))
(let ((v4 (+ v3 v1)))
(let ((v5 (- v4 (c5))))
(if (= v5 54)
(print v5)
(print 0)))))
(print 0))))
13 changes: 13 additions & 0 deletions benchmarks/whulse-constant-prop.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(define (decrement x)
(sub1 x))

(define (add y z)
(+ y z))

(define (fib n)
(if (< n 2)
n
(add (fib (decrement n)) (fib (decrement (decrement n))))))

(let ((result (fib 30)))
(print result))
25 changes: 25 additions & 0 deletions benchmarks/whulse-inlining.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(define (increment x)
(add1 x))

(define (computesum n)
(if (= n 0)
0
(+ (increment n) (computesum (sub1 n)))))

(define (computeaccumulate n)
(if (= n 0)
0
(+ (increment n) (computeaccumulate (sub1 n)))))

(define (computedoublesum n)
(if (= n 0)
0
(+ (+ (increment n) (increment n)) (computedoublesum (sub1 n)))))

(let ((resultsum (computesum 1000)))
(let ((resultaccumulate (computeaccumulate 1000)))
(let ((resultdoublesum (computedoublesum 1000)))
(print (+ resultsum (+ resultaccumulate resultdoublesum)))
)
)
)

0 comments on commit 197a14c

Please sign in to comment.