Click here to Skip to main content
15,867,453 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 0:45
mvaShao Voon Wong8-Jan-21 0:45 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 1:53
mvahoney the codewitch8-Jan-21 1:53 
GeneralRe: Learning to live without if() statements Pin
obermd8-Jan-21 3:31
obermd8-Jan-21 3:31 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 4:03
mvahoney the codewitch8-Jan-21 4:03 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 3:01
professionalBillWoodruff9-Jan-21 3:01 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 3:16
mvahoney the codewitch9-Jan-21 3:16 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 6:12
professionalBillWoodruff9-Jan-21 6:12 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 6:20
mvahoney the codewitch9-Jan-21 6: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 10:07
Cp-Coder7-Jan-21 10:07 
GeneralRe: Amazing luck Pin
OriginalGriff7-Jan-21 10:59
mveOriginalGriff7-Jan-21 10:59 
GeneralRe: Amazing luck Pin
honey the codewitch7-Jan-21 11:20
mvahoney the codewitch7-Jan-21 11:20 
GeneralRe: Amazing luck Pin
#realJSOP7-Jan-21 11:29
mve#realJSOP7-Jan-21 11:29 
PraiseRe: Amazing luck Pin
Gary R. Wheeler7-Jan-21 15:18
Gary R. Wheeler7-Jan-21 15:18 
GeneralRe: Amazing luck Pin
GenJerDan8-Jan-21 0:14
GenJerDan8-Jan-21 0:14 
GeneralRe: Amazing luck Pin
Jörgen Andersson8-Jan-21 2:15
professionalJörgen Andersson8-Jan-21 2:15 
GeneralRe: Amazing luck Pin
Cp-Coder8-Jan-21 2:55
Cp-Coder8-Jan-21 2:55 
GeneralYears ago, I learned: "never compose email while snarling" Pin
OriginalGriff7-Jan-21 7:21
mveOriginalGriff7-Jan-21 7:21 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Slacker0077-Jan-21 7:27
professionalSlacker0077-Jan-21 7:27 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
obermd8-Jan-21 3:33
obermd8-Jan-21 3:33 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
glennPattonWork37-Jan-21 7:43
professionalglennPattonWork37-Jan-21 7:43 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
theoldfool7-Jan-21 9:15
professionaltheoldfool7-Jan-21 9:15 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Rick York7-Jan-21 10:00
mveRick York7-Jan-21 10:00 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Gary R. Wheeler7-Jan-21 15:23
Gary R. Wheeler7-Jan-21 15:23 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
den2k888-Jan-21 0:09
professionalden2k888-Jan-21 0:09 
GeneralRe: Years ago, I learned: "never compose email while snarling" Pin
Rick York8-Jan-21 6:04
mveRick York8-Jan-21 6: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.