Closed Alain2019 closed 3 years ago
The c++ compiler automatically optimized these integer divisions to shift operations, so changing "x / 16" to "x >> 4" produces the same runtime code. I haven't checked to see if all values remain in range for the variables you changed from 64 to 32 bit; but they are temporary variables inside of functions so the space lost/gained is only temporary during the execution of the routines so I am not certain that the gains are worth it.
The c++ compiler automatically optimized these integer divisions to shift operations, so changing "x / 16" to "x >> 4" produces >the same runtime code.
Those changes where for clarity, when bitshifting it's clearer to use the bit shift operators.
I haven't checked to see if all values remain in range for the variables you changed from 64 to 32 bit; but they are temporary >variables inside of functions so the space lost/gained is only temporary during the execution of the routines so I am not certain >that the gains are worth it.
There won't be a space advantage, but 64-bit operations are normaly a lot more time consuming that 32-bit operations.
I see your point about bit-shifting rather than multiplying and dividing. I'll change the corresponding locations directly in version 10 under development. But I still see some multiplying that might exceed the 32-bit values, so I'll take a look at that separately.
But I still see some multiplying that might exceed the 32-bit values, so I'll take a look at that separately.
I've checked with either the Bosch library, that only uses 64-bit for some measurements and 32-bit for others.
The changes are to the temp calculation, that could have needed 64-bit at the start with 1 or 2 bits. I moved a >>4 to the first calculation, which would be enough.
I've added issue #34 with 2 additions that cover what changes you made, plus integrated the changes in computation to the source code; there would have been too many many changes to this pull request
readout sensor registers : use bit shift instead of * / temp sensor compensation changed shift's so that 32-bit variables can be used --> less use off 64-bit
results are the same