Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aysylu
committed
May 19, 2013
1 parent
e6702ad
commit 36b0c46
Showing
2 changed files
with
103 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,104 @@ | ||
(ns piplin.test.mips | ||
(:use [piplin.types | ||
[binops :only [=]]]) | ||
(:refer-clojure :as clj :exclude [not= bit-or bit-xor + - * bit-and inc dec bit-not < > <= >= = cast not cond condp and or bit-shift-right bit-shift-left pos? neg? zero?]) | ||
(:use piplin.core) | ||
(:use [piplin.mips]) | ||
(:use [clojure.test]) | ||
(:refer-clojure :as clj :exclude [=])) | ||
(:use [piplin.types.union :only [get-tag get-value]]) | ||
(:use [clojure.test])) | ||
|
||
(deftest decode-add-imm | ||
(let [decoded (decode #b001001_00001_00010_1000_0000_0000_0000)] | ||
(is (= (get decoded :op) | ||
(alu-op :add))) | ||
(is (= (get decoded :y) | ||
(reg-or-imm | ||
{:imm (u32m 32768)}))) | ||
(is (= (get decoded :x) | ||
(reg-or-imm | ||
{:reg (reg :23)}))) | ||
(is (= (get decoded :dst) | ||
(reg :22))))) | ||
(let [decoded (decode #b001001_00001_00010_1000_0000_0000_0000) | ||
add (get-value :addiu decoded)] | ||
(is (= (get-tag decoded) | ||
:addiu)) | ||
(is (= (get add :imm) | ||
(cast simm 32768))) | ||
(is (= (get add :rsrc) | ||
:r17)) | ||
(is (= (get add :rdst) | ||
:r15)))) | ||
|
||
(deftest sext-test | ||
(is (= (sext32 #b0001) #b00000000_00000000_00000000_0000_0001)) | ||
(is (= (sext32 #b1000) #b11111111_11111111_11111111_1111_1000))) | ||
|
||
(deftest zext-test | ||
(is (= (zext32 #b0001) #b00000000_00000000_00000000_0000_0001)) | ||
(is (= (zext32 #b1000) #b00000000_00000000_00000000_0000_1000))) | ||
|
||
(deftest sra-test | ||
;; shift by 7 without sign bit | ||
(is (= (sra #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000111) | ||
#b00000000_00000000_00000001_00000000)) | ||
|
||
;; shift by 7 with sign bit | ||
(is (= (sra #b10000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000111) | ||
#b11111111_00000000_00000001_00000000)) | ||
|
||
;; shift by 0 | ||
(is (= (sra #b10000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000000) | ||
#b10000000_00000000_10000000_00000000)) | ||
|
||
;; shift by 31 without sign bit | ||
(is (= (sra #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00011111) | ||
#b00000000_00000000_00000000_00000000)) | ||
|
||
;; shift by 31 with sign bit | ||
(is (= (sra #b10000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00011111) | ||
#b11111111_11111111_11111111_11111111)) | ||
|
||
;; shift by 32 without sign bit | ||
(is (= (sra #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00100000) | ||
#b00000000_00000000_00000000_00000000)) | ||
|
||
;; shift by 32 with sign bit | ||
(is (= (sra #b10000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00100000) | ||
#b11111111_11111111_11111111_11111111))) | ||
|
||
(deftest srl-test | ||
;; shift by 7 | ||
(is (= (srl #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000111) | ||
#b00000000_00000000_00000001_00000000)) | ||
|
||
;; shift by 0 | ||
(is (= (srl #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000000) | ||
#b00000000_00000000_10000000_00000000)) | ||
|
||
;; shift by 31 | ||
(is (= (srl #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00011111) | ||
#b00000000_00000000_00000000_00000000)) | ||
|
||
;; shift by 63 | ||
(is (= (srl #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00111111) | ||
#b00000000_00000000_00000000_00000000))) | ||
|
||
(deftest sll-test | ||
;; shift by 7 | ||
(is (= (sll #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000111) | ||
#b00000000_01000000_00000000_00000000)) | ||
|
||
;; shift by 0 | ||
(is (= (sll #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00000000) | ||
#b00000000_00000000_10000000_00000000)) | ||
|
||
;; shift by 31 | ||
(is (= (sll #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00011111) | ||
#b00000000_00000000_00000000_00000000)) | ||
|
||
;; shift by 63 | ||
(is (= (sll #b00000000_00000000_10000000_00000000 | ||
#b00000000_00000000_00000000_00111111) | ||
#b00000000_00000000_00000000_00000000))) |