Author Topic: Bug repport  (Read 14067 times)

nidud

  • Member
  • *****
  • Posts: 1614
    • https://github.com/nidud/asmc
Bug repport
« on: February 03, 2016, 01:51:30 AM »
Version tested:

HJWasm v2.13.32bit., Jan 29 2016, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

build: using Open Watcom
Code: [Select]
hjwasm.exe:
for %%q in (\HJWASM\SRC\*.c) do wcc386 -q -bt=nt -bc -zc -I\WATCOM\h;\HJWASM\SRC\h -3r -obmilrt -s -DNDEBUG %%q
wlink N $@ OP q, m System nt file { *.obj }
@del *.obj

result:
Code: [Select]
compile:
\HJWASM\SRC\main.c(80): Error! E1011: Symbol 'intptr_t' has not been declared
\HJWASM\SRC\parser.c(728): Warning! W118: Label 'found' has been defined but not referenced

link:
Warning! W1027: file assume.obj(K:\HJWASM\SRC\assume.c): redefinition of _broadflags ignored
Warning! W1027: file assume.obj(K:\HJWASM\SRC\assume.c): redefinition of _decoflags ignored
...
creating a Windows NT character-mode executable
Error! E2028: fopen_ is an undefined reference

After fixing main.c:
Code: [Select]
compile:
\HJWASM\SRC\parser.c(728): Warning! W118: Label 'found' has been defined but not referenced

link:
Warning! W1027: file assume.obj(K:\HJWASM\SRC\assume.c): redefinition of _broadflags ignored
Warning! W1027: file assume.obj(K:\HJWASM\SRC\assume.c): redefinition of _decoflags ignored
...
creating a Windows NT character-mode executable

So now it works, but the issue with _broadflags and _decoflags need to be sorted somehow.

Regress test

Expected output is build with the latest stable version of JWasm (v2.12A):

http://masm32.com/board/index.php?topic=902.msg49995#msg49995

Result of test (35):
Code: [Select]
..      INVOK646 BIN STRING3  BIN HLL4 err
AVX1 BIN INVOK649 BIN STRING64 BIN INDIR1 err
AVX4 BIN INVOK64A BIN VARAR642 BIN MOV645 err
AVX641 BIN MEMANY   BIN VARARG64 BIN PROC641 err
EXPANS37 BIN MOVDQ16  BIN ALIGN3   err SHLD err
EXPANS40 BIN MOVDQ32  BIN AVX2    err STRUCT29 err
HIGHWORD BIN MOVDQ64  BIN AVX3    err STRUCT37 err
INOUT BIN RTCOND3  BIN CALL3    err STRUCT41 err
INVOK644 BIN STRING2  BIN DATA7    err STRUCT29 obj

HIGHWORD.ASM: fail
Code: [Select]
mov eax,HIGHWORD 80000000h

HLL4.ASM: fail - missing label
Code: [Select]
.while !(eax || edx) && ecx
    nop
.endw

ALIGN3.ASO: missing warning
Code: [Select]
align 64 ;incompatible with segment alignment

SHLD.ASO: missing error
Code: [Select]
shld eax,ecx,1,2

AVX2.ASO: missing error(s)
Code: [Select]
vmaskmovps xmm0, xmm1
vmaskmovps m128, xmm0
vmaskmovps m256, ymm0
vmaskmovpd xmm0, xmm1
vmaskmovpd m128, xmm0
vmaskmovpd m256, ymm0
vaddpd xmm0, xmm1
vaddsubpd xmm0, xmm1
vblendvpd xmm0, xmm1, xmm2
vblendvpd xmm0, xmm1, m128
vblendvpd ymm0, ymm1, ymm2
vblendvpd ymm0, ymm1, m256
vblendvps xmm0, xmm1
vblendvps xmm0, xmm1
vblendvps ymm0, ymm1
vblendvps ymm0, ymm1
vpblendvb xmm0, xmm1, xmm2
...

Well the list goes on and on...

In the AVX1.ASM file we have the following:

