-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ext/bcmath: In the arm processor environment, NEON is used to use SIMD. #18130
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| https://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Authors: Saki Takamachi <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
|
||
#ifndef _BCMATH_SIMD_H_ | ||
#define _BCMATH_SIMD_H_ | ||
|
||
#ifdef __SSE2__ | ||
# include <emmintrin.h> | ||
typedef __m128i bc_simd_128_t; | ||
# define HAVE_BC_SIMD_128 | ||
# define bc_simd_set_8x16(x) _mm_set1_epi8(x) | ||
# define bc_simd_load_8x16(ptr) _mm_loadu_si128((const __m128i *) (ptr)) | ||
# define bc_simd_xor_8x16(a, b) _mm_xor_si128(a, b) | ||
# define bc_simd_store_8x16(ptr, val) _mm_storeu_si128((__m128i *) (ptr), val) | ||
# define bc_simd_add_8x16(a, b) _mm_add_epi8(a, b) | ||
# define bc_simd_cmpeq_8x16(a, b) _mm_cmpeq_epi8(a, b) | ||
# define bc_simd_cmplt_8x16(a, b) _mm_cmplt_epi8(a, b) | ||
# define bc_simd_movemask_8x16(a) _mm_movemask_epi8(a) | ||
|
||
#elif defined(__aarch64__) || defined(_M_ARM64) | ||
# include <arm_neon.h> | ||
typedef int8x16_t bc_simd_128_t; | ||
# define HAVE_BC_SIMD_128 | ||
# define bc_simd_set_8x16(x) vdupq_n_s8(x) | ||
# define bc_simd_load_8x16(ptr) vld1q_s8((const int8_t *) (ptr)) | ||
# define bc_simd_xor_8x16(a, b) veorq_s8(a, b) | ||
# define bc_simd_store_8x16(ptr, val) vst1q_s8((int8_t *) (ptr), val) | ||
# define bc_simd_add_8x16(a, b) vaddq_s8(a, b) | ||
# define bc_simd_cmpeq_8x16(a, b) (vreinterpretq_s8_u8(vceqq_s8(a, b))) | ||
# define bc_simd_cmplt_8x16(a, b) (vreinterpretq_s8_u8(vcltq_s8(a, b))) | ||
static inline int bc_simd_movemask_8x16(int8x16_t vec) | ||
{ | ||
/** | ||
* based on code from | ||
* https://community.arm.com/arm-community-blogs/b/servers-and-cloud-computing-blog/posts/porting-x86-vector-bitmask-optimizations-to-arm-neon | ||
*/ | ||
uint16x8_t high_bits = vreinterpretq_u16_u8(vshrq_n_u8(vreinterpretq_u8_s8(vec), 7)); | ||
uint32x4_t paired16 = vreinterpretq_u32_u16(vsraq_n_u16(high_bits, high_bits, 7)); | ||
uint64x2_t paired32 = vreinterpretq_u64_u32(vsraq_n_u32(paired16, paired16, 14)); | ||
uint8x16_t paired64 = vreinterpretq_u8_u64(vsraq_n_u64(paired32, paired32, 28)); | ||
return vgetq_lane_u8(paired64, 0) | ((int) vgetq_lane_u8(paired64, 8) << 8); | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be interesting to know if there's a way to get the byte position without something like movemask. Anyway this is likely good enough for now.