line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2021 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Faster::Maths 0.01; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
143255
|
use v5.14; |
|
3
|
|
|
|
|
28
|
|
9
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
342
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require XSLoader; |
12
|
|
|
|
|
|
|
XSLoader::load( __PACKAGE__, our $VERSION ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
C - make mathematically-intense programs faster |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Faster::Maths; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# and that's it :) |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module installs an optimizer into the perl compiler that looks for |
27
|
|
|
|
|
|
|
sequences of maths operations that it can make faster. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
When this module is lexically in scope, mathematical expressions composed of |
30
|
|
|
|
|
|
|
the four basic operators (C<+>, C<->, C<*>, C>) operating on lexical |
31
|
|
|
|
|
|
|
variables and constants will be compiled into a form that is more efficient at |
32
|
|
|
|
|
|
|
runtime. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub import |
37
|
|
|
|
|
|
|
{ |
38
|
3
|
|
|
3
|
|
3413
|
$^H{"Faster::Maths/faster"}++; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub unimport |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
|
|
delete $^H{"Faster::Maths/faster"}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 TODO |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 2 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Recognise more potential arguments - padrange and package variables at least. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item * |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Recognise more operators - C<%>, unary C<-> and C, possibly other unary |
57
|
|
|
|
|
|
|
operators like C. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Recognise the presence of overloading magic on variables and fall back to |
62
|
|
|
|
|
|
|
slower-but-correct operation in that case. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item * |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Split the runtime loop into IV/UV/NV cases, further optimise the accumulator |
67
|
|
|
|
|
|
|
value in each case. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Store IV/UV constants as values directly in the UNOP_AUX structure avoiding |
72
|
|
|
|
|
|
|
the need for SV lookup on them. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Back-compatibility to perls older than 5.22.0 by providing an UNOP_AUX |
77
|
|
|
|
|
|
|
implementation. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Paul Evans |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
0x55AA; |