OpenCores
URL https://opencores.org/ocsvn/reedsolomon/reedsolomon/trunk

Subversion Repositories reedsolomon

[/] [reedsolomon/] [trunk/] [cpp-source/] [berlekamp.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 abhiag
//----------------------------------------------------------------------//
2
// The MIT License 
3
// 
4
// Copyright (c) 2010 Abhinav Agarwal, Alfred Man Cheuk Ng
5
// Contact: abhiag@gmail.com
6
// 
7
// Permission is hereby granted, free of charge, to any person 
8
// obtaining a copy of this software and associated documentation 
9
// files (the "Software"), to deal in the Software without 
10
// restriction, including without limitation the rights to use,
11
// copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the
13
// Software is furnished to do so, subject to the following conditions:
14
// 
15
// The above copyright notice and this permission notice shall be
16
// included in all copies or substantial portions of the Software.
17
// 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
// OTHER DEALINGS IN THE SOFTWARE.
26
//----------------------------------------------------------------------//
27
 
28
#include "global_rs.h"
29
#include "gf_arith.h"
30
#include "berlekamp.h"
31
 
32
// Directive: Synthesize independently
33
void gfmult_array_array_hw (unsigned char res_vec[tt+2], unsigned char in_vec0[tt+2], unsigned char in_vec1[tt+2])
34
{
35
// Directive: Unroll loop maximally
36
  for (int i = 0; i < tt+2; ++i)
37
    res_vec[i] = gfmult_hw(in_vec0[i],in_vec1[i]);
38
}
39
 
40
// Directive: Synthesize independently
41
void gfmult_scalar_array_hw1 (unsigned char res_vec[tt+2], unsigned char val, unsigned char in_vec[tt+2])
42
{
43
// Directive: Unroll loop maximally
44
  for (int i = 0; i < tt+2; ++i)
45
    res_vec[i] = gfmult_hw(val,in_vec[i]);
46
}
47
 
48
// Directive: Synthesize independently
49
void gfmult_scalar_array_hw2 (unsigned char res_vec[tt+2], unsigned char val, unsigned char in_vec[tt+2])
50
{
51
// Directive: Unroll loop maximally
52
  for (int i = 0; i < tt+2; ++i)
53
    res_vec[i] = gfmult_hw(val,in_vec[i]);
54
}
55
 
56
// Directive: Synthesize independently
57
void gfadd_array_array_hw1 (unsigned char in_vec0[tt+2], unsigned char in_vec1[tt+2])
58
{
59
// Directive: Unroll loop maximally
60
  for (int i = 0; i < tt+2; ++i)
61
    in_vec0[i] = gfadd_hw(in_vec0[i], in_vec1[i]);
62
}
63
 
64
// Directive: Synthesize independently
65
void gfadd_array_array_hw2 (unsigned char in_vec0[tt+2], unsigned char in_vec1[tt+2])
66
{
67
// Directive: Unroll loop maximally
68
  for (int i = 0; i < tt+2; ++i)
69
    in_vec0[i] = gfadd_hw(in_vec0[i], in_vec1[i]);
70
}
71
 
72
 
73
// Directive: Synthesize independently
74
unsigned char gfsum_array_hw (unsigned char in_vec[tt+2])
75
{
76
  unsigned char res = 0;
77
 
78
  // Directive: Unroll loop maximally
79
  for (int i = 0; i < tt+2; ++i)
80
    res = gfadd_hw(res, in_vec[i]);
81
 
82
  return res;
83
}
84
 
85
#pragma hls_design 
86
void berlekamp (unsigned char t, unsigned char s[2*tt], unsigned char c_out[tt], unsigned char w_out[tt])
87
{
88
  unsigned char l = 0;
89
  unsigned char p[tt+2];
90
  unsigned char a[tt+2];
91
  unsigned char t1[tt+2];
92
  unsigned char t2[tt+2];
93
  unsigned char syn_shift_reg[tt+2];
94
  unsigned char temp[tt+2];
95
  unsigned char c[tt+2];
96
  unsigned char w[tt+2];
97
 
98
  c[0] = 1;
99
  p[0] = 1;
100
  w[0] = 0;
101
  a[0] = 1;
102
  syn_shift_reg[0] = 0;
103
  temp[0] = 0;
104
 
105
  // Directive: Unroll loop maximally
106
  BerlInit: for (int i = 1; i < tt+2; i++)
107
  {
108
    c [i] = 0;
109
    w [i] = 0;
110
    p [i] = 0;
111
    a [i] = 0;
112
    t1[i] = 0;
113
    t2[i] = 0;
114
    syn_shift_reg[i] = 0;
115
    temp[i] = 0;
116
  }
117
 
118
  unsigned char dstar = 1;
119
  unsigned char d = 0;
120
  unsigned char ddstar = 1;
121
   BerlOuter:
122
   for (int i = 0; i < 2*tt; i++ )
123
   {
124
      // Directive: Unroll loop maximally 
125
      BerlShift: for (int k = tt+1; k > 0; --k)
126
      {
127
          syn_shift_reg[k] = syn_shift_reg[k-1];
128
          p[k] = p[k-1];
129
          a[k] = a[k-1];
130
      }
131
      syn_shift_reg[0] = s[i];
132
      p[0] = 0;
133
      a[0] = 0;
134
 
135
      gfmult_array_array_hw(temp, c, syn_shift_reg);
136
      d = gfsum_array_hw(temp);
137
 
138
      if (d != 0)
139
      {
140
             ddstar = gfmult_hw(d, dstar);
141
             // Directive: Unroll loop maximally
142
             BerlSimple1: for (int k = 0; k < tt+2; ++k)
143
         {
144
               t1 [k] = p [k];
145
               t2 [k] = a [k];
146
         }
147
 
148
         if (i + 1 > 2*l)
149
         {
150
                l = i - l + 1;
151
 
152
            // Directive: Unroll loop maximally
153
            BerlSimple2: for (int k = 0; k < tt+2; ++k)
154
            {
155
               p [k] = c [k];
156
               a [k] = w [k];
157
            }
158
            dstar = gfinv_lut ( d );
159
         }
160
 
161
         gfmult_scalar_array_hw1(temp, ddstar, t1);
162
         gfadd_array_array_hw1(c,temp);
163
         gfmult_scalar_array_hw2(temp, ddstar, t2);
164
         gfadd_array_array_hw2(w,temp);
165
 
166
      }
167
   }
168
 
169
   // Directive: Unroll loop maximally
170
   BerlCopy: for (int k = 0; k < tt; ++k)
171
   {
172
       c_out[k] = c[k+1];
173
       w_out[k] = w[k+1];
174
   }
175
}
176
 
177
 
178
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.