File Coverage

lib/Random/Simple.c
Criterion Covered Total %
statement 64 91 70.3
branch 21 44 47.7
condition n/a
subroutine n/a
pod n/a
total 85 135 62.9


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_rand32_lemire); /* prototype to pass -Wmissing-prototypes */
259 100008           XS_EUPXS(XS_Random__Simple__bounded_rand32_lemire)
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_rand32_lemire(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__bounded_rand64_rejection); /* prototype to pass -Wmissing-prototypes */
279 0           XS_EUPXS(XS_Random__Simple__bounded_rand64_rejection)
280             {
281 0           dVAR; dXSARGS;
282 0 0         if (items != 1)
283 0           croak_xs_usage(cv, "range");
284             {
285             UV RETVAL;
286 0 0         dXSTARG;
287 0           UV range = (UV)SvUV(ST(0))
288             ;
289              
290 0           RETVAL = _bounded_rand64_rejection(range);
291 0 0         TARGu((UV)RETVAL, 1);
292 0           ST(0) = TARG;
293             }
294 0           XSRETURN(1);
295             }
296              
297              
298             XS_EUPXS(XS_Random__Simple__uint64_to_double); /* prototype to pass -Wmissing-prototypes */
299 40029           XS_EUPXS(XS_Random__Simple__uint64_to_double)
300             {
301 40029           dVAR; dXSARGS;
302 40029 50         if (items != 2)
303 0           croak_xs_usage(cv, "num, inclusive");
304             {
305             double RETVAL;
306 40029 50         dXSTARG;
307 40029           UV num = (UV)SvUV(ST(0))
308             ;
309 40029           U8 inclusive = (U8)SvUV(ST(1))
310             ;
311              
312 40029           RETVAL = _uint64_to_double(num, inclusive);
313 40029 100         TARGn((double)RETVAL, 1);
314 40029           ST(0) = TARG;
315             }
316 40029           XSRETURN(1);
317             }
318              
319              
320             XS_EUPXS(XS_Random__Simple__uint32_to_float); /* prototype to pass -Wmissing-prototypes */
321 0           XS_EUPXS(XS_Random__Simple__uint32_to_float)
322             {
323 0           dVAR; dXSARGS;
324 0 0         if (items != 2)
325 0           croak_xs_usage(cv, "num, inclusive");
326             {
327             float RETVAL;
328 0 0         dXSTARG;
329 0           U32 num = (unsigned long)SvUV(ST(0))
330             ;
331 0           U8 inclusive = (U8)SvUV(ST(1))
332             ;
333              
334 0           RETVAL = _uint32_to_float(num, inclusive);
335 0 0         TARGn((double)RETVAL, 1);
336 0           ST(0) = TARG;
337             }
338 0           XSRETURN(1);
339             }
340              
341             #ifdef __cplusplus
342             extern "C" {
343             #endif
344             XS_EXTERNAL(boot_Random__Simple); /* prototype to pass -Wmissing-prototypes */
345 9           XS_EXTERNAL(boot_Random__Simple)
346             {
347             #if PERL_VERSION_LE(5, 21, 5)
348             dVAR; dXSARGS;
349             #else
350 9           dVAR; dXSBOOTARGSXSAPIVERCHK;
351             #endif
352             #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
353             char* file = __FILE__;
354             #else
355 9           const char* file = __FILE__;
356             #endif
357              
358             PERL_UNUSED_VAR(file);
359              
360             PERL_UNUSED_VAR(cv); /* -W */
361             PERL_UNUSED_VAR(items); /* -W */
362             #if PERL_VERSION_LE(5, 21, 5)
363             XS_VERSION_BOOTCHECK;
364             # ifdef XS_APIVERSION_BOOTCHECK
365             XS_APIVERSION_BOOTCHECK;
366             # endif
367             #endif
368              
369 9           (void)newXSproto_portable("Random::Simple::_rand32", XS_Random__Simple__rand32, file, "");
370 9           (void)newXSproto_portable("Random::Simple::_rand64", XS_Random__Simple__rand64, file, "");
371 9           (void)newXSproto_portable("Random::Simple::_hash_mur3", XS_Random__Simple__hash_mur3, file, "$");
372 9           (void)newXSproto_portable("Random::Simple::_seed", XS_Random__Simple__seed, file, "$$");
373 9           (void)newXSproto_portable("Random::Simple::_bounded_rand32_lemire", XS_Random__Simple__bounded_rand32_lemire, file, "$");
374 9           (void)newXSproto_portable("Random::Simple::_bounded_rand64_rejection", XS_Random__Simple__bounded_rand64_rejection, file, "$");
375 9           (void)newXSproto_portable("Random::Simple::_uint64_to_double", XS_Random__Simple__uint64_to_double, file, "$$");
376 9           (void)newXSproto_portable("Random::Simple::_uint32_to_float", XS_Random__Simple__uint32_to_float, file, "$$");
377             #if PERL_VERSION_LE(5, 21, 5)
378             # if PERL_VERSION_GE(5, 9, 0)
379             if (PL_unitcheckav)
380             call_list(PL_scopestack_ix, PL_unitcheckav);
381             # endif
382             XSRETURN_YES;
383             #else
384 9           Perl_xs_boot_epilog(aTHX_ ax);
385             #endif
386 9           }
387              
388             #ifdef __cplusplus
389             }
390             #endif