top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

add load/store reverse instructions to the MD file with GCC

0 votes
491 views

I was working in an Embedded processor with GCC-4.6.4 version. I need to add load/store reverse instructions to the MD file. My instructions will look as below:

 LWX Rd,Ra,Rb
 operation: Addr := Ra + Rb
 Rd := *Addr (loading data with the opposite endianness)
 SWX Rd,Ra,Rb
 operation: Addr := Ra + Rb
 *Addr := Rd (storing data with the opposite endianness)

To add the above instructions in to md file I tried below pattern in md file

 (define_insn "movsi_rev"
 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
 (bswap: SI (match_operand:SI 1 "move_src_operand" "m,d")))]
 ""
 "@
 lwxt%0,%1,%0
 swxt%0,%1,%0"
 [(set_attr "type" "load,store")
 (set_attr "mode" "SI")
 (set_attr "length" "4,4")])

I wrote a small testcase which is generating swx instruction but the operands are more due to which it is failing in assembler phase

 ex: instead of swx r0,r2,r0 it is generating swx r0,r2,0,r0

can anyone please help me in removing the extra operand in the above instruction.

posted Aug 8, 2013 by Majula Joshi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Are you trying to modify gcc itself for your particular target, or are just wanting to use these instructions in your own code? I can't think why the compiler would need to generate endian-reversed accesses itself
(I think it would be great if gcc supported a variable or type attribute specifying that the data should be accessed with reversed endianness, but that's not available at the moment).

Using the instruction directly from your code is pretty easy with inline assembler:

static inline uint32_t LMX(uint32_t * Ra, uint32_t Rb) {
 uint32_t Rd;
 asm(" lmx %[Rd], %[Ra], %[Rb]" :
 [Rd] "=r" (Rd) :
 [Ra] "r" (Ra), [Rb] "r" (Rb) );
 return Rd;
}

That should give you optimal code.

answer Aug 8, 2013 by Mandeep Sehgal
Similar Questions
+1 vote

I wonder how one could get the compiler to generate the "movdqu" instruction, since the vector extensions always seem to assume that everything will be aligned to 16 byte.
I tried using a packed struct and this dint help much. Of course one can always resort to inline assembly but this should not be necessary

Compile with:

gcc -O2 -S -msse2 testvecs.c

Using built-in specs.

COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' 
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs 
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-4.7 --enable-shared --enable-linker-build-id 
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext 
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--enable-gnu-unique-object --enable-plugin --enable-objc-gc 
--enable-targets=all --with-arch-32=i586 --with-tune=generic 
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu 
--target=i486-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
0 votes

I have created one hard disk image file ,which has installed linux kernel on it , and its filesystem also works fine . Now I want to install gcc on it by host's gcc from source .

At earlier time ,I consider to set configure option --prefix to image mounted location on host , like this: --prefix=/mnt/image , but this is found not work at later,due to gcc depend on several files on host .

So I want to get some suggestions from here.

0 votes

How we can add two 64 bit number on 32 bit machine using c/c++ program ?

0 votes

When I was building GCC, I found out that stage1-gcc is not compiled with optimization (such as -O2). So the compilation of stage2 is very slow. Is this intended or not? If not, did I made some mistakes in configure options and caused this?

...