Thread: first look incorporate assembly?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    82

    first look incorporate assembly?

    Hi,

    I wanted to take a first look into how I might incorporate some assembly into my matrix handling c programs.

    Obviously the motivation is to achieve high performance, but I'm possibly being a bit naive about it. Scrub the possibly.

    Don't know where to start, wouild appreciate any pointers or links from anybody who might have also considered it in the past.


    Sorry for not being more specific. Googling while writing this. Cheers.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    First off: I am a fan of the MASM32 manual for some basics on how to program in assembler. Secondly, do you think your hand written assembler code will be better than your compiler's generated code? If so, more power to you. But sometimes it doesn't hurt to just have your compiler spit out the assembly language version of your output just to see what it did. In actuality, it may be a good starting place for you to make your hand-written optimizations.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    great suggestions master5001 ... on them right away ... need no more. Cheers!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What processor and OS are you using?

    If it is x86[-32, -64] from either Intel or AMD, you may want look at using ACML (AMD Core Math Library). It is highly optimized using all sorts of tricks, including assembler code - and as opposed to Intel's libraries, it actually works well on BOTH AMD _AND_ Intel processors [Intel checks the ID of the CPU, and if it's not an Intel processor, it bails out before you get any calculation done, or possibly it runs the slowest possible version in some cases].

    I promise you that you will have to either "know something more about the problem" [1] or be extremely good at optimizing before you beat the ACML code - it is written by people who spend their entire day optimizing matrix calculations.

    [1] Meaning, that you know that certain calculations can be skipped all together or some such, even if that isn't the case for the generic calculations.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah matsp addresses a couple of points since you may even wish to take advantage of SSEx which are not exactly instructions on every single chip known to man. Plus for all I know you are trying to show us what your MIPS is really made of and hand optimize your program... MASM is not necessarily the best compiler, by the way. And its manual is going to show you a lot of important considerations that apply to all assembler code, however keep in mind that it may not be the compiler that you will ultimately use, thus syntax may change. Assembly language is NOT C. All this portable mumbo jumbo stuff you hear about are the things that C really does a great job of taking care of behind the closed doors of your compiler.

    Not every processor uses the same opcodes and not every processor reads instructions in the same way. So your C compiler does a whole heck of a lot to make your code work for your machine while you may not even put much thought into whether or not your processor supports SSE2 or SSE3.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    many thanks matsp and master5001.
    That's plenty to be going on with. I appreciate it.
    Didn't know about the ACML .. yet another toy!
    Matrices, that's my thing (at the moment) - I 'd also point out that despite continuing work in this area, _and_ using much more powerful computers .. everybody seems, at some point or another, to lean on the nearly three decades old BLAS!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by stabu View Post
    many thanks matsp and master5001.
    That's plenty to be going on with. I appreciate it.
    Didn't know about the ACML .. yet another toy!
    Matrices, that's my thing (at the moment) - I 'd also point out that despite continuing work in this area, _and_ using much more powerful computers .. everybody seems, at some point or another, to lean on the nearly three decades old BLAS!
    Yes, BLAS is the fundamentals of ACML too. I think the reason for that is twofold:
    1. Everyone (at least those who understand these sort of things at all) knows how it works, and that it works. If you replace BLAS with something else, you need to first prove that it does the right thing, then convince other people that the new solution is at least as good as the old one.

    2. BLAS has pretty decent performance if you use an optimized variant of it - after all, it has had 30 years of programmers finding ways of making it faster.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    that'd be ATLAS you're referring to matsp, I guess.
    you need to first prove that it does the right thing, then convince other people that the new solution is at least as good as the old one.
    excellent and very useful insight.

    However, I didn't think the base BLAS had been changing all this time ...I'd better look it up.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by stabu View Post
    that'd be ATLAS you're referring to matsp, I guess.

    excellent and very useful insight.

    However, I didn't think the base BLAS had been changing all this time ...I'd better look it up.
    I was referring to BLAS, which is a part of ACML.

    The functions that are part of BLAS in functionality hasn't changed. How those functions are implemented / optimized does change as new processors, compilers and ideas of how to make them more efficient come around. There are few, if any, new functions added to the original BLAS (as I understand it), but that's not to say that the internals of the functions can't be improved based on modern techniques such as SIMD (SSE) instructions, cache-prefetchin, loop unrolling and other things that either didn't exist or wasn't feasible 5-10-20-30 years ago.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Assembly
    By mrafcho001 in forum Tech Board
    Replies: 5
    Last Post: 03-12-2006, 05:00 PM
  2. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM
  5. How can I incorporate Assembly code in my C++ program.
    By bman1176 in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2001, 10:58 AM