What is “=qm” in extended assembler

蓝咒 提交于 2019-11-30 09:26:30

问题


I was looking through an Intel provided reference implementation of RDRAND instruction. The page is Intel Digital Random Number Generator (DRNG) Software Implementation Guide, and the code came from Intel Digital Random Number Generator software code examples.

The following is the relevant portion from Intel. It reads a random value and places it in val, and it sets the carry flag on success.

char rc;
unsigned int val;

__asm__ volatile(
    "rdrand %0 ; setc %1"
    : "=r" (val), "=qm" (rc)
);

// 1 = success, 0 = underflow
if(rc) {
    // use val
    ...
}

Soory to have to ask. I don't think it was covered in GNU Extended Assembler, and searching for "=qm" is producing spurious hits.

What does the "=qm" mean in the extended assembler?


回答1:


What you're looking at is an inline assembler constraint. The GCC documentation is at 6.47.3.1 Simple Constraints and 6.47.3.4 Constraints for Particular Machines under x86 family section. This one (=qm) combines three flags which indicate:

  • =: The operand is write-only - its previous value is not relevant.
  • q: The operand must be in register a, b, c, or d (it cannot be in esi, for instance).
  • m: The operand may be placed in memory.



回答2:


qm probably means 1 byte 8 bit mem =qm will be valid constraint for storing 1 byte result See what setc wants

http://web.itu.edu.tr/~aydineb/index_files/instr/setc.html

reg8 and mem8

as we know only eax , ebx edx ecx .. a,b,c,d registers that q refer can be used cause they can accessed with low byte al dl cl ...With combining qm we are getting mem8 . m meant memory. Thats what I meant




回答3:


Wow that stumped me at first but I searched around a bit and found out that it is a reference to the model of the processor this peice of code is meant for.

Spicically I read that it is for the i7 Quadcore.

Is that where you got this code from?

It is a simple value indicator for a variable syntax.



来源:https://stackoverflow.com/questions/21516852/what-is-qm-in-extended-assembler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!