Accelerated Zkey

This commit is contained in:
Anthony Scemama 2018-01-23 23:52:57 +01:00
parent e0c0ec1353
commit fdf6b02043
1 changed files with 47 additions and 42 deletions

View File

@ -137,49 +137,54 @@ let to_int_array ~kind a =
(** Transform the Zkey into an int tuple *)
let to_int_tuple ~kind a =
let open Int64 in
match kind with
| Kind_3 -> Three ( Z.to_int @@ Z.extract a 20 10 ,
Z.to_int @@ Z.extract a 10 10 ,
Z.to_int @@ Z.extract a 0 10 )
| Kind_6 -> Six ((Z.to_int @@ Z.extract a 50 10 ,
Z.to_int @@ Z.extract a 40 10 ,
Z.to_int @@ Z.extract a 30 10),
(Z.to_int @@ Z.extract a 20 10 ,
Z.to_int @@ Z.extract a 10 10 ,
Z.to_int @@ Z.extract a 0 10))
| Kind_12 -> Twelve ((Z.to_int @@ Z.extract a 114 10 ,
Z.to_int @@ Z.extract a 104 10 ,
Z.to_int @@ Z.extract a 94 10),
(Z.to_int @@ Z.extract a 84 10 ,
Z.to_int @@ Z.extract a 74 10 ,
Z.to_int @@ Z.extract a 64 10),
(Z.to_int @@ Z.extract a 50 10 ,
Z.to_int @@ Z.extract a 40 10 ,
Z.to_int @@ Z.extract a 30 10),
(Z.to_int @@ Z.extract a 20 10 ,
Z.to_int @@ Z.extract a 10 10 ,
Z.to_int @@ Z.extract a 0 10))
| Kind_9 -> Nine ((Z.to_int @@ Z.extract a 84 10 ,
Z.to_int @@ Z.extract a 74 10 ,
Z.to_int @@ Z.extract a 64 10),
(Z.to_int @@ Z.extract a 50 10 ,
Z.to_int @@ Z.extract a 40 10 ,
Z.to_int @@ Z.extract a 30 10),
(Z.to_int @@ Z.extract a 20 10 ,
Z.to_int @@ Z.extract a 10 10 ,
Z.to_int @@ Z.extract a 0 10))
| Kind_4 -> Four ((Z.to_int @@ Z.extract a 48 16 ,
Z.to_int @@ Z.extract a 32 16),
(Z.to_int @@ Z.extract a 16 16 ,
Z.to_int @@ Z.extract a 0 16))
| Kind_2 -> Two ( Z.to_int @@ Z.extract a 16 16,
Z.to_int @@ Z.extract a 0 16 )
| Kind_3 -> let x = Z.to_int64 a in
Three ( to_int ( logand mask10 (shift_right x 20)),
to_int ( logand mask10 (shift_right x 10)),
to_int ( logand mask10 x) )
| Kind_6 -> let x = Z.to_int64 a in
Six ( ( to_int ( logand mask10 (shift_right x 50)),
to_int ( logand mask10 (shift_right x 40)),
to_int ( logand mask10 (shift_right x 30))),
( to_int ( logand mask10 (shift_right x 20)),
to_int ( logand mask10 (shift_right x 10)),
to_int ( logand mask10 x) ) )
| Kind_12 -> let x = Z.to_int64 @@ Z.extract a 0 60
and y = Z.to_int64 @@ Z.extract a 64 60
in
Twelve ( ( to_int ( logand mask10 (shift_right y 114)),
to_int ( logand mask10 (shift_right y 104)),
to_int ( logand mask10 (shift_right y 94))),
( to_int ( logand mask10 (shift_right y 84)),
to_int ( logand mask10 (shift_right y 74)),
to_int ( logand mask10 (shift_right y 64))),
( to_int ( logand mask10 (shift_right x 50)),
to_int ( logand mask10 (shift_right x 40)),
to_int ( logand mask10 (shift_right x 30))),
( to_int ( logand mask10 (shift_right x 20)),
to_int ( logand mask10 (shift_right x 10)),
to_int ( logand mask10 x) ))
| Kind_9 -> let x = Z.to_int64 @@ Z.extract a 0 60
and y = Z.to_int64 @@ Z.extract a 64 60
in
Nine ( ( to_int ( logand mask10 (shift_right y 84)),
to_int ( logand mask10 (shift_right y 74)),
to_int ( logand mask10 (shift_right y 64))),
( to_int ( logand mask10 (shift_right x 50)),
to_int ( logand mask10 (shift_right x 40)),
to_int ( logand mask10 (shift_right x 30))),
( to_int ( logand mask10 (shift_right x 20)),
to_int ( logand mask10 (shift_right x 10)),
to_int ( logand mask10 x) ))
| Kind_4 -> let x = Z.to_int64 a in
Four ( ( to_int ( logand mask16 (shift_right x 48)),
to_int ( logand mask16 (shift_right x 32))),
( to_int ( logand mask16 (shift_right x 16)),
to_int ( logand mask16 x) ))
| Kind_2 -> let x = Z.to_int64 a in
Two ( to_int ( logand mask16 (shift_right x 16)),
to_int ( logand mask16 x) )
| Kind_1 -> One ( Z.to_int a )