Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5431221ybp; Mon, 14 Oct 2019 22:37:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqy72RBp4M4M+we1iseVmk1Iahjcw4LjTQMupFsrYyJIFL+3OE57sku2j2UCKnOojJTQD4Fr X-Received: by 2002:a17:906:1996:: with SMTP id g22mr20948062ejd.298.1571117846600; Mon, 14 Oct 2019 22:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571117846; cv=none; d=google.com; s=arc-20160816; b=R0YqE1V/QWhBiHc9rjvcGhjSsPE6TZ7+zZw/rqRc68FIMey5D+zYxiyETEjhMLlw/r Zmo1RMn9hOPti4vGPj9U5PIsQR5mrgqRCu4zavZfUxoghH/7JvjuX6bgsw6OLZ/ROY42 US9GwEFF9Tj3wTd9FzSb1NFUjiqEV+S/IAEVVFBw5WudY9xBeq5vxHQAV2dYaceSKVFV Rp+s2/Y+HtLAhtXgxvUmgmOHqdUbc1QkcwbnxqwnwsNBDUJuZZNLM3G6OSu9LCDTDM2t 4DPFSiXg/Trv29fieDVQ4zFdWdAo2HfqFiPS60axKRr3XPJoeMpPo4Nauyz67REcCCKB sKmw== 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; bh=ShNj6dpdoV3qxQt4i9xwFO5EQ7UppT+qckLzoe6/RVM=; b=vPu0CyMaeUE1p6Vs4hpkdfqcw0CN/lePhsjhbWG4bRGc2g8MKM5lpgRHp/q4nRs0xG ZVXJsyBUVmh5kLVIKijdWi/6u7Tat90Unkh0CQ1JI/EswQcwn3FNz3LHW1juNW+slFGZ RJ4Da5ocqg4/wDl0RJdBkun/mmbwnEx74b9oa5aIkANm6mf0EbP5H2PjwU1EyUFoqWG6 IxnV4+jNPn27AQpzYBLup86D0uTKgmJg2WiuG/aSC2SbRxQP1vWNJvXu5GRlzvSZiIgS waVu4DUHB9TDsKKcHPhhH2rENxSYA9RA0gpV1KRrt4LmefmwwD+0wa2ytRtTbbXxcPYa Cr+g== 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 g22si14055788edf.398.2019.10.14.22.37.03; Mon, 14 Oct 2019 22:37:26 -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; 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 S1727995AbfJODsu (ORCPT + 99 others); Mon, 14 Oct 2019 23:48:50 -0400 Received: from mail-vk1-f196.google.com ([209.85.221.196]:43599 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727092AbfJODsu (ORCPT ); Mon, 14 Oct 2019 23:48:50 -0400 Received: by mail-vk1-f196.google.com with SMTP id p189so4001838vkf.10 for ; Mon, 14 Oct 2019 20:48:49 -0700 (PDT) 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=ShNj6dpdoV3qxQt4i9xwFO5EQ7UppT+qckLzoe6/RVM=; b=Xqn0PRGUh7L6FR68qPPZhSaHWTgxs3gG3efnhpBjDp5HpDpb1zAWTXNG2MyS5OtFSY RDNQ7wyXmXiRxsqKMgfAq/iE+PaMMzLT1aJUNTTUOv70VroV6mQkXgMVhDytqVXjK6tE 7GVWv63nVx3XdJMHmbIBQ199uw9zyfOMn0/hpbIJU4aK8S2I+lT2bKEvLRe9u02w3c5e 8MO+bPz4E4242c6iCZNFBycDYRW33vP1aKm7jbw6rsZYaX4VbfUzYLSmnp6Vagi8bJtJ kRjnGsOSOOK7Pem1iDTt2h2VtZYGdWC+rrJpJFyohxLsVJf0llCauYg3hbxVeRyPdekN je7g== X-Gm-Message-State: APjAAAUwSVuL/bmoz1rhhIqoZgMKkcqW7TkrOY/fyZ9er0VyqA7XgSu3 oPu68N0Xh9HsJ7Z2Yemw9tu4oIwiWxainJbw3U4= X-Received: by 2002:a1f:1d15:: with SMTP id d21mr17456229vkd.55.1571111329347; Mon, 14 Oct 2019 20:48:49 -0700 (PDT) MIME-Version: 1.0 References: <20191011054240.17782-1-james.qian.wang@arm.com> <20191011054240.17782-2-james.qian.wang@arm.com> <20191015011604.GA26941@jamwan02-TSP300> In-Reply-To: <20191015011604.GA26941@jamwan02-TSP300> From: Ilia Mirkin Date: Mon, 14 Oct 2019 23:48:38 -0400 Message-ID: Subject: Re: [PATCH v2 1/4] drm/komeda: Add a new helper drm_color_ctm_s31_32_to_qm_n() To: "james qian wang (Arm Technology China)" Cc: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" , "Jonathan Chai (Arm Technology China)" , "Julien Yin (Arm Technology China)" , "Thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , Ayan Halder , "Tiannan Zhu (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , nd , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , Ben Davis , "Oscar Zhang (Arm Technology China)" , "Channing Chen (Arm Technology China)" , Mihail Atanassov 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, Oct 14, 2019 at 9:16 PM james qian wang (Arm Technology China) wrote: > On Mon, Oct 14, 2019 at 11:58:48AM -0400, Ilia Mirkin wrote: > > On Fri, Oct 11, 2019 at 1:43 AM james qian wang (Arm Technology China) > > wrote: > > > + * > > > + * Convert and clamp S31.32 sign-magnitude to Qm.n 2's complement. > > > + */ > > > +uint64_t drm_color_ctm_s31_32_to_qm_n(uint64_t user_input, > > > + uint32_t m, uint32_t n) > > > +{ > > > + u64 mag = (user_input & ~BIT_ULL(63)) >> (32 - n); > > > + bool negative = !!(user_input & BIT_ULL(63)); > > > + s64 val; > > > + > > > + /* the range of signed 2s complement is [-2^n+m, 2^n+m - 1] */ > > > > This implies that n = 32, m = 0 would actually yield a 33-bit 2's > > complement number. Is that what you meant? > > Yes, since m doesn't include sign-bit So a Q0.32 is a 33bit value. This goes counter to what the wikipedia page says [ https://en.wikipedia.org/wiki/Q_(number_format) ]: (reformatted slightly for text-only consumption): """ For example, a Q15.1 format number: - requires 15+1 = 16 bits - its range is [-2^14, 2^14 - 2^-1] = [-16384.0, +16383.5] = [0x8000, 0x8001 ... 0xFFFF, 0x0000, 0x0001 ... 0x7FFE, 0x7FFF] - its resolution is 2^-1 = 0.5 """ This suggests that the proper way to represent a standard 32-bit 2's complement integer would be Q32.0. -ilia