blob: 217db0788a4b4c7317ec3ddcb77565ab7eb076cf [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
Milo Yip0571a212015-04-15 22:36:00 +080048template <typename StreamType>
49void TestSkipWhitespace() {
Milo Yip4d3c64a2015-04-15 21:07:30 +080050 for (int step = 1; step < 32; step++) {
51 char buffer[1025];
52 for (size_t i = 0; i < 1024; i++)
53 buffer[i] = " \t\r\n"[i % 4];
54 for (size_t i = 0; i < 1024; i += step)
55 buffer[i] = 'X';
56 buffer[1024] = '\0';
miloyipa32d8b72015-04-15 18:18:49 +080057
Milo Yip0571a212015-04-15 22:36:00 +080058 StreamType s(buffer);
Milo Yip4d3c64a2015-04-15 21:07:30 +080059 size_t i = 0;
60 for (;;) {
61 SkipWhitespace(s);
62 if (s.Peek() == '\0')
63 break;
64 EXPECT_EQ(i, s.Tell());
65 EXPECT_EQ('X', s.Take());
66 i += step;
67 }
miloyipa32d8b72015-04-15 18:18:49 +080068 }
69}
Milo Yip0571a212015-04-15 22:36:00 +080070
71TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) {
72 TestSkipWhitespace<StringStream>();
73 TestSkipWhitespace<InsituStringStream>();
74}