Live data from Hacker News

Why those particular integer multiplies?

fgiesen.wordpress.com

11–20 of 39 posts

Re: Why those particular integer multiplies?

#11
post #8
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

SSE2 is a requirement for x86-64, which gives at least a reasonable(128bit wide SIMD) baseline. SSE4 is from 2008, so making it a requirement isn't unreasonable. Even AVX2 is from 2013, so some apps require it nowadays. It is extremely difficult for a compiler to convert scalar code to SIMD automatically, even static C++ compilers really suck at it. A dynamic compiler for javascript would have no real hope of any mea…

I still have an old Samsung that is from 2008 aproximately. The battery last like 10 minutes, a few keys are dead, the fan makes a weird sound, so it's 99.9% retired. I still use it every few years when I need an old version of MS Office.

Re: Why those particular integer multiplies?

#12
post #8
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

SSE2 is a requirement for x86-64, which gives at least a reasonable(128bit wide SIMD) baseline. SSE4 is from 2008, so making it a requirement isn't unreasonable. Even AVX2 is from 2013, so some apps require it nowadays. It is extremely difficult for a compiler to convert scalar code to SIMD automatically, even static C++ compilers really suck at it. A dynamic compiler for javascript would have no real hope of any mea…

other thing about avx2 is it gives you FMA because of the timing.

Re: Why those particular integer multiplies?

#14
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

> Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Mostly the former. Some highly optimized bits of software do the latter—they are built with multiple code paths optimized for different hardware capabilities, and select which one to use at runtime. > Do dynamic languages (Javascript, Python, PHP...) get a speed boost because they…

.NET/C# does pretty well with SIMD for a high level language, it has portable SIMD primitives which get JITed to whatever the system supports at runtime, and they're used quite extensively throughout the stdlib so you benefit even if you're not writing SIMD routines yourself.

They tried to do something similar in Javascript but it added way too much complexity to the runtimes and ended up getting dropped in favor of WASM SIMD.

Re: Why those particular integer multiplies?

#15
post #8
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

SSE2 is a requirement for x86-64, which gives at least a reasonable(128bit wide SIMD) baseline. SSE4 is from 2008, so making it a requirement isn't unreasonable. Even AVX2 is from 2013, so some apps require it nowadays. It is extremely difficult for a compiler to convert scalar code to SIMD automatically, even static C++ compilers really suck at it. A dynamic compiler for javascript would have no real hope of any mea…

The problem is that there were CPUs made well after 2008 that don't support SSE4. In particular, Phenom II was fairly popular, sold up until 2012, and doesn't even support SSSE3 (much less SSE4.1 and SSE4.2; only an AMD-specific variant known as SSE4a).

Re: Why those particular integer multiplies?

#16
I suspect Intel uses 32x32b multipliers instead of his theorised 16x16b, just that it only has one every second lane. It lines up more closely with VPMULLQ, and it seems odd that PMULUDQ would be one uOp vs PMULLD's two.

PMULLD is probably just doing 2x PMULUDQ and discarding the high bits.

(I tried commenting on his blog but it's awaiting moderation - I don't know if that's ever checked, or just sits in the queue forever)

Re: Why those particular integer multiplies?

#17
post #15
post #8

Earlier quoted context omitted.

SSE2 is a requirement for x86-64, which gives at least a reasonable(128bit wide SIMD) baseline. SSE4 is from 2008, so making it a requirement isn't unreasonable. Even AVX2 is from 2013, so some apps require it nowadays. It is extremely difficult for a compiler to convert scalar code to SIMD automatically, even static C++ compilers really suck at it. A dynamic compiler for javascript would have no real hope of any mea…

The problem is that there were CPUs made well after 2008 that don't support SSE4. In particular, Phenom II was fairly popular, sold up until 2012, and doesn't even support SSSE3 (much less SSE4.1 and SSE4.2; only an AMD-specific variant known as SSE4a).

The early Atoms too only supported up to SSSE3.

Re: Why those particular integer multiplies?

#18
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

> Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Mostly the former. Some highly optimized bits of software do the latter—they are built with multiple code paths optimized for different hardware capabilities, and select which one to use at runtime. > Do dynamic languages (Javascript, Python, PHP...) get a speed boost because they…

It's possibly worth mentioning that Java is getting a vector API which explicitly abstracts over some of the details of SIMD, including width. You have a type Vector which represents enough of some type T to fill a vector register (eg eight 32-bit numbers in a 256-bit register), operations on Vector which produce another Vector, and some way to break arrays up into Vectors of the right size for the platform. The API is a bit clunky, but you write code with it, the compiler performs a miracle, and efficient platform-specific vector code comes out.

https://docs.oracle.com/en/java/javase/23/docs/api/jdk.incub...

https://docs.oracle.com/en/java/javase/23/docs/api/jdk.incub...

Re: Why those particular integer multiplies?

#19
post #18

Earlier quoted context omitted.

> Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Mostly the former. Some highly optimized bits of software do the latter—they are built with multiple code paths optimized for different hardware capabilities, and select which one to use at runtime. > Do dynamic languages (Javascript, Python, PHP...) get a speed boost because they…

It's possibly worth mentioning that Java is getting a vector API which explicitly abstracts over some of the details of SIMD, including width. You have a type Vector which represents enough of some type T to fill a vector register (eg eight 32-bit numbers in a 256-bit register), operations on Vector which produce another Vector , and some way to break arrays up into Vectors of the right size for the platform. The API…

Though it's pretty much incubating forever, or until Valhalla, whichever comes first.

Re: Why those particular integer multiplies?

#20
post #5

How can software run on different CPUs when they support different operations? When you download "debian-live-12.7.0-amd64-kde.iso", all the programs in the repos support all current Intel and AMD CPUs, right? Do they just target the lowest common denominator of operations? Or do they somehow adapt to the operations supported by the user's CPU? Do dynamic languages (Javascript, Python, PHP...) get a speed boost becau…

> Or do they somehow adapt to the operations supported by the user's CPU?

This is called runtime dispatch. You can do it manually or use a library, like Google Highway. GCC supports multiversioning where you write separate versions of a function and the right one is selected at runtime.

https://github.com/google/highway

https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Function-Multiv...

Post reply on HN