jerryscript-project / jerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.
https://jerryscript.net
Apache License 2.0
6.96k stars 673 forks source link

Feature, Use JERRY_NUMBER_TYPE_FLOAT64 to guard arithmetic with double only, always storage float as FLOAT64 #5174

Open lygstate opened 3 days ago

lygstate commented 3 days ago

Currently, the JERRY_NUMBER_TYPE_FLOAT64 == 0 have too much drawback because it's can not represent full int32_t, so indeed all bitwise operation is invalid when JERRY_NUMBER_TYPE_FLOAT64 == 0, if JERRY_NUMBER_TYPE_FLOAT64 is not for save memory, then we can use float do arithmatic but use double do storage.

From my point of view, ECMA_TYPE_FLOAT = 2, /**< pointer to a 64 or 32 bit floating point number */ can not save memory memory, because the minimal alignment of pointer is 8, so the size of allocated address minimal is 8, the JERRY_NUMBER_TYPE_FLOAT64 == 0 can not save memory, only increase performance.

So my will is only use JERRY_NUMBER_TYPE_FLOAT64 == 0 to do floating arithmetic, but use double to do storage.

ossy-szeged commented 3 days ago

The original goal of JERRY_NUMBER_TYPE_FLOAT64 == 0 build configuration is supporting platforms which doesn't have hardware accelerated double precision floating point support. For example ESP32 has only single precision floating point support, using double numbers can be done only with softfp, which is significantly slower. Of course, this configuration has drawbacks, for example loosing ECMAScript compatibility, many features, etc.

lygstate commented 3 days ago

compatibility

If that's only for platforms which doesn't have hardware accelerated double precision floating point support. then we only need use float do arithmetic and use double for storage, that is when double + dobule we can convert to float + float and then save the result back to double, that will significantly simplfy the code and more ECMAScript compatibility without performance penalty on ESP32, as we won't use softfp do double + double double-double double*double double/double. And convert double to float or convert float to double is fast without hardware fp

I have the will do sumbit a MR for that, I need to know if this is the right direction and acceptable

LaszloLango commented 23 hours ago

Sounds good to me, but I can speak only for myself.

LaszloLango commented 23 hours ago

CC: @zherczeg @akosthekiss @robertsipka

zherczeg commented 23 hours ago

This is an outdated feature from ES 5.1. Since that JS become far more complex. If somebody needs float, probably an old, ES 5.1 version of the engine is enough. From newer versions, this feature could be deleted.

lygstate commented 19 hours ago

This is an outdated feature from ES 5.1. Since that JS become far more complex. If somebody needs float, probably an old, ES 5.1 version of the engine is enough. From newer versions, this feature could be deleted.

OK let's me delete it first