ASM vs C

Community discussion for topics unrelated to the project.

Moderator: coordinators

ASM vs C

Postby losbellos » Sun Aug 08, 2010 3:01 am

thanks,

not directly connected just a question:
What do you think Assembly is still ahead of C in terms of speed?
Like for example wiriting a ray tracer in assembly or a sampler would be beneficial?
losbellos
 
Posts: 783
Joined: Wed Jun 24, 2009 4:59 am

Re: Minor bug in src/idevices/openclidevice.cpp

Postby SATtva » Sun Aug 08, 2010 3:30 am

This is an off-topic here, so please restrain from further discussion, but yes, this is beneficial if you're able to write and debug a complex SIMD-optimized multithreaded program in a plain asm.
Linux builds packager
聞くのは一時の恥、聞かぬのは一生の恥
User avatar
SATtva
Developer
 
Posts: 5546
Joined: Tue Apr 07, 2009 12:19 pm
Location: from Siberia with love

Re: Minor bug in src/idevices/openclidevice.cpp

Postby losbellos » Sun Aug 08, 2010 5:28 am

Hej Sattva thanks, but I asked him not you.. Hope you dont mind.
losbellos
 
Posts: 783
Joined: Wed Jun 24, 2009 4:59 am

Re: ASM vs C

Postby SATtva » Sun Aug 08, 2010 5:59 am

I do mind off-topic discussions. I've split the topic, so it's okay now.
Linux builds packager
聞くのは一時の恥、聞かぬのは一生の恥
User avatar
SATtva
Developer
 
Posts: 5546
Joined: Tue Apr 07, 2009 12:19 pm
Location: from Siberia with love

Re: ASM vs C

Postby tomb » Sun Aug 08, 2010 6:25 am

I agee with SATTva, lets try to keep the forum threads nice and tidy :)

On topic: I did write a simple raytracer in Motorola 68000 once upon a time (on the Amiga in the late 80s)- it had only sphere primitives, but it was several orders of magnitude faster than the Amiga Basic version. These days, writing efficient assembly code is no walk in the park - what with RISC microarchitectures, out of order execution etc. Pure legacy x86 is pretty straight forward though, though not portable obviously. I think it's better to focus on making the algorithms friendly towards modern microarchitectures and optimizing compilers.
User avatar
tomb
Developer
 
Posts: 1942
Joined: Thu Oct 11, 2007 4:23 pm
Location: Oslo, Norway

Re: ASM vs C

Postby losbellos » Sun Aug 08, 2010 8:16 am

well, on amiga everybody used assembly even kids, since the basic is very very slow.
But assembly and c compared.... There is not that much difference I think.
If let say the code would run 50% faster then it migght be that it would be interesting to do some more important parts in assembly.
losbellos
 
Posts: 783
Joined: Wed Jun 24, 2009 4:59 am

Re: ASM vs C

Postby jeanphi » Sun Aug 08, 2010 9:00 am

Hi,

Modern processors are extremely complex beasts with out of order scheduling, instruction/data caches management on die, huge pipelines, ... which makes writing optimized assembly by hand a daunting task. If you add to the mix that the algorithms we're dealing with are extremely complex to expres even in high level languages, then it's often better to write in a high level language and when the code is mature enough, you can try to hand optimize some critical spots.
However knowing ASM and the basics of processors and compilers helps a lot writing efficient code.

Jeanphi
jeanphi
Developer
 
Posts: 6624
Joined: Mon Jan 14, 2008 7:21 am

Re: ASM vs C

Postby Lord Crc » Sun Aug 08, 2010 10:32 pm

I wrote quite a lot of asm code for the 486 and pentium. Some years ago I wanted to optimize a graphics routine and wrote some 300 lines of careful assembly code by all the rules I knew, even having read the intel optimization guide to get the latest tricks.

The result was 10% slower than what the Delphi compiler produced...

So yeah, as jeanphi said, it's very difficult to write significantly better asm code than what the modern compilers can produce. Especially if you have learned your compiler and know how to write "optimizable" code, which I had with the Delphi compiler.
May contain traces of nuts.
User avatar
Lord Crc
Developer
 
Posts: 4518
Joined: Sat Nov 17, 2007 2:10 pm

Re: ASM vs C

Postby dougal2 » Mon Aug 09, 2010 9:32 am

[moved to off-topic forum too]
User avatar
dougal2
Developer
 
Posts: 3075
Joined: Mon Jan 14, 2008 7:21 am


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 1 guest