libosmo-netif[master]: stream.h: Add missing stdint.h include

2017-04-30 Thread Holger Freyther

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/2368
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I399e2986c9d8cb5b3dd31673a6b4bf63070a4770
Gerrit-PatchSet: 2
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-HasComments: No


libosmocore[master]: gsm0808: fixup length check of the element decoder functions

2017-04-30 Thread Holger Freyther

Patch Set 2: Code-Review+1

Hmm.. I would prefer to add the comments in another patch. Try to keep patches 
minimal and on a single topic.

-- 
To view, visit https://gerrit.osmocom.org/2446
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I78bc887f68d1963d28c6fcd631ac20ccd893d6d6
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-HasComments: No


osmo-trx[master]: debian: remove obsolete dependency

2017-04-30 Thread Holger Freyther

Patch Set 2: Code-Review+1

In two years we won't know what "latest Ubuntu" is. Always better to put a 
version number in there. Stretch won't have it either.

-- 
To view, visit https://gerrit.osmocom.org/2400
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I3ea72b4123a280a846086d083c4f3189d611f8cf
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Tom Tsou 
Gerrit-Reviewer: neels 
Gerrit-HasComments: No


openbsc[master]: Make BTS type and variant converters shareable

2017-04-30 Thread Holger Freyther

Patch Set 7:

(1 comment)

https://gerrit.osmocom.org/#/c/2286/7/openbsc/src/libcommon/gsm_data_shared.c
File openbsc/src/libcommon/gsm_data_shared.c:

