Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Saturday October 31 2015, @03:33AM   Printer-friendly
from the A|Journey|Through|the|CPU|Pipeline dept.

It is good for programmers to understand what goes on inside a processor. The CPU is at the heart of our career.

What goes on inside the CPU? How long does it take for one instruction to run? What does it mean when a new CPU has a 12-stage pipeline, or 18-stage pipeline, or even a "deep" 31-stage pipeline?

Programs generally treat the CPU as a black box. Instructions go into the box in order, instructions come out of the box in order, and some processing magic happens inside.

As a programmer, it is useful to learn what happens inside the box. This is especially true if you will be working on tasks like program optimization. If you don't know what is going on inside the CPU, how can you optimize for it?

A primer for those with a less formal background.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by shortscreen on Saturday October 31 2015, @08:49AM

    by shortscreen (2252) on Saturday October 31 2015, @08:49AM (#256831) Journal
    This tedious code takes some bits out of a 32-bit word and packs them into a byte:
    lodsd
    mov ebx,eax
    mov edx,0x03
    shr ebx,6
    and edx,ebx
    mov eax,0x3C
    shr ebx,4
    and eax,ebx
    add edx,eax
    shr ebx,6
    mov eax,0xC0
    and eax,ebx
    add eax,edx
    stosb

    This shorter code which also uses fewer registers is faster on a 486 but slower on a Core 2:
    lodsd
    shr ah,4
    shr eax,6
    shl ax,10
    shl eax,14
    shr eax,24
    stosb
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2