XS.xs

filter: Statementstmt 63.1% 24 / 38 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 61.5% 32 / 52 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Digest/FNV/XS.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #define INIT32 2166136261U
6 #define MULT32 16777619U
7 #define INIT64 14695981039346656037U
8 #define MULT64 1099511628211U
9  
10 static UV
11 47 fnv1_32 (SV *data, U32 h)
12 {
13 STRLEN l;
14 47 U8 *p = (U8 *)SvPVbyte (data, l);
15  
16 133 ▶ while (l--)
Branch: 1 branch
BranchTrueFalseTotal
while (l--) 86 47 133
17 {
18 86 h *= MULT32;
19 86 h ^= *p++;
20 }
21  
22 47 return h;
23 }
24  
25 static UV
26 12 fnv1a_32 (SV *data, U32 h)
27 {
28 STRLEN l;
29 12 U8 *p = (U8 *)SvPVbyte (data, l);
30  
31 32 ▶ while (l--)
Branch: 1 branch
BranchTrueFalseTotal
while (l--) 20 12 32
32 {
33 20 h ^= *p++;
34 20 h *= MULT32;
35 }
36  
37 12 return h;
38 }
39  
40 #if UVSIZE >= 8
41  
42 static UV
43 57 fnv1_64 (SV *data, UV h)
44 {
45 STRLEN l;
46 57 U8 *p = (U8 *)SvPVbyte (data, l);
47  
48 163 ▶ while (l--)
Branch: 1 branch
BranchTrueFalseTotal
while (l--) 106 57 163
49 {
50 106 h *= MULT64;
51 106 h ^= *p++;
52 }
53  
54 57 return h;
55 }
56  
57 static UV
58 21 fnv1a_64 (SV *data, UV h)
59 {
60 STRLEN l;
61 21 U8 *p = (U8 *)SvPVbyte (data, l);
62  
63 59 ▶ while (l--)
Branch: 1 branch
BranchTrueFalseTotal
while (l--) 38 21 59
64 {
65 38 h ^= *p++;
66 38 h *= MULT64;
67 }
68  
69 21 return h;
70 }
71  
72 #endif
73  
74 #define fnv0_32 fnv1_32
75 #define fnv0_64 fnv1_64
76  
77 static UV
78 0 xorfold (UV hash, int bits, int max)
79 {
80 0 ▶ if (bits < max)
Branch: 1 branch
BranchTrueFalseTotal
if (bits < max) 0 0 0
81 0 hash = ((hash >> (max - bits)) ^ hash) & ((1 << bits) - 1);
82  
83 0 return hash;
84 }
85  
86 #define xorfold_32(hash,bits) xorfold (hash, bits, 32)
87 #define xorfold_64(hash,bits) xorfold (hash, bits, 64)
88  
89 static UV
90 0 reduce_32 (U32 hash, U32 range)
91 {
92 0 U32 retry = 0xffffffffU / range * range;
93  
94 0 ▶ while (hash >= retry)
Branch: 1 branch
BranchTrueFalseTotal
while (hash >= retry) 0 0 0
95 0 hash = hash * MULT32 + INIT32;
96  
97 0 return hash % range;
98 }
99  
100 static UV
101 0 reduce_64 (UV hash, UV range)
102 {
103 0 U32 retry = 0xffffffffffffffffU / range * range;
104  
105 0 ▶ while (hash >= retry)
Branch: 1 branch
BranchTrueFalseTotal
while (hash >= retry) 0 0 0
106 0 hash = hash * MULT64 + INIT64;
107  
108 0 return hash % range;
109 }
110  
111 MODULE = Digest::FNV::XS PACKAGE = Digest::FNV::XS
112  
113 PROTOTYPES: ENABLE
114  
115 UV fnv0_32 (SV *data, SV *init = &PL_sv_undef)
116 C_ARGS: data, SvUV (init)
117  
118 UV fnv1_32 (SV *data, SV *init = &PL_sv_undef)
119 C_ARGS: data, SvOK (init) ? SvUV (init) : INIT32
120  
121 UV fnv1a_32 (SV *data, SV *init = &PL_sv_undef)
122 C_ARGS: data, SvOK (init) ? SvUV (init) : INIT32
123  
124 #if UVSIZE >= 8
125  
126 UV fnv0_64 (SV *data, SV *init = &PL_sv_undef)
127 C_ARGS: data, SvUV (init)
128  
129 UV fnv1_64 (SV *data, SV *init = &PL_sv_undef)
130 C_ARGS: data, SvOK (init) ? SvUV (init) : INIT64
131  
132 UV fnv1a_64 (SV *data, SV *init = &PL_sv_undef)
133 C_ARGS: data, SvOK (init) ? SvUV (init) : INIT64
134  
135 #endif
136  
137 UV xorfold_32 (UV hash, int bits)
138  
139 UV xorfold_64 (UV hash, int bits)
140  
141 UV reduce_32 (UV hash, UV range)
142  
143 UV reduce_64 (UV hash, UV range)
144  
↑ Summary blib/lib/Digest/FNV/XS.pm »