mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
std/crc64: add new package
This commit is contained in:
1 parent
6a6e8d3f09
commit
b2ab3ba008
7 files changed
+1055
No files matched your search
@@ -16,6 +16,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
|
||||
- Added `hasher_u64`.
|
||||
- Added `if.likely` and `if.unlikely`.
|
||||
- Added `slice_var as nptr array[etc] etc` conversion.
|
||||
- Added `std/crc64`.
|
||||
- Added `std/jpeg`.
|
||||
- Added `std/netpbm`.
|
||||
- Added `std/sha256`.
|
||||
|
||||
@@ -45,6 +45,8 @@ checksum.
|
||||
|
||||
- [std/adler32](/std/adler32)
|
||||
- [std/crc32](/std/crc32)
|
||||
- [std/crc64](/std/crc64)
|
||||
- [std/sha256](/std/sha256)
|
||||
- [std/xxhash32](/std/xxhash32)
|
||||
- [std/xxhash64](/std/xxhash64)
|
||||
|
||||
|
||||
@@ -8201,6 +8201,223 @@ struct wuffs_crc32__ieee_hasher__struct {
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32) || defined(WUFFS_NONMONOLITHIC)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC64) || defined(WUFFS_NONMONOLITHIC)
|
||||
|
||||
// ---------------- Status Codes
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
// ---------------- Struct Declarations
|
||||
|
||||
typedef struct wuffs_crc64__ecma_hasher__struct wuffs_crc64__ecma_hasher;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
|
||||
// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
|
||||
//
|
||||
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
|
||||
// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for options.
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options);
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_crc64__ecma_hasher(void);
|
||||
|
||||
// ---------------- Allocs
|
||||
|
||||
// These functions allocate and initialize Wuffs structs. They return NULL if
|
||||
// memory allocation fails. If they return non-NULL, there is no need to call
|
||||
// wuffs_foo__bar__initialize, but the caller is responsible for eventually
|
||||
// calling free on the returned pointer. That pointer is effectively a C++
|
||||
// std::unique_ptr<T, wuffs_unique_ptr_deleter>.
|
||||
|
||||
wuffs_crc64__ecma_hasher*
|
||||
wuffs_crc64__ecma_hasher__alloc(void);
|
||||
|
||||
static inline wuffs_base__hasher_u64*
|
||||
wuffs_crc64__ecma_hasher__alloc_as__wuffs_base__hasher_u64(void) {
|
||||
return (wuffs_base__hasher_u64*)(wuffs_crc64__ecma_hasher__alloc());
|
||||
}
|
||||
|
||||
// ---------------- Upcasts
|
||||
|
||||
static inline wuffs_base__hasher_u64*
|
||||
wuffs_crc64__ecma_hasher__upcast_as__wuffs_base__hasher_u64(
|
||||
wuffs_crc64__ecma_hasher* p) {
|
||||
return (wuffs_base__hasher_u64*)p;
|
||||
}
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__get_quirk(
|
||||
const wuffs_crc64__ecma_hasher* self,
|
||||
uint32_t a_key);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_crc64__ecma_hasher__set_quirk(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
uint32_t a_key,
|
||||
uint64_t a_value);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_crc64__ecma_hasher__update(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
wuffs_base__slice_u8 a_x);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__update_u64(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
wuffs_base__slice_u8 a_x);
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__checksum_u64(
|
||||
const wuffs_crc64__ecma_hasher* self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// ---------------- Struct Definitions
|
||||
|
||||
// These structs' fields, and the sizeof them, are private implementation
|
||||
// details that aren't guaranteed to be stable across Wuffs versions.
|
||||
//
|
||||
// See https://en.wikipedia.org/wiki/Opaque_pointer#C
|
||||
|
||||
#if defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
struct wuffs_crc64__ecma_hasher__struct {
|
||||
// Do not access the private_impl's or private_data's fields directly. There
|
||||
// is no API/ABI compatibility or safety guarantee if you do so. Instead, use
|
||||
// the wuffs_foo__bar__baz functions.
|
||||
//
|
||||
// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
|
||||
// can be stack allocated when WUFFS_IMPLEMENTATION is defined.
|
||||
|
||||
struct {
|
||||
uint32_t magic;
|
||||
uint32_t active_coroutine;
|
||||
wuffs_base__vtable vtable_for__wuffs_base__hasher_u64;
|
||||
wuffs_base__vtable null_vtable;
|
||||
|
||||
uint64_t f_state;
|
||||
} private_impl;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
using unique_ptr = std::unique_ptr<wuffs_crc64__ecma_hasher, wuffs_unique_ptr_deleter>;
|
||||
|
||||
// On failure, the alloc_etc functions return nullptr. They don't throw.
|
||||
|
||||
static inline unique_ptr
|
||||
alloc() {
|
||||
return unique_ptr(wuffs_crc64__ecma_hasher__alloc());
|
||||
}
|
||||
|
||||
static inline wuffs_base__hasher_u64::unique_ptr
|
||||
alloc_as__wuffs_base__hasher_u64() {
|
||||
return wuffs_base__hasher_u64::unique_ptr(
|
||||
wuffs_crc64__ecma_hasher__alloc_as__wuffs_base__hasher_u64());
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__HAVE_UNIQUE_PTR)
|
||||
|
||||
#if defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
// Disallow constructing or copying an object via standard C++ mechanisms,
|
||||
// e.g. the "new" operator, as this struct is intentionally opaque. Its total
|
||||
// size and field layout is not part of the public, stable, memory-safe API.
|
||||
// Use malloc or memcpy and the sizeof__wuffs_foo__bar function instead, and
|
||||
// call wuffs_foo__bar__baz methods (which all take a "this"-like pointer as
|
||||
// their first argument) rather than tweaking bar.private_impl.qux fields.
|
||||
//
|
||||
// In C, we can just leave wuffs_foo__bar as an incomplete type (unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd). In C++, we define a complete type in
|
||||
// order to provide convenience methods. These forward on "this", so that you
|
||||
// can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
|
||||
wuffs_crc64__ecma_hasher__struct() = delete;
|
||||
wuffs_crc64__ecma_hasher__struct(const wuffs_crc64__ecma_hasher__struct&) = delete;
|
||||
wuffs_crc64__ecma_hasher__struct& operator=(
|
||||
const wuffs_crc64__ecma_hasher__struct&) = delete;
|
||||
#endif // defined(WUFFS_BASE__HAVE_EQ_DELETE) && !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#if !defined(WUFFS_IMPLEMENTATION)
|
||||
// As above, the size of the struct is not part of the public API, and unless
|
||||
// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap
|
||||
// allocated, not stack allocated. Its size is not intended to be known at
|
||||
// compile time, but it is unfortunately divulged as a side effect of
|
||||
// defining C++ convenience methods. Use "sizeof__T()", calling the function,
|
||||
// instead of "sizeof T", invoking the operator. To make the two values
|
||||
// different, so that passing the latter will be rejected by the initialize
|
||||
// function, we add an arbitrary amount of dead weight.
|
||||
uint8_t dead_weight[123000000]; // 123 MB.
|
||||
#endif // !defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
initialize(
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options) {
|
||||
return wuffs_crc64__ecma_hasher__initialize(
|
||||
this, sizeof_star_self, wuffs_version, options);
|
||||
}
|
||||
|
||||
inline wuffs_base__hasher_u64*
|
||||
upcast_as__wuffs_base__hasher_u64() {
|
||||
return (wuffs_base__hasher_u64*)this;
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
get_quirk(
|
||||
uint32_t a_key) const {
|
||||
return wuffs_crc64__ecma_hasher__get_quirk(this, a_key);
|
||||
}
|
||||
|
||||
inline wuffs_base__status
|
||||
set_quirk(
|
||||
uint32_t a_key,
|
||||
uint64_t a_value) {
|
||||
return wuffs_crc64__ecma_hasher__set_quirk(this, a_key, a_value);
|
||||
}
|
||||
|
||||
inline wuffs_base__empty_struct
|
||||
update(
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
return wuffs_crc64__ecma_hasher__update(this, a_x);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
update_u64(
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
return wuffs_crc64__ecma_hasher__update_u64(this, a_x);
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
checksum_u64() const {
|
||||
return wuffs_crc64__ecma_hasher__checksum_u64(this);
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
}; // struct wuffs_crc64__ecma_hasher__struct
|
||||
|
||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC64) || defined(WUFFS_NONMONOLITHIC)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE) || defined(WUFFS_NONMONOLITHIC)
|
||||
|
||||
// ---------------- Status Codes
|
||||
@@ -34543,6 +34760,250 @@ wuffs_crc32__ieee_hasher__up_x86_sse42(
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC32)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC64)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
static const uint64_t
|
||||
WUFFS_CRC64__ECMA_TABLE[1][256] WUFFS_BASE__POTENTIALLY_UNUSED = {
|
||||
{
|
||||
0u, 12911341560706588527u, 17619267392293085275u, 5164075066763771700u, 8921845837811637811u, 14483170935171449180u, 10328150133527543400u, 4357999468653093127u,
|
||||
17843691675623275622u, 4940391307328217865u, 226782375002905661u, 12685511915359257426u, 10119945210068853333u, 4566377562367245626u, 8715998937306186254u, 14689403211693301089u,
|
||||
9051005139383707209u, 14895072503764629798u, 9880782614656435730u, 4193374422961527165u, 453564750005811322u, 13070904082541799189u, 17496296445768931361u, 4747102235666401102u,
|
||||
9960315520700766767u, 4113029525020509504u, 9132755124734491252u, 14812441257301386523u, 17431997874612372508u, 4811156168024382323u, 391483189436228679u, 13132671735097031464u,
|
||||
18102010278767414418u, 5195199925788447741u, 1131375642422963401u, 13591081480414639014u, 9288535643022529185u, 3731739485546663374u, 8386748845923054330u, 14361410892855143829u,
|
||||
907129500011622644u, 13814943346342178715u, 17875617253995106479u, 5421418680781082560u, 8594564625313771207u, 14152643483341451688u, 9494204471332802204u, 3525329033817543155u,
|
||||
9704381199536204507u, 3855837706121835956u, 8226059050041019008u, 13908973417437222383u, 18265510249468982504u, 5643692520190618503u, 718348998302913715u, 13463047253836762076u,
|
||||
8146277531524994749u, 13989069943491807698u, 9622312336048764646u, 3938150108875254153u, 782966378872457358u, 13399312233903888353u, 18327840216347633877u, 5582173445676054458u,
|
||||
7257036000092981153u, 15535280666427316430u, 10390399851576895482u, 2529986302517213333u, 2262751284845926802u, 12414353723947190013u, 16997392145760156105u, 6398650419759490726u,
|
||||
10599130201908394951u, 2322133910755632296u, 7463478971093326748u, 15329644185724306675u, 16773497691846108660u, 6622864283287239323u, 2036569382881248687u, 12640783567252986560u,
|
||||
1814259000023245288u, 12250853444207230599u, 17125426475222188467u, 6811676960462675676u, 7132938157145702363u, 15119434731753103540u, 10842837361562165120u, 2690676064372932847u,
|
||||
17189129250627542414u, 6747026957542163169u, 1875814858707893717u, 12188560364711551674u, 10762704257491731389u, 2770420489343360210u, 7050658067635086310u, 15201536148867841161u,
|
||||
11493583972846619443u, 3219832958944941148u, 7711675412243671912u, 15576564987190227975u, 16452118100082038016u, 6305011443818121839u, 1213047649942025563u, 11816267669673208372u,
|
||||
7503259434831574869u, 15784731923736995898u, 11287385040381237006u, 3425713581329221729u, 1436697996605827430u, 11591809733187859977u, 16677985422973077821u, 6078267261889762898u,
|
||||
16292555063049989498u, 5851447209550246421u, 1630020308903038241u, 11939238787801010766u, 11081681957373440841u, 3090674103720225830u, 7876300217750508306u, 16023932746787097725u,
|
||||
1565932757744914716u, 12003503911822413427u, 16230825569204842823u, 5913566482019610152u, 7956607163135676207u, 15944361922680361024u, 11164346891352108916u, 3008957496780927003u,
|
||||
14514072000185962306u, 8809633696146542637u, 4460922918905818905u, 10287960411460399222u, 12879331835779764593u, 113391187501452830u, 5059972605034426666u, 17660565739912801861u,
|
||||
4525502569691853604u, 10224187249629523019u, 14576435430675780479u, 8748148222884465680u, 4980157760350383383u, 17740628527280140920u, 12797300839518981452u, 195741594718114339u,
|
||||
13040162471224305931u, 565687821211481700u, 4644267821511264592u, 17536326748496696895u, 14926957942186653496u, 8937808626997553239u, 4297282312656885603u, 9839608450464401420u,
|
||||
4852190599768102253u, 17327666750234135042u, 13245728566574478646u, 359174499151456857u, 4073138765762497374u, 10063573324157604913u, 14700457781105076997u, 9163920108173816938u,
|
||||
3628518000046490576u, 9328460452529085631u, 14330211790445699979u, 8498696072880078052u, 5299565100954197475u, 18061012165519327884u, 13623353920925351352u, 1018284691440624343u,
|
||||
14265876314291404726u, 8562713237611094233u, 3566469078572851181u, 9390260331795218562u, 13702854325316886917u, 937907429353946858u, 5381352128745865694u, 17978417549248290481u,
|
||||
5746791986423309721u, 18225777846762470134u, 13494053915084326338u, 606523824971012781u, 3751629717415787434u, 9745292510640121029u, 13876787882151992305u, 8338992711486538910u,
|
||||
13285957365033343487u, 815010154451519120u, 5540840978686720420u, 18431906428167644875u, 14101316135270172620u, 8115412784602421411u, 3978303581567838103u, 9519354766961195256u,
|
||||
12527462061959317731u, 2230461459452909452u, 6439665917889882296u, 16893009583564617687u, 15423350824487343824u, 7288217715337890239u, 2490078880175191691u, 10493603952060017124u,
|
||||
6520081235612152965u, 16813546994155744234u, 12610022887636243678u, 2148641156328442801u, 2426095299884051126u, 10557972909709735385u, 15361512820870335213u, 7350228890552538498u,
|
||||
15006518869663149738u, 7165105895222849989u, 2649782550477098737u, 10947027550912647582u, 12362696414880903321u, 1783234539286425590u, 6851427162658443458u, 17022309211647725485u,
|
||||
2873395993211654860u, 10722532847870938531u, 15232418832718623383u, 6938393941075996152u, 6642978682516671743u, 17230443782969840528u, 12156534523779525796u, 1989151790783919051u,
|
||||
6263731030979658865u, 16556202624882645790u, 11702894419100492842u, 1245039440087595845u, 3260040617806076482u, 11390642587947386157u, 15688795063501830681u, 7680756410435167606u,
|
||||
11622868312827688983u, 1324891275238549368u, 6181348207440451660u, 16638201170595874595u, 15752600435501016612u, 7616209416359311691u, 3321489341258335871u, 11328242235714328848u,
|
||||
3131865515489829432u, 10977756817953029463u, 16137146508898304611u, 7844397531750915340u, 5811434156413844491u, 16395372229761246052u, 11827132964039220304u, 1660744670629167935u,
|
||||
15913214326271352414u, 8068573254449152305u, 2905717078206922245u, 11204220263579804010u, 12035829987123708013u, 1452858539103461122u, 6017914993561854006u, 16189773752444600153u,
|
||||
},
|
||||
};
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
// ---------------- VTables
|
||||
|
||||
const wuffs_base__hasher_u64__func_ptrs
|
||||
wuffs_crc64__ecma_hasher__func_ptrs_for__wuffs_base__hasher_u64 = {
|
||||
(uint64_t(*)(const void*))(&wuffs_crc64__ecma_hasher__checksum_u64),
|
||||
(uint64_t(*)(const void*,
|
||||
uint32_t))(&wuffs_crc64__ecma_hasher__get_quirk),
|
||||
(wuffs_base__status(*)(void*,
|
||||
uint32_t,
|
||||
uint64_t))(&wuffs_crc64__ecma_hasher__set_quirk),
|
||||
(wuffs_base__empty_struct(*)(void*,
|
||||
wuffs_base__slice_u8))(&wuffs_crc64__ecma_hasher__update),
|
||||
(uint64_t(*)(void*,
|
||||
wuffs_base__slice_u8))(&wuffs_crc64__ecma_hasher__update_u64),
|
||||
};
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
size_t sizeof_star_self,
|
||||
uint64_t wuffs_version,
|
||||
uint32_t options){
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (sizeof(*self) != sizeof_star_self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);
|
||||
}
|
||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);
|
||||
}
|
||||
|
||||
if ((options & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
|
||||
// The whole point of this if-check is to detect an uninitialized *self.
|
||||
// We disable the warning on GCC. Clang-5.0 does not have this warning.
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
if (self->private_impl.magic != 0) {
|
||||
return wuffs_base__make_status(wuffs_base__error__initialize_falsely_claimed_already_zeroed);
|
||||
}
|
||||
#if !defined(__clang__) && defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
} else {
|
||||
if ((options & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
options |= WUFFS_INITIALIZE__ALREADY_ZEROED;
|
||||
} else {
|
||||
memset(&(self->private_impl), 0, sizeof(self->private_impl));
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__hasher_u64.vtable_name =
|
||||
wuffs_base__hasher_u64__vtable_name;
|
||||
self->private_impl.vtable_for__wuffs_base__hasher_u64.function_pointers =
|
||||
(const void*)(&wuffs_crc64__ecma_hasher__func_ptrs_for__wuffs_base__hasher_u64);
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
wuffs_crc64__ecma_hasher*
|
||||
wuffs_crc64__ecma_hasher__alloc(void) {
|
||||
wuffs_crc64__ecma_hasher* x =
|
||||
(wuffs_crc64__ecma_hasher*)(calloc(sizeof(wuffs_crc64__ecma_hasher), 1));
|
||||
if (!x) {
|
||||
return NULL;
|
||||
}
|
||||
if (wuffs_crc64__ecma_hasher__initialize(
|
||||
x, sizeof(wuffs_crc64__ecma_hasher), WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {
|
||||
free(x);
|
||||
return NULL;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
size_t
|
||||
sizeof__wuffs_crc64__ecma_hasher(void) {
|
||||
return sizeof(wuffs_crc64__ecma_hasher);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
// -------- func crc64.ecma_hasher.get_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__get_quirk(
|
||||
const wuffs_crc64__ecma_hasher* self,
|
||||
uint32_t a_key) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0u;
|
||||
}
|
||||
|
||||
// -------- func crc64.ecma_hasher.set_quirk
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status
|
||||
wuffs_crc64__ecma_hasher__set_quirk(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
uint32_t a_key,
|
||||
uint64_t a_value) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_status(wuffs_base__error__bad_receiver);
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_status(
|
||||
(self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||
? wuffs_base__error__disabled_by_previous_error
|
||||
: wuffs_base__error__initialize_not_called);
|
||||
}
|
||||
|
||||
return wuffs_base__make_status(wuffs_base__error__unsupported_option);
|
||||
}
|
||||
|
||||
// -------- func crc64.ecma_hasher.update
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct
|
||||
wuffs_crc64__ecma_hasher__update(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
if (!self) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
uint64_t v_s = 0;
|
||||
wuffs_base__slice_u8 v_p = {0};
|
||||
|
||||
v_s = (18446744073709551615u ^ self->private_impl.f_state);
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = a_x;
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 1;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + i_slice_p.len;
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_s = (WUFFS_CRC64__ECMA_TABLE[0u][(((uint8_t)(v_s)) ^ v_p.ptr[0u])] ^ (v_s >> 8u));
|
||||
v_p.ptr += 1;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
self->private_impl.f_state = (18446744073709551615u ^ v_s);
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
|
||||
// -------- func crc64.ecma_hasher.update_u64
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__update_u64(
|
||||
wuffs_crc64__ecma_hasher* self,
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
wuffs_crc64__ecma_hasher__update(self, a_x);
|
||||
return wuffs_crc64__ecma_hasher__checksum_u64(self);
|
||||
}
|
||||
|
||||
// -------- func crc64.ecma_hasher.checksum_u64
|
||||
|
||||
WUFFS_BASE__GENERATED_C_CODE
|
||||
WUFFS_BASE__MAYBE_STATIC uint64_t
|
||||
wuffs_crc64__ecma_hasher__checksum_u64(
|
||||
const wuffs_crc64__ecma_hasher* self) {
|
||||
if (!self) {
|
||||
return 0;
|
||||
}
|
||||
if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
|
||||
(self->private_impl.magic != WUFFS_BASE__DISABLED)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return self->private_impl.f_state;
|
||||
}
|
||||
|
||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__CRC64)
|
||||
|
||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__DEFLATE)
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"hash"
|
||||
"hash/adler32"
|
||||
"hash/crc32"
|
||||
"hash/crc64"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -78,6 +79,8 @@ func do(r io.Reader) error {
|
||||
h = adler32.New()
|
||||
case "crc32/ieee":
|
||||
h = crc32.NewIEEE()
|
||||
case "crc64/ecma":
|
||||
h = crc64.New(crc64.MakeTable(crc64.ECMA))
|
||||
case "sha256":
|
||||
h = sha256.New()
|
||||
case "xxhash32":
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
// print-crc64-magic-numbers.go prints the std/crc64 magic number tables.
|
||||
//
|
||||
// Usage: go run print-crc64-magic-numbers.go
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"hash/crc64"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
reverse = flag.Bool("reverse", false, "whether to reverse the bits")
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := main1(); err != nil {
|
||||
os.Stderr.WriteString(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main1() error {
|
||||
flag.Parse()
|
||||
tables := [1]crc64.Table{}
|
||||
tables[0] = *crc64.MakeTable(crc64.ECMA)
|
||||
|
||||
for i, t := range tables {
|
||||
if *reverse {
|
||||
reverseTable(&t)
|
||||
}
|
||||
if i != 0 {
|
||||
fmt.Println("],[")
|
||||
}
|
||||
for j, x := range t {
|
||||
fmt.Printf("0x%016X,", x)
|
||||
if j&3 == 3 {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reverseTable reverses the bits in the keys and values of a crc64.Table
|
||||
// (which is a [256]uint32).
|
||||
func reverseTable(t *crc64.Table) {
|
||||
revT := crc64.Table{}
|
||||
for i, v := range *t {
|
||||
revI := reverse8[i]
|
||||
revV := uint64(0)
|
||||
for j := 0; j < 64; j++ {
|
||||
if (v & (uint64(1) << j)) != 0 {
|
||||
revV |= uint64(1) << (63 - j)
|
||||
}
|
||||
}
|
||||
revT[revI] = revV
|
||||
}
|
||||
*t = revT
|
||||
}
|
||||
|
||||
var reverse8 = [256]uint8{
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, // 0x00 - 0x07
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, // 0x08 - 0x0F
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, // 0x10 - 0x17
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, // 0x18 - 0x1F
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, // 0x20 - 0x27
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, // 0x28 - 0x2F
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, // 0x30 - 0x37
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, // 0x38 - 0x3F
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, // 0x40 - 0x47
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, // 0x48 - 0x4F
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, // 0x50 - 0x57
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, // 0x58 - 0x5F
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, // 0x60 - 0x67
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, // 0x68 - 0x6F
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, // 0x70 - 0x77
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, // 0x78 - 0x7F
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, // 0x80 - 0x87
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, // 0x88 - 0x8F
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, // 0x90 - 0x97
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, // 0x98 - 0x9F
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, // 0xA0 - 0xA7
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, // 0xA8 - 0xAF
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, // 0xB0 - 0xB7
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, // 0xB8 - 0xBF
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, // 0xC0 - 0xC7
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, // 0xC8 - 0xCF
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, // 0xD0 - 0xD7
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, // 0xD8 - 0xDF
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, // 0xE0 - 0xE7
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, // 0xE8 - 0xEF
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, // 0xF0 - 0xF7
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, // 0xF8 - 0xFF
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
pub struct ecma_hasher? implements base.hasher_u64(
|
||||
state : base.u64,
|
||||
)
|
||||
|
||||
pub func ecma_hasher.get_quirk(key: base.u32) base.u64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
pub func ecma_hasher.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
|
||||
pub func ecma_hasher.update!(x: roslice base.u8) {
|
||||
var s : base.u64
|
||||
var p : roslice base.u8
|
||||
|
||||
s = 0xFFFF_FFFF_FFFF_FFFF ^ this.state
|
||||
|
||||
iterate (p = args.x)(length: 1, advance: 1, unroll: 1) {
|
||||
s = ECMA_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF_FFFF_FFFF ^ s
|
||||
}
|
||||
|
||||
pub func ecma_hasher.update_u64!(x: roslice base.u8) base.u64 {
|
||||
this.update!(x: args.x)
|
||||
return this.checksum_u64()
|
||||
}
|
||||
|
||||
pub func ecma_hasher.checksum_u64() base.u64 {
|
||||
return this.state
|
||||
}
|
||||
|
||||
// The table below was created by script/print-crc64-magic-numbers.go.
|
||||
|
||||
pri const ECMA_TABLE : roarray[1] roarray[256] base.u64 = [[
|
||||
0x0000_0000_0000_0000, 0xB32E_4CBE_03A7_5F6F, 0xF484_3657_A840_A05B, 0x47AA_7AE9_ABE7_FF34,
|
||||
0x7BD0_C384_FF8F_5E33, 0xC8FE_8F3A_FC28_015C, 0x8F54_F5D3_57CF_FE68, 0x3C7A_B96D_5468_A107,
|
||||
0xF7A1_8709_FF1E_BC66, 0x448F_CBB7_FCB9_E309, 0x0325_B15E_575E_1C3D, 0xB00B_FDE0_54F9_4352,
|
||||
0x8C71_448D_0091_E255, 0x3F5F_0833_0336_BD3A, 0x78F5_72DA_A8D1_420E, 0xCBDB_3E64_AB76_1D61,
|
||||
0x7D9B_A138_5133_6649, 0xCEB5_ED86_5294_3926, 0x891F_976F_F973_C612, 0x3A31_DBD1_FAD4_997D,
|
||||
0x064B_62BC_AEBC_387A, 0xB565_2E02_AD1B_6715, 0xF2CF_54EB_06FC_9821, 0x41E1_1855_055B_C74E,
|
||||
0x8A3A_2631_AE2D_DA2F, 0x3914_6A8F_AD8A_8540, 0x7EBE_1066_066D_7A74, 0xCD90_5CD8_05CA_251B,
|
||||
0xF1EA_E5B5_51A2_841C, 0x42C4_A90B_5205_DB73, 0x056E_D3E2_F9E2_2447, 0xB640_9F5C_FA45_7B28,
|
||||
0xFB37_4270_A266_CC92, 0x4819_0ECE_A1C1_93FD, 0x0FB3_7427_0A26_6CC9, 0xBC9D_3899_0981_33A6,
|
||||
0x80E7_81F4_5DE9_92A1, 0x33C9_CD4A_5E4E_CDCE, 0x7463_B7A3_F5A9_32FA, 0xC74D_FB1D_F60E_6D95,
|
||||
0x0C96_C579_5D78_70F4, 0xBFB8_89C7_5EDF_2F9B, 0xF812_F32E_F538_D0AF, 0x4B3C_BF90_F69F_8FC0,
|
||||
0x7746_06FD_A2F7_2EC7, 0xC468_4A43_A150_71A8, 0x83C2_30AA_0AB7_8E9C, 0x30EC_7C14_0910_D1F3,
|
||||
0x86AC_E348_F355_AADB, 0x3582_AFF6_F0F2_F5B4, 0x7228_D51F_5B15_0A80, 0xC106_99A1_58B2_55EF,
|
||||
0xFD7C_20CC_0CDA_F4E8, 0x4E52_6C72_0F7D_AB87, 0x09F8_169B_A49A_54B3, 0xBAD6_5A25_A73D_0BDC,
|
||||
0x710D_6441_0C4B_16BD, 0xC223_28FF_0FEC_49D2, 0x8589_5216_A40B_B6E6, 0x36A7_1EA8_A7AC_E989,
|
||||
0x0ADD_A7C5_F3C4_488E, 0xB9F3_EB7B_F063_17E1, 0xFE59_9192_5B84_E8D5, 0x4D77_DD2C_5823_B7BA,
|
||||
0x64B6_2BCA_EBC3_87A1, 0xD798_6774_E864_D8CE, 0x9032_1D9D_4383_27FA, 0x231C_5123_4024_7895,
|
||||
0x1F66_E84E_144C_D992, 0xAC48_A4F0_17EB_86FD, 0xEBE2_DE19_BC0C_79C9, 0x58CC_92A7_BFAB_26A6,
|
||||
0x9317_ACC3_14DD_3BC7, 0x2039_E07D_177A_64A8, 0x6793_9A94_BC9D_9B9C, 0xD4BD_D62A_BF3A_C4F3,
|
||||
0xE8C7_6F47_EB52_65F4, 0x5BE9_23F9_E8F5_3A9B, 0x1C43_5910_4312_C5AF, 0xAF6D_15AE_40B5_9AC0,
|
||||
0x192D_8AF2_BAF0_E1E8, 0xAA03_C64C_B957_BE87, 0xEDA9_BCA5_12B0_41B3, 0x5E87_F01B_1117_1EDC,
|
||||
0x62FD_4976_457F_BFDB, 0xD1D3_05C8_46D8_E0B4, 0x9679_7F21_ED3F_1F80, 0x2557_339F_EE98_40EF,
|
||||
0xEE8C_0DFB_45EE_5D8E, 0x5DA2_4145_4649_02E1, 0x1A08_3BAC_EDAE_FDD5, 0xA926_7712_EE09_A2BA,
|
||||
0x955C_CE7F_BA61_03BD, 0x2672_82C1_B9C6_5CD2, 0x61D8_F828_1221_A3E6, 0xD2F6_B496_1186_FC89,
|
||||
0x9F81_69BA_49A5_4B33, 0x2CAF_2504_4A02_145C, 0x6B05_5FED_E1E5_EB68, 0xD82B_1353_E242_B407,
|
||||
0xE451_AA3E_B62A_1500, 0x577F_E680_B58D_4A6F, 0x10D5_9C69_1E6A_B55B, 0xA3FB_D0D7_1DCD_EA34,
|
||||
0x6820_EEB3_B6BB_F755, 0xDB0E_A20D_B51C_A83A, 0x9CA4_D8E4_1EFB_570E, 0x2F8A_945A_1D5C_0861,
|
||||
0x13F0_2D37_4934_A966, 0xA0DE_6189_4A93_F609, 0xE774_1B60_E174_093D, 0x545A_57DE_E2D3_5652,
|
||||
0xE21A_C882_1896_2D7A, 0x5134_843C_1B31_7215, 0x169E_FED5_B0D6_8D21, 0xA5B0_B26B_B371_D24E,
|
||||
0x99CA_0B06_E719_7349, 0x2AE4_47B8_E4BE_2C26, 0x6D4E_3D51_4F59_D312, 0xDE60_71EF_4CFE_8C7D,
|
||||
0x15BB_4F8B_E788_911C, 0xA695_0335_E42F_CE73, 0xE13F_79DC_4FC8_3147, 0x5211_3562_4C6F_6E28,
|
||||
0x6E6B_8C0F_1807_CF2F, 0xDD45_C0B1_1BA0_9040, 0x9AEF_BA58_B047_6F74, 0x29C1_F6E6_B3E0_301B,
|
||||
0xC96C_5795_D787_0F42, 0x7A42_1B2B_D420_502D, 0x3DE8_61C2_7FC7_AF19, 0x8EC6_2D7C_7C60_F076,
|
||||
0xB2BC_9411_2808_5171, 0x0192_D8AF_2BAF_0E1E, 0x4638_A246_8048_F12A, 0xF516_EEF8_83EF_AE45,
|
||||
0x3ECD_D09C_2899_B324, 0x8DE3_9C22_2B3E_EC4B, 0xCA49_E6CB_80D9_137F, 0x7967_AA75_837E_4C10,
|
||||
0x451D_1318_D716_ED17, 0xF633_5FA6_D4B1_B278, 0xB199_254F_7F56_4D4C, 0x02B7_69F1_7CF1_1223,
|
||||
0xB4F7_F6AD_86B4_690B, 0x07D9_BA13_8513_3664, 0x4073_C0FA_2EF4_C950, 0xF35D_8C44_2D53_963F,
|
||||
0xCF27_3529_793B_3738, 0x7C09_7997_7A9C_6857, 0x3BA3_037E_D17B_9763, 0x888D_4FC0_D2DC_C80C,
|
||||
0x4356_71A4_79AA_D56D, 0xF078_3D1A_7A0D_8A02, 0xB7D2_47F3_D1EA_7536, 0x04FC_0B4D_D24D_2A59,
|
||||
0x3886_B220_8625_8B5E, 0x8BA8_FE9E_8582_D431, 0xCC02_8477_2E65_2B05, 0x7F2C_C8C9_2DC2_746A,
|
||||
0x325B_15E5_75E1_C3D0, 0x8175_595B_7646_9CBF, 0xC6DF_23B2_DDA1_638B, 0x75F1_6F0C_DE06_3CE4,
|
||||
0x498B_D661_8A6E_9DE3, 0xFAA5_9ADF_89C9_C28C, 0xBD0F_E036_222E_3DB8, 0x0E21_AC88_2189_62D7,
|
||||
0xC5FA_92EC_8AFF_7FB6, 0x76D4_DE52_8958_20D9, 0x317E_A4BB_22BF_DFED, 0x8250_E805_2118_8082,
|
||||
0xBE2A_5168_7570_2185, 0x0D04_1DD6_76D7_7EEA, 0x4AAE_673F_DD30_81DE, 0xF980_2B81_DE97_DEB1,
|
||||
0x4FC0_B4DD_24D2_A599, 0xFCEE_F863_2775_FAF6, 0xBB44_828A_8C92_05C2, 0x086A_CE34_8F35_5AAD,
|
||||
0x3410_7759_DB5D_FBAA, 0x873E_3BE7_D8FA_A4C5, 0xC094_410E_731D_5BF1, 0x73BA_0DB0_70BA_049E,
|
||||
0xB861_33D4_DBCC_19FF, 0x0B4F_7F6A_D86B_4690, 0x4CE5_0583_738C_B9A4, 0xFFCB_493D_702B_E6CB,
|
||||
0xC3B1_F050_2443_47CC, 0x709F_BCEE_27E4_18A3, 0x3735_C607_8C03_E797, 0x841B_8AB9_8FA4_B8F8,
|
||||
0xADDA_7C5F_3C44_88E3, 0x1EF4_30E1_3FE3_D78C, 0x595E_4A08_9404_28B8, 0xEA70_06B6_97A3_77D7,
|
||||
0xD60A_BFDB_C3CB_D6D0, 0x6524_F365_C06C_89BF, 0x228E_898C_6B8B_768B, 0x91A0_C532_682C_29E4,
|
||||
0x5A7B_FB56_C35A_3485, 0xE955_B7E8_C0FD_6BEA, 0xAEFF_CD01_6B1A_94DE, 0x1DD1_81BF_68BD_CBB1,
|
||||
0x21AB_38D2_3CD5_6AB6, 0x9285_746C_3F72_35D9, 0xD52F_0E85_9495_CAED, 0x6601_423B_9732_9582,
|
||||
0xD041_DD67_6D77_EEAA, 0x636F_91D9_6ED0_B1C5, 0x24C5_EB30_C537_4EF1, 0x97EB_A78E_C690_119E,
|
||||
0xAB91_1EE3_92F8_B099, 0x18BF_525D_915F_EFF6, 0x5F15_28B4_3AB8_10C2, 0xEC3B_640A_391F_4FAD,
|
||||
0x27E0_5A6E_9269_52CC, 0x94CE_16D0_91CE_0DA3, 0xD364_6C39_3A29_F297, 0x604A_2087_398E_ADF8,
|
||||
0x5C30_99EA_6DE6_0CFF, 0xEF1E_D554_6E41_5390, 0xA8B4_AFBD_C5A6_ACA4, 0x1B9A_E303_C601_F3CB,
|
||||
0x56ED_3E2F_9E22_4471, 0xE5C3_7291_9D85_1B1E, 0xA269_0878_3662_E42A, 0x1147_44C6_35C5_BB45,
|
||||
0x2D3D_FDAB_61AD_1A42, 0x9E13_B115_620A_452D, 0xD9B9_CBFC_C9ED_BA19, 0x6A97_8742_CA4A_E576,
|
||||
0xA14C_B926_613C_F817, 0x1262_F598_629B_A778, 0x55C8_8F71_C97C_584C, 0xE6E6_C3CF_CADB_0723,
|
||||
0xDA9C_7AA2_9EB3_A624, 0x69B2_361C_9D14_F94B, 0x2E18_4CF5_36F3_067F, 0x9D36_004B_3554_5910,
|
||||
0x2B76_9F17_CF11_2238, 0x9858_D3A9_CCB6_7D57, 0xDFF2_A940_6751_8263, 0x6CDC_E5FE_64F6_DD0C,
|
||||
0x50A6_5C93_309E_7C0B, 0xE388_102D_3339_2364, 0xA422_6AC4_98DE_DC50, 0x170C_267A_9B79_833F,
|
||||
0xDCD7_181E_300F_9E5E, 0x6FF9_54A0_33A8_C131, 0x2853_2E49_984F_3E05, 0x9B7D_62F7_9BE8_616A,
|
||||
0xA707_DB9A_CF80_C06D, 0x1429_9724_CC27_9F02, 0x5383_EDCD_67C0_6036, 0xE0AD_A173_6467_3F59,
|
||||
]]
|
||||
@@ -0,0 +1,366 @@
|
||||
// Copyright 2023 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
// ----------------
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
|
||||
for CC in clang gcc; do
|
||||
$CC -std=c99 -Wall -Werror crc64.c && ./a.out
|
||||
rm -f a.out
|
||||
done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
//
|
||||
// To use that single file as a "foo.c"-like implementation, instead of a
|
||||
// "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
|
||||
// compiling it.
|
||||
#define WUFFS_IMPLEMENTATION
|
||||
|
||||
// Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users of
|
||||
// release/c/etc.c choose which parts of Wuffs to build. That file contains the
|
||||
// entire Wuffs standard library, implementing a variety of codecs and file
|
||||
// formats. Without this macro definition, an optimizing compiler or linker may
|
||||
// very well discard Wuffs code for unused codecs, but listing the Wuffs
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__CRC64
|
||||
|
||||
// If building this program in an environment that doesn't easily accommodate
|
||||
// relative includes, you can use the script/inline-c-relative-includes.go
|
||||
// program to generate a stand-alone C file.
|
||||
#include "../../../release/c/wuffs-unsupported-snapshot.c"
|
||||
#include "../testlib/testlib.c"
|
||||
#ifdef WUFFS_MIMIC
|
||||
// No mimic library.
|
||||
#endif
|
||||
|
||||
// ---------------- Golden Tests
|
||||
|
||||
golden_test g_crc64_midsummer_gt = {
|
||||
.src_filename = "test/data/midsummer.txt",
|
||||
};
|
||||
|
||||
golden_test g_crc64_pi_gt = {
|
||||
.src_filename = "test/data/pi.txt",
|
||||
};
|
||||
|
||||
// ---------------- CRC64 Tests
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_interface() {
|
||||
CHECK_FOCUS(__func__);
|
||||
wuffs_crc64__ecma_hasher h;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&h, sizeof h, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
return do_test__wuffs_base__hasher_u64(
|
||||
wuffs_crc64__ecma_hasher__upcast_as__wuffs_base__hasher_u64(&h),
|
||||
"test/data/hat.lossy.webp", 0, SIZE_MAX, 0xE52B1F3FF3D3389E);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_golden() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
const char* filename;
|
||||
// The want values are determined by script/checksum.go.
|
||||
uint64_t want;
|
||||
} test_cases[] = {
|
||||
{
|
||||
.filename = "test/data/hat.bmp",
|
||||
.want = 0xEADD85183B8DD1B5,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.gif",
|
||||
.want = 0x04365C489DBC96CD,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.jpeg",
|
||||
.want = 0xA4C0DB421278B786,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossless.webp",
|
||||
.want = 0x090AF44557A4E13D,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.lossy.webp",
|
||||
.want = 0xE52B1F3FF3D3389E,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.png",
|
||||
.want = 0x92E9F67A8948B654,
|
||||
},
|
||||
{
|
||||
.filename = "test/data/hat.tiff",
|
||||
.want = 0xB640F37638B639B9,
|
||||
},
|
||||
};
|
||||
|
||||
for (size_t tc = 0; tc < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); tc++) {
|
||||
wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
|
||||
.data = g_src_slice_u8,
|
||||
});
|
||||
CHECK_STRING(read_file(&src, test_cases[tc].filename));
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
wuffs_crc64__ecma_hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
uint64_t have = 0;
|
||||
size_t num_fragments = 0;
|
||||
size_t num_bytes = 0;
|
||||
do {
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = src.data.ptr + num_bytes,
|
||||
.len = src.meta.wi - num_bytes,
|
||||
});
|
||||
size_t limit = 101 + 103 * num_fragments;
|
||||
if ((j > 0) && (data.len > limit)) {
|
||||
data.len = limit;
|
||||
}
|
||||
have = wuffs_crc64__ecma_hasher__update_u64(&checksum, data);
|
||||
num_fragments++;
|
||||
num_bytes += data.len;
|
||||
} while (num_bytes < src.meta.wi);
|
||||
|
||||
if (have != test_cases[tc].want) {
|
||||
RETURN_FAIL("tc=%zu, j=%d, filename=\"%s\": have 0x%016" PRIX64
|
||||
", want 0x%016" PRIX64 "\n",
|
||||
tc, j, test_cases[tc].filename, have, test_cases[tc].want);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
do_test_xxxxx_crc64_ecma_pi(bool mimic) {
|
||||
const char* digits =
|
||||
"3."
|
||||
"141592653589793238462643383279502884197169399375105820974944592307816406"
|
||||
"2862089986280348253421170";
|
||||
if (strlen(digits) != 99) {
|
||||
RETURN_FAIL("strlen(digits): have %d, want 99", (int)(strlen(digits)));
|
||||
}
|
||||
|
||||
// The want values are determined by script/checksum.go.
|
||||
//
|
||||
// wants[i] is the checksum of the first i bytes of the digits string.
|
||||
uint64_t wants[100] = {
|
||||
0x0000000000000000, 0xDEAB38D23CD56AB6, 0x5C257BEFCFF13F5E,
|
||||
0x4BABD3D6697B9834, 0x1FE60AA0B20E44C1, 0x34C4D86E0BC41325,
|
||||
0x6202C4935B5F9D03, 0x9A46F1A15337D622, 0x62AC46BA94076EC6,
|
||||
0x34B9922211E21A0F, 0x9A104AF7E27D6BA5, 0x2494B24742FED551,
|
||||
0xFBD89FFF950FD48C, 0x2B460EB540AFCB27, 0x1AE8349F28C5B4D5,
|
||||
0xBDDE413FCD2D1EC7, 0x4C9392FF3C6A7271, 0x8FD32F7CD8D872D1,
|
||||
0x0E65369A2D7A5C6E, 0x39D14684478C19D7, 0x82A2707ED574EA50,
|
||||
0xFB7EA93DAC985EB3, 0x1EC407757264A919, 0x548FDAE4E78AD430,
|
||||
0x90ADDB7AD74F4BE5, 0x7C529D717060C1D7, 0x32EC0E4574BA45DA,
|
||||
0x0DFDB8E543882264, 0x8AFC92B43B45B4C6, 0xFCAF4DCCE3655989,
|
||||
0xE09A4703D8AFBCCB, 0xB84AE0AEA83F5088, 0xE3FB13F0EDBAFAFF,
|
||||
0xB1B19761FF90117D, 0x44F5331DED6D95D3, 0xFA2A26D1E40F49D2,
|
||||
0x4A9F04247CFF685C, 0xFBB69449F631D531, 0xD7A898DDD1B90FD0,
|
||||
0xFAB97B7A24339D48, 0x4E639C3405727ED1, 0xC65A0913998FF73E,
|
||||
0xD4B0C51EDC88ADCF, 0x70804516491376C5, 0xB8DAFAACBDAEEC42,
|
||||
0x4E21FFB5D3EBE3A0, 0xEF9BBD96ABB95EB8, 0x650021E526ECD62A,
|
||||
0x26DCCBDD2CCB56CF, 0xC35C65A689446A51, 0xFB3F572874C46E33,
|
||||
0xEBD2A873E4535B6C, 0x8A1ABDA4ADE26FBF, 0xD56E5D054013CE49,
|
||||
0x4E4C4B127A165E82, 0x502359E552CF8C9E, 0x5553E5155C05710B,
|
||||
0x6DD027892A2E30A8, 0x60ECB99DC08F6503, 0xA51B17EF5E9ABBE0,
|
||||
0x8BC6ACB41AF7A841, 0x35C2206734C3E4D7, 0x0EDF2795369647F8,
|
||||
0x8D260A38CE239CC7, 0x4CA36AB43B697CF3, 0x011532F8EFBF81A9,
|
||||
0xA87EF3B24D62F5EE, 0xB7B1703D138CF108, 0x526DCD2F01570412,
|
||||
0xE7ED3F90BE5EB8F2, 0xF53A4AFA637A1636, 0x1F589B399E04454F,
|
||||
0x4DA3CC8A11965534, 0x6430C13B11F9F73F, 0x5B465A05A3CF25A7,
|
||||
0x63FF9EBE1B58982B, 0x25FF853C20A8FEBC, 0xD5C1B83DD89E84D8,
|
||||
0x4AB0EFBA90C3F991, 0x9E9248C7A8B1601F, 0xD87EC82655C1E3AC,
|
||||
0x637CA62C38AE96ED, 0xB45FC336DAA72156, 0xF86DE5D0B3C99145,
|
||||
0xBAE57EFD07A52486, 0x2B073354423D61D7, 0x82B0A60B05715B28,
|
||||
0x951537E4C14F942D, 0x1A5667A67944548A, 0x288231134E1D9C9A,
|
||||
0xD95A00F0AA88414E, 0x711F777C8CCA7837, 0xEB588853B0AB557A,
|
||||
0x3F7F198620ADF0A4, 0xAB6528C764F3FBA2, 0xABF132F625B7A5A9,
|
||||
0x5C5021E5EBE85D91, 0x2DAAE4B7F46D14D4, 0x0EC74F51E656E908,
|
||||
0x6EAE027D39CA7F0D,
|
||||
};
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
uint64_t have = 0;
|
||||
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
|
||||
.ptr = (uint8_t*)(digits),
|
||||
.len = (size_t)(i),
|
||||
});
|
||||
|
||||
if (mimic) {
|
||||
// A simple, slow CRC-64 ECMA implementation, 1 bit at a time.
|
||||
have = 0xFFFFFFFFFFFFFFFF;
|
||||
while (data.len--) {
|
||||
uint8_t byte = *data.ptr++;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((have ^ byte) & 1) {
|
||||
have = (have >> 1) ^ 0xC96C5795D7870F42;
|
||||
} else {
|
||||
have = (have >> 1);
|
||||
}
|
||||
byte >>= 1;
|
||||
}
|
||||
}
|
||||
have ^= 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
} else {
|
||||
wuffs_crc64__ecma_hasher checksum;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
have = wuffs_crc64__ecma_hasher__update_u64(&checksum, data);
|
||||
}
|
||||
|
||||
if (have != wants[i]) {
|
||||
RETURN_FAIL("i=%d: have 0x%016" PRIX64 ", want 0x%016" PRIX64, i, have,
|
||||
wants[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_crc64_ecma_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_crc64_ecma_pi(false);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
const char* //
|
||||
test_mimic_crc64_ecma_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_test_xxxxx_crc64_ecma_pi(true);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- CRC64 Benches
|
||||
|
||||
uint64_t g_wuffs_crc64_unused_u64;
|
||||
|
||||
const char* //
|
||||
wuffs_bench_crc64_ecma(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
uint64_t len = src->meta.wi - src->meta.ri;
|
||||
if (rlimit) {
|
||||
len = wuffs_base__u64__min(len, rlimit);
|
||||
}
|
||||
wuffs_crc64__ecma_hasher checksum = {0};
|
||||
CHECK_STATUS("initialize", wuffs_crc64__ecma_hasher__initialize(
|
||||
&checksum, sizeof checksum, WUFFS_VERSION,
|
||||
wuffs_initialize_flags));
|
||||
g_wuffs_crc64_unused_u64 = wuffs_crc64__ecma_hasher__update_u64(
|
||||
&checksum, ((wuffs_base__slice_u8){
|
||||
.ptr = src->data.ptr + src->meta.ri,
|
||||
.len = len,
|
||||
}));
|
||||
src->meta.ri += len;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_crc64_ecma_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_crc64_ecma,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_crc64_midsummer_gt, UINT64_MAX, UINT64_MAX, 200);
|
||||
}
|
||||
|
||||
const char* //
|
||||
bench_wuffs_crc64_ecma_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
return do_bench_io_buffers(
|
||||
wuffs_bench_crc64_ecma,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tcounter_src,
|
||||
&g_crc64_pi_gt, UINT64_MAX, UINT64_MAX, 20);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
proc g_tests[] = {
|
||||
|
||||
test_wuffs_crc64_ecma_golden,
|
||||
test_wuffs_crc64_ecma_interface,
|
||||
test_wuffs_crc64_ecma_pi,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
test_mimic_crc64_ecma_pi,
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
proc g_benches[] = {
|
||||
|
||||
bench_wuffs_crc64_ecma_10k,
|
||||
bench_wuffs_crc64_ecma_100k,
|
||||
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// No mimic benches.
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
int //
|
||||
main(int argc, char** argv) {
|
||||
g_proc_package_name = "std/crc64";
|
||||
return test_main(argc, argv, g_tests, g_benches);
|
||||
}
|
||||
Reference in new issue
Block a user