Update: The professor posted some details, which I've copied to an "answer" on this meta. The original was posted in the wrong place and deleted.
It's somewhat broad as-is, but an edit from the OP could fix that. It isn't a fundamentally flawed question, because the too-broadness is in lack of details, not the whole question itself. Many people are overlooking the fact that it's about microarchitectural slowdowns from pipeline hazards, not C++ in general. It approaches a broad topic from a specific angle.
The OP has only just recently provided further clarifications in comments on this meta post, so it's probably time to unlock the question and make some edits. Normally it's ok for there to be some delay in shaping a question into ideal form, but unfortunately the question was widely publicized before it was the OP responded, or anyone else improved it. (A title edit to focus on the pipeline, not C++, would have helped a lot). I answered on the assumption that it would soon be improved, rather than waiting before that happened.
It's interesting enough to enough people to be an exception to the general rule that we don't want a lot of too-broad questions on SO. Besides the many comments on the SO post, it caught the interest of people on other forums like Reddit and ycombinator, where NKurz posted some results from testing it with different compilers. I assume that's the same Nathan Kurz who's posted interesting comments on Agner Fog's blog. So there are definitely people beyond just me with some detailed microarchitectural knowledge and interest that liked this question. Obviously it's not going to be interesting to everyone, but no SO question is.
IMO, this question is good enough to stay, even though there are several ways it could still be improved. It doesn't have to be perfect. A flawed question can be interesting. We can decide on a case-by-case basis to allow things like this without opening the floodgates.
In this case, what makes the question interesting is the idea of de-optimizing without simply bumping up the iteration counts or bloating the code. Also, having to justify your pessimizations as "diabolically incompetence", rather than intentional pessimization is really interesting. This is the new idea that people want to think about. The specific code in the question isn't what makes it interesting.
There are also aspects that can't change at this point, but would have made it a better question: e.g. a different choice of source-code to de-optimize. Code that didn't spend so much time in exp()
and log()
would make much more sense. Also, we can invent reasons to store things in memory, and memory stalls are a huge deal, but having some kind of data structure in the first place would have been nice.
Apparently the assignment was not intended to be very complicated, and it was only a "second semester" computer architecture course. I assumed that it must be a pretty advanced class to be studying Intel pipelines, because they are seriously complicated.
Many people have made suggestions based on the title ("deoptimizing a C++ program") that would slow down even a non-pipelined CPU. e.g. use Boost to get the compiler to generate some slow stuff using very few source lines. I think it's these suggestions that are off-topic and contribute to the impression that "too broad" is really a problem. OP hasn't done a good job of ruling out such source changes, though. This meta question got me thinking I should edit the question title to be more specific, but the question is locked ATM. (Thanks for not locking the answers, I might have more ideas to tighten up my long & rambling answer).
"obviously too broad" ... (see the first answer, which has more than 15k characters)
Too Broad applies when the minimum length of a sufficient answer is too big.
The fact that a long and detailed answer is possible isn't a problem, as long as short answers that don't go into detail could be good enough.
This isn't the case when a long answer would be required to correct all the misconceptions in a question. Or for many homework questions to an otherwise trivial question.
I think the fact that I could give a fairly detailed answer that covers many of the bases in only 2/3rd of the maximum 30k chars doesn't support the too-broad argument at all.
I could find 15k chars of things to say about performance considerations in many answers to direct questions, like SSE horizontal sums, or how to zero a register.
I had no idea this question was going to be popular! I've made several edits to shorten it and present the same information better, not just keep making it longer. One of the most important recent changes was including a TL;DR
table of contents / summary of the more plausible suggestions that the OP could justify with the proper application of diabolical incompetence, and not just outright malice / obvious pessimization.
I've been toiling away writing answers with detailed microarchitectural justification for choosing one way of doing something over another (e.g. with SIMD vectors) for a long time now, and this is one of very few that's caught the interest of anyone outside of computer-architecture or x86. Another one being this one about popcnt of bits below a position.
I tend to write long/detailed answers, because I hate leaving out information that is relevant. I've had positive feedback from many people about the microarch details and technical depth of my previous answers, and I'd much rather write for an audience that appreciates that.
My approach to answering was to consider all the ways I can think of to stall or slow down a Sandybridge-family pipeline, and consider those stalls from the PoV of this program. So a few paragraphs are spent on stalls that we can't reasonably expect to create, like LCP stalls or self-modifying code. Or partial-register stalls, which are only a really big deal on Nehalem (the first i7).
Anyway, so even though I cover a lot of ground, I tried to tie every point back to the specific angle the question is coming from.
My answer as it stands now is kinda long, and could be ordered better. I wish SO markdown allowed collapsible sections to allow interesting asides to not get in the way of more important text.