Skip to content

Commit 0e3ce9a

Browse files
committed
new misrc_extract version
1 parent 3461d0c commit 0e3ce9a

File tree

3 files changed

+95
-10
lines changed

3 files changed

+95
-10
lines changed

misrc_extract/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ TBD
2929
* Run tool without arguments to see options
3030

3131
## Version History
32+
* 0.3
33+
* New: allow extraction of data from single channel capture
34+
3235
* 0.2
3336
* Fix: signal now with correct polarity
3437
* Mod: output program name and version

misrc_extract/extract.asm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ section .data
5656
shuf_dat: db 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15
5757
shuf_aux0: db 0, 4, 8, 12, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
5858
shuf_aux1: db 0x80, 0x80, 0x80, 0x80, 0, 4, 8, 12, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
59+
shuf_auxS: db 0, 2, 4, 6, 8, 10, 12, 14, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
5960
andmask: db 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f
6061
subval: dw 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048
6162
clip_maskA: db 1, 1, 1, 1, 1, 1, 1, 1
@@ -138,6 +139,55 @@ loop_A_0:
138139
jg loop_A_0
139140
ret
140141

142+
global extract_S_sse
143+
extract_S_sse:
144+
POPARGS
145+
loop_S_0:
146+
movdqa xmm0, [in]
147+
movdqa xmm2, xmm0
148+
pand xmm0, [andmask]
149+
movdqa xmm4, [subval]
150+
psubw xmm4, xmm0
151+
movdqa [outA], xmm4
152+
psrlw xmm2, 12
153+
pshufb xmm2, [shuf_auxS]
154+
movlpd [aux], xmm2
155+
movq rax, xmm2
156+
and rax, [clip_maskA]
157+
popcnt rax, rax
158+
add [clip], rax
159+
add aux, 8
160+
add outA, 16
161+
add in, 16
162+
sub len, 8
163+
jg loop_S_0
164+
ret
165+
166+
global extract_S_p_sse
167+
extract_S_p_sse:
168+
POPARGS
169+
loop_S_p_0:
170+
movdqa xmm0, [in]
171+
movdqa xmm2, xmm0
172+
pand xmm0, [andmask]
173+
movdqa xmm4, [subval]
174+
psubw xmm4, xmm0
175+
psllw xmm4, 4
176+
movdqa [outA], xmm4
177+
psrlw xmm2, 12
178+
pshufb xmm2, [shuf_auxS]
179+
movlpd [aux], xmm2
180+
movq rax, xmm2
181+
and rax, [clip_maskA]
182+
popcnt rax, rax
183+
add [clip], rax
184+
add aux, 8
185+
add outA, 16
186+
add in, 16
187+
sub len, 8
188+
jg loop_S_p_0
189+
ret
190+
141191
global extract_B_sse
142192
extract_B_sse:
143193
POPARGS

misrc_extract/main.c

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef _WIN32
2727
#include <getopt.h>
2828
#define aligned_free(x) free(x)
29-
#define PERF_MEASURE 1
29+
#define PERF_MEASURE 0
3030
#else
3131
#include <windows.h>
3232
#include <io.h>
@@ -42,7 +42,7 @@
4242
#include <time.h>
4343
#endif
4444

45-
#define VERSION "0.2"
45+
#define VERSION "0.3"
4646
#define COPYRIGHT "licensed under GNU GPL v3 or later, (c) 2024 vrunk11, stefan_o"
4747

4848
#define BUFFER_SIZE 65536*32
@@ -59,6 +59,7 @@ void usage(void)
5959
"\t[-b ADC B output file (use '-' to write on stdout)]\n"
6060
"\t[-x AUX output file (use '-' to write on stdout)]\n"
6161
"\t[-p pad lower 4 bits of 16 bit output with 0 instead of upper 4]\n"
62+
"\t[-s input is captured as single channel (-b cannot be used)]\n"
6263
);
6364
exit(1);
6465
}
@@ -67,6 +68,16 @@ void usage(void)
6768
#define MASK_1 0xFFF
6869
#define MASK_2 0xFFF00000
6970
#define MASK_AUX 0xFF000
71+
#define MASK_AUXS 0xF000
72+
73+
void extract_S_C(uint16_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB) {
74+
for(size_t i = 0; i < len; i++)
75+
{
76+
outA[i] = 2048 - ((int16_t)(in[i] & MASK_1));
77+
aux[i] = (in[i] & MASK_AUXS) >> 12;
78+
clip[0] += ((in[i] >> 12) & 1);
79+
}
80+
}
7081

7182
void extract_A_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB) {
7283
for(size_t i = 0; i < len; i++)
@@ -76,6 +87,7 @@ void extract_A_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *
7687
clip[0] += ((in[i] >> 12) & 1);
7788
}
7889
}
90+
7991
void extract_B_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB) {
8092
for(size_t i = 0; i < len; i++)
8193
{
@@ -96,6 +108,15 @@ void extract_AB_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t
96108
}
97109
}
98110

