| 34 | |
| 35 | template<typename B> |
| 36 | void |
| 37 | Source_random_fast<B>::_generate(B* U_K, const size_t /*frame_id*/) |
| 38 | { |
| 39 | if (!mipp::isAligned(U_K)) |
| 40 | throw spu::tools::runtime_error(__FILE__, __LINE__, __func__, "'U_K' is misaligned memory."); |
| 41 | |
| 42 | const auto size = (unsigned)(this->max_data_size); |
| 43 | |
| 44 | // vectorized loop |
| 45 | const auto period = mipp::nElReg<B>() * sizeof(B) * 8; |
| 46 | const auto vec_loop_size = (unsigned)((size / period) * period); |
| 47 | for (unsigned i = 0; i < vec_loop_size; i += period) |
| 48 | { |
| 49 | mipp::Reg<int> randoms_s32 = mt19937_simd.rand_s32(); |
| 50 | mipp::Reg<B> randoms = randoms_s32.r; |
| 51 | |
| 52 | for (unsigned j = 0; j < (sizeof(B) * 8); j++) |
| 53 | { |
| 54 | auto r = randoms & 0x1; |
| 55 | r.store(&U_K[i + j * mipp::nElReg<B>()]); |
| 56 | randoms >>= 1; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // remaining scalar operations |
| 61 | for (unsigned i = vec_loop_size; i < size; i += sizeof(B) * 8) |
| 62 | { |
| 63 | auto randoms = mt19937.rand_u32(); |
| 64 | unsigned j = 0; |
| 65 | while ((j < sizeof(B) * 8) && (i + j < size)) |
| 66 | { |
| 67 | auto r = randoms & 0x1; |
| 68 | U_K[i + j] = r; |
| 69 | randoms >>= 1; |
| 70 | j++; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | template<typename B> |
| 76 | void |