public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* MIPS Built-ins
@ 2023-09-28 13:15 Ильвир Низамов
  0 siblings, 0 replies; only message in thread
From: Ильвир Низамов @ 2023-09-28 13:15 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 3677 bytes --]

Hello!
You may call me Ilvir. I got an issue while building U-Boot for MIPS
platform, because of __builtin_mips_cache needs optimization flags (like
-O2) while non-literal int passed in it ("int op" at example below).

Example code:
static inline void mips_cache(int op, const volatile void *addr) {
#if __GCC_HAVE_BUILTIN_MIPS_CACHE
__builtin_mips_cache(op, addr);
#endif
}

void f() {
const void *addr = (const void*)0xB800200;

mips_cache(op, addr);
}

Running compilation without optimization flag:
ilvir:~/test/mips_cache$ mips-linux-gnu-gcc -S -march=mips32r2 mips_cache.c
mips_cache.c: In function ‘mips_cache’:
mips_cache.c:3:9: error: invalid argument to built-in function
    3 |         __builtin_mips_cache(op, addr);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And with:
ilvir:~/test/mips_cache$ mips-linux-gnu-gcc -O2 -S -march=mips32r2
mips_cache.c
compiles well.

Well passed compilation output:
ilvir:~/test/mips_cache$ cat mips_cache.s
.file 1 "mips_cache.c"
.section .mdebug.abi32
.previous
.nan legacy
.module fp=xx
.module nooddspreg
.module arch=mips32r2
.abicalls
.text
.align 2
.globl f
.set nomips16
.set nomicromips
.ent f
.type f, @function
f:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
li $2,192937984 # 0xb800000
jr $31
cache 0x4,512($2)

.set macro
.set reorder
.end f
.size f, .-f
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits

Preprocessor output:
ilvir:~/test/mips_cache$ mips-linux-gnu-gcc -E -march=mips32r2 mips_cache.c
# 0 "mips_cache.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/mips-linux-gnu/include/stdc-predef.h" 1 3
# 0 "<command-line>" 2
# 1 "mips_cache.c"
static inline void mips_cache(int op, const volatile void *addr) {

 __builtin_mips_cache(op, addr);

}

void f() {
 unsigned int op = 0x04;
 const void *addr = (const void*)0xB800200;

 mips_cache(op, addr);
}

Compiler:
ilvir:~/test/mips_cache$ mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/mips-linux-gnu/12/lto-wrapper
Target: mips-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14'
--with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-12 --enable-shared
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-libitm --disable-libsanitizer --disable-libquadmath
--disable-libquadmath-support --enable-plugin --enable-default-pie
--with-system-zlib --enable-libphobos-checking=release
--without-target-system-zlib --enable-multiarch --disable-werror
--enable-multilib --with-arch-32=mips32r2 --with-fp-32=xx
--with-lxc1-sxc1=no --enable-targets=all --with-arch-64=mips64r2
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=mips-linux-gnu --program-prefix=mips-linux-gnu-
--includedir=/usr/mips-linux-gnu/include
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)

It will be very helpful if you tell me the importance of using optimization
flags when compiling the built-in given above. Is it really necessary to
use optimization flags there? Does the compiler operate right?
Thank you!

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-28 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 13:15 MIPS Built-ins Ильвир Низамов

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).