https://bugs.llvm.org/show_bug.cgi?id=41267

            Bug ID: 41267
           Summary: consider @bitreverse() to reduce down bit-tests, when
                    @bitreverse is cheap.
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

LLVM should be able to optimize the following real-world code (necessary for
implementing robust mutexes on Linux, and in a hot path) to use @bitreverse on
architectures where it is cheap (aarch64 for example, but not x86_64)

https://zig.godbolt.org/z/ozqI3y

pub const FUTEX_WAITERS    = 0x80000000;
pub const FUTEX_OWNER_DIED = 0x40000000;
pub const FUTEX_TID_MASK   = 0x3fffffff;

export fn naieve(n: u32) u8 {
    if ((n & FUTEX_WAITERS) == 0 and (n & FUTEX_TID_MASK) > 0) {
        // Locked without congestion
        return 1;
    } else {
        return 0;
    }
}

Here is a manually optimized version, however it can't be used because x86_64
has a very slow @bitreverse. It is also hideous.:

export fn incomprehensible(n: u32) u8 {
    var rev = @bitreverse(@typeOf(n), n);
    var sh = math.rotl(@typeOf(n), rev, u8(31));
    sh = sh -% 1;
    if (sh > 0) {
        return 1;
    } else {
        return 0;
    }
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to