| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/* |
|
2
|
|
|
|
|
|
|
* perl_math_int128.c - This file is in the public domain |
|
3
|
|
|
|
|
|
|
* Author: Salvador Fandino <sfandino@yahoo.com>, Dave Rolsky <autarch@urth.org> |
|
4
|
|
|
|
|
|
|
* |
|
5
|
|
|
|
|
|
|
* Generated on: 2015-03-11 11:04:45 |
|
6
|
|
|
|
|
|
|
* Math::Int128 version: 0.21 |
|
7
|
|
|
|
|
|
|
*/ |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#include "EXTERN.h" |
|
10
|
|
|
|
|
|
|
#include "perl.h" |
|
11
|
|
|
|
|
|
|
#include "ppport.h" |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#if ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
/* workaroung for gcc 4.4/4.5 - see http://gcc.gnu.org/gcc-4.4/changes.html */ |
|
16
|
|
|
|
|
|
|
typedef int int128_t __attribute__ ((__mode__ (TI))); |
|
17
|
|
|
|
|
|
|
typedef unsigned int uint128_t __attribute__ ((__mode__ (TI))); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#else |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
typedef __int128 int128_t; |
|
22
|
|
|
|
|
|
|
typedef unsigned __int128 uint128_t; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#endif |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
HV *math_int128_c_api_hash = NULL; |
|
28
|
|
|
|
|
|
|
int math_int128_c_api_min_version = 0; |
|
29
|
|
|
|
|
|
|
int math_int128_c_api_max_version = 0; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
int128_t (*math_int128_c_api_SvI128)(pTHX_ SV *sv) = NULL; |
|
32
|
|
|
|
|
|
|
int (*math_int128_c_api_SvI128OK)(pTHX_ SV*) = NULL; |
|
33
|
|
|
|
|
|
|
int128_t (*math_int128_c_api_SvU128)(pTHX_ SV *sv) = NULL; |
|
34
|
|
|
|
|
|
|
int (*math_int128_c_api_SvU128OK)(pTHX_ SV*) = NULL; |
|
35
|
|
|
|
|
|
|
SV * (*math_int128_c_api_newSVi128)(pTHX_ int128_t i128) = NULL; |
|
36
|
|
|
|
|
|
|
SV * (*math_int128_c_api_newSVu128)(pTHX_ uint128_t u128) = NULL; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
int |
|
39
|
18
|
|
|
|
|
|
perl_math_int128_load(int required_version) { |
|
40
|
18
|
|
|
|
|
|
dTHX; |
|
41
|
18
|
|
|
|
|
|
SV **svp; |
|
42
|
|
|
|
|
|
|
|
|
43
|
18
|
|
|
|
|
|
eval_pv("require Math::Int128", TRUE); |
|
44
|
18
|
50
|
|
|
|
|
if (SvTRUE(ERRSV)) return 0; |
|
|
|
50
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
18
|
|
|
|
|
|
math_int128_c_api_hash = get_hv("Math::Int128::C_API", 0); |
|
47
|
18
|
50
|
|
|
|
|
if (!math_int128_c_api_hash) { |
|
48
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to load Math::Int128 C API"); |
|
49
|
0
|
|
|
|
|
|
return 0; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
18
|
|
|
|
|
|
math_int128_c_api_min_version = SvIV(*hv_fetch(math_int128_c_api_hash, "min_version", 11, 1)); |
|
53
|
18
|
|
|
|
|
|
math_int128_c_api_max_version = SvIV(*hv_fetch(math_int128_c_api_hash, "max_version", 11, 1)); |
|
54
|
18
|
50
|
|
|
|
|
if ((required_version < math_int128_c_api_min_version) || |
|
|
|
50
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
(required_version > math_int128_c_api_max_version)) { |
|
56
|
0
|
0
|
|
|
|
|
sv_setpvf_mg(ERRSV, |
|
57
|
|
|
|
|
|
|
"Math::Int128 C API version mismatch. " |
|
58
|
|
|
|
|
|
|
"The installed module supports versions %d to %d but %d is required", |
|
59
|
|
|
|
|
|
|
math_int128_c_api_min_version, |
|
60
|
|
|
|
|
|
|
math_int128_c_api_max_version, |
|
61
|
|
|
|
|
|
|
required_version); |
|
62
|
0
|
|
|
|
|
|
return 0; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "SvI128", 6, 0); |
|
66
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvI128' C function from Math::Int128"); |
|
68
|
0
|
|
|
|
|
|
return 0; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
18
|
|
|
|
|
|
math_int128_c_api_SvI128 = INT2PTR(void *, SvIV(*svp)); |
|
71
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "SvI128OK", 8, 0); |
|
72
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvI128OK' C function from Math::Int128"); |
|
74
|
0
|
|
|
|
|
|
return 0; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
18
|
|
|
|
|
|
math_int128_c_api_SvI128OK = INT2PTR(void *, SvIV(*svp)); |
|
77
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "SvU128", 6, 0); |
|
78
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvU128' C function from Math::Int128"); |
|
80
|
0
|
|
|
|
|
|
return 0; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
18
|
|
|
|
|
|
math_int128_c_api_SvU128 = INT2PTR(void *, SvIV(*svp)); |
|
83
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "SvU128OK", 8, 0); |
|
84
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvU128OK' C function from Math::Int128"); |
|
86
|
0
|
|
|
|
|
|
return 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
18
|
|
|
|
|
|
math_int128_c_api_SvU128OK = INT2PTR(void *, SvIV(*svp)); |
|
89
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "newSVi128", 9, 0); |
|
90
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'newSVi128' C function from Math::Int128"); |
|
92
|
0
|
|
|
|
|
|
return 0; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
18
|
|
|
|
|
|
math_int128_c_api_newSVi128 = INT2PTR(void *, SvIV(*svp)); |
|
95
|
18
|
|
|
|
|
|
svp = hv_fetch(math_int128_c_api_hash, "newSVu128", 9, 0); |
|
96
|
18
|
50
|
|
|
|
|
if (!svp || !*svp) { |
|
|
|
50
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
sv_setpv_mg(ERRSV, "Unable to fetch pointer 'newSVu128' C function from Math::Int128"); |
|
98
|
0
|
|
|
|
|
|
return 0; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
18
|
|
|
|
|
|
math_int128_c_api_newSVu128 = INT2PTR(void *, SvIV(*svp)); |
|
101
|
|
|
|
|
|
|
|
|
102
|
18
|
|
|
|
|
|
return 1; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|