www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11071] New: REX.R and REX.W prefixes do not seem to be generated in some cases

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11071

           Summary: REX.R and REX.W prefixes do not seem to be generated
                    in some cases
           Product: D
           Version: D2
          Platform: x86_64
               URL: http://forum.dlang.org/thread/izztrfapqdzmsohchqbq for
                    um.dlang.org
        OS/Version: Linux
            Status: NEW
          Keywords: iasm
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jc7919 outlook.com


--- Comment #0 from Joseph Cassman <jc7919 outlook.com> 2013-09-19 14:41:00 PDT
---
Created an attachment (id=1250)
test suite, all should compile successfully

For some reason the following code in an asm block compiles

    mov   RAX,0x1ffffffffUL;
    and   RAX,0xffffffffUL;
    or    RAX,0xffffffffUL;
    xor   RAX,0xffffffffUL;
    add   RAX,0xffffffffUL;
    adc   RAX,0xffffffffUL;
    sub   RAX,0xffffffffUL;
    sbb   RAX,0xffffffffUL;
    cmp   RAX,0xffffffffUL;
    imul  RAX,0xffffffffUL;
    test  RAX,0xffffffffUL;

even though its disassembly (below) does not have REX prefixes.

    mov RAX,01FFFFFFFFh
    and EAX,0FFFFFFFFh
    or  EAX,0FFFFFFFFh
    xor EAX,0FFFFFFFFh
    add EAX,0FFFFFFFFh
    adc EAX,0FFFFFFFFh
    sub EAX,0FFFFFFFFh
    sbb EAX,0FFFFFFFFh
    cmp EAX,0FFFFFFFFh
    imul    EAX,RAX,0FFFFFFFFFFFFFFFFh
    test    EAX,0FFFFFFFFh

However, the following code fails to compile. The problem occurs for all
generic registers (RAX .. RDX R8 .. R15).

    mul   RAX,0xffffffffUL;
    div   RAX,0xffffffffUL;
    idiv  RAX,0xffffffffUL;
    and   RAX,0x1ffffffffUL;
    or    RAX,0x1ffffffffUL;
    xor   RAX,0x1ffffffffUL;
    add   RAX,0x1ffffffffUL;
    adc   RAX,0x1ffffffffUL;
    sub   RAX,0x1ffffffffUL;
    sbb   RAX,0x1ffffffffUL;
    cmp   RAX,0x1ffffffffUL;
    mul   RAX,0x1ffffffffUL;
    imul  RAX,0x1ffffffffUL;
    div   RAX,0x1ffffffffUL;
    idiv  RAX,0x1ffffffffUL;
    test  RAX,0x1ffffffffUL;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 19 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11071



--- Comment #1 from Joseph Cassman <jc7919 outlook.com> 2013-09-19 14:42:33 PDT
---
Created an attachment (id=1251)
instructions that compile successfully (up to line 166)

Generated using obj2asm.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 19 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11071



--- Comment #2 from Joseph Cassman <jc7919 outlook.com> 2013-09-19 14:58:12 PDT
---
Just looking for patterns in the disassembly. 

It is interesting that all instructions (other than move) encode RAX as EAX.
Also, the 64-bit immediate values are trimmed accordingly to 32-bit values
("0FFFFFFFFh") for RAX.

For the registers RBX through R15, the instructions "and", "or", "xor", and
"test" all convert every immediate to 32-bits. The other non-move instructions,
however, convert the original value of "0x1ffffffffUL" to "0FFFFFFFFFFFFFFFFh".
This sign-extension is not what I was intending, as the value was designated
unsigned long, and I expected them to be zero-extended to "000000001FFFFFFFFh".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 19 2013