Browse files

Fixed bug found by new tests. Yay!

  • Loading branch information...
1 parent 59325b9 commit 8626ea7b7ac10b7a8362bdeaa4c7d66472d11418 @johnwayner committed Apr 13, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/hermit/cpu.clj
View
15 src/hermit/cpu.clj
@@ -183,13 +183,14 @@
(def ops-map {:set (fn [a b] [b nil])
:add (fn [a b] [(bit-and 0xFFFF (+ a b)) (if (> (+ a b) 0xFFFF) 1 0)])
:sub (fn [a b] [(bit-and 0xFFFF (- a b)) (if (< (- a b) 0) 1 0)])
- :mul (fn [a b] (let [p (bit-and 0xFFFF (* a b))] [(bit-and 0xFFFF p)
- (bit-and 0xFFFF (bit-shift-right p 16))]))
-
- :div (fn [a b] (let [d (bit-and 0xFFFF (int (/ a b)))] [(if (= b 0) 0 (bit-and 0xFFFF d))
- (if (= b 0)
- 0
- (bit-and 0xFFFF (/ (bit-shift-left a 16) b)))]))
+ :mul (fn [a b] (let [p (* a b)]
+ [(bit-and 0xFFFF p)
+ (bit-and 0xFFFF (bit-shift-right p 16))]))
+ :div (fn [a b] (let [d (int (/ a b))]
+ [(if (= b 0) 0 (bit-and 0xFFFF d))
+ (if (= b 0)
+ 0
+ (bit-and 0xFFFF (/ (bit-shift-left a 16) b)))]))
:mod (non-overflow-op mod)
:shl (fn [a b] [(bit-and 0xFFFF (bit-shift-left a b)) (bit-and 0xFFFF
(bit-shift-right (bit-shift-left

0 comments on commit 8626ea7

Please sign in to comment.