Bochs/bochs/cpu/simd_pfp.h
Stanislav Shwartsman 44241a1e56 - Added support for AVX and AVX2 instructions emulation, to enable configure
with --enable-avx option. When compiled in, AVX still has to be enabled
    using .bochsrc CPUID option. AVX2 FMA instructions still not implemented.

  - Added support for Bit Manipulation Instructions (BMI) emulation. The BMI
    instructions support can be enabled using .bochsrc CPUID option.
2011-08-27 13:47:16 +00:00

343 lines
15 KiB
C

/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2011 Stanislav Shwartsman
// Written by Stanislav Shwartsman [sshwarts at sourceforge net]
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
//
/////////////////////////////////////////////////////////////////////////
#ifndef BX_SIMD_PFP_FUNCTIONS_H
#define BX_SIMD_PFP_FUNCTIONS_H
// arithmetic add/sub/mul/div
BX_CPP_INLINE void sse_addps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_add(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(1) = float32_add(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(2) = float32_add(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(3) = float32_add(op1->xmm32u(3), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_addpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_add(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(1) = float64_add(op1->xmm64u(1), op2->xmm64u(1), status);
}
BX_CPP_INLINE void sse_subps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_sub(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(1) = float32_sub(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(2) = float32_sub(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(3) = float32_sub(op1->xmm32u(3), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_subpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_sub(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(1) = float64_sub(op1->xmm64u(1), op2->xmm64u(1), status);
}
BX_CPP_INLINE void sse_mulps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_mul(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(1) = float32_mul(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(2) = float32_mul(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(3) = float32_mul(op1->xmm32u(3), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_mulpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_mul(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(1) = float64_mul(op1->xmm64u(1), op2->xmm64u(1), status);
}
BX_CPP_INLINE void sse_divps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_div(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(1) = float32_div(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(2) = float32_div(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(3) = float32_div(op1->xmm32u(3), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_divpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_div(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(1) = float64_div(op1->xmm64u(1), op2->xmm64u(1), status);
}
BX_CPP_INLINE void sse_addsubps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_sub(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(1) = float32_add(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(2) = float32_sub(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(3) = float32_add(op1->xmm32u(3), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_addsubpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_sub(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(1) = float64_add(op1->xmm64u(1), op2->xmm64u(1), status);
}
// horizontal arithmetic add/sub
BX_CPP_INLINE void sse_haddps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_add(op1->xmm32u(0), op1->xmm32u(1), status);
op1->xmm32u(1) = float32_add(op1->xmm32u(2), op1->xmm32u(3), status);
op1->xmm32u(2) = float32_add(op2->xmm32u(0), op2->xmm32u(1), status);
op1->xmm32u(3) = float32_add(op2->xmm32u(2), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_haddpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_add(op1->xmm64u(0), op1->xmm64u(1), status);
op1->xmm64u(1) = float64_add(op2->xmm64u(0), op2->xmm64u(1), status);
}
BX_CPP_INLINE void sse_hsubps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
op1->xmm32u(0) = float32_sub(op1->xmm32u(0), op1->xmm32u(1), status);
op1->xmm32u(1) = float32_sub(op1->xmm32u(2), op1->xmm32u(3), status);
op1->xmm32u(2) = float32_sub(op2->xmm32u(0), op2->xmm32u(1), status);
op1->xmm32u(3) = float32_sub(op2->xmm32u(2), op2->xmm32u(3), status);
}
BX_CPP_INLINE void sse_hsubpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
op1->xmm64u(0) = float64_sub(op1->xmm64u(0), op1->xmm64u(1), status);
op1->xmm64u(1) = float64_sub(op2->xmm64u(0), op2->xmm64u(1), status);
}
// min/max
BX_CPP_INLINE void sse_minps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
int rc = float32_compare(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(0) = (rc == float_relation_less) ? op1->xmm32u(0) : op2->xmm32u(0);
rc = float32_compare(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(1) = (rc == float_relation_less) ? op1->xmm32u(1) : op2->xmm32u(1);
rc = float32_compare(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(2) = (rc == float_relation_less) ? op1->xmm32u(2) : op2->xmm32u(2);
rc = float32_compare(op1->xmm32u(3), op2->xmm32u(3), status);
op1->xmm32u(3) = (rc == float_relation_less) ? op1->xmm32u(3) : op2->xmm32u(3);
}
BX_CPP_INLINE void sse_minpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
int rc = float64_compare(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(0) = (rc == float_relation_less) ? op1->xmm64u(0) : op2->xmm64u(0);
rc = float64_compare(op1->xmm64u(1), op2->xmm64u(1), status);
op1->xmm64u(1) = (rc == float_relation_less) ? op1->xmm64u(1) : op2->xmm64u(1);
}
BX_CPP_INLINE void sse_maxps(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm32u(0) = float32_denormal_to_zero(op1->xmm32u(0));
op1->xmm32u(1) = float32_denormal_to_zero(op1->xmm32u(1));
op1->xmm32u(2) = float32_denormal_to_zero(op1->xmm32u(2));
op1->xmm32u(3) = float32_denormal_to_zero(op1->xmm32u(3));
op2->xmm32u(0) = float32_denormal_to_zero(op2->xmm32u(0));
op2->xmm32u(1) = float32_denormal_to_zero(op2->xmm32u(1));
op2->xmm32u(2) = float32_denormal_to_zero(op2->xmm32u(2));
op2->xmm32u(3) = float32_denormal_to_zero(op2->xmm32u(3));
}
int rc = float32_compare(op1->xmm32u(0), op2->xmm32u(0), status);
op1->xmm32u(0) = (rc == float_relation_greater) ? op1->xmm32u(0) : op2->xmm32u(0);
rc = float32_compare(op1->xmm32u(1), op2->xmm32u(1), status);
op1->xmm32u(1) = (rc == float_relation_greater) ? op1->xmm32u(1) : op2->xmm32u(1);
rc = float32_compare(op1->xmm32u(2), op2->xmm32u(2), status);
op1->xmm32u(2) = (rc == float_relation_greater) ? op1->xmm32u(2) : op2->xmm32u(2);
rc = float32_compare(op1->xmm32u(3), op2->xmm32u(3), status);
op1->xmm32u(3) = (rc == float_relation_greater) ? op1->xmm32u(3) : op2->xmm32u(3);
}
BX_CPP_INLINE void sse_maxpd(BxPackedXmmRegister *op1, BxPackedXmmRegister *op2, float_status_t &status, bx_bool mxcsr_daz)
{
if (mxcsr_daz) {
op1->xmm64u(0) = float64_denormal_to_zero(op1->xmm64u(0));
op1->xmm64u(1) = float64_denormal_to_zero(op1->xmm64u(1));
op2->xmm64u(0) = float64_denormal_to_zero(op2->xmm64u(0));
op2->xmm64u(1) = float64_denormal_to_zero(op2->xmm64u(1));
}
int rc = float64_compare(op1->xmm64u(0), op2->xmm64u(0), status);
op1->xmm64u(0) = (rc == float_relation_greater) ? op1->xmm64u(0) : op2->xmm64u(0);
rc = float64_compare(op1->xmm64u(1), op2->xmm64u(1), status);
op1->xmm64u(1) = (rc == float_relation_greater) ? op1->xmm64u(1) : op2->xmm64u(1);
}
#endif