Re: Data alignment code... What goes on?



Well, it returns 0, 8, 16, 24, 32, and so on, depending on the 'len'
argument. As far as I can understand the macros, they align the data block

Yeah... But as far as I can see:

If you call Align4 gives value 4 (for len between 1-4)
If you call Align8 gives value 8 (for len between 1-8)
etc.

In the examples used, the author "hard
code" each call (i.e. Align2, Align4 etc.)

So why not simply

#define ALIGN4(len) (4)
#define ALIGN8(len) (8)
etc.

Well, I just find it peculiar :-)
I think it must be an incomplete example / usage.


best regards
Thomas







"Anders Isaksson" <blockcad@xxxxxxxxxxxxxxx> skrev i en meddelelse
news:458bb0f2$1@xxxxxxxxxxxxxxxxxxxxxxxxx
dk_sz wrote:

#define ALIGN2(len) (((len) + 1) & ~1) // round up to 2 items
#define ALIGN4(len) (((len) + 3) & ~3) // round up to 4 items
#define ALIGN8(len) (((len) + 7) & ~7) // round up to 8 items
#define ALIGN8(len) (((len) + 15) & ~15) // round up to 16 items
[...]
Isn't this a kinda convoluted way to hardcode Align8 to return 8?

Well, it returns 0, 8, 16, 24, 32, and so on, depending on the 'len'
argument. As far as I can understand the macros, they align the data block
*size* to a multiple of the power of two that's part of their name
(although you have *two* ALIGN8 there, the last one is probably ALIGN16)
so the name is badly chosen, PADSIZExx or something like that should be (a
bit) more intuitive.

--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm




.



Relevant Pages

  • Re: Data alignment code... What goes on?
    ... Isn't this a kinda convoluted way to hardcode Align8 to return 8? ... As far as I can understand the macros, they align the data block ...
    (borland.public.delphi.language.basm)
  • Re: [PATCH] x86: include ENTRY/END in entry handlers in entry_64.S
    ... This does not align "something", because something is not in the ... behind the programmers back, that's completely and totally stupid in an ... I think using the macros for opcodes make sense, as the CFI operation is ... That is a good way to use macros. ...
    (Linux-Kernel)
  • [PATCH] alpha: fix iommu-related boot panic
    ... Fix boot panic due to a typo in the recent iommu patchset from ... This also removes a couple of unnecessary BUG_ONand ALIGN() macros. ...
    (Linux-Kernel)
  • Check Boxes
    ... macros. ... I still cant seem to line up multiple boxes evenly. ... I've even tried the draw tab to align, ...
    (microsoft.public.excel.newusers)