Bug 803 - gas should avoid F-unit NOPs (and B-unit probably, too)
Summary: gas should avoid F-unit NOPs (and B-unit probably, too)
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-24 23:23 UTC by David Mosberger-Tang
Modified: 2005-03-29 02:19 UTC (History)
3 users (show)

See Also:
Host: ia64-linux
Target: ia64-linux
Build: ia64-linux
Last reconfirmed:


Attachments
Proposed fix (851 bytes, patch)
2005-03-24 23:25 UTC, David Mosberger-Tang
Details | Diff
A patch to tune for itanium1 and itanium2 (2.55 KB, patch)
2005-03-28 21:03 UTC, H.J. Lu
Details | Diff
An updated patch (3.03 KB, patch)
2005-03-28 21:48 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Mosberger-Tang 2005-03-24 23:23:09 UTC
Chips derived from McKinley-core (Itanium 2, etc.) have an anomaly which can
cause stalls if an F-unit instruction (including a NOP) is issued right after
reading certain application registers (such as ar.bsp).  Furthermore,
power-considerations also argue against the use of F-unit instructions unless
they're really needed.

Similarly, using B-unit NOPs is probably not a great idea for McKinley-derived
cores: certain templates with B unit instructions cause split-issue and the BBB
template in particular causes a branch-prediction anomaly (the first two
branches are predicated based on the slot 0 hints.

I'll attach a patch which appears to fix this problem.  If it looks OK, please
check it in.

Note: the new policy won't be optimal for Itanium (Merced) chips.  I don't think
anyone will care.
Comment 1 David Mosberger-Tang 2005-03-24 23:25:12 UTC
Created attachment 445 [details]
Proposed fix
Comment 2 H.J. Lu 2005-03-25 00:37:33 UTC
Jim, is the proposed patch OK?
Comment 3 wilson@specifixinc.com 2005-03-25 01:13:06 UTC
The patch looks OK to me, but I expect it will break the IA-64 gas testsuite,
which means we need patches for that also.  I haven't tried writing those
patches yet.
Comment 4 H.J. Lu 2005-03-25 02:22:50 UTC
Can we modify the patch to have it a switch to turn it on/off and make it
on by default? Then, we can just turn it off in the existing testcases and
add a new one for this.
Comment 5 wilson@specifixinc.com 2005-03-25 02:46:31 UTC
Subject: Re:  gas should avoid F-unit NOPs (and B-unit
	probably, too)

On Thu, 2005-03-24 at 18:22, hjl at lucon dot org wrote:
> ------- Additional Comments From hjl at lucon dot org  2005-03-25 02:22 -------
> Can we modify the patch to have it a switch to turn it on/off and make it
> on by default? Then, we can just turn it off in the existing testcases and
> add a new one for this.

Such as a -mcpu=itanium1 switch?  I suppose that could work.

Or we could try fixing the testsuite to use explicit bundles, so that it
stops changing every time the bundling heuristics change.

Or we could just say to heck with it and regenerate all of the .d files.

Or we could try to make the .d files be bundling independent.  Try
looking at some of the ones that Jan Beulich has added.  He uses "." to
match bundles when nops are involved, so that it is bundling
independent.  See for instance align.d.

However, before we make a decision, I really think that someone should
run the gas testsuite first, and check to see whether we have a problem,
and if so, how big of a problem it is.  There is no sense to trying to
write a complicated solution if we only have a simple problem.
Comment 6 H.J. Lu 2005-03-25 17:18:25 UTC
With the patch applied, I got

./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 opc-b
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 opc-f
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 opc-i
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 opc-m
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 pseudo-ops
./build-ia64-linux/gas/testsuite/gas.log:FAIL: gas/ia64/dv-imply
./build-ia64-linux/gas/testsuite/gas.log:FAIL: gas/ia64/dv-mutex
./build-ia64-linux/gas/testsuite/gas.log:FAIL: gas/ia64/dv-safe
./build-ia64-linux/gas/testsuite/gas.log:FAIL: gas/ia64/dv-srlz
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 tls
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 ldxmov-1
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 pcrel
./build-ia64-linux/gas/testsuite/gas.log:FAIL: ia64 operand-or
./build-ia64-linux/ld/ld.log:FAIL: TLS -fpic -shared
./build-ia64-linux/ld/ld.log:FAIL: TLS -fpic and -fno-pic exec

I think we should add -mcpu=[itanium1|itanium2] and make itanium2 the default.
Comment 7 wilson@specifixinc.com 2005-03-25 21:07:15 UTC
Subject: Re:  gas should avoid F-unit NOPs (and B-unit
	probably, too)

On Fri, 2005-03-25 at 09:18, hjl at lucon dot org wrote:
> I think we should add -mcpu=[itanium1|itanium2] and make itanium2 the default.

I'm OK with that.

Long term, I think writing testcases the way Jan did is a better
solution, but we've got 2k nops in just the opc-*.d files alone, and
fixing them all seems like too much work for now when we are just trying
to get David's patch in.
Comment 8 H.J. Lu 2005-03-28 21:03:15 UTC
Created attachment 447 [details]
A patch to tune for itanium1 and itanium2

This patch adds "-mtune=[itanium1|itanium2]". I will update
NEWS and doc if it is OK.
Comment 9 wilson@specifixinc.com 2005-03-28 21:36:08 UTC
Subject: Re:  gas should avoid F-unit NOPs (and B-unit
	probably, too)

On Mon, 2005-03-28 at 13:03, hjl at lucon dot org wrote:
> This patch adds "-mtune=[itanium1|itanium2]". I will update
> NEWS and doc if it is OK.

I think the extra_goodness change is a little confusing.  You are
reusing the parameter "slot" for the return value, even though the
return value has nothing to do with slot numbers.  I had to read the
code twice before I figured out why you were changing the slot numbers. 
I would prefer a new local variable named "goodness" or "retval" or
whatever.  And then we can initialize it to a sensible value like 0.  Or
perhaps just "return 2" instead of "slot = 2" like the original code
had.  There is also the issue that maybe there should be a "default:
abort ();" to make sure the code gets appropriately modified when future
processors are added.

Otherwise, it all looks OK to me.
Comment 10 H.J. Lu 2005-03-28 21:48:30 UTC
Created attachment 448 [details]
An updated patch

This is an updated patch. I documented the change and modified
extra_goodness.
Comment 11 wilson@specifixinc.com 2005-03-28 22:26:59 UTC
Subject: Re:  gas should avoid F-unit NOPs (and B-unit
	probably, too)

On Mon, 2005-03-28 at 13:48, hjl at lucon dot org wrote:
> This is an updated patch. I documented the change and modified
> extra_goodness.

OK.  Thanks.
Comment 12 wilson@specifixinc.com 2005-03-29 02:19:00 UTC
HJ checked in his patch to fix this.