2008-05-05 11:28:37     some prob with asm code

Document created by Aaronwu Employee on Aug 6, 2013
Version 1Show Document
  • View in full screen mode

2008-05-05 11:28:37     some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55516   

 

Hi every one,

 

i need help explanation about some strange behavior in my code, which is the flowing:

 

  unsigned int temp1,temp2;

 

   unsigned char ln,cn,bit_nbr;

 

   unsigned char bloc[2][2];

 

                   temp1 = bloc[ln][cn] << 24;

 

                    temp2 = 0;

 

                    //printf("***temp1 = 0x%x, temp2 = 0x%x",temp1,temp2);             

 

                    for(bit_nbr=0;bit_nbr<8;bit_nbr++)

 

                    {

 

                        asm("%0=ROT %2 by 1; %1=ROT %3 by -1;":"=r"(temp1),"=r"(temp2):"0"(temp1),"1"(temp2));

 

                        asm("nop;");

 

                        /*printf(" itiration N° %d, temp1 = 0x%x, temp2 = 0x%x",bit_nbr,temp1,temp2);*/

 

                    }

 

                     temp2 >>= 24;

                    //printf(" temp1 = 0x%x, temp2 = 0x%x ***",temp1,temp2);

 

i try to rotate 2 int in 2 reg in order to swap bits in a char from bloc[ ][ ] array. when i add the nop instruction i get true values in temp2 ans also when i put a printf but when i delete them i get 0x0 in temp2 and some constant values in temp1 when out of the loop. so i'm feeling forced to add nop instruction just to get the true values!!!

 

when i do a bfin-uclinux-gcc on the c file the complier says:

 

/tmp/cc5aTuvz.s: Assembler messages:

/tmp/cc5aTuvz.s:1655: Error: Register mismatch.

 

but i cannot find the .s file in the tmp folder

 

do  you see any strange things in my code please. is it because kernel use the cc flag? but why not when i put the nop instruction?

 

thank you.

TranslateQuoteReplyEditDelete

 

 

2008-05-05 12:08:05     Re: some prob with asm code

Mike Frysinger (UNITED STATES)

Message: 55517   

 

you can use the -S flag to tell gcc to only output assembly code ... then you can figure out where your inline asm() is incorrect

 

you're declaring your constraints in a weird way ... there should be no input constraints, only output:

"=&r"(temp1), "=&r"(temp2)

 

please review the documentation on how to write inline asm:

http://docs.blackfin.uclinux.org/doku.php?id=using_in-line_assembly_calling_external_assembly_from_c

QuoteReplyEditDelete

 

 

2008-05-05 12:38:11     Re: some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55518   

 

ok thank you Mike,

 

i'm using this and i'll see if i get  true values without nop instruction. but i cannot find the & constraint in:

 

http://docs.blackfin.uclinux.org/doku.php?id=using_in-line_assembly_calling_external_assembly_from_c

 

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html

 

how you know them?

 

thanks

TranslateQuoteReplyEditDelete

 

 

2008-05-05 13:21:59     Re: some prob with asm code

Robin Getz (UNITED STATES)

Message: 55520   

 

Hadi:

 

If you take the code (attached, next time, please attach compilable snippets, copy/paste is a waste of time).

 

Like Mike said, it produces : "bfin-elf-gcc -S foo.c -o foo.S" assembly, which looks like:

 

foo:

        R3=ROT R3 by 1;

        P1=ROT P1 by -1;

foo1:

 

As you can guess, the ROT instruction can not take a Pointer register, this causes :"/tmp/ccpHf02U.s: Assembler messages:

/tmp/ccpHf02U.s:34: Error: Register mismatch."

 

 

 

You need to make sure you use the proper contraint for the instruction (r == any register, d == Data Register (called, confusingly on the Blackfin, a R register)).

 

 

 

-Robin

 

foo.c

QuoteReplyEditDelete

 

 

2008-05-05 16:22:12     Re: some prob with asm code

Mike Frysinger (UNITED STATES)

Message: 55521   

 

well, it isnt a constraint, it's a modifier ... so look at the modifier section:

http://gcc.gnu.org/onlinedocs/gcc/Modifiers.html#Modifiers

QuoteReplyEditDelete

 

 

2008-05-06 05:08:14     Re: some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55547   

 

exactly Robin,

 

it takes P register instead of D register. I ignore that r constraint represents both D and P registers.

 

Thank you for explanation

 

-Hadi

TranslateQuoteReplyEditDelete

 

 

2008-05-06 07:40:09     Re: some prob with asm code

