[44] | 1 | exception Byte7_conversion |
---|

[28] | 2 | |
---|

| 3 | module Byte7Map = |
---|

| 4 | Map.Make (struct type t = byte7 let compare = Pervasives.compare end) |
---|

| 5 | module WordMap = |
---|

| 6 | Map.Make (struct type t = word let compare = Pervasives.compare end) |
---|

| 7 | |
---|

[91] | 8 | let int_of_bit = |
---|

| 9 | function |
---|

| 10 | false -> 0 |
---|

| 11 | | true -> 1 |
---|

[28] | 12 | |
---|

[91] | 13 | let byte7_of_byte b = |
---|

[97] | 14 | let n1,n2 = from_byte b in |
---|

| 15 | match from_nibble n1 with |
---|

| 16 | (false,b1,b2,b3) -> mk_byte7 b1 b2 b3 n2 |
---|

[91] | 17 | | _ -> raise Byte7_conversion |
---|

| 18 | |
---|

[92] | 19 | let add8_with_c (b1 : [`Eight] vect) (b2 : [`Eight] vect) (c : bit) = |
---|

[90] | 20 | let n1 = int_of_vect b1 in |
---|

| 21 | let n2 = int_of_vect b2 in |
---|

[92] | 22 | let c = int_of_bit c in |
---|

[28] | 23 | let res = n1 + n2 + c in |
---|

| 24 | let ac = n1 mod 16 + n2 mod 16 + c >= 16 in |
---|

| 25 | let c6 = n1 mod 128 + n2 mod 128 + c >= 128 in |
---|

| 26 | let res,c = res mod 256, res >= 256 in |
---|

| 27 | let ov = c <> c6 in |
---|

[92] | 28 | vect_of_int res `Eight,c,ac,ov |
---|

[28] | 29 | ;; |
---|

| 30 | |
---|

[91] | 31 | let subb8_with_c (b1 : [`Eight] vect) (b2 : [`Eight] vect) (c : bit) = |
---|

[90] | 32 | let n1 = int_of_vect b1 in |
---|

| 33 | let n2 = int_of_vect b2 in |
---|

[91] | 34 | let c = int_of_bit c in |
---|

[28] | 35 | let res = n1 - n2 - c in |
---|

| 36 | let ac = n1 mod 16 - n2 mod 16 - c < 0 in |
---|

| 37 | let c6 = n1 mod 128 - n2 mod 128 - c < 0 in |
---|

| 38 | let res,c = |
---|

| 39 | if res >= 0 then res,false |
---|

| 40 | else n1 + 256 - n2 - c, true in |
---|

| 41 | let ov = c <> c6 in |
---|

[90] | 42 | (vect_of_int res `Eight,c,ac,ov) |
---|

[28] | 43 | ;; |
---|

| 44 | |
---|

| 45 | let dec b = |
---|

[90] | 46 | let res = int_of_vect b - 1 in |
---|

| 47 | if res < 0 then vect_of_int 255 `Eight |
---|

| 48 | else vect_of_int res `Eight |
---|

[28] | 49 | ;; |
---|

| 50 | |
---|

| 51 | let inc b = |
---|

[90] | 52 | let res = int_of_vect b + 1 in |
---|

[92] | 53 | if res > 255 then (vect_of_int 0 `Eight : byte) |
---|

| 54 | else (vect_of_int res `Eight : byte) |
---|

[28] | 55 | ;; |
---|

[41] | 56 | |
---|

[42] | 57 | let byte7_of_bit b = |
---|

[91] | 58 | [false;false;false;false;false;false;b] |
---|

[41] | 59 | ;; |
---|

[42] | 60 | |
---|

[97] | 61 | let byte_of_byte7 = |
---|

| 62 | function |
---|

| 63 | ([b1;b2;b3]::n) -> [false;b1;b2;b3]::n |
---|

| 64 | | _ -> assert false |
---|

[88] | 65 | ;; |
---|