ASMC/JWASM:
Code: [Select]
00000012  C4E27D190500000000 vbroadcastsd ymm0, m64
0000008C  C4E2710DC2 vpermilpd xmm0, xmm1, xmm2
00000091  C4E2710D0500000000 vpermilpd xmm0, xmm1, m128
0000009A  C4E3790DC101 vpermilpd xmm0, xmm1, 1
000000A0  C4E2750DC2 vpermilpd ymm0, ymm1, ymm2
000000A5  C4E2750D0500000000 vpermilpd ymm0, ymm1, m256
000000AE  C4E37D0DC101 vpermilpd ymm0, ymm1, 1
000000C2  C4E3790CC101          vpermilps xmm0, xmm1, 1
000000D6  C4E37D0CC101          vpermilps ymm0, ymm1, 1
00000124  C5FC77                vzeroall
00000390  C5F1D1C2              vpsrlw  xmm0, xmm1, xmm2
00000394  C5F1D10500000000      vpsrlw  xmm0, xmm1, m128
0000039C  C5F1D2C2              vpsrld  xmm0, xmm1, xmm2
000003A0  C5F1D20500000000      vpsrld  xmm0, xmm1, m128
000003A8  C5F1D3C2              vpsrlq  xmm0, xmm1, xmm2
000003AC  C5F1D30500000000      vpsrlq  xmm0, xmm1, m128
000003B4  C5F1E1C2              vpsraw  xmm0, xmm1, xmm2
000003B8  C5F1E10500000000      vpsraw  xmm0, xmm1, m128
000003C0  C5F1E2C2              vpsrad  xmm0, xmm1, xmm2
000003C4  C5F1E20500000000      vpsrad  xmm0, xmm1, m128
000003CC  C5F1F1C2              vpsllw  xmm0, xmm1, xmm2
000003D0  C5F1F10500000000      vpsllw  xmm0, xmm1, m128
000003D8  C5F1F2C2              vpslld  xmm0, xmm1, xmm2
000003DC  C5F1F20500000000      vpslld  xmm0, xmm1, m128
000003E4  C5F1F3C2              vpsllq  xmm0, xmm1, xmm2
000003E8  C5F1F30500000000 vpsllq xmm0, xmm1, m128
...

HJWASM:
Code: [Select]
00000012  C4E2FD190500000000 vbroadcastsd ymm0, m64
0000008C  C4E2F10DC2 vpermilpd xmm0, xmm1, xmm2
00000091  C4E2F10D0500000000 vpermilpd xmm0, xmm1, m128
0000009A  C4E3F905C101 vpermilpd xmm0, xmm1, 1
000000A0  C4E2F50DC2 vpermilpd ymm0, ymm1, ymm2
000000A5  C4E2F50D0500000000 vpermilpd ymm0, ymm1, m256
000000AE  C4E3FD05C101 vpermilpd ymm0, ymm1, 1
000000C2  C4E37904C101          vpermilps xmm0, xmm1, 1
000000D6  C4E37D04C101          vpermilps ymm0, ymm1, 1
00000124  C5F877                vzeroall
00000390  C5F9D1CA              vpsrlw  xmm0, xmm1, xmm2
00000394  C5F9D10D00000000      vpsrlw  xmm0, xmm1, m128
0000039C  C5F9D2CA              vpsrld  xmm0, xmm1, xmm2
000003A0  C5F9D20D00000000      vpsrld  xmm0, xmm1, m128
000003A8  C5F9D3CA              vpsrlq  xmm0, xmm1, xmm2
000003AC  C5F9D30D00000000      vpsrlq  xmm0, xmm1, m128
000003B4  C5F9E1CA              vpsraw  xmm0, xmm1, xmm2
000003B8  C5F9E10D00000000      vpsraw  xmm0, xmm1, m128
000003C0  C5F9E2CA              vpsrad  xmm0, xmm1, xmm2
000003C4  C5F9E20D00000000      vpsrad  xmm0, xmm1, m128
000003CC  C5F9F1CA              vpsllw  xmm0, xmm1, xmm2
000003D0  C5F9F10D00000000      vpsllw  xmm0, xmm1, m128
000003D8  C5F9F2CA              vpslld  xmm0, xmm1, xmm2
000003DC  C5F9F20D00000000      vpslld  xmm0, xmm1, m128
000003E4  C5F9F3CA              vpsllq  xmm0, xmm1, xmm2
000003E8  C5F9F30D00000000 vpsllq xmm0, xmm1, m128
...

