1 /* Copyright (c) 2011 Xiph.Org Foundation
2 Written by Gregory Maxwell */
3 /*
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 - Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
19 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
deb2_impl(unsigned char * _t,unsigned char ** _p,int _k,int _x,int _y)28 static OPUS_INLINE void deb2_impl(unsigned char *_t,unsigned char **_p,int _k,int _x,int _y)
29 {
30 int i;
31 if(_x>2){
32 if(_y<3)for(i=0;i<_y;i++)*(--*_p)=_t[i+1];
33 }else{
34 _t[_x]=_t[_x-_y];
35 deb2_impl(_t,_p,_k,_x+1,_y);
36 for(i=_t[_x-_y]+1;i<_k;i++){
37 _t[_x]=i;
38 deb2_impl(_t,_p,_k,_x+1,_x);
39 }
40 }
41 }
42
43 /*Generates a De Bruijn sequence (k,2) with length k^2*/
debruijn2(int _k,unsigned char * _res)44 static OPUS_INLINE void debruijn2(int _k, unsigned char *_res)
45 {
46 unsigned char *p;
47 unsigned char *t;
48 t=malloc(sizeof(unsigned char)*_k*2);
49 memset(t,0,sizeof(unsigned char)*_k*2);
50 p=&_res[_k*_k];
51 deb2_impl(t,&p,_k,1,1);
52 free(t);
53 }
54
55 /*MWC RNG of George Marsaglia*/
56 static opus_uint32 Rz, Rw;
fast_rand(void)57 static OPUS_INLINE opus_uint32 fast_rand(void)
58 {
59 Rz=36969*(Rz&65535)+(Rz>>16);
60 Rw=18000*(Rw&65535)+(Rw>>16);
61 return (Rz<<16)+Rw;
62 }
63 static opus_uint32 iseed;
64
65 #ifdef __GNUC__
66 __attribute__((noreturn))
67 #elif defined(_MSC_VER)
68 __declspec(noreturn)
69 #endif
_test_failed(const char * file,int line)70 static OPUS_INLINE void _test_failed(const char *file, int line)
71 {
72 fprintf(stderr,"\n ***************************************************\n");
73 fprintf(stderr," *** A fatal error was detected. ***\n");
74 fprintf(stderr," ***************************************************\n");
75 fprintf(stderr,"Please report this failure and include\n");
76 fprintf(stderr,"'make check SEED=%u fails %s at line %d for %s'\n",iseed,file,line,opus_get_version_string());
77 fprintf(stderr,"and any relevant details about your system.\n\n");
78 #if defined(_MSC_VER)
79 _set_abort_behavior( 0, _WRITE_ABORT_MSG);
80 #endif
81 abort();
82 }
83 #define test_failed() _test_failed(__FILE__, __LINE__);
84
85 void regression_test(void);
86