From fdf6b02043434f67914970e2cccc0270069eb5a7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 23 Jan 2018 23:52:57 +0100 Subject: [PATCH] Accelerated Zkey --- Utils/Zkey.ml | 89 +++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/Utils/Zkey.ml b/Utils/Zkey.ml index 77fe828..12ae8cd 100644 --- a/Utils/Zkey.ml +++ b/Utils/Zkey.ml @@ -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 )