facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.38k stars 24.25k forks source link

[android 32bit build] issues with mathematical calculation #26685

Closed AdamChlupacek closed 4 years ago

AdamChlupacek commented 4 years ago

Hello,

I have recently upgraded my RN application from RN 54.4 to 61.1. The application now works great in the 64 bit version, but on 32 bit version I am having issues with mathematical calculations at random times.

React Native version: 61.1 System: OS: macOS Mojave 10.14.5 CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz Memory: 1.99 GB / 32.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 12.10.0 - /usr/local/bin/node npm: 6.11.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 Android SDK: API Levels: 23, 25, 26, 28 Build Tools: 23.0.1, 25.0.0, 25.0.1, 25.0.2, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.2, 28.0.3 System Images: android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 10.2/10E125 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.1 => 0.61.1 npmGlobalPackages: react-native-cli: 2.0.1 react-native: 0.61.1

Steps To Reproduce

Run following code on 32bit platform

for (var idx = 0; idx < 10000; idx++) {

    var hash = 2026056511
    var level = 0
    var bitmap = -128083075

    var index = (31 & ((hash >>> level) | 0));
    var mask = (1 << index);

    var i = (bitmap & (((-1) + mask) | 0));
    var t1 = ((i - ((i >> 1) & 1431655765)) | 0);
    var t2 = (((t1 & 858993459) + ((t1 >> 2) & 858993459)) | 0);
    var offset = ($imul(16843009, (252645135 & ((t2 + (t2 >> 4)) | 0))) >> 24)

    console.info("XXXXXO wrong offset", offset);
}

You will see that the print will output either 20 or 21, and the values change as the loop is performing. I have inseted this sniped just before the end of the index.js

Describe what you expected to happen:

I would expect that the calculation would output the same results for the same inputs.

AdamChlupacek commented 4 years ago

Forgot to add the $imul implementation

var $imul = Math.imul || (function(a, b) {
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
  var ah = (a >>> 16) & 0xffff;
  var al = a & 0xffff;
  var bh = (b >>> 16) & 0xffff;
  var bl = b & 0xffff;
  // the shift by 0 fixes the sign on the high part
  // the final |0 converts the unsigned value into a signed value
  return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0) | 0);
});
stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.