File Coverage

lib/Random/Simple.c
Criterion Covered Total %
statement 63 80 78.7
branch 21 38 55.2
condition n/a
subroutine n/a
pod n/a
total 84 118 71.1


line stmt bran cond sub pod time code
1             /*
2             * This file was generated automatically by ExtUtils::ParseXS version 3.57 from the
3             * contents of Simple.xs. Do not edit this file, edit Simple.xs instead.
4             *
5             * ANY CHANGES MADE HERE WILL BE LOST!
6             *
7             */
8              
9             #line 1 "lib/Random/Simple.xs"
10             #define PERL_NO_GET_CONTEXT // we'll define thread context if necessary (faster)
11             #include "EXTERN.h" // globals/constant import locations
12             #include "perl.h" // Perl symbols, structures and constants definition
13             #include "XSUB.h" // xsubpp functions and macros
14             #include // rand()
15             #include // uint64_t
16             #include "rand-common.h"
17              
18             #include "pcg.h"
19              
20             // Alernate PRNGs available
21             //#include "xorshiro.h"
22             //#include "xoroshiro128starstar.h"
23             //#include "splitmix64.h"
24             //
25             // Other PRNGs just need three functions _seed(S1,S2), _rand32(),
26             // and _rand64()
27              
28             ///////////////////////////////////////////////////////////////////////
29             ///////////////////////////////////////////////////////////////////////
30              
31             #line 32 "lib/Random/Simple.c"
32             #ifndef PERL_UNUSED_VAR
33             # define PERL_UNUSED_VAR(var) if (0) var = var
34             #endif
35              
36             #ifndef dVAR
37             # define dVAR dNOOP
38             #endif
39              
40              
41             /* This stuff is not part of the API! You have been warned. */
42             #ifndef PERL_VERSION_DECIMAL
43             # define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
44             #endif
45             #ifndef PERL_DECIMAL_VERSION
46             # define PERL_DECIMAL_VERSION \
47             PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
48             #endif
49             #ifndef PERL_VERSION_GE
50             # define PERL_VERSION_GE(r,v,s) \
51             (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
52             #endif
53             #ifndef PERL_VERSION_LE
54             # define PERL_VERSION_LE(r,v,s) \
55             (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
56             #endif
57              
58             /* XS_INTERNAL is the explicit static-linkage variant of the default
59             * XS macro.
60             *
61             * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
62             * "STATIC", ie. it exports XSUB symbols. You probably don't want that
63             * for anything but the BOOT XSUB.
64             *
65             * See XSUB.h in core!
66             */
67              
68              
69             /* TODO: This might be compatible further back than 5.10.0. */
70             #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
71             # undef XS_EXTERNAL
72             # undef XS_INTERNAL
73             # if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
74             # define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
75             # define XS_INTERNAL(name) STATIC XSPROTO(name)
76             # endif
77             # if defined(__SYMBIAN32__)
78             # define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
79             # define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
80             # endif
81             # ifndef XS_EXTERNAL
82             # if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
83             # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
84             # define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
85             # else
86             # ifdef __cplusplus
87             # define XS_EXTERNAL(name) extern "C" XSPROTO(name)
88             # define XS_INTERNAL(name) static XSPROTO(name)
89             # else
90             # define XS_EXTERNAL(name) XSPROTO(name)
91             # define XS_INTERNAL(name) STATIC XSPROTO(name)
92             # endif
93             # endif
94             # endif
95             #endif
96              
97             /* perl >= 5.10.0 && perl <= 5.15.1 */
98              
99              
100             /* The XS_EXTERNAL macro is used for functions that must not be static
101             * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
102             * macro defined, the best we can do is assume XS is the same.
103             * Dito for XS_INTERNAL.
104             */
105             #ifndef XS_EXTERNAL
106             # define XS_EXTERNAL(name) XS(name)
107             #endif
108             #ifndef XS_INTERNAL
109             # define XS_INTERNAL(name) XS(name)
110             #endif
111              
112             /* Now, finally, after all this mess, we want an ExtUtils::ParseXS
113             * internal macro that we're free to redefine for varying linkage due
114             * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
115             * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
116             */
117              
118             #undef XS_EUPXS
119             #if defined(PERL_EUPXS_ALWAYS_EXPORT)
120             # define XS_EUPXS(name) XS_EXTERNAL(name)
121             #else
122             /* default to internal */
123             # define XS_EUPXS(name) XS_INTERNAL(name)
124             #endif
125              
126             #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
127             #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
128              
129             /* prototype to pass -Wmissing-prototypes */
130             STATIC void
131             S_croak_xs_usage(const CV *const cv, const char *const params);
132              
133             STATIC void
134             S_croak_xs_usage(const CV *const cv, const char *const params)
135             {
136             const GV *const gv = CvGV(cv);
137              
138             PERL_ARGS_ASSERT_CROAK_XS_USAGE;
139              
140             if (gv) {
141             const char *const gvname = GvNAME(gv);
142             const HV *const stash = GvSTASH(gv);
143             const char *const hvname = stash ? HvNAME(stash) : NULL;
144              
145             if (hvname)
146             Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
147             else
148             Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
149             } else {
150             /* Pants. I don't think that it should be possible to get here. */
151             Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
152             }
153             }
154             #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
155              
156             #define croak_xs_usage S_croak_xs_usage
157              
158             #endif
159              
160             /* NOTE: the prototype of newXSproto() is different in versions of perls,
161             * so we define a portable version of newXSproto()
162             */
163             #ifdef newXS_flags
164             #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
165             #else
166             #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
167             #endif /* !defined(newXS_flags) */
168              
169             #if PERL_VERSION_LE(5, 21, 5)
170             # define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
171             #else
172             # define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
173             #endif
174              
175             /* simple backcompat versions of the TARGx() macros with no optimisation */
176             #ifndef TARGi
177             # define TARGi(iv, do_taint) sv_setiv_mg(TARG, iv)
178             # define TARGu(uv, do_taint) sv_setuv_mg(TARG, uv)
179             # define TARGn(nv, do_taint) sv_setnv_mg(TARG, nv)
180             #endif
181              
182             #line 183 "lib/Random/Simple.c"
183              
184             XS_EUPXS(XS_Random__Simple__rand32); /* prototype to pass -Wmissing-prototypes */
185 10278           XS_EUPXS(XS_Random__Simple__rand32)
186             {
187 10278           dVAR; dXSARGS;
188 10278 50         if (items != 0)
189 0           croak_xs_usage(cv, "");
190             {
191             U32 RETVAL;
192 10278 50         dXSTARG;
193              
194 10278           RETVAL = _rand32();
195 10278 100         TARGu((UV)RETVAL, 1);
196 10278           ST(0) = TARG;
197             }
198 10278           XSRETURN(1);
199             }
200              
201              
202             XS_EUPXS(XS_Random__Simple__rand64); /* prototype to pass -Wmissing-prototypes */
203 50317           XS_EUPXS(XS_Random__Simple__rand64)
204             {
205 50317           dVAR; dXSARGS;
206 50317 50         if (items != 0)
207 0           croak_xs_usage(cv, "");
208             {
209             UV RETVAL;
210 50317 50         dXSTARG;
211              
212 50317           RETVAL = _rand64();
213 50317 100         TARGu((UV)RETVAL, 1);
214 50317           ST(0) = TARG;
215             }
216 50317           XSRETURN(1);
217             }
218              
219              
220             XS_EUPXS(XS_Random__Simple__hash_mur3); /* prototype to pass -Wmissing-prototypes */
221 8           XS_EUPXS(XS_Random__Simple__hash_mur3)
222             {
223 8           dVAR; dXSARGS;
224 8 50         if (items != 1)
225 0           croak_xs_usage(cv, "seed1");
226             {
227             UV RETVAL;
228 8 50         dXSTARG;
229 8           UV seed1 = (UV)SvUV(ST(0))
230             ;
231              
232 8           RETVAL = _hash_mur3(seed1);
233 8 100         TARGu((UV)RETVAL, 1);
234 8           ST(0) = TARG;
235             }
236 8           XSRETURN(1);
237             }
238              
239              
240             XS_EUPXS(XS_Random__Simple__seed); /* prototype to pass -Wmissing-prototypes */
241 20           XS_EUPXS(XS_Random__Simple__seed)
242             {
243 20           dVAR; dXSARGS;
244 20 50         if (items != 2)
245 0           croak_xs_usage(cv, "seed1, seed2");
246             {
247 20           UV seed1 = (UV)SvUV(ST(0))
248             ;
249 20           UV seed2 = (UV)SvUV(ST(1))
250             ;
251              
252 20           _seed(seed1, seed2);
253             }
254 20           XSRETURN_EMPTY;
255             }
256              
257              
258             XS_EUPXS(XS_Random__Simple__bounded_rand); /* prototype to pass -Wmissing-prototypes */
259 100008           XS_EUPXS(XS_Random__Simple__bounded_rand)
260             {
261 100008           dVAR; dXSARGS;
262 100008 50         if (items != 1)
263 0           croak_xs_usage(cv, "range");
264             {
265             U32 RETVAL;
266 100008 50         dXSTARG;
267 100008           UV range = (UV)SvUV(ST(0))
268             ;
269              
270 100008           RETVAL = _bounded_rand(range);
271 100008 100         TARGu((UV)RETVAL, 1);
272 100008           ST(0) = TARG;
273             }
274 100008           XSRETURN(1);
275             }
276              
277              
278             XS_EUPXS(XS_Random__Simple__uint64_to_double); /* prototype to pass -Wmissing-prototypes */
279 40029           XS_EUPXS(XS_Random__Simple__uint64_to_double)
280             {
281 40029           dVAR; dXSARGS;
282 40029 50         if (items != 2)
283 0           croak_xs_usage(cv, "num, inclusive");
284             {
285             double RETVAL;
286 40029 50         dXSTARG;
287 40029           UV num = (UV)SvUV(ST(0))
288             ;
289 40029           U8 inclusive = (U8)SvUV(ST(1))
290             ;
291              
292 40029           RETVAL = _uint64_to_double(num, inclusive);
293 40029 100         TARGn((double)RETVAL, 1);
294 40029           ST(0) = TARG;
295             }
296 40029           XSRETURN(1);
297             }
298              
299              
300             XS_EUPXS(XS_Random__Simple__uint32_to_float); /* prototype to pass -Wmissing-prototypes */
301 0           XS_EUPXS(XS_Random__Simple__uint32_to_float)
302             {
303 0           dVAR; dXSARGS;
304 0 0         if (items != 2)
305 0           croak_xs_usage(cv, "num, inclusive");
306             {
307             float RETVAL;
308 0 0         dXSTARG;
309 0           U32 num = (unsigned long)SvUV(ST(0))
310             ;
311 0           U8 inclusive = (U8)SvUV(ST(1))
312             ;
313              
314 0           RETVAL = _uint32_to_float(num, inclusive);
315 0 0         TARGn((double)RETVAL, 1);
316 0           ST(0) = TARG;
317             }
318 0           XSRETURN(1);
319             }
320              
321             #ifdef __cplusplus
322             extern "C" {
323             #endif
324             XS_EXTERNAL(boot_Random__Simple); /* prototype to pass -Wmissing-prototypes */
325 9           XS_EXTERNAL(boot_Random__Simple)
326             {
327             #if PERL_VERSION_LE(5, 21, 5)
328             dVAR; dXSARGS;
329             #else
330 9           dVAR; dXSBOOTARGSXSAPIVERCHK;
331             #endif
332             #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
333             char* file = __FILE__;
334             #else
335 9           const char* file = __FILE__;
336             #endif
337              
338             PERL_UNUSED_VAR(file);
339              
340             PERL_UNUSED_VAR(cv); /* -W */
341             PERL_UNUSED_VAR(items); /* -W */
342             #if PERL_VERSION_LE(5, 21, 5)
343             XS_VERSION_BOOTCHECK;
344             # ifdef XS_APIVERSION_BOOTCHECK
345             XS_APIVERSION_BOOTCHECK;
346             # endif
347             #endif
348              
349 9           (void)newXSproto_portable("Random::Simple::_rand32", XS_Random__Simple__rand32, file, "");
350 9           (void)newXSproto_portable("Random::Simple::_rand64", XS_Random__Simple__rand64, file, "");
351 9           (void)newXSproto_portable("Random::Simple::_hash_mur3", XS_Random__Simple__hash_mur3, file, "$");
352 9           (void)newXSproto_portable("Random::Simple::_seed", XS_Random__Simple__seed, file, "$$");
353 9           (void)newXSproto_portable("Random::Simple::_bounded_rand", XS_Random__Simple__bounded_rand, file, "$");
354 9           (void)newXSproto_portable("Random::Simple::_uint64_to_double", XS_Random__Simple__uint64_to_double, file, "$$");
355 9           (void)newXSproto_portable("Random::Simple::_uint32_to_float", XS_Random__Simple__uint32_to_float, file, "$$");
356             #if PERL_VERSION_LE(5, 21, 5)
357             # if PERL_VERSION_GE(5, 9, 0)
358             if (PL_unitcheckav)
359             call_list(PL_scopestack_ix, PL_unitcheckav);
360             # endif
361             XSRETURN_YES;
362             #else
363 9           Perl_xs_boot_epilog(aTHX_ ax);
364             #endif
365 9           }
366              
367             #ifdef __cplusplus
368             }
369             #endif