-
Notifications
You must be signed in to change notification settings - Fork 48
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
add no_std feature #13
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
extern crate build_const; | ||
|
||
pub fn make_table_crc32(poly: u32) -> [u32; 256] { | ||
let mut table = [0u32; 256]; | ||
for i in 0..256 { | ||
let mut value = i as u32; | ||
for _ in 0..8 { | ||
value = if (value & 1) == 1 { | ||
(value >> 1) ^ poly | ||
} else { | ||
value >> 1 | ||
} | ||
} | ||
table[i] = value; | ||
} | ||
table | ||
} | ||
|
||
pub fn make_table_crc64(poly: u64) -> [u64; 256] { | ||
let mut table = [0u64; 256]; | ||
for i in 0..256 { | ||
let mut value = i as u64; | ||
for _ in 0..8 { | ||
value = if (value & 1) == 1 { | ||
(value >> 1) ^ poly | ||
} else { | ||
value >> 1 | ||
} | ||
} | ||
table[i] = value; | ||
} | ||
table | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
fn create_constants() { | ||
let mut crc32 = build_const::ConstWriter::for_build("crc32_constants") | ||
.unwrap() | ||
.finish_dependencies(); | ||
let CASTAGNOLI: u32 = 0x82f63b78; | ||
crc32.add_value("CASTAGNOLI", "u32", CASTAGNOLI); | ||
crc32.add_array("CASTAGNOLI_TABLE", "u32", &make_table_crc32(CASTAGNOLI)); | ||
|
||
let IEEE: u32 = 0xedb88320; | ||
crc32.add_value("IEEE", "u32", IEEE); | ||
crc32.add_array("IEEE_TABLE", "u32", &make_table_crc32(IEEE)); | ||
|
||
let KOOPMAN: u32 = 0xeb31d82e; | ||
crc32.add_value("KOOPMAN", "u32", KOOPMAN); | ||
crc32.add_array("KOOPMAN_TABLE", "u32", &make_table_crc32(KOOPMAN)); | ||
|
||
crc32.finish(); | ||
|
||
let mut crc64 = build_const::ConstWriter::for_build("crc64_constants") | ||
.unwrap() | ||
.finish_dependencies(); | ||
|
||
let ECMA: u64 = 0xc96c5795d7870f42; | ||
crc64.add_value("ECMA", "u64", ECMA); | ||
crc64.add_array("ECMA_TABLE", "u64", &make_table_crc64(ECMA)); | ||
|
||
let ISO: u64 = 0xd800000000000000; | ||
crc64.add_value("ISO", "u64", ISO); | ||
crc64.add_array("ISO_TABLE", "u64", &make_table_crc64(ISO)); | ||
|
||
crc64.finish(); | ||
} | ||
|
||
fn main() { | ||
create_constants(); | ||
} | ||
|
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
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.
does it make sense to move these two make table fns to a util file/module so that we don't have to repeat them in crc32.rs and crc64.rs
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.
We could move them into an internal "crate" which both
build.rs
and the individual modules depend on. I can do that if you would like.I also didn't like copy/pasting them.
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.
moving
make_table
out of crc32/crc64 is a breaking change since they're publici'll see weather we could reference them in build.rs after merging.
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.
I was thinking we could have an internal crate which
build.rs
used and some of the functions were re-exported incrc32
andcrc64
-- making it non-breaking.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.
good point. let me try that
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.
#16 was created to address this