* enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl
[not found] <20150813061109.29409.qmail@ns.horizon.com>
@ 2015-08-13 16:28 ` Linus Torvalds
2015-08-13 18:18 ` George Spelvin
0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2015-08-13 16:28 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Aug 12, 2015 at 11:11 PM, George Spelvin <linux@horizon.com> wrote:
>
> Agreed. But some x86 code I'm working on now, I have a *lot* of
> asm("divl") calls because even do_div isn't great for 64/32->32 division.
Yeah.
I'm not convinced that "64/32->32" is all that generic, though. If
the dividend in 64-bit, there's no fundamental type-based guarantee
that things will fit.
So your case is rather special, and depends (intimately) on knowing
the actual ranges and how they interact.
That's not a generic situation like "do_div()".
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl
2015-08-13 16:28 ` enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl Linus Torvalds
@ 2015-08-13 18:18 ` George Spelvin
2015-08-13 18:26 ` Linus Torvalds
0 siblings, 1 reply; 4+ messages in thread
From: George Spelvin @ 2015-08-13 18:18 UTC (permalink / raw)
To: linux-arm-kernel
> I'm not convinced that "64/32->32" is all that generic, though. If
> the dividend in 64-bit, there's no fundamental type-based guarantee
> that things will fit.
I agree that it's impossible to decide based on the types, but having
that knowledge is extremely common. Which is why it would be nice
to have a way for the programmer to communicate that knowledge.
> So your case is rather special, and depends (intimately) on knowing
> the actual ranges and how they interact.
Actually, it's the most common case. Going through "git grep -w do_div",
by far the *majority* of all calls to do_div immediately convert the
result to 32 bits (or unsigned long), with no overflow checking.
Partially that's because I'm cointing static code frequency and there
are a ridiculous number of different PLL drivers, but still.
On x86, the case that msword >= divsor causes a divide exception
(divide ba generalization of divide by zero), so it's tempting
to do the same sort of "assume no trap and fix up in the handler"
trick as <asm/uaccess.h>.
There are only 854 references to do_div in the kernel, so
doing a sweep over all of them is quite practical.
One function that would cover a significant number of use cases
(but not all, damn it) would be
rem = do_mul_div(x, mul,_div)
Which returns x * mul / div, with a 64-bit intermediate.
^ permalink raw reply [flat|nested] 4+ messages in thread
* enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl
2015-08-13 18:18 ` George Spelvin
@ 2015-08-13 18:26 ` Linus Torvalds
2015-08-13 19:09 ` George Spelvin
0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2015-08-13 18:26 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Aug 13, 2015 at 11:18 AM, George Spelvin <linux@horizon.com> wrote:
>
> On x86, the case that msword >= divsor causes a divide exception
> (divide ba generalization of divide by zero), so it's tempting
> to do the same sort of "assume no trap and fix up in the handler"
> trick as <asm/uaccess.h>.
That would be horrible. One of the reasonably common cases of do_div()
is for printing out numbers. And they are often in the 4G+ range..
> One function that would cover a significant number of use cases
> (but not all, damn it) would be
>
> rem = do_mul_div(x, mul,_div)
Yes. That might be worth introducing. Not to replace do_div(), but as
a "32-bit only" interface to a somewhat common situation.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl
2015-08-13 18:26 ` Linus Torvalds
@ 2015-08-13 19:09 ` George Spelvin
0 siblings, 0 replies; 4+ messages in thread
From: George Spelvin @ 2015-08-13 19:09 UTC (permalink / raw)
To: linux-arm-kernel
>> On x86, the case that msword >= divsor causes a divide exception
>> (divide ba generalization of divide by zero), so it's tempting
>> to do the same sort of "assume no trap and fix up in the handler"
>> trick as <asm/uaccess.h>.
> That would be horrible. One of the reasonably common cases of do_div()
> is for printing out numbers. And they are often in the 4G+ range..
Actually, printing numbers is *not* such an instance; I've had my fingers
in lib/vsprintf.c, and since the divisor is constant, it uses reciprocal
multiplies.
The only instance of do_div in lib/vsprintf.c is in a version of put_dec()
which is used only if BITS_PER_LONG == 64. If bits_per_long == 32,
it uses a neat hack due to Douglas Jones which avoids using divide
instructions entirely!
(Commit 133fd9f5cd if you are curious.)
The hot paths with 64-bit results are in the block layer and RAID
code, and that's why I wasn't seriously suggesting replacing *all*
instances; it was more of a static code size diet hack.
(It's also not likely worth the maintenance burden of the additional
code subtlety. "Tempting" is not necessarily a good idea.)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-08-13 19:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20150813061109.29409.qmail@ns.horizon.com>
2015-08-13 16:28 ` enabling libgcc for 64-bit divisions, was Re: PROBLEM: XFS on ARM corruption 'Structure needs cl Linus Torvalds
2015-08-13 18:18 ` George Spelvin
2015-08-13 18:26 ` Linus Torvalds
2015-08-13 19:09 ` George Spelvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).