From patchwork Fri Jul 24 00:28:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 247099 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1976121ilg; Thu, 23 Jul 2020 17:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGy7WESBiIivRMeAJqsz9PsZ5OMRJnxGF9nimnLEr1BpL/0CLqW9UY+umYTwD1PzBzGFIo X-Received: by 2002:a25:c05:: with SMTP id 5mr10547652ybm.301.1595550525626; Thu, 23 Jul 2020 17:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595550525; cv=none; d=google.com; s=arc-20160816; b=uj/2UBk5fkV2DiecJRc4ohYhZohB8qxELHGg11O/kd/pbTfOj8ac1ZBIOGc3obXxoN wYJ83ImxRfX45cl7V1tIDL4MRmlgnYCjCE4gqQWYaLMqOQlyc51tjZ/HgXnSs9UxNApR ALJ0KQ+XCa7PVTE+3zWo7tR4mwm/Fpik8wP+1FNlRRIpiUgDakSyJK5RT1K8uOHrWvJc 9nlPM8LbbN3gtYu/7bT9kazogIX+nchl573p1EpjlqEonjdHlrBZ0CNiOfBcim75UyX+ AC/4Of1CTmbRyNSAu4UjjTF45+sFa1b14V/YO1QbXG3o6/20S83aHJswmKY3kGJII96+ CGHg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Sujhg6CWtGD0cTKixZpHYTp8eVUCvTssOp7pcX2qTrI=; b=FYJ5BuvfVtO7VL4FbHtMJF+6FcTzJvN42XupQA4kXYpYsCuXsdLOVK8lwReXLHWSHH IeJOlV7DWx2wCxvz2m/uLRwK8Gf/ociEwMYtlRtFcZ0+5e9u5qfa8MavR0UPaMfxN3cC l2ps4mvneYN4mGF5JBJeIyaUve1MaH2XTOr4w2gn1lkTvoyU97Ha+cQm1aRsMaEh3h7y 6ZIVJEVv0C1vD2Ks4wdk73fjH7k+SDbcc+vTH+h4sZzyM7HcdcO5lM+nmKqZ9kDfX1hl bEcDSg7fWfeTqvkATFZTNcGJDEbyKgRrF7p9rbUPhIK/OztNQvkj4oGoWQo/UtjwB9Aa JEyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YkqmLXls; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id e10si4093093ybm.14.2020.07.23.17.28.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Jul 2020 17:28:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YkqmLXls; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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]:47920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jylZs-0000Hw-SF for patch@linaro.org; Thu, 23 Jul 2020 20:28:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jylZP-00009y-5E for qemu-devel@nongnu.org; Thu, 23 Jul 2020 20:28:15 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:54950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jylZM-0008EL-0U for qemu-devel@nongnu.org; Thu, 23 Jul 2020 20:28:14 -0400 Received: by mail-pj1-x102c.google.com with SMTP id mn17so4186522pjb.4 for ; Thu, 23 Jul 2020 17:28:11 -0700 (PDT) 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=Sujhg6CWtGD0cTKixZpHYTp8eVUCvTssOp7pcX2qTrI=; b=YkqmLXlsxvplRqaok+VAYFaN+60GrEEVw+VRXsOcWmtUC8TNIS1aBSMveiA7vU0uUY DjQzlaRYDFazEHFj5e8Qzm2kv6UqoZrCzZGFVxeOEWGNQsB9icnHYmSZ9NfvB1ba0q7N DtCIHVwcZIa65Kg5SLVwGlGheLrFLeaHodesZXG5ppKt2cGtSoNHhht3S2xlwH5gX49j HYkdia3Pr0Gqm5gSRQXVkLaSUvwH6VeZl7n1Bodh5CLnJr6c2iRUQodN+3NKrrUVsarY PTRNuHO1blHv/ATEx+8G9QxpjA0taenmEj7znN5VVfIztIegu8VnARH2cvUCtSLx8kGZ GViw== 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=Sujhg6CWtGD0cTKixZpHYTp8eVUCvTssOp7pcX2qTrI=; b=UT+XsbqMs/9Nz6EG8lE/QLABnWdo0t0zjt9MfqKx76fTjm8yFtwoD3IjGsRZW5Zvak +ZmStAgARqj2zyspuoSGjoXgCTyLUfvhUyzIgWu5+bvpDa178I8WWcCwW5eQHQSfYJPr ihjObeH77u7k/7T5CtK3wIeDmKNddEjxeb6V9FzvRni1rdsU0jko9fsGK2jHsA36u2kq Pe6jGoiTh2iKfXVeq5EzSQ4PaJ7vPO7n/ScJROLEtPAZ6txC8tJqL97ZAjS1NUxYPcOd a7PY46xlYE6MGPHN/MV1otrYMJ/5QVPQSial+40vICVHq0jR9cqJOuRS1elj/bhwFcqi jLVQ== X-Gm-Message-State: AOAM531q2o8MeMg9scQx0fKYYPvb4wgcNbZ+iaFGKKqdiwU2Tt0KRV7w U3T1gLNPvvj4+uNeCBBkzUkGHrxP9zI= X-Received: by 2002:a17:90a:71c4:: with SMTP id m4mr2934335pjs.178.1595550490256; Thu, 23 Jul 2020 17:28:10 -0700 (PDT) Received: from localhost.localdomain (216-160-65-90.tukw.qwest.net. [216.160.65.90]) by smtp.gmail.com with ESMTPSA id q20sm4224635pfn.111.2020.07.23.17.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 17:28:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/7] target/riscv: Generate nanboxed results from fp helpers Date: Thu, 23 Jul 2020 17:28:01 -0700 Message-Id: <20200724002807.441147-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724002807.441147-1-richard.henderson@linaro.org> References: <20200724002807.441147-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: frank.chang@sifive.com, alistair23@gmail.com, qemu-riscv@nongnu.org, zhiwei_liu@c-sky.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Make sure that all results from single-precision scalar helpers are properly nan-boxed to 64-bits. Signed-off-by: Richard Henderson --- target/riscv/internals.h | 5 +++++ target/riscv/fpu_helper.c | 42 +++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 19 deletions(-) -- 2.25.1 Reviewed-by: LIU Zhiwei Reviewed-by: Chih-Min Chao diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 37d33820ad..9f4ba7d617 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -38,4 +38,9 @@ target_ulong fclass_d(uint64_t frs1); #define SEW32 2 #define SEW64 3 +static inline uint64_t nanbox_s(float32 f) +{ + return f | MAKE_64BIT_MASK(32, 32); +} + #endif diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index 4379756dc4..72541958a7 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -81,10 +81,16 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm) set_float_rounding_mode(softrm, &env->fp_status); } +static uint64_t do_fmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, + uint64_t frs3, int flags) +{ + return nanbox_s(float32_muladd(frs1, frs2, frs3, flags, &env->fp_status)); +} + uint64_t helper_fmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t frs3) { - return float32_muladd(frs1, frs2, frs3, 0, &env->fp_status); + return do_fmadd_s(env, frs1, frs2, frs3, 0); } uint64_t helper_fmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, @@ -96,8 +102,7 @@ uint64_t helper_fmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t helper_fmsub_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t frs3) { - return float32_muladd(frs1, frs2, frs3, float_muladd_negate_c, - &env->fp_status); + return do_fmadd_s(env, frs1, frs2, frs3, float_muladd_negate_c); } uint64_t helper_fmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, @@ -110,8 +115,7 @@ uint64_t helper_fmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t helper_fnmsub_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t frs3) { - return float32_muladd(frs1, frs2, frs3, float_muladd_negate_product, - &env->fp_status); + return do_fmadd_s(env, frs1, frs2, frs3, float_muladd_negate_product); } uint64_t helper_fnmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, @@ -124,8 +128,8 @@ uint64_t helper_fnmsub_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t helper_fnmadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t frs3) { - return float32_muladd(frs1, frs2, frs3, float_muladd_negate_c | - float_muladd_negate_product, &env->fp_status); + return do_fmadd_s(env, frs1, frs2, frs3, + float_muladd_negate_c | float_muladd_negate_product); } uint64_t helper_fnmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, @@ -137,37 +141,37 @@ uint64_t helper_fnmadd_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2, uint64_t helper_fadd_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_add(frs1, frs2, &env->fp_status); + return nanbox_s(float32_add(frs1, frs2, &env->fp_status)); } uint64_t helper_fsub_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_sub(frs1, frs2, &env->fp_status); + return nanbox_s(float32_sub(frs1, frs2, &env->fp_status)); } uint64_t helper_fmul_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_mul(frs1, frs2, &env->fp_status); + return nanbox_s(float32_mul(frs1, frs2, &env->fp_status)); } uint64_t helper_fdiv_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_div(frs1, frs2, &env->fp_status); + return nanbox_s(float32_div(frs1, frs2, &env->fp_status)); } uint64_t helper_fmin_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_minnum(frs1, frs2, &env->fp_status); + return nanbox_s(float32_minnum(frs1, frs2, &env->fp_status)); } uint64_t helper_fmax_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) { - return float32_maxnum(frs1, frs2, &env->fp_status); + return nanbox_s(float32_maxnum(frs1, frs2, &env->fp_status)); } uint64_t helper_fsqrt_s(CPURISCVState *env, uint64_t frs1) { - return float32_sqrt(frs1, &env->fp_status); + return nanbox_s(float32_sqrt(frs1, &env->fp_status)); } target_ulong helper_fle_s(CPURISCVState *env, uint64_t frs1, uint64_t frs2) @@ -209,23 +213,23 @@ uint64_t helper_fcvt_lu_s(CPURISCVState *env, uint64_t frs1) uint64_t helper_fcvt_s_w(CPURISCVState *env, target_ulong rs1) { - return int32_to_float32((int32_t)rs1, &env->fp_status); + return nanbox_s(int32_to_float32((int32_t)rs1, &env->fp_status)); } uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1) { - return uint32_to_float32((uint32_t)rs1, &env->fp_status); + return nanbox_s(uint32_to_float32((uint32_t)rs1, &env->fp_status)); } #if defined(TARGET_RISCV64) uint64_t helper_fcvt_s_l(CPURISCVState *env, uint64_t rs1) { - return int64_to_float32(rs1, &env->fp_status); + return nanbox_s(int64_to_float32(rs1, &env->fp_status)); } uint64_t helper_fcvt_s_lu(CPURISCVState *env, uint64_t rs1) { - return uint64_to_float32(rs1, &env->fp_status); + return nanbox_s(uint64_to_float32(rs1, &env->fp_status)); } #endif @@ -266,7 +270,7 @@ uint64_t helper_fmax_d(CPURISCVState *env, uint64_t frs1, uint64_t frs2) uint64_t helper_fcvt_s_d(CPURISCVState *env, uint64_t rs1) { - return float64_to_float32(rs1, &env->fp_status); + return nanbox_s(float64_to_float32(rs1, &env->fp_status)); } uint64_t helper_fcvt_d_s(CPURISCVState *env, uint64_t rs1)