EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Where can I find Hardware Multiplier C code examples

Started by gerrydoulsnking January 27, 2010
I'm now studying how to use the Hardware Multipliers in MSP430. I have only the Family user's Guide and one Application note, which are both written in Assmbler, though authoritative. But I'm doing my project in C. Thus assembler is to me understandable yet not hands-on.
Is there any reliable source code example for the Multipliers in C? as for other peripherals, there are always C codes available on TI's website.

Thank you!

Gerry

Beginning Microcontrollers with the MSP430

You don't have to do anything special in C. Your compiler will use the hardware multiplier if you enable that feature in your project settings. At least it does in IAR environment.

Lloyd

--- In m..., "gerrydoulsnking" wrote:
> ...
> Is there any reliable source code example for the Multipliers in C?

Thank you, Lloyd,

That means, if I enable the compiler with that feature, I only have to write
my final calculation equation in my C code, and the compiler will make the
best of the hardware multiplier automatically, right?

Gerry

On Wed, Jan 27, 2010 at 1:37 PM, lslonim2 wrote:

> You don't have to do anything special in C. Your compiler will use the
> hardware multiplier if you enable that feature in your project settings. At
> least it does in IAR environment.
>
> Lloyd
>
> --- In m... ,
> "gerrydoulsnking" wrote:
> > ...
>
> > Is there any reliable source code example for the Multipliers in C?
>
>
>

--
Mit freundlichen Gren/Best regards

Yuelin Jin

Festo Didactic GmbH & Co. KG
Abteilung DC-RD
Masterarbeit Student
Rechbergstra 3
73770 Denkendorf
Deutschland
Telefon ++49 (0) 711-1225-4312
Mobil ++49 (0) 176-8204-7210


You said: "... and the compiler will make the best of the hardware multiplier automatically .. "

Blessed are the pure in heart, for they shall see God

-- OCY

--- In m..., Yuelin Jin wrote:
>
> Thank you, Lloyd,
>
> That means, if I enable the compiler with that feature, I only have to write
> my final calculation equation in my C code, and the compiler will make the
> best of the hardware multiplier automatically, right?
>
> Gerry
>
> On Wed, Jan 27, 2010 at 1:37 PM, lslonim2 wrote:
>
> >
> >
> > You don't have to do anything special in C. Your compiler will use the
> > hardware multiplier if you enable that feature in your project settings. At
> > least it does in IAR environment.
> >
> > Lloyd
> >
> > --- In m... ,
> > "gerrydoulsnking" wrote:
> > > ...
> >
> > > Is there any reliable source code example for the Multipliers in C?
> >
> >
> >
>
>
>
> --
> Mit freundlichen Gren/Best regards
>
> Yuelin Jin
>
> Festo Didactic GmbH & Co. KG
> Abteilung DC-RD
> Masterarbeit Student
> Rechbergstra 3
> 73770 Denkendorf
> Deutschland
> Telefon ++49 (0) 711-1225-4312
> Mobil ++49 (0) 176-8204-7210
>
>
>
>

:)

Sent via BlackBerry by AT&T



-----Original Message-----

From: "old_cow_yellow"

Date: Wed, 27 Jan 2010 21:39:35

To:

Subject: [msp430] Re: Where can I find Hardware Multiplier C code examples



You said: "... and the compiler will make the best of the hardware multiplier automatically .. "



Blessed are the pure in heart, for they shall see God



-- OCY



--- In m..., Yuelin Jin wrote:

>

> Thank you, Lloyd,

>

> That means, if I enable the compiler with that feature, I only have to write

> my final calculation equation in my C code, and the compiler will make the

> best of the hardware multiplier automatically, right?

>

> Gerry

>

> On Wed, Jan 27, 2010 at 1:37 PM, lslonim2 wrote:

>

> >

> >

> > You don't have to do anything special in C. Your compiler will use the

> > hardware multiplier if you enable that feature in your project settings. At

> > least it does in IAR environment.

> >

> > Lloyd

> >

> > --- In m... ,

> > "gerrydoulsnking" wrote:

> > > ...

> >

> > > Is there any reliable source code example for the Multipliers in C?

> >

> >

> >

>

>

>

> --

> Mit freundlichen Gren/Best regards

>

> Yuelin Jin

>

> Festo Didactic GmbH & Co. KG

> Abteilung DC-RD

> Masterarbeit Student

> Rechbergstra 3

> 73770 Denkendorf

> Deutschland

> Telefon ++49 (0) 711-1225-4312

> Mobil ++49 (0) 176-8204-7210

>

>

>

>









Yes, that how it works. In most compilers, there is a way to view the generated assembly code, so you can look at that if you want to see the actual instructions.

If you are using floating point variables (float) there is so much other work going on that the hardware multiplier might not make a difference. But if you are multiplying ints and longs it should help.

For real details of how your compiler uses the multiplier, your questions should go to the vendor.

Lloyd

--- In m..., Yuelin Jin wrote:
>
> Thank you, Lloyd,
>
> That means, if I enable the compiler with that feature, I only have to write
> my final calculation equation in my C code, and the compiler will make the
> best of the hardware multiplier automatically, right?
>
> Gerry
>

On Thu, 28 Jan 2010 13:47:52 -0000, lslonim2 wrote:

> Yes, that how it works. In most compilers, there is a way to view the
> generated assembly code, so you can look at that if you want to see the
> actual instructions.
>
> If you are using floating point variables (float) there is so much other
> work going on that the hardware multiplier might not make a difference.

It helps, believe me, it certainly helps. The 32-bit multiplier also
helps. A lot.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
Just a word of caution: in a multitasking environement you should be careful
with floating point calculations. If the code is interruptible then you
might get TWO processes trying to share the maths hardware at once ... which
doesn't always work out well.

Paul: Is the MSP430 susceptible to this risk?

regards,

Richard

----- Original Message -----
From: "Paul Curtis"
To:
Sent: Thursday, January 28, 2010 9:21 PM
Subject: Re: [msp430] Re: Where can I find Hardware Multiplier C code
examples
> On Thu, 28 Jan 2010 13:47:52 -0000, lslonim2 wrote:
>
>> Yes, that how it works. In most compilers, there is a way to view the
>> generated assembly code, so you can look at that if you want to see the
>> actual instructions.
>>
>> If you are using floating point variables (float) there is so much other
>> work going on that the hardware multiplier might not make a difference.
>
> It helps, believe me, it certainly helps. The 32-bit multiplier also
> helps. A lot.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!
>
Hi Richard,

> Just a word of caution: in a multitasking environement you should be
> careful
> with floating point calculations. If the code is interruptible then you
> might get TWO processes trying to share the maths hardware at once ...
> which
> doesn't always work out well.
>
> Paul: Is the MSP430 susceptible to this risk?

No. The MSP430 multiplier context cannot be saved and restored by the
design of the MSP430, hence there is no alternative other than to disable
interrupts around code that uses the hardware multiplier--and this is what
CrossWorks does by default, and IAR too I believe.

If you don't want to increase latency by using the multiplier, you need to
manage it yourself or elect not to use the multiplier and have bit-by-bit
software multiplies. You can do that in CrossWorks too.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks V2 is out for LPC1700, LPC3100, LPC3200, SAM9, and more!


The 2024 Embedded Online Conference