DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPGenerator.cpp
Go to the documentation of this file.
1
10
11namespace tpglibs {
12
13void
14TPGenerator::configure(const std::vector<std::pair<std::string, nlohmann::json>>& configs,
15 const std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers,
16 const int sample_tick_difference) {
17 m_num_pipelines = channel_plane_numbers.size() / m_num_channels_per_pipeline;
18 m_sample_tick_difference = sample_tick_difference;
19
20 for (int p = 0; p < m_num_pipelines; p++) {
21 AVXPipeline new_pipe = AVXPipeline();
22 auto begin_channel_plane = channel_plane_numbers.begin() + p*m_num_channels_per_pipeline;
23 auto end_channel_plane = begin_channel_plane + m_num_channels_per_pipeline;
24 new_pipe.configure(configs, std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>>(begin_channel_plane, end_channel_plane));
26 m_tpg_pipelines.push_back(new_pipe);
27 }
28}
29
30void
31TPGenerator::set_sot_minima(const std::vector<uint16_t>& sot_minima) {
32 m_sot_minima = sot_minima;
33}
34
35__m256i
36TPGenerator::expand_frame(const __m256i& regi) {
37 // Refer to the diagram and documentation on frame expansion for details.
38
39 // Prepare even (2,4,6,8), odd (1,3,5,7) rows in 64-bit sense.
40 __m256i odd = _mm256_permutevar8x32_epi32(regi, _mm256_setr_epi32(1, 0, 1, 2, 3, 4, 5, 6));
41
42 // Shift into place.
43 __m256i even = _mm256_sllv_epi64(regi, _mm256_setr_epi64x(6, 14, 22, 30));
44 odd = _mm256_srlv_epi64(odd, _mm256_setr_epi64x(30, 22, 14, 6));
45
46 // Everything is center aligned in 32-bit. Mask and right-align the right side.
47 __m256i both = _mm256_blend_epi32(even, odd, 0b01010101);
48 __m256i right = _mm256_and_si256(_mm256_set1_epi32(0xFFFFu), both);
49 __m256i left = _mm256_and_si256(_mm256_set1_epi32(0x3FFF0000u), both);
50
51 right = _mm256_srli_epi32(right, 2);
52 return _mm256_or_si256(left, right);
53}
54
55__m256i
56TPGenerator::old_expand_frame(const __m256i& regi) {
57 // Refer to the diagram and documentation on frame expansion for details.
58
59 // Rearrange original with row 3 doubled.
60 __m256i idx = _mm256_set_epi32(6, 5, 4, 3, 3, 2, 1, 0);
61 __m256i shuf1 = _mm256_permutevar8x32_epi32(regi, idx);
62
63 // Left shift each row.
64 __m256i count = _mm256_set_epi32(12, 8, 4, 0, 14, 10, 6, 2);
65 __m256i high_half = _mm256_sllv_epi32(shuf1, count);
66 high_half = _mm256_and_si256(high_half, _mm256_set1_epi32(0x3FFF0000u)); // Mask out the low half.
67
68 // Left shift for low half later.
69 count = _mm256_set_epi32(10, 6, 2, 0, 12, 8, 4, 0);
70 __m256i shift2 = _mm256_sllv_epi32(shuf1, count);
71
72 // Rearrange original and doubled rows 2 and 0.
73 idx = _mm256_set_epi32(5, 4, 3, 2, 2, 1, 0, 0);
74 __m256i shuf2 = _mm256_permutevar8x32_epi32(regi, idx);
75
76 // Right shift each row.
77 count = _mm256_set_epi32(22, 26, 30, 0, 20, 24, 28, 0);
78 __m256i shift3 = _mm256_srlv_epi32(shuf2, count);
79
80 // "Complete" the low half. Still more.
81 __m256i low_half = _mm256_or_si256(shift2, shift3);
82 low_half = _mm256_and_si256(low_half, _mm256_set1_epi32(0x3FFFu)); // Mask out the high half.
83
84 // Combine halves and clear space for an odd entry.
85 __m256i both = _mm256_or_si256(low_half, high_half);
86 both = _mm256_andnot_si256(_mm256_set_epi32(0, 0, 0, 0xFFFFu, 0, 0, 0, 0), both);
87
88 // There is a specific 16-bit entry that needs special handling.
89 // Align it.
90 __m256i shift4 = _mm256_srli_epi32(regi, 18);
91 // Mask it.
92 shift4 = _mm256_and_si256(_mm256_set_epi32(0, 0x3FFFu, 0, 0, 0, 0, 0, 0), shift4);
93
94 // Permute into the right spot
95 idx = _mm256_set_epi32(0, 0, 0, 6, 0, 0, 0, 0);
96 __m256i shuf3 = _mm256_permutevar8x32_epi32(shift4, idx);
97
98 // Add it in.
99 both = _mm256_or_si256(both, shuf3);
100 return both;
101}
102
103
104} // namespace tpglibs
AVX typed TPG pipeline.
virtual void set_sot_minima(const std::vector< uint16_t > &sot_minima)
Set the samples over threshold minimum values.
virtual void configure(const std::vector< std::pair< std::string, nlohmann::json > > configs, const std::vector< std::pair< dunedaq::trgdataformats::channel_t, int16_t > > channel_plane_numbers)
Configure the pieces to the pipeline.
std::vector< uint16_t > m_sot_minima
void set_sot_minima(const std::vector< uint16_t > &sot_minima)
Set the minimum samples over threshold for a TP according to plane.
void configure(const std::vector< std::pair< std::string, nlohmann::json > > &configs, const std::vector< std::pair< dunedaq::trgdataformats::channel_t, int16_t > > channel_plane_numbers, const int sample_tick_difference)
Setup and configure the AVX pipelines.
__m256i expand_frame(const __m256i &regi)
std::vector< AVXPipeline > m_tpg_pipelines
__m256i old_expand_frame(const __m256i &regi)
Expansion from 14-bit signals to 16-bit.
static const uint8_t m_num_channels_per_pipeline