From patchwork Fri Jan 22 22:07:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harry Wentland X-Patchwork-Id: 8093741 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 93D89BEEE5 for ; Fri, 22 Jan 2016 22:23:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A857F205CD for ; Fri, 22 Jan 2016 22:23:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 0ADA2205C7 for ; Fri, 22 Jan 2016 22:23:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8FD896E232; Fri, 22 Jan 2016 14:23:34 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1on0068.outbound.protection.outlook.com [157.56.110.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0701B6E232 for ; Fri, 22 Jan 2016 14:23:32 -0800 (PST) Received: from BY2PR12CA0015.namprd12.prod.outlook.com (10.160.121.25) by BN4PR12MB0850.namprd12.prod.outlook.com (10.164.59.12) with Microsoft SMTP Server (TLS) id 15.1.390.13; Fri, 22 Jan 2016 22:08:00 +0000 Received: from BY2NAM03FT045.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e4a::205) by BY2PR12CA0015.outlook.office365.com (2a01:111:e400:2c84::25) with Microsoft SMTP Server (TLS) id 15.1.390.13 via Frontend Transport; Fri, 22 Jan 2016 22:08:00 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from atltwp01.amd.com (165.204.84.221) by BY2NAM03FT045.mail.protection.outlook.com (10.152.85.113) with Microsoft SMTP Server id 15.1.390.12 via Frontend Transport; Fri, 22 Jan 2016 22:08:00 +0000 X-WSS-ID: 0O1DK5A-07-DLQ-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by atltwp01.amd.com (Axway MailGate 5.3.1) with ESMTPS id 28F3812C12C1 for ; Fri, 22 Jan 2016 17:07:57 -0500 (EST) Received: from SATLEXCHOV02.amd.com (10.181.40.72) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 22 Jan 2016 16:08:03 -0600 Received: from STOREXDAG02.amd.com (10.1.13.11) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Fri, 22 Jan 2016 16:07:58 -0600 Received: from cnhwentlanub.amd.com (172.29.225.36) by storexdag02.amd.com (10.1.13.11) with Microsoft SMTP Server id 14.3.266.1; Fri, 22 Jan 2016 17:07:57 -0500 From: Harry Wentland To: Subject: [PATCH 1/5] drm: Add drm_fixp_from_fraction and drm_fixp2int_ceil Date: Fri, 22 Jan 2016 17:07:25 -0500 Message-ID: <1453500449-9224-2-git-send-email-harry.wentland@amd.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453500449-9224-1-git-send-email-harry.wentland@amd.com> References: <1453500449-9224-1-git-send-email-harry.wentland@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.221; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(428002)(199003)(189002)(19580405001)(48376002)(92566002)(450100001)(11100500001)(87936001)(50226001)(2950100001)(97736004)(110136002)(5003600100002)(86362001)(105586002)(19580395003)(189998001)(47776003)(50466002)(586003)(106466001)(2351001)(2906002)(5008740100001)(36756003)(4326007)(1096002)(77096005)(33646002)(1220700001)(53416004)(5003940100001)(50986999)(76176999)(229853001)(101416001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN4PR12MB0850; H:atltwp01.amd.com; FPR:; SPF:None; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN4PR12MB0850; 2:mYXa1hZNL1skzfYfXPrlwLNAuFEmGvLZGA2xmx3CZWqoaqrZRLaZWO8s3tL3g2zM5h9Qjv3XmA1FhzsPALcyvcfue2Az9CpsXbmpO3QRxe0L/qAdLfIfv8zKmxZCEgCN71257EqgqXhU0p51S3IKVw==; 3:6CZ3cs5SkCpU+ybdvMikil3OyVIMWRvk7228uj726jH/8bIrk070w8NC+fOP1TF4w1/5QNM1TvkGHBQdGGux//iRZPpg4cnct5KigQ/eYlfnVhu9NNHo+kNOWrfWDaLpwsFYBEZc7uFiPfKYnJjoGC57pXTuXBdoA83H7jhCSogLicHczaiCbzwZt5OEhTS/3jm+yfbWxC8QqYaYdEt/FWqL3OTBge2M7ghikXG1xDk=; 25:BGvdDg0Epj1tYNG6OLeqMfEyCXPNk1R7VRR860YJj8zVEqD0zj1f3MCVDJkucU1jbkXVxjs9+jRibbw/7Vlc+yMfzOa/JHM/QScck/+ZNMq32VTQNIw7X3jOApoCGbHWUqOBCKEgmxguRA1aQQnoEoa3naO61RedfflDQdX7krLeSgWEIaUDRAWJV9E6Jn5mCnvO3g4hHyT1MZzacEkAX1TpvARMPdg2CZCBtO2vNqlQLbhhPHwAg8KEwgOa2s7m X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN4PR12MB0850; X-MS-Office365-Filtering-Correlation-Id: b46eac7d-5ac9-400b-2861-08d323787dc8 X-Microsoft-Exchange-Diagnostics: 1; BN4PR12MB0850; 20:FkQbsxN23F1FyVIzLKfNQjnUhFGISkVMM2HoC+XJvFkwx88/7o2UsjX6qEcHRBkCPKCLzcUlgvmMsOc0lPmY1NE+slGvF6YtZ93eMOvJb3FNrr9Plil1CGpLLUElAMjW/fhEwU2usSk/Y7C4AZTFQePaCU5DeeFpfQrrFEF7Ntr7klbGqiJmT+iFAQBxNM26YZYvgL3RSoP2ZuIvXBfYc4l1MyFyRlm090GM/bEGfb6TCrbIZvECFPW0BKVim0yIf6DxExhUGaHq68i2ujmGg6MdsW3G3Izo5AKnkDwfBmDfDSSluSgXG1Vq/VPs1MG00cex6Cze9uDzvyr6ujWEEi+6Ko1u6Ht6OduxmraGLy+L6M1qhYWyEGDcNNWT3cHxyGETIG6P3LdD2qvr07snqFMKsyAdo9dNlyGgTzGirjq8fwXB9d5zjjr6CwWE2msnNpZRbSQoZ2bwJqu2hq+tfQG/3CRCa9OJ7OQiYcxlv9qhaMQ5dHRwr4MX9xHNvUsC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(123027)(601004)(2401047)(5005006)(520078)(13018025)(13024025)(13023025)(13015025)(13017025)(8121501046)(10201501046)(3002001); SRVR:BN4PR12MB0850; BCL:0; PCL:0; RULEID:; SRVR:BN4PR12MB0850; X-Microsoft-Exchange-Diagnostics: 1; BN4PR12MB0850; 4:qjQz6p9sciBGazUjIaxtEgq+ChZXoM11x+GuaZWgEp8NFoC50rY8s1JsGvQR3B3sVfYndBwCU/Lmuo7HWixUBHR6QrsXAPGa5meagVsnDd7zhoTHRgteUoWVbw9Ssz+n6oYF7lfzUPhgw9gISDisd3QOlNo1d5Jgo2wGBObzSK9KgLtJMaeNbKh6vU7BoFp9rWvJsNGhlSYE0vuZ+s7uenViv/EKmQnY6VoluVT0LjS3Ik9xutTXs8NX2njPObnENx3hw2mxpwYTDN1qAfvX7hX6o0HSsCoXyEZzwZBzG4ddEDyWHlt9kfs2iYXYBVSLOgBzlsJ3t8rzhI7HEEsam/WUy1V+JS9Yfy0NgRDQ2z2cbUBtkcZbrkOS/QGYVtO/+NT5jVnpKUR0+6TYuMWCtfdoM+X92b7LlGoq+1sT0WS3TGjCaUdqZIwhgN/rRO483soOkwUe7juw4ScnYvSsbcVDa8ww9qWdyEBY1ZzZZmCniyXp/jH/L+70h4kEjrazyO0OnkspIS79TejnZsqd5Q== X-Forefront-PRVS: 08296C9B35 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN4PR12MB0850; 23:7HJIzM5ltZRUbtOR1hu26+oY89VONO1v+qoAEziCd?= =?us-ascii?Q?FxxZdOe7OUi2woNTYJu/ZAofH4re+pdK9o+RUmeD8BjpoSsAgmpuZ71uBDrf?= =?us-ascii?Q?KzxC/AJCSvoPppBvDRyiWreUENdg+JOQKPToQ+cQNM0TvbuCUiWypjPh0Key?= =?us-ascii?Q?AQMdec99KHq1kwTgGNmUrsppSBdKm33AGzI8QRlLLnhXYkDW1Jr6HA58C9/f?= =?us-ascii?Q?mCcYc8DGw5oVBv0iz8BvDmJ1cCs1traJy69co9nrkxAVFRFRH2rAJ2sdJwJk?= =?us-ascii?Q?c24vGSI2fAkYbEt/zzzUSzt3zuNniV7O3mevO5rZzdR1ugw2XTW5HSeAAIAK?= =?us-ascii?Q?IxvMTJ2//vgjX1TyzN5kioXHixBpb/wbeLYivsEvimzmHmnCG6TRcpml1x0v?= =?us-ascii?Q?Feten9mjfEwjAADbwZgl6LPehEf+Mknie1IAxueTE82Xyq4b1K5W0rmZQKxs?= =?us-ascii?Q?V25pDR2lFanpB/ljtTiTzxc9Xudq29xnVYaKmKtxawehy/LHOCrkScCV3yh/?= =?us-ascii?Q?WvChzvj0aD1eiiMmBJwKb4O/gxJ1A7Dnh6QnyrlfpL9LYUrRMsGC5njRr97O?= =?us-ascii?Q?kNJP6yvxzZptsrVST3EUWgr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dI2hxuUPfu4gFHtOQWXdUQp2UNQFHGt3Yqk4AcC SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2016 22:08:00.0657 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.221]; Helo=[atltwp01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN4PR12MB0850 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP drm_fixp_from_fraction allows us to create a fixed point directly from a fraction, rather than creating fixed point values and dividing later. This avoids overflow of our 64 bit value for large numbers. drm_fixp2int_ceil allows us to return the ceiling of our fixed point value. Signed-off-by: Harry Wentland Reviewed-by: Alex Deucher --- include/drm/drm_fixed.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h index d639049a613d..16e725c42422 100644 --- a/include/drm/drm_fixed.h +++ b/include/drm/drm_fixed.h @@ -73,18 +73,28 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B) #define DRM_FIXED_ONE (1ULL << DRM_FIXED_POINT) #define DRM_FIXED_DECIMAL_MASK (DRM_FIXED_ONE - 1) #define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK) +#define DRM_FIXED_EPSILON 1LL +#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) static inline s64 drm_int2fixp(int a) { return ((s64)a) << DRM_FIXED_POINT; } -static inline int drm_fixp2int(int64_t a) +static inline int drm_fixp2int(s64 a) { return ((s64)a) >> DRM_FIXED_POINT; } -static inline unsigned drm_fixp_msbset(int64_t a) +static inline int drm_fixp2int_ceil(s64 a) +{ + if (a > 0) + return drm_fixp2int(a + DRM_FIXED_ALMOST_ONE); + else + return drm_fixp2int(a - DRM_FIXED_ALMOST_ONE); +} + +static inline unsigned drm_fixp_msbset(s64 a) { unsigned shift, sign = (a >> 63) & 1; @@ -136,6 +146,46 @@ static inline s64 drm_fixp_div(s64 a, s64 b) return result; } +static inline s64 drm_fixp_from_fraction(s64 a, s64 b) +{ + s64 res; + bool a_neg = a < 0; + bool b_neg = b < 0; + u64 a_abs = a_neg ? -a : a; + u64 b_abs = b_neg ? -b : b; + u64 rem; + + /* determine integer part */ + u64 res_abs = a_abs / b_abs; + rem = a_abs % b_abs; + + /* determine fractional part */ + { + u32 i = DRM_FIXED_POINT; + + do { + rem <<= 1; + res_abs <<= 1; + if (rem >= b_abs) { + res_abs |= 1; + rem -= b_abs; + } + } while (--i != 0); + } + + /* round up LSB */ + { + u64 summand = (rem << 1) >= b_abs; + + res_abs += summand; + } + + res = (s64) res_abs; + if (a_neg ^ b_neg) + res = -res; + return res; +} + static inline s64 drm_fixp_exp(s64 x) { s64 tolerance = div64_s64(DRM_FIXED_ONE, 1000000);