| 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 | ▶ | use v5.14; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 3 | require XSLoader; | |
| 12 | 3 | XSLoader::load( __PACKAGE__, our $VERSION ); | |
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | C<Faster::Maths> - 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 | 3 | ▶ | { |
|
Subroutine
import: called CC=1 SCAR=0.0
| |||
| 38 | 3 | $^H{"Faster::Maths/faster"}++; | |
| 39 | } | ||
| 40 | |||
| 41 | sub unimport | ||
| 42 | 0 | ▶ | { |
|
Subroutine
unimport: not called CC=1 SCAR=6.9
| |||
| 43 | 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<https://rt.cpan.org/Ticket/Display.html?id=136453> | ||
| 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<https://rt.cpan.org/Ticket/Display.html?id=136454> | ||
| 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<sqrt>, possibly other unary | ||
| 82 | operators like C<sin>. | ||
| 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 <leonerd@leonerd.org.uk> | ||
| 101 | |||
| 102 | =cut | ||
| 103 | |||
| 104 | 3 | 0x55AA; | |