MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parity2D_4x4.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*- */
2 
3 /*
4  Parity2D_4x4.h Support for simple 2D parity management
5  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20  USA
21 */
22 
29 #ifndef PARITY2D_4x4_H
30 #define PARITY2D_4x4_H
31 
32 #include "itype.h"
33 
34 namespace MFM {
35 
61  {
62  public:
63  enum {
64  W = 4,
65  H = 4,
66  DATA_BITS = W * H,
67  ECC_BITS = W + H + 1,
68  TABLE_SIZE = 1 << DATA_BITS,
69  INDEX_MASK = TABLE_SIZE - 1,
70  ECC_MASK = (1 << ECC_BITS) - 1
71  };
72 
97  static u32 Compute2DParity(u32 dataBits) {
98  return eccTable[dataBits&INDEX_MASK];
99  }
100 
101  static u32 ComputeParitySlow(u32 dataBits);
102 
109  static u32 Add2DParity(u32 dataBits) {
110  return (dataBits&INDEX_MASK) | (Compute2DParity(dataBits) << DATA_BITS);
111  }
112 
124  static bool Remove2DParity(u32 allBits, u32 & dataBits) {
125  u32 corrected = CheckAndCorrect2DParity(allBits);
126  if (corrected == 0)
127  return false;
128  dataBits = corrected&INDEX_MASK;
129  return true;
130  }
131 
145  static bool Check2DParity(const u32 allBits) {
146  u32 eccBits = (allBits>>DATA_BITS) & ECC_MASK;
147  u32 dataBits = allBits&INDEX_MASK;
148  return Compute2DParity(dataBits) == eccBits;
149  }
150 
167  static u32 CheckAndCorrect2DParity(const u32 allBits) {
168  u32 eccBits = (allBits>>DATA_BITS) & ECC_MASK;
169  u32 dataBits = allBits&INDEX_MASK;
170  if (Compute2DParity(dataBits) == eccBits)
171  return allBits;
172  return Correct2DParityIfPossible(allBits);
173  }
174 
190  static u32 Correct2DParityIfPossible(u32 allBits);
191 
192  static const u8 indices2D[H + 1][W + 1];
193 
194  private:
195  static const u16 eccTable[TABLE_SIZE];
196  static const u32 masks[H + 1 + W + 1];
197  };
198 } /* namespace MFM */
199 
200 #endif /*PARITY2D_4x4_H*/
201 
static u32 Add2DParity(u32 dataBits)
Definition: Parity2D_4x4.h:109
static bool Remove2DParity(u32 allBits, u32 &dataBits)
Definition: Parity2D_4x4.h:124
Definition: Parity2D_4x4.h:60
static u32 Correct2DParityIfPossible(u32 allBits)
Definition: Parity2D_4x4.cpp:18
static u32 Compute2DParity(u32 dataBits)
Definition: Parity2D_4x4.h:97
static bool Check2DParity(const u32 allBits)
Definition: Parity2D_4x4.h:145
static u32 CheckAndCorrect2DParity(const u32 allBits)
Definition: Parity2D_4x4.h:167