Re: [RFC PATCH] MIPS: optimise 32-bit do_div() with constant divisor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Daney <ddaney.cavm@xxxxxxxxx> writes:

> On 11/06/2014 08:23 AM, Mans Rullgard wrote:
>> This is an adaptation of the optimised do_div() for ARM by
>> Nicolas Pitre implementing division by a constant using a
>> multiplication by the inverse.  Ideally, the compiler would
>> do this internally as it does for 32-bit operands, but it
>> doesn't.
>>
>> This version of the code requires an assembler with support
>> for the DSP ASE syntax since accessing the hi/lo registers
>> sanely from inline asm is impossible without this.
>
> It is easy to access hi/lo from inline asm.  It is true that it is
> difficult to use them as input/output registers.

Of course they can be accessed directly, but that tends to produce worse
code since the compiler then can't schedule the mfhi/mflo (or mthi/mtlo
on entry to the asm) around other instructions to avoid stalling.

> You should use MFHI/MFLO and to move the results to some general
> purpose registers.  Then mention "hi", "lo" in the clobbers statement
> for the inline asm.

In some cases, results in needless bouncing between hi/lo and gprs.
It's better to let the compiler decide if and when to retrieve the
values.

Moreover, using "ka" constraints lets the compiler use the additional
accumulator registers available on CPUs with the DSP ASE.

> FWIW, it seems like you are missing the clobbers in your inline asm below.

No clobbers are needed when using explicit input/output arguments.  In
fact, if hi/lo were marked as clobbered this would fail to compile as
these would then be unavailable as inputs or outputs.

Is there a compelling reason to support old assembler versions without
this syntax?  I'm not sure when this was added, but I see references to
it from 2005.

-- 
Måns Rullgård
mans@xxxxxxxxx





[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux