Skip to content

lea esi, [rdx - 32]+cmp edx, 32+mov edx, esi => sub edx, 32 #163125

@Validark

Description

@Validark

[Zig Godbolt]
[C Godbolt]
[LLVM Godbolt]

Here's some C code:

#include <stdint.h>
#include <immintrin.h>

uint32_t foo(uint8_t byte) {
    uint32_t q = byte;
    uint32_t acc = 0;

    while (1) {
        uint32_t mask = _bzhi_u32(~0u, q);
        acc ^= mask;

        int br = q <= 16;
        q -= 16;
        if (br) break;
    }

    return acc;
}

Compiles to: (current in red, ideal in green)

foo:
        mov     ecx, -1
        xor     eax, eax
.LBB0_1:
        bzhi    edx, ecx, edi
        xor     eax, edx
-       lea     edx, [rdi - 16]
-       cmp     edi, 16
-       mov     edi, edx
+       sub     edi, 16
        ja      .LBB0_1
        ret

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions