#387: Fortran interface to LoopControl broken in stable Carpet ---------------------+------------------------------------------------------ Reporter: rhaas | Owner: rhaas Type: defect | Status: review Priority: major | Milestone: ET_2011_05 Component: Carpet | Version: Resolution: | Keywords: ---------------------+------------------------------------------------------
Comment (by eschnett):
This expression rounds down to the next multiple of lc_di, assuming that lc_di is a power of 2. This is necessary for vectorisation; for example, a 2-vector of an 8-byte quantity can only be efficiently loaded and stored if it is located at an address that is a multiple of 16.
If lc_di is a power of 2, then -lc_di is a mask that sets some of the lowest bits to zero, and lc_ipos & -lc_di is the rounded-down multiple of lc_di. The difference to lc_ipos is then the offset to this location.
The expression lc_ipos & -lc_di is in this case equivalent to lc_ipos/lc_di*lc_di, but is evaluated much faster.
This is standard C and C++. The inline variable declarations may require choosing C99 semantics.
Without vectorisation, lc_di is 1, and lc_ioffset is always 0.