Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
name: Build on Alpine ${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
# setup-alpine + qemu can flake on one arch (apk DB under emulation);
# do not cancel the others.
fail-fast: false
matrix:
arch:
- x86_64
Expand All @@ -22,11 +25,15 @@ jobs:
- name: Install extra dependencies
run: |
sudo apt update && sudo apt install -y binfmt-support
- name: Install latest Alpine Linux for ${{ matrix.arch }}
- name: Install Alpine Linux for ${{ matrix.arch }}
uses: jirutka/setup-alpine@v1
with:
arch: ${{ matrix.arch }}
branch: ${{ matrix.arch == 'riscv64' && 'edge' || 'latest-stable' }}
# latest-stable is 3.23+ (apk-tools v3). setup-alpine still
# bootstraps with a static apk v2.14 binary, so apk add in the
# chroot fails with "database: file format is invalid" on some
# qemu arches (seen on ppc64le). v3.22 is the last apk v2 release.
branch: ${{ matrix.arch == 'riscv64' && 'edge' || 'v3.22' }}
packages: >
build-base
cmake
Expand Down
6 changes: 4 additions & 2 deletions include/ada/idna/to_ascii.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ std::string to_ascii(std::string_view ut8_string);
// https://url.spec.whatwg.org/#forbidden-domain-code-point
bool contains_forbidden_domain_code_point(std::string_view ascii_string);

bool constexpr is_ascii(std::u32string_view view);
bool constexpr is_ascii(std::string_view view);
// Runtime SIMD (SSE2/NEON) with a SWAR fallback. Not constexpr: vector
// paths cannot be evaluated at compile time.
bool is_ascii(std::u32string_view view) noexcept;
bool is_ascii(std::string_view view) noexcept;

} // namespace ada::idna

Expand Down
24 changes: 2 additions & 22 deletions src/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>

#include "table_store.hpp"
#include "simd.hpp"
#include "mapping_tables.cpp"

namespace ada::idna {
Expand Down Expand Up @@ -81,28 +82,7 @@ static size_t utf8_count_codepoints(const uint8_t* ptr) noexcept {

// --- ASCII fast path ---------------------------------------------------------
void ascii_map(char* input, size_t length) {
auto broadcast = [](uint8_t v) -> uint64_t {
return 0x101010101010101ull * v;
};
uint64_t broadcast_80 = broadcast(0x80);
uint64_t broadcast_Ap = broadcast(128 - 'A');
uint64_t broadcast_Zp = broadcast(128 - 'Z' - 1);
size_t i = 0;

for (; i + 7 < length; i += 8) {
uint64_t word{};
std::memcpy(&word, input + i, sizeof(word));
word ^=
(((word + broadcast_Ap) ^ (word + broadcast_Zp)) & broadcast_80) >> 2;
std::memcpy(input + i, &word, sizeof(word));
}
if (i < length) {
uint64_t word{};
std::memcpy(&word, input + i, length - i);
word ^=
(((word + broadcast_Ap) ^ (word + broadcast_Zp)) & broadcast_80) >> 2;
std::memcpy(input + i, &word, length - i);
}
(void)simd::ascii_lowercase_is_ascii(input, length);
}

// Two-pass map: first validate + exact size, then write once (no growth
Expand Down
Loading
Loading