File Coverage

blib/lib/Faster/Maths.pm
Criterion Covered Total %
statement 6 7 85.7
branch n/a
condition n/a
subroutine 3 4 75.0
pod n/a
total 9 11 81.8


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.02;
7              
8 3     3   144389 use v5.14;
  3         30  
9 3     3   17 use warnings;
  3         14  
  3         359  
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   3438 $^H{"Faster::Maths/faster"}++;
39             }
40              
41             sub unimport
42             {
43 0     0     delete $^H{"Faster::Maths/faster"};
44             }
45              
46             =head2 BUGS
47              
48             =over 2
49              
50             =item *
51              
52             Does not currently respect operator overloading. All values will get converted
53             into NVs individually, and composed using regular NV maths.
54              
55             We should recognise the presence of overloading magic on variables and fall
56             back to slower-but-correct operation in that case; also potentially ignore any
57             OP_CONSTs with magical values.
58              
59             L
60              
61             =item *
62              
63             Does not currently retain full integer precision on integer values larger than
64             platform float (NV) size. All values will get converted to NVs immediately,
65             thus losing the lower bits of precision if the value is too large.
66              
67             L
68              
69             =back
70              
71             =head1 TODO
72              
73             =over 2
74              
75             =item *
76              
77             Recognise more potential arguments - padrange and package variables at least.
78              
79             =item *
80              
81             Recognise more operators - C<%>, unary C<-> and C, possibly other unary
82             operators like C.
83              
84             =item *
85              
86             Store IV/UV constants as values directly in the UNOP_AUX structure avoiding
87             the need for SV lookup on them.
88              
89             =item *
90              
91             Back-compatibility to perls older than 5.22.0 by providing an UNOP_AUX
92             implementation.
93              
94             =back
95              
96             =cut
97              
98             =head1 AUTHOR
99              
100             Paul Evans
101              
102             =cut
103              
104             0x55AA;