Skip to content

Support build codepage.c for Windows arm64 #7702

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion win32/codepage.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

#include "php.h"
#include "SAPI.h"
#include <emmintrin.h>
#ifdef _M_ARM64
# include <arm_neon.h>
#else
# include <emmintrin.h>
#endif // _M_ARM64

#include "win32/console.h"

Expand Down Expand Up @@ -134,6 +138,18 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
}

/* Process aligned chunk. */
#ifdef _M_ARM64
uint8x16_t ver_err = {0};
while (end - idx > 15) {
const uint8x16_t block = vld1q_u8((const void*)idx);
ver_err = vorrq_u8(ver_err, block);
idx += 16;
}
ver_err = vshrq_n_u8(ver_err, 7);
if (vmaxvq_u8(ver_err)) {
ASCII_FAIL_RETURN()
}
#else
__m128i vec_err = _mm_setzero_si128();
while (end - idx > 15) {
const __m128i block = _mm_load_si128((__m128i *)idx);
Expand All @@ -143,6 +159,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
if (_mm_movemask_epi8(vec_err)) {
ASCII_FAIL_RETURN()
}
#endif // _M_ARM64
}

/* Process the trailing part, or otherwise process string < 16 bytes. */
Expand Down Expand Up @@ -173,6 +190,22 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size

/* Process aligned chunk. */
if (end - idx > 15) {
#ifdef _M_ARM64
while (end - idx > 15) {
/*
vst2q_u8 below will store interlaced vector by 8bits, so this will be little endian wchar
at wrote time all windows arm64 is little endian
*/
uint8x16x2_t vec = {/* .val = */{
vld1q_u8((const void*)idx),
{0},
}};

vst2q_u8((void*)ret_idx, vec);
idx += 16;
ret_idx += 16;
}
#else
const __m128i mask = _mm_set1_epi32(0);
while (end - idx > 15) {
const __m128i block = _mm_load_si128((__m128i *)idx);
Expand All @@ -187,6 +220,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size
idx += 16;
ret_idx += 8;
}
#endif // _M_ARM64
}
}

Expand Down