Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Incorrect order of operands for inline assembly MULX.

AYee1
Novice
476 Views

The following code produces different output between ICC16.2 and GCC5.3.

#include <stdint.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

int main(){
    uint64_t a = 123456789123456789;
    uint64_t b = 987654321987654321;
    uint64_t L, H;

    __asm__(
        "mulx   %, %, %;"
        :  "=r" (L),  "=r" (H)
        :  "r" (a),  "d" (b)
    );

    cout << "low  = " << L << endl;
    cout << "high = " << H << endl;

    system("pause");
}

On Windows/ICC16, it outputs:

low  = 6609981190679600
high = 14369616054794401669

On Linux/GCC5.3, it outputs:

low  = 14369616054794401669
high = 6609981190679600

The order of the output operands on the MULX instruction are swapped. I believe GCC is correct since the inline assembly maps 1-to-1 to the AT&T GCC syntax, whereas ICC converts it to Intel syntax and in the process switches the order of the operands.

 

0 Kudos
3 Replies
KitturGanesh
Employee
476 Views

Hi @a-yee,
I could reproduce on Windows/16.0.2. Can you let me know the OS info and the platform you're running on with Linux* as I couldn't on Linux*
Thanks,
Kittur

0 Kudos
AYee1
Novice
476 Views

Hi Kittur,

The hardware is:

  • Core i7 4770K (Haswell)

I've tested on two versions of Ubuntu/GCC. They both produce the same result - which is different from what ICC 16.02 produces on Windows.

  • Ubuntu 15.10
  • GCC 5.3.0
  • Compile as: "g++ mulx.cpp" (no other compiler options)

and

  • Ubuntu 16.04
  • GCC 5.3.1
  • Compile as: "g++ mulx.cpp" (no other compiler options)

The Ubuntu 16.04 is freshly installed out-of-the box from one of the recent ISOs.

0 Kudos
KitturGanesh
Employee
476 Views

Hi Alex,
Thanks, yes I could reproduce the issue and will file the issue with the developers and update you accordingly - appreciate much.

Kittur

0 Kudos
Reply