Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp803115pxm; Thu, 3 Mar 2022 05:05:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3i/bL5LkPXozoK1C0svVzhqLmuHN2JWvU14rw8jGCnwbGS/GgmT+I7UjAN6MMz6OIKQrm X-Received: by 2002:a17:902:bb93:b0:14f:3c15:566f with SMTP id m19-20020a170902bb9300b0014f3c15566fmr35293894pls.6.1646312738632; Thu, 03 Mar 2022 05:05:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646312738; cv=none; d=google.com; s=arc-20160816; b=TxGRcBgHVj+gVk0LaVcBsKBEkA45KaeWTey3drLosB0k3j4YmbRCK4qrP12T1tOqo5 9IgSKkbt49hVnqDZCZDwlCdfmD/0kqMc9q7RazIoNteKIrdtOfLDOkxkBp3+hbpBO57E ofOjJ5uL8QHpEB7CKnk0IUWVxohCYtTSNdRenb0B82uB9Nbd01LG4Qboqtqs44pEJShw wx0JsoXLx0twv0c9/j0LEDNPdaR++j5FgcklTW9Z99bo136MSJ7ypCqcznPMoI+XqhLO fanfhorpM5RFlZ67HOQ/LHE0MeAp10e7Q1pkvawPcRIEruMDjgRQmtRbrA4Zvn/cfdGf DKyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=8ydqyQ4KH00qGQ2ak8xfq9T/ZIKOXMia2MRXPo2T/ME=; b=i4go4/JwcvHUtAUjMgyEeWqQIc/CeBSTYkdZkEfYPSC82PCgD+ZSOuSVq9kLVkVpEC VBnnWrFMwH/VhYpYbUpGCbW7LzVMCibmHDCSBysedNPvBO6T8Y3rU1OvT/kp7GzpCbIB Vvpm8N21jpKwgA/mw4hz9wkbXXEvklMBlMOZFFs36b8C3pKclX6m4m0VagTSYsbhaWYv 3rcPcv/qmLU6Qv+5JbEp3n+9QcTEOOgZrE7zc+Soo39ojWK4mDQwURuiC5mGhW8K2g43 uUGaVAoYENT6y7unEwGJimYofhofJwfWGgkRZ3XjYxkxrPoGj6pJpsXwTSSaACmAGNDV 2hsQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 190-20020a6301c7000000b0037c5466a20bsi1941381pgb.782.2022.03.03.05.05.23; Thu, 03 Mar 2022 05:05:38 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232296AbiCCKYc convert rfc822-to-8bit (ORCPT + 99 others); Thu, 3 Mar 2022 05:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbiCCKYb (ORCPT ); Thu, 3 Mar 2022 05:24:31 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A39DD5DF7 for ; Thu, 3 Mar 2022 02:23:45 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-85-giSk7cqsO3ulJJXd9AQGxQ-1; Thu, 03 Mar 2022 10:23:42 +0000 X-MC-Unique: giSk7cqsO3ulJJXd9AQGxQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 3 Mar 2022 10:23:40 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Thu, 3 Mar 2022 10:23:40 +0000 From: David Laight To: "'Maciej W. Rozycki'" , Jiri Slaby CC: =?iso-8859-1?Q?=27Uwe_Kleine-K=F6nig=27?= , "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 , =?iso-8859-1?Q?Andreas_F=E4rber?= Subject: RE: [PATCH v3] serial: make uart_console_write->putchar()'s character an unsigned char Thread-Topic: [PATCH v3] serial: make uart_console_write->putchar()'s character an unsigned char Thread-Index: AQHYLl5tVpWrjMz0S0GPyaCV/1nc9aysw9yAgACo/IGAAAYHAA== Date: Thu, 3 Mar 2022 10:23:40 +0000 Message-ID: <20f24492d4944de4986245c59e5be71f@AcuMS.aculab.com> References: <20220302072732.1916-1-jslaby@suse.cz> <20220302175242.ejiaf36vszr4xvou@pengutronix.de> <5c7045c1910143e08ced432d938b5825@AcuMS.aculab.com> <84ad3854-28b9-e450-f0a2-f1448f32f137@suse.cz> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Maciej W. Rozycki > Sent: 03 March 2022 09:55 > > > > 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. Or just not worry that the 'char' value (either [128..127] or [0..255]) is held in a 'signed int' variable. That basically happens every time it is loaded into a register anyway. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)