Line 70: const struct value_string bts_variant_names[_NUM_BTS_VARIANT + 1] = {
BikeShedding:

* bts_variant.. they are all osmo-bts variants. Reflect that in the name?
* In fact some of them are not BTS variants but more the Phy. So all of them 
are osmo-bts but have various limitations/features in the Phy (dual-trx, 
single-trx, no HR1, higher latency due Ethernet?)

Maybe do it based on features? Have a name enable/unlock features?

So something like.. can_have_multiple_sdcch8, can_be_multi_trx?


-- 
To view, visit https://gerrit.osmocom.org/2286
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ida94725a6fce968443541e3526f48f13758031fd
Gerrit-PatchSet: 7
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: Yes


[MERGED] mncc-python[master]: test: Add a manual test to simulate DTMF handling in osmo-si...

2017-04-30 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: test: Add a manual test to simulate DTMF handling in 
osmo-sip-connector
..


test: Add a manual test to simulate DTMF handling in osmo-sip-connector

Add a manul test to the contrib folder that helped and can help during
the development of osmo-sip-connector or similar software. This avoids
having to create a separate mncc module.

It can be started like:

$ PYTHONPATH=$PWD/../ python manual_test_server.py

Change-Id: I7f62efbc62455e6fcb1f091afb5fa120099834f0
---
A contrib/manual_test_server.py
1 file changed, 126 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved; Verified



diff --git a/contrib/manual_test_server.py b/contrib/manual_test_server.py
new file mode 100644
index 000..5625670
--- /dev/null
+++ b/contrib/manual_test_server.py
@@ -0,0 +1,126 @@
+import mncc
+import mncc_sock
+import ctypes
+import socket
+
+GSM340_PLAN_ISDN = 1
+GSM340_TYPE_NATIONAL = 2
+
+class MnccMessageBuilder(object):
+"""
+I help in creating messages...
+"""
+@staticmethod
+def build_hello():
+hello = mncc.gsm_mncc_hello()
+hello.msg_type = mncc.MNCC_SOCKET_HELLO
+hello.version = mncc.MNCC_SOCK_VERSION
+hello.mncc_size = ctypes.sizeof(mncc.gsm_mncc)
+hello.data_frame_size = ctypes.sizeof(mncc.gsm_data_frame)
+hello.called_offset = mncc.gsm_mncc.called.offset
+hello.signal_offset = mncc.gsm_mncc.signal.offset
+hello.emergency_offset = mncc.gsm_mncc.emergency.offset
+hello.lchan_type_offset = mncc.gsm_mncc.lchan_type.offset
+return hello
+
+@staticmethod
+def build_mncc_number(number):
+return mncc.gsm_mncc_number(
+type=GSM340_TYPE_NATIONAL,
+plan=GSM340_PLAN_ISDN,
+number=number)
+
+@staticmethod
+def build_setup_ind(calling, called, callref=1):
+setup = mncc.gsm_mncc()
+setup.msg_type = mncc.MNCC_SETUP_IND
+setup.callref = callref
+setup.fields = mncc.MNCC_F_CALLED | mncc.MNCC_F_CALLING
+setup.called = MnccMessageBuilder.build_mncc_number(called)
+setup.calling = MnccMessageBuilder.build_mncc_number(calling)
+return setup
+
+@staticmethod
+def build_setup_cmpl_ind(callref=1):
+setup = mncc.gsm_mncc()
+setup.msg_type = mncc.MNCC_SETUP_COMPL_IND
+setup.callref = callref
+return setup
+
+@staticmethod
+def build_rtp_msg(msg_type, callref, addr, port):
+return mncc.gsm_mncc_rtp(
+msg_type=msg_type, callref=callref,
+ip=addr, port=port,
+#payload_type=3,
+#payload_msg_type=mncc.GSM_TCHF_FRAME)
+payload_type=98,
+payload_msg_type=mncc.GSM_TCH_FRAME_AMR)
+
+@staticmethod
+def build_dtmf_start(callref, data):
+return mncc.gsm_mncc(
+msg_type=mncc.MNCC_START_DTMF_IND,
+callref=callref,
+fields=mncc.MNCC_F_KEYPAD,
+keypad=ord(data))
+
+@staticmethod
+def build_dtmf_stop(callref, data):
+return mncc.gsm_mncc(
+callref=callref,
+msg_type=mncc.MNCC_STOP_DTMF_IND)
+
+def send_dtmf(callref):
+global conn
+
+conn.send_msg(MnccMessageBuilder.build_dtmf_start(callref, '1'))
+conn.send_msg(MnccMessageBuilder.build_dtmf_stop(callref, '1'))
+conn.send_msg(MnccMessageBuilder.build_dtmf_start(callref, '2'))
+conn.send_msg(MnccMessageBuilder.build_dtmf_stop(callref, '2'))
+
+
+server = mncc_sock.MnccSocketServer()
+conn = server.accept()
+
+# Say hello and set-up a call
+conn.send_msg(MnccMessageBuilder.build_hello())
+conn.send_msg(MnccMessageBuilder.build_setup_ind("1234", "5000"))
+print("=> Sent hello + setup indication")
+
+# Wait for the RTP crate.. and actknowledge it..
+msg = conn.recv()
+assert msg.msg_type == mncc.MNCC_RTP_CREATE
+print("<= Received request to create a RTP socket")
+conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CREATE,
+msg.callref,
+#socket.INADDR_LOOPBACK, 4000))
+socket.INADDR_ANY, 4000))
+print("=> Claimed socket was created...")
+
+msg = conn.recv()
+assert msg.msg_type == mncc.MNCC_CALL_PROC_REQ
+print("<= Received proceeding...")
+
+
+
+while True:
+msg = conn.recv()
+if msg.msg_type == mncc.MNCC_ALERT_REQ:
+print("=> I should alert...")
+continue
+if msg.msg_type == mncc.MNCC_RTP_CONNECT:
+conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CONNECT,
+msg.callref,
+

mncc-python[master]: test: Add a manual test to simulate DTMF handling in osmo-si...

2017-04-30 Thread Harald Welte

Patch Set 1: Code-Review+2 Verified+1

-- 
To view, visit https://gerrit.osmocom.org/2452
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7f62efbc62455e6fcb1f091afb5fa120099834f0
Gerrit-PatchSet: 1
Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


