?

Log in

No account? Create an account
GCC 4.2 + LLVM 2.2 = 35% faster than GCC 4.2 alone. - Adventures in Engineering — LiveJournal
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2008-03-03 12:03
  Subject:   GCC 4.2 + LLVM 2.2 = 35% faster than GCC 4.2 alone.
Public
  Mood:der uber-nerd
  Tags:  reddit



Where these performance differences come from? In Himeno bench, The inner-most loop in jacobi() consumes 99.7% of whole computation time. I disassembled executables of this part, and found LLVM 2.2 emits very efficient x86 assembly. It is composed of move, add/sub and mul instructions. These 3 instructions can be executed in parallel on Core2 CPU. (Core2 has independent load/store unit, additive fp ALU and multiply fp ALU)

http://lucille.atso-net.jp/blog/?p=430

Back in the 70's everyone argued that compilers would never produce faster code than hand-tweaked assembly. These days, you have to be awfully damn good at assembly to create faster code than an optimizing compiler can. So gee, I wonder what's going to happen in the future with virtual machines - which "everyone knows" will never be as fast as compiled code. (Especially when everyone has a multi-core CPU. Cuz we all know great human beings are at thinking in parallel, don't we?)

(Another advantage of VMs - they can optimize code for cache coherency. Which can get you between one and two orders of magnitude increase in performance, if done exactly right.)

NB: Someone suggested that the tests be run again, this time passing "-march=Core2" to gcc. It might create more optimized code and beat LLVM in that case.
Post A Comment | 6 Comments | | Link






Alex Belits: mona
  User: abelits
  Date: 2008-03-03 22:10 (UTC)
  Subject:   (no subject)
Keyword:mona
Which definition of "Virtual Machine" are you using?

1. Virtual instruction set not designed, and usually impractical, nearly impossible to be implemented in hardware (all interpreted and JIT-compiled languages)?

2. Virtual execution environment transparently translating a hardware instruction set and memory management to itself at runtime, providing hardware partitioning and a level of access control (IBM mainframe architecture, current generation of virtualization products that compensate for Windows' poor multitasking and security)?

3. Virtual execution environment transparently translating a hardware instruction set to another hardware instruction set at runtime with or without hardware partitioning and a level of access control (FX!32)?

4. Virtual execution environment translating virtual instruction set into a particular hardware instruction set at runtime? (Java, .NET)

5. Translator between instruction sets running offline before the program is executed?

6. Translator between instruction sets that combines offline and runtime code generation? (what LLVM is).

7. Virtual Memory subsystem with its set of controls implemented as a set of calls or instructions?

8. Resource partitioning and state management mechanism within OS kernel.

9. Any kind of mechanism implemented in hardware or software with calls or control language that consists of instructions?

I am afraid, "Virtual machine" is no longer useful as a term to describe any category of software infrastructure.

To be blunt:

1. Perl, PHP, Python, Java, Lisp, Basic. Name ones that are not like the others in this list (they all are).

2. "Our OS has such a crappy virtual memory, scheduler and security, placing ONE MORE LEVEL OF EXACTLY THE SAME on top of it improves its performance." or, alternatively, "Quick, sell more of (2) until someone developed (8) and put all of us out of business!"

3. Digital tried to sell software. And failed. Then it tried to sell hardware. And failed.

4. Sun thinks, developers don't want to give users the sources, and don't want to compile it themselves. Microsoft thinks, anything that gives it a reason to stop writing on Win32 level is a good thing because $deity, that API sucks ass.

5. LLVM probably will be fine if it limited itself to this.

6. Apparently works, but I wonder if runtime thing self-deoptimizes itself for rare cases, then stumbles when its performance actually matters. Profilers are tools for humans.

7. NUMA probably needs that. Combined with parallelism in compilers.

8. What everyone SHOULD be doing, because people use freaking monstrosities like VMWare for that purpose alone.

9. All of the above.

Edited at 2008-03-03 10:13 pm (UTC)
Reply | Thread | Link



Ben Cantrick
  User: mackys
  Date: 2008-03-03 22:40 (UTC)
  Subject:   (no subject)
I am afraid, "Virtual machine" is no longer useful as a term to describe any category of software infrastructure.

This is a good point. In my personal opinion, I think a good virtual machine would be mostly a mixture of 4, 5 and 6 from the first list. And some 7 (and/or 8) probably sneaks in there whether I like or not.

Microsoft thinks, anything that gives it a reason to stop writing on Win32 level is a good thing because $deity, that API sucks ass.

This may be the best reason of all to have virtual machines. ;D
Reply | Parent | Thread | Link



  User: nickhalfasleep
  Date: 2008-03-03 22:29 (UTC)
  Subject:   (no subject)
Great, another toolchain component I'd need a phd to understand.
Reply | Thread | Link



Ben Cantrick
  User: mackys
  Date: 2008-03-03 22:44 (UTC)
  Subject:   (no subject)
Well, I don't understand compilers (much), but it doesn't stop me from being a decent programmer.

Also, just because I think LLVM is a good idea, doesn't mean I think we should take away people's ability to write in assembly. The world is plenty big enough to keep both approaches around.
Reply | Parent | Thread | Link



Jon: satchel
  User: j_b
  Date: 2008-03-04 00:04 (UTC)
  Subject:   (no subject)
Keyword:satchel "what"

Lissen to my story;
'Tis a story true;
'Bout a might man, --Teapot was his name,
An' Teapot was a 'ssembly-coder too--
Lawd, -- Lawd, --
Teapot was a 'ssembly-coder too.

Teapot had a assemblah;
Weighed nigh fo'ty poun';
Eb'ry time Teapot hit compile
He seen his runtime go 'bout two seconds down,--
Lawd, -- Lawd, --
He seen his runtime go 'bout two seconds down.

Teapot's woman, Lucy,--
Dress she wore was blue;
Eyes like stars an' teeth lak-a marble stone,
An' Teapot named his assembler "Lucy" too,--
Lawd, -- Lawd, --
Teapot named his assembler "Lucy" too.

Lucy came to see him;
Bucket in huh han';
All th' time Teapot ate his snack,
O Lucy she'd write opcodes lak-a man,--
Lawd, -- Lawd, --
O Lucy she'd write opcodes lak-a man.

Teapot's cap'n Tommy,--
V'ginny gave him birth;
Loved Teapot like his only son,
And Cap' Tommy was the whitest man on earth,--
Lawd, -- Lawd, --
Cap' Tommy was th' whitest man on earth.

One day Cap' Tommy told him
How he'd bet a man;
Bet Teapot'd beat a just-in-time compilah down,
Jes' cause he was th' best in th' lan',--
Lawd, -- Lawd, --
'Cause he was th' best in th' lan.

Teapot tol' Cap' Tommy;
Lightnin' in his eye;
"Cap'n, bet yo' las' red cent on me,
Fo' I'll beat it on th' benchmark or I'll die,--
Lawd, -- Lawd, --
I'll beat it on th' benchmark or I'll die."

"Pelmeni's in my stomach;
Hammah's in my han';
Haint no just-in-time compilah on dis realtime job
Can beat 'Lucy' an' her assembly-codin' man,
Lawd, -- Lawd, --
Can beat 'Lucy' an' her assembly-codin' man."

"Bells ring on de build-scripts;
Runnin' down th' line;
Dinnahs done when Lucy pulls th' c'od;
But no compiler in this codebase runs like mine,--
Lawd, -- Lawd, --
No compiler in this codebase runs like mine."

Sun shined hot an' burning'
Wer'n't no breeze at-tall;
Sweat ran down like watah down a hill
That day Teapot let his compiler fall,--
Lawd, -- Lawd, --
That day Teapot let his compiler fall.

Teapot kissed his compiler;
White Man turned on JIT;
Li'l Bill checked Teapot's code in review,--
'Twas th' biggest race th' worl' had ever seen,--
Lawd, -- Lawd, --
Th' biggest race th' worl' had ever seen.

White Man tol' Teapot,--
"Belarussian, dam yo' soul,
You might beat dis JIT compiler o' mine
When th' rocks in this mountain turn to gol',--
Lawd, -- Lawd, --
When th' rocks in this mountain turn to gol'."

Teapot tol' th' white man;
Tol' him kind-a sad:
"Cap'n George I want-a be yo' fr'en;
If I beat yo' runtime, don't git mad,--
Lawd, -- Lawd, --
If I beat yo' runtime, don't git mad."

Cap' Tommy sees Teapot's
Opcodes cachein' in;
Cap'n slaps Teapot on th' back,
Says, "I'll give yo' fifty dollars if yo' win,--
Lawd, -- Lawd, --
I'll give yo' fifty dollars if yo' win."

White Man saw Teapot's
Steel a-goin' down;
White Man says,--"That man's a mighty man,
But he'll weaken when th' paralell loops are foun',--
Lawd, -- Lawd, --
He'll weaken when th' parallel loops are foun'."

Teapot, O Teapot,--
Teapot's compiler too;
When a woman's 'pendin' on a man
Haint no tellin' what a might man can do,--
Lawd, -- Lawd, --
No tellin' what a mighty man can do.

Reply | Thread | Link



Jon: satchel
  User: j_b
  Date: 2008-03-04 00:04 (UTC)
  Subject:   (no subject)
Keyword:satchel "what"

Teapot, O, Teapot!
Blood am runnin' red!
Falls right down with his compiler to th' groun',
Says, "I've beat him on the benchmark but I'm dead,--
Lawd, -- Lawd, --
I've beat him on the benchmark but I'm dead."

Teapot kissed his compiler;
Kissed it with a groan;
Sighed a sigh an' closed his weary eyes,
Now po' Lucy has no man to call huh own,--
Lawd, -- Lawd, --
Po' Lucy has no man to call huh own.

Cap' Tommy came a-runnin'
To Teapot's side;
Says, "Lawd, Lawd,--O Lawdy, Lawdy, Lawd,--
He's beat it in the benchmark but he's died,--
Lawd, -- Lawd, --
He's beat it in the benchmark but he's died."

Lucy ran to see him;
Dress she wore was blue;
Started down th' track an' she nevvah did turn back,
Sayin', "Teapot, I'll be true--true to you,--
Lawd, -- Lawd, --
Teapot, I'll be true--true to you."

Teapot, O, Teapot!
Sing it if yo' can,--
High an' low an' ev'ry where yo' go,--
He died with his assembler in his han',--
Lawd, -- Lawd, --
He died with his assembler in his han'.

Buddie, where'd yo' come from
To this codin' job?
If yo' wantta be a good code-drivin' man,
Put yo' trus' in yo' assembler an' yo' God,--
Lawd, -- Lawd, --
Put yo' trus' in yo' assembler an' yo God.

Reply | Thread | Link



browse
May 2015