<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - consider @bitreverse() to reduce down bit-tests, when @bitreverse is cheap."
href="https://bugs.llvm.org/show_bug.cgi?id=41267">41267</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>consider @bitreverse() to reduce down bit-tests, when @bitreverse is cheap.
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>slandden@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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)
<a href="https://zig.godbolt.org/z/ozqI3y">https://zig.godbolt.org/z/ozqI3y</a>
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;
}
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>