Skip to content

Commit 105ce13

Browse files
committed
Fix failure of AVX2-accelerated mb_check_encoding on 32-bit MS Windows
Thanks to Ilija Tovilo for noticing and reporting this problem. Thanks also to Michael Voříšek for finding the StackOverflow post which explained the reason for the failure.
1 parent e447036 commit 105ce13

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ext/mbstring/mbstring.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5155,7 +5155,12 @@ static bool mb_fast_check_utf8_avx2(zend_string *str)
51555155
goto check_operand;
51565156
case 7:
51575157
case 8:
5158-
operand = _mm256_set_epi64x(0, 0, 0, *((int64_t*)p));
5158+
/* This was originally: operand = _mm256_set_epi64x(0, 0, 0, *((int64_t*)p));
5159+
* However, that caused test failures on 32-bit MS Windows
5160+
* (Bad 7/8-byte UTF-8 strings would be wrongly passed through as 'valid')
5161+
* It seems this is caused by a bug in MS Visual C++
5162+
* Ref: https://stackoverflow.com/questions/37509129/potential-bug-in-visual-studio-c-compiler-or-in-intel-intrinsics-avx2-mm256-s */
5163+
operand = _mm256_set_epi32(0, 0, 0, 0, 0, 0, ((int32_t*)p)[1], ((int32_t*)p)[0]);
51595164
goto check_operand;
51605165
case 9:
51615166
operand = _mm256_set_m128i(_mm_setzero_si128(), _mm_srli_si128(_mm_loadu_si128((__m128i*)(p - 6)), 6));

ext/mbstring/tests/utf_encodings.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mbstring
55
--SKIPIF--
66
<?php
77
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
8-
if (substr(PHP_OS, 0, 3) === 'WIN' && PHP_INT_SIZE === 4) die("skip not for Windows x86");
98
?>
109
--FILE--
1110
<?php

0 commit comments

Comments
 (0)