2

This tutorial (https://www.tutorialspoint.com/assembly_programming/assembly_arithmetic_instructions) is just work in integer, doesn't work in double-precision floating point.

It said I must use xmm register with addsd instruction. Actually yes it's working fine I was using it.

addsd xmm0, xmm1

But can I have same rule like that tutorial I mean with using general purpose like rax and this rule:

  • Register to register
  • Memory to register
  • Register to memory
  • Register to constant data
  • Memory to constant data

Also why xmm register is 128-bit while double-precision floating point is 64-bit. Is another bit wasted?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Citra Dewi
  • 213
  • 3
  • 12
  • 1
    SSE registers `xmm0` to `xmm15` are 128 bit, but if you use the “scalar single” or “scalar double” (`ss` or `sd`) variants of floating point instructions, only the low 32 or 64 bit are changed. As for “rules,” I don't quite understand what you mean. Check the instruction set reference for details on what operands each instruction you want to use supports. – fuz Jul 14 '22 at 15:12
  • 1
    What i mean "rules" is operand rules, like I can use immediate value like this ```addsd xmm0, 3.14``` my assembler GAS can't recognize it. ```junk.14 after expression``` – Citra Dewi Jul 14 '22 at 15:25
  • 2
    Yes, please refer to the instruction set reference for these rules. The canonical instruction set reference is in the *Intel Software Development Manuals,* vol. 2. SSE instructions (just like x87 instructions) do not support immediate operands. You have to place the floating point constant you want into memory and use a memory operand. If you like, I can write an answer with some more pointers. – fuz Jul 14 '22 at 16:11
  • 4
    I've found referring to compiler output helpful, e.g. https://godbolt.org/z/hE4rGjsPr has some examples as well as links into documentation when you right-click on instructions – Sam Mason Jul 14 '22 at 16:51
  • 4
    The high 64 bits of XMM registers are not wasted; they're usable for instructions like `addpd xmm0, xmm1` to do two additions with one instruction (with the same performance as `addsd` on Core 2 / K10 and later.) SSE stands for "Streaming [**SIMD**](https://en.wikipedia.org/wiki/Single_instruction,_multiple_data) Extensions", after all – Peter Cordes Jul 15 '22 at 09:37
  • 2
    As @SamMason says, looking at compiler output can be really helpful for examples of how to do basic stuff on any ISA you're curious about, including x86-64. Like `double f(double x){ return x + 1.25; }`, or adding integer variables to float using `cvtsi2sd` for conversion. See [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) for more about looking at compiler output, including Matt Godbolt's talk. – Peter Cordes Jul 15 '22 at 09:39
  • 1
    there are no bits wasted. The xmm/ymm/zmm registers are for SIMD: [What are the 128-bit to 512-bit registers used for?](https://stackoverflow.com/q/52932539/995714) – phuclv Jul 15 '22 at 12:16

0 Answers0