CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

int32 overflow
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 3:46 am     Reply with quote

Quote:

This is in fact 'why' the
CCS fp maths format differs from the IEEE format, allowing a saving of
about four instructions.

I didn't know that...Rolling Eyes , but thinking for few my projects where I need converting back to IEEE 754 and may be my program is slower than using directly IEEE 754?

Quote:

but gives you the extra output bits allowing you
to 'know' if an overflow has occurred

Where CCS tell how to access those bits?
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 6:26 am     Reply with quote

kmp84 wrote:
Quote:

This is in fact 'why' the
CCS fp maths format differs from the IEEE format, allowing a saving of
about four instructions.

I didn't know that...Rolling Eyes , but thinking for few my projects where I need converting back to IEEE 754 and may be my program is slower than using directly IEEE 754?

Quote:

but gives you the extra output bits allowing you
to 'know' if an overflow has occurred

Where CCS tell how to access those bits?


They are the upper 32bits of the 64bit result. Normally when you overflow multiplication, you get a wrong answer because the upper bits of the result are lost. with _mul, you get the full up to 64 bit answer

consider 0x20000 multiplied by 0x20000, two 32 bit numbers:
Code:

         00020000
       x 00020000
-----------------
00000004 00000000


Normally that value of 4 is lost because it is overflow and multiplication of two 32bit values in C results in a 32bit result. with the _mul() function it always returns a result twice as large as the largest operand (up to 32bit operand). So instead of losing the overflow bits (the 4), you now get the whole answer with _mul(), assuming your operands are no bigger than 32bits
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 6:50 am     Reply with quote

Yes Mr. jeremiah it is logic answer. I'm still thinking for bits... not for bytes:)

Thanks,
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 7:39 am     Reply with quote

It's also worth repeating my comments about using unions:
Code:

    union {
       unsigned int32 words[2];
       unsigned int64 whole;
   } value;
   int32 num1, num2;

   value.whole=_mul(num1,num2);

   //at this point, value.words[1] contains any overflow bits


With this if value.words[1]!=0 you have had an overflow.
value.words[0] is the int32 result.

Makes testing very easy... Very Happy
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 9:01 am     Reply with quote

kmp84 wrote:
Yes Mr.jeremiah it is logic answer. I'm still thinking for bits... not for bytes:)

Thanks,


My previous response indicated that the bits were stored in the upper 32bits of the 64bit result. Ttelmah's post shows you how to access them using a union.
kmp84



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 12:41 pm     Reply with quote

Yes, the union are great things Smile
Thanks guys. Everything is clear!
I hope this long thread will be useful and CCS correct "STATUS" core register.

Best Wishes!
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Fri Apr 17, 2020 2:46 pm     Reply with quote

kmp84 wrote:
Yes, the union are great things Smile
Thanks guys. Everything is clear!
I hope this long thread will be useful and CCS correct "STATUS" core register.

Best Wishes!


They may not see it. This is only a user forum. They generally only do official support through phone/email. I would definitely recommend sending your suggestions to CCS
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Apr 18, 2020 2:06 am     Reply with quote

It's worth perhaps pointing out that this is not really a required 'fix'. C
itself defines the behaviour when a operation overflows as 'undefined'.

There is no requirement for this to be flagged in any way.

Now it would be 'nice' if it was, and once we are through Covid-19,
I will make a suggestion to CCS, that they might consider adding this,
but it very much is something that isn't required....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group