Skip to content

Cast the parameter type of arm BLOCKCONV_LOAD #14159

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

Conversation

SakiTakamachi
Copy link
Member

@SakiTakamachi SakiTakamachi commented May 7, 2024

take2 of #14151
The conflict was bothersome, so I redid the PR.

When compiling with a combination of Arm and gcc, the following runtime error will occur, so fix it.

# export  UBSAN_OPTIONS=print_stacktrace=1
# php -v
/usr/lib/gcc/aarch64-linux-gnu/11/include/arm_neon.h:758:14: runtime error: signed integer overflow: 103 + 63 cannot be represented in type 'signed char'
    #0 0xaaaac38f7ddc in vaddq_s8 /usr/lib/gcc/aarch64-linux-gnu/11/include/arm_neon.h:758
    #1 0xaaaac38f7ddc in zend_string_tolower_ex /php-src/Zend/zend_operators.c:3056
    #2 0xaaaac3953a34 in zend_register_functions /php-src/Zend/zend_API.c:2981
    #3 0xaaaac394b9b0 in zend_register_module_ex /php-src/Zend/zend_API.c:2568
    #4 0xaaaac39c98f8 in zend_startup_builtin_functions /php-src/Zend/zend_builtin_functions.c:63
    #5 0xaaaac39120c4 in zend_startup /php-src/Zend/zend.c:1030
    #6 0xaaaac3630ee0 in php_module_startup /php-src/main/main.c:2117
    #7 0xaaaac41e31dc in php_cli_startup /php-src/sapi/cli/php_cli.c:410
    #8 0xaaaac41e8f58 in main /php-src/sapi/cli/php_cli.c:1307
    #9 0xffff9cea73f8 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #10 0xffff9cea74c8 in __libc_start_main_impl ../csu/libc-start.c:392
    #11 0xaaaac2a161ec in _start (/usr/local/bin/php+0x20361ec)

configure:

./configure --enable-debug --disable-all CFLAGS='-ffp-contract=off -fsanitize=undefined,address -fno-sanitize-recover -DZEND_TRACK_ARENA_ALLOC' LDFLAGS='-fsanitize=undefined,address'

master: OK
8.3: OK

@SakiTakamachi SakiTakamachi force-pushed the fix_blockconv_arm_83 branch from a2f042d to 6404f33 Compare May 7, 2024 00:06
@SakiTakamachi SakiTakamachi marked this pull request as ready for review May 7, 2024 00:43
@SakiTakamachi SakiTakamachi requested a review from iluuu1994 as a code owner May 7, 2024 00:43
@SakiTakamachi SakiTakamachi requested a review from nielsdos May 7, 2024 00:43
@SakiTakamachi SakiTakamachi changed the title Cast the parameter type of arm's BLOCKCONV_LOAD (8.3) Cast the parameter type of arm's BLOCKCONV_LOAD May 7, 2024
@@ -122,7 +122,7 @@ static _locale_t current_locale = NULL;

#define BLOCKCONV_LOAD(input) \
int8x16_t blconv_operand = vld1q_s8((const int8_t*)(input)); \
uint8x16_t blconv_mask = vcltq_s8(vaddq_s8(blconv_operand, blconv_offset), blconv_threshold);
uint8x16_t blconv_mask = vcltq_s8(vreinterpretq_s8_u8(vaddq_u8(vreinterpretq_u8_s8(blconv_operand), vreinterpretq_u8_s8(blconv_offset))), blconv_threshold);
Copy link
Member Author

@SakiTakamachi SakiTakamachi May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(edit)
vreinterpretq_u8_s8 converts int8x16_t to uint8x16_t. vreinterpretq_s8_u8 is the opposite.
(vreinterpretq_{to}_{from})

Since vaddq_s8 overflows, use vaddq_u8 to prevent overflow, so need to convert the argument of vaddq_u8 to unsigned. Then convert retval to signed to pass it to vcltq_s8.

@SakiTakamachi SakiTakamachi changed the title Cast the parameter type of arm's BLOCKCONV_LOAD Cast the parameter type of arm BLOCKCONV_LOAD May 7, 2024
SakiTakamachi added a commit that referenced this pull request May 7, 2024
* PHP-8.3:
  Cast the parameter type of arm BLOCKCONV_LOAD (#14159)
@SakiTakamachi SakiTakamachi deleted the fix_blockconv_arm_83 branch June 13, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants