Commit Graph

391 Commits

Author SHA1 Message Date
Peter Kokot
f66feaec0f
Sync HAVE_<extension> help texts (#15167)
This syncs all help texts of extension preprocessor macros to the same
style "Define to 1 if the PHP extension '<ext>' is available.".
[skip ci]
2024-08-02 01:41:47 +02:00
Peter Kokot
1ceadaed52
Autotools: Normalize and quote all PHP_NEW_EXTENSION arguments (#15144)
This adds Autoconf quote characters to all PHP_NEW_EXTENSION arguments
and syncs the CS across the php-src Autotools build system.
2024-07-29 00:14:59 +02:00
Saki Takamachi
8a4a30469a
Zend: Add ZEND_BYTES_SWAP32/ZEND_BYTES_SWAP64 (#14910) 2024-07-22 17:57:16 +09:00
Peter Kokot
6857c7c8d6
Autotools: Expand m4_normalize sooner (#15018)
Quoted m4_normalize will expand and change its argument later in the
macro call when M4 is processing the *.m4 sources. Without quotes the
already normalized string is passed to the macro directly. In these
specific cases generated configure script is the same. This is more for
consistency to have this synced and not repeat the pattern too much
in the future when copy/pasting. Note, that many AC_* macros require
similar behavior already (for example, AC_CHECK_FUNCS.)
2024-07-19 15:20:04 +02:00
Tim Düsterhus
5905857fd2
RFC: Add the RoundingMode enum (#14833)
see https://wiki.php.net/rfc/correctly_name_the_rounding_mode_and_make_it_an_enum

Co-authored-by: Saki Takamachi <saki@php.net>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-07-18 20:44:30 +02:00
Saki Takamachi
3c9ab6eb71
ext/bcmath: Moved macros and added a test 2024-07-17 21:48:16 +09:00
Peter Kokot
0e2e8e0f13
Autotools: Quote all PHP_ADD_BUILD_DIR arguments (#14947)
- All arguments quoted for consistency
- m4_normalize used where list of directories becomes a bit simpler to
  read and see the diff
2024-07-14 16:58:43 +02:00
Saki Takamachi
be4b10e95e
Added scale to bc_compare argument (#14802)
In the original specification, the scale of bc_num was directly changed
and compared.

This becomes a problem when objects are supported, so we will modify it
to compare without changing bc_num.
2024-07-12 00:08:47 +09:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Peter Kokot
835cb69ab5
Normalize bcmath extension sources (#14655)
Follow-up of GH-14654
2024-06-24 22:51:51 +02:00
Saki Takamachi
37488d6e01
ext/bcmath: Minor fixes to bcmul() (#14564)
The original calculation method for prod_arr_size allowed for some error,
which could have increased the number of simple loops without byte tricks
at the end of the calculation when converting to bc_num.

The new method calculates the size accurately, so the number of loops does
not increase unnecessarily.
2024-06-14 02:20:32 +09:00
Saki Takamachi
25579a8616
ext/bcmath: Renamed macros and variables (#14507)
Made the macro BC_UINT_T a typedef and renamed it BC_VECTOR.

Additionally, several macros have been renamed to be consistent with BC_VECTOR.
2024-06-09 09:11:11 +09:00
Gina Peter Banyard
ec54edb9e1
ext/bcmath: Use an enum for comparison result (#14374)
Improve logic of callers of bc_compare
2024-05-30 17:26:03 +01:00
Gina Peter Banyard
c7bdf30daa
Merge branch 'PHP-8.3'
* PHP-8.3:
  ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)
2024-05-30 15:52:45 +01:00
Gina Peter Banyard
ba7b305530
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0)
2024-05-30 15:51:05 +01:00
Gina Peter Banyard
709869c8bd
ext/bcmath: Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0) 2024-05-30 15:47:25 +01:00
Niels Dossche
4e99bb5935 Faster BCD into integer parsing 2024-05-23 22:38:21 +02:00
Niels Dossche
04a34c3433 Faster writing of BCD representation 2024-05-23 22:38:21 +02:00
Niels Dossche
aef0eada16 Use size_t for length 2024-05-23 22:38:21 +02:00
Saki Takamachi
8734a9a4af
ext/bcmath: Prevent overflow of uint32_t/uint64_t (#14297)
If add more than a certain number of times, it will overflow, so need to adjust
the digits before adding.
2024-05-23 06:13:11 +09:00
Gina Peter Banyard
d775ba8804
ext/bcmath: Fix [-Wenum-int-mismatch] compiler warning 2024-05-21 12:17:25 +01:00
Saki Takamachi
1d38656b6d
ext/bcmath: Changed the bcmul calculation method (#14213)
Multiplication is performed after converting to uint32_t/uint64_t, making calculations faster.

---------

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2024-05-20 20:29:19 +09:00
Saki Takamachi
22c7250d50
ext/bcmath: Avoid unnecessary memset from _bc_do_add (#14257)
Apply the same changes as #14180 to _bc_do_add.
2024-05-18 07:00:47 +09:00
Saki Takamachi
959ea5fb83
Avoid unnecessary memset (#14180)
Avoid unnecessary memset from `_bc_do_sub`
2024-05-17 08:03:34 +09:00
Saki Takamachi
7203ca8286
ext/bcmath: Made the same changes to _bc_do_add as _bc_do_sub (#14196)
The code for _bc_do_add and _bc_do_sub were written slightly differently for
similar processing (and add was slower than sub), so I changed the code to one
similar to sub.

Also, _bc_do_add has been changed to use SIMD to perform faster calculations
when possible.
2024-05-12 15:07:37 +09:00
Saki Takamachi
e976c2d4f0
ext/bcmath: Fixed an issue where macros may become undefined (#14179) 2024-05-10 09:13:03 +09:00
Saki Takamachi
1a3d870c1e
ext/bcmath: Use SIMD for trailing zero counts during conversion (#14166)
Changed to count trailing zeros using SIMD when converting a string to
a bc_num structure if possible.

Removed unnecessary pointer resetting.

Added UNEXPECTED to some branches.
2024-05-09 19:23:59 +09:00
Niels Dossche
70b5a4d554
BCMath: Avoid using the heap for temporary objects by using arena allocations (#14170)
* BCMath: Avoid using the heap for temporary objects by using arena allocations

* Fix alignment

* Improve size computation
2024-05-08 19:36:14 +02:00
Niels Dossche
90a5b871ef
Simplify conversion in BCMath (#14157)
This simplifies the code, and also might indirectly improve performance
due to a decrease in instruction cache pressure. Although the latter is
probably negligible.

This works because 0x30 has no overlapping bits with [0, 9].
2024-05-07 18:24:00 +02:00
Saki Takamachi
02732007f7
Refactor BCMath _bc_do_sub (#14132)
_bc_do_sub now uses SIMD to perform calculations at high speed.

Moved the macros used for SIMD to `private.h`, and added some constants
and macros.
2024-05-07 11:39:31 +09:00
Gina Peter Banyard
70acd6e9ad
ext/bcmath: Remove unused ODD() macro function 2024-05-05 01:02:46 +01:00
Niels Dossche
bf3c4870b6
Avoid needless memsets by creating a variant of bc_new_num that doesn't memset (#14133)
Also avoid some memsets where we do call bc_new_num.

After:
```
1.2066178321838
1.5389559268951
1.6050860881805
```

Before:
```
1.3858470916748
1.6806011199951
1.9091980457306
```
2024-05-04 17:11:57 +02:00
Saki Takamachi
1ae58d4784
ext/bcmath: Removed unnecessary zero padding (#14134)
bc_num is initialized to 0 by `memset`, so there is no need to write it to 0.
2024-05-05 00:03:08 +09:00
Niels Dossche
a728e541e9
Remove some dead code from BCMath (#14130)
* Remove unused output.c code

* Remove unused ignore_last parameter from _bc_do_compare()
2024-05-04 16:00:54 +02:00
Niels Dossche
b8abd2693e
Increase test coverage of _bc_do_add() (#14131)
The final carry code was not tested.
2024-05-04 16:00:47 +02:00
Niels Dossche
cad0e555ac
Faster validation logic in bc_str2num() (#14115)
Using SIMD to accelerate the validation.

Using the benchmark from #14076.

After:
```
1.3504369258881
1.6206321716309
1.6845638751984
```

Before:
```
1.4750170707703
1.9039781093597
1.9632289409637
```
2024-05-03 17:34:38 +02:00
Niels Dossche
039344cf70 Avoid extra inits while flooring or ceiling 2024-05-02 20:03:59 +02:00
Niels Dossche
34b2116eb5 Avoid unnecessary destruction in bc_mul() 2024-05-02 20:03:59 +02:00
Niels Dossche
0cd952d851 Avoid unnecessary destruction in bc_sub() 2024-05-02 20:03:59 +02:00
Niels Dossche
959e11544c Avoid unnecessary destruction in bc_add() 2024-05-02 20:03:59 +02:00
Niels Dossche
a604d1d342 Use SSE2 in bc_copy_and_shift_numbers() if possible 2024-05-02 20:03:59 +02:00
Niels Dossche
4964c5cb23 Move bc_copy_num to header to allow inlining 2024-05-02 20:03:59 +02:00
Niels Dossche
be072d7be4 Use RETVAL_NEW_STR
The strings are always new, not interned.
2024-05-02 20:03:59 +02:00
Niels Dossche
a66439adbb
Avoid unnecessary number initializations in BCMath (#14104)
Since freeing can deal with NULL, we can avoid calling bc_init_num and
avoid resetting the number during parsing.

Using benchmark from #14076.

Before:
```
1.544440984726
2.0288550853729
2.092139005661
```

After:
```
1.5324399471283
1.9081380367279
2.065819978714
```
2024-05-01 17:52:06 +02:00
Niels Dossche
0a3ccc0b99
Use bulk conversion in BCMath of BCD/CHAR where possible (#14103)
On my i7-4790 with benchmark from #14076, on top of #14101 I obtain the
following results:

before (with #14101):
```
1.672737121582
2.3618471622467
2.3474779129028
```

after (with #14101 + this):
```
1.5878579616547
2.0568618774414
2.0204811096191
```
2024-05-01 16:48:42 +02:00
Niels Dossche
d2d4596f20 Use an unsigned number for the refcount of bcmath objects 2024-05-01 16:18:37 +02:00
Niels Dossche
5dc11de558 Merge n_value and n_ptr 2024-05-01 16:18:37 +02:00
Niels Dossche
3215e86a11 Avoid double allocation in _bc_new_num_ex
Since the two allocations are tied together anyway, we can just use a
single allocation. Moreover, this actually seemed like the intention
because the bc_struct allocation already accounted for the length and
scale.
2024-05-01 16:18:37 +02:00
Saki Takamachi
a481556d31
Refactor BCMath (#14076)
Optimized the order of structure members and the process of converting
strings to bc_num structures.

closes #14076
2024-05-01 21:54:23 +09:00
Saki Takamachi
5359392717
[RFC] Add bcfloor, bcceil and bcround to BCMath (#13096)
Implementation for the "Adding bcround, bcfloor and bcceil to BCMath" RFC: https://wiki.php.net/rfc/adding_bcround_bcfloor_bcceil_to_bcmath

* Separated round mode into separate header file

Co-authored-by: Gina Peter Banyard <girgias@php.net>
2024-04-30 18:32:33 +01:00