It's difficult with regards to the AVX instructions to say what is correct or not, but it would be good to have corrected binaries for the test.

johnsa

  • Member
  • ****
  • Posts: 706
    • Uasm
Re: Bug repport
« Reply #1 on: February 03, 2016, 03:34:34 AM »
Thanks for an excellent/ detailed report!

Let's work through the issues one by one.

The first one is this annoyance around intptr_t in main.c

If we use long and forget about intptr_t.. (how it used to be once in the source) then the binary version of hjwasm works on Win7 but gives a general failure when executed on Win10...
If we use intptr_t .. it doesn't compile for some compilers like GCC ..

Code: [Select]


#ifdef __UNIX__
#if defined( intptr_t )
intptr_t    fh; //fixed by ToutEnMasm intptr_t instead of long
#else
long        fh; // more compatible type (linux builds etc) when intptr_t isn't valid.
#endif
#else
intptr_t    fh;
#endif

This block needs to be modified to something that works with EVERY C compiler then.. suggestions welcome? :)



ALIGN3.ASO: missing warning
We intentionally removed this warning, because you would have it using align 32 as well, which was very annoying when trying to align AVX structs / data.
For this particular case I would say we need to amend the regression, as a user I would expect to align things however I see fit. [open for discussion for values > 32]?

working bottom up..

Code: [Select]
HJWASM
00000124  C5F877                vzeroall
vs
ASMC/JWASM
00000124  C5FC77                vzeroall
0000000000402004 C5 FC 77             vzeroall 
0000000000402007 C5 F8 77             vzeroupper 
This is what the encoding should be.. so this is a BUG.

Code: [Select]
HJWASM
000000D6  C4E37D04C101          vpermilps ymm0, ymm1, 1
vs
ASMC/JWASM
000000D6  C4E37D0CC101          vpermilps ymm0, ymm1, 1
In this case HJWASM encoding is correct and confirmed against FASM and Intel manual..
FASM = C4 E3 7D 04 C1 01
Intel Manual: VEX.256.66.0F3A.W0 04 /r ib      [c4 e3 7d]= the vex portion which should be followed by 0x04.

Code: [Select]
vpsllq  xmm0, xmm1, xmm2
This one is a BUG, the src/dst registers are being encoded the wrong way around.

Code: [Select]
C4E2FD190500000000 vbroadcastsd ymm0, m64
The W bit of the 3 byte vex encoding SHOULD be 0 yielding 7D not FD as the 3rd byte... bug


mov   eax,HIGHWORD 80000000h appears to be leaving the top half of eax signed with 0xffff... this is wrong.


shld eax,ecx,1,2    <--- this isn't a valid instruction:  SHLD eax,ecx,1 is and works ?


johnsa

  • Member
  • ****
  • Posts: 706
    • Uasm
Re: Bug repport
« Reply #2 on: February 03, 2016, 03:42:49 AM »
I've logged the above into github issues and will start fixing them.
I suggest we get them sorted and then re-run the tests, Bearing in mind that there are a few cases where hjwasm is correct and the others not !

nidud

  • Member
  • *****
  • Posts: 1614
    • https://github.com/nidud/asmc
Re: Bug repport
« Reply #3 on: February 03, 2016, 04:26:37 AM »
Quote
This block needs to be modified to something that works with EVERY C compiler then.. suggestions welcome? :)

I assumed the first one worked..
The reversed version:
Code: [Select]
#if !defined( intptr_t )
#define intptr_t long
#endif

