blob: 6b49034f3f69f7a3b1157a4a6edc47182031d902 [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)) {
Milo Yip4d3c64a2015-04-15 21:07:30 +080049 for (int step = 1; step < 32; step++) {
50 char buffer[1025];
51 for (size_t i = 0; i < 1024; i++)
52 buffer[i] = " \t\r\n"[i % 4];
53 for (size_t i = 0; i < 1024; i += step)
54 buffer[i] = 'X';
55 buffer[1024] = '\0';
miloyipa32d8b72015-04-15 18:18:49 +080056
Milo Yip4d3c64a2015-04-15 21:07:30 +080057 StringStream s(buffer);
58 size_t i = 0;
59 for (;;) {
60 SkipWhitespace(s);
61 if (s.Peek() == '\0')
62 break;
63 EXPECT_EQ(i, s.Tell());
64 EXPECT_EQ('X', s.Take());
65 i += step;
66 }
miloyipa32d8b72015-04-15 18:18:49 +080067 }
68}