<p>Jan Hrach has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/10263">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">phy/tetra_burst.c: use bitwise operations to speed up synchronization<br><br>Finding synchronization sequence eats several times more CPU time than the<br>actual decoding. This is especially pronounced on channels with lots of errors<br>(where synchronization is lost frequently) and channels that are most of the<br>time empty (such as uplink channels, support for which is coming in following<br>patches).<br><br>Profiling shows that all the time is spent in memcmp calls.<br><br>A complicated and efficient algorithm, e.g. Aho-Corasick, turned out to be<br>not necessary. Compilers can optimize even a simple bit filter into fast code.<br><br>This provides only a modest (~25 %) performance gain, more fixes are coming.<br><br>Fixes: OS#1897<br>Change-Id: I3b90cc70c2ec67253a0fd2f00c6957a80971c38b<br>---<br>M src/phy/tetra_burst.c<br>1 file changed, 30 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-tetra refs/changes/63/10263/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/phy/tetra_burst.c b/src/phy/tetra_burst.c</span><br><span>index 62efb72..5bede06 100644</span><br><span>--- a/src/phy/tetra_burst.c</span><br><span>+++ b/src/phy/tetra_burst.c</span><br><span>@@ -269,9 +269,39 @@</span><br><span> int tetra_find_train_seq(const uint8_t *in, unsigned int end_of_in,</span><br><span>                     uint32_t mask_of_train_seq, unsigned int *offset)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+       static uint32_t tsq_bytes[5];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       if (tsq_bytes[0] == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+#define FILTER_LOOKAHEAD_LEN 22</span><br><span style="color: hsl(120, 100%, 40%);">+#define FILTER_LOOKAHEAD_MASK ((1<<FILTER_LOOKAHEAD_LEN)-1)</span><br><span style="color: hsl(120, 100%, 40%);">+          for (int i = 0; i < FILTER_LOOKAHEAD_LEN; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   tsq_bytes[0] = (tsq_bytes[0] << 1) | y_bits[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                 tsq_bytes[1] = (tsq_bytes[1] << 1) | n_bits[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                 tsq_bytes[2] = (tsq_bytes[2] << 1) | p_bits[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                 tsq_bytes[3] = (tsq_bytes[3] << 1) | q_bits[i];</span><br><span style="color: hsl(120, 100%, 40%);">+                 tsq_bytes[4] = (tsq_bytes[4] << 1) | x_bits[i];</span><br><span style="color: hsl(120, 100%, 40%);">+         }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   uint32_t filter = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        for (int i = 0; i < FILTER_LOOKAHEAD_LEN-2; i++)</span><br><span style="color: hsl(120, 100%, 40%);">+           filter = (filter << 1) | in[i];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      const uint8_t *cur;</span><br><span> </span><br><span>      for (cur = in; cur < in + end_of_in; cur++) {</span><br><span style="color: hsl(120, 100%, 40%);">+              filter = ((filter << 1) | cur[FILTER_LOOKAHEAD_LEN-1]) & FILTER_LOOKAHEAD_MASK;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           int match = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+              for (int i = 0; i < 5; i++)</span><br><span style="color: hsl(120, 100%, 40%);">+                        if (filter == tsq_bytes[i])</span><br><span style="color: hsl(120, 100%, 40%);">+                           match = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          if (!match)</span><br><span style="color: hsl(120, 100%, 40%);">+                   continue;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>          int remain_len = (in + end_of_in) - cur;</span><br><span> </span><br><span>                 if (mask_of_train_seq & (1 << TETRA_TRAIN_SYNC) &&</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/10263">change 10263</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/10263"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-tetra </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I3b90cc70c2ec67253a0fd2f00c6957a80971c38b </div>
<div style="display:none"> Gerrit-Change-Number: 10263 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Jan Hrach <jenda.2vf9h@hrach.eu> </div>