Skip to contentSkip to conversation

ASoC: prevent compilers from optimising pll calculation into __aeabi__uldivmod

PATCH In review Barry Song 6 participants 13 messages Apr 27, 2011 – Apr 28, 2011 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH 1/1 ASoC: prevent compilers from optimising pll calculation into __aeabi__uldivmod

From: Barry Song <[email protected]>

The newest compiliers can optimize pll calculation in several codecs into __aeabi__uldivmod which doesn't exist in kernel. Then the link will fail:
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8940.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8510.ko] undefined!
This patch prevent the optimizaton by insert ASM.

Cc Zhiwu Song <[email protected]>
Cc Binghua Duan <[email protected]>
---
 sound/soc/codecs/wm8510.c |    6 ++++++
 sound/soc/codecs/wm8940.c |    6 ++++++
 sound/soc/codecs/wm8974.c |    6 ++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
sound/soc/codecs/wm8510.c +6 -0
index db0dced..a636b15 100644
@@ -258,6 +258,12 @@ static void pll_factors(unsigned int target, unsigned int source)
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8940.c +6 -0
index 25580e3..f6148af 100644
@@ -520,6 +520,12 @@ static void pll_factors(unsigned int target, unsigned int source)
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8974.c +6 -0
index ca646a8..c9036d9 100644
@@ -317,6 +317,12 @@ static void pll_factors(struct pll_ *pll_div,
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
Signature · 5 lines
1.7.1



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
#1 lore raw

At Wed, 27 Apr 2011 00:27:32 -0700,

Quoted 9 lines · Barry Song

From: Barry Song <[email protected]>

The newest compiliers can optimize pll calculation in several codecs into __aeabi__uldivmod which doesn't exist in kernel. Then the link will fail:
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8940.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8510.ko] undefined!
This patch prevent the optimizaton by insert ASM.

Don't do this in the low driver level. If any, we should fix do_div() instead.

thanks,

Takashi

Quoted 72 lines
Cc Zhiwu Song <[email protected]>
Cc Binghua Duan <[email protected]>
---
 sound/soc/codecs/wm8510.c |    6 ++++++
 sound/soc/codecs/wm8940.c |    6 ++++++
 sound/soc/codecs/wm8974.c |    6 ++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
sound/soc/codecs/wm8510.c +6 -0
index db0dced..a636b15 100644
@@ -258,6 +258,12 @@ static void pll_factors(unsigned int target, unsigned int source)
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8940.c +6 -0
index 25580e3..f6148af 100644
@@ -520,6 +520,12 @@ static void pll_factors(unsigned int target, unsigned int source)
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8974.c +6 -0
index ca646a8..c9036d9 100644
@@ -317,6 +317,12 @@ static void pll_factors(struct pll_ *pll_div,
 	Nmod = target % source;
 	Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+	/*
+	 * The following asm() prevents the compiler from optimising
+	 * into a standard EABI function __aeabi__uldivmod()
+	 */
+	asm("" : "+r"(source));
+
 	do_div(Kpart, source);
 
 	K = Kpart & 0xFFFFFFFF;
Signature · 9 lines
1.7.1



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#2 lore raw

2011/4/27 Takashi Iwai <[email protected]>:

Quoted 12 lines

At Wed, 27 Apr 2011 00:27:32 -0700,

Quoted 9 lines · Barry Song

From: Barry Song <[email protected]>

The newest compiliers can optimize pll calculation in several codecs into __aeabi__uldivmod which doesn't exist in kernel. Then the link will fail:
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8940.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8510.ko] undefined!
This patch prevent the optimizaton by insert ASM.

Quoted 2 lines

Don't do this in the low driver level.  If any, we should fix do_div() instead.

do_div is just a macro, it has no problem by itself. only while working together with other more codes before do_div, gcc can make some codes merging and cause problems.

if do_div is a function, we'd just fix it.

Quoted 72 lines

thanks,

Takashi

Quoted 66 lines
Cc Zhiwu Song <[email protected]>
Cc Binghua Duan <[email protected]>

---

 sound/soc/codecs/wm8510.c |    6 ++++++
 sound/soc/codecs/wm8940.c |    6 ++++++
 sound/soc/codecs/wm8974.c |    6 ++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
sound/soc/codecs/wm8510.c +6 -0
index db0dced..a636b15 100644
@@ -258,6 +258,12 @@ static void pll_factors(unsigned int target, unsigned int source)
       Nmod = target % source;
       Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+     /*
+      * The following asm() prevents the compiler from optimising
+      * into a standard EABI function __aeabi__uldivmod()
+      */
+     asm("" : "+r"(source));
+
       do_div(Kpart, source);
 
       K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8940.c +6 -0
index 25580e3..f6148af 100644
@@ -520,6 +520,12 @@ static void pll_factors(unsigned int target, unsigned int source)
       Nmod = target % source;
       Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+     /*
+      * The following asm() prevents the compiler from optimising
+      * into a standard EABI function __aeabi__uldivmod()
+      */
+     asm("" : "+r"(source));
+
       do_div(Kpart, source);
 
       K = Kpart & 0xFFFFFFFF;
sound/soc/codecs/wm8974.c +6 -1
index ca646a8..c9036d9 100644
@@ -317,6 +317,12 @@ static void pll_factors(struct pll_ *pll_div,
       Nmod = target % source;
       Kpart = FIXED_PLL_SIZE * (long long)Nmod;
 
+     /*
+      * The following asm() prevents the compiler from optimising
+      * into a standard EABI function __aeabi__uldivmod()
+      */
+     asm("" : "+r"(source));
+
       do_div(Kpart, source);
 
       K = Kpart & 0xFFFFFFFF;
--

1.7.1

Quoted 7 lines
Quoted 6 lines

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

At Wed, 27 Apr 2011 16:24:44 +0800,

Quoted 14 lines · Barry Song

2011/4/27 Takashi Iwai <[email protected]>:

Quoted 12 lines

At Wed, 27 Apr 2011 00:27:32 -0700,

Quoted 9 lines · Barry Song

From: Barry Song <[email protected]>

The newest compiliers can optimize pll calculation in several codecs into __aeabi__uldivmod which doesn't exist in kernel. Then the link will fail:
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8940.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8510.ko] undefined!
This patch prevent the optimizaton by insert ASM.

Quoted 4 lines
Quoted 2 lines

Don't do this in the low driver level.  If any, we should fix do_div() instead.

do_div is just a macro, it has no problem by itself.

It has a problem by itself because it's a macro with a side-effect :)

Could we put an asm to do_div() itself? The asm statement can be defined depending on the compiler version.

Quoted 5 lines

only while
working together with other more codes before do_div, gcc can make some codes merging and cause problems.

if do_div is a function, we'd just fix it.

Better to ask this in LKML, then.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw

2011/4/27 Takashi Iwai <[email protected]>:

Quoted 26 lines

At Wed, 27 Apr 2011 16:24:44 +0800,

Quoted 14 lines · Barry Song

2011/4/27 Takashi Iwai <[email protected]>:

Quoted 12 lines

At Wed, 27 Apr 2011 00:27:32 -0700,

Quoted 9 lines · Barry Song

From: Barry Song <[email protected]>

The newest compiliers can optimize pll calculation in several codecs into __aeabi__uldivmod which doesn't exist in kernel. Then the link will fail:
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8940.ko] undefined!
ERROR: "__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8510.ko] undefined!
This patch prevent the optimizaton by insert ASM.

Quoted 4 lines
Quoted 2 lines

Don't do this in the low driver level.  If any, we should fix do_div() instead.

do_div is just a macro, it has no problem by itself.

It has a problem by itself because it's a macro with a side-effect :)

Could we put an asm to do_div() itself?  The asm statement can be defined depending on the compiler version.

Quoted 7 lines
Quoted 5 lines

only while
working together with other more codes before do_div, gcc can make some codes merging and cause problems.

if do_div is a function, we'd just fix it.

Better to ask this in LKML, then.

I must have been delaying a little from gcc. Michael Hope has thought it as a gcc bug on 26 April,2011at:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

Marking pll_factors() as noinline or putting asm("" : "+r"(source)); before the call to do_div() works around the problem.

Quoted 6 lines

thanks,

Takashi

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw
Quoted 2 lines · Barry Song

Marking pll_factors() as noinline or putting asm("" : "+r"(source)); before the call to do_div() works around the problem.

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

A message that is not in the archive (sent off-list or not yet received): 20110427143002.GC31952-yzvPICuk2AATkU/[email protected]

#7 lore raw

2011/4/27 Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>

Quoted 9 lines · Barry Song
Quoted 3 lines

Marking pll_factors() as noinline or putting asm("" : "+r"(source)); before the call to do_div() works around the problem.

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

I agree. for this patch which will not be applied, people can just get information about how to workaround the gcc issue while they have the same problem. google can find there are other people who failed to compile wm8974 module too. eg.
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt

Andrew Stubbs, Michael Hope in Linaro's toolchain team are working hard on this gcc issue. there have been many update today:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

#8 lore raw
Quoted 12 lines · Barry Song

2011/4/27 Mark Brown <[email protected]>

Quoted 3 lines

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

I agree. for this patch which will not be applied, people can just get information about how to workaround the gcc issue while they have the same problem. google can find there are other people who failed to compile wm8974 module too. eg.
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt

Quoted 3 lines

Andrew Stubbs, Michael Hope in Linaro's toolchain team are working hard on this gcc issue. there have been many update today:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

Is this just some Linaro toolchain that has the issue rather than a vanilla GCC release? If so and they fix the compiler bug it doesn't seem terribly useful to bodge it in mainline.

A message that is not in the archive (sent off-list or not yet received): 20110427151249.GE31952-yzvPICuk2AATkU/[email protected]

