diff mbox

[4/6] powerpc/boot: Add extended precision shifts to the boot wrapper.

Message ID 1322630640-13708-5-git-send-email-tony@bakeyournoodle.com (mailing list archive)
State Accepted, archived
Commit e32a03290c72773c304ffeebffed0a63c0a672ae
Delegated to: Josh Boyer
Headers show

Commit Message

Tony Breeds Nov. 30, 2011, 5:23 a.m. UTC
Code copied from arch/powerpc/kernel/misc_32.S

Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
---
 arch/powerpc/boot/div64.S |   52 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

Comments

Benjamin Herrenschmidt Nov. 30, 2011, 5:48 a.m. UTC | #1
On Wed, 2011-11-30 at 16:23 +1100, Tony Breeds wrote:
> Code copied from arch/powerpc/kernel/misc_32.S
> 
> Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
> ---
>  arch/powerpc/boot/div64.S |   52 +++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 52 insertions(+), 0 deletions(-)

Should we just link with libgcc ? :-)

Cheers,
Ben.

> diff --git a/arch/powerpc/boot/div64.S b/arch/powerpc/boot/div64.S
> index d271ab5..bbcb8a4 100644
> --- a/arch/powerpc/boot/div64.S
> +++ b/arch/powerpc/boot/div64.S
> @@ -57,3 +57,55 @@ __div64_32:
>  	stw	r8,4(r3)
>  	mr	r3,r6		# return the remainder in r3
>  	blr
> +
> +/*
> + * Extended precision shifts.
> + *
> + * Updated to be valid for shift counts from 0 to 63 inclusive.
> + * -- Gabriel
> + *
> + * R3/R4 has 64 bit value
> + * R5    has shift count
> + * result in R3/R4
> + *
> + *  ashrdi3: arithmetic right shift (sign propagation)	
> + *  lshrdi3: logical right shift
> + *  ashldi3: left shift
> + */
> +	.globl __ashrdi3
> +__ashrdi3:
> +	subfic	r6,r5,32
> +	srw	r4,r4,r5	# LSW = count > 31 ? 0 : LSW >> count
> +	addi	r7,r5,32	# could be xori, or addi with -32
> +	slw	r6,r3,r6	# t1 = count > 31 ? 0 : MSW << (32-count)
> +	rlwinm	r8,r7,0,32	# t3 = (count < 32) ? 32 : 0
> +	sraw	r7,r3,r7	# t2 = MSW >> (count-32)
> +	or	r4,r4,r6	# LSW |= t1
> +	slw	r7,r7,r8	# t2 = (count < 32) ? 0 : t2
> +	sraw	r3,r3,r5	# MSW = MSW >> count
> +	or	r4,r4,r7	# LSW |= t2
> +	blr
> +
> +	.globl __ashldi3
> +__ashldi3:
> +	subfic	r6,r5,32
> +	slw	r3,r3,r5	# MSW = count > 31 ? 0 : MSW << count
> +	addi	r7,r5,32	# could be xori, or addi with -32
> +	srw	r6,r4,r6	# t1 = count > 31 ? 0 : LSW >> (32-count)
> +	slw	r7,r4,r7	# t2 = count < 32 ? 0 : LSW << (count-32)
> +	or	r3,r3,r6	# MSW |= t1
> +	slw	r4,r4,r5	# LSW = LSW << count
> +	or	r3,r3,r7	# MSW |= t2
> +	blr
> +
> +	.globl __lshrdi3
> +__lshrdi3:
> +	subfic	r6,r5,32
> +	srw	r4,r4,r5	# LSW = count > 31 ? 0 : LSW >> count
> +	addi	r7,r5,32	# could be xori, or addi with -32
> +	slw	r6,r3,r6	# t1 = count > 31 ? 0 : MSW << (32-count)
> +	srw	r7,r3,r7	# t2 = count < 32 ? 0 : MSW >> (count-32)
> +	or	r4,r4,r6	# LSW |= t1
> +	srw	r3,r3,r5	# MSW = MSW >> count
> +	or	r4,r4,r7	# LSW |= t2
> +	blr
Josh Boyer Nov. 30, 2011, 11:45 a.m. UTC | #2
On Wed, Nov 30, 2011 at 12:48 AM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> On Wed, 2011-11-30 at 16:23 +1100, Tony Breeds wrote:
>> Code copied from arch/powerpc/kernel/misc_32.S
>>
>> Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
>> ---
>>  arch/powerpc/boot/div64.S |   52 +++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 52 insertions(+), 0 deletions(-)
>
> Should we just link with libgcc ? :-)

Please tell me you're joking.

However, adding this code and wonderful and all but why do we need to
add it?  Changelog should say why.

josh
Benjamin Herrenschmidt Nov. 30, 2011, 8:21 p.m. UTC | #3
On Wed, 2011-11-30 at 06:45 -0500, Josh Boyer wrote:
> On Wed, Nov 30, 2011 at 12:48 AM, Benjamin Herrenschmidt
> <benh@kernel.crashing.org> wrote:
> > On Wed, 2011-11-30 at 16:23 +1100, Tony Breeds wrote:
> >> Code copied from arch/powerpc/kernel/misc_32.S
> >>
> >> Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
> >> ---
> >>  arch/powerpc/boot/div64.S |   52 +++++++++++++++++++++++++++++++++++++++++++++
> >>  1 files changed, 52 insertions(+), 0 deletions(-)
> >
> > Should we just link with libgcc ? :-)
> 
> Please tell me you're joking.

