Skip to content

Add crc64 support#5047

Merged
dlang-bot merged 5 commits intodlang:masterfrom
deadalnix:crc64
May 21, 2017
Merged

Add crc64 support#5047
dlang-bot merged 5 commits intodlang:masterfrom
deadalnix:crc64

Conversation

@deadalnix
Copy link
Contributor

As per title.

@deadalnix
Copy link
Contributor Author

This is not quite ready yet, but as I can't run the tests manually because of https://issues.dlang.org/show_bug.cgi?id=17107 , I have to rely on autotester.

@deadalnix deadalnix force-pushed the crc64 branch 8 times, most recently from bcee6d5 to 689e438 Compare January 18, 2017 21:37
@deadalnix
Copy link
Contributor Author

Alright this is in better shape now. Tests are green? No idea what circle is unhappy about.

@JackStouffer
Copy link
Contributor

cc @wilzbach

@deadalnix
Copy link
Contributor Author

deadalnix commented Jan 19, 2017

Also, among interesting questions, CRC64 has 2 standards: ECMA and ISO. The algorithm is the same, but the polynomial is different ( 0xD800000000000000 for OSI, 0xC96C5795D7870F42 for ECMA ). ECMA is generally considered better, but maybe we'd like to support both ?

@deadalnix
Copy link
Contributor Author

Ok Added support for both CRC64-ECMA and CRC64-ISO, that wasn't significantly harder, and can be leveraged to do CRC32C and other variations as well.

@deadalnix
Copy link
Contributor Author

I have no idea why circle is complaining. That'd be great if someone would look at this is less than a week.

@JackStouffer
Copy link
Contributor

There seems to be a dearth of reviews in Phobos right now.

Do you know of anyone who would be qualified to review this code?

@deadalnix
Copy link
Contributor Author

@JackStouffer I asked someone who dug into this CRC thing with me to figure it out. He'll be able to assert the validitity of the algorithm, but is not an experimented D coder, so that'd be great to have someone checks that.

Also, I'd be glad if someone could explain me what circle is complaining about.


/**
* Generic Template API used for CRC32 and CRC64 implementations.
* See $(D std.digest.digest) for differences between template and OOP API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs Params section for N and P


static immutable T[256][8] tables = genTables!T(P);

alias R = ubyte[T.sizeof];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be documented as it shows up in the docs

@JackStouffer JackStouffer added this to the 2.074.0 milestone Feb 8, 2017
@JackStouffer
Copy link
Contributor

Also, needs a changelog entry

std/digest/crc.d Outdated
unittest
{
CRC32 dig;
CRC dig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the reason why CircleCi fails with:

out/std_digest_crc.d(46): Error: struct std.digest.crc.CRC(uint N, ulong P) if (N == 32 || N == 64) is used as a type
out/std_digest_crc.d(59): Error: struct std.digest.crc.CRC(uint N, ulong P) if (N == 32 || N == 64) is used as a type
out/std_digest_crc.d(71): Error: struct std.digest.crc.CRC(uint N, ulong P) if (N == 32 || N == 64) is used as a type
out/std_digest_crc.d(73): Error: undefined identifier 'R'

The script at CircleCi seperates all public unittests and tries to run them with the newly compiled release library to ensure that all unittests on dlang.org are runnable as they are.

Btw I remember there was a long discussion last summer about the problems of using unittest blocks in templated code - in short in theory it's discouraged at Phobos because the unittest block gets instantiated very every new instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the test is generated for each templates, it is a 3 line tests, so I don't think there is really any problem here.

@deadalnix
Copy link
Contributor Author

Sadly I find myself unable to continue this work.

https://issues.dlang.org/show_bug.cgi?id=17236

I was already required to jump though hoops to run the tests, but this is getting out of hands.

@wilzbach
Copy link
Contributor

wilzbach commented Mar 3, 2017

Sadly I find myself unable to continue this work.
I was already required to jump though hoops to run the tests, but this is getting out of hands.

As mentioned on the NG I am still not sure what your exact problem is.
In any case, you can always build a module directly if you have a recent DMD compiler, e.g.:

source $(curl https://i.dlang.io | bash -s dmd-nightly -a)

@JackStouffer JackStouffer added this to the 2.075.0 milestone Mar 7, 2017
@JackStouffer JackStouffer removed this from the 2.074.0 milestone Mar 7, 2017
@deadalnix
Copy link
Contributor Author

Added doc for N, P and R.

Rebased. I got various merge conflicts for style changes that arguably do not improve the code in any way. Especially the one which puts template constraint on their own line.

* CRC64-ECMA of data
*/
//simple alias doesn't work here, hope this gets inlined...
ubyte[8] crc64ECMAOf(T...)(T data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Circle, this needs an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what I'm expected to do here. I looked at crc32Of and there is no example. Is there a piece of code I can look at to know what to do ?

* CRC64-ISO of data
*/
//simple alias doesn't work here, hope this gets inlined...
ubyte[8] crc64ISOOf(T...)(T data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too too !

@JackStouffer
Copy link
Contributor

@deadalnix Was that person you mentioned able to verify the CRC code correctness?

@deadalnix
Copy link
Contributor Author

@ftrader , we need you :)

@deadalnix
Copy link
Contributor Author

You can check it matches the test vector from go here: https://golang.org/src/hash/crc64/crc64_test.go

@deadalnix deadalnix force-pushed the crc64 branch 2 times, most recently from 601c8b7 to f216ed6 Compare March 15, 2017 13:12
@JackStouffer
Copy link
Contributor

@deadalnix Sorry, I only just saw your comment about verification.

Any chance you can fix the public example issue so this can be pulled?

@CyberShadow
Copy link
Member

FWIW, I had a CRC64 (ECMA variant) implementation on top of std.digest lying around. I plugged the unittests from here into my implementation, and everything worked.

@deadalnix
Copy link
Contributor Author

OK @CyberShadow confirm that the result are good, which is pretty convincing the algorithm is correct (this is a hash function after all, so you'd expect to get very different results).

So I rebased and I want to get that in good shape so we can merge it.

@deadalnix
Copy link
Contributor Author

Looks like circle is happy. Do we move forward with that one ?

* Type of the finished CRC hash.
* ubyte[8] if N is 32, ubyte[16] if N is 64.
*/
alias R = ubyte[T.sizeof];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't R be ubyte[4] for 32 bit? Because finish used to return ubyte[4] originally and now it returns ubyte[8].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is correct, but the comment is wrong. Fixing.

@deadalnix
Copy link
Contributor Author

Fixed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants