Re: ARM modulo operator corrupted result?

  • From: Mike Pall <mikelj-1512@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 29 Dec 2015 22:21:30 +0100

Ben Garney wrote:

We're experiencing what seems to be buggy behavior with the modulo operator
(%) on ARM devices.

Are you 100% sure it's only the modulo operator? Because it looks
like a calling convention issue and that might affect quite a few
more functions.

We made a small test case [1] that returns the expected results on Windows
8.1 and OSX 10.9.5 [2], but on ARM devices (observed on Nexus 5 w/ Android
6.0.1 and an iPod Touch 5th Gen on iOS 7.1.2) can give very wrong results
[3].

We're talking about ARM32 userland, I guess? Also, I'm assuming
this is a build with ARM hard-float calling conventions (hardfp).

We are only seeing the buggy behavior in LuaJIT 2.1.0-beta1 and up (still
present in 0345f361531c756367257eb2f147c707e1710218), whether the JIT
engine is enabled or disabled and only on ARM devices (32/64bit x86 Win/OSX
are fine). Lua classic and LuaJIT 2.0.4 work fine on x86 and ARM.

Well, I can't reproduce it. And I guess someone would have spotted
this by now, because the results are completely off.

The results look like a calling-convention mixup between
soft-float and hard-float builds. I.e. the wrong register set is
passed and you get whatever was left in the other registers.

Are you sure you've recompiled LuaJIT from scratch (i.e. make
clean inbetween) and with the proper cross-compiler options? And
are you sure the C test runner has been compiled with the same
options?

Also: what does print(-10%4) say when run directly from the
interpreter, without your test wrapper? Because this expression is
constant-folded in C code during the bytecode generation step. The
result should not depend on the actual bytecode execution of the
interpreter at all.

[Umm, and ... in case you attempted to create your own build system
instead of the standard makefiles ... this would be a typical symptom.
The docs strictly advise not to do this. There's zero support for
that, because, so far, everyone who tried to do it screwed it up.]

--Mike

Other related posts: