| 1 |
|
| // Disables the implicit 'pTHX_' context pointer argument, which is good practice for
|
| 2 |
|
| // modern Perl XS code that uses the 'aTHX_' macro explicitly.
|
| 3 |
|
| #define PERL_NO_GET_CONTEXT 1
|
| 4 |
|
| #include <EXTERN.h>
|
| 5 |
|
| #include <perl.h>
|
| 6 |
|
| // Disables Perl's internal locking mechanisms for certain structures.
|
| 7 |
|
| // This is often used when the XS module manages its own thread safety.
|
| 8 |
|
| #define NO_XSLOCKS
|
| 9 |
|
| #include <XSUB.h>
|
| 10 |
|
|
|
| 11 |
|
| #include <inttypes.h>
|
| 12 |
|
| #include <string.h>
|
| 13 |
|
|
|
| 14 |
|
| #ifdef __MINGW32__
|
| 15 |
|
| #include <stdint.h>
|
| 16 |
|
| #endif
|
| 17 |
|
|
|
| 18 |
|
| #ifdef _MSC_VER
|
| 19 |
|
| #include <stdlib.h>
|
| 20 |
|
| typedef __int64 int64_t;
|
| 21 |
|
| typedef unsigned __int64 uint64_t;
|
| 22 |
|
| #endif
|
| 23 |
|
|
|
| 24 |
|
| #define MATH_INT64_NATIVE_IF_AVAILABLE
|
| 25 |
|
|
|
| 26 |
|
| #include "perl_math_int64.h"
|
| 27 |
|
|
|
| 28 |
|
| #define XXH_STATIC_LINKING_ONLY
|
| 29 |
|
| #include "xxhash.h"
|
| 30 |
|
|
|
| 31 |
|
| #define XXH_TYPE_XXH32 0
|
| 32 |
|
| #define XXH_TYPE_XXH64 1
|
| 33 |
|
| #define XXH_TYPE_XXH3_64 2
|
| 34 |
|
| #define XXH_TYPE_XXH3_128 3
|
| 35 |
|
|
|
| 36 |
|
| static const char hex_chars[16] = "0123456789abcdef";
|
| 37 |
|
|
|
| 38 |
|
| #if defined(__GNUC__)
|
| 39 |
|
| #define FORCE_INLINE static inline __attribute__((always_inline))
|
| 40 |
|
| #elif defined(_MSC_VER)
|
| 41 |
|
| #define FORCE_INLINE static inline __forceinline
|
| 42 |
|
| #else
|
| 43 |
|
| #define FORCE_INLINE static inline
|
| 44 |
|
| #endif
|
| 45 |
|
|
|
| 46 |
|
| FORCE_INLINE void write_hex32(char * buf, uint32_t val) {
|
| 47 |
6 |
| buf[0] = hex_chars[(val >> 28) & 0xf];
|
| 48 |
6 |
| buf[1] = hex_chars[(val >> 24) & 0xf];
|
| 49 |
6 |
| buf[2] = hex_chars[(val >> 20) & 0xf];
|
| 50 |
6 |
| buf[3] = hex_chars[(val >> 16) & 0xf];
|
| 51 |
6 |
| buf[4] = hex_chars[(val >> 12) & 0xf];
|
| 52 |
6 |
| buf[5] = hex_chars[(val >> 8) & 0xf];
|
| 53 |
6 |
| buf[6] = hex_chars[(val >> 4) & 0xf];
|
| 54 |
6 |
| buf[7] = hex_chars[(val) & 0xf];
|
| 55 |
6 |
| }
|
| 56 |
|
|
|
| 57 |
|
| FORCE_INLINE void write_hex64(char * buf, uint64_t val) {
|
| 58 |
96 |
| buf[0] = hex_chars[(val >> 60) & 0xf];
|
| 59 |
96 |
| buf[1] = hex_chars[(val >> 56) & 0xf];
|
| 60 |
96 |
| buf[2] = hex_chars[(val >> 52) & 0xf];
|
| 61 |
96 |
| buf[3] = hex_chars[(val >> 48) & 0xf];
|
| 62 |
96 |
| buf[4] = hex_chars[(val >> 44) & 0xf];
|
| 63 |
96 |
| buf[5] = hex_chars[(val >> 40) & 0xf];
|
| 64 |
96 |
| buf[6] = hex_chars[(val >> 36) & 0xf];
|
| 65 |
96 |
| buf[7] = hex_chars[(val >> 32) & 0xf];
|
| 66 |
96 |
| buf[8] = hex_chars[(val >> 28) & 0xf];
|
| 67 |
96 |
| buf[9] = hex_chars[(val >> 24) & 0xf];
|
| 68 |
96 |
| buf[10] = hex_chars[(val >> 20) & 0xf];
|
| 69 |
96 |
| buf[11] = hex_chars[(val >> 16) & 0xf];
|
| 70 |
96 |
| buf[12] = hex_chars[(val >> 12) & 0xf];
|
| 71 |
96 |
| buf[13] = hex_chars[(val >> 8) & 0xf];
|
| 72 |
96 |
| buf[14] = hex_chars[(val >> 4) & 0xf];
|
| 73 |
96 |
| buf[15] = hex_chars[(val) & 0xf];
|
| 74 |
96 |
| }
|
| 75 |
|
|
|
| 76 |
|
| #ifndef PERL_UNUSED_VAR
|
| 77 |
|
| #define PERL_UNUSED_VAR(var) \
|
| 78 |
|
| if (0) \
|
| 79 |
|
| var = var
|
| 80 |
|
| #endif
|
| 81 |
|
|
|
| 82 |
|
| #ifndef dVAR
|
| 83 |
|
| #define dVAR dNOOP
|
| 84 |
|
| #endif
|
| 85 |
|
|
|
| 86 |
|
| #undef XS_INTERNAL
|
| 87 |
|
| #if defined(PERL_EUPXS_ALWAYS_EXPORT)
|
| 88 |
|
| #define XS_INTERNAL(name) XS_EXTERNAL(name)
|
| 89 |
|
| #else
|
| 90 |
|
| #define XS_INTERNAL(name) XS(name)
|
| 91 |
|
| #endif
|
| 92 |
|
|
|
| 93 |
|
| #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
|
| 94 |
|
| #define PERL_ARGS_ASSERT_CROAK_XS_USAGE \
|
| 95 |
|
| assert(cv); \
|
| 96 |
|
| assert(params)
|
| 97 |
|
|
|
| 98 |
|
| STATIC void S_croak_xs_usage(const CV * const cv, const char * const params);
|
| 99 |
|
|
|
| 100 |
|
| STATIC void S_croak_xs_usage(const CV * const cv, const char * const params) {
|
| 101 |
|
| const GV * const gv = CvGV(cv);
|
| 102 |
|
| PERL_ARGS_ASSERT_CROAK_XS_USAGE;
|
| 103 |
|
| if (gv) {
|
| 104 |
|
| const char * const gvname = GvNAME(gv);
|
| 105 |
|
| const HV * const stash = GvSTASH(gv);
|
| 106 |
|
| const char * const hvname = stash ? HvNAME(stash) : NULL;
|
| 107 |
|
| if (hvname)
|
| 108 |
|
| Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
|
| 109 |
|
| else
|
| 110 |
|
| Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
|
| 111 |
|
| }
|
| 112 |
|
| else {
|
| 113 |
|
| Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
|
| 114 |
|
| }
|
| 115 |
|
| }
|
| 116 |
|
| #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
|
| 117 |
|
| #define croak_xs_usage S_croak_xs_usage
|
| 118 |
|
| #endif
|
| 119 |
|
|
|
| 120 |
|
| #ifdef newXS_flags
|
| 121 |
|
| #define newXSproto_portable(name, c_impl, file) newXS_flags(name, c_impl, file, NULL, 0)
|
| 122 |
|
| #else
|
| 123 |
|
| #define newXSproto_portable(name, c_impl, file) (PL_Sv = (SV *)newXS(name, c_impl, file), (CV *)PL_Sv)
|
| 124 |
|
| #endif
|
| 125 |
|
|
|
| 126 |
13 |
| XS_INTERNAL(Digest_xxHash_xxhash32) {
|
| 127 |
13 |
| dXSARGS;
|
| 128 |
13 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
13 |
13 |
|
| 129 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 130 |
|
| {
|
| 131 |
13 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
13 |
0 |
13 |
|
| 132 |
|
| STRLEN len;
|
| 133 |
13 |
| const char * input = SvPV(ST(0), len);
|
| 134 |
13 |
| UV seed = SvUV(ST(1));
|
| 135 |
13 |
▶ | TARGu((UV)XXH32(input, len, seed), 1);
|
Branch: 1 branch
| Branch | True | False | Total |
| TARGu((UV)XXH32(input, len, seed), 1);
|
7 |
6 |
13 |
|
| 136 |
13 |
| ST(0) = TARG;
|
| 137 |
|
| }
|
| 138 |
13 |
| XSRETURN(1);
|
| 139 |
|
| }
|
| 140 |
|
|
|
| 141 |
10 |
| XS_INTERNAL(Digest_xxHash_xxhash64) {
|
| 142 |
10 |
| dXSARGS;
|
| 143 |
10 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
10 |
10 |
|
| 144 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 145 |
|
| {
|
| 146 |
10 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
10 |
0 |
10 |
|
| 147 |
|
| STRLEN len;
|
| 148 |
10 |
| const char * input = SvPV(ST(0), len);
|
| 149 |
10 |
| UV seed = SvUV(ST(1));
|
| 150 |
10 |
▶ | TARGu((UV)XXH64(input, len, seed), 1);
|
Branch: 1 branch
| Branch | True | False | Total |
| TARGu((UV)XXH64(input, len, seed), 1);
|
2 |
8 |
10 |
|
| 151 |
10 |
| ST(0) = TARG;
|
| 152 |
|
| }
|
| 153 |
10 |
| XSRETURN(1);
|
| 154 |
|
| }
|
| 155 |
|
|
|
| 156 |
0 |
| XS_INTERNAL(Digest_xxHash_xxh3_64) {
|
| 157 |
0 |
| dXSARGS;
|
| 158 |
0 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
0 |
0 |
|
| 159 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 160 |
|
| {
|
| 161 |
0 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
0 |
0 |
0 |
|
| 162 |
|
| STRLEN len;
|
| 163 |
0 |
| const char * input = SvPV(ST(0), len);
|
| 164 |
0 |
| UV seed = SvUV(ST(1));
|
| 165 |
0 |
▶ | TARGu((UV)XXH3_64bits_withSeed(input, len, seed), 1);
|
Branch: 1 branch
| Branch | True | False | Total |
| TARGu((UV)XXH3_64bits_withSeed(input, len, seed), 1);
|
0 |
0 |
0 |
|
| 166 |
0 |
| ST(0) = TARG;
|
| 167 |
|
| }
|
| 168 |
0 |
| XSRETURN(1);
|
| 169 |
|
| }
|
| 170 |
|
|
|
| 171 |
2 |
| XS_INTERNAL(Digest_xxHash_xxhash32_hex) {
|
| 172 |
2 |
| dXSARGS;
|
| 173 |
2 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
2 |
2 |
|
| 174 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 175 |
|
| {
|
| 176 |
2 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
2 |
0 |
2 |
|
| 177 |
|
| STRLEN len;
|
| 178 |
2 |
| const char * input = SvPV(ST(0), len);
|
| 179 |
2 |
| UV seed = SvUV(ST(1));
|
| 180 |
|
| char * buf;
|
| 181 |
2 |
| sv_setpvn(TARG, "", 0);
|
| 182 |
2 |
▶ | buf = SvGROW(TARG, 9);
|
Branch: 2 branches
| Branch | True | False | Total |
| buf = SvGROW(TARG, 9);
|
2 |
0 |
2 |
| buf = SvGROW(TARG, 9);
|
0 |
2 |
2 |
|
| 183 |
2 |
| write_hex32(buf, (uint32_t)XXH32(input, len, seed));
|
| 184 |
2 |
| SvCUR_set(TARG, 8);
|
| 185 |
2 |
| ST(0) = TARG;
|
| 186 |
|
| }
|
| 187 |
2 |
| XSRETURN(1);
|
| 188 |
|
| }
|
| 189 |
|
|
|
| 190 |
4 |
| XS_INTERNAL(Digest_xxHash_xxhash64_hex) {
|
| 191 |
4 |
| dXSARGS;
|
| 192 |
4 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
4 |
4 |
|
| 193 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 194 |
|
| {
|
| 195 |
4 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
4 |
0 |
4 |
|
| 196 |
|
| STRLEN len;
|
| 197 |
4 |
| const char * input = SvPV(ST(0), len);
|
| 198 |
4 |
| UV seed = SvUV(ST(1));
|
| 199 |
|
| char * buf;
|
| 200 |
4 |
| sv_setpvn(TARG, "", 0);
|
| 201 |
4 |
▶ | buf = SvGROW(TARG, 17);
|
Branch: 2 branches
| Branch | True | False | Total |
| buf = SvGROW(TARG, 17);
|
4 |
0 |
4 |
| buf = SvGROW(TARG, 17);
|
4 |
0 |
4 |
|
| 202 |
4 |
| write_hex64(buf, (uint64_t)XXH64(input, len, seed));
|
| 203 |
4 |
| SvCUR_set(TARG, 16);
|
| 204 |
4 |
| ST(0) = TARG;
|
| 205 |
|
| }
|
| 206 |
4 |
| XSRETURN(1);
|
| 207 |
|
| }
|
| 208 |
|
|
|
| 209 |
9 |
| XS_INTERNAL(Digest_xxHash_xxh3_64_hex) {
|
| 210 |
9 |
| dXSARGS;
|
| 211 |
9 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
9 |
9 |
|
| 212 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 213 |
|
| {
|
| 214 |
9 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
9 |
0 |
9 |
|
| 215 |
|
| STRLEN len;
|
| 216 |
9 |
| const char * input = SvPV(ST(0), len);
|
| 217 |
9 |
| UV seed = SvUV(ST(1));
|
| 218 |
|
| char * buf;
|
| 219 |
9 |
| sv_setpvn(TARG, "", 0);
|
| 220 |
9 |
▶ | buf = SvGROW(TARG, 17);
|
Branch: 2 branches
| Branch | True | False | Total |
| buf = SvGROW(TARG, 17);
|
9 |
0 |
9 |
| buf = SvGROW(TARG, 17);
|
9 |
0 |
9 |
|
| 221 |
9 |
| write_hex64(buf, (uint64_t)XXH3_64bits_withSeed(input, len, seed));
|
| 222 |
9 |
| SvCUR_set(TARG, 16);
|
| 223 |
9 |
| ST(0) = TARG;
|
| 224 |
|
| }
|
| 225 |
9 |
| XSRETURN(1);
|
| 226 |
|
| }
|
| 227 |
|
|
|
| 228 |
0 |
| XS_INTERNAL(Digest_xxHash_xxh3_128) {
|
| 229 |
0 |
| dXSARGS;
|
| 230 |
0 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
0 |
0 |
|
| 231 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 232 |
|
| PERL_UNUSED_VAR(ax);
|
| 233 |
0 |
| SP -= items;
|
| 234 |
|
| {
|
| 235 |
|
| STRLEN len;
|
| 236 |
0 |
| const char * input = SvPV(ST(0), len);
|
| 237 |
0 |
| UV seed = SvUV(ST(1));
|
| 238 |
0 |
| XXH128_hash_t h = XXH3_128bits_withSeed(input, len, seed);
|
| 239 |
0 |
▶ | XPUSHs(sv_2mortal(newSVu64(h.low64)));
|
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVu64(h.low64)));
|
0 |
0 |
0 |
|
| 240 |
0 |
▶ | XPUSHs(sv_2mortal(newSVu64(h.high64)));
|
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVu64(h.high64)));
|
0 |
0 |
0 |
|
| 241 |
0 |
| PUTBACK;
|
| 242 |
0 |
| return;
|
| 243 |
|
| }
|
| 244 |
|
| }
|
| 245 |
|
|
|
| 246 |
8 |
| XS_INTERNAL(Digest_xxHash_xxh3_128_hex) {
|
| 247 |
8 |
| dXSARGS;
|
| 248 |
8 |
▶ | if (items != 2)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 2)
|
0 |
8 |
8 |
|
| 249 |
0 |
| croak_xs_usage(cv, "input, seed");
|
| 250 |
|
| {
|
| 251 |
8 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
8 |
0 |
8 |
|
| 252 |
|
| STRLEN len;
|
| 253 |
8 |
| const char * input = SvPV(ST(0), len);
|
| 254 |
8 |
| UV seed = SvUV(ST(1));
|
| 255 |
8 |
| XXH128_hash_t h = XXH3_128bits_withSeed(input, len, seed);
|
| 256 |
|
| char * buf;
|
| 257 |
8 |
| sv_setpvn(TARG, "", 0);
|
| 258 |
8 |
▶ | buf = SvGROW(TARG, 33);
|
Branch: 2 branches
| Branch | True | False | Total |
| buf = SvGROW(TARG, 33);
|
8 |
0 |
8 |
| buf = SvGROW(TARG, 33);
|
8 |
0 |
8 |
|
| 259 |
8 |
| write_hex64(buf, (uint64_t)h.high64);
|
| 260 |
8 |
| write_hex64(buf + 16, (uint64_t)h.low64);
|
| 261 |
8 |
| SvCUR_set(TARG, 32);
|
| 262 |
8 |
| ST(0) = TARG;
|
| 263 |
|
| }
|
| 264 |
8 |
| XSRETURN(1);
|
| 265 |
|
| }
|
| 266 |
|
|
|
| 267 |
3 |
| XS_INTERNAL(Digest_xxHash_xxh3_generate_secret_from_seed) {
|
| 268 |
3 |
| dXSARGS;
|
| 269 |
3 |
▶ | if (items != 1)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 1)
|
0 |
3 |
3 |
|
| 270 |
0 |
| croak_xs_usage(cv, "seed");
|
| 271 |
|
| PERL_UNUSED_VAR(ax);
|
| 272 |
3 |
| SP -= items;
|
| 273 |
|
| {
|
| 274 |
3 |
| UV seed = SvUV(ST(0));
|
| 275 |
|
| unsigned char secret[XXH3_SECRET_DEFAULT_SIZE];
|
| 276 |
3 |
| XXH3_generateSecret_fromSeed(secret, seed);
|
| 277 |
3 |
▶ | XPUSHs(sv_2mortal(newSVpvn((const char *)secret, XXH3_SECRET_DEFAULT_SIZE)));
|
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpvn((const char *)secret, XXH3_SECRET_DEFAULT_SIZE)));
|
0 |
3 |
3 |
|
| 278 |
3 |
| PUTBACK;
|
| 279 |
3 |
| return;
|
| 280 |
|
| }
|
| 281 |
|
| }
|
| 282 |
|
|
|
| 283 |
|
| /* ========================================================================
|
| 284 |
|
| * CONSOLIDATED INTERNAL API — no argument checks, type-dispatched in C
|
| 285 |
|
| * ======================================================================== */
|
| 286 |
|
|
|
| 287 |
48 |
| XS_INTERNAL(Digest_xxHash_xxxh_create) {
|
| 288 |
48 |
| dXSARGS;
|
| 289 |
48 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
48 |
0 |
48 |
|
| 290 |
48 |
| UV type_code = SvUV(ST(0));
|
| 291 |
|
| IV ctx;
|
| 292 |
48 |
| switch (type_code) {
|
| 293 |
4 |
| case XXH_TYPE_XXH32:
|
| 294 |
4 |
| ctx = PTR2IV(XXH32_createState());
|
| 295 |
4 |
| break;
|
| 296 |
4 |
| case XXH_TYPE_XXH64:
|
| 297 |
4 |
| ctx = PTR2IV(XXH64_createState());
|
| 298 |
4 |
| break;
|
| 299 |
40 |
| default:
|
| 300 |
40 |
| ctx = PTR2IV(XXH3_createState());
|
| 301 |
40 |
| break;
|
| 302 |
|
| }
|
| 303 |
48 |
▶ | TARGi(ctx, 1);
|
Branch: 1 branch
| Branch | True | False | Total |
| TARGi(ctx, 1);
|
46 |
2 |
48 |
|
| 304 |
48 |
| ST(0) = TARG;
|
| 305 |
48 |
| XSRETURN(1);
|
| 306 |
|
| }
|
| 307 |
|
|
|
| 308 |
44 |
| XS_INTERNAL(Digest_xxHash_xxxh_free) {
|
| 309 |
44 |
| dXSARGS;
|
| 310 |
44 |
| IV ctx = SvIV(ST(0));
|
| 311 |
44 |
| UV type_code = SvUV(ST(1));
|
| 312 |
44 |
| switch (type_code) {
|
| 313 |
3 |
| case XXH_TYPE_XXH32:
|
| 314 |
3 |
| XXH32_freeState(INT2PTR(XXH32_state_t *, ctx));
|
| 315 |
3 |
| break;
|
| 316 |
3 |
| case XXH_TYPE_XXH64:
|
| 317 |
3 |
| XXH64_freeState(INT2PTR(XXH64_state_t *, ctx));
|
| 318 |
3 |
| break;
|
| 319 |
38 |
| default:
|
| 320 |
38 |
| XXH3_freeState(INT2PTR(XXH3_state_t *, ctx));
|
| 321 |
38 |
| break;
|
| 322 |
|
| }
|
| 323 |
44 |
| XSRETURN_EMPTY;
|
| 324 |
|
| }
|
| 325 |
|
|
|
| 326 |
2 |
| XS_INTERNAL(Digest_xxHash_xxxh_copy) {
|
| 327 |
2 |
| dXSARGS;
|
| 328 |
2 |
| IV dst = SvIV(ST(0));
|
| 329 |
2 |
| IV src = SvIV(ST(1));
|
| 330 |
2 |
| UV type_code = SvUV(ST(2));
|
| 331 |
2 |
| switch (type_code) {
|
| 332 |
0 |
| case XXH_TYPE_XXH32:
|
| 333 |
0 |
| XXH32_copyState(INT2PTR(XXH32_state_t *, dst), INT2PTR(const XXH32_state_t *, src));
|
| 334 |
0 |
| break;
|
| 335 |
0 |
| case XXH_TYPE_XXH64:
|
| 336 |
0 |
| XXH64_copyState(INT2PTR(XXH64_state_t *, dst), INT2PTR(const XXH64_state_t *, src));
|
| 337 |
0 |
| break;
|
| 338 |
2 |
| default:
|
| 339 |
2 |
| XXH3_copyState(INT2PTR(XXH3_state_t *, dst), INT2PTR(const XXH3_state_t *, src));
|
| 340 |
2 |
| break;
|
| 341 |
|
| }
|
| 342 |
2 |
| XSRETURN_EMPTY;
|
| 343 |
|
| }
|
| 344 |
|
|
|
| 345 |
44 |
| XS_INTERNAL(Digest_xxHash_xxxh_reset) {
|
| 346 |
44 |
| dXSARGS;
|
| 347 |
44 |
| IV ctx = SvIV(ST(0));
|
| 348 |
44 |
| UV type_code = SvUV(ST(1));
|
| 349 |
44 |
| UV seed = SvUV(ST(2));
|
| 350 |
44 |
| switch (type_code) {
|
| 351 |
4 |
| case XXH_TYPE_XXH32:
|
| 352 |
4 |
| XXH32_reset(INT2PTR(XXH32_state_t *, ctx), (XXH32_hash_t)seed);
|
| 353 |
4 |
| break;
|
| 354 |
4 |
| case XXH_TYPE_XXH64:
|
| 355 |
4 |
| XXH64_reset(INT2PTR(XXH64_state_t *, ctx), seed);
|
| 356 |
4 |
| break;
|
| 357 |
23 |
| case XXH_TYPE_XXH3_64:
|
| 358 |
23 |
| XXH3_64bits_reset_withSeed(INT2PTR(XXH3_state_t *, ctx), seed);
|
| 359 |
23 |
| break;
|
| 360 |
13 |
| case XXH_TYPE_XXH3_128:
|
| 361 |
13 |
| XXH3_128bits_reset_withSeed(INT2PTR(XXH3_state_t *, ctx), seed);
|
| 362 |
13 |
| break;
|
| 363 |
|
| }
|
| 364 |
44 |
| XSRETURN_EMPTY;
|
| 365 |
|
| }
|
| 366 |
|
|
|
| 367 |
2 |
| XS_INTERNAL(Digest_xxHash_xxxh_reset_withSecret) {
|
| 368 |
2 |
| dXSARGS;
|
| 369 |
2 |
| IV ctx = SvIV(ST(0));
|
| 370 |
2 |
| UV type_code = SvUV(ST(1));
|
| 371 |
|
| STRLEN len;
|
| 372 |
2 |
| const char * secret = SvPV(ST(2), len);
|
| 373 |
2 |
▶ | if (type_code == XXH_TYPE_XXH3_64)
|
Branch: 1 branch
| Branch | True | False | Total |
| if (type_code == XXH_TYPE_XXH3_64)
|
1 |
1 |
2 |
|
| 374 |
1 |
| XXH3_64bits_reset_withSecret(INT2PTR(XXH3_state_t *, ctx), secret, len);
|
| 375 |
|
| else
|
| 376 |
1 |
| XXH3_128bits_reset_withSecret(INT2PTR(XXH3_state_t *, ctx), secret, len);
|
| 377 |
2 |
| XSRETURN_EMPTY;
|
| 378 |
|
| }
|
| 379 |
|
|
|
| 380 |
396 |
| XS_INTERNAL(Digest_xxHash_xxxh_update) {
|
| 381 |
396 |
| dXSARGS;
|
| 382 |
396 |
| IV ctx = SvIV(ST(0));
|
| 383 |
|
| STRLEN len;
|
| 384 |
396 |
| const char * input = SvPV(ST(1), len);
|
| 385 |
396 |
| UV type_code = SvUV(ST(2));
|
| 386 |
396 |
| switch (type_code) {
|
| 387 |
6 |
| case XXH_TYPE_XXH32:
|
| 388 |
6 |
| XXH32_update(INT2PTR(XXH32_state_t *, ctx), input, len);
|
| 389 |
6 |
| break;
|
| 390 |
6 |
| case XXH_TYPE_XXH64:
|
| 391 |
6 |
| XXH64_update(INT2PTR(XXH64_state_t *, ctx), input, len);
|
| 392 |
6 |
| break;
|
| 393 |
330 |
| case XXH_TYPE_XXH3_64:
|
| 394 |
330 |
| XXH3_64bits_update(INT2PTR(XXH3_state_t *, ctx), input, len);
|
| 395 |
330 |
| break;
|
| 396 |
54 |
| case XXH_TYPE_XXH3_128:
|
| 397 |
54 |
| XXH3_128bits_update(INT2PTR(XXH3_state_t *, ctx), input, len);
|
| 398 |
54 |
| break;
|
| 399 |
|
| }
|
| 400 |
396 |
| XSRETURN_EMPTY;
|
| 401 |
|
| }
|
| 402 |
|
|
|
| 403 |
1 |
| XS_INTERNAL(Digest_xxHash_xxxh_digest) {
|
| 404 |
1 |
| dXSARGS;
|
| 405 |
1 |
| IV ctx = SvIV(ST(0));
|
| 406 |
1 |
| UV type_code = SvUV(ST(1));
|
| 407 |
|
| #if !MATH_INT64_NATIVE
|
| 408 |
|
| PERL_MATH_INT64_LOAD;
|
| 409 |
|
| #endif
|
| 410 |
1 |
| switch (type_code) {
|
| 411 |
0 |
| case XXH_TYPE_XXH32:
|
| 412 |
0 |
| ST(0) = sv_2mortal(newSVuv((UV)XXH32_digest(INT2PTR(const XXH32_state_t *, ctx))));
|
| 413 |
0 |
| break;
|
| 414 |
0 |
| case XXH_TYPE_XXH64:
|
| 415 |
0 |
| ST(0) = sv_2mortal(newSVu64(XXH64_digest(INT2PTR(const XXH64_state_t *, ctx))));
|
| 416 |
0 |
| break;
|
| 417 |
1 |
| case XXH_TYPE_XXH3_64:
|
| 418 |
1 |
| ST(0) = sv_2mortal(newSVu64(XXH3_64bits_digest(INT2PTR(const XXH3_state_t *, ctx))));
|
| 419 |
1 |
| break;
|
| 420 |
0 |
| case XXH_TYPE_XXH3_128:
|
| 421 |
|
| {
|
| 422 |
0 |
| XXH128_hash_t h = XXH3_128bits_digest(INT2PTR(const XXH3_state_t *, ctx));
|
| 423 |
|
| char buf[16];
|
| 424 |
0 |
| memcpy(buf, &h.low64, 8);
|
| 425 |
0 |
| memcpy(buf + 8, &h.high64, 8);
|
| 426 |
0 |
| ST(0) = sv_2mortal(newSVpvn(buf, 16));
|
| 427 |
0 |
| break;
|
| 428 |
|
| }
|
| 429 |
|
| }
|
| 430 |
1 |
| XSRETURN(1);
|
| 431 |
|
| }
|
| 432 |
|
|
|
| 433 |
54 |
| XS_INTERNAL(Digest_xxHash_xxxh_hex) {
|
| 434 |
54 |
| dXSARGS;
|
| 435 |
54 |
▶ | dXSTARG;
|
Branch: 1 branch
| Branch | True | False | Total |
| dXSTARG;
|
54 |
0 |
54 |
|
| 436 |
54 |
| IV ctx = SvIV(ST(0));
|
| 437 |
54 |
| UV type_code = SvUV(ST(1));
|
| 438 |
54 |
| sv_setpvn(TARG, "", 0);
|
| 439 |
54 |
| switch (type_code) {
|
| 440 |
4 |
| case XXH_TYPE_XXH32:
|
| 441 |
|
| {
|
| 442 |
4 |
▶ | char * buf = SvGROW(TARG, 9);
|
Branch: 2 branches
| Branch | True | False | Total |
| char * buf = SvGROW(TARG, 9);
|
4 |
0 |
4 |
| char * buf = SvGROW(TARG, 9);
|
0 |
4 |
4 |
|
| 443 |
4 |
| write_hex32(buf, (uint32_t)XXH32_digest(INT2PTR(const XXH32_state_t *, ctx)));
|
| 444 |
4 |
| SvCUR_set(TARG, 8);
|
| 445 |
4 |
| break;
|
| 446 |
|
| }
|
| 447 |
4 |
| case XXH_TYPE_XXH64:
|
| 448 |
|
| {
|
| 449 |
4 |
▶ | char * buf = SvGROW(TARG, 17);
|
Branch: 2 branches
| Branch | True | False | Total |
| char * buf = SvGROW(TARG, 17);
|
4 |
0 |
4 |
| char * buf = SvGROW(TARG, 17);
|
0 |
4 |
4 |
|
| 450 |
4 |
| write_hex64(buf, (uint64_t)XXH64_digest(INT2PTR(const XXH64_state_t *, ctx)));
|
| 451 |
4 |
| SvCUR_set(TARG, 16);
|
| 452 |
4 |
| break;
|
| 453 |
|
| }
|
| 454 |
29 |
| case XXH_TYPE_XXH3_64:
|
| 455 |
|
| {
|
| 456 |
29 |
▶ | char * buf = SvGROW(TARG, 17);
|
Branch: 2 branches
| Branch | True | False | Total |
| char * buf = SvGROW(TARG, 17);
|
29 |
0 |
29 |
| char * buf = SvGROW(TARG, 17);
|
3 |
26 |
29 |
|
| 457 |
29 |
| write_hex64(buf, (uint64_t)XXH3_64bits_digest(INT2PTR(const XXH3_state_t *, ctx)));
|
| 458 |
29 |
| SvCUR_set(TARG, 16);
|
| 459 |
29 |
| break;
|
| 460 |
|
| }
|
| 461 |
17 |
| case XXH_TYPE_XXH3_128:
|
| 462 |
|
| {
|
| 463 |
17 |
| XXH128_hash_t h = XXH3_128bits_digest(INT2PTR(const XXH3_state_t *, ctx));
|
| 464 |
17 |
▶ | char * buf = SvGROW(TARG, 33);
|
Branch: 2 branches
| Branch | True | False | Total |
| char * buf = SvGROW(TARG, 33);
|
17 |
0 |
17 |
| char * buf = SvGROW(TARG, 33);
|
4 |
13 |
17 |
|
| 465 |
17 |
| write_hex64(buf, (uint64_t)h.high64);
|
| 466 |
17 |
| write_hex64(buf + 16, (uint64_t)h.low64);
|
| 467 |
17 |
| SvCUR_set(TARG, 32);
|
| 468 |
17 |
| break;
|
| 469 |
|
| }
|
| 470 |
|
| }
|
| 471 |
54 |
| ST(0) = TARG;
|
| 472 |
54 |
| XSRETURN(1);
|
| 473 |
|
| }
|
| 474 |
|
|
|
| 475 |
1 |
| void boot_Digest__xxHash(pTHX_ CV * cv) {
|
| 476 |
|
| dVAR;
|
| 477 |
1 |
| dXSBOOTARGSXSAPIVERCHK;
|
| 478 |
|
| PERL_UNUSED_VAR(cv);
|
| 479 |
|
| PERL_UNUSED_VAR(items);
|
| 480 |
|
|
|
| 481 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxhash32", Digest_xxHash_xxhash32, __FILE__);
|
| 482 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxhash64", Digest_xxHash_xxhash64, __FILE__);
|
| 483 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxh3_64", Digest_xxHash_xxh3_64, __FILE__);
|
| 484 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxhash32_hex", Digest_xxHash_xxhash32_hex, __FILE__);
|
| 485 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxhash64_hex", Digest_xxHash_xxhash64_hex, __FILE__);
|
| 486 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxh3_64_hex", Digest_xxHash_xxh3_64_hex, __FILE__);
|
| 487 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxh3_128", Digest_xxHash_xxh3_128, __FILE__);
|
| 488 |
1 |
| (void)newXSproto_portable("Digest::xxHash::xxh3_128_hex", Digest_xxHash_xxh3_128_hex, __FILE__);
|
| 489 |
1 |
| (void)newXSproto_portable(
|
| 490 |
|
| "Digest::xxHash::xxh3_generate_secret_from_seed", Digest_xxHash_xxh3_generate_secret_from_seed, __FILE__);
|
| 491 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_create", Digest_xxHash_xxxh_create, __FILE__);
|
| 492 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_free", Digest_xxHash_xxxh_free, __FILE__);
|
| 493 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_copy", Digest_xxHash_xxxh_copy, __FILE__);
|
| 494 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_reset", Digest_xxHash_xxxh_reset, __FILE__);
|
| 495 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_reset_withSecret", Digest_xxHash_xxxh_reset_withSecret, __FILE__);
|
| 496 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_update", Digest_xxHash_xxxh_update, __FILE__);
|
| 497 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_digest", Digest_xxHash_xxxh_digest, __FILE__);
|
| 498 |
1 |
| (void)newXSproto_portable("Digest::xxHash::_xxxh_hex", Digest_xxHash_xxxh_hex, __FILE__);
|
| 499 |
1 |
| Perl_xs_boot_epilog(aTHX_ ax);
|
| 500 |
1 |
| }
|