Live data from Hacker News

ARM chips have an instruction with JavaScript in the name

stackoverflow.com

21–30 of 312 posts

Re: ARM chips have an instruction with JavaScript in the name

#21
post #12

So it was easier to add an instruction in silicon to cater for an ill-designed programming language, than to change the language itself? I mean, if float-to-integer performance is so critical, why was this not fixed a long time ago in the language ? What am I missing?

> What am I missing?

I guess the incredibly long tail of JavaScript deployments. You could change the language today and it would take years for it to percolate down to all the deployments out there. By comparison a silicon change requires zero code changes and is entirely backwards compatible. Plus there's a pretty simple marketing argument: "buy our CPU, it makes commonly-encountered workloads faster", vs "buy our CPU, when everyone upgrades the platform they use it'll be faster"

Re: ARM chips have an instruction with JavaScript in the name

#22
post #5
post #4

Earlier quoted context omitted.

No it doesn’t, it’s still surprising to see a CPU instruction added specifically to cater for such a high level language like JS. It does totally makes sense though, given the importance of JS and it’s common use in mobiles.

> No it doesn’t, it’s still surprising to see a CPU instruction added specifically to cater for such a high level language like JS. It surprises you personally, but if you think about it it's easy to understand that widespread interpreters that use a specific number crunching primitive implented in software can and do benefit from significant performance improvements if they offload that to the hardware. You only nee…

Considering that JS is JIT-compiled and doesn't have an integer type, this is not suprising to me at all.. (but still interesting)

Re: ARM chips have an instruction with JavaScript in the name

#23
post #13
post #4

Earlier quoted context omitted.

No it doesn’t, it’s still surprising to see a CPU instruction added specifically to cater for such a high level language like JS. It does totally makes sense though, given the importance of JS and it’s common use in mobiles.

Not surprising to me to see CPU instructions being added for widely used use cases. Basically, a CPU instruction set maker's job is to perform clustering of the tasks that the CPUs do and accelerate commonly used tasks. If people do a lot of AES, the instruction set maker adds AES extensions. If people do a lot of CRC, they add CRC instructions. If people convert doubles to integers all day in a very JS specific way,…

Can you name any other instructions with the name of a programming language in the actual instruction name?

No? Then it seems way more specific than the other examples you listed. So specific that it’s only applicable to a single language and that language is in the instruction name. That’s surprising, like finding an instruction called “python GIL release”.

Re: ARM chips have an instruction with JavaScript in the name

#24
post #3

FTA: > Which is odd, because you don't expect to see JavaScript so close to the bare metal. This seems to ignore all the work done on server-side javascript with projects such as node.js and deno, as well as the fact that cloud service providers such as AWS have been developing their own ARM-based servers.

Just because a language is used on servers / at scale / in enterprise, doesn't make it any closer to the metal. I mean, look at Python, Java, or Ruby: All used on servers for "serious" applications, but certainly not any sort of "bare metal" languages still.

Re: ARM chips have an instruction with JavaScript in the name

#25
post #12

So it was easier to add an instruction in silicon to cater for an ill-designed programming language, than to change the language itself? I mean, if float-to-integer performance is so critical, why was this not fixed a long time ago in the language ? What am I missing?

> What am I missing?

ARM wants to be appropriate for more workloads. They don't want to have to wait for software to change. The want to sell processor designs now.

Re: ARM chips have an instruction with JavaScript in the name

#26
post #17
post #12

So it was easier to add an instruction in silicon to cater for an ill-designed programming language, than to change the language itself? I mean, if float-to-integer performance is so critical, why was this not fixed a long time ago in the language ? What am I missing?

Consider Node JS is a top server side language, and arm for data centers is coming ( to the extent it's not already here), this makes sense. Technically someone can just make a better VM engine for JavaScript to execute inside of, but whatever I guess they decided this would be easier.

I'd say JS on the mobile ARM devices is 10.000x more common, and thus important, than the NodeJS on ARM servers.

Re: ARM chips have an instruction with JavaScript in the name

#27
post #16
post #7

My guess is that this is what JIT people asked for.

Don't sufficiently advanced compilers infer what the real type of a variable is, in the most important cases?

First comment on question: “The JavaScript engine has to do this operation (which is called ToInt32 in the spec) whenver you apply a bitwise operator to a number and at various other times (unless the engine has been able to maintain the number as an integer as an optimization, but in many cases it cannot). – T.J. Crowder”

Edit: From https://www.ecma-international.org/ecma-262/5.1/#sec-9.5

  9.5 ToInt32: (Signed 32 Bit Integer)

  The abstract operation ToInt32 converts its argument to one of 2 integer values in the range −2³¹ through 2³¹−1, inclusive. This abstract operation functions as follows:

  Let number be the result of calling ToNumber on the input argument.
  If number is NaN, +0, −0, +∞, or −∞, return +0.
  Let posInt be sign(number) * floor(abs(number)).
  Let int32bit be posInt modulo 2³²; that is, a finite integer value k of Number type with positive sign and less than 2³² in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 2³².
  If int32bit is greater than or equal to 2³¹, return int32bit − 2³², otherwise return int32bit.

  NOTE Given the above definition of ToInt32:

    The ToInt32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.

    ToInt32(ToUint32(x)) is equal to ToInt32(x) for all values of x. (It is to preserve this latter property that +∞ and −∞ are mapped to +0.)

    ToInt32 maps −0 to +0.

Re: ARM chips have an instruction with JavaScript in the name

#28
post #19

It seems like every 2 months I feel the burn of JS not having more standard primitive types and choices for numbers. I get this urge to learn Rust or Swift or Go which lasts about 15 minutes... until I realize how tied up I am with JS. But I do think one day (might take a while) JS will no longer be the obvious choice for front-end browser development.

With WebAssembly that day is nearing. However it is certainly many years out.

Re: ARM chips have an instruction with JavaScript in the name

#29
post #19

It seems like every 2 months I feel the burn of JS not having more standard primitive types and choices for numbers. I get this urge to learn Rust or Swift or Go which lasts about 15 minutes... until I realize how tied up I am with JS. But I do think one day (might take a while) JS will no longer be the obvious choice for front-end browser development.

Are you saying you'd like to have specific int32, int64, float32, float64 types?

Re: ARM chips have an instruction with JavaScript in the name

#30
post #19

It seems like every 2 months I feel the burn of JS not having more standard primitive types and choices for numbers. I get this urge to learn Rust or Swift or Go which lasts about 15 minutes... until I realize how tied up I am with JS. But I do think one day (might take a while) JS will no longer be the obvious choice for front-end browser development.

You could split the difference and go C# or Java and use one of their web stacks.
Post reply on HN