Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2524937imu; Sun, 23 Dec 2018 01:35:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/UCce77Gkbiou8mDjW0unhceLDxCdzBSHbc2C1Iy2drr4HqT1U6F1REr0FkXFh/b0huA/b0 X-Received: by 2002:a62:109b:: with SMTP id 27mr8980251pfq.227.1545557754368; Sun, 23 Dec 2018 01:35:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545557754; cv=none; d=google.com; s=arc-20160816; b=IlWrc9TN5osZvOQiH448XIJHFzzkbwBA4jd/pJHwbLCN5y6xc6SKW4zU1dDrPih9ST U89poYmTW78SVrf/zjcnZE/59g6Nd05sgY/R514RF2HQt3nWPyrhwxTyArNSDhDAOHOc en8mK8jiJJLxhXf3GFhD97qZ8PdEs+T5RRvF4lOGepRSydispAUCJhr01M3bObpL6Ah7 u0udvywu/O882egzkTTL6XCPMxXyYDLOCgA8VFe2/FXBj0DjkX+nW4QAPE4GdEsVNbnp +ad3EDqvZsDasJnnHVEKN5gQd1nAu6haUByG0k/H1gISksZluv+up+mVgH89hE8RIX/9 U3wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=tqjPEfz05zCKSU4qKAfMOu2za4tv63mqdEIzGTmdzAI=; b=eM+bv+OQ8GKuWeO/Lxx6mdcj3NOHjBJqu5UCw4EPb2NbwvY7V42axlzoSgCEc2ois/ mYwOiu8BwWupONo0BMwNs4CNPtklyaLnxgM25TBUME9SjaP2sUXtU49LMub1kqcUzlql bAShUNF/g1raLn75i3OZkE8nQb0VGTctLIgDbr0t0AIjCWlz8A+lJ+rCsVHSUdWoX5u3 tqJGI7A2ZU/XieyRDfFrvybVi/mYLrgEU/w2XULYE8paFkTlwCTECLWo5m/+QVjAyAzH jmouDanVjwhLxijnNp83J2LOxRwSInjbHFumzWI2P3oxAKAKNTUfCHNGkd5Yhr4/TO7A FV6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e34si25077151pgb.80.2018.12.23.01.35.38; Sun, 23 Dec 2018 01:35:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404581AbeLUWU3 (ORCPT + 99 others); Fri, 21 Dec 2018 17:20:29 -0500 Received: from smtprelay0037.hostedemail.com ([216.40.44.37]:40566 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730887AbeLUWU3 (ORCPT ); Fri, 21 Dec 2018 17:20:29 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay02.hostedemail.com (Postfix) with ESMTP id B98213A91; Fri, 21 Dec 2018 22:20:28 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1801:2197:2199:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3355:3622:3653:3865:3866:3867:3868:3871:3872:3874:4321:4605:5007:6119:7808:7903:8957:9121:9149:10004:10400:10848:10967:11026:11232:11233:11658:11914:12043:12438:12555:12679:12740:12760:12895:12986:13132:13231:13439:13870:14093:14096:14097:14180:14181:14659:14721:21080:21221:21433:21451:21622:30029:30041:30054:30069:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:38,LUA_SUMMARY:none X-HE-Tag: frame06_78561ece8b74c X-Filterd-Recvd-Size: 5031 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf02.hostedemail.com (Postfix) with ESMTPA; Fri, 21 Dec 2018 22:20:26 +0000 (UTC) Message-ID: <84199633fd49db573c9ba71f1992936422e907d4.camel@perches.com> Subject: Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro From: Joe Perches To: Steven Rostedt , Andreas Schwab Cc: Linus Torvalds , Linux List Kernel Mailing , Ingo Molnar , Andrew Morton , Namhyung Kim , Masami Hiramatsu , Tom Zanussi , Greg Kroah-Hartman Date: Fri, 21 Dec 2018 14:20:25 -0800 In-Reply-To: <20181221160826.34c544e6@gandalf.local.home> References: <20181221175618.968519903@goodmis.org> <20181221175659.208858193@goodmis.org> <20181221144054.20bdeb33@gandalf.local.home> <20181221153526.5e6055ca@gandalf.local.home> <077eeb8b09baebe78822819b5f15d671b738a2b2.camel@perches.com> <20181221155435.38a9a221@gandalf.local.home> <871s6ad2br.fsf@igel.home> <20181221160826.34c544e6@gandalf.local.home> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-12-21 at 16:08 -0500, Steven Rostedt wrote: > On Fri, 21 Dec 2018 21:58:32 +0100 > Andreas Schwab wrote: > > > > > Well, perhaps I can just remove the ending ones. I get paranoid with > > > macro variables, and tend to over do it so that there's no question. > > > > Why not make it an inline function? > > Matters if that removes the strlen(const) optimization. I could try it > and see what happens. Using static inline bool str_has_prefix(const char *str, const char prefix[]) { return !strncmp(str, prefix, strlen(prefix)); } eliminates the strlen with gcc 4.8 (oldest I still have) $ cat lib/test_module.c * This module emits "Hello, world" on printk when loaded. * * It is designed to be used for basic evaluation of the module loading * subsystem (for example when validating module signing/verification). It * lacks any extra dependencies, and will not normally be loaded by the * system unless explicitly requested by name. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include #include static inline bool str_has_prefix(const char *str, const char prefix[]) { return !strncmp(str, prefix, strlen(prefix)); } bool test_str_has_prefix(const char *foo) { return str_has_prefix("TomJonesPrefix", foo); } bool test_str_has_prefix_TomJones(void) { return str_has_prefix("TomJonesPrefix", "TomJones"); } $ make CC=/usr/bin/gcc-4.8 lib/test_module.o $ objdump -d -s lib/test_module.o lib/test_module.o: file format elf64-x86-64 Contents of section .text: 0000 534889fb e8000000 00b90f00 00004883 SH............H. 0010 f80f4889 df480f4e c848c7c6 00000000 ..H..H.N.H...... 0020 4839c9f3 a65b0f94 c0c3660f 1f440000 H9...[....f..D.. 0030 b8010000 00c3 ...... Contents of section .rodata.str1.1: 0000 546f6d4a 6f6e6573 50726566 697800 TomJonesPrefix. Contents of section .comment: 0000 00474343 3a202855 62756e74 7520342e .GCC: (Ubuntu 4. 0010 382e352d 34756275 6e747539 2920342e 8.5-4ubuntu9) 4. 0020 382e3500 8.5. Contents of section .orc_unwind_ip: 0000 00000000 00000000 00000000 00000000 ................ 0010 00000000 00000000 ........ Contents of section .orc_unwind: 0000 08000000 05001000 00000500 08000000 ................ 0010 05000000 00000000 08000000 05000000 ................ 0020 00000000 .... Disassembly of section .text: 0000000000000000 : 0: 53 push %rbx 1: 48 89 fb mov %rdi,%rbx 4: e8 00 00 00 00 callq 9 9: b9 0f 00 00 00 mov $0xf,%ecx e: 48 83 f8 0f cmp $0xf,%rax 12: 48 89 df mov %rbx,%rdi 15: 48 0f 4e c8 cmovle %rax,%rcx 19: 48 c7 c6 00 00 00 00 mov $0x0,%rsi 20: 48 39 c9 cmp %rcx,%rcx 23: f3 a6 repz cmpsb %es:(%rdi),%ds:(%rsi) 25: 5b pop %rbx 26: 0f 94 c0 sete %al 29: c3 retq 2a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) 0000000000000030 : 30: b8 01 00 00 00 mov $0x1,%eax 35: c3 retq