From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 584E53858D37 for ; Fri, 28 Apr 2023 21:37:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 584E53858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-63b4dfead1bso425883b3a.3 for ; Fri, 28 Apr 2023 14:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682717855; x=1685309855; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GGnxdcHutZkm+9gsEkBfiT3k4oKBLrfCQvsR0iwYRV8=; b=lvPkSLXabqLTDh86l5EhXdJ/dioDRvyO46hOVgNLkUZVgKWEBRfQ7CMg14GmVQ8dqC VjUm1ou0un9mPnjNNFsa7I84OE4a+29XzAoop4LOUU5wdM97Z9pepSk3BlzDCJkRfKLb 8mjBwVb30SruJJquIqUcE5uHEp/Cal/9yhfsqNeicri20IosyqYB1DZlm0h+OuDMrAea YbmyJKyJvLwu6XFaZNrqXd+aNz4nUuuHApINLEJdrW4RaYkUJ4j4gG75SSPkCfsmN/5e FJ3XjFdUFU9/UKey+T3ycgM8WwMIF8C9yyJzP4gjMW+XbaKPKvZdw5+rSGsK8FoZDRij ZcUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682717855; x=1685309855; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GGnxdcHutZkm+9gsEkBfiT3k4oKBLrfCQvsR0iwYRV8=; b=bOpKsBdJMLInU1fndRKRWh3xVJUJECc8uoXrxOeQ7hG4swCZ87Q1rWoBTPoUbM3rVr JVkZ6l7PHyPPfWAyMS7a1cSdunDHJlcH6bk/w9C7lNYl5p0LArOW9PVjIDdnlxzBkBk8 6DeTQ7DJLaF4NU0cPnTxYi4r+tjqecTveoPIIehREvzWWzJAVwCO7D+LwdyYrqvHqMPb orJTdlAv6UhJtQGewGoiUQbm/Qz/CRirqRFO7CnAZlOM5qs5eIAPkAxZkHwbKQdtE9fy h7be2UgsxOHaSzPjpjsvVx0FmgdfrHljTbMsv8pjUVJ9OETt3SsbkdiYdHOxRaUriuYp pZlg== X-Gm-Message-State: AC+VfDwoYOUZvBKNsNivnK8UiOMQ2lauJwFC8YbQWf/qv4YphNN8BMBk HtGpjVR7eaGmJ78H8lq1E2cR1Q== X-Google-Smtp-Source: ACHHUZ6xkOAgHjkDt9tdPvCgXAqVLziQVsqMyzu2Xq1+aoE+WjuUyOCTu5rKBK93x7R9cLWXamZSDQ== X-Received: by 2002:aa7:88d0:0:b0:63d:4407:b6c with SMTP id k16-20020aa788d0000000b0063d44070b6cmr9051672pff.7.1682717855302; Fri, 28 Apr 2023 14:37:35 -0700 (PDT) Received: from [192.168.50.116] ([71.202.114.183]) by smtp.gmail.com with ESMTPSA id x3-20020a628603000000b0063d666566d1sm15573771pfd.72.2023.04.28.14.37.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Apr 2023 14:37:35 -0700 (PDT) Message-ID: <7a5c650c-b97f-33dc-6e8c-df6612dff295@rivosinc.com> Date: Fri, 28 Apr 2023 14:37:33 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] riscv: generate builtin macro for compilation with strict alignment Content-Language: en-US To: Jeff Law , gcc-patches@gcc.gnu.org, Kito Cheng References: <20230117225908.1604948-1-vineetg@rivosinc.com> <3dbcefe5-5b62-eb89-442a-abebe621f3bc@gmail.com> From: Vineet Gupta In-Reply-To: <3dbcefe5-5b62-eb89-442a-abebe621f3bc@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 4/20/23 09:56, Jeff Law via Gcc-patches wrote: > > > On 1/17/23 15:59, Vineet Gupta wrote: >> This could be useful for library writers who want to write code variants >> for fast vs. slow unaligned accesses. >> >> We distinguish explicit -mstrict-align (1) vs. slow_unaligned_access >> cpu tune param (2) for even more code divesity. >> >> gcc/ChangeLog: >> >>     * config/riscv-c.cc (riscv_cpu_cpp_builtins): >>       Generate __riscv_strict_align with value 1 or 2. >>     * config/riscv/riscv.cc: Define riscv_user_wants_strict_align. >>       (riscv_option_override) Set riscv_user_wants_strict_align to >>       TARGET_STRICT_ALIGN. >>     * config/riscv/riscv.h: Declare riscv_user_wants_strict_align. >> >> gcc/testsuite/ChangeLog: >> >>     * gcc.target/riscv/attribute.c: Check for >>       __riscv_strict_align=1. >>     * gcc.target/riscv/predef-align-1.c: New test. >>     * gcc.target/riscv/predef-align-2.c: New test. >>     * gcc.target/riscv/predef-align-3.c: New test. >>     * gcc.target/riscv/predef-align-4.c: New test. >>     * gcc.target/riscv/predef-align-5.c: New test. >> >> Signed-off-by: Vineet Gupta >> --- >>   gcc/config/riscv/riscv-c.cc                     | 11 +++++++++++ >>   gcc/config/riscv/riscv.cc                       |  9 +++++++++ >>   gcc/config/riscv/riscv.h                        |  1 + >>   gcc/testsuite/gcc.target/riscv/attribute-4.c    |  9 +++++++++ >>   gcc/testsuite/gcc.target/riscv/predef-align-1.c | 12 ++++++++++++ >>   gcc/testsuite/gcc.target/riscv/predef-align-2.c | 11 +++++++++++ >>   gcc/testsuite/gcc.target/riscv/predef-align-3.c | 15 +++++++++++++++ >>   gcc/testsuite/gcc.target/riscv/predef-align-4.c | 16 ++++++++++++++++ >>   gcc/testsuite/gcc.target/riscv/predef-align-5.c | 16 ++++++++++++++++ >>   9 files changed, 100 insertions(+) >>   create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-1.c >>   create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-2.c >>   create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-3.c >>   create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-4.c >>   create mode 100644 gcc/testsuite/gcc.target/riscv/predef-align-5.c >> >> diff --git a/gcc/config/riscv/riscv-c.cc b/gcc/config/riscv/riscv-c.cc >> index 826ae0067bb8..47a396501d74 100644 >> --- a/gcc/config/riscv/riscv-c.cc >> +++ b/gcc/config/riscv/riscv-c.cc >> @@ -102,6 +102,17 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile) >>         } >>   +  /* TARGET_STRICT_ALIGN does not cover all cases.  */ >> +  if (riscv_slow_unaligned_access_p) >> +    { >> +      /* Explicit -mstruct-align preceedes cpu tune param >> +         slow_unaligned_access=true.  */ > Did you mean "-mstrict-align" above? Doh sorry yes. > > >> +      if (riscv_user_wants_strict_align) >> +        builtin_define_with_int_value ("__riscv_strict_align", 1); >> +      else >> +        builtin_define_with_int_value ("__riscv_strict_align", 2); > So I don't understand why we're testing > "riscv_user_wants_strict_align" instead of TARGET_STRICT_ALIGN here.  > AFAICT they're equivalent.  But maybe there's something subtle I'm > missing. The missing part is slightly over-engineered unaligned access signaling in RV gcc frontend IMHO. Thing is -mno-strict-align can be over-ruled by the cpu tune param slow_unaligned_access=true (and behave as if -mstrict-align was passed) And I wanted the macro to reflect this (for future proofing) by being defined but with different values. There's some renewed discussion with Kito on [1] so I need to respin this after getting the agreed upon specification in there. Thx, -Vineet [1] https://github.com/riscv-non-isa/riscv-c-api-doc/issues/32