From patchwork Wed Feb 17 23:40:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 384011 Delivered-To: patch@linaro.org Received: by 2002:a02:c80e:0:0:0:0:0 with SMTP id p14csp3222210jao; Wed, 17 Feb 2021 15:50:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+All9CD7OS3XVRlsyLf53WRbAIyKz30/aLYl4faww4FAnGMlzCZp1/1xkeK5d3Doc/KfX X-Received: by 2002:a25:d4d0:: with SMTP id m199mr3054190ybf.26.1613605826065; Wed, 17 Feb 2021 15:50:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613605826; cv=none; d=google.com; s=arc-20160816; b=h+ec02atMqzfIYJLum/WU1dlSebYMAhs6W51kV7OXCPFKoYFqyYMFZhtp+EDs+/Wnp WeSnRG6cJHXQsXxEe9DEKPhscrbiGgyh4Oo99AUu12IEI/LH37sm3l0tX32Hvhaf8ypZ 82jsKgdD7a//66wM+esIfQIrixn7HyYMROJQ1QOmyLZBmK0N+W2DhqlpTQ+8UIGKHFXO OClt7t8fZ8LG3BmNqNBVpgF0PD8tQZS37/IxVfuJbEXIybedTX90Mtx7ceK23aA91lI/ XKFQK305MLeW43dhH46vTL6ZFWfRimGdee2b5mgvxPzHJBRaDPbIi/lhSmQ87IMujPDD FwkQ== 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=nKMqug/uvk4wMgHy5mH79wL6sqcjbk2He0GvstqA04M=; b=Ub9bcH5KFIS3lZM1hwyfudIWYwwJufAASme3aFaxOrkZvrKZa0ZVNJOvlZHGfbzsML sNnQIQ5NPpHwsGX1EdQIAzXk9xqUGDQeJZymE17IMui1H1+qPeEpclj6AmQqroy2m6To +SmSjZ9l7QX/Prss/dwyiIp+LK4jhsEypmezGIAIaaASMPSmi13nQMMO+dRwEooF31mG Wh9pugphb/mUsIUGUG0FDworeHan2FIoB3iqBhi6OzojnBn4gHav0uZzhLsL4QePPOVM L4SiFHS6B6kk8mWANPm3LIe46wbkfPaC34KS3NKGo7oDtRBIYPjAD9VqXOQdqlwJwem3 orng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dL6YCej4; 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=pass (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 b12si816212ybm.165.2021.02.17.15.50.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Feb 2021 15:50:26 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=dL6YCej4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lCWaP-0002x0-HG for patch@linaro.org; Wed, 17 Feb 2021 18:50:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lCWRP-0000Md-Be for qemu-devel@nongnu.org; Wed, 17 Feb 2021 18:41:07 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:46488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lCWRM-0004gg-28 for qemu-devel@nongnu.org; Wed, 17 Feb 2021 18:41:06 -0500 Received: by mail-pg1-x530.google.com with SMTP id 75so6129874pgf.13 for ; Wed, 17 Feb 2021 15:41: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=nKMqug/uvk4wMgHy5mH79wL6sqcjbk2He0GvstqA04M=; b=dL6YCej4rLazl8wNXiSnLDcWaPzPpuCsNbwiQZ3zL12Xt1GBCE7bHsWq1setRHOr/J ODExBTvYB3lPHHeI/cNWe6YAu1MC1THz0wuPM4Yiyyb5v5KlBXSQHvr6uLOXoqj/Cxom haAZu401O93Ds0jss2QfxmvNC35QihNd/Er5DgYXke49vsj6poTI8BXsZuN2TgVnMjq6 t9RZbu7VXua/P3YVRwf7tg29J80M3gy6J5hq+RULTj3nxrIzzs+V41f2vJeKs1jyYD56 Lc7dkfY4GqXfNvVNRhMZZluhfbFt7ZtVPSoRr+T+B7Izo9Vn+tZ6vb+X1xJa+Dvg6QTy 9hRQ== 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=nKMqug/uvk4wMgHy5mH79wL6sqcjbk2He0GvstqA04M=; b=k9zgsrFk+4Lmhqk0jAcuMfL7QaXs3IA4l/3mOXl0f009fLvqxfzkJDObmdE/nEzlh1 O/PJenM5Ra1bBYgy8EpWzfNjxOo6qOQcvGx7TxfBjxNljymQt+3ivA/rWwxbeqtqghxn msqUG4NIl94dWL1+wb9VWeoYG2WOOgG2F3gL5kWhkXtZ4pf4Xod9hLoa1rUQEZ2kaADW zqf9qBAnC95CgncoSCSAwGcgrC4JtJte1cchiW6uRV8h+MSAqBy1Kq+Q4lhNCqj7g9OA tnBUFU+OAvIKvWtQj4ChjfCKWnfY5QEKiMgYgYkEsT/ujVZqfumU3DLqBAh9cEytqa7b iXxg== X-Gm-Message-State: AOAM531bSob4nDJNdGdIGNdBM2GEl6jjucsjb3a6nehjnhnec6InFOga LEU4BdEbEN2wL8sq2smFejticZqfJ62Rtw== X-Received: by 2002:aa7:92d9:0:b029:1bb:b6de:c872 with SMTP id k25-20020aa792d90000b02901bbb6dec872mr1577503pfa.68.1613605262469; Wed, 17 Feb 2021 15:41:02 -0800 (PST) Received: from localhost.localdomain (047-051-160-125.biz.spectrum.com. [47.51.160.125]) by smtp.gmail.com with ESMTPSA id c21sm3950355pgh.0.2021.02.17.15.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 15:41:01 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 17/35] Hexagon (target/hexagon/conv_emu.[ch]) utility functions Date: Wed, 17 Feb 2021 15:40:05 -0800 Message-Id: <20210217234023.1742406-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210217234023.1742406-1-richard.henderson@linaro.org> References: <20210217234023.1742406-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com 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=ham 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: peter.maydell@linaro.org, Taylor Simpson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Taylor Simpson Signed-off-by: Taylor Simpson Message-Id: <1612763186-18161-17-git-send-email-tsimpson@quicinc.com> Signed-off-by: Richard Henderson --- target/hexagon/conv_emu.h | 31 +++++++ target/hexagon/conv_emu.c | 177 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 target/hexagon/conv_emu.h create mode 100644 target/hexagon/conv_emu.c -- 2.25.1 diff --git a/target/hexagon/conv_emu.h b/target/hexagon/conv_emu.h new file mode 100644 index 0000000000..cade9de91f --- /dev/null +++ b/target/hexagon/conv_emu.h @@ -0,0 +1,31 @@ +/* + * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef HEXAGON_CONV_EMU_H +#define HEXAGON_CONV_EMU_H + +uint64_t conv_sf_to_8u(float32 in, float_status *fp_status); +uint32_t conv_sf_to_4u(float32 in, float_status *fp_status); +int64_t conv_sf_to_8s(float32 in, float_status *fp_status); +int32_t conv_sf_to_4s(float32 in, float_status *fp_status); + +uint64_t conv_df_to_8u(float64 in, float_status *fp_status); +uint32_t conv_df_to_4u(float64 in, float_status *fp_status); +int64_t conv_df_to_8s(float64 in, float_status *fp_status); +int32_t conv_df_to_4s(float64 in, float_status *fp_status); + +#endif diff --git a/target/hexagon/conv_emu.c b/target/hexagon/conv_emu.c new file mode 100644 index 0000000000..3985b1032a --- /dev/null +++ b/target/hexagon/conv_emu.c @@ -0,0 +1,177 @@ +/* + * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/host-utils.h" +#include "fpu/softfloat.h" +#include "macros.h" +#include "conv_emu.h" + +#define LL_MAX_POS 0x7fffffffffffffffULL +#define MAX_POS 0x7fffffffU + +static uint64_t conv_f64_to_8u_n(float64 in, int will_negate, + float_status *fp_status) +{ + uint8_t sign = float64_is_neg(in); + if (float64_is_infinity(in)) { + float_raise(float_flag_invalid, fp_status); + if (float64_is_neg(in)) { + return 0ULL; + } else { + return ~0ULL; + } + } + if (float64_is_any_nan(in)) { + float_raise(float_flag_invalid, fp_status); + return ~0ULL; + } + if (float64_is_zero(in)) { + return 0; + } + if (sign) { + float_raise(float_flag_invalid, fp_status); + return 0; + } + if (float64_lt(in, float64_half, fp_status)) { + /* Near zero, captures large fracshifts, denorms, etc */ + float_raise(float_flag_inexact, fp_status); + switch (get_float_rounding_mode(fp_status)) { + case float_round_down: + if (will_negate) { + return 1; + } else { + return 0; + } + case float_round_up: + if (!will_negate) { + return 1; + } else { + return 0; + } + default: + return 0; /* nearest or towards zero */ + } + } + return float64_to_uint64(in, fp_status); +} + +static void clr_float_exception_flags(uint8_t flag, float_status *fp_status) +{ + uint8_t flags = fp_status->float_exception_flags; + flags &= ~flag; + set_float_exception_flags(flags, fp_status); +} + +static uint32_t conv_df_to_4u_n(float64 fp64, int will_negate, + float_status *fp_status) +{ + uint64_t tmp; + tmp = conv_f64_to_8u_n(fp64, will_negate, fp_status); + if (tmp > 0x00000000ffffffffULL) { + clr_float_exception_flags(float_flag_inexact, fp_status); + float_raise(float_flag_invalid, fp_status); + return ~0U; + } + return (uint32_t)tmp; +} + +uint64_t conv_df_to_8u(float64 in, float_status *fp_status) +{ + return conv_f64_to_8u_n(in, 0, fp_status); +} + +uint32_t conv_df_to_4u(float64 in, float_status *fp_status) +{ + return conv_df_to_4u_n(in, 0, fp_status); +} + +int64_t conv_df_to_8s(float64 in, float_status *fp_status) +{ + uint8_t sign = float64_is_neg(in); + uint64_t tmp; + if (float64_is_any_nan(in)) { + float_raise(float_flag_invalid, fp_status); + return -1; + } + if (sign) { + float64 minus_fp64 = float64_abs(in); + tmp = conv_f64_to_8u_n(minus_fp64, 1, fp_status); + } else { + tmp = conv_f64_to_8u_n(in, 0, fp_status); + } + if (tmp > (LL_MAX_POS + sign)) { + clr_float_exception_flags(float_flag_inexact, fp_status); + float_raise(float_flag_invalid, fp_status); + tmp = (LL_MAX_POS + sign); + } + if (sign) { + return -tmp; + } else { + return tmp; + } +} + +int32_t conv_df_to_4s(float64 in, float_status *fp_status) +{ + uint8_t sign = float64_is_neg(in); + uint64_t tmp; + if (float64_is_any_nan(in)) { + float_raise(float_flag_invalid, fp_status); + return -1; + } + if (sign) { + float64 minus_fp64 = float64_abs(in); + tmp = conv_f64_to_8u_n(minus_fp64, 1, fp_status); + } else { + tmp = conv_f64_to_8u_n(in, 0, fp_status); + } + if (tmp > (MAX_POS + sign)) { + clr_float_exception_flags(float_flag_inexact, fp_status); + float_raise(float_flag_invalid, fp_status); + tmp = (MAX_POS + sign); + } + if (sign) { + return -tmp; + } else { + return tmp; + } +} + +uint64_t conv_sf_to_8u(float32 in, float_status *fp_status) +{ + float64 fp64 = float32_to_float64(in, fp_status); + return conv_df_to_8u(fp64, fp_status); +} + +uint32_t conv_sf_to_4u(float32 in, float_status *fp_status) +{ + float64 fp64 = float32_to_float64(in, fp_status); + return conv_df_to_4u(fp64, fp_status); +} + +int64_t conv_sf_to_8s(float32 in, float_status *fp_status) +{ + float64 fp64 = float32_to_float64(in, fp_status); + return conv_df_to_8s(fp64, fp_status); +} + +int32_t conv_sf_to_4s(float32 in, float_status *fp_status) +{ + float64 fp64 = float32_to_float64(in, fp_status); + return conv_df_to_4s(fp64, fp_status); +}