Skip to contentSkip to conversation

powerpc: provide __bswapdi2

PATCH In review David Woodhouse 8 participants 18 messages May 10, 2013 – May 14, 2013 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: provide __bswapdi2

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

---
Untested.

arch/powerpc/kernel/misc_32.S +11 -0
index 19e096b..f077dc2 100644
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)
+	rlwinm	10,4,8,0xffffffff
+	rlwinm	11,3,8,0xffffffff
+	rlwimi	10,4,24,0,7
+	rlwimi	11,3,24,0,7
+	rlwimi	10,4,24,16,23
+	rlwimi	11,3,24,16,23
+	mr	4,11
+	mr	3,10
+	blr
+
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
arch/powerpc/kernel/misc_64.S +12 -0
index 5cfa800..3b2e6e8 100644
@@ -234,6 +234,18 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
+_GLOBAL(__bswapdi2)
+	srdi	8,3,32
+	rlwinm	7,3,8,0xffffffff
+	rlwimi	7,3,24,0,7
+	rlwinm	9,8,8,0xffffffff
+	rlwimi	7,3,24,16,23
+	rlwimi	9,8,24,0,7
+	rlwimi	9,8,24,16,23
+	sldi	7,7,32
+	or	7,7,9
+	mr	3,7
+	blr
 
 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
 /*
arch/powerpc/kernel/ppc_ksyms.c +2 -1
index 78b8766..c296665 100644
@@ -143,7 +143,8 @@ EXPORT_SYMBOL(__lshrdi3);
 int __ucmpdi2(unsigned long long, unsigned long long);
 EXPORT_SYMBOL(__ucmpdi2);
 #endif
-
+long long __bswapdi2(long long);
+EXPORT_SYMBOL(__bswapdi2);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
Signature · 1 line
dwmw2
#1 lore raw
Quoted 3 lines · On Fri, 10 May 2013 22:18:27 +0100 David Woodhouse <[email protected]> wrote:

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

Thanks Dave. We were discussing this with Alan Modra and he doesn't think the 64bit target should ever emit a call to __bswapdi2. Did you only see it on 32bit, or 64bit as well?

Alan: I notice Dave is adding calls to __builtin_bswap, perhaps some versions of the 64bit compiler did emit __bswapdi2 calls for that.

Anton

Quoted 65 lines

---
Untested.

(quoted diff) +0 -0

b/arch/powerpc/kernel/misc_32.S index 19e096b..f077dc2 100644

arch/powerpc/kernel/misc_32.S +11 -0
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)
+	rlwinm	10,4,8,0xffffffff
+	rlwinm	11,3,8,0xffffffff
+	rlwimi	10,4,24,0,7
+	rlwimi	11,3,24,0,7
+	rlwimi	10,4,24,16,23
+	rlwimi	11,3,24,16,23
+	mr	4,11
+	mr	3,10
+	blr
+
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
(quoted diff) +0 -0

b/arch/powerpc/kernel/misc_64.S index 5cfa800..3b2e6e8 100644

arch/powerpc/kernel/misc_64.S +12 -0
@@ -234,6 +234,18 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
+_GLOBAL(__bswapdi2)
+	srdi	8,3,32
+	rlwinm	7,3,8,0xffffffff
+	rlwimi	7,3,24,0,7
+	rlwinm	9,8,8,0xffffffff
+	rlwimi	7,3,24,16,23
+	rlwimi	9,8,24,0,7
+	rlwimi	9,8,24,16,23
+	sldi	7,7,32
+	or	7,7,9
+	mr	3,7
+	blr
 
 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
 /*
(quoted diff) +0 -0

b/arch/powerpc/kernel/ppc_ksyms.c index 78b8766..c296665 100644

arch/powerpc/kernel/ppc_ksyms.c +2 -1
@@ -143,7 +143,8 @@ EXPORT_SYMBOL(__lshrdi3);
 int __ucmpdi2(unsigned long long, unsigned long long);
 EXPORT_SYMBOL(__ucmpdi2);
 #endif
-
+long long __bswapdi2(long long);
+EXPORT_SYMBOL(__bswapdi2);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
#2 lore raw
Quoted 5 lines · Anton Blanchard
Quoted 2 lines · On Fri, 10 May 2013 22:18:27 +0100 David Woodhouse <[email protected]> wrote:

From: David Woodhouse <[email protected]>

Quoted 8 lines
Quoted 1 line

Some versions of GCC apparently expect this to be provided by libgcc.

Thanks Dave. We were discussing this with Alan Modra and he doesn't think the 64bit target should ever emit a call to __bswapdi2. Did you only see it on 32bit, or 64bit as well?

Alan: I notice Dave is adding calls to __builtin_bswap, perhaps some versions of the 64bit compiler did emit __bswapdi2 calls for that.

I did a little digging, and it looks like gcc-4.4 will emit __bswapdi2 calls. Support in rs6000.md appeared 2009-06-25.

Signature · 2 lines
Alan Modra
Australia Development Lab, IBM
#3 lore raw
Quoted 2 lines · Alan Modra

I did a little digging, and it looks like gcc-4.4 will emit __bswapdi2 calls. Support in rs6000.md appeared 2009-06-25.

That's where it was seen. I don't have anything that ancient any more so it didn't show up in my testing, but Al saw it on a Debian system.

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#4 lore raw
Quoted 5 lines
Quoted 2 lines

I did a little digging, and it looks like gcc-4.4 will emit __bswapdi2 calls. Support in rs6000.md appeared 2009-06-25.

That's where it was seen. I don't have anything that ancient any more so it didn't show up in my testing, but Al saw it on a Debian system.

It should never happen on 32-bit -- it is broken into two bswapsi's -- although, old compiler, who knows. Lack of testing makes some people nervous though ;-)

Segher

#5 lore raw
In reply to David Woodhouse
Quoted 17 lines · David Woodhouse

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

---
Untested.

arch/powerpc/kernel/misc_32.S +1 -0
index 19e096b..f077dc2 100644
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)

arch/powerpc/kernel/misc_32.S _GLOBAL(__ucmpdi2) · line 670

Quoted 10 lines
arch/powerpc/kernel/misc_32.S +10 -0
+	rlwinm	10,4,8,0xffffffff
+	rlwinm	11,3,8,0xffffffff
+	rlwimi	10,4,24,0,7
+	rlwimi	11,3,24,0,7
+	rlwimi	10,4,24,16,23
+	rlwimi	11,3,24,16,23
+	mr	4,11
+	mr	3,10
+	blr
+

This doesn't work for me but the below does:

_GLOBAL(__bswapdi2)

	rotlwi  r9,r4,8
	rotlwi  r10,r3,8
	rlwimi  r9,r4,24,0,7
	rlwimi  r10,r3,24,0,7
	rlwimi  r9,r4,24,16,23
	rlwimi  r10,r3,24,16,23
	mr      r4,r10
	mr      r3,r9

blr

stolen from GCC -02 output of:
unsigned long long __bswapdi2(unsigned long long x)

  {
	 return ((x & 0x00000000000000ffULL) << 56) |
		((x & 0x000000000000ff00ULL) << 40) |
		((x & 0x0000000000ff0000ULL) << 24) |
		((x & 0x00000000ff000000ULL) <<  8) |
		((x & 0x000000ff00000000ULL) >>  8) |
		((x & 0x0000ff0000000000ULL) >> 24) |
		((x & 0x00ff000000000000ULL) >> 40) |
		((x & 0xff00000000000000ULL) >> 56);

}

Quoted 13 lines
arch/powerpc/kernel/misc_32.S +0 -0
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
arch/powerpc/kernel/misc_64.S +2 -0
index 5cfa800..3b2e6e8 100644
@@ -234,6 +234,18 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
+_GLOBAL(__bswapdi2)
+	srdi	8,3,32

arch/powerpc/kernel/misc_64.S _GLOBAL(__flush_dcache_icache) · line 248

Quoted 10 lines
arch/powerpc/kernel/misc_64.S +10 -0
+	rlwinm	7,3,8,0xffffffff
+	rlwimi	7,3,24,0,7
+	rlwinm	9,8,8,0xffffffff
+	rlwimi	7,3,24,16,23
+	rlwimi	9,8,24,0,7
+	rlwimi	9,8,24,16,23
+	sldi	7,7,32
+	or	7,7,9
+	mr	3,7
+	blr

This works but we should add "r" to the register names.

I'll repost

Mikey

Quoted 25 lines
arch/powerpc/kernel/misc_64.S +0 -0
 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
 /*
arch/powerpc/kernel/ppc_ksyms.c +2 -1
index 78b8766..c296665 100644
@@ -143,7 +143,8 @@ EXPORT_SYMBOL(__lshrdi3);
 int __ucmpdi2(unsigned long long, unsigned long long);
 EXPORT_SYMBOL(__ucmpdi2);
 #endif
-
+long long __bswapdi2(long long);
+EXPORT_SYMBOL(__bswapdi2);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
Signature · 7 lines
-- 
dwmw2

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
#6 lore raw

PATCH v2 1/1 powerpc: provide __bswapdi2

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

Updates from Mikey to fix 32 bit version and adding "r" to registers.

arch/powerpc/kernel/misc_32.S +11 -0
index 19e096b..3bcaa7ee 100644
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)
+	rotlwi  r9,r4,8
+	rotlwi  r10,r3,8
+	rlwimi  r9,r4,24,0,7
+	rlwimi  r10,r3,24,0,7
+	rlwimi  r9,r4,24,16,23
+	rlwimi  r10,r3,24,16,23
+	mr      r4,r10
+	mr      r3,r9
+	blr
+
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
arch/powerpc/kernel/misc_64.S +12 -0
index 5cfa800..637bd82 100644
@@ -234,6 +234,18 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
+_GLOBAL(__bswapdi2)
+	srdi	r8,r3,32
+	rlwinm	r7,r3,8,0xffffffff
+	rlwimi	r7,r3,24,0,7
+	rlwinm	r9,r8,8,0xffffffff
+	rlwimi	r7,r3,24,16,23
+	rlwimi	r9,r8,24,0,7
+	rlwimi	r9,r8,24,16,23
+	sldi	r7,r7,32
+	or	r7,r7,r9
+	mr	r3,r7
+	blr
 
 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
 /*
arch/powerpc/kernel/ppc_ksyms.c +2 -1
index 78b8766..c296665 100644
@@ -143,7 +143,8 @@ EXPORT_SYMBOL(__lshrdi3);
 int __ucmpdi2(unsigned long long, unsigned long long);
 EXPORT_SYMBOL(__ucmpdi2);
 #endif
-
+long long __bswapdi2(long long);
+EXPORT_SYMBOL(__bswapdi2);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
#7 lore raw
In reply to Michael Neuling
Quoted 41 lines · Michael Neuling
Quoted 17 lines · David Woodhouse

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

---
Untested.

arch/powerpc/kernel/misc_32.S +1 -0
index 19e096b..f077dc2 100644
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)

arch/powerpc/kernel/misc_32.S _GLOBAL(__ucmpdi2) · line 670

Quoted 10 lines
arch/powerpc/kernel/misc_32.S +10 -0
+	rlwinm	10,4,8,0xffffffff
+	rlwinm	11,3,8,0xffffffff
+	rlwimi	10,4,24,0,7
+	rlwimi	11,3,24,0,7
+	rlwimi	10,4,24,16,23
+	rlwimi	11,3,24,16,23
+	mr	4,11
+	mr	3,10
+	blr
+

This doesn't work for me but the below does:

_GLOBAL(__bswapdi2)

	rotlwi  r9,r4,8
	rotlwi  r10,r3,8
	rlwimi  r9,r4,24,0,7
	rlwimi  r10,r3,24,0,7
	rlwimi  r9,r4,24,16,23
	rlwimi  r10,r3,24,16,23
	mr      r4,r10
	mr      r3,r9
Quoted 2 lines

blr

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Quoted 24 lines

stolen from GCC -02 output of:
unsigned long long __bswapdi2(unsigned long long x)

  {
	 return ((x & 0x00000000000000ffULL) << 56) |
		((x & 0x000000000000ff00ULL) << 40) |
		((x & 0x0000000000ff0000ULL) << 24) |
		((x & 0x00000000ff000000ULL) <<  8) |
		((x & 0x000000ff00000000ULL) >>  8) |
		((x & 0x0000ff0000000000ULL) >> 24) |
		((x & 0x00ff000000000000ULL) >> 40) |
		((x & 0xff00000000000000ULL) >> 56);

}

Quoted 11 lines
arch/powerpc/kernel/misc_32.S +0 -0
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
arch/powerpc/kernel/misc_64.S +0 -0
index 5cfa800..3b2e6e8 100644
@@ -234,6 +234,18 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
Quoted 15 lines

arch/powerpc/kernel/misc_64.S _GLOBAL(__flush_dcache_icache) · line 248

Quoted 12 lines
arch/powerpc/kernel/misc_64.S +12 -0
+_GLOBAL(__bswapdi2)
+	srdi	8,3,32
+	rlwinm	7,3,8,0xffffffff
+	rlwimi	7,3,24,0,7
+	rlwinm	9,8,8,0xffffffff
+	rlwimi	7,3,24,16,23
+	rlwimi	9,8,24,0,7
+	rlwimi	9,8,24,16,23
+	sldi	7,7,32
+	or	7,7,9
+	mr	3,7
+	blr

This works but we should add "r" to the register names.

And merge the last two instructions as a single "or r3,r7,r9".

Gabriel

#8 lore raw

PATCH v3 1/1 powerpc: provide __bswapdi2

From: David Woodhouse <[email protected]>

Some versions of GCC apparently expect this to be provided by libgcc.

Updates from Mikey to fix 32 bit version and adding "r" to registers.

---
Fixes from Gabriel.

 arch/powerpc/kernel/misc_32.S   |   11 +++++++++++
 arch/powerpc/kernel/misc_64.S   |   11 +++++++++++
 arch/powerpc/kernel/ppc_ksyms.c |    3 ++-
 3 files changed, 24 insertions(+), 1 deletion(-)
arch/powerpc/kernel/misc_32.S +11 -0
index 19e096b..e469f30 100644
@@ -657,6 +657,17 @@ _GLOBAL(__ucmpdi2)
 	li	r3,2
 	blr
 
+_GLOBAL(__bswapdi2)
+	rotlwi  r9,r4,8
+	rotlwi  r10,r3,8
+	rlwimi  r9,r4,24,0,7
+	rlwimi  r10,r3,24,0,7
+	rlwimi  r9,r4,24,16,23
+	rlwimi  r10,r3,24,16,23
+	mr      r3,r9
+	mr      r4,r10
+	blr
+
 _GLOBAL(abs)
 	srawi	r4,r3,31
 	xor	r3,r3,r4
arch/powerpc/kernel/misc_64.S +11 -0
index 5cfa800..6820e45 100644
@@ -234,6 +234,17 @@ _GLOBAL(__flush_dcache_icache)
 	isync
 	blr
 
+_GLOBAL(__bswapdi2)
+	srdi	r8,r3,32
+	rlwinm	r7,r3,8,0xffffffff
+	rlwimi	r7,r3,24,0,7
+	rlwinm	r9,r8,8,0xffffffff
+	rlwimi	r7,r3,24,16,23
+	rlwimi	r9,r8,24,0,7
+	rlwimi	r9,r8,24,16,23
+	sldi	r7,r7,32
+	or	r3,r7,r9
+	blr
 
 #if defined(CONFIG_PPC_PMAC) || defined(CONFIG_PPC_MAPLE)
 /*
arch/powerpc/kernel/ppc_ksyms.c +2 -1
index 78b8766..c296665 100644
@@ -143,7 +143,8 @@ EXPORT_SYMBOL(__lshrdi3);
 int __ucmpdi2(unsigned long long, unsigned long long);
 EXPORT_SYMBOL(__ucmpdi2);
 #endif
-
+long long __bswapdi2(long long);
+EXPORT_SYMBOL(__bswapdi2);
 EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memmove);
Signature · 1 line
1.7.10.4
#9 lore raw
In reply to Michael Neuling
Quoted 2 lines · Michael Neuling

This doesn't work for me but the below does:

...

Quoted 3 lines

stolen from GCC -02 output of:
unsigned long long __bswapdi2(unsigned long long x)

Hm, so was mine:

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

	.file	"bswapdi2.c"
	.section	".text"
	.align 2
	.p2align 4,,15
	.globl __bswapdi2
	.type	__bswapdi2, @function
__bswapdi2:
	rlwinm 10,4,8,0xffffffff
	rlwinm 11,3,8,0xffffffff
	rlwimi 10,4,24,0,7
	rlwimi 11,3,24,0,7
	rlwimi 10,4,24,16,23
	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
	blr
	.size	__bswapdi2,.-__bswapdi2
	.ident	"GCC: (GNU) 4.7.2 20121105 (Red Hat 4.7.2-2.aa.20121114svn)"
Quoted 3 lines · Gabriel Paubert

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Bad GCC. No biscuit.

Should we file a PR?

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#10 lore raw
Quoted 9 lines · David Woodhouse
Quoted 3 lines · Gabriel Paubert

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Bad GCC. No biscuit.

Should we file a PR?

Maybe not. If you tell it to tune for an in-order machine like Cell, it swaps them round. Although now I'm confused about which of POWER[567] were in-order:

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 | grep -B1 mr

	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=cell | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 3,10
	mr 4,11
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power5 | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 3,10
	mr 4,11
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power6 | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power7 | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#11 lore raw

"Linuxppc-dev" <linuxppc-dev-bounces+joakim.tjernlund=transmode.se@lists.ozlabs.org> wrote 2013/05/13 12:38:13:

Quoted 10 lines · David Woodhouse
Quoted 8 lines · Gabriel Paubert
Quoted 3 lines

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Bad GCC. No biscuit.

Quoted 7 lines
Quoted 1 line

Should we file a PR?

Maybe not. If you tell it to tune for an in-order machine like Cell, it swaps them round. Although now I'm confused about which of POWER[567] were in-order:

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 | grep

-B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=cell | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 3,10
   mr 4,11

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power5 | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 3,10
   mr 4,11

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power6 | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power7 | grep -B1 mr

Quoted 3 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10

A bit rusty on the ppc asm but can you not remove the mr completely:

                 rlwimi 10,4,24,16,23
                 rlwimi 11,3,24,16,23
                 mr 4,11
                 mr 3,10
to
                 rlwimi 4,4,24,16,23
                 rlwimi 3,3,24,16,23

Jocke

#12 lore raw

"Linuxppc-dev" <linuxppc-dev-bounces+joakim.tjernlund=transmode.se@lists.ozlabs.org> wrote on 2013/05/13 12:51:59:

Quoted 17 lines

"Linuxppc-dev" <linuxppc-dev-bounces+joakim.tjernlund=transmode.se@lists.ozlabs.org> wrote 2013/05/13 12:38:13:

Quoted 13 lines · David Woodhouse
Quoted 9 lines · Gabriel Paubert
Quoted 3 lines

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Bad GCC. No biscuit.

Should we file a PR?

Maybe not. If you tell it to tune for an in-order machine like Cell,

it

Quoted 4 lines
Quoted 4 lines

swaps them round. Although now I'm confused about which of POWER[567] were in-order:

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 |

grep

Quoted 25 lines

-B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=cell | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 3,10
   mr 4,11

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power5 | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 3,10
   mr 4,11

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power6 | grep -B1 mr

Quoted 4 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32

-mtune=power7 | grep -B1 mr

Quoted 3 lines
   rlwimi 11,3,24,16,23
   mr 4,11
   mr 3,10
Quoted 8 lines

A bit rusty on the ppc asm but can you not remove the mr completely:

                 rlwimi 10,4,24,16,23
                 rlwimi 11,3,24,16,23
                 mr 4,11
                 mr 3,10
to
                 rlwimi 4,4,24,16,23
                 rlwimi 3,3,24,16,23

Oops, that got twisted. Forget my comment.

#13 lore raw
In reply to David Woodhouse
Quoted 7 lines · David Woodhouse
Quoted 6 lines · David Woodhouse
Quoted 3 lines · Gabriel Paubert

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Quoted 7 lines
Quoted 3 lines

Bad GCC. No biscuit.

Should we file a PR?

Maybe not. If you tell it to tune for an in-order machine like Cell, it swaps them round. Although now I'm confused about which of POWER[567] were in-order:

It was Power6 IIRC. On this kind of fine point, don't rely too much on what GCC produces.

Quoted 13 lines

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 | grep -B1 mr

	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=cell | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 3,10
	mr 4,11
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power5 | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 3,10
	mr 4,11
Quoted 8 lines

[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power6 | grep -B1 mr

	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
[dwmw2@i7 ~]$ powerpc64-linux-gnu-gcc -O2 -S -o- bswapdi2.c -m32 -mtune=power7 | grep -B1 mr
	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10

I don't know of any processor in which putting the mr 3,10 first can cause stalls, so even a generic tuning should put it first.

Gabriel

#14 lore raw
In reply to David Woodhouse
Quoted 9 lines
	rlwinm 10,4,8,0xffffffff
	rlwinm 11,3,8,0xffffffff
	rlwimi 10,4,24,0,7
	rlwimi 11,3,24,0,7
	rlwimi 10,4,24,16,23
	rlwimi 11,3,24,16,23
	mr 4,11
	mr 3,10
Quoted 7 lines
Quoted 3 lines

Actually, I'd swap the two mr instructions to never have an instruction that uses the result from the previous one.

Bad GCC. No biscuit.

Should we file a PR?

This is scheduled just fine. Every pair of instructions here can execute together (on most CPUs, if not all); all instructions after it are dependent on previous instructions. There also is no issue (group) restriction that makes this scheduling suboptimal afaics.

Segher

#15 lore raw
In reply to Michael Neuling

Hi Mikey,

Quoted 25 lines · On Mon, 13 May 2013 17:09:59 +1000 Michael Neuling <[email protected]> wrote:

This doesn't work for me but the below does:

_GLOBAL(__bswapdi2)

	rotlwi  r9,r4,8
	rotlwi  r10,r3,8
	rlwimi  r9,r4,24,0,7
	rlwimi  r10,r3,24,0,7
	rlwimi  r9,r4,24,16,23
	rlwimi  r10,r3,24,16,23
	mr      r4,r10
	mr      r3,r9

blr

stolen from GCC -02 output of:
unsigned long long __bswapdi2(unsigned long long x)

  {
	 return ((x & 0x00000000000000ffULL) << 56) |
		((x & 0x000000000000ff00ULL) << 40) |
		((x & 0x0000000000ff0000ULL) << 24) |
		((x & 0x00000000ff000000ULL) <<  8) |
		((x & 0x000000ff00000000ULL) >>  8) |
		((x & 0x0000ff0000000000ULL) >> 24) |
		((x & 0x00ff000000000000ULL) >> 40) |
		((x & 0xff00000000000000ULL) >> 56);
Quoted 1 line

}

So, if we are just stealing the output of gcc, why not just use the C version (at least for 32 bit)?

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
#16 lore raw
Quoted 4 lines · Stephen Rothwell

Hi Mikey,

On Mon, 13 May 2013 17:09:59 +1000 Michael Neuling <[email protected]>

Quoted 27 lines · wrote:
Quoted 25 lines

This doesn't work for me but the below does:

_GLOBAL(__bswapdi2)

      rotlwi  r9,r4,8
      rotlwi  r10,r3,8
      rlwimi  r9,r4,24,0,7
      rlwimi  r10,r3,24,0,7
      rlwimi  r9,r4,24,16,23
      rlwimi  r10,r3,24,16,23
      mr      r4,r10
      mr      r3,r9

blr

stolen from GCC -02 output of:
unsigned long long __bswapdi2(unsigned long long x)

  {
       return ((x & 0x00000000000000ffULL) << 56) |
              ((x & 0x000000000000ff00ULL) << 40) |
              ((x & 0x0000000000ff0000ULL) << 24) |
              ((x & 0x00000000ff000000ULL) <<  8) |
              ((x & 0x000000ff00000000ULL) >>  8) |
              ((x & 0x0000ff0000000000ULL) >> 24) |
              ((x & 0x00ff000000000000ULL) >> 40) |
              ((x & 0xff00000000000000ULL) >> 56);
Quoted 1 line

}

Quoted 2 lines

So, if we are just stealing the output of gcc, why not just use the C version (at least for 32 bit)?

Woodhouse: can we just do this?

Mikey

#17 lore raw
Quoted 5 lines · Michael Neuling
Quoted 3 lines

So, if we are just stealing the output of gcc, why not just use the C version (at least for 32 bit)?

Woodhouse: can we just do this?

Sure, if you don't mind GCC optimising the contents of your C function by turning it into a call to libgcc's __bswapdi2() :)

OK, you might be able to do some archaeology and determine that the only compiler that emits calls to __bswapdi2() is GCC 4.4, and furthermore that the same compiler *doesn't* have the wit to notice that the contents of the function are a 64-bit byteswap, so it's never going to happen. But I don't like that approach. I'd feel I have to sacrifice a goat *anyway*, and I don't have a spare goat.

Although now I come to explicitly explain why I did it that way... it occurs to me that the libgcc version is just written in C, and the compiler evidently trusts itself not to optimise that into a recursive call. Is there a compiler switch which guarantees that, which we could use without other unwanted side-effects?

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation