Highlighted

how do do unsigned int multiply without it rounding on ARM processors?

Participant ,
Dec 12, 2015

Copy link to clipboard

Copied

I have encountered a very tricky issue, that I AM SURE has bitten many a person in the ass, and that is assuming that you can multiply two 32-bit unsigned numbers, and get the 32 bit quotient, (the 32 least significant bits) without any rounding going on. It works fine on Intel chips, because A*B is converted to a floating multiply by the Ecmascript spec (why did they do this one wonders!), and since on intel chips you have 80 bits of precision, there is no problem with the conversion to and from 80 bit floating point. But when you try running your code on android, you get a rounding error, and if like me you are trying to do a hashing function that depends on perfect arithmetic, you are screwed!

Unfortunately, on ARM tablets such as Trasnformer Prime, and others, there is a loss of precision. This is deadly for hashing algorithms, random number generators, any other function that is expecting full 32 bit x 32 bit = 32 bit result with higher order bits ignored.

    var a : uint = 0xaf1ac315;

    var b : uint = 0x01000193;

    var c : uint = uint(a*b);

the answer in 64 bit arithmetic would be 0xaf1bc6bc211a0f

on 64 bit intel CPU, you will get bc211a0f  (correct, least significant 32 bits)

on ARM CPU, you will get bc211a10  (rounded answer due to loss of precision)

i have yet to figure out how to get AS3 to correctly multiply two integers without screwing it up on the ARM CPU platform.

Perhaps some clever person knows a function in the AS3 runtime that will allow you to multiply two unsigned integers without converting to floating point, which on the ARM architecture is a measly 64 bits.

TOPICS
Performance issues

Views

219

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

how do do unsigned int multiply without it rounding on ARM processors?

Participant ,
Dec 12, 2015

Copy link to clipboard

Copied

I have encountered a very tricky issue, that I AM SURE has bitten many a person in the ass, and that is assuming that you can multiply two 32-bit unsigned numbers, and get the 32 bit quotient, (the 32 least significant bits) without any rounding going on. It works fine on Intel chips, because A*B is converted to a floating multiply by the Ecmascript spec (why did they do this one wonders!), and since on intel chips you have 80 bits of precision, there is no problem with the conversion to and from 80 bit floating point. But when you try running your code on android, you get a rounding error, and if like me you are trying to do a hashing function that depends on perfect arithmetic, you are screwed!

Unfortunately, on ARM tablets such as Trasnformer Prime, and others, there is a loss of precision. This is deadly for hashing algorithms, random number generators, any other function that is expecting full 32 bit x 32 bit = 32 bit result with higher order bits ignored.

    var a : uint = 0xaf1ac315;

    var b : uint = 0x01000193;

    var c : uint = uint(a*b);

the answer in 64 bit arithmetic would be 0xaf1bc6bc211a0f

on 64 bit intel CPU, you will get bc211a0f  (correct, least significant 32 bits)

on ARM CPU, you will get bc211a10  (rounded answer due to loss of precision)

i have yet to figure out how to get AS3 to correctly multiply two integers without screwing it up on the ARM CPU platform.

Perhaps some clever person knows a function in the AS3 runtime that will allow you to multiply two unsigned integers without converting to floating point, which on the ARM architecture is a measly 64 bits.

TOPICS
Performance issues

Views

220

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 12, 2015 0

Have something to add?

Join the conversation