Bugs item #2413278, was opened at 2008-12-09 22:54
Message generated for change (Comment added) made by hpa
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=106208&aid=2413278&group_id=6208
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 8
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Suboptimal code generated for EAX math operations
Initial Comment:
Using the latest snapshot.
Example code.
BITS 32
add eax, 4
add ecx, 4
add eax, 0x11223344
add ecx, 0x11223344
Generates
00000000 0504000000 add eax,0x4
00000005 83C104 add ecx,byte +0x4
00000008 0544332211 add eax,0x11223344
0000000D 81C144332211 add ecx,0x11223344
Using the byte keyword gives me what I'd expect
add eax, byte 4
'adc', 'sub', 'or', etc are also affected.
----------------------------------------------------------------------
Comment By: H. Peter Anvin (hpa)
Date: 2008-12-29 20:02
Message:
This item has been resolved; the fix has been checked into git
(http://repo.or.cz/w/nasm.git) and will be in the next release.
You can usually also obtain a nightly snapshot at
ftp://ftp.zytor.com/pub/nasm/snapshots/; the snapshot robot usually runs
some time between 07:00 and 10:30 UTC, but sometimes runs immediately if
there was no previous snapshot for today.
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2008-12-11 00:00
Message:
>From insns.dat
ADD reg_eax,imm \321\1\x05\41 386,SM
That line provides the 05 form for EAX. A few more lines farther down
ADD rm32,imm \321\155\x81\200\151 386,SM
That line provides both the 81 and 83 forms for all registers. A few
lines above the 'ADD reg_eax'
ADD rm32,imm8 \321\1\x83\200\275 386
That line only provides the 83 form for when the byte keyword is used e.g.
'add eax, byte 4'.
It appears as if the eax specific line provides only the 05 form of the
instruction. If you swap precedence for the general form and the eax form
then you lose the 05 form. The reg_eax line is never used.
ADD rm32,imm \321\155\x81\200\151 386,SM
ADD reg_eax,imm \321\1\x05\41 386,SM
Desired results achieved by adding an sbyte form with the following
precedence
ADD reg_eax,sbyte32 \321\1\x83\200\275 386,SM
ADD reg_eax,imm \321\1\x05\41 386,SM
ADD rm32,imm \321\155\x81\200\151 386,SM
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2008-12-10 21:48
Message:
The bug is in 2.05.01 but not 2.04.
Diffing insns.dat shows that a bunch of ax,eax,rax sbyte lines were
removed. Adding them in fixes the problem in my superficial tests. I
don't know enough about nasm to know why there were removed or what is
affected by adding them back in.
Affected instructions
ADC
ADD
AND
CMP
OR
SBB
SUB
XOR
----------------------------------------------------------------------
Comment By: H. Peter Anvin (hpa)
Date: 2008-12-10 10:53
Message:
Confirmed bug with optimizer enabled with latest git. The problem appears
to be using the 05/15/25/35 form even when the 83 form is available; the 83
form will be shorter except in 16-bit mode, where they are equivalent.
Somehow the instruction picker fails to do the right thing here.
----------------------------------------------------------------------
Comment By: H. Peter Anvin (hpa)
Date: 2008-12-10 10:44
Message:
Use the -O option to have nasm optimize immediates.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=106208&aid=2413278&group_id=6208
|