Jump to content




[CC1.74] Bit api bugs


  • You cannot reply to this topic
3 replies to this topic

#1 gamax92

  • Members
  • 157 posts

Posted 21 July 2015 - 05:30 PM

When the bit api changed up in CC1.74, it became a bit less useful and even break various functions:

All functions will limit the number to the range of a signed 32bit number, but give numbers that are unsigned 32bit numbers.
And by limit to a range, it'll do something more like
math.min(math.max(number, -2^31), 2^31-1)
instead of wrapping around

This will for example, break colors.subtract:
bit.bnot will generally return a number larger than 2^31-1, but when it's passed to bit.band it gets rounded down to 2^31-1, and no bits will change.
This results in the color not being subtracted

I'm assuming the api was changed up for the eventual migration towards Lua 5.2, but numbers should wrap around instead or being range limited

EDIT: I guess this is more Java's fault instead of ComputerCraft's fault, casting a double directly to an int will range limit it, but intermediately casting it to a long and then to an int gets the correct wrapped result.

Edited by gamax92, 21 July 2015 - 05:54 PM.


#2 ElvishJerricco

  • Members
  • 803 posts

Posted 19 September 2015 - 03:56 AM

This bug has broken asm.lua and subsequently JVML-JIT, and now I have to find a different, pure Lua (and therefore slow) bit API. Anyone have any suggestions?

Edited by ElvishJerricco, 19 September 2015 - 03:56 AM.


#3 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 19 September 2015 - 07:27 AM

View PostElvishJerricco, on 19 September 2015 - 03:56 AM, said:

This bug has broken asm.lua and subsequently JVML-JIT, and now I have to find a different, pure Lua (and therefore slow) bit API. Anyone have any suggestions?

I just added some unsigned integer to integer casts for my AES's bit library, its faster than a pure-Lua version.

Edited by SquidDev, 19 September 2015 - 07:28 AM.


#4 ElvishJerricco

  • Members
  • 803 posts

Posted 19 September 2015 - 07:55 PM

Doesn't seem to have a distinction between logical and arithmetic shift.

I didn't even manage to convert everything to the new bit library. Just anything that could have been vulnerable. It'd be great if you could go through asm.lua and JVML-JIT and see about improving the bit stuff.

Although honestly, the emit time didn't go up at all with the adoption of the pure lua one.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users