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

32 bit multiplication
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kkelis



Joined: 13 Dec 2006
Posts: 5

View user's profile Send private message

PostPosted: Tue Mar 11, 2014 3:40 pm     Reply with quote

Thanks for the reply Ttelmah. I think i follow you up to a certain point. Sorry my programming skills are a bit limited.
I understand that the compiler understands up to int32 so some how the int64 has to be broken down to a high part and a low part but i believe were moving to assembly programming
I dont know how the shift() and make32() commands can help.

I am trying to get better accuracy out of my DDS ad9850 and a multiplication yielding a result over 32bits is needed
Ttelmah



Joined: 11 Mar 2010
Posts: 19258

View user's profile Send private message

PostPosted: Wed Mar 12, 2014 2:08 am     Reply with quote

You never need to shift for this!....

Look at how the cast32x64 is done. It writes the 32bit value given into the low 32bits of the target, and then writes '0' to the high 32bits. Done through the union. Key nice thing is that this is exactly how it would be done if you did have 64 bit support. Problem is if you just copy the value into a variable, the compiler doesn't realise it has the extra four bytes needing clearing...

If however you want to print a 64bit value, you have to do all the printout arithmetic in 64bit. Not terribly hard, but needs thought.

Where the 64bit form is really useful, is if you are starting with 32bit values, and want to end up with a 32bit result, since then the existing 32bit routines can be used to do the print (accessing 64bitvariable.w[0], which is the low 32bit part), but this can't be used, unless the value _is_ 32bit at the end, otherwise the most important part is being lost!...

Just as a demonstration, to show how this works:
Code:

void main()
{
   int64 test1,test2,b;
   int32 fout,a;

   //lcd_init(); //printing to serial on my chip
   a=343597386;
   fout=20000000;
   b=cast32x64(10000000); //write the low 32 bits into a 64bit variable
   for(;;)
   {

      test1=mult32x32(fout,a);

      test2=div64x64(test1,b);

      printf("\f%lu",test2.w[0]); //print the low 32bits
      delay_ms(100);
      //now to make something different happen
      a-=6;
   }   
}

Merrily prints 687194772 on the first pass. Going 'through' a 64bit intermediate value (test1), of 68717947720000000!....
Then keeps going with the reducing 'a' value.
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
Page 2 of 2

 
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