[llvm-bugs] [Bug 41267] New: consider @bitreverse() to reduce down bit-tests, when @bitreverse is cheap.
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Mar 27 17:11:43 PDT 2019
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: unassignedbugs at nondot.org
Reporter: slandden at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190328/744469be/attachment-0001.html>
More information about the llvm-bugs
mailing list