PPC NCG: Implement callish prim ops
ClosedPublic

Authored by trommler on Jan 14 2017, 10:09 AM.

Details

Summary

Provide PowerPC optimised implementations of callish prim ops.

MO_?_QuotRem
The generic implementation of quotient remainder prim ops uses
a division and a remainder operation. There is no remainder on
PowerPC and so we need to implement remainder "by hand" which
results in a duplication of the divide operation when using the
generic code.

Avoid this duplication by implementing the prim op in the native
code generator.

MO_U_Mul2
Use PowerPC's instructions for long multiplication.

Addition and subtraction
Use PowerPC add/subtract with carry/overflow instructions

MO_Clz and MO_Ctz
Use PowerPC's CNTLZ instruction and implement count trailing
zeros using count leading zeros

MO_QuotRem2
Implement an algorithm given by Henry Warren in "Hacker's Delight"
using PowerPC divide instruction. TODO: Use long division instructions
when available (POWER7 and later).

Test Plan

validate on AIX and 32-bit Linux

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
trommler updated this revision to Diff 10469.Jan 14 2017, 10:09 AM
trommler retitled this revision from to PPC NCG: Implement callish prim ops.
trommler updated this object.
trommler edited the test plan for this revision. (Show Details)
trommler added reviewers: hvr, erikd, simonmar, austin, bgamari.
trommler added subscribers: thomie, kgardas.
trommler edited edge metadata.Jan 14 2017, 11:02 AM
trommler updated this revision to Diff 10470.Jan 14 2017, 11:26 AM
  • Break up long lines
trommler updated this object.Jan 17 2017, 3:44 AM
trommler edited edge metadata.
erikd accepted this revision.Jan 17 2017, 3:51 AM
erikd edited edge metadata.

This looks ok to me, but I can't currently built it cause my PowerPC machine is busted.

In D2973#86962, @erikd wrote:

This looks ok to me, but I can't currently built it cause my PowerPC machine is busted.

Thanks @ erikd.

If it works on AIX then most likely it will work on PPC 32-bit Linux as well. Let's wait for @hvr's review.

bgamari edited edge metadata.EditedFeb 1 2017, 3:33 PM

@hvr, any news here?

bgamari requested changes to this revision.Feb 5 2017, 8:32 PM

Bumping out of review queue until we get a review by @hvr.

This revision now requires changes to proceed.Feb 5 2017, 8:32 PM
trommler updated this revision to Diff 11840.Mar 21 2017, 2:03 PM
trommler edited edge metadata.

Rebase so it applies cleanly to HEAD again.

trommler updated this revision to Diff 11860.Mar 24 2017, 3:39 AM

Fix long lines.
Rebase again to fix Habormaster builds.

@hvr, can you have a look at this? It would be good to get poor
@trommler off the hook for rebasing this.

Fix long lines.
Rebase again to fix Habormaster builds.

Sorry, I did not mean this to be a nag. I was just unlucky to have rebased onto a commit that built locally but failed on Harbormaster.

trommler updated this revision to Diff 11894.Mar 27 2017, 10:08 AM
  • Fix count trailing zeros formula in comment
hvr accepted this revision.Apr 24 2017, 5:17 PM

Sorry this took me so long! I finally got GHC HEAD to build again on AIX, and was able to apply this patch cleanly to GHC 8.2.1.

I was able to build a working GHC ("perf" settings). So I guess there's a good chance this works well enough. Is there any particular test-case that exercises specifically this part of the code-gen? I can't easily run the whole validate testsuite currently, due to a broken Python installation.

This revision now requires changes to proceed.Apr 24 2017, 5:17 PM
In D2973#99561, @hvr wrote:

Is there any particular test-case that exercises specifically this part of the code-gen? I can't easily run the whole validate testsuite currently, due to a broken Python installation.

numeric/should_run has some tests. There might be more in base.

hvr added a comment.Apr 25 2017, 2:14 AM

I've manually run the numeric testcases, and it looks all good to me! Let's merge this!

bgamari accepted this revision.Apr 25 2017, 8:12 AM
bgamari added a subscriber: trofi.

Great, thanks @hvr and @trofi!

This revision is now accepted and ready to land.Apr 25 2017, 8:12 AM
This revision was automatically updated to reflect the committed changes.