From patchwork Mon Dec 17 10:56:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 153981 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2324827ljp; Mon, 17 Dec 2018 02:59:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/WUFfErYpsxy/EIR7qnDE+cAxeeQog/ZMgShmj2zzvGyOi4vJurhI/ymk62+RoV+zsIz4+1 X-Received: by 2002:aed:3482:: with SMTP id x2mr12436874qtd.72.1545044342528; Mon, 17 Dec 2018 02:59:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545044342; cv=none; d=google.com; s=arc-20160816; b=wH+86G/S3aCG1o2h3KPSZHXWQ+7bjBTp7heUQ9tTLpJFFCinG0qpq2YK5AejTdCQAH KyvPiwhtAihA4ICRaALY3RH1Yiv3bEhrNdcDYkyXzcZPduy0f0nMZ+u5uJCJMkPQb++T ZUMYy+Y+3WWPl9JlfL1NppOFlq59hE/9Xawzv1dD5IkZQrpDNvu9nC+QR22IRW55mkMH 0aBAxgT/VWFDMkZt+C1RS0evnjRECApLmNEy1QSZwJWTA0CuFg1cRpbmoi+FjI0lqeSk G8ADz/QiqtvLU+tI1mBohcIAtwp35qyWHJDiD6WSGRywEuavAS+GoVQLUBIayewjA4/C H3wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Jo7mvkk8gYJZ07ZsA1PodkuMG0iSUhQYU7WZB/7bsKE=; b=g3kNKPr9MPGEfDZOb7z6uqnN4VpvqzrzJqDiRCxVfNhjaEkG4yw3hAn4OePStxlIKO OmvU8w7C1yEz0F8MwEtonP4gciAjDAqWIjNDUeI1INVHQoGJuXPuBrOOHbpZ42OQqjKQ l8ezsgplIsdpPj7memMnrgV7Tbh94fSaEPr6B1fCsYFIKzFNsWo7jcokBQMDYBffOGmR Vu8ai/cb5yrDt/gQq5Dapb7hSYxRBdNIb8F8zSXZdraVRXEFwxHmw5UGP8yFnI1sZ/ST jAtJ2p7kSwvwI0uPGVUedk3BZLAf+zvMXmcl+u8+RfW/+IC0DraOYbcYnzb+q70qctfB GvKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XPWruz+W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p4si761566qtj.126.2018.12.17.02.59.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 17 Dec 2018 02:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XPWruz+W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYqc2-0002hG-3A for patch@linaro.org; Mon, 17 Dec 2018 05:59:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYqbW-0002Y7-KI for qemu-devel@nongnu.org; Mon, 17 Dec 2018 05:58:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYqa8-0000C1-9N for qemu-devel@nongnu.org; Mon, 17 Dec 2018 05:57:09 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:52619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gYqa8-0000BI-0h for qemu-devel@nongnu.org; Mon, 17 Dec 2018 05:57:04 -0500 Received: by mail-wm1-x344.google.com with SMTP id m1so11885606wml.2 for ; Mon, 17 Dec 2018 02:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jo7mvkk8gYJZ07ZsA1PodkuMG0iSUhQYU7WZB/7bsKE=; b=XPWruz+WhKjIYbKM1dKlVI1XecohSvhfIZ1mYFqXTCxZh8bPjqaeuOlr10P8DljMus 4se/1N8mAiLfqqQ6jgwVImELBodcVN1EBzBTgD60XtSzfpm/1XU4PoTFlA9Tco/evOLT Jd6nloYuQ1QrISb4eVE4YcAl+Kc/GiyHwCdxU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jo7mvkk8gYJZ07ZsA1PodkuMG0iSUhQYU7WZB/7bsKE=; b=tcmbOQID8+mMmYZyAo3pHT5XBydsK79FSR2+2Eu7Cs1Gf+Ps658gytDCVJwCwrn5BJ G2mLvhqBUNxZMsQcVTQ3EizSK85DlrdKPnJgySaD4IxE8Iv5F2wi7Al+laI2p7yVQbYd F8SSeTZJ2P+5ab9k/Uky5cHSIOpV5uRUh5sEtQpsqFz022Iko66mQtGXxG26q79K/cX+ L+tf4w+Um4jr4c44V3uKmLftycA26KZ978ZS3E9XCXj2tsJN5OOwz6kxRtCsU2RcIP7N 95qUS6V5zEG0rkO2uo+MlsFkXG+5VUEVtM4RUwiXHB0Heq1qwIS/IMa1rlKDq94UwyYN 305A== X-Gm-Message-State: AA+aEWbEIDlKphglAszzQHmWYwk+Azgr4hXUTJPYuP4p8bOkmBiWqr12 /KETFsU170nP+6OPuEv5ilOZfg== X-Received: by 2002:a1c:384:: with SMTP id 126mr11260519wmd.26.1545044222396; Mon, 17 Dec 2018 02:57:02 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id v8sm11562185wrq.53.2018.12.17.02.56.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Dec 2018 02:56:59 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BBA343E0629; Mon, 17 Dec 2018 10:56:51 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 17 Dec 2018 10:56:49 +0000 Message-Id: <20181217105650.27361-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181217105650.27361-1-alex.bennee@linaro.org> References: <20181217105650.27361-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL v3 14/15] hardfloat: implement float32/64 square root X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Emilio G. Cota" , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Performance results for fp-bench: Host: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz - before: sqrt-single: 42.30 MFlops sqrt-double: 22.97 MFlops - after: sqrt-single: 311.42 MFlops sqrt-double: 311.08 MFlops Here USE_FP makes a huge difference for f64's, with throughput going from ~200 MFlops to ~300 MFlops. Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée -- 2.17.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 7554d63495..fbd66fd8dc 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3044,20 +3044,76 @@ float16 QEMU_FLATTEN float16_sqrt(float16 a, float_status *status) return float16_round_pack_canonical(pr, status); } -float32 QEMU_FLATTEN float32_sqrt(float32 a, float_status *status) +static float32 QEMU_SOFTFLOAT_ATTR +soft_f32_sqrt(float32 a, float_status *status) { FloatParts pa = float32_unpack_canonical(a, status); FloatParts pr = sqrt_float(pa, status, &float32_params); return float32_round_pack_canonical(pr, status); } -float64 QEMU_FLATTEN float64_sqrt(float64 a, float_status *status) +static float64 QEMU_SOFTFLOAT_ATTR +soft_f64_sqrt(float64 a, float_status *status) { FloatParts pa = float64_unpack_canonical(a, status); FloatParts pr = sqrt_float(pa, status, &float64_params); return float64_round_pack_canonical(pr, status); } +float32 QEMU_FLATTEN float32_sqrt(float32 xa, float_status *s) +{ + union_float32 ua, ur; + + ua.s = xa; + if (unlikely(!can_use_fpu(s))) { + goto soft; + } + + float32_input_flush1(&ua.s, s); + if (QEMU_HARDFLOAT_1F32_USE_FP) { + if (unlikely(!(fpclassify(ua.h) == FP_NORMAL || + fpclassify(ua.h) == FP_ZERO) || + signbit(ua.h))) { + goto soft; + } + } else if (unlikely(!float32_is_zero_or_normal(ua.s) || + float32_is_neg(ua.s))) { + goto soft; + } + ur.h = sqrtf(ua.h); + return ur.s; + + soft: + return soft_f32_sqrt(ua.s, s); +} + +float64 QEMU_FLATTEN float64_sqrt(float64 xa, float_status *s) +{ + union_float64 ua, ur; + + ua.s = xa; + if (unlikely(!can_use_fpu(s))) { + goto soft; + } + + float64_input_flush1(&ua.s, s); + if (QEMU_HARDFLOAT_1F64_USE_FP) { + if (unlikely(!(fpclassify(ua.h) == FP_NORMAL || + fpclassify(ua.h) == FP_ZERO) || + signbit(ua.h))) { + goto soft; + } + } else if (unlikely(!float64_is_zero_or_normal(ua.s) || + float64_is_neg(ua.s))) { + goto soft; + } + ur.h = sqrt(ua.h); + return ur.s; + + soft: + return soft_f64_sqrt(ua.s, s); +} + /*---------------------------------------------------------------------------- | The pattern for a default generated NaN. *----------------------------------------------------------------------------*/