-
Notifications
You must be signed in to change notification settings - Fork 952
rand.Int() does not work on avr #2882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can be related to #2389 |
Not sure why this test didn't trigger it: https://github.com/tinygo-org/tinygo/blob/release/testdata/stdlib.go#L27 |
@ysoldak is this still an issue with the latest |
On latest release v0.30.0 and LLVM 16
Arduino (AVR) target
Same code for
Same happens on dev branch |
That means the binary is too big to fit on an AVR. I don't think there is anything to fix here. |
So random generator is basically not available on AVR. We could mention that in docs and close the ticket then?.. |
There are so many things that are too large for AVR, it doesn't make sense to spell out every little thing that doesn't work. It is of course possible to build a different pseudorandom number generator instead, for example there is one at the bottom of https://github.com/aykevl/things/blob/master/earring-ring/main.go: var xorshift32State uint32 = 1
func random() uint32 {
x := xorshift32State
x = xorshift32(x)
xorshift32State = x
return x
}
// Xorshift32 RNG. The usual algorithm uses the shift amounts [13, 17, 5], but
// [7, 1, 9] as used below are a much better fit for AVR. It is "only" 37
// instructions (excluding return) when compiled with Clang 16 while the usual
// algorithm uses 57 instructions.
// On the other hand, avr-gcc (tested most versions starting with 5.4.0) is just
// terrible in both cases, using loops for these shifts.
//
// The [7, 1, 9] algorithm is mentioned on page 9 of this paper:
// http://www.iro.umontreal.ca/~lecuyer/myftp/papers/xorshift.pdf
//
// Godbolt reference (both algorithms in avr-gcc and Clang 16):
// https://godbolt.org/z/KdeKhP54d
func xorshift32(x uint32) uint32
x ^= x << 7
x ^= x >> 1
x ^= x << 9
return x
} |
Closing because the original bug has been fixed and the followup issue is not really something we can fix. |
rand.Int()
does not work for me on dev branch.Did not try on latest release 0.23.0, rumour has it does not work there either.
Compilation for targets "arduino" and "arduino-nano" fails with:
error: interp: ptrtoint integer size does not equal pointer size
Simple reproducer:
The text was updated successfully, but these errors were encountered: