123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- #ifndef __RDPF_HPP__
- #define __RDPF_HPP__
- #include <vector>
- #include <iostream>
- #include "mpcio.hpp"
- #include "coroutine.hpp"
- #include "types.hpp"
- #include "bitutils.hpp"
- template <typename T>
- class StreamEval {
- const T &rdpf;
- size_t &op_counter;
- bool use_expansion;
- nbits_t depth;
- address_t indexmask;
- address_t pathindex;
- address_t nextindex;
- std::vector<typename T::node> path;
- public:
-
-
-
-
-
- StreamEval(const T &rdpf, address_t start, size_t &op_counter,
- bool use_expansion = true);
-
- typename T::node next();
- };
- struct RDPF {
-
- using node = DPFnode;
-
- DPFnode seed;
-
- bit_t whichhalf;
-
-
- std::vector<DPFnode> cw;
-
- value_t cfbits;
-
-
- value_t unit_sum_inverse;
-
-
- RegAS scaled_sum;
-
-
- RegXS scaled_xor;
-
- std::vector<DPFnode> expansion;
- RDPF() {}
-
-
-
-
-
-
-
-
-
-
-
-
- RDPF(MPCTIO &tio, yield_t &yield,
- RegXS target, nbits_t depth, bool save_expansion = false);
-
- size_t size() const;
-
-
- static size_t size(nbits_t depth);
-
- inline nbits_t depth() const { return cw.size(); }
-
- inline node get_seed() const { return seed; }
-
- inline bool has_expansion() const { return expansion.size() > 0; }
-
- inline node get_expansion(address_t index) const {
- return expansion[index];
- }
-
-
-
-
-
- DPFnode descend(const DPFnode &parent, nbits_t parentdepth,
- bit_t whichchild, size_t &op_counter) const;
-
-
-
- DPFnode leaf(address_t input, size_t &op_counter) const;
-
- void expand(size_t &op_counter);
-
- inline RegBS unit_bs(DPFnode leaf) const {
- RegBS b;
- b.bshare = get_lsb(leaf);
- return b;
- }
-
- inline RegAS unit_as(DPFnode leaf) const {
- RegAS a;
- value_t lowword = value_t(_mm_cvtsi128_si64x(leaf));
- if (whichhalf == 1) {
- lowword = -lowword;
- }
- a.ashare = lowword * unit_sum_inverse;
- return a;
- }
-
- inline RegXS scaled_xs(DPFnode leaf) const {
- RegXS x;
- value_t highword =
- value_t(_mm_cvtsi128_si64x(_mm_srli_si128(leaf,8)));
- x.xshare = highword;
- return x;
- }
-
- inline RegAS scaled_as(DPFnode leaf) const {
- RegAS a;
- value_t highword =
- value_t(_mm_cvtsi128_si64x(_mm_srli_si128(leaf,8)));
- if (whichhalf == 1) {
- highword = -highword;
- }
- a.ashare = highword;
- return a;
- }
- };
- struct RDPFTriple {
-
- using node = std::tuple<DPFnode, DPFnode, DPFnode>;
- RegAS as_target;
- RegXS xs_target;
- RDPF dpf[3];
-
- inline nbits_t depth() const { return dpf[0].depth(); }
-
- inline node get_seed() const {
- return std::make_tuple(dpf[0].get_seed(), dpf[1].get_seed(),
- dpf[2].get_seed());
- }
-
- inline bool has_expansion() const {
- return dpf[0].expansion.size() > 0;
- }
-
- inline node get_expansion(address_t index) const {
- return std::make_tuple(dpf[0].get_expansion(index),
- dpf[1].get_expansion(index), dpf[2].get_expansion(index));
- }
- RDPFTriple() {}
-
-
- RDPFTriple(MPCTIO &tio, yield_t &yield,
- nbits_t depth, bool save_expansion = false);
-
- node descend(const node &parent, nbits_t parentdepth,
- bit_t whichchild, size_t &op_counter) const;
-
-
-
- template <typename T>
- inline std::tuple<T,T,T> scaled_value() const;
- template <typename T>
- inline std::tuple<T,T,T> unit(node leaf) const;
- template <typename T>
- inline std::tuple<T,T,T> scaled(node leaf) const;
- };
- struct RDPFPair {
-
- using node = std::tuple<DPFnode, DPFnode>;
- RDPF dpf[2];
- RDPFPair() {}
-
-
-
-
- RDPFPair(RDPFTriple &&trip, int which0, int which1) {
- dpf[0] = std::move(trip.dpf[which0]);
- dpf[1] = std::move(trip.dpf[which1]);
- }
-
- inline nbits_t depth() const { return dpf[0].depth(); }
-
- inline node get_seed() const {
- return std::make_tuple(dpf[0].get_seed(), dpf[1].get_seed());
- }
-
- inline bool has_expansion() const {
- return dpf[0].expansion.size() > 0;
- }
-
- inline node get_expansion(address_t index) const {
- return std::make_tuple(dpf[0].get_expansion(index),
- dpf[1].get_expansion(index));
- }
-
- node descend(const node &parent, nbits_t parentdepth,
- bit_t whichchild, size_t &op_counter) const;
-
-
-
- template <typename T>
- inline std::tuple<T,T> scaled_value() const;
- template <typename T>
- inline std::tuple<T,T> unit(node leaf) const;
- template <typename T>
- inline std::tuple<T,T> scaled(node leaf) const;
- };
- #include "rdpf.tcc"
- #endif
|