[MERGED] mncc-python[master]: mncc: Make it possible to build a MNCC server for testing

2017-04-30 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: mncc: Make it possible to build a MNCC server for testing
..


mncc: Make it possible to build a MNCC server for testing

For manual testing the osmo-sip-connector it is nice to run a custom
MNCC server to mock certain behavior. Refactor the socket class to
share code between client/server.

Change-Id: I8387fe1687557c6a1a26ff1e0cc9dbff3087aa82
---
M mncc_sock.py
1 file changed, 32 insertions(+), 13 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved; Verified



diff --git a/mncc_sock.py b/mncc_sock.py
index 48da514..3d29691 100644
--- a/mncc_sock.py
+++ b/mncc_sock.py
@@ -52,21 +52,13 @@
 plan = num_plan, present = num_present,
 screen = num_screen)
 
-class MnccSocket(object):
-def __init__(self, address = '/tmp/bsc_mncc'):
-self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
-print 'connecting to %s' % address
-try:
-self.sock.connect(address)
-except socket.error, errmsg:
-print >>sys.stderr, errmsg
-sys.exit(1)
-
-# FIXME: parse the HELLO message
-msg = self.recv()
-
+class MnccSocketBase(object):
 def send(self, msg):
 return self.sock.sendall(msg.send())
+
+def send_msg(self, msg):
+data = buffer(msg)[:]
+return self.sock.sendall(data)
 
 def recv(self):
 data = self.sock.recv(1500)
@@ -76,3 +68,30 @@
ms = mncc_rtp_msg()
ms.receive(data)
 return ms
+
+class MnccSocket(MnccSocketBase):
+def __init__(self, address = '/tmp/bsc_mncc'):
+super(MnccSocketBase, self).__init__()
+self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+print('connecting to %s' % address)
+try:
+self.sock.connect(address)
+except socket.error as errmsg:
+sys.stderr.write("%s\n" % errmsg)
+sys.exit(1)
+
+# FIXME: parse the HELLO message
+msg = self.recv()
+
+class MnccSocketServer(object):
+def __init__(self, address = '/tmp/bsc_mncc'):
+os.unlink(address)
+self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
+self.sock.bind(address)
+self.sock.listen(5)
+
+def accept(self):
+(fd,_) = self.sock.accept()
+sock = MnccSocketBase()
+sock.sock = fd
+return sock

-- 
To view, visit https://gerrit.osmocom.org/2451
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8387fe1687557c6a1a26ff1e0cc9dbff3087aa82
Gerrit-PatchSet: 1
Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Neels Hofmeyr 


mncc-python[master]: mncc: Make it possible to build a MNCC server for testing

2017-04-30 Thread Harald Welte

Patch Set 1: Verified+1

-- 
To view, visit https://gerrit.osmocom.org/2451
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I8387fe1687557c6a1a26ff1e0cc9dbff3087aa82
Gerrit-PatchSet: 1
Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


mncc-python[master]: mncc: Make it possible to build a MNCC server for testing

2017-04-30 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/2451
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I8387fe1687557c6a1a26ff1e0cc9dbff3087aa82
Gerrit-PatchSet: 1
Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


libosmocore[master]: core/conv: add x86 SSE support for Viterbi decoder

2017-04-30 Thread Vadim Yanitskiy

Patch Set 2:

> (1 comment)

No, of course. SSE3 support is mandatory for accelerated Viterbi
implementation only (viterbi_sse.c). If SSE3 isn't supported by
target CPU, then not-accelerated Viterbi implementation will be
used (viterbi_sse.c).

