View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Fri Apr 17, 2020 3:46 am |
|
|
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... , 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: 1317
|
|
Posted: Fri Apr 17, 2020 6:26 am |
|
|
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... , 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
|
|
Posted: Fri Apr 17, 2020 6:50 am |
|
|
Yes Mr. jeremiah it is logic answer. I'm still thinking for bits... not for bytes:)
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19221
|
|
Posted: Fri Apr 17, 2020 7:39 am |
|
|
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... |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1317
|
|
Posted: Fri Apr 17, 2020 9:01 am |
|
|
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
|
|
Posted: Fri Apr 17, 2020 12:41 pm |
|
|
Yes, the union are great things
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: 1317
|
|
Posted: Fri Apr 17, 2020 2:46 pm |
|
|
kmp84 wrote: | Yes, the union are great things
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: 19221
|
|
Posted: Sat Apr 18, 2020 2:06 am |
|
|
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.... |
|
|
|