Bernd Schmidt (GERMANY)

Message: 55559   

 

That doesn't sound right.  The values are inputs into the asm statement, so they must be listed as input constraints.  You're right about the need for earlyclobbers (although in this particular example it probably doesn't matter).

QuoteReplyEditDelete

 

 

2008-05-06 08:17:20     Re: some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55562   

 

Thank you Mike again,

 

but there is no assmbler error messages, but when i use:

 

asm("%0=ROT %0 by 1; %1=ROT %1 by -1;" : "=&d"(temp1), "=&d"(temp2));

 

i got all temp2 variables null, and the same when i add the nop instruction after. so i don't know if the cc flag is being changed before. I hope you have understand what i want to do, it's just inverting bit order in each byte ( b0 becomes b7 and b7 becomes b0).

 

I can do this only with what i wrote before:

 

asm("%0=ROT %0 by 1; %1=ROT %1 by -1;" : "=d"(temp1), "=d"(temp2) : "0"(temp1), "0"(temp2));  asm("nop";);

 

else i got wrong values in temp2.

 

I hope i'm not boring you with this!

 

 

 

Thank you again.

TranslateQuoteReplyEditDelete

 

 

2008-05-06 08:28:02     Re: some prob with asm code

Mike Frysinger (UNITED STATES)

Message: 55564   

 

please post a fully self contained example instead of one line snippet

 

yyou should also re-add the input constraints as Bernd already corrected me

QuoteReplyEditDelete

 

 

2008-05-06 08:46:25     Re: some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55565   

 

sorry I didn't see Bernd's message before posting mine.

 

I still talking about the same code:

 

  unsigned int temp1,temp2;

  unsigned char ln,cn,bit_nbr;

  unsigned char bloc[2][2];

 

 

                    temp1 = bloc[ln][cn] << 24;

                    temp2 = 0;

                    //printf("***temp1 = 0x%x, temp2 = 0x%x",temp1,temp2);

                      

                    for(bit_nbr=0;bit_nbr<8;bit_nbr++)

                    {

                        asm("%0=ROT %2 by 1; %1=ROT %3 by -1;":"=d"(temp1),"=d"(temp2):"0"(temp1),"1"(temp2));

                        //asm("nop;");

                        /*printf(" itiration N° %d, temp1 = 0x%x, temp2 = 0x%x",bit_nbr,temp1,temp2);*/

                    }

                  

                    temp2 >>= 24;

 

with nop enabled I got in asm:

 

.L43:

    R1 = [FP+-12];

    R0 = [FP+-8];

    R3 = R1;

    R2 = R0;

#APP

    R3=ROT R3 by 1; R2=ROT R2 by -1;

#NO_APP

    R1 = R2;

    R0 = R3;

    [FP+-12] = R0;

    [FP+-8] = R1;

    R0 = B [FP+-2] (X);

    R0 += 1;

    B [FP+-2] = R0;

.L42:

 

and with nop disabled I got in asm:

 

L43:

    R1 = [FP+-12];

    R0 = [FP+-8];

    R3 = R1;

    R2 = R0;

#APP

    R3=ROT R3 by 1; R2=ROT R2 by -1;

#NO_APP

    R1 = R2;

    R0 = R3;

    [FP+-12] = R0;

    [FP+-8] = R1;

#APP

    nop;

#NO_APP

    R0 = B [FP+-2] (X);

    R0 += 1;

    B [FP+-2] = R0;

.L42:

 

i don't see what the nop instruction can change in the content of temp2

TranslateQuoteReplyEditDelete

 

 

2008-05-06 08:57:08     Re: some prob with asm code

Mike Frysinger (UNITED STATES)

Message: 55566   

 

that is still just a snippet, not a fully contained example.  we need something we can just do `bfin-uclinux-gcc -elf2flt test.c` and be able to reproduce your issue.

QuoteReplyEditDelete

 

 

2008-05-06 09:02:26     Re: some prob with asm code

Hadi Boulfelfel (FRANCE)

Message: 55567   

 

Ok,

 

I'm doing modification on the fcd.c file under /uClinux-dist-2008R1-RC8/user/blkfin-apps/ppifcd-cgi/src.

 

 

 

fcd.c

TranslateQuoteReplyEditDelete

 

 

2008-05-06 17:29:49     Re: some prob with asm code

Bernd Schmidt (GERMANY)

Message: 55585   

 

The other thing you need to do is to add a clobber of "CC" to the asm statement, since the ROT instruction clobbers that register.

Attachments

Outcomes