3 ms·
Interesting. So it's as much an x86 legacy issue as JS and presumably JS followed x86 because it was more efficient to do so (or maybe by default). Sounds too
by klelatti 6y ago
Interesting. So it's as much an x86 legacy issue as JS and presumably JS followed x86 because it was more efficient to do so (or maybe by default).
Sounds too like performance gains will depend on how often the branch is taken which seems highly dependent on the values that are being converted?
- freeone3000 6y agoThe branch always has to be taken if executing JavaScript, because otherwise how would you tell if the value was correct or not? You'd have to calculate it using this method regardless and then compare!
- olliej 6y agoWhat are you defining as correct?
- freeone3000 6y ago"correct" in this case being consistent with the JavaScript specification.
- fred256 6y agoIf you always take a branch, it's not a branch. Or did you mean by "taken" that the branch instruction has to be executed regardless of whether the branch is taken or not?
- freeone3000 6y agoJavaScript JITs always emit this instruction when ToInt32 is required, since checking would be more expensive in user code. And the instruction always used the JS rounding method, since that's cheaper in silicon. I used branch since the parent used "branch".
- formerly_proven 6y ago> Interesting. So it's as much an x86 legacy issue as JS and presumably JS followed x86 because it was more efficient to do so (or maybe by default). Most languages don't start with a spec, so the semantics of a lot of these get later specced as "uhhhhh whatever the C compiler did by default on the systems we initially built this on".
- brundolf 6y agoSeeing as JavaScript was designed and implemented in two weeks, I'm betting this is the answer
- tekromancr 6y agoToday's JavaScript is so divorced, so radically different from the the original implementation to be considered a different language, though.
- monocasa 6y agoRounding mode was defined then and hasn't changed since though.
- goatlover 6y agoIsn’t modern JS backward compatible with 1.1?
- domenicd 6y agoMostly. See https://tc39.es/ecma262/#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions https://tc39.es/ecma262/#sec-additions-and-changes-that-intr... for a comprehensive list of backward-incompatible changes in the spec. Using that list to answer your question is a bit tricky, since it also includes backward-compatibility breaks with newer features. But, e.g., > In ECMAScript 2015, ToNumber applied to a String value now recognizes and converts BinaryIntegerLiteral and OctalIntegerLiteral numeric strings. In previous editions such strings were converted to NaN. and > In ECMAScript 2015, the Date prototype object is not a Date instance. In previous editions it was a Date instance whose TimeValue was NaN. sound like backward-incompatible changes to a JS 1.1 behavior. Another notable example is the formalization of function-in-block semantics, which broke compatibility with various implementations in order to find a least-bad compromise everyone could interop on. I'm not sure if JS 1.1 even had blocks though, much less functions in blocks...