Changeset 86 for Deliverables/D4.1/Word11.ml
 Timestamp:
 Sep 17, 2010, 5:12:19 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D4.1/Word11.ml
r85 r86 16 16 type word11 = private (bit * bit * bit * byte) 17 17 18 val get_bit_at: int > word11 > bit option 19 val set_bit_at: int > bit > word11 > word11 option 20 21 val (&): word11 > word11 > word11 22 val (): word11 > word11 > word11 23 val (^): word11 > word11 > word11 24 (* 25 val rotate_right: word11 > word11 26 val rotate_left: word11 > word11 27 val shift_right: word11 > word11 28 val shift_left: word11 > word11 29 *) 30 val not: word11 > word11 31 32 val map_bit: (bit > bit) > word11 > word11 33 val iter_bit: (bit > string) > word11 > string 34 val zip_bit: (bit > bit > bit) > word11 > word11 > word11 35 36 val zero: word11 37 38 val half_add: word11 > word11 > (word11 * bit) 39 val full_add: (word11 * bit) > word11 > (word11 * bit) 40 18 41 val to_string: word11 > string 19 42 end;; … … 29 52 type word11 = bit * bit * bit * byte 30 53 31 let to_string (b1,b2,b3,b) = 32 Bit.to_string b1 ^ Bit.to_string b2 ^ Bit.to_string b3 ^ Byte.to_string b 54 let get_bit_at index (b1,b2,b3,b) = 55 if index < 8 then 56 Byte.get_bit_at index b 57 else 58 match index with 59 8 > Some b3 60  9 > Some b2 61  10 > Some b1 62  _ > None 63 let set_bit_at index new_val (b1,b2,b3,b) = 64 if index < 8 then 65 let nib = Byte.set_bit_at index new_val b in 66 match nib with 67 Some nib > Some (b1, b2, b3, nib) 68  None > None 69 else 70 match index with 71 8 > Some (b3, b2, new_val, b) 72  9 > Some (b3, new_val, b1, b) 73  10 > Some (new_val, b2, b1, b) 74  _ > None 75 76 let (&) (l1, l2, l3, l) (r1, r2, r3, r) = 77 (Bit.(&) l1 r1, Bit.(&) l2 r2, Bit.(&) l3 r3, Byte.(&) l r) 78 let () (l1, l2, l3, l) (r1, r2, r3, r) = 79 (Bit.() l1 r1, Bit.() l2 r2, Bit.() l3 r3, Byte.() l r) 80 let (^) (l1, l2, l3, l) (r1, r2, r3, r) = 81 (Bit.(^) l1 r1, Bit.(^) l2 r2, Bit.(^) l3 r3, Byte.(^) l r) 82 let not (b1, b2, b3, b) = (Bit.not b1, Bit.not b2, Bit.not b3, Byte.not b) 83 84 let map_bit f (b1, b2, b3, b) = 85 (f b1, f b2, f b3, Byte.map_bit f b) 86 let iter_bit f (b1, b2, b3, b) = 87 let n_bits = f b1 ^ f b2 ^ f b3 in 88 let n_byte = Byte.iter_bit f b in 89 n_bits ^ n_byte 90 let zip_bit f (l1, l2, l3, l) (r1, r2, r3, r) = 91 (f l1 r1, f l2 r2, f l3 r3, Byte.zip_bit f l r) 92 93 let zero = (Bit.zero, Bit.zero, Bit.zero, Byte.zero) 94 95 let to_string = iter_bit Bit.to_string 96 97 let half_add (l1, l2, l3, l) (r1, r2, r3, r) = 98 let (n, c) = Byte.half_add l r in 99 let (n3, c3) = Bit.full_add (l3, c) r3 in 100 let (n2, c2) = Bit.full_add (l2, c3) r2 in 101 let (n1, c1) = Bit.full_add (l1, c2) r1 in 102 ((n1, n2, n3, n), c1) 103 let full_add ((l1, l2, l3, l), c) (r1, r2, r3, r) = 104 let (n, c) = Byte.full_add (l, c) r in 105 let (n3, c3) = Bit.full_add (l3, c) r3 in 106 let (n2, c2) = Bit.full_add (l2, c3) r2 in 107 let (n1, c1) = Bit.full_add (l1, c2) r1 in 108 ((n1, n2, n3, n), c1) 109 let to_string = iter_bit Bit.to_string 33 110 end;; 34 111
Note: See TracChangeset
for help on using the changeset viewer.