Thread: Inlining Assembly for PPC440GX

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    19

    Question Inlining Assembly for PPC440GX

    Does anyone have an example of how to inline Assembly instructions for PPC440GX processor?

    Thanks,

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's compiler-specific.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    19
    ok, how about for gcc compiler?

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    If you understand what you're doing, you're not learning anything.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Similarly, you also then need to search for some processor reference manuals so you know what opcodes to use, what the names of the registers are etc etc.

    Or maybe you can tell us why you feel the need for assembly language at all?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    19
    There is an assembly instruction in PPC440GX manual, that counts leading 1's and 0's of any unsigned long integer.
    My boss asked me to research this posibility, so that we do not write a separate "C" routine with a loop that would count leading 1's.
    With this implementation I'll have just 3 instructions excecuted once, instead of 4 instructions excecuted up to 32 times.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Ah, good old premature optimisation at work.
    Have you done any profiling to determine just how significant this particular part of the problem is?

    How about looking at this thread for more ideas without having to resort to assembler just to get at an instruction which will only save a small amount of time.

    > instead of 4 instructions excecuted up to 32 times.
    Or how about two comparisons and up to 8 times - any better?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    19
    If you disassembled that piece of code, it would turn out to be more than just 2 comparisons up to 8 times.
    In addition to setting up the variables, and the loop, there are 2 increments, a shift, and a 2 compare. While it looks pretty in C, it is still quite inefficient when compared to the 1 specialized assembly instruction that does exactly what I am looking for.

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Um....then read the manual for the processor. It's not like we have every processor's opcodes memorized. The processor manual should show you everything you need to know including instruction timings and so forth.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You have code which works - stop worrying about it and work on another part of the project thats not implemented yet, or has bugs, or needs more features, or is far more time critical than this.

    How many hours / days / weeks are you going to spend getting this 3-line assembler insert to work ?
    I'm guessing your 'cost' to the company - salary, taxes, insurance, overheads etc are somewhere between $50 and $100 per hour. They'll be the most expensive lines in the whole system - better put them in a nice frame and hang them on the wall for all to admire.

    > My boss asked me to research this posibility
    Say "yes it's possible, but it's going to be expensive".

    What you're not likely to get is a nice free lunch where someone takes the time to do your job of looking stuff up in the manual and reading a few howto's for your commercial benefit.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by edunia11
    While it looks pretty in C, it is still quite inefficient when compared to the 1 specialized assembly instruction that does exactly what I am looking for.
    But isn't that taking into account not using optimization? The compiler can probably optimize better than you could. Especially since you don't even know how to use it. Chances are you're better off optimizing something else - like an algorithm. You'd save a great deal more doing that than trying to optimize some little component.
    Last edited by Frobozz; 09-13-2006 at 02:15 AM.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The basic problem is he's let the PHB near the manual and he's gone "hey, what about ...."
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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. C to assembly interface
    By Roaring_Tiger in forum C Programming
    Replies: 4
    Last Post: 02-04-2005, 03:51 PM
  3. 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
  4. 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
  5. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM