-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hard-code global tables' contents instead of calculating them at run-time #131
Draft
adrianmay
wants to merge
43
commits into
tahoe-lafs:master
Choose a base branch
from
adrianmay:init-tables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+581
−371
Draft
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
ac17dd1
Remove uses of unsafePerformIO
exarkun 9ffd704
Add an aggressive property test for encoding sanely
exarkun 989f90f
Merge remote-tracking branch 'origin/master' into remove-unsafePerformIO
exarkun e452854
Adapt to switch to quickcheck-instances
exarkun eb47bfc
Adapt to enFEC and deFEC being in IO
exarkun ec5e1dd
let fourmolu do its thing
exarkun 768fe4e
bump version to reflect incompatible change
exarkun 390bfad
prefer where over let
exarkun b515dbf
remove redundant parens
exarkun 3820caa
prefer where over let
exarkun 1fa8a58
more frequent failure reproduction
exarkun 40beb48
Initialise tables instead of calculating them at run time
adrianmay 2108bbc
Bump version, add changelog entry
adrianmay fc4d19d
Merge remote-tracking branch 'origin/master' into inittables
adrianmay dfefc04
Update a comment about fec_init
adrianmay 4ce97ec
Fix typo
adrianmay e51db10
Merge from master
adrianmay 31bbbaa
Merge from master
adrianmay 28cc766
Merge from master
adrianmay 3527617
Merge commit '14fc79b' into slowmerge
adrianmay 923f11a
Merge commit '6de0374' into slowmerge
adrianmay a23f2a7
Fix errors and warnings
adrianmay 882c5c9
Bump major version
adrianmay 29bffee
Bump major version
adrianmay e81cc13
Completely remove fec_init and Haskell's initialize
adrianmay 519b64b
Use a better lock
adrianmay 05da318
Merge better lock from remove-unsafePerformIO to init-tables
adrianmay bf0e50d
Reduce cabal version contraints to hackage rules
adrianmay a27931c
Merge branch 'remove-unsafePerformIO' into init-tables
adrianmay 2e9f5ac
Oops: reinstate uninitialised check
adrianmay 1e650f8
Merge from remove-unsafePerformIO
adrianmay 977fa5e
Move code that's purely for table generation to write.c
adrianmay 096aaf4
Typo
adrianmay 7c8629a
Merge remote-tracking branch 'tahoe/127.pypi-trusted-publishing' into…
adrianmay fde70c3
Merge branch 'remove-unsafePerformIO' into init-tables
adrianmay 8a4d067
Add workflow-dispatch trigger so I can manually start CI
adrianmay 25ee0d9
Typo
adrianmay dd99b5f
Another typo
adrianmay 31507fb
Merge branch 'master' into remove-unsafePerformIO
adrianmay fde8efd
Merge branch 'remove-unsafePerformIO' into init-tables
adrianmay 0e782f7
Undoing workflow_dispatch cos it didn't do anything
adrianmay c4781a5
Merge branch 'remove-unsafePerformIO' into init-tables
adrianmay 2fd7156
Removing the irrelevant distraction of py310
adrianmay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This is not part of the main build but is included for reference only. | ||
# It is used to generate tables.c, but that's been done and the result committed to source control. | ||
|
||
tables.c: write.c fec.c fec.h Makefile | ||
touch tables.c | ||
gcc -o write write.c && ./write > tables.c | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// This is not part of the main build but is included for reference onby. | ||
// It's used to generate tables.c, but that's been done and the result committed to source control. | ||
|
||
#include "fec.c" | ||
|
||
/* | ||
* Primitive polynomials - see Lin & Costello, Appendix A, | ||
* and Lee & Messerschmitt, p. 453. | ||
*/ | ||
static const char*const Pp="101110001"; | ||
static int gf_log[256]; /* Poly->index form conversion table */ | ||
|
||
/* | ||
* Generate GF(2**m) from the irreducible polynomial p(X) in p[0]..p[m] | ||
* Lookup tables: | ||
* index->polynomial form gf_exp[] contains j= \alpha^i; | ||
* polynomial form -> index form gf_log[ j = \alpha^i ] = i | ||
* \alpha=x is the primitive element of GF(2^m) | ||
* | ||
* For efficiency, gf_exp[] has size 2*GF_SIZE, so that a simple | ||
* multiplication of two numbers can be resolved without calling modnn | ||
*/ | ||
static void | ||
_init_mul_table(void) { | ||
int i, j; | ||
for (i = 0; i < 256; i++) | ||
for (j = 0; j < 256; j++) | ||
gf_mul_table[i][j] = gf_exp[modnn (gf_log[i] + gf_log[j])]; | ||
|
||
for (j = 0; j < 256; j++) | ||
gf_mul_table[0][j] = gf_mul_table[j][0] = 0; | ||
} | ||
|
||
/* | ||
* initialize the data structures used for computations in GF. | ||
*/ | ||
static void | ||
generate_gf (void) { | ||
int i; | ||
gf mask; | ||
|
||
mask = 1; /* x ** 0 = 1 */ | ||
gf_exp[8] = 0; /* will be updated at the end of the 1st loop */ | ||
/* | ||
* first, generate the (polynomial representation of) powers of \alpha, | ||
* which are stored in gf_exp[i] = \alpha ** i . | ||
* At the same time build gf_log[gf_exp[i]] = i . | ||
* The first 8 powers are simply bits shifted to the left. | ||
*/ | ||
for (i = 0; i < 8; i++, mask <<= 1) { | ||
gf_exp[i] = mask; | ||
gf_log[gf_exp[i]] = i; | ||
/* | ||
* If Pp[i] == 1 then \alpha ** i occurs in poly-repr | ||
* gf_exp[8] = \alpha ** 8 | ||
*/ | ||
if (Pp[i] == '1') | ||
gf_exp[8] ^= mask; | ||
} | ||
/* | ||
* now gf_exp[8] = \alpha ** 8 is complete, so can also | ||
* compute its inverse. | ||
*/ | ||
gf_log[gf_exp[8]] = 8; | ||
/* | ||
* Poly-repr of \alpha ** (i+1) is given by poly-repr of | ||
* \alpha ** i shifted left one-bit and accounting for any | ||
* \alpha ** 8 term that may occur when poly-repr of | ||
* \alpha ** i is shifted. | ||
*/ | ||
mask = 1 << 7; | ||
for (i = 9; i < 255; i++) { | ||
if (gf_exp[i - 1] >= mask) | ||
gf_exp[i] = gf_exp[8] ^ ((gf_exp[i - 1] ^ mask) << 1); | ||
else | ||
gf_exp[i] = gf_exp[i - 1] << 1; | ||
gf_log[gf_exp[i]] = i; | ||
} | ||
/* | ||
* log(0) is not defined, so use a special value | ||
*/ | ||
gf_log[0] = 255; | ||
/* set the extended gf_exp values for fast multiply */ | ||
for (i = 0; i < 255; i++) | ||
gf_exp[i + 255] = gf_exp[i]; | ||
|
||
/* | ||
* again special cases. 0 has no inverse. This used to | ||
* be initialized to 255, but it should make no difference | ||
* since noone is supposed to read from here. | ||
*/ | ||
inverse[0] = 0; | ||
inverse[1] = 1; | ||
for (i = 2; i <= 255; i++) | ||
inverse[i] = gf_exp[255 - gf_log[i]]; | ||
} | ||
|
||
|
||
/* This is the logic for setting up gf_exp, gf_log, gf_inverse and gf_mul_table. | ||
* It is not used at run time but has been invoked by write.c to generate | ||
* tables.c in which the contents of these tables are initialised verbatim. | ||
*/ | ||
void | ||
fec_init_internal (void) { | ||
generate_gf(); | ||
_init_mul_table(); | ||
} | ||
|
||
/* The above comprises all code used purely for table generation. | ||
* Now we just print the results | ||
*/ | ||
|
||
void print_table_int(const char * name, const int data[], int len) { | ||
printf("static int %s[%d]={", name, len); | ||
printf("%d", data[0]); | ||
for (int i=1; i<len; i++) printf(",%d", data[i]); | ||
printf("};\n\n"); | ||
} | ||
|
||
void print_gfs(const gf data[], int len) { | ||
printf("{%d", data[0]); | ||
for (int i=1; i<len; i++) printf(",%d", data[i]); | ||
printf("}"); | ||
} | ||
|
||
void print_table_gf(const char * name, const gf data[], int len) { | ||
printf("static gf %s[%d]=", name, len); | ||
print_gfs(data, len); | ||
printf(";\n\n"); | ||
} | ||
|
||
void print_table_gf_256_256(const char * name, const gf data[256][256]) { | ||
printf("static gf %s[256][256]={", name); | ||
print_gfs(data[0], 256); | ||
for (int i=1; i<256; i++) { | ||
printf(",\n"); | ||
print_gfs(data[i], 256); | ||
} | ||
printf("};\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
fec_init_internal(); | ||
print_table_gf("gf_exp", gf_exp, 510); | ||
print_table_int("gf_log", gf_log, 256); | ||
print_table_gf("inverse", inverse, 256); | ||
print_table_gf_256_256("gf_mul_table", gf_mul_table); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!