Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5072086ybe; Tue, 17 Sep 2019 02:03:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjYOHakYRk0ezsZxgkR629fVfHgiSX0JuE3rnVwf3TsnCU+hLwKEPCV4puwktSnxOV/Xn7 X-Received: by 2002:a17:906:6897:: with SMTP id n23mr3699695ejr.93.1568710992861; Tue, 17 Sep 2019 02:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568710992; cv=none; d=google.com; s=arc-20160816; b=EzR9Lyi68kzEiP6mYw6LKL/wDqCun/DHaOqPQ+5fnqzibkXU+lNU8nIZLoxoSBXO1Y i6NaWr48JDFd5S2xUGJ4iiJPF8uZGOPgLiFpgiQok3qbHzTmViedQXrQ6vHMGzPe+ScR XHL4pBwt+FPhBl8iMKiifjUWTjBChUclqN0MC2ygGTp99yCqrb9L98cGBGpR8Em/SDT/ rhfXkWp29A5lfj/Jr9FsiFMAZZFFSRqB/ZAdHMScp7Cjm5FfqiWBLHKZ823RrzwnJipE cPS7YTWwl3dxBdw19BcyIGZs+vC6KjQJBoJ0t2ABJvulcTIrmBTAx7m16iugwbf3HoxB cQ6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=E3AifJka0WH3TNUz39kekLnY0BYRUhm027YZs0bTau4=; b=XiKERSNauGNWsP4jEAXsqX0wBKtyLY01+VZy3afu3ffU32b+SBVweb4uB16t0ki/Ow t820kC8gKl4vkdt2M1sTXAe20A0xKFaRpJUsI5RMbEZns5q5dERi9HQW8m/zMjm2QRAP +9mNvpyfAwJs+HEgz7USfzO3zmGBFf5hJ3LoiPieAnvCvJCeG+LJYVTiAZhMAhZZ3mAl 5GvJsCLUpMtdvIpNAJc0mqb0cwiHvtZCu5zeKENc8+orB1qLruqQ+rLOg3r35XFlJHRh 52OY1/97BrXDOeX9o0KQFbLY/rshBQ6WE3FA4Td6y28MxCC/7qI/aGCU7sRO7pV6WBSv geYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Fcnexcbm; 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 e22si971557eda.300.2019.09.17.02.02.49; Tue, 17 Sep 2019 02:03:12 -0700 (PDT) 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; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Fcnexcbm; 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 S2388092AbfIPX0m (ORCPT + 99 others); Mon, 16 Sep 2019 19:26:42 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46699 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbfIPX0m (ORCPT ); Mon, 16 Sep 2019 19:26:42 -0400 Received: by mail-lj1-f193.google.com with SMTP id e17so1503435ljf.13 for ; Mon, 16 Sep 2019 16:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E3AifJka0WH3TNUz39kekLnY0BYRUhm027YZs0bTau4=; b=Fcnexcbmqxc9hlTD8moElunKXU89PjAgpQ9ZjFZB+MQQXNo+0oCJPgdSHOeaO5CQ3N dBEY/GR7sF7b3qS1I9aU1hZqM5ixulnBbvLEP1vZuY7iTJWfaHLC0RBHLfX15XdtHaIx y865/wSwuU+yYbC0RxjKz2M5e0Dh5WkCre2sc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E3AifJka0WH3TNUz39kekLnY0BYRUhm027YZs0bTau4=; b=d6mXUZu/DcUAUw5AbUuYkq7ApyXwX0ttoFv1RwkOAOVzRIWf2UjVW3B6QtjocqlG5D FYyNaDD3oP8AorF0i0T6NsD4Ntd4w2ZHcW86rsp2qjZ5jB3DkO5zPvpUJc9R2UiqCobj 7dFL+jLUuwpXMRGy6oCwmAbfFgT/j8tpeYXKqt5RUzWhZKJPHJ2jZempMYViafUCiv+6 5kVu6ncxL8GHGDhqgPlD5DgHiLY2+udhcPuDu0u7py63+bhzQbbbg1Dlb9mQdLY4Px3l +GB4uE7yhfRDTYNcWeMYksLIyN7sS3S6gSmdGruw+BgKou28x8nCE5SNMBp1eix4oXwI WVkw== X-Gm-Message-State: APjAAAVmM1BQ3l6fR6Aajhu0jWVmFe7JrlF3R/IAXxE5cgNkeJZgP5JI B6RISTOCdG2K1tHv+Cxsa/lS9Cbtqo8= X-Received: by 2002:a2e:9a18:: with SMTP id o24mr182800lji.123.1568676399518; Mon, 16 Sep 2019 16:26:39 -0700 (PDT) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com. [209.85.208.175]) by smtp.gmail.com with ESMTPSA id y204sm46400lfa.64.2019.09.16.16.26.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Sep 2019 16:26:38 -0700 (PDT) Received: by mail-lj1-f175.google.com with SMTP id y23so1565750ljn.5 for ; Mon, 16 Sep 2019 16:26:38 -0700 (PDT) X-Received: by 2002:a2e:5b9a:: with SMTP id m26mr197851lje.90.1568676398001; Mon, 16 Sep 2019 16:26:38 -0700 (PDT) MIME-Version: 1.0 References: <20190913072237.GA12381@zn.tnic> <9dc9f1e6-5d19-167c-793d-2f4a5ebee097@rasmusvillemoes.dk> <20190913104232.GA4190@zn.tnic> <20190913163645.GC4190@zn.tnic> <3fc31917-9452-3a10-d11d-056bf2d8b97d@rasmusvillemoes.dk> In-Reply-To: From: Linus Torvalds Date: Mon, 16 Sep 2019 16:26:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] Improve memset To: Andy Lutomirski Cc: Rasmus Villemoes , Borislav Petkov , Rasmus Villemoes , x86-ml , Josh Poimboeuf , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 16, 2019 at 4:14 PM Andy Lutomirski wrote: > > Well, when I wrote this email, I *thought* it was inlining the > 'memset' function, but maybe I just can't read gcc's output today. Not having your compiler, it's also possible that it works for you, but just doesn't work for me. > It seems like gcc is maybe smart enough to occasionally optimize > memset just because it's called 'memset'. This generates good code: Yup, that does the rigth thing for me and ignores the definition of memset() in favor of the built-in one. However, at least part of this discussion started because of the reverse problem (turning a couple of assignments into memset), and the suggestion that we might be able to use -ffreestanding together with #define memset __builtin_memset and then your nice code generation goes away, because the magical treatment of memset goes away. I get one_word: xorl %eax, %eax ret not_one_word: movq %rsi, %rdx xorl %esi, %esi jmp memset despite having that "inline void *memset()" definition. Linus