Mail Archives: djgpp/2016/02/16/20:15:11
Hi,
On Tuesday, February 16, 2016 at 3:19:21 AM UTC-6, Wiktor S. wrote:
> >> This was a one-line problem in assembly code:
> >>
> >> rep/movsl (%esi),(%edi)
> >>
> >> Newest as.exe generates wrong binary code on the above line. After
> >> changing to "rep movsl" with space it worked.
> >>
> >> I don't know if rep/movsl syntax is correct or not, but if it is
> >> not, AS should fail instead of silently generating bad code.
> >
> > Do you mean that GCC itself is generating [sic] "rep/movsl" or is it
> > some inline or handwritten (external) assembly file?
>
> It is in handwritten assembly.
>
> The dissasembled (wrong) instruction is
>
> rep add %eax,%esi
I don't know if this is truly a bug or not. I also don't know if the
BinUtils maintainers will fix it. I also don't know what Juan plans
to do (apparently BNU2251BR4.ZIP is already on mirrors, uploaded
yesterday). I would not necessarily rush to delete BNU226B.ZIP just yet.
Yes, I see d_copy.s (circa 1998) from Q1SOURCE.ZIP has this line.
That's obviously not your fault, only the original author's, but
I suspect that BinUtils maintainers will just tell you to change
your code locally.
While I'm not sure exactly, I've never noticed anybody using "rep/..."
in their sources (with a slash). Normally you only see tabs or blanks,
but I guess other variations exist as well. I did see "rep ; ret"
a few years back, but I wasn't 100% comfortable using it (and don't
know if it really helped speed much).
That's my point here, mostly. "rep" (and other prefixes) are sometimes
used in weird ways. I think extra prefixes are usually just ignored.
And sometimes new instructions will use a formerly-invalid combo
since nobody was using it for anything anyways. Not sure if
"as --march=..." will help you here or not.
For instance, I was already vaguely aware that "pause" [SSE2?] was
really "rep nop". And a quick check shows that it didn't stop there.
Apparently "lzcnt" [SSE4.2?] is really "rep bsr".
So, for testing, here's a simple FASM example:
N.B. FASM dude is very savvy, so if his accepts something, I assume
he has good reason. He supports (AFAIK) all modern instructions,
including AVX and probably the others (MOVBE, etc). EDIT: Even
NASM 2.11.08 doesn't complain.
=== blah.asm begins ===
use32
format coff
nop
rep add eax,ebx
rep xor eax,ebx
rep aam 16
nop
rep ret
rep nop
nop
bsr eax,[ebx]
lzcnt eax,[ebx]
nop
ret
=== blah.asm ends ===
And here's what (DJGPP) Objdump 2.25.1 says:
=== objdump.out begins ===
blah.o: file format coff-go32
Disassembly of section .flat:
00000000 <.flat>:
0: 90 nop
1: f3 01 d8 repz add eax,ebx
4: f3 31 d8 repz xor eax,ebx
7: f3 d4 10 repz aam 0x10
a: 90 nop
b: f3 c3 repz ret
d: f3 90 pause
f: 90 nop
10: 0f bd 03 bsr eax,DWORD PTR [ebx]
13: f3 0f bd 03 lzcnt eax,DWORD PTR [ebx]
17: 90 nop
18: c3 ret
=== objdump.out ends ===
Now, of course you can argue that "rep/movsl" isn't anywhere close to
"rep add", so that's not intentional and presumably bad. I don't
disagree, just saying, it's probably hard to catch every possible
error like this.
- Raw text -