BTW: I forgot to change commit author :(

-- 
To view, visit https://gerrit.osmocom.org/2454
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I1da6d71ed0564f1d684f3a836e998d09de5f0351
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Tom Tsou 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Reviewer: dexter 
Gerrit-HasComments: No


libosmocore[master]: core/conv: add x86 SSE support for Viterbi decoder

2017-04-30 Thread Harald Welte

Patch Set 2:

(1 comment)

https://gerrit.osmocom.org/#/c/2454/2//COMMIT_MSG
Commit Message:

Line 11: is the minimal requirement. SSE4.1 and AVX2 are used if available.
Do you mean this patch introduces a mandatory requirement for SSE3 capable 
CPUs? if so, it is not acceptable.


-- 
To view, visit https://gerrit.osmocom.org/2454
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I1da6d71ed0564f1d684f3a836e998d09de5f0351
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Alexander Chemeris 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Tom Tsou 
Gerrit-Reviewer: dexter 
Gerrit-HasComments: Yes


libosmocore[master]: tests/conv: add GSM 05.03 specific test

2017-04-30 Thread Harald Welte

Patch Set 7: Code-Review+2

deferring to Tom's judgement here, but generally it looks fine to me, and if 
there are issues remaining, they can be adressed later on.

-- 
To view, visit https://gerrit.osmocom.org/1628
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I76d1cd4032d2f74c5bb93bde4fab99aa655b7f1a
Gerrit-PatchSet: 7
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-Reviewer: Tom Tsou 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-Reviewer: tnt 
Gerrit-HasComments: No


[PATCH] libosmocore[master]: core/conv: add x86 SSE support for Viterbi decoder

2017-04-30 Thread Vadim Yanitskiy
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/2454

to look at the new patch set (#2).

core/conv: add x86 SSE support for Viterbi decoder

Fast convolutional decoding is provided through x86 intrinsic based
SSE operations. SSE3, found on virtually all modern x86 processors,
is the minimal requirement. SSE4.1 and AVX2 are used if available.

To enable this feature, the source code should be configured with
SIMD support (see --enable-simd). Otherwise, the viterbi_sse.c
won't be compiled.

Also, the original code was extended with runtime SIMD detection,
so only supported extensions will be used by target CPU. It makes
the library more partable, what is very important for binary
packages distribution. The SIMD detection is currently implemented
through the __builtin_cpu_supports(EXT), which is only supported
by GCC.

Change-Id: I1da6d71ed0564f1d684f3a836e998d09de5f0351
---
M src/Makefile.am
M src/viterbi.c
M src/viterbi_gen.c
A src/viterbi_sse.c
4 files changed, 746 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/54/2454/2

diff --git a/src/Makefile.am b/src/Makefile.am
index 999436d..2f19838 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,10 @@
 macaddr.c stat_item.c stats.c stats_statsd.c prim.c \
 viterbi.c viterbi_gen.c
 
+if HAVE_SSE3
+libosmocore_la_SOURCES += viterbi_sse.c
+endif
+
 BUILT_SOURCES = crc8gen.c crc16gen.c crc32gen.c crc64gen.c
 
 if ENABLE_PLUGIN
diff --git a/src/viterbi.c b/src/viterbi.c
index ea4fb21..d68db23 100644
--- a/src/viterbi.c
+++ b/src/viterbi.c
@@ -24,12 +24,34 @@
 #include 
 #include 
 
-#include 
 #include "config.h"
+
+#include 
 
 #define BIT2NRZ(REG,N) (((REG >> N) & 0x01) * 2 - 1) * -1
 #define NUM_STATES(K)  (K == 7 ? 64 : 16)
-#define SSE_ALIGN  16
+
+static int init_complete = 0;
+
+__attribute__ ((visibility("hidden"))) int avx2_supported = 0;
+__attribute__ ((visibility("hidden"))) int sse3_supported = 0;
+__attribute__ ((visibility("hidden"))) int sse41_supported = 0;
+
+/**
+ * This pointers will be initialized by the osmo_conv_init()
+ * depending on supported SIMD extensions.
+ */
+static int16_t *(*vdec_malloc)(size_t n);
+static void (*vdec_free)(int16_t *ptr);
+
+/* Forward malloc wrappers */
+int16_t *osmo_conv_vdec_malloc(size_t n);
+void osmo_conv_vdec_free(int16_t *ptr);
+
+#ifdef HAVE_SSE3
+int16_t *osmo_conv_vdec_malloc_sse3(size_t n);
+void osmo_conv_vdec_free_sse3(int16_t *ptr);
+#endif
 
 /* Forward Metric Units */
 void osmo_conv_gen_metrics_k5_n2(const int8_t *seq, const int16_t *out,
@@ -44,6 +66,21 @@
int16_t *sums, int16_t *paths, int norm);
 void osmo_conv_gen_metrics_k7_n4(const int8_t *seq, const int16_t *out,
int16_t *sums, int16_t *paths, int norm);
+
+#ifdef HAVE_SSE3
+void osmo_conv_gen_metrics_k5_n2_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k5_n3_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k5_n4_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n2_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n3_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n4_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+#endif
 
 /* Trellis State
  * state - Internal lshift register value
@@ -90,20 +127,6 @@
void (*metric_func)(const int8_t *, const int16_t *,
int16_t *, int16_t *, int);
 };
-
-/* Aligned Memory Allocator
- * SSE requires 16-byte memory alignment. We store relevant trellis values
- * (accumulated sums, outputs, and path decisions) as 16 bit signed integers
- * so the allocated memory is casted as such.
- */
-static int16_t *vdec_malloc(size_t n)
-{
-#ifdef HAVE_SSE3
-   return (int16_t *) memalign(SSE_ALIGN, sizeof(int16_t) * n);
-#else
-   return (int16_t *) malloc(sizeof(int16_t) * n);
-#endif
-}
 
 /* Accessor calls */
 static inline int conv_code_recursive(const struct osmo_conv_code *code)
@@ -303,9 +326,9 @@
if (!trellis)
return;
 
+   vdec_free(trellis->outputs);
+   vdec_free(trellis->sums);
free(trellis->vals);
-   free(trellis->outputs);
-   free(trellis->sums);
free(trellis);
 }
 
@@ -439,7 +462,7 @@
if (!dec)
return;
 
-   free(dec->paths[0]);
+   vdec_free(dec->paths[0]);
free(dec->paths);
free_trellis(dec->trellis);
free(dec);
@@ -465,13 +488,31 @@
if (dec->k == 5) {
switch (dec->n) {
case 2:
+   #ifdef HAVE_SSE3
+

[PATCH] libosmocore[master]: configure.ac: add SIMD detection capabilities

2017-04-30 Thread Vadim Yanitskiy

Review at  https://gerrit.osmocom.org/2453

configure.ac: add SIMD detection capabilities

This change adds a new configure flag, which triggers a check
whether compiller supports some SIMD (Single Instruction,
Multiple Data) instructions. The check macro is based on
the AX_EXT from autoconf-archive:

www.gnu.org/software/autoconf-archive/ax_ext.html

And depends on the ax_check_compile_flag macro:

www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html

Currently only the following SIMD extensions are being checked:
AVX2, SSE3, SSE4.1, but adding others is also possible. All found
extensions are being defined in the 'config.h' header.

Change-Id: Idf8fff984bd936a75c7c307338df88ba4b005817
---
M .gitignore
M configure.ac
A m4/ax_check_compile_flag.m4
A m4/ax_check_simd.m4
M src/Makefile.am
5 files changed, 174 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/53/2453/1

diff --git a/.gitignore b/.gitignore
index 5111b25..2b0ca64 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 acinclude.m4
 aminclude.am
 m4/*.m4
+!m4/ax_*.m4
 autom4te.cache
 config.cache
 config.h*
diff --git a/configure.ac b/configure.ac
index a18197d..61b2af8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -226,6 +226,22 @@
CPPFLAGS+=" -fsanitize=address -fsanitize=undefined"
 fi
 
+AC_ARG_ENABLE(simd,
+   [AS_HELP_STRING(
+   [--enable-simd],
+[Enable SIMD (SSE, AVX) support]
+)],
+[simd=$enableval], [simd="no"])
+if test x"$simd" = x"yes"
+then
+   # Find and define supported SIMD extensions
+   AX_CHECK_SIMD
+else
+   AM_CONDITIONAL(HAVE_AVX2, false)
+   AM_CONDITIONAL(HAVE_SSE3, false)
+   AM_CONDITIONAL(HAVE_SSE4_1, false)
+fi
+
 AC_OUTPUT(
libosmocore.pc
libosmocodec.pc
diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
new file mode 100644
index 000..dcabb92
--- /dev/null
+++ b/m4/ax_check_compile_flag.m4
@@ -0,0 +1,74 @@
+# ===
+#  https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
+# ===
+#
+# SYNOPSIS
+#
+#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], 
[EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+#   Check whether the given FLAG works with the current language's compiler
+#   or gives an error.  (Warnings, however, are ignored)
+#
+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+#   success/failure.
+#
+#   If EXTRA-FLAGS is defined, it is added to the current language's default
+#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with
+#   the flags: "CFLAGS EXTRA-FLAGS FLAG".  This can for example be used to
+#   force the compiler to issue an error when a bad flag is given.
+#
+#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.
+#
+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+#   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Guido U. Draheim 
+#   Copyright (c) 2011 Maarten Bosmans 
+#
+#   This program is free software: you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation, either version 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see .
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 5
+
+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
+  

[PATCH] libosmocore[master]: core/conv: add x86 SSE support for Viterbi decoder

2017-04-30 Thread Vadim Yanitskiy

Review at  https://gerrit.osmocom.org/2454

core/conv: add x86 SSE support for Viterbi decoder

Fast convolutional decoding is provided through x86 intrinsic based
SSE operations. SSE3, found on virtually all modern x86 processors,
is the minimal requirement. SSE4.1 and AVX2 are used if available.

To enable this feature, the source code should be configured with
SIMD support (see --enable-simd). Otherwise, the viterbi_sse.c
won't be compiled.

Also, the original code was extended with runtime SIMD detection,
so only supported extensions will be used by target CPU. It makes
the library more partable, what is very important for binary
packages distribution. The SIMD detection is currently implemented
through the __builtin_cpu_supports(EXT), which is only supported
by GCC.

Change-Id: I1da6d71ed0564f1d684f3a836e998d09de5f0351
---
M src/Makefile.am
M src/viterbi.c
A src/viterbi_sse.c
3 files changed, 699 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/54/2454/1

diff --git a/src/Makefile.am b/src/Makefile.am
index 999436d..2f19838 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,10 @@
 macaddr.c stat_item.c stats.c stats_statsd.c prim.c \
 viterbi.c viterbi_gen.c
 
+if HAVE_SSE3
+libosmocore_la_SOURCES += viterbi_sse.c
+endif
+
 BUILT_SOURCES = crc8gen.c crc16gen.c crc32gen.c crc64gen.c
 
 if ENABLE_PLUGIN
diff --git a/src/viterbi.c b/src/viterbi.c
index ea4fb21..1484a31 100644
--- a/src/viterbi.c
+++ b/src/viterbi.c
@@ -20,16 +20,30 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include 
 #include 
 #include 
 #include 
 
-#include 
 #include "config.h"
+
+#include 
 
 #define BIT2NRZ(REG,N) (((REG >> N) & 0x01) * 2 - 1) * -1
 #define NUM_STATES(K)  (K == 7 ? 64 : 16)
 #define SSE_ALIGN  16
+
+static int init_complete = 0;
+
+__attribute__ ((visibility("hidden"))) int avx2_supported = 0;
+__attribute__ ((visibility("hidden"))) int sse3_supported = 0;
+__attribute__ ((visibility("hidden"))) int sse41_supported = 0;
+
+/**
+ * This pointer will be initialized by the osmo_conv_init()
+ * depending on supported SIMD extensions.
+ */
+static int16_t *(*vdec_malloc)(size_t n);
 
 /* Forward Metric Units */
 void osmo_conv_gen_metrics_k5_n2(const int8_t *seq, const int16_t *out,
@@ -44,6 +58,21 @@
int16_t *sums, int16_t *paths, int norm);
 void osmo_conv_gen_metrics_k7_n4(const int8_t *seq, const int16_t *out,
int16_t *sums, int16_t *paths, int norm);
+
+#ifdef HAVE_SSE3
+void osmo_conv_gen_metrics_k5_n2_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k5_n3_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k5_n4_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n2_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n3_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+void osmo_conv_gen_metrics_k7_n4_sse(const int8_t *seq, const int16_t *out,
+   int16_t *sums, int16_t *paths, int norm);
+#endif
 
 /* Trellis State
  * state - Internal lshift register value
@@ -96,13 +125,14 @@
  * (accumulated sums, outputs, and path decisions) as 16 bit signed integers
  * so the allocated memory is casted as such.
  */
-static int16_t *vdec_malloc(size_t n)
+static int16_t *vdec_malloc_no_sse3(size_t n)
 {
-#ifdef HAVE_SSE3
-   return (int16_t *) memalign(SSE_ALIGN, sizeof(int16_t) * n);
-#else
return (int16_t *) malloc(sizeof(int16_t) * n);
-#endif
+}
+
+static int16_t *vdec_malloc_sse3(size_t n)
+{
+   return (int16_t *) memalign(SSE_ALIGN, sizeof(int16_t) * n);
 }
 
 /* Accessor calls */
@@ -465,13 +495,31 @@
if (dec->k == 5) {
switch (dec->n) {
case 2:
+   #ifdef HAVE_SSE3
+   dec->metric_func = !sse3_supported ?
+   osmo_conv_gen_metrics_k5_n2 :
+   osmo_conv_gen_metrics_k5_n2_sse;
+   #else
dec->metric_func = osmo_conv_gen_metrics_k5_n2;
+   #endif
break;
case 3:
+   #ifdef HAVE_SSE3
+   dec->metric_func = !sse3_supported ?
+   osmo_conv_gen_metrics_k5_n3 :
+   osmo_conv_gen_metrics_k5_n3_sse;
+   #else
dec->metric_func = osmo_conv_gen_metrics_k5_n3;
+   #endif
break;
case 4:
+   #ifdef HAVE_SSE3
+   dec->metric_func = !sse3_supported ?
+   osmo_conv_gen_metrics_k5_n4 :
+ 

osmo-trx[master]: buildenv: Turn off native architecture builds

2017-04-30 Thread Vadim Yanitskiy

Patch Set 3: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/2098
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I3df4b8db9692016115edbe2247beeec090715687
Gerrit-PatchSet: 3
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-trx[master]: cosmetic: Add info about SSE support

2017-04-30 Thread Vadim Yanitskiy

Patch Set 3: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/2101
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Iacc83fd668c31644e0efb3e18962cf2870ed1daf
Gerrit-PatchSet: 3
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-trx[master]: buildenv: Make build CPU invariant

2017-04-30 Thread Vadim Yanitskiy

Patch Set 4: Code-Review+1

(2 comments)

https://gerrit.osmocom.org/#/c/2102/4/config/ax_ext.m4
File config/ax_ext.m4:

Line 22: # HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 / 
HAVE_SSE4.1 / HAVE_SSE4.2 / HAVE_AVX
Now we have only HAVE_SSE3 and HAVE_SSE4.1, right?
So, it would be good to update this line with actual info.


PS4, Line 47: AC_REQUIRE([AX_GCC_X86_CPUID])
:   AC_REQUIRE([AX_GCC_X86_AVX_XGETBV])
: 
:   AX_GCC_X86_CPUID(0x0001)
Do we still need this?


-- 
To view, visit https://gerrit.osmocom.org/2102
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ic913aa13c23c348ae62e78c9dfd6ed8b0a62798c
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes