使用联合与结构实现64位整数除法

大整数移动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;
}

  
  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值