Only half... I wonder what it would look like. Wouldn't ld only pickup
what we use anyway ?

> However, adding this code and wonderful and all but why do we need to
> add it?  Changelog should say why.

Agreed.

Cheers,
Ben.
Scott Wood Nov. 30, 2011, 8:28 p.m. UTC | #4
On 11/30/2011 02:21 PM, Benjamin Herrenschmidt wrote:
> On Wed, 2011-11-30 at 06:45 -0500, Josh Boyer wrote:
>> On Wed, Nov 30, 2011 at 12:48 AM, Benjamin Herrenschmidt
>> <benh@kernel.crashing.org> wrote:
>>> On Wed, 2011-11-30 at 16:23 +1100, Tony Breeds wrote:
>>>> Code copied from arch/powerpc/kernel/misc_32.S
>>>>
>>>> Signed-off-by: Tony Breeds <tony@bakeyournoodle.com>
>>>> ---
>>>>  arch/powerpc/boot/div64.S |   52 +++++++++++++++++++++++++++++++++++++++++++++
>>>>  1 files changed, 52 insertions(+), 0 deletions(-)
>>>
>>> Should we just link with libgcc ? :-)
>>
>> Please tell me you're joking.
> 
> Only half... I wonder what it would look like. Wouldn't ld only pickup
> what we use anyway ?

We do it in U-Boot...

Only problem I see is that it would need to be built as soft-float, and
apparently that isn't supported by gcc on 64-bit ppc.  Unfortunately
there's isn't a "no float" mode.

-Scott
Tony Breeds Nov. 30, 2011, 11:25 p.m. UTC | #5
On Wed, Nov 30, 2011 at 06:45:37AM -0500, Josh Boyer wrote:

> However, adding this code and wonderful and all but why do we need to
> add it?  Changelog should say why.

Okay changelog updated to:

    powerpc/boot: Add extended precision shifts to the boot wrapper.
    
    The upcoming currituck patches will need to do 64-bit shifts which will
    fail with undefined symbol without this patch.
    
    I looked at linking against libgcc but we can't guarantee that libgcc
    was compiled with soft-float.  Also Using ../lib/div64.S or
    ../kernel/misc_32.S, this will break the build as the .o's need to be
    built with different flags for the bootwrapper vs the kernel.  So for
    now the easiest option is to just copy code from
    arch/powerpc/kernel/misc_32.S  I don't think this code changes too often ;P

Yours Tony
diff mbox

Patch

diff --git a/arch/powerpc/boot/div64.S b/arch/powerpc/boot/div64.S
index d271ab5..bbcb8a4 100644
--- a/arch/powerpc/boot/div64.S
+++ b/arch/powerpc/boot/div64.S
@@ -57,3 +57,55 @@  __div64_32:
 	stw	r8,4(r3)
 	mr	r3,r6		# return the remainder in r3
 	blr
+
+/*
+ * Extended precision shifts.
+ *
+ * Updated to be valid for shift counts from 0 to 63 inclusive.
+ * -- Gabriel
+ *
+ * R3/R4 has 64 bit value
+ * R5    has shift count
+ * result in R3/R4
+ *
+ *  ashrdi3: arithmetic right shift (sign propagation)	
+ *  lshrdi3: logical right shift
+ *  ashldi3: left shift
+ */
+	.globl __ashrdi3
+__ashrdi3:
+	subfic	r6,r5,32
+	srw	r4,r4,r5	# LSW = count > 31 ? 0 : LSW >> count
+	addi	r7,r5,32	# could be xori, or addi with -32
+	slw	r6,r3,r6	# t1 = count > 31 ? 0 : MSW << (32-count)
+	rlwinm	r8,r7,0,32	# t3 = (count < 32) ? 32 : 0
+	sraw	r7,r3,r7	# t2 = MSW >> (count-32)
+	or	r4,r4,r6	# LSW |= t1
+	slw	r7,r7,r8	# t2 = (count < 32) ? 0 : t2
+	sraw	r3,r3,r5	# MSW = MSW >> count
+	or	r4,r4,r7	# LSW |= t2
+	blr
+
+	.globl __ashldi3
+__ashldi3:
+	subfic	r6,r5,32
+	slw	r3,r3,r5	# MSW = count > 31 ? 0 : MSW << count
+	addi	r7,r5,32	# could be xori, or addi with -32
+	srw	r6,r4,r6	# t1 = count > 31 ? 0 : LSW >> (32-count)
+	slw	r7,r4,r7	# t2 = count < 32 ? 0 : LSW << (count-32)
+	or	r3,r3,r6	# MSW |= t1
+	slw	r4,r4,r5	# LSW = LSW << count
+	or	r3,r3,r7	# MSW |= t2
+	blr
+
+	.globl __lshrdi3
+__lshrdi3:
+	subfic	r6,r5,32
+	srw	r4,r4,r5	# LSW = count > 31 ? 0 : LSW >> count
+	addi	r7,r5,32	# could be xori, or addi with -32
+	slw	r6,r3,r6	# t1 = count > 31 ? 0 : MSW << (32-count)
+	srw	r7,r3,r7	# t2 = count < 32 ? 0 : MSW >> (count-32)
+	or	r4,r4,r6	# LSW |= t1
+	srw	r3,r3,r5	# MSW = MSW >> count
+	or	r4,r4,r7	# LSW |= t2
+	blr