-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added zend_simd.h
#18413
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
Merged
Merged
Added zend_simd.h
#18413
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c896245
Added zend_simd.h
SakiTakamachi 178000f
use zend_simd in url.c
SakiTakamachi 37f66bc
use zend_simd.h in ZendAccelerator.c
SakiTakamachi 004123a
Use zend_simd.h as a wrapper for neon
SakiTakamachi 59efacf
use zend_simd.h in string.c
SakiTakamachi f142b6e
use zend_simd.h in bcmath
SakiTakamachi 4f0fc89
Changed argument type from `int8x16_t` to `__m128i` for type hinting.
SakiTakamachi d00d75d
fixed `_mm_set_epi64` to `_mm_set_epi64x`
SakiTakamachi 22c505a
fixed `_mm_srli_si128` and `_mm_slli_si128`
SakiTakamachi 0f73ba4
fixed `_mm_add_epi8`
SakiTakamachi 0e9302b
Revert "use zend_simd.h in bcmath"
SakiTakamachi 95407ca
use "xsee.h" lib for zend_simd.h
SakiTakamachi 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 hidden or 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,83 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Zend Engine | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 2.00 of the Zend license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.zend.com/license/2_00.txt. | | ||
| If you did not receive a copy of the Zend 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 ZEND_SIMD_H | ||
#define ZEND_SIMD_H | ||
|
||
#ifdef __SSE2__ | ||
#include <emmintrin.h> | ||
#define ZEND_HAVE_VECTOR_128 | ||
|
||
|
||
#elif defined(__aarch64__) || defined(_M_ARM64) | ||
#include <arm_neon.h> | ||
#define ZEND_HAVE_VECTOR_128 | ||
|
||
typedef int8x16_t __m128i; | ||
|
||
#define _mm_setzero_si128() vdupq_n_s8(0) | ||
#define _mm_set1_epi8(x) vdupq_n_s8(x) | ||
#define _mm_set_epi16(x0, x1, x2, x3, x4, x5, x6, x7) \ | ||
vreinterpretq_s8_s16((int16x8_t) { \ | ||
(int16_t) (x7), (int16_t) (x6), (int16_t) (x5), (int16_t) (x4), \ | ||
(int16_t) (x3), (int16_t) (x2), (int16_t) (x1), (int16_t) (x0) }) | ||
#define _mm_set_epi32(x0, x1, x2, x3) \ | ||
vreinterpretq_s8_s32((int32x4_t) { (int32_t) (x3), (int32_t) (x2), (int32_t) (x1), (int32_t) (x0) }) | ||
#define _mm_set_epi64x(x0, x1) vreinterpretq_s8_s64((int64x2_t) { (int64_t) (x1), (int64_t) (x0) }) | ||
#define _mm_load_si128(x) vld1q_s8((const int8_t *) (x)) | ||
#define _mm_loadu_si128(x) _mm_load_si128(x) | ||
#define _mm_store_si128(to, x) vst1q_s8((int8_t *) (to), x) | ||
#define _mm_storeu_si128(to, x) _mm_store_si128(to, x) | ||
|
||
#define _mm_or_si128(a, b) vorrq_s8(a, b) | ||
#define _mm_xor_si128(a, b) veorq_s8(a, b) | ||
#define _mm_and_si128(a, b) vandq_s8(a, b) | ||
|
||
#define _mm_slli_si128(x, imm) \ | ||
((imm) >= 16 ? vdupq_n_s8(0) : \ | ||
vreinterpretq_s8_u8(vextq_u8(vdupq_n_u8(0), vreinterpretq_u8_s8(x), 16 - (imm)))) | ||
#define _mm_srli_si128(x, imm) \ | ||
((imm) >= 16 ? vdupq_n_s8(0) : \ | ||
vreinterpretq_s8_u8(vextq_u8(vreinterpretq_u8_s8(x), vdupq_n_u8(0), (imm)))) | ||
|
||
/** | ||
* In practice, there is no problem, but a runtime error for signed integer overflow is triggered by UBSAN, | ||
* so perform the calculation as unsigned. Since it is optimized at compile time, there are no unnecessary casts at runtime. | ||
*/ | ||
#define _mm_add_epi8(a, b) vreinterpretq_s8_u8(vaddq_u8(vreinterpretq_u8_s8(a), vreinterpretq_u8_s8(b))) | ||
|
||
#define _mm_cmpeq_epi8(a, b) (vreinterpretq_s8_u8(vceqq_s8(a, b))) | ||
#define _mm_cmplt_epi8(a, b) (vreinterpretq_s8_u8(vcltq_s8(a, b))) | ||
#define _mm_cmpgt_epi8(a, b) (vreinterpretq_s8_u8(vcgtq_s8(a, b))) | ||
|
||
static zend_always_inline int _mm_movemask_epi8(__m128i x) | ||
{ | ||
/** | ||
* 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(x), 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 /* ZEND_SIMD_H */ |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
I think it would be better to license it under BSD (there are already other files) and not give copyright to Zend Technologies.
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.
Although copyright probably doesn't matter so I don't really mind. It's kind of the same like giving it to PHP Group. Once PHP Foundation will become legal entity, this should be much easier...
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.
Maybe add you as a copy right holder and just change it to BSD. It would be good because it will make easier to use this file elsewhere without pulling in Zend license...
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.
By elsewhere I mean outside php-src...
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.
I would like to potentially pull it to jso (project that I currently use for JsonSchema development). So it might be actually even better to license it under MIT.