Live data from Hacker News

How many x86 instructions are there? (2016)

fgiesen.wordpress.com

31–40 of 92 posts

Re: How many x86 instructions are there? (2016)

#31
post #4

I feel sudden urge to write some assembly for fun. Have not done it for at least a couple of years I think.

The assembly bug bit me again a few months back, but instead of writing it I had a grand time hand-disassembling some ARMv4T binaries - scratched something of the same itch as solving a sudoku.

Re: How many x86 instructions are there? (2016)

#32
post #29
post #23

Earlier quoted context omitted.

It's really more like 6000, if you do the accounting right. And, as someone who just ate a 2x (customer-facing) slow down porting a piece of x86 assembly to ARM, because that "one nifty instruction" was missing, I'm going to say: we should keep all of 'em.

Which one?

_mm256_movemask_epi8, i.e., the "fast lexer" instruction. That instruction takes ~3c (depending on uarch), and the ARM equivalent (7-8 instructions) takes ~5-6c (depending on uarch). It's just annoying.

Re: How many x86 instructions are there? (2016)

#34
post #15

> To not leave you hanging: Intel has an official x86 encoder/decoder library called XED. According to Intel’s XED, as of this writing, there are 1503 defined x86 instructions (“iclasses” in XED lingo), from AAA to XTEST (this includes AMD-specific extensions too, by the way). Straightforward, right? Hopefully this will have either saved you a click or validated your time in reading the article.

Curious, does anyone actually care about the actual number primarily? I thought pretty much everyone who clicks on an article with that title would do so because they are interested in the insights gathered when getting to that number.

If you are writing a disassembler or binary program decoder, such a number will help you be sure that you enumerate all the instructions.

Re: How many x86 instructions are there? (2016)

#35

Earlier quoted context omitted.

I've always been able to beat the compiler, and that's usually after trying to optimize using C. Admittedly, it's a whole lot harder to understand what's fast than it used to be. Access to SSE has it's own benefits. It's been a problem (optimizing) for some time though. I remember it being some work to beat the compiler on the i960CA. OTOH, I seem to remember the i860 being not-so-great and for sure the TI C80 C comp…

Back in the Pentium 1 and earlier days I could beat the compiler. But then it got hard. And it changes so often, instructions that are fast on one CPU are not so fast on the next one, and vice versa. Not to mention branch prediction and out-of-order execution makes it very difficult to meaningfully benchmark. Is my code really faster, or just seems like it because some address got better aligned or similar. I've gott…

>I've gotten significant speed gains in certain projects by simply replacing certain hand-optimized assembly in libraries (ie not my code) with the plain C code equivalent.

That's an interesting point, plus there's the portability issue.

My own breadcrumbs of legacy code for this kind of innerloopish stuff has been to write a straightforward 'C' implementation (and time it), an optimized 'C' version (which itself can depend on the processor used), and a handtuned assembly version where really needed.

It allows you to back out of the tricky stuff plus acts as a form of documentation.

Re: How many x86 instructions are there? (2016)

#36
post #32
post #29

Earlier quoted context omitted.

Which one?

_mm256_movemask_epi8, i.e., the "fast lexer" instruction. That instruction takes ~3c (depending on uarch), and the ARM equivalent (7-8 instructions) takes ~5-6c (depending on uarch). It's just annoying .

This instruction does quite a bit of leg work, and it becomes obvious why a RISK architecture would need 7-8 instructions to do the same, see: https://software.intel.com/sites/landingpage/IntrinsicsGuide...

Re: How many x86 instructions are there? (2016)

#37
post #9

More than 1,500! Holy cow! While having instructions for everything that are slow in early models but can be significantly improved in silicon over time is one way to look at CISC, I genuinely wonder how much silicon is spent on instructions that are so rarely used they'd be better in software. Or to ask another way: how many instructions are in billions of x86 cores that rarely if ever get used? Hmmm...

AMD Zen dropped a few instructions sets from the previous architecture.

FMA4 https://en.wikipedia.org/wiki/FMA_instruction_set#FMA4_instr...

XOP https://en.wikipedia.org/wiki/XOP_instruction_set

TBM https://en.wikipedia.org/wiki/Bit_manipulation_instruction_s...

Re: How many x86 instructions are there? (2016)

#38
post #27
post #18

Earlier quoted context omitted.

It's way easier to determine instruction length on ARM. It's usually fixed. That eliminates a lot of brute force thrashing that X86 decoders have to do. It doesn't impact transistor count all that much on a huge modern CPU but it saves a decent amount of power. It's one of the things that factors into why ARM is so power efficient. ARM has also been willing to drop older optional legacy stuff like Java oriented instr…

It's not that variable length is expensive, it's that variable length the way Intel does it is expensive. For instance — not that this is a good idea — you could burn the top 2b to mark instructions as 2/4/6/8 bytes (or whatever) in length. Then you can have your variable-width-cake-and-eat-your-fast-decode-too.

Variable length is always going to restrict the parralelism of your instruction decode (for a given chip area/power/etc cost).

Re: How many x86 instructions are there? (2016)

#39
post #7

How about undocumented instructions? Sandsifter[1] is an interesting project and the video from BlackHat[2] is a good watch. There's also a previous discussion of it on HN[3]. [1] https://github.com/Battelle/sandsifter [2] https://www.youtube.com/watch?v=KrksBdWcZgQ [3] https://news.ycombinator.com/item?id=18179212

yes and sansdifter are continue finding more, recent undocumented microcode modify instruction are find with it.

Re: How many x86 instructions are there? (2016)

#40
post #4

I feel sudden urge to write some assembly for fun. Have not done it for at least a couple of years I think.

Then when checking the results are half the speed of what the compiler spits out and the fun is gone. At least that's what happens to me...

For this case all fun is in the process ;)
Post reply on HN