]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/blobdiff - zfec/zfec/fec.c
stick a .gitignore file
[tahoe-lafs/zfec.git] / zfec / zfec / fec.c
index 0fb2f1b98e48fd30628a54b79bb4c2c73d0dcd3d..751c00a77ebad4cec3f5169d7abcf9cc7d38c43b 100644 (file)
@@ -9,21 +9,6 @@
 #include <string.h>
 #include <assert.h>
 
-#if defined(_MSC_VER)
-// actually, some of the flavors (i.e. Enterprise) do support restrict
-//#define restrict __restrict
-#define restrict
-#define inline __inline
-#define alloca _alloca
-#else
-#ifdef __GNUC__
-#define alloca(x) __builtin_alloca(x)
-#else
-#include <alloca.h>
-#endif
-#endif
-
-
 /*
  * Primitive polynomials - see Lin & Costello, Appendix A,
  * and  Lee & Messerschmitt, p. 453.
@@ -49,7 +34,7 @@ static gf inverse[256]; /* inverse of field elem.               */
  * modnn(x) computes x % GF_SIZE, where GF_SIZE is 2**GF_BITS - 1,
  * without a slow divide.
  */
-static inline gf
+static gf
 modnn(int x) {
     while (x >= 255) {
         x -= 255;
@@ -427,7 +412,7 @@ fec_free (fec_t *p) {
 }
 
 fec_t *
-fec_new(unsigned k, unsigned n) {
+fec_new(unsigned short k, unsigned short n) {
     unsigned row, col;
     gf *p, *tmp_m;
 
@@ -471,9 +456,11 @@ fec_new(unsigned k, unsigned n) {
     return retval;
 }
 
-/* To make sure that we stay within cache in the inner loops of fec_encode()
-   and fec_decode(). */
+/* To make sure that we stay within cache in the inner loops of fec_encode().  (It would
+   probably help to also do this for fec_decode(). */
+#ifndef STRIDE
 #define STRIDE 8192
+#endif
 
 void
 fec_encode(const fec_t* code, const gf*restrict const*restrict const src, gf*restrict const*restrict const fecs, const unsigned*restrict const block_nums, size_t num_block_nums, size_t sz) {
@@ -524,6 +511,7 @@ fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*
     build_decode_matrix_into_space(code, index, code->k, m_dec);
 
     for (row=0; row<code->k; row++) {
+        assert ((index[row] >= code->k) || (index[row] == row)); /* If the block whose number is i is present, then it is required to be in the i'th element. */
         if (index[row] >= code->k) {
             memset(outpkts[outix], 0, sz);
             for (col=0; col < code->k; col++)
@@ -535,13 +523,13 @@ fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*
 
 /**
  * zfec -- fast forward error correction library with Python interface
- * 
- * Copyright (C) 2007 Allmydata, Inc.
+ *
+ * Copyright (C) 2007-2010 Zooko Wilcox-O'Hearn
  * Author: Zooko Wilcox-O'Hearn
- * 
+ *
  * This file is part of zfec.
- * 
- * See README.txt for licensing information.
+ *
+ * See README.rst for licensing information.
  */
 
 /*
@@ -554,7 +542,7 @@ fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*
  * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari
  * Thirumoorthy (harit@spectra.eng.hawaii.edu), Aug 1995
  *
- * Modifications by Dan Rubenstein (see Modifications.txt for 
+ * Modifications by Dan Rubenstein (see Modifications.txt for
  * their description.
  * Modifications (C) 1998 Dan Rubenstein (drubenst@cs.umass.edu)
  *