Quote
ALIGN3.ASO: missing warning
We intentionally removed this warning, because you would have it using align 32 as well, which was very annoying when trying to align AVX structs / data.
For this particular case I would say we need to amend the regression, as a user I would expect to align things however I see fit. [open for discussion for values > 32]?

copy tmp\ALIGN3.err exp\ALIGN3.EXP

The DBGCV.obj file only differ in assembler name, so
copy tmp\DBGCV.obj exp\DBGCV.EXP

Quote
mov   eax,HIGHWORD 80000000h appears to be leaving the top half of eax signed with 0xffff... this is wrong.

HIGHWORD.ASM:
Code: [Select]
; ASMC v2.14 - JWASM 2.12 (signed) HIGHWORD -- qword


.486
.model flat
.code

mov eax,HIGHWORD 80000000h

end

Generated code:

MOV EAX,00008000h

EXPREVAL.C: highword_op()
{
    TokenAssign( opnd1, opnd2 );
    if ( opnd2->kind == EXPR_ADDR && opnd2->instr != T_SEG ) {
opnd1->instr = T_HIGHWORD;
opnd1->mem_type = MT_EMPTY;
    }
    opnd1->value = (opnd1->value >> 16) & 0xFFFF; /* ASMC v2.14 */
    return( NOT_ERROR );
}

Quote
shld eax,ecx,1,2    <--- this isn't a valid instruction:  SHLD eax,ecx,1 is and works ?

if the latter don't work the regression test will tell you so

Quote
I suggest we get them sorted and then re-run the tests, Bearing in mind that there are a few cases where hjwasm is correct and the others not !

That's why it's important to have a regression test with correct binaries

TWell

  • Member
  • ****
  • Posts: 748
Re: Bug repport
« Reply #4 on: February 03, 2016, 05:04:19 AM »
Quote
intptr_t   uintptr_t   Integer type capable of holding a value converted from a void pointer and then be converted back to that type with a value that compares equal to the original pointer.
Optional: These typedefs may not be defined in some library implementations.*
Quote
intptr_t    fh;
We compile hjwasm to x64 too. There have to use it?

nidud

  • Member
  • *****
  • Posts: 1614
    • https://github.com/nidud/asmc
Re: Bug repport
« Reply #5 on: February 03, 2016, 06:26:05 AM »
We compile hjwasm to x64 too. There have to use it?

It's just a handle sizeof(size_t).
I assume DWORD in 32-bit and QWORD in 64-bit.

So maybe this will work:
Code: [Select]
size_t fh;

johnsa

  • Member
  • ****
  • Posts: 706
    • Uasm
Re: Bug repport
« Reply #6 on: February 03, 2016, 08:33:54 AM »
size_t is working for me here on win7 and win10 using both Visual C and GCC 5.x builds, so for now I'm going to stick to that and see how it goes :)

habran

  • Member
  • *****
  • Posts: 1175
    • uasm
Re: Bug repport
« Reply #7 on: February 03, 2016, 08:42:13 AM »
Good job nidud :t
it works for me as well on windows 8.1
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1614
    • https://github.com/nidud/asmc
Re: Bug repport
« Reply #8 on: February 04, 2016, 04:49:37 AM »
New test: HJWasm v2.13, Feb  3 2016, Masm-compatible assembler.

compile: 49 warnings
\HJWASM\SRC4\h\instruct.h(1932): Warning! W138: No newline at end of file
...

link: warnings
Warning! W1027: file assume.obj(K:\HJWASM\SRC4\assume.c): redefinition of _evex ignored
Warning! W1027: file assume.obj(K:\HJWASM\SRC4\assume.c): redefinition of _broadflags ignored
Warning! W1027: file assume.obj(K:\HJWASM\SRC4\assume.c): redefinition of _decoflags ignored
...

