Skip to content

Commit aadecbb

Browse files
committed
small changes
1 parent 8756606 commit aadecbb

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

src/libunicode/scan256.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
#include <libunicode/scan.h>
23
#include <libunicode/scan_simd_impl.h>
34

src/libunicode/scan512.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
#include <libunicode/scan.h>
23
#include <libunicode/scan_simd_impl.h>
34

src/libunicode/scan_simd_impl.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
#pragma once
23
#include <algorithm>
34
#include <cstdint>
@@ -31,9 +32,9 @@ size_t scan_for_text_ascii_simd(std::string_view text, size_t maxColumnCount) no
3132
while (input < end - simd_size)
3233
{
3334
simd_text.copy_from(input, stdx::element_aligned);
34-
auto is_control_mask = simd_text < 0x20;
35-
auto is_complex_mask = (simd_text & 0x80) == 0x80;
36-
auto ctrl_or_complex_mask = is_control_mask || is_complex_mask;
35+
auto const is_control_mask = simd_text < 0x20;
36+
auto const is_complex_mask = (simd_text & 0x80) == 0x80;
37+
auto const ctrl_or_complex_mask = is_control_mask || is_complex_mask;
3738
if (stdx::any_of(ctrl_or_complex_mask))
3839
{
3940
input += stdx::find_first_set(ctrl_or_complex_mask);
@@ -74,13 +75,13 @@ size_t scan_for_text_ascii_simd(std::string_view text, size_t maxColumnCount) no
7475

7576
while (input < end - simd_size)
7677
{
77-
auto batch = intrinsics::load(input);
78-
auto is_control_mask = intrinsics::less(batch, vec_control);
79-
auto is_complex_mask = intrinsics::equal(intrinsics::and_vec(batch, vec_complex), vec_complex);
80-
auto ctrl_or_complex_mask = intrinsics::or_mask(is_control_mask, is_complex_mask);
78+
auto const batch = intrinsics::load(input);
79+
auto const is_control_mask = intrinsics::less(batch, vec_control);
80+
auto const is_complex_mask = intrinsics::equal(intrinsics::and_vec(batch, vec_complex), vec_complex);
81+
auto const ctrl_or_complex_mask = intrinsics::or_mask(is_control_mask, is_complex_mask);
8182
if (is_control_mask)
8283
{
83-
int advance = trailing_zero_count(intrinsics::to_unsigned(ctrl_or_complex_mask));
84+
int const advance = trailing_zero_count(intrinsics::to_unsigned(ctrl_or_complex_mask));
8485
input += advance;
8586
break;
8687
}
@@ -89,8 +90,8 @@ size_t scan_for_text_ascii_simd(std::string_view text, size_t maxColumnCount) no
8990
#endif
9091

9192
constexpr auto is_ascii = [](char ch) noexcept {
92-
auto is_control = static_cast<uint8_t>(ch) < 0x20;
93-
auto is_complex = static_cast<uint8_t>(ch) & 0x80;
93+
auto const is_control = static_cast<uint8_t>(ch) < 0x20;
94+
auto const is_complex = static_cast<uint8_t>(ch) & 0x80;
9495
return !is_control && !is_complex;
9596
};
9697
while (input != end && is_ascii(*input))

src/libunicode/simd_detector.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
#include "simd_detector.h"
23

34
#include <cstdint>
@@ -11,6 +12,11 @@
1112

1213
void cpuid(int32_t out[4], int32_t eax, int32_t ecx);
1314
uint64_t xgetbv(unsigned int index);
15+
enum class Simd_Size
16+
{
17+
sse2,
18+
avx,
19+
};
1420
auto detect_os_avx() -> bool;
1521
auto detect_os_avx512() -> bool;
1622

@@ -54,12 +60,12 @@ auto detect_os_avx() -> bool
5460
int32_t cpuInfo[4];
5561
cpuid(cpuInfo, 1, 0);
5662

57-
bool osUsesXSAVE_XRSTORE = (cpuInfo[2] & (1 << 27)) != 0;
58-
bool cpuAVXSuport = (cpuInfo[2] & (1 << 28)) != 0;
63+
bool const osUsesXSAVE_XRSTORE = (cpuInfo[2] & (1 << 27));
64+
bool const cpuAVXSuport = (cpuInfo[2] & (1 << 28)) != 0;
5965

6066
if (osUsesXSAVE_XRSTORE && cpuAVXSuport)
6167
{
62-
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
68+
uint64_t const xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
6369
avxSupported = (xcrFeatureMask & 0x6) == 0x6;
6470
}
6571

@@ -70,7 +76,7 @@ auto detect_os_avx512() -> bool
7076
{
7177
if (!detect_os_avx())
7278
return false;
73-
uint64_t xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
79+
uint64_t const xcrFeatureMask = xgetbv(_XCR_XFEATURE_ENABLED_MASK);
7480
return (xcrFeatureMask & 0xe6) == 0xe6;
7581
}
7682

@@ -81,7 +87,7 @@ auto unicode::detail::max_simd_size() -> size_t
8187

8288
int32_t info[4];
8389
cpuid(info, 0, 0);
84-
int nIds = info[0];
90+
int const nIds = info[0];
8591

8692
// cpuid(info, 0x80000000, 0);
8793
// uint32_t nExIds = info[0];
@@ -108,7 +114,7 @@ auto unicode::detail::max_simd_size() -> size_t
108114
if (nIds >= 0x00000007)
109115
{
110116
cpuid(info, 0x00000007, 0);
111-
bool HW_AVX2 = (info[1] & ((int) 1 << 5)) != 0;
117+
bool const HW_AVX2 = (info[1] & ((int) 1 << 5)) != 0;
112118
if (!HW_AVX2)
113119
return 128;
114120

@@ -121,13 +127,13 @@ auto unicode::detail::max_simd_size() -> size_t
121127
// bool HW_PREFETCHWT1 = (info[2] & ((int) 1 << 0)) != 0;
122128
// bool HW_RDPID = (info[2] & ((int) 1 << 22)) != 0;
123129

124-
bool HW_AVX512_F = (info[1] & ((int) 1 << 16)) != 0;
130+
bool const HW_AVX512_F = (info[1] & ((int) 1 << 16));
125131
// bool HW_AVX512_CD = (info[1] & ((int) 1 << 28)) != 0;
126132
// bool HW_AVX512_PF = (info[1] & ((int) 1 << 26)) != 0;
127133
// bool HW_AVX512_ER = (info[1] & ((int) 1 << 27)) != 0;
128134

129135
// bool HW_AVX512_VL = (info[1] & ((int) 1 << 31)) != 0;
130-
bool HW_AVX512_BW = (info[1] & ((int) 1 << 30)) != 0;
136+
bool const HW_AVX512_BW = (info[1] & ((int) 1 << 30));
131137
// bool HW_AVX512_DQ = (info[1] & ((int) 1 << 17)) != 0;
132138

133139
// bool HW_AVX512_IFMA = (info[1] & ((int) 1 << 21)) != 0;
@@ -143,9 +149,9 @@ auto unicode::detail::max_simd_size() -> size_t
143149
// bool HW_GFNI = (info[2] & ((int) 1 << 8)) != 0;
144150
// bool HW_VAES = (info[2] & ((int) 1 << 9)) != 0;
145151
// bool HW_AVX512_VPCLMUL = (info[2] & ((int) 1 << 10)) != 0;
146-
bool HW_AVX512_BITALG = (info[2] & ((int) 1 << 12)) != 0;
152+
bool const HW_AVX512_BITALG = (info[2] & ((int) 1 << 12));
147153

148-
bool use512 = detect_os_avx512() && HW_AVX512_F && HW_AVX512_BW && HW_AVX512_BITALG;
154+
bool const use512 = detect_os_avx512() && HW_AVX512_F && HW_AVX512_BW && HW_AVX512_BITALG;
149155
if (!use512)
150156
return 256;
151157
else

src/libunicode/simd_detector.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
#pragma once
23

34
#include <cstddef>

0 commit comments

Comments
 (0)