-
Notifications
You must be signed in to change notification settings - Fork 6
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
Overflow for 64 bit modular types #182
Comments
Here are the hacks I'm currently adding manually to the generated code. In the return (if Value'Size < 64
then Value'Val (Result mod (2**Value'Size))
else Value'Val (Result)); In - Element_Value : constant Long_Integer := (Value'Pos (Val) mod 2**Value'Size);
+ Element_Value : constant Long_Integer := (if Value'Size < 32 then Value'Pos (Val) mod 2**Value'Size else Value'Pos (Val)); This only happens to work for me as my type is 32 bit - we need a solution for 64 bit types, too. Most likely, the type of |
One more thought on intermediate values: If we define a 64bit type unconditionally, we'll get in trouble on non-64-bit platforms. We have to come up with a solution that uses types with the maximum system word size ( @jklmnn @treiher Ideas how we could test less-than-64-bit support in the CI? It's probably a good idea to open another ticket for that. |
What would happen on a non-64-bit platform if we defined an unconditional 64 bit type? From what I can tell it would either fail to compile or the compiler would insert software support (at the expense of performance). |
It think I didn't make my point very clear and there are multiple issues to consider here:
|
So can I assume that 2. is already a problem but it only is visible when we have a 64bit type because it would use a greater than 64bit type internally? |
Yes, 64bit types are a problem, already. Hence this ticket. We should just make sure that the fix is not limited to 64-bit platforms and does not create undesired inefficiencies (such as always using a 64-bit emulation). |
But if we fix the 64bit problem in a generic way (so that we don't need any integers larger than the original data type) wouldn't that implicitly fix the problem for 32 bit platforms? |
Hopefully. I'd still argue that we need to test this to be sure. |
Okay, I think now I understood the problem correctly. So in theory if we try a protocol with a 32bit value on a 32bit only architecture with the current implementation it should already fail? About the performance impact of 64bit values on 32bit platforms. I compiled the following code: procedure Long
is
type Long is mod 2 ** 64;
L1 : Long := Long'Last;
L2 : Long;
begin
L2 := L1 + 42;
end Long; On x86_64 it compiled with
On arm the result with
It seams that 64bit on 32bit arm are software emulated. Instead of one instruction each line required 4 of which two are STR instructions that write to memory. According to the ARM Infocenter these only need on cycle. Since this is a really simple example If we want to prevent this we'd need to instruct the compiler to prevent this kind of code generation. I also tried to restrict the available types via runtime as defined here. But changing these properties in the runtime results in the same generated code and no errors. |
Using |
It should work, depending on what the compiler does with the |
Could you redo this experiment with optimizations ( |
I had to change the example because even package Long is
type Long is mod 2 ** 64;
procedure Add (A : Long;
B : Long;
C : out Long);
end Long;
package body Long is
procedure Add (A : Long;
B : Long;
C : out Long)
is
begin
C := A + B;
end Add;
end Long;
On X86 with optimization it is done with a single |
The following simple message
yields an overflow in the field extraction code:
The text was updated successfully, but these errors were encountered: