1 // Tencent is pleased to support the open source community by making RapidJSON available. 2 // 3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 // 5 // Licensed under the MIT License (the "License"); you may not use this file except 6 // in compliance with the License. You may obtain a copy of the License at 7 // 8 // http://opensource.org/licenses/MIT 9 // 10 // Unless required by applicable law or agreed to in writing, software distributed 11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 // specific language governing permissions and limitations under the License. 14 15 // Since Travis CI installs old Valgrind 3.7.0, which fails with some SSE4.2 16 // The unit tests prefix with SIMD should be skipped by Valgrind test 17 18 // __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler. 19 // We use -march=native with gmake to enable -msse2 and -msse4.2, if supported. 20 #if defined(__SSE4_2__) 21 # define RAPIDJSON_SSE42 22 #elif defined(__SSE2__) 23 # define RAPIDJSON_SSE2 24 #endif 25 26 #define RAPIDJSON_NAMESPACE rapidjson_simd 27 28 #include "unittest.h" 29 30 #include "rapidjson/reader.h" 31 32 using namespace rapidjson_simd; 33 34 #ifdef RAPIDJSON_SSE2 35 #define SIMD_SUFFIX(name) name##_SSE2 36 #elif defined(RAPIDJSON_SSE42) 37 #define SIMD_SUFFIX(name) name##_SSE42 38 #else 39 #define SIMD_SUFFIX(name) name 40 #endif 41 42 template <typename StreamType> 43 void TestSkipWhitespace() { 44 for (int step = 1; step < 32; step++) { 45 char buffer[1025]; 46 for (size_t i = 0; i < 1024; i++) 47 buffer[i] = " \t\r\n"[i % 4]; 48 for (size_t i = 0; i < 1024; i += step) 49 buffer[i] = 'X'; 50 buffer[1024] = '\0'; 51 52 StreamType s(buffer); 53 size_t i = 0; 54 for (;;) { 55 SkipWhitespace(s); 56 if (s.Peek() == '\0') 57 break; 58 EXPECT_EQ(i, s.Tell()); 59 EXPECT_EQ('X', s.Take()); 60 i += step; 61 } 62 } 63 } 64 65 TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { 66 TestSkipWhitespace<StringStream>(); 67 TestSkipWhitespace<InsituStringStream>(); 68 } 69