regress result: 35
Code: [Select]
ALIGN3.err
AVX1.BIN
AVX2.err
AVX3.err
AVX4.BIN
AVX641.BIN
CALL3.err
DATA7.err
DBGCV.obj
EXPANS37.BIN
EXPANS40.BIN
HLL4.err
INDIR1.err
INOUT.BIN
INVOK644.BIN
INVOK646.BIN
INVOK649.BIN
INVOK64A.BIN
MEMANY.BIN
MOV645.err
MOVDQ16.BIN
MOVDQ32.BIN
MOVDQ64.BIN
PROC641.err
RTCOND3.BIN
SHLD.err
STRING2.BIN
STRING3.BIN
STRING64.BIN
STRUCT29.err
STRUCT29.obj
STRUCT37.err
STRUCT41.err
VARAR642.BIN
VARARG64.BIN

Some of the files tested:
Code: [Select]
A ASMC
H HJWASM
J JWASM 2.12B
* assumed error

EXPANS37.ASM: good
Code: [Select]
A 0000000A  85C0      * test ax, ax
H 0000000A  85C0      * test ax, ax
J 0000000A  23C0      * and ax, ax

copy tmp\EXPANS37.bin exp\EXPANS37.EXP

EXPANS40.ASM: good
Code: [Select]
A 00000000  85C0     *1 test eax, eax
H 00000000  85C0     *1 test eax, eax
J 00000000  23C0     *1 and eax, eax

A 00000006  85C0     *1 test eax, eax
H 00000006  85C0     *1 test eax, eax
J 00000006  23C0     *1 and eax, eax

copy tmp\EXPANS40.bin exp\EXPANS40.EXP

AVX1.ASM: reduced number of errors
Code: [Select]
A 0000008C  C4 E2 71 0D C2 vpermilpd xmm0, xmm1, xmm2
*H 0000008C C4 E2 F1 0D C2 vpermilpd xmm0, xmm1, xmm2
A 00000091  C4 E2 71 0D 0500000000 vpermilpd xmm0, xmm1, m128
*H 00000091 C4 E2 F1 0D 0500000000 vpermilpd xmm0, xmm1, m128
A 0000009A  C4 E3 79 05 C1 01 vpermilpd xmm0, xmm1, 1
*H 0000009A C4 E3 F9 05 C1 01 vpermilpd xmm0, xmm1, 1
A 000000A0  C4 E2 75 0D C2 vpermilpd ymm0, ymm1, ymm2
*H 000000A0 C4 E2 F5 0D C2 vpermilpd ymm0, ymm1, ymm2
A 000000A5  C4 E2 75 0D 0500000000 vpermilpd ymm0, ymm1, m256
*H 000000A5 C4 E2 F5 0D 0500000000 vpermilpd ymm0, ymm1, m256
A 000000AE  C4 E3 7D 05 C1 01 vpermilpd ymm0, ymm1, 1
*H 000000AE C4 E3 FD 05 C1 01 vpermilpd ymm0, ymm1, 1

A 00000440  C5F973F901 vpslldq xmm0, xmm1, 1
H 00000440  C5F173F801 vpslldq xmm0, xmm1, 1
A 00000445  C5F973D902 vpsrldq xmm0, xmm1, 2
H 00000445  C5F173D802 vpsrldq xmm0, xmm1, 2
A 0000044A  C5F971D103 vpsrlw xmm0, xmm1, 3
H 0000044A  C5F171D003 vpsrlw xmm0, xmm1, 3
A 0000044F  C5F972D104 vpsrld xmm0, xmm1, 4
H 0000044F  C5F172D004 vpsrld xmm0, xmm1, 4
A 00000454  C5F973D105 vpsrlq xmm0, xmm1, 5
H 00000454  C5F173D005 vpsrlq xmm0, xmm1, 5
A 00000459  C5F971E106 vpsraw xmm0, xmm1, 6
H 00000459  C5F171E006 vpsraw xmm0, xmm1, 6
A 0000045E  C5F972E107 vpsrad xmm0, xmm1, 7
H 0000045E  C5F172E007 vpsrad xmm0, xmm1, 7
A 00000463  C5F971F108 vpsllw xmm0, xmm1, 8
H 00000463  C5F1F1C008 vpsllw xmm0, xmm1, 8
A 00000468  C5F972F109 vpslld xmm0, xmm1, 9
H 00000468  C5F1F2C009 vpslld xmm0, xmm1, 9
A 0000046D  C5F973F10A vpsllq xmm0, xmm1, 10
H 0000046D  C5F1F3C00A vpsllq xmm0, xmm1, 10
A 000006E6  C5FFE60500000000 vcvtpd2dq xmm0, m256   ;L bit set?
H 000006E6  C5FBE60500000000 vcvtpd2dq xmm0, m256   ;L bit set?
A 000006FE  C5FDE60500000000 vcvttpd2dq xmm0, m256  ;L bit set?
H 000006FE  C5F9E60500000000 vcvttpd2dq xmm0, m256  ;L bit set?
A 00000716  C5FD5A0500000000 vcvtpd2ps xmm0, m256   ;L bit set?
H 00000716  C5F95A0500000000 vcvtpd2ps xmm0, m256   ;L bit set?
A 000008BE  C5F9C5C102 vpextrw eax, xmm1, 2
H 000008BE  C5F8C5C102 vpextrw eax, xmm1, 2

