tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: 4byte aligned com(4) and PCI_MAPREG_TYPE_MEM
On 11 Feb, 2014, at 13:21 , Eduardo Horvath <eeh%NetBSD.org@localhost> wrote:
> When do you ever really want to byte swap the contents of one register to
> another register? Byte swapping almost always involves I/O, which
> means reading or writing memory or a device register. In this case we
> are specifically talking about DMA, in which case there is always a load
> or store operation involved.
I've written code to determine the length of the common prefix of
two addresses, stored in network byte order, which looks vaguely like
uint32_t *addr1, *addr2;
u_int p;
[...]
for (p = 0; p < ADDR_BITS; p += 32) {
uint32_t diff = *addr1++ ^ *addr2++;
if (diff != 0) {
p += __builtin_clz(ntohl(diff));
break;
}
}
The code wouldn't actually care if the bytes were instead swapped
when the words were loaded, but who would think to write code which
looks like it might do many byte swaps when doing just one, or none,
is sufficient?
So to answer the question, I want register byte swaps when the
machine has an instruction for that, and I want byte swaps from
memory when the machine does that well, but I really want the compiler
to figure out the best thing for the machine I'm compiling for since
there is no one right answer but I want to write the code just once.
I think this means using the compiler's built-in byte swap primitives,
so there's some hope of the compiler eventually understanding what is
going on well enough to do the best thing for any machine, even if the
code the compiler generates right now isn't all that pretty.
Dennis Ferguson
Home |
Main Index |
Thread Index |
Old Index