Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp665914pxm; Thu, 3 Mar 2022 02:01:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3h3cDToO2W6m6ols0NiZLx9rt1r8ZecBhTODLoQCjYDkjy6WKBf9e8kMkB6JH0IOINFeW X-Received: by 2002:aa7:909a:0:b0:4e1:6d4:5905 with SMTP id i26-20020aa7909a000000b004e106d45905mr37451190pfa.34.1646301699487; Thu, 03 Mar 2022 02:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646301699; cv=none; d=google.com; s=arc-20160816; b=LMR6QalqvnekrfLv5WEMrnJaUTjQI/EngtbKeE/8C3bbxDoF2VZpHg/kbcJAORQgxw yltlvhMz+HjcZajIHdO7wrYHrN6JbJuLs0EDbsAsDVVFgyghp/PAhz0JurvtcBuC0b8d pvgy/nG+6ME+FMIBawxIIO67m/I0NPN4xUZn32nQP1G6h3sFhudY3IUDegWSCH/aluGt BPWa9s5fmjvOLgQJkhEGdwgjR4zCJ/mQVrov4D4vSh3RM3x0ayEgzzHguin9goO1EzEL 28lRWevix6rkkISkfkgelsGeIzEIrzwftP/RiKDb1E+ORlH/iPNSTvs7MpL7rT3ElMkh W5Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=6g/fIInxMSgt1aX04ELPXpUW1cIsKLfAPLG9qE24p0o=; b=u+8L7pBKsOEkWJ0dOiNgxCcAYM71vwl1iG60zHWWLCiQZ4IGG3dPgLC2ceb4r+NoO6 DcIwayDXS+msYThPWkbNvJYJ48+zVOmsr351nMVQDqej73XjbMsIH+yPlQVqg2p2G4eA nUsL9uAMdmjoX/RkgH9q9C0FOJlcBIEDjow6Z+6VVcrCrqcbWUyBQlvKvRpdAMBkGWvx 2+x/i2RmL90NTLT+z3gYcD+FTYmthKUn1m8fzYOrTVvzEoP06YZ1UIGCl4tAuDQ547hz ypsTazPc+YcNOloGjXQjuR9SeiiZ9hCQU/BvdF6/ukI7wQCqcrEqh9b9cEulI5XR540P q4cA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g68-20020a636b47000000b0037c501b8915si1594492pgc.772.2022.03.03.02.01.22; Thu, 03 Mar 2022 02:01:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232071AbiCCJ4S (ORCPT + 99 others); Thu, 3 Mar 2022 04:56:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbiCCJ4K (ORCPT ); Thu, 3 Mar 2022 04:56:10 -0500 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A300615DB2E; Thu, 3 Mar 2022 01:55:19 -0800 (PST) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 6680E92009C; Thu, 3 Mar 2022 10:55:17 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 62A4E92009B; Thu, 3 Mar 2022 09:55:17 +0000 (GMT) Date: Thu, 3 Mar 2022 09:55:17 +0000 (GMT) From: "Maciej W. Rozycki" To: Jiri Slaby cc: David Laight , =?UTF-8?Q?'Uwe_Kleine-K=C3=B6nig'?= , "gregkh@linuxfoundation.org" , Alexandre Belloni , Mateusz Holenko , Neil Armstrong , Benjamin Herrenschmidt , Liviu Dudau , Baruch Siach , "linux-kernel@vger.kernel.org" , Paul Cercueil , Paul Mackerras , Michael Ellerman , Michal Simek , Karol Gugala , Jerome Brunet , Peter Korsgaard , Florian Fainelli , Alexander Shiyan , Krzysztof Kozlowski , Alexandre Torgue , Fabio Estevam , Russell King , Ludovic Desroches , Andy Gross , "bcm-kernel-feedback-list@broadcom.com" , NXP Linux Team , "linux-serial@vger.kernel.org" , Vineet Gupta , Orson Zhai , Tobias Klauser , Patrice Chotard , Albert Ou , Maxime Coquelin , Manivannan Sadhasivam , Martin Blumenstingl , Sascha Hauer , Takao Orito , Vladimir Zapolskiy , Lorenzo Pieralisi , Paul Walmsley , Bjorn Andersson , Sudeep Holla , Richard Genoud , Chunyan Zhang , Nicolas Ferre , "David S. Miller" , Taichi Sugaya , Palmer Dabbelt , Pengutronix Kernel Team , Kevin Hilman , Baolin Wang , Shawn Guo , =?UTF-8?Q?Andreas_F=C3=A4rber?= Subject: Re: [PATCH v3] serial: make uart_console_write->putchar()'s character an unsigned char In-Reply-To: <84ad3854-28b9-e450-f0a2-f1448f32f137@suse.cz> Message-ID: References: <20220302072732.1916-1-jslaby@suse.cz> <20220302175242.ejiaf36vszr4xvou@pengutronix.de> <5c7045c1910143e08ced432d938b5825@AcuMS.aculab.com> <84ad3854-28b9-e450-f0a2-f1448f32f137@suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Mar 2022, Jiri Slaby wrote: > > The real problem is that using char (or short) for a function parameter > > or result is very likely to require the compile add code to mask > > the value to 8 (or 16) bits. > > > > Remember that almost every time you do anything with a signed or unsigned > > char/short variable the compiler has to use the integer promotion rules > > to convert the value to int. > > > > You'll almost certainly get better code if the value is left in an > > int (or unsigned int) variable until the low 8 bits get written to > > a buffer (or hardware register). > > So should we use int/uint instead of more appropriate shorter types everywhere > now? The answer is: definitely not. The assembly on x86 looks good (it uses > movz, no ands), RISC architectures have to do what they chose to. We do have an issue, because we still have this: void uart_console_write(struct uart_port *port, const char *s, unsigned int count, void (*putchar)(struct uart_port *, int)) and then: putchar(port, *s); there. Consequently on targets where plain `char' type is signed the value retrieved from `*s' has to be truncated in the call to `putchar'. And indeed it happens with the MIPS target: 803ae47c: 82050000 lb a1,0(s0) 803ae480: 26100001 addiu s0,s0,1 803ae484: 02402025 move a0,s2 803ae488: 0220f809 jalr s1 803ae48c: 30a500ff andi a1,a1,0xff vs current code: 803ae47c: 82050000 lb a1,0(s0) 803ae480: 26100001 addiu s0,s0,1 803ae484: 0220f809 jalr s1 803ae488: 02402025 move a0,s2 (NB the last instruction shown after the call instruction, JALR, is in the delay slot that is executed before the PC gets updated). Now arguably the compiler might notice that and use an unsigned LBU load instruction rather than the signed LB load instruction, which would make the ANDI instruction redundant, but still I think we ought to avoid gratuitous type signedness changes. So I'd recommend changing `s' here to `const unsigned char *' or, as I previously suggested, maybe to `const u8 *' even. Maciej