Issue Details (XML | Word | Printable)

Key: PCC-178
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Anders Magnusson
Reporter: Iain Hibbert
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

register miscounting on i386?

Created: 07/Nov/10 02:33 PM   Updated: 07/Nov/10 09:25 PM
Component/s: i386 target
Affects Version/s: None
Fix Version/s: None

Environment: NetBSD-current/i386

 Description  « Hide
The following code fragment

static inline unsigned short __ntohs (unsigned short x)
        __asm__ ("xchgb %b0, %h0"
                : "=q" (x) : "0" (x));
        return (x);

struct a {
        struct a *nxt;

extern struct a *new(void);

foo(unsigned short p)
        struct a *a;

        a->nxt = new();

        p = __ntohs(p);

when compiled with "pcc -O2 -c" fails at assembly stage, with the following output

/tmp/ctm.10671a: Assembler messages:
/tmp/ctm.10671a:16: Error: too many memory references for `xchg'

The code produced:

        .align 4
        .globl foo
        .type foo,@function
        pushl %ebp
        movl %esp,%ebp
        subl $8,%esp
        movl %ebx,-4(%ebp)
        movl %esi,-8(%ebp)
        movw 8(%ebp),%si
        call new
        movl %eax,(%ebx)
        xchgb eaxedx, eaxecx
        movl -4(%ebp),%ebx
        movl -8(%ebp),%esi
        .size foo,.-foo
        .ident "PCC: pcc 0.9.9 [20101107] (netbsd)"

shows a strange xchgb statement; perhaps the register counting has gone awry?

(this affects building tcpdump at least, on NetBSD-current)

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Anders Magnusson added a comment - 07/Nov/10 06:11 PM
 si get assigned for the asm instruction, but there are no byte registers in si so it fails.
There must be a constraint missing.

Anders Magnusson added a comment - 07/Nov/10 09:25 PM
Fixed now. Not the best way, but it works.