[sdiy] help...no make8() function in Arduino...converting PIC to AVR

dan snazelle subjectivity at hotmail.com
Wed Apr 11 19:05:36 CEST 2012


I see

it did not work with the functions


sorry for my ignorance but i just dont understand how to make a #define with these parameters (i guess I have never made macros before)


would it be

#define make8 (((var >> (offset*8)) (& 0xff))


??


thanks



On Apr 11, 2012, at 12:57 PM, Olivier Gillet wrote:

> There's a cost associated to calling "proper" functions - parameters
> being pushed to the stack or moved to the right register, then a jump,
> the body of the function, a return, and moving the result from the
> output register to whatever register the result should be in. You
> don't want such small things to be functions - and that's probably why
> they were defined as macros in the first place! So you either have to
> define those as macro ; or as inline functions, using something like
> __attribute__((always_inline)) in the declaration. gcc might be smart
> enough to inline them without being forced to do so with the
> __attribute__, but it's not a very good thing to make such
> assumptions.
> 
> Olivier
> 
> On Wed, Apr 11, 2012 at 6:47 PM, dan snazelle <subjectivity at hotmail.com> wrote:
>> ok so if
>> 
>> 
>>  make8  = (((var >> (offset*8)) & 0xff)
>>  _mul  value = (int)( a1*val1>>8);
>> 
>> 
>> 
>> then since i dont quite understand the parentheses in define I could make 2 functions
>> 
>> 
>> 
>> byte make8(int var, byte offset)
>> {
>> byte result=(((var >> (offset*8)) & 0xff);
>> return result;}
>> 
>> 
>> 
>> and for the other function  (_mul)
>> 
>> 
>> int _mul (byte a1, byte val) {
>> 
>> int result=(int)( a1*val1>>8);
>> return result;
>> }
>> 
>> 
>> 
>> do those look right?
>> 
>> 
>> thanks
>> 
>> 
>> 
>> 
>> 
>> On Apr 11, 2012, at 12:00 PM, Martin Klang wrote:
>> 
>>> 
>>> what do they do on the pic?
>>> 
>>> make8 I found in the PIC C Compiler Reference:
>>> i8 = MAKE8(var, offset)
>>> Same as: i8 = (((var >> (offset*8)) & 0xff)
>>> 
>>> so that
>>>> tmpbyte1 = make8(tmp1, 1);
>>> 
>>> would be
>>> tmpbyte1 = (tmp1 >> 8) & 0xff;
>>> 
>>> and _mul() multiplies, right?
>>> 
>>> Looks like the code is specifically optimised for the pic instructions set -
>>> tmp1 is 16 bit, right? acc1 and val1 8-bit unsigned integers?
>>> 
>>> Presumably you can replace the two lines with
>>> uint8_t value = (uint8_t)( acc1*val1>>8);
>>> depending on data types, but would have to see some more code to know.
>>> 
>>> 
>>> hth,
>>> 
>>> /m
>>> 
>>> On 11 Apr 2012, at 16:25, dan snazelle wrote:
>>> 
>>>> can someone help me ?
>>>> 
>>>> i am trying to convert some PIC code to AVR
>>>> 
>>>> it is going fine except for 2 things
>>>> 
>>>> there is no make8() function and there is no _mul()
>>>> 
>>>> 
>>>> so code lines like this:
>>>> 
>>>> 
>>>> tmp1 = _mul (acc1, val1);
>>>> 
>>>> tmpbyte1 = make8(tmp1, 1);
>>>> 
>>>> 
>>>> do not work
>>>> 
>>>> 
>>>> 
>>>> i have been looking for the make8 function online so i can just write that function into my code but no luck
>>>> 
>>>> 
>>>> thanks for any help!
>>> 
>>> 
>> 
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at dropmix.xs4all.nl
>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
> 




More information about the Synth-diy mailing list