1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Commit Graph

143 Commits

Author SHA1 Message Date
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
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
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
Saki Takamachi
5d91f8761b Remove rscale in bc_raisemod
power is a copy of base and returns early if base->n_scale is non-zero. Since
scale is size_t, it is always greater than or equal to 0, so rscale is always
the value of scale.
2024-04-11 08:59:48 +09:00
Jorg Adam Sowa
6647d5f609 ext/bcmath: Remove debug.c file (#13359) 2024-02-09 11:29:57 +00:00
Jorg Adam Sowa
e56ed6e1ab BCmath extension code reformatting (#11896)
Re-formats the BCmath extension to have consistent formatting.

Mostly, it adds the spaces in calculations to have them more readable.

Also:

   -  removes unused headers
   -  removes few variables which are used only once in the code

Co-authored-by: George Peter Banyard <girgias@php.net>
2023-08-13 16:17:36 +01:00
Jorg Adam Sowa
549c657897 Fix GH-11761: Bcmath numbers with trailing zeros (#11798) 2023-07-26 13:48:50 +01:00
George Peter Banyard
68247c02d5 Refactor BCMath bundledlib and extension (#10774)
* ext/bcmath: coding style: use indentation

And add braces to block statements, as the current code was pretty much unreadable with how inconsistent it was.

* ext/bcmath: Remove some useless header inclusions

* ext/bcmath: Use standard C99 bool type instead of char

* ext/bcmath: Include specific headers instead of config.h

* Restructure definitions to reduce header inclusions

* Use size_t as a more appropriate type

* Remove unused variable full_scale

* Refactor bc_raisemod() to get rid of Zend dependencies

This separates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsibility of the library

* Refactor bc_raise() to get rid of Zend dependencies

This separates the concerns of throwing exceptions back into the PHP_FUNCTION instead of being the responsibility of the library

* Refactor bc_divmod() and bc_modulo() to return bool

Return false on division by 0 attempt instead of -1 and true on success instead of 0

* Refactor bc_divide() to return bool

Return false on division by 0 attempt instead of -1 and true on success instead of 0
2023-07-24 16:42:34 +01:00
George Peter Banyard
82e761eaac Fix [-Wenum-int-mismatch] compiler warnings (#11352) 2023-06-01 13:27:46 +01:00
George Peter Banyard
f13d541ca6 Fix GCC 12 compiler warnings (#10713)
* Fix -Wunused-but-set-variable compiler warning in ext/mysqli

* Fix -Wstrict-prototypes compiler warning in ext/mysqlnd

* Fix -Wstrict-prototypes compiler warning in ext/soap

* Fix -Wunused-but-set-variable compiler warning in ext/exif

However, this code looks really sketchy...

* Fix -Wstrict-prototypes compiler warning in ext/openssl

* Fix -Wstrict-prototypes compiler warning in ext/dba

Add void to our bundled libraries

* Refactor bundled BCMath library

Fix -Wdeprecated-non-prototype compiler warnings
Use bool instead of char/int
Cleanup some useless header includes
2023-02-28 14:21:01 +00:00
Max Kellermann
d46dea169c Make globals const (part 2) (#10610)
* Zend/zend_enum: make `forbidden_methods` static+const

* main/php_syslog: make `xdigits` static

* sapi/fpm: make several globals `const`

* sapi/phpdbg: make `OPTIONS` static

* sapi/phpdbg/help: make help texts const

* sapi/cli: make `template_map` const

* ext/ffi: make `zend_ffi_types` static

* ext/bcmath: make `ref_str` const

* ext/phar: make several globals static+const
2023-02-18 19:52:53 +00:00
Christoph M. Becker
d66854bece Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix #78238: BCMath returns "-0"
2021-07-16 16:01:03 +02:00
Christoph M. Becker
9fbcaa57aa Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix #78238: BCMath returns "-0"
2021-07-16 15:56:15 +02:00
Christoph M. Becker
bcb89c75ec Fix #78238: BCMath returns "-0"
There is no negative zero in the decimal system, so we must suppress
the sign.

Closes GH-7250.
2021-07-16 15:54:24 +02:00
George Peter Banyard
57a8bf62dd Use standard function declaration style instead of K&R in libbcmath
Fixes [-Wstrict-prototypes] warnings.
2021-05-12 15:33:55 +01:00
Nikita Popov
3d2819e491 Fix memory leak with bcsqrt on number 0<X<1 2020-11-12 11:37:54 +01:00