|
Boost : |
From: Boris Gubenko (Boris.Gubenko_at_[hidden])
Date: 2007-11-14 09:14:24
Markus Schoepflin wrote:
> For Tru64/CXX there is an easy workaround available, please refer to the
> attached patch for this. Of course this isn't a general solution, although
> I would think that acc supports something similar, which then could be
> wrapped into a macro hiding the platform dependency.
aCC supports #pragma unalign [1|2|4|8|16] which is not as convenient, in my
opinion, as __unaligned type specifier in cxx compiler.
With aCC, you'd have to do something like:
#pragma unalign 1
typedef bitfield_t ua_bitfield_t; // bitfield_t with 1 byte alignment
ua_bitfield_t& data() const { ... }
Thanks,
Boris
----- Original Message -----
From: "Markus Schöpflin" <markus.schoepflin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, November 14, 2007 7:46 AM
Subject: Re: [boost] [GIL] 64-bit alignment issue
> Lubomir Bourdev wrote:
>
> [...]
>
>> I believe this is indeed the problem. GIL needs to read/write a type
>> bigger than a byte that starts at a char* address, so it is possibly not
>> aligned.
>>
>> One approach is to special-case platforms which cannot dereference at a
>> non-byte boundary (I couldn't find a config flag that detects this,
>> anyone?) and provide a special solution for such platforms. The solution
>> I imagine will involve static recursion that reads/writes each byte and
>> shifts it in place.
>
> [...]
>
> For Tru64/CXX there is an easy workaround available, please refer to the
> attached patch for this. Of course this isn't a general solution, although
> I would think that acc supports something similar, which then could be
> wrapped into a macro hiding the platform dependency.
>
> But you should be aware that unaligned accesses usually hurt performance a
> lot, even on platforms where the hardware is able to deal with it.
>
> HTH,
> Markus
>
--------------------------------------------------------------------------------
> Index: channel.hpp
> ===================================================================
> --- channel.hpp (revision 41078)
> +++ channel.hpp (working copy)
> @@ -292,8 +292,8 @@
> data_ptr_t operator &() const {return _data_ptr;}
> protected:
> static const integer_t max_val = (1<<NumBits) - 1;
> - const bitfield_t& const_data() const { return *static_cast<const
> bitfield_t*>(_data_ptr); }
> - bitfield_t& data() const { return *static_cast<
> bitfield_t*>(_data_ptr); }
> + __unaligned const bitfield_t& const_data() const { return
> *static_cast<const bitfield_t*>(_data_ptr); }
> + __unaligned bitfield_t& data() const { return *static_cast<
> bitfield_t*>(_data_ptr); }
> private:
> void set(integer_t value) const { // can this be done faster??
> const integer_t num_values = max_val+1;
> @@ -383,7 +383,7 @@
> integer_t get() const { return
> integer_t((this->const_data()&channel_mask) >> FirstBit); }
> void set_unsafe(integer_t value) const { this->data() =
> (this->const_data() & ~channel_mask) | (value<<FirstBit); }
> private:
> - void set_from_reference(const BitField& other_bits) const { this->data()
> = (this->const_data() & ~channel_mask) | (other_bits & channel_mask); }
> + void set_from_reference(__unaligned const BitField& other_bits) const {
> this->data() = (this->const_data() & ~channel_mask) | (other_bits &
> channel_mask); }
> };
>
> } } // namespace boost::gil
>
--------------------------------------------------------------------------------
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk