Skip to content

Conversation

@helintongh
Copy link
Contributor

Why

issue 939

// in cinatra have function split_sv:
inline std::vector<std::string_view> split_sv(std::string_view s,
                                              std::string_view delimiter) {
  size_t start = 0;
  size_t end = s.find_first_of(delimiter);

  std::vector<std::string_view> output;

  while (end <= std::string_view::npos) {
    output.emplace_back(s.substr(start, end - start));

    if (end == std::string_view::npos)
      break;

    start = end + 1;
    end = s.find_first_of(delimiter, start);
  }

  return output;
}

use simd optimize it.

in the future optimize json and base64 etc by simd.

What is changing

simd dispatch, auto chose simd fucntion.now implement string and string_view split.

Example

#include <ylt/simd_util/simd_str_split.h>

#include "doctest.h"

TEST_CASE("test string_view split") {
  std::string_view sv_tmp =
      "hello world\t127.0.0.1\t1024\twww.yalantinglibs.com";

  auto tokens = ylt::split_sv(sv_tmp, '\t');

  CHECK(tokens[0] == "hello world");
  CHECK(tokens[1] == "127.0.0.1");
  CHECK(tokens[2] == "1024");
  CHECK(tokens[3] == "www.yalantinglibs.com");
}

TEST_CASE("test string split") {
  std::string_view sv_tmp =
      "hello world\t127.0.0.1\t1024\twww.yalantinglibs.com";

  auto tokens = ylt::split_str(sv_tmp, '\t');

  CHECK(tokens[0] == "hello world");
  CHECK(tokens[1] == "127.0.0.1");
  CHECK(tokens[2] == "1024");
  CHECK(tokens[3] == "www.yalantinglibs.com");
}

Refer to the tests path and benchmark path in simd_util.

in neon:
image

neon better than normal.

in avx2:
image

image

It's single header library, when wanna use avx2 add compile option -mavx2,-mbmi.when in arm,do nothing will auto use neon simd.

@github-actions
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@github-actions
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@helintongh
Copy link
Contributor Author

use macro dispatch real simd function, can't add spaces to macro definitions like clang-format want.

-#define INCLUDE_ARCH_FILE(file) YLT_STRINGIFY(common/file)
+#define INCLUDE_ARCH_FILE(file) YLT_STRINGIFY(common / file) // ignore this error

@github-actions
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@github-actions
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

@github-actions
Copy link

for detail, goto summary download Artifacts base-ylt-cov-report(base commit coverage report) and ylt-cov-report(current pull request coverage report)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant