mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Nicolas Pitre <nicolas.pitre@linaro.org>
Cc: "Måns Rullgård" <mans@mansr.com>,
	"Ben Dooks" <ben.dooks@codethink.co.uk>,
	"Russell King - ARM Linux" <linux@arm.linux.org.uk>,
	"Stephen Boyd" <sboyd@codeaurora.org>,
	linux-kernel@vger.kernel.org,
	"Christopher Covington" <cov@codeaurora.org>,
	"Jean-Christophe PLAGNIOL-VILLARD" <plagnioj@jcrosoft.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2] ARM: Use udiv/sdiv for __aeabi_{u}idiv library functions
Date: Tue, 12 Nov 2013 18:03:56 +0000	[thread overview]
Message-ID: <yw1xzjp9ts37.fsf@unicorn.mansr.com> (raw)
In-Reply-To: <alpine.LFD.2.10.1311120948000.9667@knanqh.ubzr> (Nicolas Pitre's message of "Tue, 12 Nov 2013 09:55:09 -0500 (EST)")

Nicolas Pitre <nicolas.pitre@linaro.org> writes:

> On Tue, 12 Nov 2013, Måns Rullgård wrote:
>
>> Nicolas Pitre <nicolas.pitre@linaro.org> writes:
>> 
>> > On Tue, 12 Nov 2013, Ben Dooks wrote:
>> >
>> >> Given these are single instructoins for ARM, is it possible we could
>> >> make a table of all the callers and fix them up when we initialise
>> >> as we do for the SMP/UP case and for page-offset?
>> >
>> > Not really.  Calls to those functions are generated by the compiler 
>> > implicitly when a divisor operand is used and therefore we cannot 
>> > annotate those calls.  We'd have to use special accessors everywhere to 
>> > replace the standard division operand (like we do for 64 by 32 bit 
>> > divisions) but I doubt that people would accept that.
>> 
>> It might be possible to extract this information from relocation tables.
>
> True, but only for individual .o files.  Once the linker puts them 
> together the information is lost, and trying to infer what the linker 
> has done is insane.
>
> Filtering the compiler output to annotate idiv calls before it is 
> assembled would probably be a better solution.

OK, here's an extremely ugly hootenanny of a patch.  It seems to work on
an A7 Cubieboard2.  I would never suggest actually doing this, but maybe
it can be useful for comparing performance against the more palatable
solutions.

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 7397db6..cf1cd30 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -113,7 +113,7 @@ endif
 endif
 
 # Need -Uarm for gcc < 3.x
-KBUILD_CFLAGS	+=$(CFLAGS_ABI) $(CFLAGS_THUMB2) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm
+KBUILD_CFLAGS	+=$(CFLAGS_ABI) $(CFLAGS_THUMB2) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm -include asm/divhack.h
 KBUILD_AFLAGS	+=$(CFLAGS_ABI) $(AFLAGS_THUMB2) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float
 
 CHECKFLAGS	+= -D__arm__
diff --git a/arch/arm/include/asm/divhack.h b/arch/arm/include/asm/divhack.h
new file mode 100644
index 0000000..c750b78
--- /dev/null
+++ b/arch/arm/include/asm/divhack.h
@@ -0,0 +1,23 @@
+__asm__ (".macro dobl tgt                                       \n"
+         "    .ifc \\tgt, __aeabi_idiv                          \n"
+         "        .L.sdiv.\\@:                                  \n"
+         "        .pushsection .sdiv_tab.init, \"a\", %progbits \n"
+         "        .word    .L.sdiv.\\@                          \n"
+         "        .popsection                                   \n"
+         "    .endif                                            \n"
+         "    .ifc \\tgt, __aeabi_uidiv                         \n"
+         "        .L.udiv.\\@:                                  \n"
+         "        .pushsection .udiv_tab.init, \"a\", %progbits \n"
+         "        .word    .L.udiv.\\@                          \n"
+         "        .popsection                                   \n"
+         "    .endif                                            \n"
+         "    bl \\tgt                                          \n"
+         ".endm                                                 \n"
+         ".macro defbl                                          \n"
+         "    .macro bl tgt                                     \n"
+         "        .purgem bl                                    \n"
+         "        dobl \\tgt                                    \n"
+         "        defbl                                         \n"
+         "    .endm                                             \n"
+         ".endm                                                 \n"
+         "defbl                                                 \n");
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 067815c1..b3a3fe1 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -375,6 +375,18 @@ static void __init cpuid_init_hwcaps(void)
 	case 1:
 		elf_hwcap |= HWCAP_IDIVT;
 	}
+
+	if (!IS_ENABLED(CONFIG_THUMB2_KERNEL) && (elf_hwcap & HWCAP_IDIVA)) {
+		extern u32 __sdiv_tab_start, __sdiv_tab_end;
+		extern u32 __udiv_tab_start, __udiv_tab_end;
+		u32 *div;
+
+		for (div = &__sdiv_tab_start; div < &__sdiv_tab_end; div++)
+			*(u32 *)*div = 0xe710f110;
+
+		for (div = &__udiv_tab_start; div < &__udiv_tab_end; div++)
+			*(u32 *)*div = 0xe730f110;
+	}
 }
 
 static void __init feat_v6_fixup(void)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 43a31fb..3d5c103 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -176,6 +176,8 @@ SECTIONS
 		CON_INITCALL
 		SECURITY_INITCALL
 		INIT_RAM_FS
+		__sdiv_tab_start = .; *(.sdiv_tab.init); __sdiv_tab_end = .;
+		__udiv_tab_start = .; *(.udiv_tab.init); __udiv_tab_end = .;
 	}
 #ifndef CONFIG_XIP_KERNEL
 	.exit.data : {


-- 
Måns Rullgård
mans@mansr.com

  parent reply	other threads:[~2013-11-12 18:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 23:00 Stephen Boyd
2013-11-09  6:46 ` Matt Sealey
2013-11-09 18:20   ` Måns Rullgård
2013-11-12  1:23   ` Stephen Boyd
2013-11-10  5:03 ` Nicolas Pitre
2013-11-12  2:34   ` Stephen Boyd
2013-11-12 11:28     ` Måns Rullgård
2013-11-12 14:01     ` Nicolas Pitre
2013-11-12 14:04       ` Russell King - ARM Linux
2013-11-12 14:16         ` Nicolas Pitre
2013-11-12 14:17         ` Ben Dooks
2013-11-12 14:32           ` Nicolas Pitre
2013-11-12 14:40             ` Måns Rullgård
2013-11-12 14:55               ` Nicolas Pitre
2013-11-12 15:20                 ` Nicolas Pitre
2013-11-12 18:03                 ` Måns Rullgård [this message]
2013-11-12 14:22       ` Måns Rullgård
2013-11-12 14:36         ` Nicolas Pitre
2013-11-11  7:46 ` Uwe Kleine-König
2013-11-12  2:35   ` Stephen Boyd

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xzjp9ts37.fsf@unicorn.mansr.com \
    --to=mans@mansr.com \
    --cc=ben.dooks@codethink.co.uk \
    --cc=cov@codeaurora.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=nicolas.pitre@linaro.org \
    --cc=plagnioj@jcrosoft.com \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®