FFmpeg
llauddsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Alexandra Hájková
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <string.h>
22 
23 #include "libavutil/common.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/mem_internal.h"
27 
29 
30 #include "checkasm.h"
31 
32 #define randomize_buf(buf, len) \
33  do { \
34  for (int i = 0; i < len; i++) \
35  buf[i] = rnd(); \
36  } while (0)
37 
39 {
40 #define BUF_SIZE 1088 // multiple of 16
41  LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
42  LOCAL_ALIGNED_16(int16_t, v2, [BUF_SIZE]);
43  LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
44  int mul;
45 
46  declare_func(int32_t, int16_t *, const int16_t *, const int16_t *,
47  int, int);
48 
52  mul = rnd();
53 
54  if (check_func(c->scalarproduct_and_madd_int16,
55  "scalarproduct_and_madd_int16")) {
56  LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
57  LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
58  int ref, val;
59 
60  memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
61  memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
62  ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
63  val = call_new(dst1, v2, v3, BUF_SIZE, mul);
64  if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
65  fail();
66 
67  bench_new(v1, v2, v3, BUF_SIZE, mul);
68  }
69 
70  report("scalarproduct_and_madd_int16");
71 }
72 
74 {
75 #define BUF_SIZE 1088 // multiple of 16
76  LOCAL_ALIGNED_16(int16_t, v1, [BUF_SIZE]);
78  LOCAL_ALIGNED_16(int16_t, v3, [BUF_SIZE]);
79  int mul;
80 
81  declare_func(int32_t, int16_t *, const int32_t *, const int16_t *,
82  int, int);
83 
87  mul = rnd();
88 
89  if (check_func(c->scalarproduct_and_madd_int32,
90  "scalarproduct_and_madd_int32")) {
91  LOCAL_ALIGNED_16(int16_t, dst0, [BUF_SIZE]);
92  LOCAL_ALIGNED_16(int16_t, dst1, [BUF_SIZE]);
93  int ref, val;
94 
95  memcpy(dst0, v1, sizeof (*dst0) * BUF_SIZE);
96  memcpy(dst1, v1, sizeof (*dst1) * BUF_SIZE);
97  ref = call_ref(dst0, v2, v3, BUF_SIZE, mul);
98  val = call_new(dst1, v2, v3, BUF_SIZE, mul);
99  if (memcmp(dst0, dst1, sizeof (*dst0) * BUF_SIZE) != 0 || ref != val)
100  fail();
101 
102  bench_new(v1, v2, v3, BUF_SIZE, mul);
103  }
104 
105  report("scalarproduct_and_madd_int32");
106 }
107 
109 {
111 
115 }
mem_internal.h
check_func
#define check_func(func,...)
Definition: checkasm.h:170
call_ref
#define call_ref(...)
Definition: checkasm.h:185
ff_llauddsp_init
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
Definition: lossless_audiodsp.c:57
randomize_buf
#define randomize_buf(buf, len)
Definition: llauddsp.c:32
check_scalarproduct_and_madd_int32
static void check_scalarproduct_and_madd_int32(LLAudDSPContext *c)
Definition: llauddsp.c:73
fail
#define fail()
Definition: checkasm.h:179
checkasm.h
val
static double val(void *priv, double ch)
Definition: aeval.c:78
rnd
#define rnd()
Definition: checkasm.h:163
intreadwrite.h
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:150
BUF_SIZE
#define BUF_SIZE
LLAudDSPContext
Definition: lossless_audiodsp.h:28
call_new
#define call_new(...)
Definition: checkasm.h:288
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
report
#define report
Definition: checkasm.h:182
bench_new
#define bench_new(...)
Definition: checkasm.h:358
common.h
lossless_audiodsp.h
checkasm_check_llauddsp
void checkasm_check_llauddsp(void)
Definition: llauddsp.c:108
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
check_scalarproduct_and_madd_int16
static void check_scalarproduct_and_madd_int16(LLAudDSPContext *c)
Definition: llauddsp.c:38
mem.h
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:174
int32_t
int32_t
Definition: audioconvert.c:56