blob: ebbbead784ac08c0aed681018e845effd08dc59c [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
miloyipee505262015-04-15 18:34:18 +080032#define RAPIDJSON_NAMESPACE rapidjson_simd
33
miloyipa32d8b72015-04-15 18:18:49 +080034#include "unittest.h"
35
36#include "rapidjson/reader.h"
37
miloyipee505262015-04-15 18:34:18 +080038using namespace rapidjson_simd;
miloyipa32d8b72015-04-15 18:18:49 +080039
40#ifdef RAPIDJSON_SSE2
41#define SIMD_SUFFIX(name) name##_SSE2
42#elif defined(RAPIDJSON_SSE42)
43#define SIMD_SUFFIX(name) name##_SSE42
44#else
45#define SIMD_SUFFIX(name) name
46#endif
47
48TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) {
49 char buffer[258];
50 for (size_t i = 0; i < 256; i++)
51 buffer[i] = " \t\r\n"[i % 4];
52 buffer[256] = 'X';
53 buffer[257] = '\0';
54
55 // Try to start from different position, to test different memory alignments
56 for (size_t i = 0; i < 256; i++) {
57 StringStream s(buffer + i);
58 SkipWhitespace(s);
59 EXPECT_EQ('X', s.Peek());
60 }
61}