111+
void extract_S_p_C(uint16_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB) {
112+
for(size_t i = 0; i < len; i++)
113+
{
114+
outA[i] = (2048 - ((int16_t)(in[i] & MASK_1)))<<4;
115+
aux[i] = (in[i] & MASK_AUXS) >> 12;
116+
clip[0] += ((in[i] >> 12) & 1);
117+
}
118+
}
119+
99120
void extract_A_p_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB) {
100121
for(size_t i = 0; i < len; i++)
101122
{
@@ -128,9 +149,11 @@ void extract_AB_p_C(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_
128149
void extract_A_sse (uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
129150
void extract_B_sse (uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
130151
void extract_AB_sse (uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
152+
void extract_S_sse (uint16_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
131153
void extract_A_p_sse (uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
132154
void extract_B_p_sse (uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
133155
void extract_AB_p_sse(uint32_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
156+
void extract_S_p_sse (uint16_t *in, size_t len, size_t *clip, uint8_t *aux, int16_t *outA, int16_t *outB);
134157
int check_cpu_feat();
135158
#endif
136159

@@ -142,7 +165,7 @@ int main(int argc, char **argv)
142165
_setmode(_fileno(stdin), O_BINARY);
143166
#endif
144167

145-
int opt, pad=0;
168+
int opt, pad=0, single=0;
146169

147170

148171
//file adress
@@ -184,7 +207,7 @@ int main(int argc, char **argv)
184207
COPYRIGHT "\n\n"
185208
);
186209

187-
while ((opt = getopt(argc, argv, "i:a:b:x:p")) != -1) {
210+
while ((opt = getopt(argc, argv, "i:a:b:x:psh")) != -1) {
188211
switch (opt) {
189212
case 'i':
190213
input_name_1 = optarg;
@@ -201,13 +224,18 @@ int main(int argc, char **argv)
201224
case 'p':
202225
pad = 1;
203226
break;
227+
case 's':
228+
single = 1;
229+
break;
230+
case 'h':
204231
default:
205232
usage();
206233
break;
207234
}
208235
}
209236

210-
if(input_name_1 == NULL || (output_name_1 != NULL && output_name_2 != NULL && output_name_aux != NULL))
237+
if((input_name_1 == NULL || (output_name_1 != NULL && output_name_2 != NULL && output_name_aux != NULL))
238+
|| (single == 1 && output_name_2 != NULL))
211239
{
212240
usage();
213241
}
@@ -283,12 +311,14 @@ int main(int argc, char **argv)
283311
if(check_cpu_feat()==0) {
284312
fprintf(stderr,"Detected processor with SSSE3 and POPCNT, using optimized extraction routine\n\n");
285313
if (pad==1) {
286-
if (output_name_1 == NULL) conv_function = &extract_B_p_sse;
314+
if (single == 1) conv_function = (void (*)(uint32_t*, size_t, size_t*, uint8_t*, int16_t*, int16_t*)) &extract_S_p_sse;
315+
else if (output_name_1 == NULL) conv_function = &extract_B_p_sse;
287316
else if (output_name_2 == NULL) conv_function = &extract_A_p_sse;
288317
else conv_function = &extract_AB_p_sse;
289318
}
290319
else {
291-
if (output_name_1 == NULL) conv_function = &extract_B_sse;
320+
if (single == 1) conv_function = (void (*)(uint32_t*, size_t, size_t*, uint8_t*, int16_t*, int16_t*)) &extract_S_sse;
321+
else if (output_name_1 == NULL) conv_function = &extract_B_sse;
292322
else if (output_name_2 == NULL) conv_function = &extract_A_sse;
293323
else conv_function = &extract_AB_sse;
294324
}
@@ -297,12 +327,14 @@ int main(int argc, char **argv)
297327
fprintf(stderr,"Detected processor without SSSE3 and POPCNT, using standard extraction routine\n\n");
298328
#endif
299329
if (pad==1) {
300-
if (output_name_1 == NULL) conv_function = &extract_B_p_C;
330+
if (single == 1) conv_function = (void (*)(uint32_t*, size_t, size_t*, uint8_t*, int16_t*, int16_t*)) &extract_S_p_C;
331+
else if (output_name_1 == NULL) conv_function = &extract_B_p_C;
301332
else if (output_name_2 == NULL) conv_function = &extract_A_p_C;
302333
else conv_function = &extract_AB_p_C;
303334
}
304335
else {
305-
if (output_name_1 == NULL) conv_function = &extract_B_C;
336+
if (single == 1) conv_function = (void (*)(uint32_t*, size_t, size_t*, uint8_t*, int16_t*, int16_t*)) &extract_S_C;
337+
else if (output_name_1 == NULL) conv_function = &extract_B_C;
306338
else if (output_name_2 == NULL) conv_function = &extract_A_C;
307339
else conv_function = &extract_AB_C;
308340
}
@@ -318,7 +350,7 @@ int main(int argc, char **argv)
318350
clock_gettime(CLOCK_MONOTONIC, &start);
319351
#endif
320352

321-
nb_block = fread(buf_tmp,4,BUFFER_SIZE,input_1);
353+
nb_block = fread(buf_tmp,4>>single,BUFFER_SIZE,input_1);
322354

323355
#if PERF_MEASURE
324356
clock_gettime(CLOCK_MONOTONIC, &stop);

0 commit comments

Comments
 (0)