Re: Use of C99 int types

2005-04-04 Thread Dag Arne Osvik
Renate Meijer wrote:
On Apr 4, 2005, at 12:08 AM, Kyle Moffett wrote:
On Apr 03, 2005, at 16:25, Kenneth Johansson wrote:
But is this not exactly what Dag Arne Osvik was trying to do ??
uint_fast32_t means that we want at least 32 bits but it's OK with
more if that happens to be faster on this particular architecture.
The problem was that the C99 standard types are not defined anywhere
in the kernel headers so they can not be used.

Uhh, so what's wrong with "int" or "long"?

Nothing, as long as they work as required.  And Grzegorz Kulewski 
pointed out that unsigned long is required to be at least 32 bits, 
fulfilling the present need for a 32-bit or wider type.

My point exactly, though I agree with Kenneth that adding the C99 types
would be a Good Thing.

If it leads to better code, then indeed it would be.  However, Al Viro 
disagrees and strongly hints they would lead to worse code.


GCC will generally do the right thing if you just tell it "int".

And if you don't, you imply some special requirement, which, if none 
really exists, is
misleading.

And in this case there is such a requirement.  Anyway, I've already 
decided to use unsigned long as a replacement for uint_fast32_t in my 
implementation.

--
 Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Use of C99 int types

2005-04-04 Thread Dag Arne Osvik
Herbert Xu wrote:
Dag Arne Osvik <[EMAIL PROTECTED]> wrote:
 

... and with such name 99% will assume (at least at the first reading)
that it _is_ 32bits.  We have more than enough portability bugs as it
is, no need to invite more by bad names.
 

Agreed.  The way I see it there are two reasonable options.  One is to 
just use u32, which is always correct but sacrifices speed (at least 
with the current gcc).  The other is to introduce C99 types, which Linus 
doesn't seem to object to when they are kept away from interfaces 
(http://infocenter.guardiandigital.com/archive/linux-kernel/2004/Dec/0117.html).
   

There is a third option which has already been pointed out before:
Use unsigned long.
 

Yes, as Kulewski pointed out, unsigned long is at least 32 bits wide and 
therefore correct.  Whether it's also fastest is less of a concern, but 
it is so for at least the x86* architectures.  So, sure, I'll use it.

Cheers all,
--
 Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Use of C99 int types

2005-04-03 Thread Dag Arne Osvik
Grzegorz Kulewski wrote:
On Mon, 4 Apr 2005, Dag Arne Osvik wrote:
(...) And, at least in theory, long may even provide less than 32 bits.

Are you sure?
My copy of famous C book by B. W. Kernighan and D. Ritchie says that
sizeof(short) <= sizeof(int) <= sizeof(long)
and
sizeof(short) >= 16,
sizeof(int) >= 16,
sizeof(long) >= 32.
The book is about ANSI C not C99 but I think this is still valid.
Am I wrong?

No, I just looked it up (section 2.2), and you're right.
--
 Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Use of C99 int types

2005-04-03 Thread Dag Arne Osvik
Al Viro wrote:
On Sun, Apr 03, 2005 at 02:30:11PM +0200, Dag Arne Osvik wrote:
 

Yes, but wouldn't it be much better to avoid code like the following, 
which may also be wrong (in terms of speed)?

#ifdef CONFIG_64BIT  // or maybe CONFIG_X86_64?
#define fast_u32 u64
#else
#define fast_u32 u32
#endif
   

... and with such name 99% will assume (at least at the first reading)
that it _is_ 32bits.  We have more than enough portability bugs as it
is, no need to invite more by bad names.
 

Agreed.  The way I see it there are two reasonable options.  One is to 
just use u32, which is always correct but sacrifices speed (at least 
with the current gcc).  The other is to introduce C99 types, which Linus 
doesn't seem to object to when they are kept away from interfaces 
(http://infocenter.guardiandigital.com/archive/linux-kernel/2004/Dec/0117.html).

--
 Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Use of C99 int types

2005-04-03 Thread Dag Arne Osvik
Andreas Schwab wrote:
Dag Arne Osvik <[EMAIL PROTECTED]> writes:
 

Yes, but wouldn't it be much better to avoid code like the following, 
which may also be wrong (in terms of speed)?

#ifdef CONFIG_64BIT  // or maybe CONFIG_X86_64?
#define fast_u32 u64
#else
#define fast_u32 u32
#endif
   

How about using just unsigned long instead?
 

unsigned long happens to coincide with uint_fast32_t for x86 and x86-64, 
but there's no guarantee that it will on other architectures.  And, at 
least in theory, long may even provide less than 32 bits.

--
 Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Use of C99 int types

2005-04-03 Thread Dag Arne Osvik
Stephen Rothwell wrote:
On Sun, 03 Apr 2005 13:55:39 +0200 Dag Arne Osvik <[EMAIL PROTECTED]> wrote:
 

I've been working on a new DES implementation for Linux, and ran into
the problem of how to get access to C99 types like uint_fast32_t for
internal (not interface) use.  In my tests, key setup on Athlon 64 slows
down by 40% when using u32 instead of uint_fast32_t.
   

If you look in stdint.h you may find that uint_fast32_t is actually
64 bits on Athlon 64 ... so does it help if you use u64?
 

Yes, but wouldn't it be much better to avoid code like the following, 
which may also be wrong (in terms of speed)?

#ifdef CONFIG_64BIT  // or maybe CONFIG_X86_64?
 #define fast_u32 u64
#else
 #define fast_u32 u32
#endif
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Use of C99 int types

2005-04-03 Thread Dag Arne Osvik
Hi,
I've been working on a new DES implementation for Linux, and ran into
the problem of how to get access to C99 types like uint_fast32_t for
internal (not interface) use.  In my tests, key setup on Athlon 64 slows
down by 40% when using u32 instead of uint_fast32_t.
So I wonder if there is any standard way of, say, including stdint.h for
internal use in kernel code?
  Dag Arne
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/