[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a06f559c-3507-210c-d743-765163900935@suse.cz>
Date: Thu, 26 Mar 2020 07:38:29 +0100
From: Jiri Slaby <jslaby@...e.cz>
To: Joe Perches <joe@...ches.com>,
Arnaud POULIQUEN <arnaud.pouliquen@...com>,
Ohad Ben-Cohen <ohad@...ery.com>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-kernel@...r.kernel.org, linux-remoteproc@...r.kernel.org,
Mathieu Poirier <mathieu.poirier@...aro.org>
Cc: Suman Anna <s-anna@...com>,
Fabien DESSENNE <fabien.dessenne@...com>,
linux-stm32@...md-mailman.stormreply.com,
xiang xiao <xiaoxiang781216@...il.com>
Subject: Re: [PATCH v7 2/2] tty: add rpmsg driver
On 26. 03. 20, 1:01, Joe Perches wrote:
> On Wed, 2020-03-25 at 14:31 +0100, Jiri Slaby wrote:
>> The question was exactly about that: can a compiler optimize it to a
>> bare number or will strlen call remain there?
>
> $ cat str.c
> #include <string.h>
>
> int foo(void)
> {
> return strlen("abc");
> }
>
> $ gcc -c -O2 str.c
> $ objdump -d str.o
> str.o: file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <foo>:
> 0: f3 0f 1e fa endbr64
> 4: b8 03 00 00 00 mov $0x3,%eax
> 9: c3 retq
Perfect, but:
* that is userspace (different strlen).
* what about other archs -- AFAIR, i386 implements strlen in asm in the
kernel
Maybe compilers use intrinsics and only after optimizations, they put a
call to strlen?
/me digging
Yeah, even gimple already contains:
int D.2094;
D.2094 = 3;
return D.2094;
That means, even -O0 should generate 3 instead of the call:
$ echo -e '#include <string.h>\nint f() { return strlen("abc"); }' | gcc
-S -x c - -o - -O0
...
f:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $3, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
So fine, use strlen :).
thanks,
--
js
suse labs
Powered by blists - more mailing lists