This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: AS, and saving and restoring .cpu directive on ARM?

Hi Jeffrey,

>      __inline unsigned int GCC_INLINE_ATTRIB
>      CRC32B(unsigned int crc, unsigned char v)
>      {
>          unsigned int r;
>          asm (".cpu generic+fp+simd+crc+crypto  \n"
>               "crc32b %w2, %w1, %w0             \n"
>               : "=r"(r) : "r"(crc), "r"((unsigned int)v));
>          return r;
>      }

> 1) Does the .cpu directive need to be saved and restored in the inline
> assembly block?

Yes.  But ... since you have already specified that if this instruction 
is executed then runtime code has already checked and ensured that the 
hardware is present.  In which case it probably will not matter that you
leave the .cpu directive in its altered state.

> 2) If so, then how do I do it under ARM?

You can't. :-(

Instead you will need a workaround.  Here are some suggestions:

  * Compile the function in its own file.  That way it does not 
    matter that you do not restore the .cpu setting after 
    encoding the crc instruction.  Of course you lose the advantage
    of inlining.

  * If you know what the original .cpu settings were, then you can
    always restore them afterwards.

  * Construct the instruction by hand and insert it directly into the
    assembler output.  This is a bit tedious, but code like this might

    unsigned int 
    CRC32B(unsigned int crc, unsigned char v)
          unsigned int r;
	  asm (".set crcr2,2\n");
	  asm (".set crcr3,3\n");
	  asm (".inst (0x1ac04000 + crc%2 + (crc%1 << 5) + (crc%0 << 16))\n"
             : "=r"(r) : "r"(crc), "r"((unsigned int)v));
          return r;

    The advantage here is that you do not need the .cpu directive to 
    select the desired architecture.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]