Farid Zaripov wrote:
-----Original Message-----
From: Martin Sebor [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 10, 2006 9:30 PM
To: [email protected]
Subject: Re: [PATCH] bitset.cc (STDCXX-297)


 5 is log2(sizeof (*bits) * CHAR_BIT)
 2 is log2(sizeof (*bits))

[...]

I would just hardcode it based on the size of the type. Something simple like this (the same code is at the top of bitset.cpp) will
work:

  enum {
  #if 4 == _RWSTD_ULONG_SIZE
      log2_long_size = 2,
      log2_long_bits = 5


  "log2_long_bits = 5" is correct only for CHAR_BIT == 8

Good point. Not that we have been ported to any architectures
where CHAR_BIT is not 8, but if we want to avoid making the
assumption that we will never be, we should be as general as
possible. The thing is, there have been architectures where
the number of bits in a byte isn't a power of 2 (e.g., 9 on
the Univac or 36 on PDP-10).


  More correct to define log2_long_bits = log2_long_size +
log2_char_bits, but
how we can define log2_char_bits?

enum {
#if 8 == _RWSTD_CHAR_BIT
    log2_char_bits = 3
#else if 16 == _RWSTD_CHAR_BIT
    log2_char_bits = 4
#else if 32 == _RWSTD_CHAR_BIT
    log2_char_bits = 5
#else // assume 64 == _RWSTD_CHAR_BIT
    log2_char_bits = 6
#endif
};

  That will be enough?

This would work if we were willing to exclude CHAR_BIT values
that are not powers of 2 (we probably already are making this
assumption elsewhere but that doesn't mean we have to perpetuate
it here as well). We could deal with it by having two code paths,
a faster one for power-of-2 CHAR_BIT values and a slower one for
the rare cases when it isn't (guarded by suitable #if's).

Martin

Reply via email to