AVX4.ASM: reduced number of errors
Code: [Select]
A 00000048  C4E2710D03 vpermilpd xmm0, xmm1, [ebx]
H 00000048  C4E2F10D03 vpermilpd xmm0, xmm1, [ebx]
A 0000004D  C4E2750D03 vpermilpd ymm0, ymm1, [ebx]
H 0000004D  C4E2F50D03 vpermilpd ymm0, ymm1, [ebx]

AVX641.ASM: ?
Code: [Select]
A 00000098  C5 F9 C5 C1 02 vpextrw eax, xmm1, 2
H 00000098  C5 F8 C5 C1 02 vpextrw eax, xmm1, 2
A 00000168  C5 F9 D7 C1 vpmovmskb eax, xmm1
H 00000168  C5 F8 D7 C1 vpmovmskb eax, xmm1
A 0000016C  C4 E1 F9 D7 C1 vpmovmskb rax, xmm1
H 0000016C  C4 E1 F8 D7 C1 vpmovmskb rax, xmm1

johnsa

  • Member
  • ****
  • Posts: 706
    • Uasm
Re: Bug repport
« Reply #9 on: February 04, 2016, 08:26:56 AM »
Excellent thanks!

I'm slowly working my way through the regression findings one by one and putting them onto the github issues page, from whence Habran and I are making our way through them in batches.. it's a bit of a process but we'll get there shortly!

Thanks for all the testing and support!

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: Bug repport
« Reply #10 on: February 04, 2016, 04:46:07 PM »
Win 10
Link problem,"corrupted object file"
Fa is a musical note to play with CL

habran

  • Member
  • *****
  • Posts: 1175
    • uasm
Re: Bug repport
« Reply #11 on: February 05, 2016, 09:26:28 AM »
ToutEnMasm, it happens because vblendvpd xmm0, xmm1,m128 is missing 4th operand,
it suppose to be vblendvpd xmm0, xmm1,m128,xmm2
It is now fixed but you have to wait until Johnsa upload it on Git.
He will let you know when ready.
Cod-Father

dedndave

  • Member
  • *****
  • Posts: 8808
  • Still using Abacus 2.0
    • DednDave
Re: Bug repport
« Reply #12 on: February 05, 2016, 11:33:00 AM »
"repport" should have only one "p"

habran

  • Member
  • *****
  • Posts: 1175
    • uasm
Re: Bug repport
« Reply #13 on: February 05, 2016, 02:15:47 PM »
Pure thing, "rapport" is much better off ;)
Where is that equal opportunity , it also has 2 "p" :(
« Last Edit: February 05, 2016, 04:42:19 PM by habran »
Cod-Father

dedndave

  • Member
  • *****
  • Posts: 8808
  • Still using Abacus 2.0
    • DednDave
Re: Bug repport
« Reply #14 on: February 05, 2016, 04:21:35 PM »
it was a bug, so i repported it   :lol: