janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.45k stars 223 forks source link

Odd results subtracting from `int/u64` on Android Termux (aarch64) #1217

Closed sogaiu closed 1 year ago

sogaiu commented 1 year ago

On an Android device (aarch64) via termux, I got a strange result when subtracting 1 from (int/u64 "0xFF_FF_FF_FF"):

$ janet
Janet 1.29.1-54377441 linux/aarch64/clang - '(doc)' for help

repl:1:> (- (int/u64 "0xFF_FF_FF_FF") 1)
<core/u6 4294967295>

repl:2> (int/u64 "0xFF_FF_FF_FF")
<core/u6 4294967295>

(Output above edited to space things out.)

The surprise was that subtracting 1 from (int/u64 "0xFF_FF_FF_FF") did not yield a result different from (int/u64 "0xFF_FF_FF_FF").

Trying with some other values like 2 and 127:

repl:3:> (- (int/u64 "2") 2)
<core/u64 2>

repl:4:> (- (int/u64 "2") 127)
<core/u64 2>

It is as if nothing was subtracted.

When subtracting -1 or 0, things seem ok:

repl:5:> (- (int/u64 "2") -1)
<core/u64 3>

repl:6:> (- (int/u64 "2") 0)
<core/u64 2>

The version of janet used was 5437744126f86a352f93187099cdd5820715ad7f.

pyrmont commented 1 year ago

I'm seeing the same issue with (- (int/u64 "0xFF_FF_FF_FF") 1) being equal to (int/u64 "0xFF_FF_FF_FF") on an Apple Silicon M1 as well.

sogaiu commented 1 year ago

Ah, so may be it's an ARM thing of some sort.

sogaiu commented 1 year ago

I tried 8183cc5a8dc6fa7beeddb434ed26db966bf8aee5 and things look better there.

Thanks @bakpakin!

yunfan commented 1 year ago

@sogaiu which repo of termux provide janet?

sogaiu commented 1 year ago

@yunfan I build from source.

I think the instructions which start at this comment may still be relevant. Some of the dependencies are:

pkg install binutils clang git libandroid-spawn make

FWIW, I do a "user" install via the Makefile with an invocation like this from the janet source directory:

make clean && PREFIX=$HOME/.local make && PREFIX=$HOME/.local make install

Also, my ~/.profile has at least:

export PATH=$HOME/.local/bin:$PATH

in it.