PandA-2024.02
getbits.c
Go to the documentation of this file.
1 /*
2 +--------------------------------------------------------------------------+
3 | CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4 | ======================================================================== |
5 | |
6 | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7 | H. Takada and K. Ishii |
8 | Nagoya University, Japan |
9 | |
10 | * Remark : |
11 | 1. This source code is modified to unify the formats of the benchmark |
12 | programs in CHStone. |
13 | 2. Test vectors are added for CHStone. |
14 | 3. If "main_result" is 0 at the end of the program, the program is |
15 | correctly executed. |
16 | 4. Please follow the copyright of each benchmark program. |
17 +--------------------------------------------------------------------------+
18 */
19 /* getbits.c, bit level routines */
20 
21 /*
22  * All modifications (mpeg2decode -> mpeg2play) are
23  * Copyright (C) 1996, Stefan Eckart. All Rights Reserved.
24  */
25 
26 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
27 
28 /*
29  * Disclaimer of Warranty
30  *
31  * These software programs are available to the user without any license fee or
32  * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
33  * any and all warranties, whether express, implied, or statuary, including any
34  * implied warranties or merchantability or of fitness for a particular
35  * purpose. In no event shall the copyright-holder be liable for any
36  * incidental, punitive, or consequential damages of any kind whatsoever
37  * arising from the use of these programs.
38  *
39  * This disclaimer of warranty extends to the user of these programs and user's
40  * customers, employees, agents, transferees, successors, and assigns.
41  *
42  * The MPEG Software Simulation Group does not represent or warrant that the
43  * programs furnished hereunder are free of infringement of any third-party
44  * patents.
45  *
46  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
47  * are subject to royalty fees to patent holders. Many of these patents are
48  * general enough such that they are unavoidable regardless of implementation
49  * design.
50  *
51  */
52 
53 
54 /* initialize buffer, call once before first getbits or showbits */
55 int
56 read (unsigned char *s1, const unsigned char *s2, int n)
57 {
58  unsigned char *p1;
59  const unsigned char *p2;
60  int n_tmp;
61 
62 p1 = s1;
63  p2 = s2;
64  n_tmp = n;
65 
66 while (n_tmp-- > 0)
67  {
68  *p1 = *p2;
69 
70 p1++;
71 
72 p2++;
73 
74 }
75 
76 return n;
77 }
78 
79 void
81 {
82  int Buffer_Level;
83  unsigned char *p;
84  p = ld_Rdbfr;
85 
86 
87  Buffer_Level = read (ld_Rdbfr, inRdbfr, 2048);
89 
91  ld_Rdmax -= 2048;
92 
93 
94  /* end of the bitstream file */
95  if (Buffer_Level < 2048)
96  {
97  /* just to be safe */
98  if (Buffer_Level < 0)
99  Buffer_Level = 0;
100 
101  /* pad until the next to the next 32-bit word boundary */
102  while (Buffer_Level & 3)
103  ld_Rdbfr[Buffer_Level++] = 0;
104 
105  /* pad the buffer with sequence end codes */
106  while (Buffer_Level < 2048)
107  {
108  ld_Rdbfr[Buffer_Level++] = SEQUENCE_END_CODE >> 24;
109  ld_Rdbfr[Buffer_Level++] = SEQUENCE_END_CODE >> 16;
110  ld_Rdbfr[Buffer_Level++] = SEQUENCE_END_CODE >> 8;
111  ld_Rdbfr[Buffer_Level++] = SEQUENCE_END_CODE & 0xff;
112  }
113  }
114 }
115 
116 unsigned int
118  int N;
119 {
120  return ld_Bfr >> (unsigned)(32-N)%32;
121 }
122 
123 
124 /* return next bit (could be made faster than Get_Bits(1)) */
125 
126 unsigned int
128 {
129  return Get_Bits (1);
130 }
131 
132 
133 /* advance by n bits */
134 
135 void
137  int N;
138 {
139  int Incnt;
140 
141 #ifdef RAND_VAL
142  /* N is between 0 and 20 with realistic input sets, while it may become larger than the width of the integer type when using randomly generated input sets which are used in the contained input set. The following is to avoid this. */
143  ld_Bfr <<= (N%20);
144 #else
145  ld_Bfr <<= N;
146 #endif
147 
148  Incnt = ld_Incnt -= N;
149 
150  if (Incnt <= 24)
151  {
152  if (ld_Rdptr < ld_Rdbfr + 2044)
153  {
154  do
155  {
156 #ifdef RAND_VAL
157  /* N is between 0 and 20 with realistic input sets, while it may become larger than the width of the integer type when using randomly generated input sets which are used in the contained input set. The following is to avoid this. */
158  ld_Bfr |= *ld_Rdptr++ << ((24 - Incnt)%20);
159 #else
160  ld_Bfr |= *ld_Rdptr++ << (24 - Incnt);
161 #endif
162  Incnt += 8;
163  }
164  while (Incnt <= 24);
165  }
166  else
167  {
168  do
169  {
170  if (ld_Rdptr >= ld_Rdbfr + 2048)
171  Fill_Buffer ();
172 #ifdef RAND_VAL
173  /* N is between 0 and 20 with realistic input sets, while it may become larger than the width of the integer type when using randomly generated input sets which are used in the contained input set. The following is to avoid this. */
174  ld_Bfr |= *ld_Rdptr++ << ((24 - Incnt)%20);
175 #else
176  ld_Bfr |= *ld_Rdptr++ << (24 - Incnt);
177 #endif
178  Incnt += 8;
179  }
180  while (Incnt <= 24);
181  }
182  ld_Incnt = Incnt;
183  }
184 }
185 
186 
187 /* return next n bits (right adjusted) */
188 
189 unsigned int
191  int N;
192 {
193  unsigned int Val;
194 
195  Val = Show_Bits (N);
196  Flush_Buffer (N);
197 
198  return Val;
199 }
void Flush_Buffer(int N)
Definition: getbits.c:136
unsigned int Get_Bits(int N)
Definition: getbits.c:190
const unsigned char inRdbfr[Num]
Definition: mpeg2.c:48
void Fill_Buffer()
Definition: getbits.c:80
int ld_Incnt
Definition: global.h:80
int System_Stream_Flag
Definition: global.h:75
int read(unsigned char *s1, const unsigned char *s2, int n)
Definition: getbits.c:56
unsigned char ld_Rdbfr[2048]
Definition: global.h:77
unsigned char * ld_Rdmax
Definition: global.h:78
unsigned int Show_Bits(int N)
Definition: getbits.c:117
#define N
Definition: dfdiv.c:60
unsigned char * ld_Rdptr
Definition: global.h:78
unsigned int Get_Bits1()
Definition: getbits.c:127
unsigned int ld_Bfr
Definition: global.h:79
#define SEQUENCE_END_CODE
Definition: mpeg2dec.h:49

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13