Results 1 to 3 of 3

Thread: Questions about code efficiency

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Questions about code efficiency

    1. Does anyone have a list of opcodes along with the number of clock cycles they use up?

    2. When comparing speeds of code, is it enough to just compare the number of clock cycles that each instruction takes? Or is it more complex than that (I'm talking about instruction-by-instruction comparison at the moment, not looping or anything I realise that makes things infinitely more complex).

    3. For things like shifting does shifting by 25 bits (for example) take the same time as shifting by 1 bit? Or is it 25 times longer?

    I'm used to High level languages as you can probably tell and I'm finding it difficult to comprehend the speed of ASM.

    ("Damn this thing its not working, it just returns immediately!! Oh wait its finished already, bloody hell" )
    I don't live here any more.

  2. #2
    Addicted Member
    Join Date
    Aug 2005
    Location
    York
    Posts
    197

    Re: Questions about code efficiency

    1. Does anyone have a list of opcodes along with the number of clock cycles they use up?
    I do.....
    http://www.agner.org/assem/pentopt.pdf
    http://www.intel.com/design/pentium4...tm#em64_doc_ch
    These are everything you need...unless you want the AMD versions...which you can find on their website.

    2. When comparing speeds of code, is it enough to just compare the number of clock cycles that each instruction takes? Or is it more complex than that (I'm talking about instruction-by-instruction comparison at the moment, not looping or anything I realise that makes things infinitely more complex).

    More complex. You have cache misses, memory reads/writes, dependencies etc. (Read pentopt.pdf)

    3. For things like shifting does shifting by 25 bits (for example) take the same time as shifting by 1 bit? Or is it 25 times longer?
    Same speed.
    e.g.
    shr eax, 5 = shr eax, 25
    however
    rol, rot might be different i believe.

    So it depends on the instruction. but generally they are the same provided that the type of operand is the same e.g. add eax, [mem] will be slower than add eax, ebx

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Questions about code efficiency

    Nice one thanks (again )
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width