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

Multiplications

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
.C



Joined: 06 May 2004
Posts: 19
Location: Italy

View user's profile Send private message

Multiplications
PostPosted: Sun May 23, 2004 2:40 am     Reply with quote

Hi,

PIC18 family:

If I write a=b*c , Does the compiler use hardware multiplication?
Or I have to use a special 'C' istruction or built-in functions?

Thank
C-H Wu
Guest







PostPosted: Sun May 23, 2004 2:56 am     Reply with quote

It depends on the data type, here's my test report with PCH 3.200

Code:
// computation speed:     ( usec )    16F877      18F452    Wu
// ---------------------------------------------------------------
// ----- int8    * int8                10           1
// ----- int16   * int16               48           7        9
// ----- s_int16 * s_int16             50           7        9
//   . . with saturation routine       --          --       21
// ----- s_int32 * s_int32            127          45
// ----- float   + float               --          37 !
// ----- float   * float              136         136 !     52 (1e-7)
// ----- float   / float              277         277      287 (1e-7)
//                                                         200 (1e-5)


It seems that they still don't like the hardware multiplier for float multiplication, and my own float_mult() routine is still three times faster.
.C



Joined: 06 May 2004
Posts: 19
Location: Italy

View user's profile Send private message

PostPosted: Mon May 24, 2004 2:31 am     Reply with quote

In the my code I wrote :

long A;
int b;

A=B*.800;

but I have not seen in the dissassemby listing multiplications hardware
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon May 24, 2004 3:23 am     Reply with quote

Remember the hardware multiplier works only on 8-bit and 16-bit isgned/unsigned integers, not floats.
Ttelmah
Guest







PostPosted: Mon May 24, 2004 4:50 am     Reply with quote

Haplo wrote:
Remember the hardware multiplier works only on 8-bit and 16-bit isgned/unsigned integers, not floats.

This does not matter.
All the multiplication is 'built up' from operations on smaller types. So the hardware function, can be used as one of the 'building blocks' to create the higher operation types. At present, CCS do not use this (basically, they have not re-written their own 'library' to take advantage of the ability) for floats. They have done for integers. This is why the 32*32 multiplication, has gained from the function, despite the function not handling this type. The function can be very effectively used to help when dealing with floats, but it requires the maths routine to be re-written to do so. Basically, since the chip iself (on versions without the hardware multiplier), only deals with 8bit values, and the 16bit and higher routines on these chips is built from the functions using the 8bit type, CCS elected to write the floating point routine to use only the 8bit operations. On chips with the hardware multiplier however there is a saving from using 16bit arithmetic routines (so for instance, a 16*16 multiply, only takes 7usec on the table published by C-H Wu, when a 8*8 multiply takes 10uSec, and building the 16*16 multiply using the 8*8 multiply, takes 48uSec.
On some other compilers, the hardware multiplier is used for floating point arithmetic, and the time taken for a floating point multiplication, typically halves.

Best Wishes
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon May 24, 2004 5:45 am     Reply with quote

Ttelmah wrote:
At present, CCS do not use this (basically, they have not re-written their own 'library' to take advantage of the ability) for floats.


That is basically what I was trying to say Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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