Skip to content

Add $crc32() function for CRC-32 checksum computation#101

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/add-crc-checksum-support
Draft

Add $crc32() function for CRC-32 checksum computation#101
Copilot wants to merge 5 commits intomasterfrom
copilot/add-crc-checksum-support

Conversation

Copy link

Copilot AI commented Dec 3, 2025

  • Understand the problem statement: Add CRC/checksum support to Emboss
  • Add CRC32 function support to Emboss compiler and runtime
  • Add unit tests for CRC-32 implementation
    • Tests for empty input
    • Tests for known test vectors (e.g., "123456789" -> 0xCBF43926)
    • Tests for single bytes (0x00, 0xFF)
    • Tests for multi-byte sequences
    • Tests for lookup table correctness
    • Tests for longer messages
Original prompt

This section details on the original issue you should resolve

<issue_title>CRC/Checksum Support</issue_title>
<issue_description>This issue was copied from the upstream repository google/emboss.

Original issue: google#31
Original state: open, created at: 2022-02-15T23:11:57Z, updated at: 2024-12-18T23:14:41Z, by @reventlov


Original description

CRCs and checksums are common enough that there should be built-in support for verifying and setting CRCs/checksums to the correct value. One possible implementation would be $crc(range : UInt:8[]) and $checksum(range : UInt:8[]) functions which can be used in [requires].


Discussion (copied comments)

Comment by @AaronWebster on 2022-03-14T17:52:47Z:

Would be useful if the type could be specified, e.g. $checksum(type : CRC32C, range : UInt:8[]). Maybe more useful if Emboss had a way of supporting a type whose value was computed using a user-defined function.


Comment by @reventlov on 2022-03-14T19:44:32Z:

I was thinking $crc() and $checksum() specifically so that you don't have to specify which algorithm as a parameter. User-defined functions would be nice, but a much bigger feature to design.

$crc() should have an optional parameter for the polynomial, though. Probably default to the IEEE polynomial, at least for CRC-32.

We also need some way to specify how many bits are in the CRC/checksum.


Comment by @AaronWebster on 2022-03-15T17:28:34Z:

pycrc might be a good fit using its c code generator. Supports arbitrary polynomials/bits/endianness/etc.


Comment by @reventlov on 2022-03-15T20:50:24Z:

Something like CRC_t is probably better: a C++ template takes advantage of the C++ compiler to avoid having multiple copies of the same code or extra unneeded code in the final binary, even across translation units.

We would need to import a copy and shove it into a different namespace to avoid potential version skew between the copy in Emboss and a copy that happens to be used in application code.

Also, it would be good to add some options to the C++ backend or site_defines.h to allow applications to pick their own implementation. I assume a lot of embedded projects will already have a CRC library somewhere; we should use theirs when possible instead of adding binary image size.


</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 3, 2025 21:31
- Add CRC FunctionMapping in ir_data.py
- Add $crc32 token to tokenizer.py
- Add $crc32 function parsing in module_ir.py
- Add $crc32 type checking in type_check.py
- Add $crc32 expression bounds computation in expression_bounds.py
- Add $crc32 code generation in header_generator.py
- Add C++ CRC32 implementation in emboss_crc.h
- Include emboss_crc.h in emboss_cpp_util.h
- Add $crc32 to format_emb.py formatter
- Update grammar.md with new function
- Regenerate cached_parser.py
- Add __init__.py to generated directory
- Add test cases in module_ir_test.py and format test files

Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
- Remove trailing whitespace from expression_bounds.py docstring
- Add performance note to emboss_crc.h CRC32 implementation

Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
- Add $crc32() function documentation
- Add $crc32 to operators precedence list

Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
Copilot AI changed the title [WIP] Add built-in support for CRC and checksum functions Add $crc32() function for CRC-32 checksum computation Dec 3, 2025
Copilot AI requested a review from AaronWebster December 3, 2025 21:40
@AaronWebster
Copy link
Owner

@copilot wright unit tests for the CRC implementation

- Add emboss_crc_test.cc with comprehensive tests for the Crc32 function
- Test empty input, known test vectors (e.g., "123456789" -> 0xCBF43926)
- Test single bytes, multi-byte sequences, and longer messages
- Test lookup table correctness
- Add test target to BUILD file

Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 6, 2025

@copilot wright unit tests for the CRC implementation

Added unit tests for the CRC-32 implementation in commit 457af49. The tests cover:

  • Empty input
  • Well-known test vector "123456789" → 0xCBF43926
  • Single byte inputs (0x00, 0xFF)
  • Multi-byte sequences
  • Lookup table correctness verification
  • Longer message ("The quick brown fox...")

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.googleapis.com
    • Triggering command: /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 test //runtime/cpp/test:emboss_crc_test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRC/Checksum Support

2 participants