What's new

x86 Code Optimization

blueshogun96

A lowdown dirty shame
Hey everyone, I was wondering if anyone could point me in the right direction to some tutorials and/or documents on optimizing C/C++ code with MMX, SSE, SIMD instructions? I searched google, but modt of the information i found pertained to pure assembly.
 

Cyberman

Moderator
Moderator
one thing I should mention Microsofts optimizations for these particular instructions aren't very good. In fact they are horrible. If you plan on the MMX instructions being in a loop consider using ASM only otherwise you will get nasty gotcha's from Microsoft's compilor.

Cyb
 

smcd

Active member
Cyberman said:
one thing I should mention Microsofts optimizations for these particular instructions aren't very good. In fact they are horrible. If you plan on the MMX instructions being in a loop consider using ASM only otherwise you will get nasty gotcha's from Microsoft's compilor.

Cyb

Agreed, MMX/SSE/SSE2 from MS's compiler (tried VC++2003) is icky.
 
OP
blueshogun96

blueshogun96

A lowdown dirty shame
Cyberman said:
one thing I should mention Microsofts optimizations for these particular instructions aren't very good. In fact they are horrible. If you plan on the MMX instructions being in a loop consider using ASM only otherwise you will get nasty gotcha's from Microsoft's compilor.

Cyb
Hmm. Is that so? Ok. But how can I use ASM files in a VS 2003 project?
 

Cyberman

Moderator
Moderator
I believe you can use it inline, there are some things you need to be careful with in dealing with MMX etc code. FIRST you must at the end SWITCH back to FPU register usage or the CPU's behavior will invoke an deadly embrace problem if it hits an FPU instruction mix.
I recomend grabing AMD's instruction reference it's what I used to mess with MMX instructions (and it certain made more sense that Intels poo of a manual). Be sure to remember how parameters are passed and if they are by reference or value. I don't recomend passing any C++ objects unless you are a glutton for severe traumatic punishment.
Code:
asm
{
}
I believe it's been a few years for moi :D

You could look at the VirtualDub source to find examples of it.


Cyb
 

smcd

Active member
The assembly doesnt have to be inline even. You can use ml to assemble MASM-style assembly, or you can define a custom build step to use nasm to assemble some source too.
 

Falcon4ever

Plugin coder / Betatester
we need samples people!!! :p
I wanted to learn programming ASM a few months ago, so I looked up what the easiest way was and in my case it was inline asm. But I've been very curious about how to do it the other ways :)

edit/note @ sethmcdoogle
I was doing it in MS VS2K5
 
Last edited:

smcd

Active member
Falcon4ever said:
we need samples people!!! :p
I wanted to learn programming ASM a few months ago, so I looked up what the easiest way was and in my case it was inline asm. But I've been very curious about how to do it the other ways :)

There are a couple emulators that do this (use assembly source files not just inline source) already, I forget the names - gens i think? Anyhow, let me get home from work and I'll make a very crude example project (VC++ 2003 is the only MS compiler I have currently).

EDIT: OK, see crappy attached project using custom build steps to assemble (using ml.exe) and link (using link.exe) an assembly file in a project and presto, it's a crappy demo for VC++ 2003!
 
Last edited:
OP
blueshogun96

blueshogun96

A lowdown dirty shame
Hey, sorry it's been so long since I replied to your post. Getting online has been nothing but a b@#%& lately. Thanks for your code example. I really learned alot from it. :arabia:

I've been wanting to learn how to do this for ages now.
 

Runik

Saturnin forever !
IIRC ZSnes is done in assembly, and only uses C for some GUI parts ...
Browse their CVS files on SourceForge to get an idea of their work ;)

On my own project I'm using inline assembly for some critical parts, and some naked assembly functions too (mainly for a future dynarec implementation :p )
 

smcd

Active member
I was trying for simple examples to not overwhelm people but yeah zsnes was another project that came to mind
 

Top