<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 - Improve bitfield arithmetic"
href="https://bugs.llvm.org/show_bug.cgi?id=34526">34526</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Improve bitfield arithmetic
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>We could improve math ops on irregular bitfields with the relevant SWAR style
patterns:
struct Counters {
unsigned a:7;
unsigned b:16;
unsigned c:9;
};
Counters IncCounters(Counters x) {
x.a++;
x.b++;
x.c++;
return x;
}
Counters AddCounters(Counters x, Counters y) {
Counters c;
c.a = x.a + y.a;
c.b = x.b + y.b;
c.c = x.c + y.c;
return c;
}
define i32 @IncCounters(i32) {
%2 = add i32 %0, 1
%3 = and i32 %2, 127
%4 = add i32 %0, 128
%5 = and i32 %4, 8388480
%6 = or i32 %5, %3
%7 = add i32 %0, 8388608
%8 = and i32 %7, -8388608
%9 = or i32 %6, %8
ret i32 %9
}
define i32 @AddCounters(i32, i32) {
%3 = add i32 %1, %0
%4 = and i32 %3, 127
%5 = and i32 %0, 8388480
%6 = add i32 %5, %1
%7 = and i32 %6, 8388480
%8 = or i32 %4, %7
%9 = and i32 %0, -8388608
%10 = add i32 %9, %1
%11 = and i32 %10, -8388608
%12 = or i32 %8, %11
ret i32 %12
}
llc -mcpu=btver2
IncCounters(Counters): # @IncCounters(Counters)
movl %edi, %ecx
leal 1(%rdi), %eax
addl $8388608, %edi # imm = 0x800000
subl $-128, %ecx
andl $127, %eax
andl $-8388608, %edi # imm = 0xFF800000
andl $8388480, %ecx # imm = 0x7FFF80
orl %ecx, %eax
orl %edi, %eax
retq
AddCounters(Counters, Counters): # @AddCounters(Counters, Counters)
movl %edi, %ecx
leal (%rsi,%rdi), %eax
andl $-8388608, %edi # imm = 0xFF800000
andl $8388480, %ecx # imm = 0x7FFF80
addl %esi, %edi
andl $127, %eax
addl %esi, %ecx
andl $-8388608, %edi # imm = 0xFF800000
andl $8388480, %ecx # imm = 0x7FFF80
orl %ecx, %eax
orl %edi, %eax
retq</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>