Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The cmpxchg16b instruction for doing atomic 128 bit memory exchanges is not supported on old versions of the x64 processor but it seems like this has been supported by newer versions of the processor for several years now. How likely am I to encounter a 64-bit machine with an old processor that lacks this instruction?

share|improve this question
7  
Your most important customer certainly have one of those in one of their critical production server thats used only for important tasks run on Christmas Eve, but nowhere else, and absolutely not in the test environment... –  KarlP Sep 9 '10 at 20:06
2  
I don't think question this should have been migrated to superuser. It just ensures that fewer people who know the answer will ever see this question. –  Christopher Barber Sep 21 '10 at 19:09
add comment

migrated from stackoverflow.com Sep 11 '10 at 2:08

This question came from our site for professional and enthusiast programmers.

3 Answers

You are looking at early AMD 64-bit processors, before Rev F. There is some early stepping D Intel Noconas too that did not support it, I think, but these are rarer.

share|improve this answer
add comment

I have no data regarding the prevalence of certain types of CPUs, so I can't directly answer your question. However, you can find out whether the CPU supports CMPXCHG16B by checking whether CPUID.01h.ECX.bit13 is 1 (available) or 0 (not available).

Also note that Intel's manuals suggest that for this instruction to be carried out atomically, you need to combine it with the LOCK prefix.

share|improve this answer
    
Yes, I know how to check the cpuid result. The issue is what to do if it is not supported. I would rather not waste time working around a missing instruction if I am never going to see that case in practice. –  Christopher Barber Sep 9 '10 at 20:37
    
@Christopher Barber - CPUID has been supported since late 486 processors, which also implies that every 64-bit capable x86 processor will support CPUID. –  PhiS Sep 10 '10 at 6:49
    
@PhiS: I'm pretty sure Christopher was talking about the lack of support for the cmpxchg16b. What to do if that is missing –  Bahbar Sep 10 '10 at 8:01
add comment

Nowadays maybe it's less likely that you'll see such old PCs. But in case that it shows up you can use some workarounds like this

Or you can use SSE to read/write all 128 bit at once since all x86_64 processors have support for SSE2

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.