#10 lore raw

2011/4/27 Mark Brown <[email protected]>:

Quoted 13 lines · Barry Song
Quoted 11 lines

2011/4/27 Mark Brown <[email protected]>

Quoted 3 lines

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

I agree. for this patch which will not be applied, people can just get information about how to workaround the gcc issue while they have the same problem. google can find there are other people who failed to compile wm8974 module too. eg.
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt

Quoted 8 lines
Quoted 3 lines

Andrew Stubbs, Michael Hope in Linaro's toolchain team are working hard on this gcc issue. there have been many update today:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

Is this just some Linaro toolchain that has the issue rather than a vanilla GCC release?  If so and they fix the compiler bug it doesn't seem terribly useful to bodge it in mainline.

i am guessing it is a generic gcc issue since Michael posted it at
http://gcc.gnu.org/bugzilla not Linaro's Launchpad. not sure :-)

_______________________________________________
linaro-toolchain mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-toolchain

A message that is not in the archive (sent off-list or not yet received): BANLkTin4y192A0Jdujv2t5tjoccmUBzQMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw

2011/4/27 Barry Song <[email protected]>:

Quoted 18 lines

2011/4/27 Mark Brown <[email protected]>:

Quoted 17 lines · Barry Song
Quoted 15 lines

2011/4/27 Mark Brown <[email protected]>

Quoted 3 lines

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

I agree. for this patch which will not be applied, people can just get information about how to workaround the gcc issue while they have the same problem. google can find there are other people who failed to compile wm8974 module too. eg.
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt

Andrew Stubbs, Michael Hope in Linaro's toolchain team are working hard on this gcc issue. there have been many update today:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

Quoted 7 lines
Quoted 4 lines

Is this just some Linaro toolchain that has the issue rather than a vanilla GCC release?  If so and they fix the compiler bug it doesn't seem terribly useful to bodge it in mainline.

i am guessing it is a generic gcc issue since Michael posted it at
http://gcc.gnu.org/bugzilla not Linaro's Launchpad. not sure :-)

Linaro doesn't exist yet when the discussion happened at
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt discussion:

" [19:03] <nosse1> I got this while compiling: "ERROR:
"__aeabi_uldivmod" [sound/soc/codecs/snd-soc-wm8974.ko] undefined!" [19:04] <nosse1> Now, I can disable the driver alltogether, but is this related to the CSL cross compiler?
[19:04] <hrw> nosse1: google should give answer - common problem it was [19:04] <nosse1> hehe - sorry, you're right
"

_______________________________________________
linaro-toolchain mailing list
[email protected]
http://lists.linaro.org/mailman/listinfo/linaro-toolchain

#13 lore raw
In reply to a message not in the archive

Hi Mark. The fault exists in FSF GCC 4.5.2 and Linaro GCC 4.5-2011.04. The fault does not exist in FSF GCC 4.6.0 or Linaro GCC 4.6-2011.04.

-- Michael

Quoted 26 lines · Mark Brown
Quoted 12 lines · Barry Song

2011/4/27 Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>

Quoted 3 lines

If we do have to do something in the callers rather than in do_div() the annotation seems substantially more taseful than inserting a random asm into the code.

I agree. for this patch which will not be applied, people can just get information about how to workaround the gcc issue while they have the same problem. google can find there are other people who failed to compile wm8974 module too. eg.
http://irclogs.ubuntu.com/2010/03/30/%23ubuntu-arm.txt

Quoted 3 lines

Andrew Stubbs, Michael Hope in Linaro's toolchain team are working hard on this gcc issue. there have been many update today:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48783

Is this just some Linaro toolchain that has the issue rather than a vanilla GCC release?  If so and they fix the compiler bug it doesn't seem terribly useful to bodge it in mainline.

_______________________________________________
linaro-toolchain mailing list [email protected]
http://lists.linaro.org/mailman/listinfo/linaro-toolchain

#14 lore raw

On Thu, Apr 28, 2011 at 10:30:24AM +1200, Michael Hope wrote:

Don't top post!

Quoted 3 lines

Hi Mark. The fault exists in FSF GCC 4.5.2 and Linaro GCC 4.5-2011.04. The fault does not exist in FSF GCC 4.6.0 or Linaro GCC 4.6-2011.04.

Given that nobody's reported it previously and there's already a new GCC release I'm not sure it's worth worry about - it's a fairly clear compiler bug.

#15 lore raw
In reply to Barry Song
Quoted 10 lines · Barry Song

2011/4/27 Takashi Iwai <[email protected]>:

Quoted 2 lines

Don't do this in the low driver level.  If any, we should fix do_div() instead.

do_div is just a macro, it has no problem by itself. only while working together with other more codes before do_div, gcc can make some codes merging and cause problems.

if do_div is a function, we'd just fix it.

It's a macro which expands to a problem so we should make it expand to something which includes the fix as well rather than going round and fixing each and every caller.