#include "iostream"
using namespace std;
/* return x % (mod) align
* eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align)
* eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align)
*/
#define P2PHASE(x, align) ((x) & ((align) - 1))
/*
* return how much space is left in this block (but if it's perfectly
* aligned, return 0).
* eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x)
* eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x)
*/
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
int main()
{
int align = 4096;
int off = 3896;
int len = 200;
printf("%d \n", P2PHASE(off, align));
printf("%d \n", P2NPHASE(len + off, align));
getchar();
return 0;
}
C++ PHASE Align
最新推荐文章于 2024-09-07 23:15:53 发布