News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Optimisation

Started by jj2007, September 10, 2023, 10:58:08 AM

Previous topic - Next topic

NoCforMe

One thing from the article (just started skimming it):

QuoteOne thing to keep in mind is that the CPU is no longer the CPU you think it is. While the x86 instruction set used to directly control the processor, today it's just a compatibility shim. Under the covers, the CPU is converting your assembly into its own microcode and it's that microcode which is doing the real work.

But but but ... hasn't this been true since ... a long time now? I don't think this is really saying much, in that assembly language is still the lowest level at which we (programmers) can access any CPU. I mean, we can't code in microcode, right? We can only anticipate and try to utilize its effects, like caching and branch prediction if we're interested in optimization.

I've always been curious about microcode, btw: is it possible to actually see what the microcode is, say for x86, or is it some closely-guarded industrial secret? I'd be very interested to see what these instructions actually look like, if anyone has access to that info.
Assembly language programming should be fun. That's why I do it.

daydreamer

Isn't creating your own circuit that adds,subtract lowest level?
Did that as exercise when digital electronic class
First add circuit,followed by combine with  Neg circuit = sub circuit,microcode on first generation microcode cpu's?
NoCforMe isn't your 64 bit div code closest thing to code microcode?  And old cpu mul proc, when it lacks that opcode?

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: NoCforMe on September 10, 2023, 12:00:14 PMI mean, we can't code in microcode, right? We can only anticipate and try to utilize its effects, like caching and branch prediction if we're interested in optimization.

I've always been curious about microcode, btw: is it possible to actually see what the microcode is, say for x86, or is it some closely-guarded industrial secret? I'd be very interested to see what these instructions actually look like, if anyone has access to that info.

Coding in microcode would require
a) an entirely new, and much bigger, instruction set
b) that the cpu would interpret what it finds in memory as microcode, i.e. some special prefix?

Btw it's optimising in Europe, India, Australia and most other states. Try googling site:quora.com "American English" - About 247,000 results

NoCforMe

Quote from: jj2007 on September 10, 2023, 06:13:47 PMCoding in microcode would require
a) an entirely new, and much bigger, instruction set
b) that the cpu would interpret what it finds in memory as microcode, i.e. some special prefix?

Yes, I understand that. I said I was curious about microcode, not that I was interested in actually using it to code, which would be absurd (and horrendous, I'm sure). I still am curious. Is it possible to see what microcode actually looks like? (Thinking Intel/AMD here.)
Assembly language programming should be fun. That's why I do it.

mikeburr

if you want to get a lot closer to the heart of the machine get yourself a Xilinx FPGA [other brands are available] board ...
regards mikeb

NoCforMe

Um, that's a little closer than I care to get. But let me ask you: is any of this microcode published anywhere? If so, do you know where I can take a peek at it? Or is it considered top-sekrit©® proprietary info?
Assembly language programming should be fun. That's why I do it.

FORTRANS

Hi,

   Actual microcode would probably require employment
at a chip maker.  Given past actions, searching academia
would seem your best bet.  Though you might end up with
some sort of RISC rather than speculations on micro-coding
of a CISC instruction set.  If you find something, let us
know.

Regards,

Steve N.

NoCforMe

"Actual microcode would probably require employment at a chip maker."

Yes, you'd think, but no: I actually found some posted online. (Decided to get un-lazy and do my research.) Here's what I found:

Disclaimer: Although I did find microcode, it should be understood that this is an academic exercise only. It really is of no practical use to us programmers; we can't get access to it inside any processor (at least so far as I know, or perhaps very indirectly). The example here is from an ancient microprocessor, not one in current use. It also is not in an easily understood format. It is, however, a fascinating subject.

I found this page, where a guy shows us incredibly detailed pictures of the die of a microprocessor (8086) that he exposed by etching away parts in acid!, then doing photomicrography on it. Check out these pictures and his description.

From these images, he was able to trace the operation of the microcode ROM which was part of that chip (yes, even back then in the 1980s, μprocessors used microcode, contrary to some of what you read).

This person actually went so far as to "disassemble" that (8086) microcode. (It turns out that that microcode was actually published in a patent application that Intel filed for that chip.) I downloaded a .zip archive with the microcode. Here's a sample:

000 A CD F H J L  OPQR  U      R    -> tmpb      4  none  WB,NX      0100010??.00  MOV rm<->r
001  B  E GHI  L  OPQR          tmpb  -> M        4  none  RNI                     
002 ABC  F HI  LM O QRSTU                          6  W    DD,P0                   
003  CD FG IJ L N    TU      IJ    -> tmpa      5  UNC  EAOFFSET                  [SI]
004 AB  E  HI  L  OPQR          IND  -> R        4  none  RNI        010001101.00  LEA
005                                                                                   
006                                                                                   
007                                                                                   
008  CD F  J  MN  R          M    -> tmpa      1  XI    tmpa        000???0??.00  alu rm<->r
009 A CD F H J L  OPQR  U      R    -> tmpb      4  none  WB,NX                   
00a  B  EF  I KL  OPQR          SIGMA -> M        4  none  RNI      F               
00b ABC  F HI  LM O QRSTU                          6  W    DD,P0                   
00c A C E  HIJ    P  T        Q    -> tmpbL    0  L8      2        0100000??.00  alu rm,i
00d ABC E  HIJ L  OPQRSTU      Q    -> tmpbH                                       
00e  CD F  J  MN  R  U      M    -> tmpa      1  XI    tmpa, NX                 
00f  B  EF  I KL  OPQR          SIGMA -> M        4  none  RNI      F               

Of course, I can't make head nor tail out of this funky collection of symbols, but if you were diligent you could figure it out.

Now, as Raymond Chen likes to add at the end of his posts, bonus chatter:
Did you know that the entire x86 line of processors, all the way up to the latest and greatest that we're using right now, bear a striking family resemblance to the Datapoint 2200 minicomputer from the 1960s? I didn't. For one thing, it's why we do things the little-endian way.

(This person, Ken Shirriff has one of the most well-written blogs I've ever had the pleasure to read. Lotsa fascinating computah stuff.)


Assembly language programming should be fun. That's why I do it.

Caché GB

Apparently it is possible to extract the µCode for RISC.

Christopher Domas demonstrates the process in this video at DEF CON on YouTube
https://www.youtube.com/watch?v=jmTwlEh8L7g

His repository
github.com/xoreaxeaxeax

I think he was a member here.
https://masm32.com/board/index.php?msg=354

I hear he now works for Intel.
Caché GB's 1 and 0-nly language:MASM

NoCforMe

Assembly language programming should be fun. That's why I do it.

jj2007

Wow indeed, very interesting, thanks Caché & NoCforMe :thumbsup:

Biterider

Very interesting and scary at the same time.

Biterider

zedd151

With the video, this topic has unintentionally taken a hard left turn. I would advise to refrain from openly talking about certain specifics from the video, as it may attract the wrong type of attention to the forum.  :wink2: 
Interesting stuff there, nonetheless.

jj2007

Quote from: zedd151 on September 14, 2023, 10:51:08 PMI would advise to refrain from openly talking about...

Normally, I never look at long videos, but now you've got my full attention :biggrin: