大整数移动16位或8位。
// Authors: perry peng
// Date: Octember 09, 2012
#include
typedef unsigned char uint8, *puint8;
typedef unsigned short uint16,*puint16;
typedef unsigned int uint32,*puint32;
typedef union _tag_rdtdat rdtdat, *prdtdat;
#pragma pack(push, 1) // enable 8-bit struct packing
union _tag_rdtdat
{
union
{
uint32 dd1;
struct
{
uint16 idata1;
uint8 b1, b2;
};
};
struct
{
uint16 idata3;
union
{
struct
{
uint32 reserved;
union
{
uint32 dd2;
struct
{
uint16 idata4;
uint16 idata5;
};
};
};
struct
{
uint16 idata6;
uint32 dd3;
};
};
};
};
#pragma pack(pop)
void __stdcall rdtsc(prdtdat);
uint32 __stdcall rdtsc_diff(prdtdat);
int
main(ac, av)
int ac;
char *av[];
{
uint32
tcnt;
rdtsc(&rd);
for (tcnt = 0; tcnt < TEST_COUNT; tcnt++)
delay(100);
fprintf(stdout, "rdtsc = %d\n", rdtsc_diff(&rd));
return 0;
}
void
__stdcall rdtsc(d)
prdtdat
d;
{
uint32
*p = &d->dd3;
__asm rdtsc
__asm mov ebx, d
__asm mov dword ptr [ebx], edx
__asm mov ebx, p
__asm mov dword ptr [ebx], eax
}
uint32
__stdcall rdtsc_diff(d)
prdtdat
d;
{
rdtdat
t;
__asm rdtsc
__asm mov t.dd3, eax
__asm mov t.dd1, edx
t.idata5 = t.idata1;
d->idata5 = d->idata1;
return t.dd2 - d->dd2;
}