Changeset 88
 Timestamp:
 Sep 20, 2010, 10:35:53 AM (9 years ago)
 Location:
 Deliverables/D4.1
 Files:

 4 edited
 2 moved
Legend:
 Unmodified
 Added
 Removed

Deliverables/D4.1/BitVectors.ml
r87 r88 63 63 let half_add l r = full_add l r false 64 64 65 let rec split_last = function [] > assert false  [he] > he,[]  he::tl > let l,res = split_last tl in l,he::res 65 let rec split_last = 66 function 67 [] > assert false 68  [he] > he,[] 69  he::tl > 70 let l,res = split_last tl in 71 l,he::res 66 72 67 let shift_left = function [] > assert false  _::tl > tl @ [false] 73 let shift_left = 74 function 75 [] > assert false 76  _::tl > tl @ [false] 68 77 let shift_right l = false :: snd (split_last l) 69 let rotate_left = function [] > assert false  he::tl > tl @ [he] 70 let rotate_right l = let he,tl = split_last l in he::tl 78 let rotate_left = 79 function 80 [] > assert false 81  he::tl > tl @ [he] 82 let rotate_right l = 83 let he,tl = split_last l in 84 he::tl 85 86 let int_of_vect v = 87 let rec aux pow v = 88 match v with 89 [] > 0 90  hd::tl > 91 if hd = true then 92 pow + (aux (pow * 2) tl) 93 else 94 aux (pow * 2) tl 95 in 96 aux 1 (List.rev v) 
Deliverables/D4.1/BitVectors.mli
r87 r88 24 24 val set_bit: 'a vect > int > bit > 'a vect option 25 25 26 val int_of_vect: 'a vect > int 27 val vect_of_int: int > 'a > 'a vect 28 26 29 val (&): 'a vect > 'a vect > 'a vect 27 30 val (): 'a vect > 'a vect > 'a vect 
Deliverables/D4.1/Byte.ml
r86 r88 61 61 type bit = Bit.bit 62 62 type nibble = Nibble.nibble 63 type byte = nibble * nibble 63 type byte = nibble * nibble(l & r)  (c & (l ^ r) 64 64 65 65 let from_bits b1 b2 b3 b4 b5 b6 b7 b8 = … … 138 138 let to_int (n1, n2) = 139 139 let [b1; b2; b3; b4] = Nibble.to_bits n1 in 140 let [b5; b6; b7; b8] = Nibble.to_bits n2 in140 let [b5; b6; b7;h b8] = Nibble.to_bits n2 in 141 141 (128 * Bit.to_int b8) + (64 * Bit.to_int b8) + 142 142 (32 * Bit.to_int b8) + (16 * Bit.to_int b8) + 
Deliverables/D4.1/Nibble.ml
r86 r88 66 66  8 > Some (Bit.from_int 1, Bit.from_int 0, Bit.from_int 0, Bit.from_int 0) 67 67  9 > Some (Bit.from_int 1, Bit.from_int 0, Bit.from_int 0, Bit.from_int 1) 68  10 > Some (Bit.from_int 1, B it.from_int 0, Bit.from_int 1, Bit.from_int 0)68  10 > Some (Bit.from_int 1, B(l & r)  (c & (l ^ r)it.from_int 0, Bit.from_int 1, Bit.from_int 0) 69 69  11 > Some (Bit.from_int 1, Bit.from_int 0, Bit.from_int 1, Bit.from_int 1) 70 70  12 > Some (Bit.from_int 1, Bit.from_int 1, Bit.from_int 0, Bit.from_int 0) … … 88 88  1 > Some b3 89 89  2 > Some b2 90  3 > Some b1 90  3 > Some b1(l & r)  (c & (l ^ r) 91 91  _ > None 92 92 
Deliverables/D4.1/physical.ml
r58 r88 1 open Bit_vectors 2 1 3 exception Byte7_conversion 2 3 type bit = bool4 type nibble = bit * bit * bit * bit5 type byte = nibble * nibble6 type byte7 = bit * bit * bit * nibble7 type word = byte * byte8 type word11 = bit * bit * bit * byte9 4 10 5 module Byte7Map = … … 17 12 (false,b2,b3,b4),n > (b2,b3,b4,n) 18 13  _ > raise Byte7_conversion 19 20 let int_of_bit b = if b then 0 else 121 22 let int_of_nibble (b1,b2,b3,b4) =23 int_of_bit b4 + int_of_bit b3 * 2 + int_of_bit b2 * 4 + int_of_bit b1 * 824 25 let int_of_byte (n1,n2) = int_of_nibble n2 + int_of_nibble n1 * 1626 27 let int_of_byte7 (b1,b2,b3,n2) = int_of_nibble n2 + int_of_bit b3 * 16 +28 int_of_bit b2 * 32 + int_of_bit b1 * 6429 30 let int_of_word (b1,b2) = int_of_byte b2 + int_of_byte b1 * 25631 32 let bit_of_int n =33 if n >= 2 then assert false34 else35 if n = 0 then false36 else true37 ;;38 39 let nibble_of_int n =40 if n >= 16 then assert false41 else42 let b1 = n / 8 in43 let b2 = (n mod 8) / 4 in44 let b3 = (n mod 4) / 2 in45 let b4 = n mod 2 in46 bit_of_int b1, bit_of_int b2, bit_of_int b3, bit_of_int b447 ;;48 49 let byte_of_int n =50 if n >= 256 then assert false51 else52 let b1 = n / 16 in53 let b2 = n mod 16 in54 nibble_of_int b1, nibble_of_int b255 ;;56 57 let byte7_of_int n =58 if n >= 128 then assert false59 else60 let (_,b1,b2,b3),n = byte_of_int n in61 (b1,b2,b3,n)62 ;;63 64 let word_of_int n =65 if n >= 256 * 256 then assert false66 else67 let b1 = n / 256 in68 let b2 = n mod 256 in69 byte_of_int b1, byte_of_int b270 ;;71 72 let complement ((b1,b2,b3,b4),(b5,b6,b7,b8)) =73 (not b1,not b2,not b3,not b4),(not b5,not b6,not b7,not b8)74 75 let (++) w n = word_of_int (int_of_word w + n);;76 14 77 15 let add8_with_c b1 b2 c = … … 119 57 let byte_of_byte7 (b1,b2,b3,n) = 120 58 (false,b1,b2,b3),n 121 122 let nth_bit pos ((b1,b2,b3,b4),(b5,b6,b7,b8)) = 123 match pos with 124 0 > b1 125  1 > b2 126  2 > b3 127  3 > b4 128  4 > b5 129  5 > b6 130  6 > b7 131  7 > b8 132 133 let set_nth_bit pos v ((b1,b2,b3,b4) as n1,((b5,b6,b7,b8) as n2)) = 134 match pos with 135 0 > ((v,b2,b3,b4),n2) 136  1 > ((b1,v,b3,b4),n2) 137  2 > ((b1,b2,v,b4),n2) 138  3 > ((b1,b2,b3,v),n2) 139  4 > (n1,(v,b6,b7,b8)) 140  5 > (n1,(b5,v,b7,b8)) 141  6 > (n1,(b5,b6,v,b8)) 142  7 > (n1,(b5,b6,b7,v)) 59 ;; 
Deliverables/D4.1/physical.mli
r72 r88 1 open Bit_vectors 2 1 3 exception Byte7_conversion 2 3 type bit = bool4 type nibble = bit * bit * bit * bit5 type byte = nibble * nibble6 type byte7 = bit * bit * bit * nibble7 type word = byte * byte8 type word11 = bit * bit * bit * byte9 4 10 5 module Byte7Map : Map.S with type key = byte7 … … 13 8 val byte7_of_byte: byte > byte7 14 9 15 val word_of_int: int > word16 val int_of_word: word > int17 val byte7_of_int: int > byte718 val byte_of_int: int > byte19 val int_of_bit: bit > int20 val int_of_byte: byte > int21 val int_of_byte7: byte7 > int22 val int_of_nibble: nibble > int23 val nibble_of_int: int > nibble24 val byte7_of_bit: bit > byte725 val byte_of_byte7: byte7 > byte26 27 val complement: byte > byte28 29 val (++): word > int > word30 31 val add8_with_c:32 byte > byte > bit > byte * bit * bit * bit (* +, c, ac, ov *)33 10 val subb8_with_c: 34 11 byte > byte > bit > byte * bit * bit * bit (* , c, ac, ov *) 35 12 val dec: byte > byte (* with rollover *) 36 13 val inc: byte > byte (* with rollover *) 37 38 val nth_bit: int > byte > bit39 val set_nth_bit: int > bit > byte > byte
Note: See TracChangeset
for help on using the changeset viewer.