最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

64位整数CMPXCHG例子

SEO心得admin79浏览0评论
本文介绍了64位整数CMPXCHG例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用CMPXCHG(比较和交换)在i686的架构,32位比较和交换如下:

静态INT CAS(INT * PTR,诠释OLDVAL,诠释的newval){    unsigned char型RET;    __asm​​__ __volatile__(            锁\\ n            cmpxchgl%2%1 \\ n            SETE%0 \\ n            := Q(RET),= M(* PTR)            :R(的newval),M(* PTR),一(OLDVAL)            :内存);    //上述装配失败的情况下返回0    如果(RET)返回0;}

什么是相当于x86_64体系为64位的比较和交换

静态INT CAS(长* PTR,OLDVAL长,长的newval){    unsigned char型RET;    //?    如果(RET)返回0;}

解决方案

x86_64的有 cmpxchgq (Q为四字)指令为8字节(64位)比较和交换

I am using cmpxchg (compare-and-exchange) in i686 architecture for 32 bit compare and swap as follows.

static int CAS(int *ptr, int oldVal, int newVal) { unsigned char ret; __asm__ __volatile__ ( " lock\n" " cmpxchgl %2,%1\n" " sete %0\n" : "=q" (ret), "=m" (*ptr) : "r" (newVal), "m" (*ptr), "a" (oldVal) : "memory"); //above assembly returns 0 in case of failure if (ret) return 0; }

What is the equivalent for x86_64 architecture for 64 bit compare and swap

static int CAS(long *ptr, long oldVal, long newVal) { unsigned char ret; // ? if (ret) return 0; }

解决方案

x86_64 has the cmpxchgq ("q" for quadword) instruction for 8-byte (64 bit) compare and swap

发布评论

评论列表(0)

  1. 暂无评论