Re: [PARPORT] Programming challenge!


Philip Blundell (pb@nexus.co.uk)
Mon, 19 Oct 1998 14:39:52 +0200


>Attached is a code fragment from the ppa driver modified to use parport calls
>rather than by direct IO. Direct IO limits the driver to PC style hardware,
>whereas parport calls allows for the driver to be generic for all hardware
>platforms. Your job is to adjust the C code such that the optimum assembler
>code is generated. Ideally this involves the minimum memory fetches to
>evaluate the parallel port address.

FWIW, I just compiled this fragment myself (using egcs 1.1, incidentally) and
the code looks fairly reasonable already. You can save a couple of
instructions here and there but I don't think it will make much difference in
real life -- certainly not enough to worry about at the moment. As I said, if
you have timings that show it really is a big deal then I'd be interested to
see the.

I've attached the assembler output that I get.

p.

        .file "dc.c"
        .version "01.01"
gcc2_compiled.:
..text
        .align 16
..globl ppa_nibble_in
        .type ppa_nibble_in,@function
ppa_nibble_in:
        subl $4,%esp
        pushl %ebp
        pushl %edi
        pushl %esi
        pushl %ebx
        movl 24(%esp),%edi
        movl 28(%esp),%esi
        movl 32(%esp),%ebx
        testl %ebx,%ebx
        je .L915
        .p2align 4,,7
..L917:
        movw (%edi),%cx
        movw %cx,18(%esp)
        addw $2,18(%esp)
        movb $4,%al
        movw 18(%esp),%dx
#APP
        outb %al,%dx
#NO_APP
        movl %ecx,%ebp
        incl %ebp
        movl %ebp,%edx
#APP
        inb %dx,%al
#NO_APP
        movb %al,%cl
        movb $6,%al
        movw 18(%esp),%dx
#APP
        outb %al,%dx
#NO_APP
        movl %ebp,%edx
#APP
        inb %dx,%al
#NO_APP
        andb $240,%cl
        shrb $4,%al
        orb %cl,%al
        movb %al,(%esi)
        incl %esi
        decl %ebx
        jnz .L917
..L915:
        movl $1,%eax
        popl %ebx
        popl %esi
        popl %edi
        popl %ebp
        popl %ecx
        ret
..Lfe1:
        .size ppa_nibble_in,.Lfe1-ppa_nibble_in
        .ident "GCC: (GNU) egcs-2.91.57 19980901 (egcs-1.1 release)"

-- To unsubscribe, send mail to: linux-parport-request@torque.net --
-- with the single word "unsubscribe" in the body of the message. --



This archive was generated by hypermail 2.0b3 on Wed 30 Dec 1998 - 10:18:38 EST