This is the mail archive of the
mailing list for the binutils project.
Re: AS, and saving and restoring .cpu directive on ARM?
- From: Nick Clifton <nickc at redhat dot com>
- To: noloader at gmail dot com, Binutils <binutils at sourceware dot org>
- Date: Thu, 20 Apr 2017 16:18:21 +0100
- Subject: Re: AS, and saving and restoring .cpu directive on ARM?
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nickc at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 911234E4CA
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 911234E4CA
- References: <CAH8yC8k1MVong2CA4nPHz53GNStR7BFagFeWwiO-aW9RH+1JDA@mail.gmail.com>
> __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
* 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
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));
The advantage here is that you do not need the .cpu directive to
select the desired architecture.