lkml.org 
[lkml]   [2004]   [Sep]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC, 2.6] a simple FIFO implementation
On Fri, Sep 17, 2004 at 11:00:22AM +1000, Peter Chubb wrote:

> Andrew> All the struct needs is `head', `tail' and
> Andrew> `number_of_bytes_at_buf', all unsigned.
>
> Andrew> add(char c) {
> Andrew> p-> buf[p->head++ % p->number_of_bytes_at_buf] = c;
> Andrew> }
>
> This depends on how expensive % is. On IA64, something like this:
>
> add(char c) {
> int i = p->head == p->len ? p->head++ : 0;
> p->buf[i] = c;
> }
>
> is cheaper, as % generates a subroutine call to __modsi3. It also is
> shorter =-- 12 bundles as opposed to 15.

Yup, but this is when doing char-by-char operations.

When using one or two memcpy() we have only two '%' intead of
(perhaps) many 'if's.

Of course the memcpy() has its own while() loop but since it's
optimized in assembly (and I guess we're not going to implement
kfifo_get/put in assembly) I will stay with the memcpy + '%' version.

Stelian.
--
Stelian Pop <stelian@popies.net>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:06    [W:0.059 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site