From 9799ae3f29197eb65508e398d59591c238e59d6b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 25 Aug 2024 00:33:09 +0200 Subject: Use _mm512_set1_epi8() --- c/simd-isascii/isascii.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'c') diff --git a/c/simd-isascii/isascii.c b/c/simd-isascii/isascii.c index 612aa49..299894f 100644 --- a/c/simd-isascii/isascii.c +++ b/c/simd-isascii/isascii.c @@ -16,21 +16,10 @@ static const unsigned char *readfile(const char *, size_t *); -static const uint8_t charmsk[64] = { - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, -}; - bool strisascii(const unsigned char *s, size_t n) { - __m512i msk = _mm512_loadu_epi8(charmsk); + __m512i msk = _mm512_set1_epi8((char)(1 << 7)); while (n >= VECWDTH) { if (_mm512_test_epi8_mask(_mm512_loadu_epi8(s), msk) != 0) return false; @@ -69,12 +58,12 @@ main(int argc, char **argv) clock_t tmbeg = clock(); if (!strisascii(beg, len)) puts("Non-ASCII"); - printf("Elapsed time: %.3fs\n", (double)(clock() - tmbeg) / CLOCKS_PER_SEC); + printf("Elapsed time (AVX-512): %.3fs\n", (double)(clock() - tmbeg) / CLOCKS_PER_SEC); tmbeg = clock(); if (!strisascii_dumb((const unsigned char *)beg, len)) puts("Non-ASCII"); - printf("Elapsed time: %.3fs\n", (double)(clock() - tmbeg) / CLOCKS_PER_SEC); + printf("Elapsed time (Generic): %.3fs\n", (double)(clock() - tmbeg) / CLOCKS_PER_SEC); munmap((void *)beg, len); return rv; -- cgit v1.2.3