-
Notifications
You must be signed in to change notification settings - Fork 38
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 crc32 jet #653
Merged
Merged
Add crc32 jet #653
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e9647a4
Add crc32 jet
nathanlever d7bb2c9
add zlib to dependencies
nathanlever 2d10d98
remove old jet registration comments, correct crc32 parentheses
nathanlever bfd29c0
fix leading-zero placement
nathanlever b3987e2
crc: tidy up the crc32 jet
pkova a6eac43
crc: crc -> crc_w
pkova 1e6253d
crc: fix bogus head
pkova 9e10ece
crc: add comment to move the jet to 137
pkova 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,56 @@ | ||
/// @file | ||
|
||
#include <stdio.h> | ||
#include <allocate.h> | ||
#include "zlib.h" | ||
|
||
#include "jets/w.h" | ||
|
||
#include "noun.h" | ||
|
||
u3_noun | ||
u3qe_crc32(u3_noun input_octs) | ||
{ | ||
u3_atom head = u3h(input_octs); | ||
u3_atom tail = u3t(input_octs); | ||
c3_w tel_w = u3r_met(3, tail); | ||
c3_w hed_w = u3r_met(3, head); | ||
c3_y* input; | ||
|
||
if (c3y == u3a_is_cat(tail)) { | ||
input = &tail; | ||
} | ||
else { | ||
u3a_atom* vat_u = u3a_to_ptr(tail); | ||
input = (c3_y*)vat_u->buf_w; | ||
} | ||
|
||
if ( tel_w > hed_w ) { | ||
return u3m_error("subtract-underflow"); | ||
} | ||
|
||
c3_w led_w = hed_w - tel_w; | ||
c3_w crc_w = 0; | ||
|
||
crc_w = crc32(crc_w, input, tel_w); | ||
|
||
while ( led_w > 0 ) { | ||
c3_y byt_y = 0; | ||
crc_w = crc32(crc_w, &byt_y, 1); | ||
led_w--; | ||
} | ||
|
||
return u3i_word(crc_w); | ||
} | ||
|
||
u3_noun | ||
u3we_crc32(u3_noun cor) | ||
{ | ||
u3_noun a = u3r_at(u3x_sam, cor); | ||
|
||
if ( (u3du(a) == c3y) && (u3ud(u3h(a)) == c3y) && (u3ud(u3t(a)) == c3y) ) { | ||
return u3qe_crc32(a); | ||
} else { | ||
return u3m_bail(c3__exit); | ||
} | ||
} |
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
Oops, something went wrong.
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.
hed_w
should be the value ofhead
as ac3_w
, not its byte-width.