Click here to Skip to main content
15,176,222 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Learning to live without if() statements Pin
Shao Voon Wong8-Jan-21 1:45
mvaShao Voon Wong8-Jan-21 1:45 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 2:53
mvahoney the codewitch8-Jan-21 2:53 
GeneralRe: Learning to live without if() statements Pin
obermd8-Jan-21 4:31
Memberobermd8-Jan-21 4:31 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 5:03
mvahoney the codewitch8-Jan-21 5:03 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 4:01
mveBillWoodruff9-Jan-21 4:01 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 4:16
mvahoney the codewitch9-Jan-21 4:16 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 7:12
mveBillWoodruff9-Jan-21 7:12 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 7:20
mvahoney the codewitch9-Jan-21 7:20 
Sure!

avx implementation of strstr() by Wojciech Muła

SIMD-friendly algorithms for substring searching[^]

I didn't make my own because i'm allergic to bugs. this compares 16 bytes at a time.

C++
#define _mm512_set1_epu8(c) _mm512_set1_epi32(uint32_t(c) * 0x01010101u)

size_t avx512f_strstr_v2_anysize(const char* string, size_t n, const char* needle, size_t k) {

    assert(n > 0);
    assert(k > 0);

    const __m512i first = _mm512_set1_epu8(needle[0]);
    const __m512i last  = _mm512_set1_epu8(needle[k - 1]);

    char* haystack = const_cast<char*>(string);
    char* end      = haystack + n;

    for (/**/; haystack < end; haystack += 64) {

        const __m512i block_first = _mm512_loadu_si512(haystack + 0);
        const __m512i block_last  = _mm512_loadu_si512(haystack + k - 1);

        const __m512i first_zeros = _mm512_xor_si512(block_first, first);
        // zeros = first_zeros | (block_last ^ last)
        const __m512i zeros = _mm512_ternarylogic_epi32(first_zeros, block_last, last, 0xf6);

        uint32_t mask = zero_byte_mask(zeros);
        while (mask) {

            const uint64_t p = __builtin_ctz(mask);

            if (memcmp(haystack + 4*p + 0, needle, k) == 0) {
                return (haystack - string) + 4*p + 0;
            }

            if (memcmp(haystack + 4*p + 1, needle, k) == 0) {
                return (haystack - string) + 4*p + 1;
            }

            if (memcmp(haystack + 4*p + 2, needle, k) == 0) {
                return (haystack - string) + 4*p + 2;
            }

            if (memcmp(haystack + 4*p + 3, needle, k) == 0) {
                return (haystack - string) + 4*p + 3;
            }

            mask = bits::clear_leftmost_set(mask);
        }
    }

    return size_t(-1);
}

Real programmers use butterflies

GeneralAmazing luck Pin
Cp-Coder7-Jan-21 11:07
MemberCp-Coder7-Jan-21 11:07 
GeneralRe: Amazing luck Pin
OriginalGriff7-Jan-21 11:59
mveOriginalGriff7-Jan-21 11:59 
GeneralRe: Amazing luck Pin
honey the codewitch7-Jan-21 12:20
mvahoney the codewitch7-Jan-21 12:20 
GeneralRe: Amazing luck Pin
#realJSOP7-Jan-21 12:29
mva#realJSOP7-Jan-21 12:29 
PraiseRe: Amazing luck Pin
Gary R. Wheeler7-Jan-21 16:18
MemberGary R. Wheeler7-Jan-21 16:18 
GeneralRe: Amazing luck Pin
GenJerDan8-Jan-21 1:14
MemberGenJerDan8-Jan-21 1:14 
GeneralRe: Amazing luck Pin
Jörgen Andersson8-Jan-21 3:15
professionalJörgen Andersson8-Jan-21 3:15 
GeneralRe: Amazing luck Pin
Cp-Coder8-Jan-21 3:55
MemberCp-Coder8-Jan-21 3:55 
GeneralYears ago, I learned: "never compose email while snarling" Pin
OriginalGriff7-Jan-21 8:21
mveOriginalGriff7-Jan-21 8:21 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Slacker0077-Jan-21 8:27
professionalSlacker0077-Jan-21 8:27 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
obermd8-Jan-21 4:33
Memberobermd8-Jan-21 4:33 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
glennPattonInThePub37-Jan-21 8:43
professionalglennPattonInThePub37-Jan-21 8:43 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
theoldfool7-Jan-21 10:15
professionaltheoldfool7-Jan-21 10:15 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Rick York7-Jan-21 11:00
mveRick York7-Jan-21 11:00 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Gary R. Wheeler7-Jan-21 16:23
MemberGary R. Wheeler7-Jan-21 16:23 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
den2k888-Jan-21 1:09
professionalden2k888-Jan-21 1:09 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Rick York8-Jan-21 7:04
mveRick York8-Jan-21 7:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.