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  ld_Bfr <<= N;
142 
143  Incnt = ld_Incnt -= N;
144 
145  if (Incnt <= 24)
146  {
147  if (ld_Rdptr < ld_Rdbfr + 2044)
148  {
149  do
150  {
151  ld_Bfr |= *ld_Rdptr++ << (24 - Incnt);
152  Incnt += 8;
153  }
154  while (Incnt <= 24);
155  }
156  else
157  {
158  do
159  {
160  if (ld_Rdptr >= ld_Rdbfr + 2048)
161  Fill_Buffer ();
162  ld_Bfr |= *ld_Rdptr++ << (24 - Incnt);
163  Incnt += 8;
164  }
165  while (Incnt <= 24);
166  }
167  ld_Incnt = Incnt;
168  }
169 }
170 
171 
172 /* return next n bits (right adjusted) */
173 
174 unsigned int
176  int N;
177 {
178  unsigned int Val;
179 
180  Val = Show_Bits (N);
181  Flush_Buffer (N);
182 
183  return Val;
184 }
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