blob: 42fb10f404f8598189d6bb11a10ae81b99c17f24 [file] [log] [blame]
miloyipa32d8b72015-04-15 18:18:49 +08001// Copyright (C) 2011 Milo Yip
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21// Since Travis CI installs old Valgrind 3.7.0, which fails with some SSE4.2
22// The unit tests prefix with SIMD should be skipped by Valgrind test
23
24// __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler.
25// We use -march=native with gmake to enable -msse2 and -msse4.2, if supported.
26#if defined(__SSE4_2__)
27# define RAPIDJSON_SSE42
28#elif defined(__SSE2__)
29# define RAPIDJSON_SSE2
30#endif
31
32#include "unittest.h"
33
34#include "rapidjson/reader.h"
35
36using namespace rapidjson;
37
38#ifdef RAPIDJSON_SSE2
39#define SIMD_SUFFIX(name) name##_SSE2
40#elif defined(RAPIDJSON_SSE42)
41#define SIMD_SUFFIX(name) name##_SSE42
42#else
43#define SIMD_SUFFIX(name) name
44#endif
45
46TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) {
47 char buffer[258];
48 for (size_t i = 0; i < 256; i++)
49 buffer[i] = " \t\r\n"[i % 4];
50 buffer[256] = 'X';
51 buffer[257] = '\0';
52
53 // Try to start from different position, to test different memory alignments
54 for (size_t i = 0; i < 256; i++) {
55 StringStream s(buffer + i);
56 SkipWhitespace(s);
57 EXPECT_EQ('X', s.Peek());
58 }
59}