From mboxrd@z Thu Jan 1 00:00:00 1970 From: "james qian wang (Arm Technology China)" Subject: Re: [PATCH v2 1/4] drm/komeda: Add a new helper drm_color_ctm_s31_32_to_qm_n() Date: Tue, 15 Oct 2019 08:04:26 +0000 Message-ID: <20191015080420.GA22242@jamwan02-TSP300> References: <20191011054240.17782-1-james.qian.wang@arm.com> <20191011054240.17782-2-james.qian.wang@arm.com> <20191015011604.GA26941@jamwan02-TSP300> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Content-Language: en-US Content-ID: <12E7DBFF2DC9DE4CA94DC451C6EEB50D@eurprd08.prod.outlook.com> Sender: linux-kernel-owner@vger.kernel.org To: Ilia Mirkin 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 List-Id: dri-devel@lists.freedesktop.org On Mon, Oct 14, 2019 at 11:48:38PM -0400, Ilia Mirkin wrote: > 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 =3D (user_input & ~BIT_ULL(63)) >> (32 - n); > > > > + bool negative =3D !!(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 =3D 32, m =3D 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. >=20 > This goes counter to what the wikipedia page says [ > https://en.wikipedia.org/wiki/Q_(number_format) ]: >=20 > (reformatted slightly for text-only consumption): >=20 > """ > For example, a Q15.1 format number: >=20 > - requires 15+1 =3D 16 bits > - its range is [-2^14, 2^14 - 2^-1] =3D [-16384.0, +16383.5] =3D [0x8000, > 0x8001 ... 0xFFFF, 0x0000, 0x0001 ... 0x7FFE, 0x7FFF] > - its resolution is 2^-1 =3D 0.5 > """ >=20 > This suggests that the proper way to represent a standard 32-bit 2's > complement integer would be Q32.0. > Yes you're right, I will send a new version to correct this code according to the Wiki. Thanks James > -ilia